Screenshot New Years Sale Get the "ALL ACCESS PASS" and Save $349. Unlimited Licenses.
Show All Access Pass

CORS Requests

Published: June 26, 2020 | Updated: June 26th, 2020
  1. Home
  2. Docs
  3. Common Issues
  4. CORS Requests

It is typical to that requests need to be made to the server (WP and WP OAuth Server) using CORS (Cross-origin Resource Sharing). WP OAuth Server may need some adjustments made to the server to ensure everything works as expected.

There is a couple ways to enable CORS for your server.

.htaccess Method

Adding the following snippet to the .htaccess file usually works the best. It is important to note that the origin in this snippet is unrestricted.

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

functions.php Method

Add the following to your themes functions.php at the end of the file. It is important to note that the origin in this snippet is unrestricted.

function wo_cors_check_and_response(){
if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: POST, GET');
    header('Access-Control-Allow-Headers: Authorization');
    header('Access-Control-Max-Age: 1');  //1728000
    header("Content-Length: 0");
    header("Content-Type: text/plain charset=UTF-8");
    exit(0);
  }
}
add_action('wo_before_api', 'wo_cors_check_and_response');
Icon