You can use the set_user_role hook, that will only fire when the user role changes:
add_action( 'set_user_role', function( $user_id, $role, $old_roles )
{
// Your code ...
}, 10, 3 );
If you want to restrict this to a profile update, you can use:
add_action( 'set_user_role', function( $user_id )
{
add_action( 'profile_update', function( $user_id )
{
// Your code here ...
} );
} );
Related Posts:
- If the current user is an administrator or editor
- Editor can create any new user except administrator
- Remove Ability for Other Users to View Administrator in User List?
- Find out if logged in user is not subscriber
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- Allowing users to edit only their page and nobody else’s
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Hide Admin Menu for Specific User ID who has administrator Role
- Show admin bar only for some USERS roles
- Disable delete user
- Grouping users under parent user
- How to update user role without logout
- How to check user role without using current_user_can()
- Extending WP_User class and using this sub-class during the whole lifecycle
- Do not allow users to create new posts and pages
- How to enable the theme editor cap for an editor role?
- How to assign capabilities to user NOT to User Role
- How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
- How to stop a user from updating the post date
- BuddyPress | Check if user is in current group [closed]
- WordPress edit_user_profile_update update secondary role
- How do I properly format the user_role array?
- How to customize wp_signon()
- Is there a simple way to manage capabilities per user?
- Is it possible to get a user with just the password field?
- How to get the Role Name of the current user? (WordPress)
- Redirect after login based on user role (custom login page)
- set_role has no effect
- Can I create users that have access to *some* other users posts instead of all other users posts?
- Users roles, make a page belonging to multiple users
- Tagging users in WordPress
- Redirect after users complete profile form
- How do I list in the backend all users that were assigned to a custom role?
- How to add local users to wordpress without email password?
- Getting users by specific capability, not role
- add_cap not working with Shop Manager role
- Managing Users and Creating Groups [closed]
- How to disable a specific page for a specific user
- Are User Levels Still Currently Used?
- Error: How to allow the “contributor” to upload media in wordpress
- Remove Capabilities from WP admin for specific user role
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- Execute a ultimate member action when user role is updated
- User capability for editing their own comments
- What are some best practices for user exit strategy?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- Problem with automatic role change through cron job
- Allow Contributors to Upload Files
- How can I allow an User to publish only 5 posts per month?
- Is possible to allow user to login with different role?
- Add a role and give admin priviledges
- How do I let contributors edit their posts after being approved once?
- Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
- Load user by specific role
- How to hide user profile fields based on the role of the viewed user?
- Fix ‘Add Role’ Option not there in wordpress 5.2.2
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Can I Create a Second Admin Level User Role?
- Customising “user ids” and add to ‘user’ panel in the admin area
- New User Save Filter
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- Change User Role based on Point System Issue
- how do I add role and capability after I create a new user
- Get Authors Role
- How do I modify the user role ‘subscriber’ to allow the user to delete posts
- WordPress user role with create user capability?
- Editor role can only create/edit/delete users who have one of two roles
- Update user role for expired membership
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- Find count of WordPress users by role and search string for user name
- Hook into add_user_role and update based on new and removed roles
- fine-grained capabilities for user related capabilities
- wp_get_current_user Not working
- Updated user role inncorrect when using wp_get_current_user()
- In admin manage users page, how can I stop users with certain privileges from editing users with other privileges?
- User Role not showing in Users Screen
- Groups roles & capabilities
- Custom User Role: Can Edit Own Page, Cannot Create New
- Show user details only
- Button for users to upgrade their user role + Button to show current user role!
- Access level seems to have gone from admin to editor
- Restrict Access to the User Profile
- Subscriber role – blank page
- How to get only 1 role from user
- Front end login and page restriction
- User “none” role
- Retrieve New user’s ID
- Giving users an editable homepage/business directory
- i need to let a user to add a role from a frontend form
- Limit user access to installing/configuring a plugin?
- Increase by one the user counter on specific role
- Show only users with the same role in Dashboard user list
- Redirect user based on role when they try access a particular page
- Send email to user if their role is changed to Author
- Remove My Account Menu items in Woocommerce based on user roles
- WordPress: New user role which is ONLY allowed to manage media
- How to allow users in wordpress to switch between two assigned roles e.g. Candidate & Employer