Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#20878 closed defect (bug) (duplicate)

Invalid get_admin_page_parent(), after use of remove_submenu_page()

Reported by: hinok Owned by:
Milestone: Priority: normal
Severity: major Version: 3.3.2
Component: Administration Keywords:
Focuses: Cc:


I create my plugin pages with functions:


It works.

I want hide some of my subpages, so I used:


My pages was removed from wordpress menu admin, but I can not view them by direct url.
I get only error:

You do not have sufficient permissions to access this page.

I found that, problem is with get_admin_page_parent(), because my hookname was different. (when I used remove_submenu_page(), and not), for example:

Without use of remove_submenu_page:

With use of remove_submenu_page:

I found function user_can_access_admin_page() in wp-admin/includes/menu.php, and then look in wp-admin/includes/plugin.php, I found this:

		if ( !isset($_registered_pages[$hookname]) ) // here is problem with wrong generated $hookname
			return false; 

I get return false, because $hookname was wrong generated.
Why hookname was wrong generated? Because I dont get my $parent.

So I found get_plugin_page_hookname() and get_admin_page_parent() in wp-admin/includes/plugins.php.

Weird is that, global variables like $_registered_pages and $_parent_pages are OK.
So I used this piece of code to repair my problem.

In 1403 line of wp-admin/icludes/plugin.php, I added:

	global $_parent_pages;
	// global $plugin_page; // globalized above
	foreach ($_parent_pages as $key => $value) {
		if ( $key == $plugin_page ) {
			return $value;

And now is ok, but my wordpress menu doesnt open, when I view my hidden page.

Why in get_admin_page_parent(), wordpress doesn`t look for $parent in $_parent_pages?

Change History (2)

#1 @hinok
8 years ago

Ok, now my wordpress menu open correctly, new one line of code :)

	global $_parent_pages;
	// global $plugin_page; // globalized above
	foreach ($_parent_pages as $key => $value) {
		if ( $key == $plugin_page ) {
			$parent_file = $value; // magic
			return $value;

#2 @SergeyBiryukov
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.