Detect New User Registration

Is there a filter or action hook I could use to detect from a third-party plugin when a new user has been registered? It seems the hook WordPress uses: user_register will not work.

@mycred: how about trying set_user_role as your hook?

@KTS915: It runs when levels are changed too…

@mycred: Better use notifications, instead hooks.

I chose WP hooks since I know WP but I do not know S2. Do you know where i could find information about what “notifications” are?

Read at “s2Member -> API / Notifications”, there is lot of info.

1 Like

Ah, perfect, thank you I will have a look.

@krumch, yes, you’re right, set_user_role does run on updates too, but you can deal with that with a conditional, like this:

function new_user_registered( $user_id, $new_role, $old_role ) {
    $user_info = get_userdata( $user_id );
        
    if ( empty( $old_role ) && $new_role == 's2member_level1' ) { 
        // do stuff
    }
}
add_action( 'set_user_role', 'new_user_registered', 10, 3);
1 Like

Great solution, @KTS915 :slight_smile:

Thanks, @krumch! :grin: