Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Php 如何在注册时添加多个角色?_Php_Wordpress - Fatal编程技术网

Php 如何在注册时添加多个角色?

Php 如何在注册时添加多个角色?,php,wordpress,Php,Wordpress,我正在尝试在注册时向用户添加2个角色。 角色1-两个默认、已预设的角色之一。 角色2-在注册时为每个用户单独生成 仅分配默认角色时-分配没有问题。 当我添加动态生成的角色时,它只分配这个角色,缺少默认角色 $user = wp_insert_user( $userdata ); $getuser = new WP_User($user); $getuser->set_role('profile_1'); add_role( 'user-ID'.$

我正在尝试在注册时向用户添加2个角色。 角色1-两个默认、已预设的角色之一。 角色2-在注册时为每个用户单独生成

仅分配默认角色时-分配没有问题。 当我添加动态生成的角色时,它只分配这个角色,缺少默认角色

    $user = wp_insert_user( $userdata );
    $getuser = new WP_User($user); 
    $getuser->set_role('profile_1');
    add_role( 
    'user-ID'.$user, 
    __( 'user-ID'.$user, 'wordpress-66604-809452.cloudwaysapps.com' ), 
    array(
        'read' => true,
        'edit_posts' => true,
    ));
    $getuser->set_role('user-ID'.$user);

从我阅读的内容来看,set_role删除了角色,只分配了一个新的角色,就像您描述的那样

设定角色 设置角色($role) 设置用户的角色

这将删除用户以前的角色,并为用户分配新角色。您可以将角色设置为空字符串,它将从用户中删除所有角色

参数 角色(字符串)-角色名称。 退换商品 没有什么 自从 2.0.0 相关行动

添加角色 添加角色($role) 向用户添加角色

使用功能和角色更新用户的元数据选项

参数 角色(字符串)-角色名称