Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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's profile ioannup Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords: has-patch
Focuses: administration Cc:

Description

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.

  1. Moreover, open WP Settings -> Writing Settings and check $current_screen. https://i.imgur.com/kgJUukF.png
  2. 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, '' );
 

Attachments (1)

plugin.diff (463 bytes) - added by ioannup 5 years ago.
The patch

Download all attachments as: .zip

Change History (3)

@ioannup
5 years ago

The patch

#1 @ocean90
5 years ago

  • Component changed from Menus to Plugins
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version 5.2.2 deleted

Hello @ioannup, welcome to WordPress Trac!

Thanks for the report. We're already tracking this issue in #18857.

#2 @ioannup
5 years ago

@ocean90 What do you mean tracking? It's already tracking 8 years for a quick fix.

Last edited 5 years ago by ioannup (previous) (diff)
Note: See TracTickets for help on using tickets.