自动将具有空用户角色的成员替换为另一个角色
Automatically replace members with an empty user role with another role
我想将所有用户角色为空的成员移动到默认角色。有相关代码吗?
是的,首先你可以使用wp_get_users_with_no_role()
function to get all users with no role (This function returns user ids). Then you can pass that user_id $u = new WP_User( $user_id );
and set the new role $u->set_role( 'subscriber' );
. Here you can also find list of user Roles and Capabilities。
将其粘贴到您的主题 functions.php
文件中。
add_action('init', function(){
$users = wp_get_users_with_no_role();
if( !empty($users) ){
foreach($users as $user_id) {
$u = new WP_User( $user_id );
$u->set_role( 'subscriber' );
}
}
}, 10);
此代码未经测试,如果有效请告诉我们!
我想将所有用户角色为空的成员移动到默认角色。有相关代码吗?
是的,首先你可以使用wp_get_users_with_no_role()
function to get all users with no role (This function returns user ids). Then you can pass that user_id $u = new WP_User( $user_id );
and set the new role $u->set_role( 'subscriber' );
. Here you can also find list of user Roles and Capabilities。
将其粘贴到您的主题 functions.php
文件中。
add_action('init', function(){
$users = wp_get_users_with_no_role();
if( !empty($users) ){
foreach($users as $user_id) {
$u = new WP_User( $user_id );
$u->set_role( 'subscriber' );
}
}
}, 10);
此代码未经测试,如果有效请告诉我们!