Sometime you want to restrict parts of your plugin using additional permissions management, since this is quite easy, hiding menu items can be a bit tricky – you need to know root menu url, and submenu url. So where to get them? Somewhere just put this:
1 2 |
global $submenu; print_r($submenu); |
so you will get list of all available items (wordpress is calling them “menu slugs”) like this:
[edit.php?post_type=page] => Array ( [5] => Array ( [0] => All Pages [1] => edit_pages [2] => edit.php?post_type=page ) [10] => Array ( [0] => Add New [1] => edit_pages [2] => post-new.php?post_type=page ) )
and we have all stuff needed – array key is menu slug (root menu hook), array item with key 2 is sub menu slug, so to hide it just use:
1 |
remove_submenu_page('edit.php?post_type=page', 'post-new.php?post_type=page'); |
and put this along with permissions checking in:
1 2 3 4 |
add_action('admin_init', 'acRemoveMenuPages'); function acRemoveMenuPages() { remove_submenu_page('edit.php?post_type=page', 'post-new.php?post_type=page'); } |
this way at each admin’s init your permission will be checked, and unnecessary items will be removed.