Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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' ) ) {
        unset($tabs['library']);
        return $tabs;
    }    }
add_filter('media_upload_tabs','remove_medialibrary_tab');

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.

share|improve this question
    
Check out this posting, then this plugin: wordpress.org/support/topic/… wordpress.org/support/view/plugin-reviews/… Seems to fix it in WP 3.5 –  user25716 Jan 8 '13 at 2:47

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 ware 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!

share|improve this answer
    
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 at 1:26
    
You're welcome, @Jake –  timocouckuyt Dec 8 at 14:23

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

share|improve this answer

protected by Community Nov 1 '13 at 16:56

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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