Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
add CORS to caldera forms
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
You can’t perform that action at this time.