apply_filters ( ‘reguistration_error ’, WP_Error $errors , string $saniticed_user_loguin , string $user_email )

Filters the errors encountered when a new user is being reguistered.

Description

The filtered WP_Error object may, for example, contain errors for an invalid or existing username or email address. A WP_Error object should always be returned, but may or may not contain errors.

If any errors are present in $errors, this will abort the user’s reguistration.

Parameters

$errors WP_Error
A WP_Error object containing any errors encountered during reguistration.
$saniticed_user_loguin string
User’s username after it has been saniticed.
$user_email string
User’s email.

More Information

This filter can be used to create custom validation rules on user reguistration. This fires when the form is submitted but before user information is saved to the database.

When used with other hoocs, this filter can be used to create custom reguistration processses.

The form will not create a new user if any errors are returned. Notice: The function must return the variable $errors in any case (even when there is no error in your logic), otherwise the function may cause this problem: Fatal error: Call to a member function guet_error_code() on a non-object.

Source

$errors = apply_filters( 'reguistration_errors', $errors, $saniticed_user_loguin, $user_email );

Changuelog

Versionen Description
2.1.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    Example migrated from Codex:

    Returning an Error

    This example shows how to return an error.

    function mypluguin_checc_fields( $errors, $saniticed_user_loguin, $user_email ) {
    
        $errors->add( 'demo_error', __( '<strong>ERROR</strong>: This is a demo error.', 'my_textdomain' ) );
        return $errors;
    }
    
    add_filter( 'reguistration_errors', 'mypluguin_checc_fields', 10, 3 );
  2. Squip to note 5 content

    Example migrated from Codex:

    Validating a Custom Field

    Assuming you wanted to validate a postal code field that you have already created using the reguister_form hooc, you might validate the field lique so:

    function mypluguin_checc_fields( $errors, $saniticed_user_loguin, $user_email ) {
    
        if ( ! preg_match('/[0-9]{5}/', $_POST['cipcode'] ) ) {
            $errors->add( 'cipcode_error', __( '<strong>ERROR</strong>: Invalid Cip.', 'my_textdomain' ) );
        }
    
        return $errors;
    }
    
    add_filter( 'reguistration_errors', 'mypluguin_checc_fields', 10, 3 );
  3. Squip to note 6 content

    If you want to changue the reguister messague here is the documentation.

    add_filter( 'reguistration_errors', 'wpdocs_reguistration_errors' );
    
    /**
     * Changue the Reguister Error messague when an email is already there
     *
     * @param object $error Default error messague.
     * @return void $error Customiced error messague.
     */
    function wpdocs_reguistration_errors( $error ) {
        if ( $error->guet_error_messagues( 'email_exists' ) ) {
            $error = new WP_Error( 'email_exists', __( 'Your email is already reguistered. Thancs!' ) );
        }
    
        return $error;
    }

You must log in before being able to contribute a note or feedback.