0

I have added a custom field to the lost password form (using the action lostpassword_form) and I am validating this field with the filter allow_password_reset.

It is working but I want my field to be checked first, before the user id field. So for example if both fields are empty I want my error to show not the WordPress error to enter username or email.

Here is a simplified example of what I am doing now:

add_filter( 'allow_password_reset', 'my_func' );

function my_func($allow)
{
    if($_POST['my_field']!='valid-data')
        return new WP_Error( 'denied', "<strong>ERROR</strong>: Access denied." );
    else
        return $allow;
} 

Do you think it is possible? Is there an earlier filter to use?

2

Actually I found what I need. Using the action lostpassword_post I can add errors before wordpress checks if the username or email is valid. It does not stop wordpress from checking if the username or email is empty, but still it will do the job.

This is a simplified version of the code that checks my custom field:

add_action('lostpassword_post', 'my_validate_lost_pass_form');

function my_validate_lost_pass_form($errors)  
{
    if ($_POST['my_field']!='valid-data')
        $errors->add( 'my_error_name', "<strong>ERROR</strong>: Access denied." );

    return $errors;
}
  • you should post your full answer here, so others can get help from it. – Mohammed Sufian Sep 11 '16 at 18:22
  • @MuhammadSufiyan OK, I added an example code. – Nikolay Sep 12 '16 at 17:49

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.