[wp-trac] [WordPress Trac] #12718: Better structure for admin $menu

WordPress Trac wp-trac at lists.automattic.com
Tue Sep 28 01:13:03 UTC 2010


#12718: Better structure for admin $menu
-------------------------+--------------------------------------------------
 Reporter:  scribu       |       Owner:                 
     Type:  enhancement  |      Status:  assigned       
 Priority:  normal       |   Milestone:  Awaiting Triage
Component:  Plugins      |     Version:                 
 Severity:  normal       |    Keywords:                 
-------------------------+--------------------------------------------------

Comment(by mikeschinkel):

 Replying to [comment:12 scribu]:
 > Mike, how would you remove a single menu item with your API?

 What I presented was a proof of concept and not a fully fleshed-out
 example. That said, I just spent time and updated to it provide a
 `delete_admin_menu_item()` to encapsulate the object calls and thus make
 it easier for the average guy (and I found and fixed a few bugs. :)

 Here's the gist/download link:

    https://gist.github.com/792b7aa5b695d1092520

 So let's say you wanted to delete the ''"Editor"'' items for both
 ''"Appearance"'' and ''"Plugins"'' menu sections.  The first one requires
 you to set a priority of 102 because the Editor item is added using a
 priority of 101:

 {{{
 add_action('admin_menu', 'my_admin_menu',102);
 function my_admin_menu() {
   delete_admin_menu_item('Appearance','Editor');
 }
 }}}

 The second one requires a regular expression because the Plugin menu
 section title has a `<span></span>` that follows it to display the number
 of plugins that need to be updated so I use a simple RegEx to match:

 {{{
 add_action('admin_menu', 'my_admin_menu');
 function my_admin_menu() {
   delete_admin_menu_item('Plugins .*','Editor');
 }
 }}}

 Another I could do these is to use the slugs, i.e.

 {{{
 add_action('admin_menu', 'my_admin_menu',102);
 function my_admin_menu() {
   delete_admin_menu_item('themes.php','theme-editor.php',array(
         'find_section_by' => 'slug',
         'find_item_by'    => 'slug',
   ));
   delete_admin_menu_item('plugins.php','plugin-editor.php',array(
         'find_section_by' => 'slug',
         'find_item_by'    => 'slug',
   ));
 }
 }}}

 As I write that last example I think maybe it would be better if I
 modified it to "sniff" out the distinction between title, slug, and/or
 index; i.e. look first to see if is_numeric(), if not then look to match
 slug, if not look to match title.  Your thoughts?

 BTW, I'd be happy to evolve of change this in whatever direction would be
 needed to use it in core, if potential.  Let me know.

 -Mike

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12718#comment:13>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list