Multiple role when creating user doesn’t work
-
I find something strange.
I Have a website, when i create user, i can allow multiple, but doesn’t work when the user is create, but working when i do the same thing for an existing user. So it’s not working when user create but ok with existing user.
In your code, on /includes/admin-load.php you have this
add_action('profile_update', [$this, 'action_profile_update'], 10, 2); if (is_multisite()) { add_action('add_user_to_blog', [$this, 'action_profile_update'], 9); } else { add_action('user_register', [$this, 'action_profile_update'], 9); }So when a user is created or is updated, we use action_profile_update
And on this function we have this :
// Check if we need to update the user's roles, allowing to set multiple roles. if (!empty($_REQUEST['_wpnonce']) && wp_verify_nonce(sanitize_key($_REQUEST['_wpnonce']), 'update-user_' . $userId) && isset($_POST['pp_roles']) && current_user_can('promote_users')) {in my case, i don’t have $_REQUEST[‘_wpnonce’] but this $_REQUEST[‘_wpnonce_create-user’], this can work. And i’m not sure but the seconde condition ( wp_verify_nonce(sanitize_key($_REQUEST[‘_wpnonce’]), ‘update-user_’ . $userId) ) can working when user is creating.
If i replace this
if (!empty($_REQUEST['_wpnonce']) && wp_verify_nonce(sanitize_key($_REQUEST['_wpnonce']), 'update-user_' . $userId) && isset($_POST['pp_roles']) && current_user_can('promote_users')) {by this
if (isset($_POST['pp_roles']) && current_user_can('promote_users')) {but it’s obviously not the good solution
Thanks for your time.
The topic ‘Multiple role when creating user doesn’t work’ is closed to new replies.