Created
July 26, 2017 19:06
-
-
Save lenilsonjr/b3dbf67c5370cf3ac46f7d9960114d92 to your computer and use it in GitHub Desktop.
Allow CORS on WP-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
add_action( 'rest_api_init', 'handle_preflight' ); | |
function handle_preflight() { | |
header("Access-Control-Allow-Origin: *"); //Pay attention | |
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); | |
header("Access-Control-Allow-Credentials: true"); | |
header("Access-Control-Allow-Headers: x-requested-with,x-wp-nonce"); | |
if ( 'OPTIONS' == $_SERVER['REQUEST_METHOD'] ) { | |
status_header(200); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment