我有一个网站,使用愿望清单会员来控制注册和 BBPress。
我可以在注册论坛时为用户分配角色。但是,我无法为他们分配网站角色,WordPress 使用该角色来允许用户访问他们的个人资料: http: //www.domainname.com/wp-admin/profile
如果用户希望更改密码或上传图片等,我可以如何允许他们访问他们的个人资料。
我已在 WordPress 中将新用户的默认角色设置为“观众”,但当我创建新用户时,未设置任何用户角色。
谷歌仍然是你的朋友。
来自 EarnestoDev(设置默认角色):
// Hijack the option, the role will follow!
add_filter('pre_option_default_role', function($default_role){
// You can also add conditional tags here and return whatever
return 'subscriber'; // This is changed
return $default_role; // This allows default
});
Run Code Online (Sandbox Code Playgroud)
Fromt t310s(更改用户角色):
// NOTE: Of course change 3 to the appropriate user ID
$u = new WP_User( 3 );
// Remove role
$u->remove_role( 'subscriber' );
// Add role
$u->add_role( 'editor' );
Run Code Online (Sandbox Code Playgroud)
https://wordpress.stackexchange.com/questions/4725/how-to-change-a-users-role
来自 mike23(更改用户角色):
$my_user = new WP_User( $user_id );
$my_user->set_role( "editor" );
Run Code Online (Sandbox Code Playgroud)
https://wordpress.stackexchange.com/questions/22962/how-to-programmatically-add-a-user-to-a-role
来自 Dan Gilmore(在多站点上更改角色):
//Short version
$user_id = $result['user_id'];
$user = new WP_User($user_id);
$user->remove_role('owner');
$user->add_role('administrator');
Run Code Online (Sandbox Code Playgroud)
http://dangilmore.com/blog/2011/10/19/programatically-changing-users-roles-in-wordpress-multisite/
| 归档时间: |
|
| 查看次数: |
4586 次 |
| 最近记录: |