Skip to content

Instantly share code, notes, and snippets.

@bitflower
Created December 30, 2014 18:05
Show Gist options
  • Save bitflower/1a7efbcbec19079414d0 to your computer and use it in GitHub Desktop.
Save bitflower/1a7efbcbec19079414d0 to your computer and use it in GitHub Desktop.
Activate CORS for WP-API (JSON REST API)
/**
* bitflower: Activate CORS for WP-API (JSON REST API)
*/
do_action("json_api", $controller, $method);
add_action( 'json_api', function( $controller, $method )
{
# DEBUG
// wp_die( "To target only this method use <pre><code>add_action('$controller-$method', function(){ /*YOUR-STUFF*/ });</code></pre>" );
header( "Access-Control-Allow-Origin: *" );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment