As an admin I really like the features and functionality of the WordPress 3.5 media manager.

With a multi-user site however all users can see all images in the media library - whether uploaded by them or not. Previously a functions.php script could mask / restrict access.
For example:

// Hide Media Library tab Tab from each individual agent
function remove_medialibrary_tab($tabs) {
    if ( !current_user_can( 'update_core' ) ) {
        return $tabs;
    }    }

This no longer works as I believe the media library is now JavaScript based.

The question: how can I now hide or mask the WordPress 3.5 media library images from users that did not upload the images in the library? I want users to only see their own images or to only see the images they uploaded to this specific post or page.

The current structure and design is great for the likes of a newspaper that wants to share images across their entire organization of users - but not so good for sites that have needs for stricter controls with independent multi-user access.

I am not a coder - or am an amateur at best - but it occurs to me that options might include: masking or coding out all attachment filters in the new 3.5 library dropdown menu only leaving the "uploaded to this page" in the list - or - possibly a switch that would allow admins to switch visibility on or off to the media library images for general users.

Any guidance or direction on this would be appreciated.


2 Answers 2


To let the current users only view his/her uploaded attachments, add the following code to your themes actions:

add_filter( 'posts_where', 'devplus_wpquery_where' );
function devplus_wpquery_where( $where ){
    global $current_user;

    if( is_user_logged_in() ){
         // logged in user, but are we viewing the library?
         if( isset( $_POST['action'] ) && ( $_POST['action'] == 'query-attachments' ) ){
            // here you can add some extra logic if you'd want to.
            $where .= ' AND post_author='.$current_user->data->ID;

    return $where;

Hope this helps!

  • Tried so many options for this to work on the front end and with ACF. This is the first one that works for me. A great solution! Thanks!
    – Jake
    Feb 1, 2014 at 1:26
  • I was struggling to limit the Media Uploader for a frontend ACF form to only display user-uploaded attachments. Didn't know about posts_where - This seems to be working great! Thanks for posting.
    – derekshirk
    Mar 16, 2016 at 18:01

Thanks @timocouckuyt, that works fine but you also need this one for the /wp-admin/upload.php link :

add_filter('pre_get_posts', 'hide_posts_media_by_other');
function hide_posts_media_by_other($query) {
global $pagenow;

if( 'upload.php' != $pagenow || !$query->is_admin ){
    return $query;

if( !current_user_can( 'manage_options' ) ) {
    global $user_ID;
    $query->set('author', $user_ID );
return $query;

For complete tutorial to hide media and posts from other users please check this tutorial : http://jeffreycarandang.com/tutorials/hide-wordpress-posts-media-uploaded-users/

Cheers, phpbits

  • The link in this answer is broken @JeffreyCarandang , would you perhaps be able to fix it?
    – osxconor
    Oct 12, 2021 at 9:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.