From b74398f96e04c57bd65b5881cb8f3b26dab70d66 Mon Sep 17 00:00:00 2001 From: wpalani Date: Mon, 11 Nov 2024 16:41:57 -0700 Subject: [PATCH] Properly modify page title to avoid lint error introduced by #633 --- includes/WP_Admin.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 9f031acda..e57b614ae 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -30,6 +30,7 @@ final class WP_Admin { public function __construct() { \add_action( 'init', array( __CLASS__, 'load_php_textdomain' ) ); \add_action( 'admin_menu', array( __CLASS__, 'register_page' ) ); + \add_filter( 'admin_title', array( __CLASS__, 'page_title' ), 10, 1 ); \add_action( 'load-dashboard_page_' . self::$slug, array( __CLASS__, 'initialize' ) ); if ( 'sitegen' === Data::current_flow() ) { \add_action( 'load-themes.php', array( __CLASS__, 'mark_sitegen_generated_themes' ) ); @@ -70,6 +71,20 @@ public static function register_page() { ); } + /** + * Set the page title for the Onboarding page. + * + * @param string $admin_title The title of the admin page. + * @return string + */ + public static function page_title( $admin_title ) { + if ( isset( $_GET['page'] ) && \sanitize_text_field( wp_unslash( $_GET['page'] ) ) === self::$slug ) { + $admin_title = \__( 'Onboarding', 'wp-module-onboarding' ) . $admin_title; + } + + return $admin_title; + } + /** * Render DOM element for React SPA mount. * @@ -155,12 +170,6 @@ public static function enqueue_block_assets() { * @return void */ public static function initialize() { - global $title; - - if ( is_null( $title ) ) { - $title = __( 'Onboarding', 'wp-module-onboarding' ); - } - if ( ! empty( $_GET['nfd_plugins'] ) && 'true' === sanitize_text_field( $_GET['nfd_plugins'] ) ) { PluginService::initialize(); }