Last active
August 29, 2015 14:26
-
-
Save adriangritz/7e8f36e2eb7173132438 to your computer and use it in GitHub Desktop.
How to enable CORS for WP Rest API so you can consume the API via JavaScript.
This file contains 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 | |
//http://torquemag.io/preparing-wordpress-site-power-single-page-web-app/ | |
add_filter( 'json_serve_request', 'uf_json_serve_request' ); | |
function uf_json_serve_request() | |
{ | |
$domains = array('http://warrington.ufl.edu', 'https://warrington.ufl.edu', 'http://beta.warrington.ufl.edu', 'https://beta.warrington.ufl.edu'); | |
$domain = $_SERVER['HTTP_ORIGIN']; | |
if(in_array( $domain, $domains )) { | |
header( "Access-Control-Allow-Origin: {$domain}" ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment