[wp-trac] [WordPress Trac] #40649: parent_file filter seems to be overwritten by get_admin_page_parent call

WordPress Trac noreply at wordpress.org
Wed May 3 13:37:54 UTC 2017


#40649: parent_file filter seems to be overwritten by get_admin_page_parent call
----------------------------+-----------------------------
 Reporter:  jontis          |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:  4.7.4
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 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.

 {{{#!php
 <?php
 /**
  * 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
 );

 get_admin_page_parent();
 }}}

 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:
 {{{#!php
 <?php
 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.

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


More information about the wp-trac mailing list