Skip to content

Commit

Permalink
Fixed CORS error when using the Botwiki API.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbohacek committed Aug 2, 2022
1 parent 4e66a52 commit 9ff67d3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,16 @@ 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 );

0 comments on commit 9ff67d3

Please sign in to comment.