admin管理员组文章数量:1122846
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.
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.
Share Improve this question edited Apr 14, 2015 at 12:20 lea asked Apr 14, 2015 at 11:10 lealea 234 bronze badges3 Answers
Reset to default 0You might simply want to go to Settings > General
. Here you can select the standard role a user gets, once he registers.
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');
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.
本文标签: buddypressSet user role on registration so can upload file to own media library area
版权声明:本文标题:buddypress - Set user role on registration so can upload file to own media library area 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303198a1931800.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论