fix menu item visibility

This commit is contained in:
Abhijit Bhatnagar 2025-08-10 00:22:24 +05:30
parent 01a7f967a4
commit 38067e490a

View file

@ -28,23 +28,7 @@ add_action(
// Remove all admin menu separators. // Remove all admin menu separators.
remove_all_admin_menu_separators(); remove_all_admin_menu_separators();
// 2) Ensure the "WordPress Admin" return link is present on first load. // 2) Add custom Helix menu items.
if ( ! get_option( 'helix_use_default_admin', false ) ) {
global $admin_page_hooks;
if ( ! isset( $admin_page_hooks['wordpress-admin'] ) ) {
add_menu_page(
'WordPress Admin',
'WordPress Admin',
'read',
'wordpress-admin',
'wordpress_admin_callback',
'dashicons-wordpress',
2
);
}
}
// 3) Add custom Helix menu items.
add_menu_page( add_menu_page(
'Helix Posts', 'Helix Posts',
'Posts', 'Posts',
@ -68,11 +52,6 @@ add_action(
10 10
); );
/**
* Ensure the "WordPress Admin" return link is present when landing on Helix, even on the first load
* after switching modes in the same request.
*/
/** /**
* Remove all admin menu separators. * Remove all admin menu separators.
*/ */
@ -95,10 +74,18 @@ function remove_all_admin_menu_separators() {
add_action( add_action(
'admin_menu', 'admin_menu',
function () { function () {
// Only show the "WordPress Admin" link when in Helix mode. global $pagenow;
// Check if we're going to the Helix page by looking at the sanitized request.
$page_requested = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_URL );
$is_helix_request = ( 'admin.php' === $pagenow && 'helix' === $page_requested );
$use_default_admin = get_option( 'helix_use_default_admin', false ); $use_default_admin = get_option( 'helix_use_default_admin', false );
if ( $use_default_admin ) {
return; // Always show the WordPress Admin link when navigating to Helix, or when not in default admin mode.
if ( $is_helix_request || ! $use_default_admin ) {
// If this is a Helix request, ensure we're in Helix mode.
if ( $is_helix_request ) {
update_option( 'helix_use_default_admin', false );
} }
// Add a menu item to go back to default WordPress admin. // Add a menu item to go back to default WordPress admin.
@ -111,6 +98,7 @@ add_action(
'dashicons-wordpress', // Icon. 'dashicons-wordpress', // Icon.
2 // Position (after main Helix menu). 2 // Position (after main Helix menu).
); );
}
}, },
1000 1000
); );