Looks like this only happens when you have “Allow users to have multiple roles” enabled.
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,
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.
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,
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.
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,