WordPress.org

Make WordPress Core

#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:

Description

I create my plugin pages with functions:

add_menu_page()
add_submenu_page()

It works.

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

remove_submenu_page().

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:
prefixgeneratedfromtitlepage_my-slug-page

With use of remove_submenu_page:
admin_page_my-slug-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)

comment:1 hinok23 months 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;
		}
	}

comment:2 SergeyBiryukov23 months ago

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