1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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 ; } |