From 749919e202bac09cb8ec5f8ae811836034db9bb8 Mon Sep 17 00:00:00 2001 From: Stefan Bohacek Date: Tue, 2 Aug 2022 09:50:46 -0400 Subject: [PATCH] Fixed CORS error when using the Botwiki API. --- functions.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/functions.php b/functions.php index 6f7cc16..1511b6c 100644 --- a/functions.php +++ b/functions.php @@ -702,15 +702,7 @@ function bw_admin_reorder_posts( $query ){ add_action( 'pre_get_posts', 'bw_admin_reorder_posts' ); -function custom_rest_api_init() { - remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' ); - add_filter( 'rest_pre_serve_request', function( $value ) { - header( 'Access-Control-Allow-Origin: *' ); - header( 'Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, PATCH, DELETE' ); - header( 'Access-Control-Allow-Credentials: true' ); - header( 'Access-Control-Expose-Headers: Link', false ); - header( 'Access-Control-Allow-Headers: X-Requested-With' ); - return $value; - } ); -} -add_action( 'rest_api_init', 'custom_rest_api_init', 15 ); + +add_action('rest_api_init', function() { + remove_filter('rest_pre_serve_request', 'rest_send_cors_headers'); +}, 15);