UsersWP fires its own actions and filters while it processes the register form. To run code once registration has finished, for example to change the new user’s role or copy a field somewhere else, use the uwp_after_process_register action.
Why user_register runs too early
WordPress fires user_register inside wp_insert_user(), as soon as the account exists. UsersWP saves the extra fields from your register form after that, in its own uwp_usermeta table. So when user_register runs, the values from your custom fields are not saved yet.
Registration hooks in the order they run
uwp_before_validate(action) runs before the submitted fields are checked. It receives the form type,register.uwp_validate_result(filter) lets you add your own checks. Return aWP_Errorto stop the registration and show your message.uwp_after_validate(action) runs once validation has passed, before the user is created.uwp_before_extra_fields_save(filter) runs after the user is created and before the custom fields are saved, so you can change the values.uwp_after_extra_fields_save(filter) runs straight after the custom fields are saved.uwp_after_custom_fields_save(action) runs when the custom fields are saved and can be read back. It receives the form type, the posted data, the validated values and the user ID.uwp_after_process_register(action) runs when registration is complete and the emails have gone out. It receives the validated values and the new user ID.
The validation hooks also run for the login, forgot password, change password, reset and account forms. Check the form type in your callback so your code only runs for registration.
Example: change the role based on a field
This snippet reads a custom field after registration and gives the user the Author role when the field has a certain value. Replace account_type with the key of your own field, and use roles that exist on your site.
add_action( 'uwp_after_process_register', 'my_uwp_after_register', 10, 2 );
function my_uwp_after_register( $data, $user_id ) {
$account_type = uwp_get_usermeta( $user_id, 'account_type', '' );
if ( 'business' === $account_type ) {
$user = new WP_User( $user_id );
$user->set_role( 'author' );
}
}
Add the code to your child theme’s functions.php file or with a plugin such as Code Snippets. uwp_get_usermeta() reads any UsersWP field for a user.
A different role for each register form
If all you need is a different role per form, you can do it without code. Each register form in UsersWP is a user type with its own role. Go to UsersWP > User Types, edit the user type and choose the role in User Role to Assign.
UsersWP also saves the ID of the form a user signed up with in the user meta key _uwp_register_form_id, so your own code can check which form was used with get_user_meta( $user_id, '_uwp_register_form_id', true ).
These hooks belong to the UsersWP register form. Accounts that an admin adds in wp-admin, or that another plugin creates, do not pass through them.