I have this wordpress site with a plugin called JSON API. This plugin provides a JSON format for the content that is in the wordpress. I was able to enable CORS on the wordp
Before the response is sent to the browser, we can run two action hooks and insert a new header()
:
do_action("json_api", $controller, $method);
do_action("json_api-{$controller}-$method");
The first one runs on every method, and the second one is to target specific methods. Here's an implementation of the first one, with a commented way to find the second:
add_action( 'json_api', function( $controller, $method )
{
# DEBUG
// wp_die( "To target only this method use add_action('$controller-$method', function(){ /*YOUR-STUFF*/ });
" );
header( "Access-Control-Allow-Origin: *" );
}, 10, 2 );