Skip to content

Instantly share code, notes, and snippets.

@jfcode
Created March 8, 2014 00:09
Show Gist options
  • Save jfcode/9422915 to your computer and use it in GitHub Desktop.
Save jfcode/9422915 to your computer and use it in GitHub Desktop.
/**
* Allow access to own content only
*/
function my_authored_content($query) {
//get current user info to see if they are allowed to access ANY posts and pages
$current_user = wp_get_current_user();
// set current user to $is_user
$is_user = $current_user->user_login;
//if is admin or 'is_user' does not equal #username
if (!current_user_can('manage_options')){
//if in the admin panel
if($query->is_admin) {
global $user_ID;
$query->set('author', $user_ID);
}
return $query;
}
return $query;
}
add_filter('pre_get_posts', 'my_authored_content');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment