Allow ONLY ACESS to Images a User has uploaded
add_filter( 'ajax_query_attachments_args', 'filter_query_attachments_args' );
function filter_query_attachments_args( $query ) {
$current_user = wp_get_current_user();
// 1. Only users with access
if ( ! current_user_can( 'upload_files' ) ) {
wp_send_json_error();
}
// 2. No manipulation for admins.
// After all they have access to all images.
if ( current_user_can( 'administrator' ) ) {
return $query;
}
// 10. Filter to display only the user uploaded image
$query['author'] = $current_user->ID;
return $query;
}