Wordpress - Prevent Authors from viewing each others Posts

If you want to prevent a user with the "Author" role to view other users' posts in the overview screen (they won't be able to view the details anyway), you can add an extra filter on the author:

add_action( 'load-edit.php', 'wpse14230_load_edit' );
function wpse14230_load_edit()
{
    add_action( 'request', 'wpse14230_request' );
}

function wpse14230_request( $query_vars )
{
    if ( ! current_user_can( $GLOBALS['post_type_object']->cap->edit_others_posts ) ) {
        $query_vars['author'] = get_current_user_id();
    }
    return $query_vars;
}

The little links above the post table ("Mine", "All", "Drafts") are less useful now, you can also remove them:

add_filter( 'views_edit-post', 'wpse14230_views_edit_post' );
function wpse14230_views_edit_post( $views )
{
    return array();
}

Tags:

Posts

Author