I'm using the following code to let users only access their own media files, which works great;
add_filter( 'ajax_query_attachments_args', 'show_current_user_attachments', 10, 1 );
function show_current_user_attachments( $query = array() ) {
$user_id = get_current_user_id();
if( $user_id ) {
$query['author'] = $user_id;
}
return $query;
}
The trouble is, I want to do this for those with a user role lower than editor (So editors/admins only can see all the media files).
I have tried wrapping my function in this code but it didn't seem to work as intended, it just hangs whilst trying to load the media files (for any user), here's a screenshot of what it looks like.
Does anyone have any suggestions for solving this issue?
Thanks, Harry.