Skip to content

Instantly share code, notes, and snippets.

@ivanmendoza
Last active March 21, 2020 12:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanmendoza/5872302 to your computer and use it in GitHub Desktop.
Save ivanmendoza/5872302 to your computer and use it in GitHub Desktop.
Wordpress: Show only my attachments (current user) in media library. Admins can see everything. #php #wordpress
function filter_my_attachments( $wp_query ) {
if (is_admin() && ($wp_query->query_vars['post_type'] == 'attachment')) {
if ( !current_user_can( 'activate_plugins' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'filter_my_attachments' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment