• Resolved karbou

    (@karbou)


    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.

    • This topic was modified 3 years, 12 months ago by karbou.
    • This topic was modified 3 years, 12 months ago by karbou.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Steve Burge

    (@stevejburge)

    Hi @karbou

    Thanks for using PublishPress Capabilities.

    Sorry, that question isn’t clear.

    We can’t help with custom code for Free users here on ww.wp.xz.cn, but we may be able to give you some guidance if the question is clearer.

    Thread Starter karbou

    (@karbou)

    Sorry if i’m not clear, i talking about the free version, but this bug must be the same with the pro version. The code isn’t a custom code, it’s a solution i can find to fix this, temporarily. But let me explain the probleme just with your code.

    My problem is this. I want to allow multiple role for a user.
    Case 1: Basic case
    – I create a user, i choose his role
    – After saved this user, i edit them and now i can add multiple role.

    Case 2 : PP_CAPABILITIES_ADD_USER_MULTI_ROLES defined
    – I define PP_CAPABILITIES_ADD_USER_MULTI_ROLES
    – I create a user and choose multiple role, contributor, editor
    – After i saved this user, his role is wrong, he’s currently administrator and i need to change this role on a second time, and after that, his role is good.

    So, Case 1 is OK, but i would like to save multiple role when i creating a user. So i use PP_CAPABILITIES_ADD_USER_MULTI_ROLES and case 2. But in this case, it’s not work perfectly. And in this case, for me, the problem is in includes/admin-load on line 355

    if (!empty($_REQUEST['_wpnonce']) && wp_verify_nonce(sanitize_key($_REQUEST['_wpnonce']), 'update-user_' . $userId) && isset($_POST['pp_roles']) && current_user_can('promote_users')) {

    Because in my request, i don’t have _wpnonce but this _wpnonce_create-user and obviously, when you check the, it’s not gonna work. And Publish Press can’t handle a case with _wpnonce_create-user

    For you, it’s a probleme with an another plugin or, Publish Press, should work with a request like _wpnonce_create-user ?

    Thaks a lot and i hope i am more clear

    Best regards
    Matt

    Plugin Author Steve Burge

    (@stevejburge)

    @karbou Thanks for the feedback.

    We’re going to improve this code in the next release of Capabilities and allow new users to have multiple roles.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Multiple role when creating user doesn’t work’ is closed to new replies.