I try to hook in user creation process in admin dashboard /wp/wp-admin/user-new.php
to make some custom validation on data with the following hook, but the hook is not executed on form submit. What goes wrong in this case?
What I want, I have a custom ACF relation field which should be mandatory only if the selected role is editor. So I want to parse the request and check against the rules. If it fails than do not create the user return the custom error message.
add_action( 'register_post', function($user_login, $user_email, $errors) {
var_dump('test');
die;
$userIsValid = ValidateUser::make($errors);
if(!$userIsValid) {
$errors->add( 'bad_email_domain', '<strong>ERROR</strong>: errors' );
}
});
ValidateUser
is and what is insideValidateUser::make
, or why you're hooking intoregister_post
? Use theEdit
link to add more details to your questionregister_post
though, users are not posts.register_post
only fires for user registrations via the WordPress login page. You should use theuser_profile_update_errors
hook instead.