Created
June 17, 2019 18:22
-
-
Save wpscholar/59f5708cba291a314375b2dedd104e1e to your computer and use it in GitHub Desktop.
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: WP REST API - Allow All CORS Requests | |
* Description: Adds headers to allow cross-origin requests to the WordPress REST API. | |
* Version: 1.0 | |
* Plugin URI: https://gist.github.com/wpscholar/59f5708cba291a314375b2dedd104e1e | |
* Author: Micah Wood | |
* Author URI: https://wpscholar.com | |
*/ | |
add_action( 'rest_api_init', function() { | |
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' ); | |
add_filter( 'rest_pre_serve_request', function( $value ) { | |
header( 'Access-Control-Allow-Origin: *' ); | |
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' ); | |
header( 'Access-Control-Allow-Credentials: true' ); | |
return $value; | |
}); | |
}, 12 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment