0

I've followed the documentation from WordPress, but my functions.php file still is not getting the token (abcd) variable from the URL: https://example.com/reset-password/?token=abcd

My functions.php file includes the following:

function add_query_vars_filter( $vars ) {
  $vars[] = "token";
  return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );

...

add_filter( 'wpcf7_validate_text*', 'custom_password_reset_validation_filter', 10, 2 );
function custom_password_reset_validation_filter( $result, $tag ) {
    // Make POST request to change password
            $token = get_query_var( 'token', "fk" );
            write_log("TKN: {$token}");
    }

    return $result;
}

For some reason, get__query_var always returns fk instead of abcd.

2
  • If wpcf7_validate_text is handled in a separate AJAX request, then the token parameter is not going to exist. Commented Aug 21, 2019 at 5:23
  • But then how can I get the GET parameter in my Contact Form 7 validation? Commented Aug 22, 2019 at 1:15

2 Answers 2

0

Contact Form 7 provides a recipe for Validation as a Filter which looks very much like what you are trying to do.

Adapting their example to your code, I believe the following should work for you:

add_filter( 'wpcf7_validate_text*', 'custom_password_reset_validation_filter', 10, 2 );
function custom_password_reset_validation_filter( $result, $tag ) {        
    if ('token'==$tag->name){
        $token = isset($_POST['token']) ? $_POST['token'] : "fk";
        write_log("TKN: {$token}");
    }

    return $result;
}
-1

You can try

$token = $_REQUEST['token']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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