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

WordPress Trac wp-trac at lists.automattic.com
Wed Sep 29 08:54:09 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:16 scribu]:
 > Ok, I guess also looking at the title makes sense.
 >
 > Looking forward to the cleaned up patch.

 As promised, major positive changes. Your input helped me greatly to
 simplify it:

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

 I removed the $args parameter and now lookups are done first via slug and
 if that fails then via Title. I did not (yet?) perform Title translations
 because I was thinking maybe we shouldn't; that way use of Titles would
 really only apply for specific sites.
 I could possibly add a check for a constant something like
 'FIND_ADMIN_MENUS_BY_TITLE' that must be set for Find-By-Title to work.
 That way they'd have to find the docs to learn how to use which could say
 to only use Titles for individual sites, not for distributed themes nor
 for distributed plugins.

 One thing I did was recode it so that any properties or methods of the
 objects that might expose the internal structure became private. The idea
 is that the developer should not be able to use this API in a manner that
 would disallow us to later replace the underlying structure with something
 more rational ''(as you requested above)'' and not break the developers
 code. Because of this constraint I placed on the code architecture I had
 to write some code less than straightforward in one place but I think
 we'll greatly benefit down the road by this encapsulation.

 Also, I used the terms ''"Menu Section"'' and ''"Menu Item"'' because
 AFAICT there hasn't been consistent naming and the names that have been
 used are unclear (at least to me.)  If there are terms that others would
 prefer, I can change.

 Here is some example use cases:

 {{{
   // This example creates one menu in place of Dashboard called "My Menu",
 adds a few things, and removes all else.
   // This example assumes this might only be done for end users, not
 administrators

   $dashboard = rename_admin_menu_section('Dashboard','My Menu');
   delete_admin_menu_item($dashboard,'index.php');         // Dashboard
   delete_admin_menu_item($dashboard,'update-core.php');   // Updates

   $movies = "edit.php?post_type=movie";
   copy_admin_menu_item($dashboard,$movies);
   $movie_genre = 'edit-tags.php?taxonomy=movie-genre&post_type=movie';
   copy_admin_menu_item($dashboard,$movies,$movie_genre);
   rename_admin_menu_item($dashboard,$movie_genre,'Movie Genre');
   delete_admin_menu_item($movies);
   delete_admin_menu_item($movies,$movie_genre);
   delete_admin_menu_item($movies,'post-new.php?post_type=movie');
   delete_admin_menu_section($movies);

   $actors = "edit.php?post_type=actor";
   copy_admin_menu_item($dashboard,$actors);
   delete_admin_menu_item($actors);
   delete_admin_menu_item($actors,'post-new.php?post_type=actor');
   //delete_admin_menu_section($actors);

   rename_admin_menu_item($dashboard,'Pages','Other Pages');

   delete_admin_menu_section('edit.php');                  // Posts
   delete_admin_menu_section('upload.php');                // Media
   delete_admin_menu_section('link-manager.php');          // Links
   delete_admin_menu_section('edit-comments.php');         // Comments
   delete_admin_menu_section('edit.php?post_type=page');   // Pages
   delete_admin_menu_section('plugins.php');               // Plugins
   delete_admin_menu_section('themes.php');                // Appearance
   delete_admin_menu_section('users.php');                 // Users
   delete_admin_menu_section('tools.php');                 // Tools
   delete_admin_menu_section('options-general.php');       // Settings
 }}}

 This is definitely still an alpha; no hooks, no real code documentation,
 etc. but I wanted to get a working version up to get feedback.  Let me
 know your thoughts.

 -Mike

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


More information about the wp-trac mailing list