Last active
March 21, 2020 12:39
-
-
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
This file contains hidden or 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
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