Created
March 26, 2019 09:52
-
-
Save Macagare/a6c7f0f25eb26cd46f853844445ca367 to your computer and use it in GitHub Desktop.
add CORS to caldera forms
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
add_action( 'init', 'handle_preflight' ); | |
function handle_preflight() { | |
// Set the domain that's allowed to make the API call. | |
header("Access-Control-Allow-Origin: " . get_http_origin()); | |
// Set the methods | |
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); | |
header("Access-Control-Allow-Headers: Origin, Content-Type, Accept"); | |
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