I've been researching this all day and haven't come up with much results.
I want to restrict who can see my Custom Post Types by User Level (or some other way). So if the person logged in is not an 'administrator' the added Custom Post Types are not visible to them.
Here is part of a Custom Post Type that I have:
add_action('init', 'portfolio_register');
function portfolio_register() {
$labels = array(
'name' => _x('Case Studies', 'post type general name'),
'singular_name' => _x('Case Study Item', 'post type singular name'),
'add_new' => _x('Add New', 'portfolio item'),
'add_new_item' => __('Add New Case Study Item'),
'edit_item' => __('Edit Case Study Item'),
'new_item' => __('New Case Study Item'),
'view_item' => __('View Case Study Item'),
'search_items' => __('Search Case Studies'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
/*'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',*/
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail')
);
register_post_type( 'portfolio' , $args );
}
And here are the potential solutions that I found that don't work for the Custom Post Type menu removal:
function remove_menus()
{
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login != 'admin')
{
$restricted = array(__('Posts'),
__('Media'),
__('Links'),
__('Pages'),
__('Comments'),
__('Appearance'),
__('Plugins'),
__('Users'),
__('Tools'),
__('Settings')
);
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}// end while
}// end if
}
add_action('admin_menu', 'remove_menus');
The above works to remove the default menu items but I couldn't get it to remove a Custom Post Type menu. Plus it is username specific, which is ok if I could add more than one user to it.
global $user_login;
get_currentuserinfo();
if (!current_user_can('update_plugins')) {
.......
}
The above didn't work at all.
Thanks.