• I am using a WP Rest Api controller, I have installed my plugin locally on XAMP and its working fine, but when I upload it to a shared hosted wordpress, CORS headers missing in preflight request also http_origing is empty, does any body have a clue on this? i am using wp 4.6 and rest api 2:

    this is my controllers constructor:

    public function __construct(){

    add_action( ‘rest_api_init’,[$this, ‘register_routes’] );

    add_action( ‘init’, function () {

    header(“Access-Control-Allow-Origin: ” . get_http_origin());
    header(“Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE”);
    header(“Access-Control-Allow-Credentials: true”);
    header(“Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-WP-Nonce, X-Requested-With”);

    if ( ‘OPTIONS’ == $_SERVER[‘REQUEST_METHOD’] ) {
    status_header(200);
    exit();
    }
    } );

    }

    • This topic was modified 9 years, 9 months ago by khoshru.

The topic ‘shared hosted plugin not sending cors headers’ is closed to new replies.