I want to hide / remove a particular menu item from +New menu on admin menu bar based on specific user role. I referred to this post and tried what is suggested here but for me it did not work.
I have a user role fuel-surcharge-editor, which should not get access to Weather Alert content type (please see screenshot).
Both Fuel Surcharge and Weather Alert are custom post types. So from +New menu both are pointing to same location:
http://vagrant.local/wp/wp-admin/post-new.php?post_type=fuel-surcharge
, with a different post_type.
I tried the following:
function remove_new_content_items(){
if(current_user_can('fuel-surcharge-editor')) {
global $wp_admin_bar;
$wp_admin_bar->remove_menu( 'post-new', 'weather_alert' );
}
}
add_action( 'wp_before_admin_bar_render', 'remove_new_content_items', 0 );
I also tried
$wp_admin_bar->remove_menu('post-new.php?post_type=weather_alert');
and $wp_admin_bar->remove_menu('post-new.php', 'weather_alert');
but none worked. How can I do this?
remove_node
, notremove_menu
. Reference: codex.wordpress.org/Function_Reference/remove_node.