Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
Created May 30, 2021 09:11
Show Gist options
  • Save ofernandolopes/cb02d02905513ef531a1a0281c94a5cb to your computer and use it in GitHub Desktop.
Save ofernandolopes/cb02d02905513ef531a1a0281c94a5cb to your computer and use it in GitHub Desktop.
Restricting Authors to View Only Posts They Created
//Restricting Authors to View Only Posts They Created
//https://www.isitwp.com/restricting-authors-to-view-only-posts-they-created/
function posts_for_current_author($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( 'manage_options' ) ) {
global $user_ID;
$query->set('author', $user_ID );
}
return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment