From 7fc23ee300e4d73a02f139c75592a32478d6bae0 Mon Sep 17 00:00:00 2001 From: Henrique Mouta Date: Wed, 13 Nov 2024 09:49:36 +0000 Subject: [PATCH] Remove submenu highlight when the page loads --- src/UI/class-dashboard-page.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/UI/class-dashboard-page.php b/src/UI/class-dashboard-page.php index dd66d63b5..d2208d821 100644 --- a/src/UI/class-dashboard-page.php +++ b/src/UI/class-dashboard-page.php @@ -29,6 +29,7 @@ final class Dashboard_Page { public function run(): void { add_action( 'admin_menu', array( $this, 'add_dashboard_page_to_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_dashboard_page_scripts' ) ); + add_filter( 'parent_file', array( $this, 'fix_submenu_highlighting' ) ); } /** @@ -89,6 +90,28 @@ public function add_dashboard_page_placeholder(): void { echo '
'; } + /** + * Fixes the highlighting of the submenu items. + * + * This removes the highlighting from the submenu items when the dashboard page is active, so it can + * later be added by the React app. + * + * @since 3.18.0 + * + * @param string $parent_file The parent file. + * @return string The parent file. + */ + public function fix_submenu_highlighting( string $parent_file ): string { + global $submenu_file, $current_screen; + + if ( 'toplevel_page_parsely-dashboard-page' === $current_screen->base ) { + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + $submenu_file = 'non-existent-slug'; + } + + return $parent_file; + } + /** * Enqueues all needed scripts and styles for the dashboard page. *