Make WordPress Core

Opened 13 years ago

Closed 11 years ago

#20595 closed defect (bug) (invalid)

Collapsible Admin menu fails if items are added by code

Reported by: digitaldonkey's profile digitaldonkey Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: Administration Keywords: dev-feedback
Focuses: Cc:

Description

If I add a Button to the admin meny by action adminmenu the menu wont rebuid from collapsed state due z-index issues. In my opinion creating the menue might be changed to the following:

diff --git a/wp-admin/menu-header.php b/wp-admin/menu-header.php
index cdd81b2..8454a3d 100644
--- a/wp-admin/menu-header.php
+++ b/wp-admin/menu-header.php
@@ -164,10 +164,6 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
                }
                echo "</li>";
        }
-
-       echo '<li id="collapse-menu" class="hide-if-no-js"><div id="collapse-button"><div></div></div>';
-       echo '<span>' . esc_html__( 'Collapse menu' ) . '</span>';
-       echo '</li>';
 }

 ?>
@@ -181,6 +177,9 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {

 _wp_menu_output( $menu, $submenu );
 do_action( 'adminmenu' );
+echo '<li id="collapse-menu" class="hide-if-no-js"><div id="collapse-button"><div></div></div>';
+echo '<span>' . esc_html__( 'Collapse menu' ) . '</span>';
+echo '</li>';

 ?>
 </ul>

see also: http://wordpress.org/support/topic/admin-menu-wont-dis-collapse-anymore

Change History (3)

#1 follow-up: @SergeyBiryukov
13 years ago

  • Keywords reporter-feedback added

What code do you use to create the menu item? The one in the forums thread doesn't seem to be a correct way to do that.

A correct example: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_menu

#2 in reply to: ↑ 1 @digitaldonkey
13 years ago

Replying to SergeyBiryukov:

What code do you use to create the menu item? The one in the forums thread doesn't seem to be a correct way to do that.

A correct example: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_menu

The standard way using add_submenu_page() requires to have a file and a actual subpage as far as I know.
I require a link which will only add a get var in order to implement some cache-clear, loading the current-admin page.

Is there a reason, why the action-hook is not called before collapse-menu-button? Then everything will work as expected.

function clearcachify_menue() { 
?>
<li class="wp-not-current-submenu menu-top menu-top-last" id="menu-clearcachifyclear">
	<div class="wp-menu-image">
    <a href="<?php print $GLOBALS['cache-clear-uri']; ?>"><img alt="" src="/wp-admin/images/generic.png"></a>	</div>
	<div class="wp-menu-arrow">
	  <div></div>
	</div>
	<a href="<?php print $GLOBALS['cache-clear-uri']; ?>" class="wp-not-current-submenu menu-top " tabindex="1">Clear Cache</a>
	
	</li>
<?php }

#3 @DrewAPicture
11 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Adding a menu link in this way is not supported by the admin menu API. And printing a $_GLOBAL value via an href probably isn't advisable either.

Regardless, I'd suggest maybe adding a toolbar link instead where you can specify the href destination you need. Take a look at `WP_Admin_Bar->add_menu|add_node()`.

Note: See TracTickets for help on using tickets.