Skip to content

Instantly share code, notes, and snippets.

@1shiharat
Created June 3, 2014 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1shiharat/09b3ed476d18cecdee2e to your computer and use it in GitHub Desktop.
Save 1shiharat/09b3ed476d18cecdee2e to your computer and use it in GitHub Desktop.
allow x-domain for wp json api
/**
* ぜっっっったいわすれんな : テスト用
*
*/
add_action( 'init', 'handle_preflight' );
function handle_preflight() {
header("Access-Control-Allow-Origin: " . get_http_origin());
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Credentials: true");
if ( 'OPTIONS' == $_SERVER['REQUEST_METHOD'] ) {
status_header(200);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment