hooks - Output Redirect Headers on Admin Dashboard Page

Question:Is there a way to output headers with either wp_redirect() or header() when a user is requesting an admin dash

Question: Is there a way to output headers with either wp_redirect() or header() when a user is requesting an admin dashboard page with additional query parameters?

ex: .php?page=example_page+auth_code=1234xyz+state=abcdef1234

When I try calling either function above in my PHP script which displays the admin page, (hooked into add_submenu_page) nothing is done, and the page simply terminates

Reason: I am trying to implement OAuth 2.0 with Intuit Quickbooks Online and need to refresh the redirect link sent back from Intuit Quickbooks. I need to strip the $_GET parameters and placing them in $_POST so that they are not publicly accessible. Currently I am echoing JavaScript to facilitate the redirect <script>window.href.location=""</script>. This works, but I would like to not have to echo JavaScript to achieve this.

Code:

function submenu_hook_function(){
        require_once(plugin_dir_path(__FILE__) . "quickbooks-sync.php");
}

//...inside quickbooks-sync.php...
if (isset($_GET['code'])  && isset($_GET['state'])){

    $self_url = site_url( '/wp-admin/admin.php?page=quickbooks_sync', 'https' );

    if (headers_sent()) {
        die("<script>window.location.href='$self_url'</script>");
    } else {
        header('Location: ' . $self_url);
        die();
    }
}

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

相关推荐

  • hooks - Output Redirect Headers on Admin Dashboard Page

    Question:Is there a way to output headers with either wp_redirect() or header() when a user is requesting an admin dash

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信