Enable CORS on JSON API Wordpress

前端 未结 10 2092
南笙
南笙 2020-12-03 03:28

I have this wordpress site with a plugin called JSON API. This plugin provides a JSON format for the content that is in the wordpress. I was able to enable CORS on the wordp

10条回答
  •  旧巷少年郎
    2020-12-03 03:52

    In wordpress goto plugins > JSON API > Edit

    From the right hand file selection select

    json-api/singletons/api.php

    You will need to add the following line

    header("Access-Control-Allow-Origin: *");

    Your code should look similar to this once done. Adding this line anywhere else might not work as expected.

    query = new JSON_API_Query();
        $this->introspector = new JSON_API_Introspector();
        $this->response = new JSON_API_Response();
        add_action('template_redirect', array(&$this, 'template_redirect'));
        add_action('admin_menu', array(&$this, 'admin_menu'));
        add_action('update_option_json_api_base', array(&$this, 'flush_rewrite_rules'));
        add_action('pre_update_option_json_api_controllers', array(&$this, 'update_controllers'));
      }
    
      function template_redirect() {
    

提交回复
热议问题