slugs. Keys and slugs come from web/lib/help/keys.ts of smsportal.app * (scripts/validate-help.mjs checks that they match). */ const ARTICLES = array( 'wp-install' => array( 'pl' => 'wordpress-instalacja', 'en' => 'wordpress-install', ), 'wp-connect' => array( 'pl' => 'wordpress-polaczenie', 'en' => 'wordpress-connect', ), 'wp-rules' => array( 'pl' => 'wordpress-reguly', 'en' => 'wordpress-rules', ), 'wp-woocommerce' => array( 'pl' => 'wordpress-woocommerce', 'en' => 'wordpress-woocommerce', ), 'wp-forms' => array( 'pl' => 'wordpress-formularze', 'en' => 'wordpress-forms', ), 'wp-bookings' => array( 'pl' => 'wordpress-rezerwacje', 'en' => 'wordpress-bookings', ), 'wp-members' => array( 'pl' => 'wordpress-ultimate-member-automator', 'en' => 'wordpress-ultimate-member-automator', ), 'wp-replies-stop' => array( 'pl' => 'wordpress-odpowiedzi-i-stop', 'en' => 'wordpress-replies-and-stop', ), 'wp-log' => array( 'pl' => 'wordpress-wyslane-i-dziennik', 'en' => 'wordpress-sent-and-log', ), 'wp-settings' => array( 'pl' => 'wordpress-ustawienia', 'en' => 'wordpress-settings', ), 'wp-troubleshooting' => array( 'pl' => 'wordpress-problemy', 'en' => 'wordpress-troubleshooting', ), 'offline' => array( 'pl' => 'telefon-offline', 'en' => 'phone-offline', ), 'battery' => array( 'pl' => 'oszczedzanie-baterii', 'en' => 'battery-optimization', ), 'sms-length' => array( 'pl' => 'polskie-znaki-i-dlugosc-sms', 'en' => 'sms-length-and-special-characters', ), ); /** * Articles of each plugin tab; the first one is the main guide (also linked from the header). */ const TABS = array( 'overview' => array( 'wp-connect', 'offline' ), 'rules' => array( 'wp-rules', 'wp-woocommerce', 'wp-forms', 'wp-bookings', 'wp-members' ), 'sent' => array( 'wp-log' ), 'replies' => array( 'wp-replies-stop' ), 'log' => array( 'wp-log' ), 'blocked' => array( 'wp-replies-stop' ), 'settings' => array( 'wp-settings' ), ); /** * Articles linked in the help sidebar of every tab, after the help center itself. */ const SIDEBAR = array( 'wp-troubleshooting', 'battery' ); /** * Whether the admin works in Polish (pl, pl_PL…). Every other language gets the English help center. * * @return bool */ private static function polish(): bool { return 0 === strpos( determine_locale(), 'pl' ); } /** * Help center home in the admin's language. * * @return string */ public static function index_url(): string { return self::SITE . ( self::polish() ? '/pomoc' : '/en/help' ); } /** * Article in the admin's language. An unknown key gives the help center home. * * @param string $key Article key (self::ARTICLES). * @return string */ public static function url( string $key ): string { if ( ! isset( self::ARTICLES[ $key ] ) ) { return self::index_url(); } return self::index_url() . '/' . self::ARTICLES[ $key ][ self::polish() ? 'pl' : 'en' ]; } /** * Main guide of a plugin tab. An unknown tab gives the overview guide. * * @param string $tab Tab slug (Menu::tabs()). * @return string */ public static function tab_url( string $tab ): string { $keys = self::TABS[ $tab ] ?? self::TABS['overview']; return self::url( $keys[0] ); } /** * Add the help tab of the current plugin tab and the help sidebar to the screen. Runs on load-{hook}. * * @return void */ public static function register(): void { $screen = get_current_screen(); if ( null === $screen ) { return; } $tab = Menu::current_tab(); $screen->add_help_tab( array( 'id' => 'smsportal-help-' . $tab, 'title' => Menu::tabs()[ $tab ], 'content' => self::tab_content( $tab ), ) ); $screen->set_help_sidebar( self::sidebar() ); } /** * Body of a help tab: a short explanation and links to the guides. * * @param string $tab Tab slug. * @return string */ private static function tab_content( string $tab ): string { $html = ''; foreach ( self::texts()[ $tab ] as $paragraph ) { $html .= '
' . esc_html( $paragraph ) . '
'; } $html .= '' . esc_html__( 'Step-by-step guides (they open in a new tab):', '85pl-android-sms-api' ) . '
' . esc_html__( 'More help', '85pl-android-sms-api' ) . '
'; $html .= '' . self::anchor( self::index_url(), __( 'Help center', '85pl-android-sms-api' ) ) . '
'; foreach ( self::SIDEBAR as $key ) { $html .= '' . self::link( $key ) . '
'; } return wp_kses_post( $html ); } /** * Link to an article, labelled with its title. * * @param string $key Article key. * @return string */ private static function link( string $key ): string { return self::anchor( self::url( $key ), self::titles()[ $key ] ); } /** * Link that opens in a new tab. * * @param string $url Address. * @param string $label Link text. * @return string */ private static function anchor( string $url, string $label ): string { return '' . esc_html( $label ) . ''; } /** * Titles of the linked articles. * * @return array