Pull GET parameter from URL in functions.php

I've followed the documentation from WordPress, but my functions.php file still is not getting the token (abcd) var

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.

Share Improve this question asked Aug 21, 2019 at 3:56 Jameson RaderJameson Rader 11 bronze badge 2
  • If wpcf7_validate_text is handled in a separate AJAX request, then the token parameter is not going to exist. – Jacob Peattie Commented Aug 21, 2019 at 5:23
  • But then how can I get the GET parameter in my Contact Form 7 validation? – Jameson Rader Commented Aug 22, 2019 at 1:15
Add a comment  | 

2 Answers 2

Reset to default 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;
}

You can try

$token = $_REQUEST['token']

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745223082a4617339.html

相关推荐

  • Pull GET parameter from URL in functions.php

    I've followed the documentation from WordPress, but my functions.php file still is not getting the token (abcd) var

    9小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信