From 3cb149a92d9205220a4bf15a5dab4445ea736f4a Mon Sep 17 00:00:00 2001 From: TallblokeUK Date: Sun, 18 Oct 2026 09:43:02 +0100 Subject: [PATCH 1/2] fix: give the edit snippet screen its page title --- src/php/Admin/Menus/Edit_Menu.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/php/Admin/Menus/Edit_Menu.php b/src/php/Admin/Menus/Edit_Menu.php index b29fb7872..7d84dd487 100644 --- a/src/php/Admin/Menus/Edit_Menu.php +++ b/src/php/Admin/Menus/Edit_Menu.php @@ -115,9 +115,25 @@ private function register_without_menu_item(): void { if ( $hook ) { add_action( 'load-' . $hook, array( $this, 'load' ) ); + add_action( 'load-' . $hook, array( $this, 'set_page_title' ) ); } } + /** + * Give the edit screen its title. + * + * WordPress looks a page's title up in the admin menu, where this page is not + * registered, and the admin header requires one. + * + * @return void + */ + public function set_page_title(): void { + global $title; + + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- the admin header reads the page title from this global. + $title = $this->title; + } + /** * Mark the snippet being edited in the menu. * From 608f53a4c77142f3017032584e7b7f1183ef14ea Mon Sep 17 00:00:00 2001 From: TallblokeUK Date: Sun, 18 Oct 2026 09:43:12 +0100 Subject: [PATCH 2/2] test: cover the edit snippet screen title --- tests/unit/Admin/Menus/Edit_Menu_Test.php | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/unit/Admin/Menus/Edit_Menu_Test.php b/tests/unit/Admin/Menus/Edit_Menu_Test.php index bfa981ed2..9249cc4c5 100644 --- a/tests/unit/Admin/Menus/Edit_Menu_Test.php +++ b/tests/unit/Admin/Menus/Edit_Menu_Test.php @@ -130,4 +130,43 @@ public function test_hookname_matches_the_registered_page(): void { $this->assertContains( $registered, $menu->get_hooknames() ); $this->assertNotFalse( has_action( 'load-' . $registered, [ $menu, 'load' ] ), 'the load hook is bound to the same name' ); } + + /** + * The edit screen has a title for the admin header. + * + * WordPress looks a page's title up in the admin menu, where the edit page is + * not registered, and the admin header passes the result to strip_tags(). + * + * @return void + */ + public function test_edit_screen_has_a_title(): void { + global $title, $pagenow, $plugin_page; + + $edit_slug = code_snippets()->get_menu_slug( 'edit' ); + $_GET['page'] = $edit_slug; + $_GET['id'] = '11'; + + $menu = new Edit_Menu(); + $menu->register(); + + $load_hook = 'load-' . $menu->get_hookname(); + remove_action( $load_hook, [ $menu, 'load' ] ); + + $previous_pagenow = $pagenow; + + // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited -- the title lookup reads the current page from these globals. + $pagenow = 'admin.php'; + $plugin_page = $edit_slug; + $title = null; + + try { + do_action( $load_hook ); + $this->assertSame( $menu->title, get_admin_page_title() ); + } finally { + $pagenow = $previous_pagenow; + $plugin_page = null; + $title = null; + } + // phpcs:enable WordPress.WP.GlobalVariablesOverride.Prohibited + } }