From 6208be768b81bf5b656a7546aa015489c2099278 Mon Sep 17 00:00:00 2001 From: Vicente Canales <1157901+vcanales@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:34:18 -0300 Subject: [PATCH] Set page titles that set only within cbt (#479) Fixes: https://github.com/WordPress/create-block-theme/issues/478 --- admin/class-manage-fonts.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/admin/class-manage-fonts.php b/admin/class-manage-fonts.php index 6b70a907..5d9d2fa7 100644 --- a/admin/class-manage-fonts.php +++ b/admin/class-manage-fonts.php @@ -31,25 +31,41 @@ function create_admin_menu() { return; } + $manage_font_page_slug = 'manage-fonts'; + $add_google_font_page_slug = 'add-google-font-to-theme-json'; + $add_local_font_page_slug = 'add-local-font-to-theme-json'; + $manage_fonts_page_title = _x( 'Manage Theme Fonts', 'UI String', 'create-block-theme' ); $manage_fonts_menu_title = $manage_fonts_page_title; - add_theme_page( $manage_fonts_page_title, $manage_fonts_menu_title, 'edit_theme_options', 'manage-fonts', array( 'Fonts_Page', 'manage_fonts_admin_page' ) ); + add_theme_page( $manage_fonts_page_title, $manage_fonts_menu_title, 'edit_theme_options', $manage_font_page_slug, array( 'Fonts_Page', 'manage_fonts_admin_page' ) ); // Check if the admin page title is set, and if not, set one. // This is needed to avoid a warning in the admin menu, due to the admin page title not being set in // the add_submenu_page() function for the Google Fonts and Local Fonts pages. global $title; - if ( ! isset( $title ) ) { + + // Check if current admin page is a create block theme page. + // Context: https://github.com/WordPress/create-block-theme/issues/478 + $admin_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; + $manage_font_pages = array( + $manage_font_page_slug, + $add_google_font_page_slug, + $add_local_font_page_slug, + ); + + $is_manage_fonts_page = in_array( $admin_page, $manage_font_pages, true ); + + if ( ! isset( $title ) && $is_manage_fonts_page ) { $title = $manage_fonts_page_title; } $google_fonts_page_title = _x( 'Embed Google font in the active theme', 'UI String', 'create-block-theme' ); $google_fonts_menu_title = $google_fonts_page_title; - add_submenu_page( '', $google_fonts_page_title, $google_fonts_menu_title, 'edit_theme_options', 'add-google-font-to-theme-json', array( 'Google_Fonts', 'google_fonts_admin_page' ) ); + add_submenu_page( '', $google_fonts_page_title, $google_fonts_menu_title, 'edit_theme_options', $add_google_font_page_slug, array( 'Google_Fonts', 'google_fonts_admin_page' ) ); $local_fonts_page_title = _x( 'Embed local font in the active theme', 'UI String', 'create-block-theme' ); $local_fonts_menu_title = $local_fonts_page_title; - add_submenu_page( '', $local_fonts_page_title, $local_fonts_menu_title, 'edit_theme_options', 'add-local-font-to-theme-json', array( 'Local_Fonts', 'local_fonts_admin_page' ) ); + add_submenu_page( '', $local_fonts_page_title, $local_fonts_menu_title, 'edit_theme_options', $add_local_font_page_slug, array( 'Local_Fonts', 'local_fonts_admin_page' ) ); } function has_file_and_user_permissions() {