I would like to hide Pages and Comments from the editor.
I tried to override them with my custom types' menu_position but it doesn't work in WordPress 3.7.1 any more.
I found another way: removing the entries from admin menu by altering the global $menu variable on menu_order filter. Unfortunately it produces errors in menu.php: array_flip() gets passed a null.
I'm guessing that WordPress assumes that default values are still there.
Is there some way of filtering the menu entries when they are rendered? Even better: is there a way of setting the default post types public option to false?
class RemoveAdminMenuItems {
/**
* List of values used for key identification
*
* @var array
*/
public $remove_keys = array();
/**
* List of values used for key identification. Identified keys will be removed.
*
* @param array $remove_keys
*/
public function __construct($remove_keys)
{
$this->remove_keys = $remove_keys;
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', array($this, 'reconstruct_menu'));
}
/**
* Method modifies the admin menu before it gets rendered.
*
* @global array $menu
*/
public function reconstruct_menu() {
global $menu;
foreach ($menu as $menu_key => $menu_value) {
foreach ($this->remove_keys as $remove_key) {
$key = array_search($remove_key, $menu_value);
if ($key) {
unset($menu[$menu_key]);
}
}
}
}
}