Created
February 21, 2014 22:26
-
-
Save sokratisg/9144896 to your computer and use it in GitHub Desktop.
WordPress - Restrict Media access per user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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