Codex

Plugin API/Filter Reference/registration errors

This page is marked as incomplete. You can help Codex by expanding it.

Contents

Description

The registration_errors filter hook is used to create custom validation rules on user registration. This fires when the form is submitted but before user information is saved to the database.

When used with other hooks, this filter can be used to create custom registration processes.

Examples

The form will not create a new user if any errors are returned.

Returning an Error

This example shows how to return an error.

function myplugin_check_fields($errors, $sanitized_user_login, $user_email) {

    $errors->add( 'demo_error', __('<strong>ERROR</strong>: This is a demo error. Registration halted.','mydomain') );

    return $errors;

}

add_filter('registration_errors', 'myplugin_check_fields', 10, 3);

Validating a Custom Field

Assuming you wanted to validate a postal code field that you have already created using the register_form hook, you might validate the field like so...

function myplugin_check_fields($errors, $sanitized_user_login, $user_email) {

    if ( ! preg_match('/\d{5}/', $_POST['user_extra']) )
        $errors->add( 'zipcode_error', __('<strong>ERROR</strong>: Enter a valid 5-digit postal code.','mydomain') );

    return $errors;

}

add_filter('registration_errors', 'myplugin_check_fields', 10, 3);

Source File

The registration_errors hook is located in wp-login.php

Related

Tutorials

Action Hooks

Filter Hooks

  • registration_errors

Return to Plugin API/Filter Reference