[wp-trac] [WordPress Trac] #19085: Removing First Submenu Page in Admin Menu breaks URL for Menu Page

WordPress Trac noreply at wordpress.org
Sun Oct 25 01:31:18 UTC 2015


#19085: Removing First Submenu Page in Admin Menu breaks URL for Menu Page
-------------------------------------+------------------------------
 Reporter:  mikeschinkel             |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Administration           |     Version:  3.1
 Severity:  normal                   |  Resolution:
 Keywords:  needs-testing has-patch  |     Focuses:
-------------------------------------+------------------------------

Comment (by chrisguitarguy):

 The patch I just added is an alterntive take on filtering here that I
 think makes sense. Keep all the behavior the same as before, which works
 for 99% of people. But add two filters. One to change the global
 `$submenu_as_parent` value, the other to change the beavhior on individual
 admin pages. Meaning you can do something like this:

 {{{#!php
 add_action('admin_menu', 'wpse206471_add_pages');
 function wpse206471_add_pages()
 {
     $hook = add_menu_page(
         __('WPSE206471 Main Page', 'wpse206471'),
         __('Main Page', 'wpse206471'),
         'manage_options',
         'wpse206471-main',
         'wpse206471_main_page'
     );
     add_submenu_page(
         'wpse206471-main',
         __('WPSE206471 Sub Page', 'wpse206471'),
         __('Sub Page', 'wpse206471'),
         'manage_options',
         'wpse206471-sub',
         'wpse206471_sub_page'
     );

     // remove the "main" submenue page
     remove_submenu_page('wpse206471-main', 'wpse206471-main');
     // tell `_wp_menu_output` not to use the submenu item as its link
     add_filter("submenu_as_parent_{$hook}", '__return_false');
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/19085#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list