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();
}
}