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.

3 Answers 3

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

1
  • 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
    Commented Apr 14, 2015 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');
0

I have a solution that I believe would work (I tested it with the most recent version of Wordpress and Buddypress which are 6.5.4 and 12.5.1 respectively).

There is a code on this website: https://buddydev.com/assign-user-roles-based-on-buddypress-profile-field-data-on-user-registration/

It allows you to assign a user role that you set, to users that register with the default Buddypress registration form. the way it works is it conditionally assigns a role based on a field in the registration form. Instructions are on the page.

Now, no matter what your default user role is, anyone that registers with the buddypress registration form will be assigned the role you set in the code.

Then, if you use the Mediapress plugin (free from the same developer as the website above), your users can upload media to their account. To make the media private, after you install the Mediapress plugin, in the settings under "Enabled Media/Gallery Statuses", select Private and then users will be able upload media that are private.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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