$screen ) { $parent = 'left' === swiftdash_screen_location( $screen ) ? 'swift-dash' : ''; swiftdash_screen_hooks( add_submenu_page( $parent, $screen['title'], $screen['menu'], $cap, $slug, $render ) ); } } add_action( 'admin_menu', 'swiftdash_admin_menu' ); /** * Keep the SwiftWebDev menu item highlighted on every plugin screen, including the ones * reached from the user menu. * * @param string $parent_file Parent menu slug. * @return string */ function swiftdash_menu_parent_file( $parent_file ) { return swiftdash_is_screen() ? 'swift-dash' : $parent_file; } add_filter( 'parent_file', 'swiftdash_menu_parent_file' ); /** * Hidden screens are registered without a parent, so WordPress would reset the highlighted * parent to none while it prints the menu. Unlist them once access checks are done * (admin_head runs right before the menu); the pages stay registered and reachable. */ function swiftdash_menu_unlist_hidden() { global $submenu; if ( ! swiftdash_is_screen() || empty( $submenu[''] ) ) { return; } $slugs = array_keys( swiftdash_screens() ); foreach ( $submenu[''] as $i => $item ) { if ( in_array( $item[2], $slugs, true ) ) { unset( $submenu[''][ $i ] ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- removes our own hidden entries only. } } } add_action( 'admin_head', 'swiftdash_menu_unlist_hidden' ); /** * Browser tab title from the screen title. Hidden pages (no parent menu) otherwise get a null * $title: an empty tab title plus a strip_tags() deprecation in admin-header.php. */ function swiftdash_admin_page_title() { global $title, $plugin_page; $screens = swiftdash_screens(); if ( empty( $title ) && $plugin_page && isset( $screens[ $plugin_page ] ) && swiftdash_is_screen() ) { $title = $screens[ $plugin_page ]['title']; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- WordPress reads it for the document title. } } add_action( 'current_screen', 'swiftdash_admin_page_title' ); /** * Menu restyle on every admin page for permitted users. */ function swiftdash_menu_assets() { if ( swiftdash_menu_enabled() ) { // Tokens carry the bundled font the menu uses; their variables stay scoped to .swiftdash. wp_enqueue_style( 'swiftdash-tokens', SWIFTDASH_URL . 'assets/css/tokens.css', array(), SWIFTDASH_VERSION ); wp_enqueue_style( 'swiftdash-admin-menu', SWIFTDASH_URL . 'assets/css/admin-menu.css', array( 'colors', 'swiftdash-tokens' ), SWIFTDASH_VERSION ); } } add_action( 'admin_enqueue_scripts', 'swiftdash_menu_assets' ); /** * Brand block: the site's logo and name, placed first with CSS. */ function swiftdash_menu_extras() { if ( ! swiftdash_menu_enabled() ) { return; } $brand = swiftdash_brand(); ?>