Created
July 31, 2017 22:00
-
-
Save itzikbenh/81ca6b18a5341baf9ef7c2dbaf9670d5 to your computer and use it in GitHub Desktop.
WordPress - show current user attachments
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
<?php | |
//Besides administrator show only the current user media files | |
function show_current_user_attachments( $query ) { | |
if( ! current_user_can( 'manage_options' ) ) { | |
$user_id = get_current_user_id(); | |
if ( $user_id ) { | |
$query['author'] = $user_id; | |
} | |
return $query; | |
} | |
return $query; | |
} | |
add_filter( 'ajax_query_attachments_args', 'show_current_user_attachments' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment