Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sokratisg
Created February 21, 2014 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sokratisg/9144896 to your computer and use it in GitHub Desktop.
Save sokratisg/9144896 to your computer and use it in GitHub Desktop.
WordPress - Restrict Media access per user
/* Restrict users viewing their own attachments */
add_filter('pre_get_posts', 'restrict_media');
function restrict_media($arg) {
global $user_ID;
if ( current_user_can('editor') ) { // Disable this to apply on all roles
if ($arg->query['post_type'] == 'attachment' && is_admin()) {
$arg->query['author'] = $user_ID;
$arg->query_vars['author'] = $user_ID;
}
}
return $arg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment