Skip to content

Commit

Permalink
fix empty body for schema OPTIONS requests
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBarnes committed Jan 24, 2024
1 parent 0d03178 commit 946fa68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion wordpress/plugins/nextwp-toolkit/nextwp-toolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: NextWP - Headless Toolkit
* Plugin URI: https://www.nextwp.org/packages/wordpress/nextwp-toolkit-plugin
* Description: A toolkit for headless Wordpress sites built with NextWP
* Version: 1.1.3
* Version: 1.1.4
* Author: Caleb Barnes
* Author URI: https://github.com/CalebBarnes
*/
Expand Down
10 changes: 7 additions & 3 deletions wordpress/plugins/nextwp-toolkit/wp/cors.php
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)
}

0 comments on commit 946fa68

Please sign in to comment.