[wp-hackers] Restricting Users to View Only their OWN Media Library Items

aw2 aw4all at gmail.com
Tue Nov 23 14:32:48 UTC 2010


I have a question:

I want users to be able to upload photos using 'upload_files' but in their
profile page. The Media Library shows every image that's been uploaded by every
user. How can I filter that so that they can ONLY view the images THEY uploaded?

I've found an article here:
http://wordpress.stackexchange.com/questions/1482/restricting-users-to-view-only-media-library-items-they-have-uploaded/4412#4412


But I don't know where to put this code:
____________________

add_action('pre_get_posts','users_own_attachments');
function users_own_attachments( $wp_query_obj ) {

    global $current_user, $pagenow;

    if( !is_a( $current_user, 'WP_User') )
        return;

    if( 'upload.php' != $pagenow )
        return;

    if( !current_user_can('delete_pages') )
        $wp_query_obj->set('author', $current_user->id );

    return;
}


____________________


Anybody an idea?
This would be of great help for me.

Thanks in advance,

Arthur



More information about the wp-hackers mailing list