You need to add , 10, 3
after your closure to set the hook priority and (more importantly) the number of accepted arguments - otherwise $user_email
and $errors
will not be passed.
add_action( 'register_post', function ( $user_login, $user_email, $errors ) {
$userIsValid = ValidateUser::make($errors);
if(!$userIsValid) {
$errors->add( 'bad_email_domain', '<strong>ERROR</strong>: errors' );
}
}, 10, 3 );
Update: The register_post
hook only fires inside register_new_user()
, which is only used for user registration via the WordPress login page.
To handle errors within the admin (i.e. Users > Add New) use the user_profile_update_errors
hook instead.