[wp-trac] [WordPress Trac] #14666: Create reliable way to remove admin menus and submenus
WordPress Trac
wp-trac at lists.automattic.com
Tue Aug 31 04:51:55 UTC 2010
#14666: Create reliable way to remove admin menus and submenus
----------------------------+-----------------------------------------------
Reporter: markjaquith | Owner:
Type: task (blessed) | Status: new
Priority: high | Milestone: 3.1
Component: Administration | Version:
Severity: normal | Keywords: has-patch
----------------------------+-----------------------------------------------
Comment(by mikeschinkel):
Here is almost a full API I've written for managing the admin menus:
https://gist.github.com/792b7aa5b695d1092520
Here are some examples of how they would be used.
{{{
<?php
require_once('wp-admin-menu-classes.php');
add_action('admin_menu','my_admin_menu');
function my_admin_menu() {
swap_admin_menu_sections('Pages','Posts'); // Swap
location of Posts Section with Pages Section
rename_admin_menu_section('Media','Photos & Video'); // Rename
Media Section to "Photos & Video"
delete_admin_menu_section('Links'); // Get rid
of Links Section
$movie_tags_item_array = get_admin_menu_item_array('Movies','Movie
Tags'); // Save off the Movie Tags Menu
update_admin_menu_section('Movies',array( // Rename
two Movie Menu Items and Delete the Movie Tags Item
array('rename-item','item'=>'Movies','new_title'=>'List
Movies'),
array('rename-item','item'=>'Add New','new_title'=>'Add
Movie'),
array('delete-item','item'=>'Movie Tags'),
));
copy_admin_menu_item('Movies',array('Actors','Add New')); // Copy
the 'Add New' over from Actors
renamed_admin_menu_item('Movies','Add New','Add Actor'); //
Rename copied Actor 'Add New' to 'Add Actor
add_admin_menu_item('Movies',array( //
(Another way to get a 'Add Actor' Link to a section.)
'title' => 'Alt Add Actor ',
'slug' => 'post-new.php?post_type=actor',
), array(// Add Back the Movie Tags at the end.
'where'=>'end'
));
add_admin_menu_item('Movies',$movie_tags_item_array,array(// Add
Back the Movie Tags at the end.
'where'=>'end'
));
delete_admin_menu_section('Actors'); //
Finally just get rid of the actors section
}
}}}
I designed the objects to be wrappers around the current global variables
as much as possible and not attempt to contain the values themselves so as
to be fully 100% compatible with existing code. That design decision made
for some slightly unusual usage patterns; i.e. that the list of menu items
instances can get out of sync from the $submenu array so the classes
automatically refresh themselves until refresh is paused using
`pause_admin_menu_section_refresh()`.
Also, the objects themselves don't contain the menu section or item data;
those are still contained in the global arrays and as such almost all
access to data is made through method calls instead of by reading
properties.
I had also planned to implement streamlined alternative wrappers to the
existing `add_submenu_page()` to use `$args` instead of positional
parameters but haven't done it yet. I'd be happy to prioritize doing that
if there is interest.
I look forward to your feedback. I'd love to see these used, but I'm also
happy to see them discussed or changed significantly if we can
collectively make them better.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14666#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list