Created
September 29, 2017 15:24
-
-
Save dtateii/288c39d27d79f4847b4dc53064c83b2a to your computer and use it in GitHub Desktop.
Q+D CORS headers for WP REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: CORS | |
* Description: Just adds headers to every response to enable cross-origin GET requests for API. | |
* Version: 0.0.1 | |
* Author: NJI Media | |
* Author URI: https://www.njimedia.com | |
* License: GPLv2 or later | |
* Text Domain: cors | |
* | |
* @package WordPress | |
* @subpackage CORS | |
*/ | |
// Hook in. | |
add_action( 'init', 'add_cors_headers' ); | |
/** | |
* Add CORS headers to all responses. | |
*/ | |
function add_cors_headers() { | |
header( 'Access-Control-Allow-Origin: *' ); | |
header( 'Access-Control-Allow-Methods: GET' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment