Skip to content

Instantly share code, notes, and snippets.

@ataylorme
Created November 17, 2012 22:46
Show Gist options
  • Save ataylorme/4100947 to your computer and use it in GitHub Desktop.
Save ataylorme/4100947 to your computer and use it in GitHub Desktop.
Restrict user posts
/* ===== START RESTRICT USER POSTS ====== */
function restricted_posts_for_current_author($query) {
global $user_ID;
if($query->is_admin && $user_ID !== 10 )
$query->set('author', -10);
unset($user_level);
return $query;
}
add_filter('pre_get_posts', 'restricted_posts_for_current_author');
function restricted_save_post($post_id){
global $post;
$message = 'If you want to edit my posts you need to ask first.';
if( get_current_user_id() !== 10 AND $post->post_author == 10 )
exit($message);
}
add_action( 'save_post', 'restricted_save_post');
/* ===== END RESTRICT USER POSTS ====== */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment