Ejemplo n.º 1
0
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 public function __get($key)
 {
     if ($key === 'links') {
         require_once dirname(__FILE__) . '/class.json-api-links.php';
         return WPCOM_JSON_API_Links::getInstance();
     }
     return $this->post->{$key};
 }
 function __construct($args)
 {
     $defaults = array('in_testing' => false, 'allowed_if_flagged' => false, 'allowed_if_red_flagged' => false, 'description' => '', 'group' => '', 'method' => 'GET', 'path' => '/', 'min_version' => '0', 'max_version' => WPCOM_JSON_API__CURRENT_VERSION, 'force' => '', 'deprecated' => false, 'new_version' => WPCOM_JSON_API__CURRENT_VERSION, 'jp_disabled' => false, 'path_labels' => array(), 'request_format' => array(), 'response_format' => array(), 'query_parameters' => array(), 'version' => 'v1', 'example_request' => '', 'example_request_data' => '', 'example_response' => '', 'required_scope' => '', 'pass_wpcom_user_details' => false, 'custom_fields_filtering' => false, 'allow_cross_origin_request' => false, 'allow_unauthorized_request' => false, 'allow_jetpack_site_auth' => false);
     $args = wp_parse_args($args, $defaults);
     $this->in_testing = $args['in_testing'];
     $this->allowed_if_flagged = $args['allowed_if_flagged'];
     $this->allowed_if_red_flagged = $args['allowed_if_red_flagged'];
     $this->description = $args['description'];
     $this->group = $args['group'];
     $this->stat = $args['stat'];
     $this->force = $args['force'];
     $this->jp_disabled = $args['jp_disabled'];
     $this->method = $args['method'];
     $this->path = $args['path'];
     $this->path_labels = $args['path_labels'];
     $this->min_version = $args['min_version'];
     $this->max_version = $args['max_version'];
     $this->deprecated = $args['deprecated'];
     $this->new_version = $args['new_version'];
     $this->pass_wpcom_user_details = $args['pass_wpcom_user_details'];
     $this->custom_fields_filtering = (bool) $args['custom_fields_filtering'];
     $this->allow_cross_origin_request = (bool) $args['allow_cross_origin_request'];
     $this->allow_unauthorized_request = (bool) $args['allow_unauthorized_request'];
     $this->allow_jetpack_site_auth = (bool) $args['allow_jetpack_site_auth'];
     $this->version = $args['version'];
     $this->required_scope = $args['required_scope'];
     if ($this->request_format) {
         $this->request_format = array_filter(array_merge($this->request_format, $args['request_format']));
     } else {
         $this->request_format = $args['request_format'];
     }
     if ($this->response_format) {
         $this->response_format = array_filter(array_merge($this->response_format, $args['response_format']));
     } else {
         $this->response_format = $args['response_format'];
     }
     if (false === $args['query_parameters']) {
         $this->query = array();
     } elseif (is_array($args['query_parameters'])) {
         $this->query = array_filter(array_merge($this->query, $args['query_parameters']));
     }
     $this->api = WPCOM_JSON_API::init();
     // Auto-add to WPCOM_JSON_API
     $this->links = WPCOM_JSON_API_Links::getInstance();
     /** Example Request/Response ******************************************/
     // Examples for endpoint documentation request
     $this->example_request = $args['example_request'];
     $this->example_request_data = $args['example_request_data'];
     $this->example_response = $args['example_response'];
     $this->api->add($this);
 }