-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix empty body for schema OPTIONS requests
- Loading branch information
1 parent
0d03178
commit 946fa68
Showing
2 changed files
with
8 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
<?php | ||
|
||
add_action('init', 'handle_preflight'); | ||
function handle_preflight() { | ||
function handle_preflight() | ||
{ | ||
// This is for CORS when using the WP REST API, especially when submitting Gravity Forms | ||
header("Access-Control-Allow-Origin: *"); | ||
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); | ||
header("Access-Control-Allow-Headers: Origin, Content-Type, Accept"); | ||
|
||
if('OPTIONS' == $_SERVER['REQUEST_METHOD']) { | ||
// Check for CORS preflight request headers | ||
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']) || isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { | ||
// It's a CORS preflight request, handle accordingly | ||
status_header(200); | ||
exit(); | ||
} | ||
} | ||
// Not a preflight request, let WordPress handle it (possibly a schema request) | ||
} |