0

I need my users to be able to upload files to the media library and therefore need to somehow automatically set the user role to something other than the default "subscriber" when they register.

I know in Settings > General you can set the ‘New User Default Role’, however if I change this to a role that allows user uploads this gives access to the main media library. If they could upload to their own media library that would be great but I don’t want everyone seeing everyone elses files in the media library.

I am using Buddypress but can't find any documentation on this and so have installed the Members Plugin to see if this would help but I am still struggling to find out exactly how this would be implemented.

Any help would be greatly appreciated.

0

You might simply want to go to Settings > General. Here you can select the standard role a user gets, once he registers.

Select standard user role in WordPress

  • Sorry I should have been more specific. if I change this setting to say "Author" it does allow all new users to upload files. However, this gives access to everything in the media library and I dont want this to happen. If they could upload to their own media library that would be great but I dont want everyone seeing everyone elses files in the media library. – lea Apr 14 '15 at 12:11
0

I used the below code in the end. Hope someone finds this useful.

/* Display only user-uploaded files to each user in Media Library for file upload form*/

function user_restrict_media_library( $wp_query_obj ) {
    global $current_user, $pagenow;
    if( !is_a( $current_user, 'WP_User') )
        return;
    if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
        return;
    if( !current_user_can('manage_media_library') )
        $wp_query_obj->set('author', $current_user->ID );
    return;
}
add_action('pre_get_posts','user_restrict_media_library');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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