Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress注册主题“我的登录”时的用户角色_Wordpress_User Registration - Fatal编程技术网

Wordpress注册主题“我的登录”时的用户角色

Wordpress注册主题“我的登录”时的用户角色,wordpress,user-registration,Wordpress,User Registration,我正在使用“我的登录主题”进行注册。 要在注册页面中添加单选按钮字段。 我希望用户通过使用单选按钮注册role-1或role-2。通过使用此插件完成此操作 这不需要插件,您可以在theme-my-login-custom.php中轻松使用下面的函数 假设您的默认用户角色是subscribe function tml_new_user_registered( $user_id ) { $u = new WP_User( $user_id ); if($_REQUEST['radio_but

我正在使用“我的登录主题”进行注册。 要在注册页面中添加单选按钮字段。
我希望用户通过使用单选按钮注册role-1或role-2。

通过使用此插件完成此操作


这不需要插件,您可以在theme-my-login-custom.php中轻松使用下面的函数

假设您的默认用户角色是subscribe

function tml_new_user_registered( $user_id ) 
{

$u = new WP_User(  $user_id );

if($_REQUEST['radio_button_name']=='value1'){

    // Remove role which is your default 
    $u->remove_role( 'subscriber' );//remove default role

    // Add role
    $u->add_role( 'role1' );
}else
{
    // Remove role
    $u->remove_role( 'subscriber' );

    // Add role
    $u->add_role( 'role2' );

}
}
add_action( 'tml_new_user_registered', 'tml_new_user_registered' );

你试过什么吗?一些代码?是的,在register-form.php中添加了复选框,但给定的值不会在数据库中更新。