Skip to content

Instantly share code, notes, and snippets.

@itzikbenh
Created July 31, 2017 22:00
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 itzikbenh/81ca6b18a5341baf9ef7c2dbaf9670d5 to your computer and use it in GitHub Desktop.
Save itzikbenh/81ca6b18a5341baf9ef7c2dbaf9670d5 to your computer and use it in GitHub Desktop.
WordPress - show current user attachments
<?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