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 dashboard page with additional query parameters?

ex: https://example.com/wp-admin/admin.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 scriptwindow.href.location="https://example.com"/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("scriptwindow.location.href='$self_url'/script");
    } else {
        header('Location: ' . $self_url);
        die();
    }
}

Topic oauth wp-redirect hooks Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.