Edit postmeta when user changes user role?

Well, you’re not entirely correct. This code will run, when the action called basic will be called using do_action('basic', ...). But… There is no such action in WP core, so your code won’t run at all, I’m afraid.

There is hook that might be helpful in your case. It’s called set_user_role and it has 3 params ($user_id, $role, $old_roles).

So your code should look more like this:

add_action( 'set_user_role', function( $user_id, $role, $old_roles ) 
{
    if ( 'basic' == $role ) {
        // Your code ...
    }

}, 10, 3 );

Leave a Comment