#47805 closed defect (bug) (duplicate)
The $current_screen->base is based on $menu_title of `add_menu_page` function instead of $menu_slug of its parent
Reported by: | ioannup | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Plugins | Keywords: | has-patch |
Focuses: | administration | Cc: |
Description
Steps:
- 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.
- Install Woocomerce (https://wordpress.org/plugins/woocommerce/) or any other plugin with their own page as an example for checking $current_screen.
- 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
- 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. - 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.
- Moreover, open WP Settings -> Writing Settings and check $current_screen. https://i.imgur.com/kgJUukF.png
- Change WP Settings $menu_title from
Settings
toTest2
(/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, '' );
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.
The patch