Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#41343 closed defect (bug) (invalid)

Multisite issue: Applying remove_submenu_pages($parent_slug, $menu_slug) to a page like admin.php?page=qs takes out all sub menus under that parent

Reported by: subrataemfluence's profile subrataemfluence Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: Administration Keywords:
Focuses: ui, administration, multisite Cc:

Description

Hi,

Having strange issue with admin menu in multisite environment. I have a menu which has two sub-menus, YRC Global Settings (first on the list) and YRC Homepage Settings (second in the list). The parent and sub-menus are all pointing to admin.php?page=qs, qs being different for teh second sub-menu in the list.

I required to hide the second sub-menu item keeping the first one visible, so that when admin/user hovers on the parent menu i.e. YRC Settings, the first one (YRC Global Settings) only flies out keeping the other one in the list invisible.

I used remove_submenu_page( 'yrc_settings', 'yrc_home_settings' );, but this takes out both sub when in multisite mode but in single installation mode it works fine.

Menu structure is like this:

Parent: YRC Settings
Pointing to: /wp-admin/admin.php?page=yrc_settings

First Sub menu item: YRC Global Settings:
Pointing to: /wp-admin/admin.php?page=yrc_settings

Second Sub menu item: YRC Homepage Settings
Pointing to: /wp-admin/admin.php?page=yrc_home_settings

I am not sure if this is a multisite specific bug, but because the same approach works well with single installation then either this is a bug or there is not enough or no documentation about how to use this function in multisite mode!

Either way I feel this should be looked into.

The code in functions.php file looks like this:

<?php
function restrict_admin_access_by_role() {
   if(function_exists('remove_menu_page')) {
      if(is_multisite()) {
         if(!is_super_admin()) {
           remove_submenu_page( 'yrc_settings', 'yrc_home_settings' );
         }
      }
   }
}

add_action('admin_menu', 'restrict_admin_access_by_role', 999);

Attachments (3)

all-sub-menu-items.jpg (44.1 KB) - added by subrataemfluence 8 years ago.
This is how the menu looks like for admin
sub-menu-items-disappeared.jpg (30.8 KB) - added by subrataemfluence 8 years ago.
All sub menu items disappeared
what-is-required.jpg (43.7 KB) - added by subrataemfluence 8 years ago.
Should come up like this, i.e. remove only the sub menu I told WP to do

Download all attachments as: .zip

Change History (5)

@subrataemfluence
8 years ago

This is how the menu looks like for admin

@subrataemfluence
8 years ago

All sub menu items disappeared

@subrataemfluence
8 years ago

Should come up like this, i.e. remove only the sub menu I told WP to do

#1 @subrataemfluence
8 years ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

Ah! Got this to work :) The hook I should be using is admin_init not admin_menu. Now everything is fine! Closing as invalid.

#2 @netweb
7 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.