[wp-trac] [WordPress Trac] #47805: The $current_screen->base is based on $menu_title of `add_menu_page` function instead of $menu_slug of its parent

WordPress Trac noreply at wordpress.org
Tue Jul 30 19:59:32 UTC 2019


#47805: The $current_screen->base is based on $menu_title of `add_menu_page`
function instead of $menu_slug of its parent
----------------------------+-----------------------------
 Reporter:  ioannup         |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Menus           |    Version:  5.2.2
 Severity:  normal          |   Keywords:  has-patch
  Focuses:  administration  |
----------------------------+-----------------------------
 Steps:
 1. Install Query Monitor (https://wordpress.org/plugins/query-monitor/)
 plugin for checking $current_screen variable or you can find another way
 to check $current_screen.
 2. Install Woocomerce (https://wordpress.org/plugins/woocommerce/) or any
 other plugin with their own page as an example for checking
 $current_screen.
 3. Open Woocommerce Settings page /wp-admin/admin.php?page=wc-settings and
 Admin Screen section of the Query Monitor's menu on the Admin Bar on this
 page. https://i.imgur.com/tBdBExF.png
 4. Change Woocomerce $menu_title (the second attr of `add_menu_page`
 function ) to Test in the `/wp-content/plugins/woocommerce/includes/admin
 /class-wc-admin-menus.php` file, line ~59. It's just for test. Nobody will
 change it manually, but it's a translatable string. It means it can be
 changed via localization files.
 5. Check the Settings page again. https://i.imgur.com/vZlX0ac.png
 The current screen base was changed despite the Parent base wasn't.

 So, it proves that the $current_screen->base is based on
 $menu_titleinstead of $menu_slug of its parent.

 6. Moreover, open WP Settings -> Writing Settings and check
 $current_screen. https://i.imgur.com/kgJUukF.png
 7. Change WP Settings $menu_title from `Settings` to `Test2` (`/wp-
 admin/menu.php` file, line ~274 ) and check the $current_screen again.
 https://i.imgur.com/6u5ixkS.png
 The current screen base didn't change, but the Menu title did. And it's
 expected behavior.

 The patch

 {{{
 Index: src/wp-admin/includes/plugin.php
 ===================================================================
 --- src/wp-admin/includes/plugin.php    (revision 45699)
 +++ src/wp-admin/includes/plugin.php    (working copy)
 @@ -1276,7 +1276,7 @@

         $menu_slug = plugin_basename( $menu_slug );

 -       $admin_page_hooks[ $menu_slug ] = sanitize_title( $menu_title );
 +       $admin_page_hooks[ $menu_slug ] = $menu_slug;

         $hookname = get_plugin_page_hookname( $menu_slug, '' );

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47805>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list