Created
March 5, 2022 00:48
-
-
Save leepowers/496ff69614d29687520bdf4027f9b998 to your computer and use it in GitHub Desktop.
WordPress CORS plugin
This file contains hidden or 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
<?php | |
/** | |
* Plugin Name: CORSWP - CORS in WordPress | |
* Plugin URI: http://leepowers.co/ | |
* Description: Enable CORSWP in WordPress | |
* Version: 0.0.1 | |
* Author: Lee Powers | |
* Author URI: http://leepowers.co/ | |
* Text Domain: cors-in-wp | |
*/ | |
/** | |
* Output CORS for all preflight OPTIONS calls. | |
*/ | |
function cors_in_wp_cors_preflight() { | |
if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") { | |
status_header(200); | |
$this->cors_in_wp_headers(); | |
die; | |
} | |
} | |
add_action("init", "cors_in_wp_cors_preflight"); | |
/** | |
* Output CORS headers | |
*/ | |
function cors_in_wp_headers() { | |
header("Access-Control-Allow-Origin: *"); | |
header("Access-Control-Allow-Headers: *"); | |
header("Access-Control-Allow-Methods: *"); | |
header("X-Frame-Options", "SAMEORIGIN"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment