Show Authors Their Own Posts in Admin

You can redirect the normal All Posts pages to a version that only displays the current user’s posts. (Similar to this post). Users will not be able to get back to the ‘all’ view, as in the other sample. Users are not prevented from changing the author ID in the URL and viewing another user’s posts.

add_action( 'load-edit.php', 'posts_for_current_author' );
function posts_for_current_author() {
	global $user_ID;

	/*if current user is an 'administrator' do nothing*/
	//if ( current_user_can( 'add_users' ) ) return;

	/*if current user is an 'administrator' or 'editor' do nothing*/
	//if ( current_user_can( 'edit_others_pages' ) ) return;

	if ( ! isset( $_GET['author'] ) ) {
		wp_redirect( add_query_arg( 'author', $user_ID ) );
		exit;
	}

}

Default All Posts to the Current User’s Posts

When clicking on All Posts in the main menu, Administrators and Editors will normall see all posts. Use this to change the default view to the user’s own posts. See comments to limit the change to users of a certain roll.

add_action( 'admin_menu', 'show_users_posts_by_default' );
function show_users_posts_by_default() {

	/*if current user is an 'administrator' do nothing*/
	//if ( current_user_can( 'add_users' ) ) return;

	/*if current user is an 'administrator' or 'editor' do nothing*/
	//if ( current_user_can( 'edit_others_pages' ) ) return;

	global $submenu, $user_ID;
	$submenu['edit.php'][5][2] = 'edit.php?author='. $user_ID;
}

Remove Library Tab from Post-Side Media Pop-Up

I’m working on a plugin right now where I’m having to hide or limit a lot of features depending on the current user’s capabilities. Among those limitations is media uploading and editing access. I’m using this snippet to hide the Media Library tab from the Add an Image pop-up on the edit post page.

add_filter('media_upload_tabs','no_library_tab');
function no_library_tab($tabs) {
    if (!current_user_can('promote_users')) { 
        unset($tabs['library']);
    }
    return $tabs;
}

Customize Post Views

Depending on your role and capabilities, you may see something like this on your posts/pages screen “mine () | all () | published ()”

Those items are editable.

In my case, I wanted ‘authors’ to only have access to the ‘mine’ list, since ‘mine’ is default, I wanted to remove the views list entirely, but only for non-administrators.

add_filter('views_edit-post', 'only_show_mine');
function only_show_mine( $views ) {
    if (!current_user_can('promote_users')) {
        $views = array(); //remove all options
        //unset($views['all']);
        //unset($views['publish']);
    }
return $views;
}