I've been struggling with this problem for a good while now, and just can't seem to get it work.
I have
When an author is uploading a photo into a post, the author can see other authors' uploads in the media upload dialog. I don't want this to happen. I want authors to see only their own uploads in the media upload dialog.
I can get this to work, with this:
// Prevent Authors from seeing other authors media files
add_filter('parse_query', 'my_parse_query' );
function my_parse_query( $wp_query ) {
// Only applicable for Media Library && Media Upload Dialog
if (! preg_match('/wp-admin\/(?:upload|media-upload|admin-ajax).php/', $_SERVER['REQUEST_URI']) ) {
return;
}
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ($user_role && is_string($user_role) && strtolower($user_role)==='author') {
$wp_query->set( 'author', $current_user->id );
}
}
But in turn, this prevents the custom fields from working in the user profiles. This is because ACF uses the admin-ajax to add the fields to an edit screen, but if I remove the admin-ajax part from the function above, it starts to show other authors media again, so it's back to square one.
I've tried to use dozens of different methods (1)(2)(3) that I've found from the internet, but none of them work due to the new wordpress 3.5 media upload dialog and/or ACF.
Any idea how to prevent authors from seeing other authors media, while using ACF?
Just add
if($wp_query->query_vars['post_type']!=='attachment'){return;}
It will work. Regards.