• Resolved mikejandreau

    (@mikejandreau)


    I’m using the WP Webhooks plugin, specifically with the User Updated webhook.

    When I change the Role of a user with Members activated, the User Old Data Roles 0 passed to the webhook is incorrect. It shows the new role and not the old role.

    I’m trying to run automation when a role changes and this is blocking that work.

    This video shows the issue: https://share.cleanshot.com/t4ShZ2Cx

    When I disable Members, the correct old role is sent in the webhook. WP Webhooks says this is an issue with Members generating the changed JSON that they’re readying to send via webhook.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter mikejandreau

    (@mikejandreau)

    Looks like this only happens when you have “Allow users to have multiple roles” enabled.

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @mikejandreau,

    Thanks for reaching out Members Support Team!

    I just checked with dev team and kindly find the reply below:

    If the user has more than one role, then the roles would be looped through which would update the user each time. So the old data would be the last iteration.

    Regards,

    Thread Starter mikejandreau

    (@mikejandreau)

    That’s not what I’m seeing. I’m assigning a single role and that new role is being sent as the old role in the payload.

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @mikejandreau,

    Could you please share steps for how to repoduce the issue from my end so I can replicate it and check it with dev team?

    Regards,

    Thread Starter mikejandreau

    (@mikejandreau)

    Enable the multiple roles setting.
    Setup a webhook that triggers when a User profile is updated — I’m using WP Webhooks free
    Modify a user role and remove their old role
    Add a new role
    View the webhook response and see the User Old Data Roles 0 shows as the new role.

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @mikejandreau,

    I checked things with dev team and kindly find the reply below:

    I investigated this issue from Members and I believe that the cause of this is the hook priority. We’re using the?profile_update?action hook with the default priority set to 10 to add or remove roles. This hook accepts?$user_id?and?$old_user_data?arguments where?$old_user_data?is WP_User object. If the webhook listens to this action and uses default priority 10 or more, the roles in the?$old_user_data?object will run after Members update the user role, which would be the new roles the user updates. To get old roles before Members update user roles, you must use a priority lower than 10.

    The?$old_user_data?is user object so if you fetch user data after our code runs you will get updated data with new role. When I used the hook like this:?add_action('profile_update', 'custom_func', 9, 2)?I received old role for user, but when I used this hook:?add_action('profile_update', 'custom_func', 10, 2)?with higher priority, it returned new role.

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.