How to hook into user registration process Before user registers

I need to add a field to the user registration form and then validate it before I add a new user to my WordPress

I know how to hook into the registration form via add_filter('register_form', 'my_function');

Read More

But how do I hook into the registration process before the user registers? Hence I do not want add_action('user_register','my_other_function');.

Related posts

2 comments

  1. You need to create your own hook for registration_errors filter:

    add_filter( 'registration_errors', 'wpse8170_registration_errors', 10, 3 );
    function wpse8170_registration_errors( $errors, $sanitized_user_login, $user_email ) {
        if ( /* something happens */ ) {
            $errors->add( 'myexception_code', 'This is my message' );
        }
    
        return $errors;
    }
    
  2. Take a look at the WordPress Codex: Customizing The Registration Form

    Theme and plugin developers can customize WordPress’s built-in user
    registration page through the use of hooks.

    Customizing the registration form involves utilizing the following
    three hooks:

    1. register_form
      Allows rendering of new HTML form elements.
    2. registration_errors
      Perform validation on form registration fields.
    3. user_register
      Save custom form data.

Comments are closed.