I've followed the documentation from WordPress, but my functions.php
file still is not getting the token
(abcd
) variable from the URL: /?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
.
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/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 Answers
Reset to default 0Contact 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;
}
You can try
$token = $_REQUEST['token']
GET
parameter in myContact Form 7
validation? – Jameson Rader Commented Aug 22, 2019 at 1:15