set role specific screen options in post summary page

I need to set different screen options(title,author,categories…) in post summary page for non admin users(editor,author..) which can not be altered by user him/her self.

Example :
enter image description here

This is the administrator view and I need to hide View Count & SEO columns for non admin users.

Does anybody have an idea, how to achieve this ?

3 Answers
3

I assume, you need something like editors can’t see the category column or something like this.

This snippet might help you:

/** Remove "Options"-Panel, when User is not admin **/
add_filter( 'manage_posts_columns', 'change_columns_for_user', 10, 2 );
function change_columns_for_user( $columns, $post_type ){
    if( 'post' != $post_type )
        return $columns;

    if( current_user_can( 'manage_options' ) )
        return $columns;
    else{
        //Remove Categories
        unset( $columns['categories'] );
        //Remove Tags
        unset( $columns['tags'] );
        //Remove Comments
        unset( $columns['comments'] );
        return $columns;
    }

}

In this snippet we unset some columns if the user cant managa options. You know the options panel on the top: In this case, they wouldn’t even show up in this panel no more.

But It should not be able to change from the particular user login.

If you still want to disable the options panel for some users, have a look into this snippet:

/** Remove "Options"-Panel, when User is not admin **/
add_filter( 'screen_options_show_screen', 'remove_screen_settings', 10, 2 );
function remove_screen_settings( $show_screen, $class ){
    if( 'edit-post' != $class->id )
        return $show_screen;

    if( ! current_user_can( 'manage_options' ) )
        return false;
    else
        return true;
}

Leave a Comment