Skip to content

Instantly share code, notes, and snippets.

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 oliviercardoen/aea1830c4774d78bf385 to your computer and use it in GitHub Desktop.
Save oliviercardoen/aea1830c4774d78bf385 to your computer and use it in GitHub Desktop.
Prevent Authors from seeing other authors media files
// Prevent Authors from seeing other authors media files
add_filter('parse_query', 'my_parse_query' );
function my_parse_query( $wp_query ) {
// Only applicable for Media Library && Media Upload Dialog
if (! preg_match('/wp-admin\/(?:upload|media-upload|admin-ajax).php/', $_SERVER['REQUEST_URI']) ) {
return;
}
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ($user_role && is_string($user_role) && strtolower($user_role)==='author') {
$wp_query->set( 'author', $current_user->id );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment