[wp-trac] [WordPress Trac] #26935: Add empty submenu page to hide menu page title in list

WordPress Trac noreply at wordpress.org
Fri Mar 21 12:35:21 UTC 2014


#26935: Add empty submenu page to hide menu page title in list
-------------------------+------------------------------
 Reporter:  josh401      |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Menus        |     Version:  3.8
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------
Changes (by SergeyBiryukov):

 * version:  trunk => 3.8


Old description:

> My question has to do with `add_menu_page()` and `add_submenu_page()`.
> If we add a menu page, and one sub_menu page.. we end up with the main
> menu page being duplicated in the sub pages list.
>
> If we have "Main" as our main page, and "Sub" as our sub page...
>
>     add_menu_page('Main', 'Main', 'manage_options', 'main_options',
> array($this, 'main_do_page'));
>     add_submenu_page('main_options', 'Sub', 'Sub', 'manage_options',
> 'sub_options', null);
>
> This will create a menu structure such as:
> * Main
>  * Main
>  * Sub
>
> The "Main" page is duplicated in the sub list.
>
> Now, we can hide that duplication with a slight adjustment to the code:
>
>     add_menu_page('Main', 'Main', 'manage_options', 'main_options',
> array($this, 'main_do_page'));
>     add_submenu_page('main_options', 'Sub', 'Sub', 'manage_options',
> 'main_options', null);
>
> By changing the fifth argument to match the "Main" page slug.. it will
> successfully hide the submenu; resulting in:
>
> * Main
>  * Sub
>
> However... the issue with this... is a menu item still gets created in
> the generated html.  The inner html is blank.. so no title is actually
> displayed.. but the outer html is still there.
>
> It appears in the submenu html output as such (with the second snippet
> above):
>
>     <li class="wp-first-item current">
>     <a class="wp-first-item current"
> href="admin.php?page=main_options"></a>
>     </li>
>     <li>
>     <a href="admin.php?page=sub_options">Options</a>
>     </li>
>
> See how the top item has the html for a list item.. but has no inner
> html?
>
> This creates a space, about 4 or 5 pixels.. in between the main item and
> the sub menu items.
>
> Now, I know this is trivial when there is only one menu item.  But, now
> that I know it exists.. it is driving me nuts.
>
> 1. It results in unnecessary html output.
> 2. It results in a space in the menu item list.. which is faint, but
> unattractive... and hinders the visual appeal of the new admin panel.
>
> Could we perhaps first check if the `add_submenu_page()` fifth argument
> ($menu_slug) matches the `add_menu_page()` first argument
> ($page_title)... then the outer html wrapper doesn't get rendered?
>
> With space example(http://joshlobe.com/testsite/images/trac1)
> Without space example(http://joshlobe.com/testsite/images/trac2)
>
> Thank you for reading.

New description:

 My question has to do with `add_menu_page()` and `add_submenu_page()`.  If
 we add a menu page, and one sub_menu page.. we end up with the main menu
 page being duplicated in the sub pages list.

 If we have "Main" as our main page, and "Sub" as our sub page...
 {{{
 add_menu_page('Main', 'Main', 'manage_options', 'main_options',
 array($this, 'main_do_page'));
 add_submenu_page('main_options', 'Sub', 'Sub', 'manage_options',
 'sub_options', null);
 }}}
 This will create a menu structure such as:
 * Main
  * Main
  * Sub

 The "Main" page is duplicated in the sub list.

 Now, we can hide that duplication with a slight adjustment to the code:
 {{{
 add_menu_page('Main', 'Main', 'manage_options', 'main_options',
 array($this, 'main_do_page'));
 add_submenu_page('main_options', 'Sub', 'Sub', 'manage_options',
 'main_options', null);
 }}}
 By changing the fifth argument to match the "Main" page slug.. it will
 successfully hide the submenu; resulting in:

 * Main
  * Sub

 However... the issue with this... is a menu item still gets created in the
 generated html.  The inner html is blank.. so no title is actually
 displayed.. but the outer html is still there.

 It appears in the submenu html output as such (with the second snippet
 above):
 {{{
 <li class="wp-first-item current">
     <a class="wp-first-item current"
 href="admin.php?page=main_options"></a>
 </li>
 <li>
     <a href="admin.php?page=sub_options">Options</a>
 </li>
 }}}
 See how the top item has the html for a list item.. but has no inner html?

 This creates a space, about 4 or 5 pixels.. in between the main item and
 the sub menu items.

 Now, I know this is trivial when there is only one menu item.  But, now
 that I know it exists.. it is driving me nuts.

 1. It results in unnecessary html output.
 2. It results in a space in the menu item list.. which is faint, but
 unattractive... and hinders the visual appeal of the new admin panel.

 Could we perhaps first check if the `add_submenu_page()` fifth argument
 ($menu_slug) matches the `add_menu_page()` first argument ($page_title)...
 then the outer html wrapper doesn't get rendered?

 With space example(http://joshlobe.com/testsite/images/trac1)
 Without space example(http://joshlobe.com/testsite/images/trac2)

 Thank you for reading.

--

Comment:

 Related: #19085

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


More information about the wp-trac mailing list