0

I'm trying to hide a series of posts from my editors in the admin panel based on either custom post type or category (whichever is easiest).

I tried adding a function such as:

add_action( 'admin_menu', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
global $current_user;
get_currentuserinfo();
if($current_user->user_login = 'test2') {
    remove_submenu_page( 'edit.php?post_type=post', 'edit.php?post_format=image&post_type=post' );
        }
}

(In this snippet, I'm hiding it from one specific account) but it doesn't seem to work. Any ideas on how to do this?

3
  • What do you mean by a 'series of posts'? What are you trying to hide? Commented Jun 3, 2015 at 16:35
  • @StephenHarris Basically, I'd like to hide all posts filed under a certain category so that an editor can't edit it. Ex.: Editors won't be able to see anything filed under "Dogs" category
    – flipnotic
    Commented Jun 3, 2015 at 16:39
  • OK, your snippet appears to be attempting to remove a nonexistent admin submenu, In WordPress if a user can only edit a subset of posts they can still see the others. If that's sufficient I'd recommend looking into meta capability mapping: codex.wordpress.org/Function_Reference/map_meta_cap or a hook in current_user_can. Will try to furnish you with details unless you/someone posts an answer in the mean time. Commented Jun 3, 2015 at 16:50

1 Answer 1

0

Here a little function which takes care to hide (In admin) Custom Post Types.

function remove_from_admin_menu(){
    // Check capability (admin)
    if( current_user_can( 'edit_dashboard' )){
        //Do nothing
    } elseif ( current_user_can( 'moderate_comments' ) ) { // editor capability
        remove_menu_page( 'edit.php?post_type=cpt01' ); // add here your cpt name
        remove_menu_page( 'edit.php?post_type=cpt02' );             
        remove_menu_page( 'edit.php?post_type=cpt03' );
        // for submenu pages
        remove_submenu_page( 'edit.php?post_type=testimonials-widget', 'testimonialswidget_settings' ); 

    }
}
add_action('admin_menu', 'remove_from_admin_menu');

FYI:
About roles/capabilities see codex.
Remove menu page. (Codex)
Remove sub-menu page.(Codex)
Credits to michael-cannon for his sub-menu cpt sample.(Github)

To do the same kind of trick for categories you could take a look here because it is unclear to me if that is what you realy want to do that way. If yes, then the credits should go to him and not to me :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.