Skip to content

Instantly share code, notes, and snippets.

@ideodora
Created November 21, 2014 18:11
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 ideodora/c7fa1c6154917c421fff to your computer and use it in GitHub Desktop.
Save ideodora/c7fa1c6154917c421fff to your computer and use it in GitHub Desktop.
WP JSON REST API の header 設定
# http://torquemag.io/preparing-wordpress-site-power-single-page-web-app/
add_filter( 'json_serve_request', function( ) {
$domains = array( 'http://torquemag.io', 'http://wordpress.org' );
if( isset( $_SERVER['HTTP_ORIGIN'] && in_array( $_SERVER['HTTP_ORIGIN'], $domain ) ) ) {
$domain = $_SERVER['HTTP_ORIGIN'];
header( "Access-Control-Allow-Origin: {$domain}" );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment