Make WordPress Core

Opened 3 years ago

Last modified 16 months ago

#40649 new defect (bug)

parent_file filter seems to be overwritten by get_admin_page_parent call — at Version 3

Reported by: jontis Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.4
Component: Menus Keywords:
Focuses: administration Cc:

Description (last modified by welcher)

In wp-admin/menu-header.php the filter parent_file seems to have little to no impact most of the time.
This is because the global $parent_file variable often gets immediately overwritten by the get_admin_page_parent function call.

 * Filters the parent file of an admin menu sub-menu item.
 * Allows plugins to move sub-menu items around.
 * @since MU
 * @param string $parent_file The parent file.
$parent_file = apply_filters( 'parent_file', $parent_file );

 * Filters the file of an admin menu sub-menu item.
 * @since 4.4.0
 * @param string $submenu_file The submenu file.
 * @param string $parent_file  The submenu item's parent file.
$submenu_file = apply_filters( 'submenu_file', $submenu_file, $parent_file );


I am not completely sure what the purpose of the get_admin_page_parent is, but maybe the filter should be called after or inside that function?

To try to give an example. If I have the "Broken Link Checker" plugin installed and try to move it's settings page to the Tools menu I would want use this code:

add_filter('parent_file', 'move_to_tools');
function move_to_tools($parent_file){
  global $hook_suffix;

  if($hook_suffix === 'settings_page_link-checker-settings'){
    $parent_file = 'tools.php';

  return $parent_file;

However, because of the above mentioned issue this code does nothing.
I am aware completely moving a settings page requires more work than this, this is purely an example.

Change History (3)

#1 @jontis
3 years ago

  • Component changed from General to Plugins

#2 @jontis
3 years ago

  • Component changed from Plugins to Menus

#3 @welcher
3 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.