I've added a custom input field with login_form hook.

So, I need to process the post data to validate. I've used the lostpassword_post for lostpassword_form and works great, but I cant find a hook to validate my data at login form.

Any Ideas?

2 Answers 2


Use the action 'login_init' to catch all calls to wp-login.php.

Sample code:

add_action( 'login_init', 'wpse_51227_validate_custom_field' );

function wpse_51227_validate_custom_field()
    if ( ! isset ( $_POST['special_custom'] )

    if ( ! is_numeric( $_POST['special_custom'] )
        // handle the error

There are two important global variables available:

  • $errors is an instance of WP_Error. Maybe you want to use it to store error data.
  • $action is the current action. Maybe you want to rest it to login to prevent a redirect if the user input is invalid.

Haven't really tested this but I'm just guessing by how I do it with the registration & profile pages.

Try something like this:

function my_login_errors( $errors ) {
    if ( empty( $_POST['custom_field'] ) )
        $errors->add( 'empty_custom_field', '<strong>ERROR</strong>: Please enter some info.' );
    return $errors;
add_filter( 'login_errors', 'my_login_errors' );

Note: Modify the custom_field part and the message accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.