WordPress重定向不工作


WordPress redirection is not working

我需要重定向我的页面到我的api服务,而paypal-payment-redirect页被调用。下面的代码重定向如我所料。但它没有在header中传递授权令牌。有办法解决这个问题吗?

<?php
function my_page_template_redirect()
{
    global $wppimsettings;
    if (isset($_COOKIE['login_token'])) {
        if (is_page('paypal-payment-redirect')) {
            $token = json_decode(str_replace('''', '', $_COOKIE['login_token']));
            $data = array(
                'headers' => array(
                    'Authorization' => $token->token_type . ' ' . $token->access_token
                )
            );
            header("Authorization: {$token->token_type} {$token->access_token}");
            header("Location: {$wppimsettings['api_url']}purchaseHelper/paypalPayment");
            exit();
        }
    }
}
add_action('template_redirect', 'my_page_template_redirect');

From PHP HEADER doc

可选的replace参数表示该报头是替换之前类似的报头,还是添加相同类型的第二个报头。默认情况下它会替换,但是如果你传入FALSE作为第二个参数,你可以强制使用多个相同类型的头文件。例如:

<?php
header('WWW-Authenticate: Negotiate');
header('WWW-Authenticate: NTLM', false);
?>