Hooking into User Role changes
-
I am working on an existing plugin where we perform a modification to a
site_options
field whenever a user’s role changes.Right now we are tracking this by hooking into
user_profile_update_errors
andset_user_role
.user_profile_update_errors
hook will always catch edits to a user by firing at the end of the user update function, whether done on the user edit page or the profile page for a given user.set_user_role
hook will catch user role changes done through thewp-admin/users.php
listing page using the bulk role change drop down window.The issue is that the
set_user_role
will also occur shortly after theuser_profile_update_errors
does when editing a user via the edit page or profile page, resulting in our functionality being run twice when it only needs to run once in those cases.This may just be a regression on our part; I think we were using
user_profile_update_errors
to look for any issues with the updating the user before calling our own functionality.Is it safe to assume that we can just hook into
set_user_role
, and that this is the only place where the codebase will have updated a user role? Or is there another hook I need to look for in case there is a different place where the user’s role may have been updated?
- The topic ‘Hooking into User Role changes’ is closed to new replies.