[wp-trac] [WordPress Trac] #20878: Invalid get_admin_page_parent(), after use of remove_submenu_page()

WordPress Trac wp-trac at lists.automattic.com
Thu Jun 7 16:14:55 UTC 2012


#20878: Invalid get_admin_page_parent(), after use of remove_submenu_page()
----------------------------+-----------------------------
 Reporter:  hinok           |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  3.3.2
 Severity:  major           |   Keywords:
----------------------------+-----------------------------
 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:[[BR]]

 Without use of remove_submenu_page:[[BR]]
 ''prefixgeneratedfromtitlepage_my-slug-page''[[BR]]


 With use of remove_submenu_page:[[BR]]
 ''admin_page_my-slug-page''[[BR]]

 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?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20878>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list