File "class-wc-legacy-api.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-api.php
File
size: 6.5 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
if (!defined('ABSPATH')) {
exit;
}
class WC_Legacy_API
{
const VERSION = '3.1.0';
public $server;
public $authentication;
public function init()
{
add_action('parse_request', array($this, 'handle_rest_api_requests'), 0);
}
public function add_query_vars($vars)
{
$vars[] = 'wc-api-version';
$vars[] = 'wc-api-route';
return $vars;
}
public static function add_endpoint()
{
add_rewrite_rule('^wc-api/v([1-3]{1})/?$', 'index.php?wc-api-version=$matches[1]&wc-api-route=/', 'top');
add_rewrite_rule('^wc-api/v([1-3]{1})(.*)?', 'index.php?wc-api-version=$matches[1]&wc-api-route=$matches[2]', 'top');
}
public function handle_rest_api_requests()
{
global $wp;
if (!empty($_GET['wc-api-version'])) {
$wp->query_vars['wc-api-version'] = $_GET['wc-api-version'];
}
if (!empty($_GET['wc-api-route'])) {
$wp->query_vars['wc-api-route'] = $_GET['wc-api-route'];
}
if (!empty($wp->query_vars['wc-api-version']) && !empty($wp->query_vars['wc-api-route'])) {
wc_maybe_define_constant('WC_API_REQUEST', true);
wc_maybe_define_constant('WC_API_REQUEST_VERSION', absint($wp->query_vars['wc-api-version']));
if (1 === WC_API_REQUEST_VERSION) {
$this->handle_v1_rest_api_request();
} elseif (2 === WC_API_REQUEST_VERSION) {
$this->handle_v2_rest_api_request();
} else {
$this->includes();
$this->server = new WC_API_Server($wp->query_vars['wc-api-route']);
$this->register_resources($this->server);
$this->server->serve_request();
}
exit;
}
}
public function includes()
{
include_once dirname(__FILE__) . '/api/v3/class-wc-api-exception.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-server.php';
include_once dirname(__FILE__) . '/api/v3/interface-wc-api-handler.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-json-handler.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-authentication.php';
$this->authentication = new WC_API_Authentication();
include_once dirname(__FILE__) . '/api/v3/class-wc-api-resource.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-coupons.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-customers.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-orders.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-products.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-reports.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-taxes.php';
include_once dirname(__FILE__) . '/api/v3/class-wc-api-webhooks.php';
do_action('woocommerce_api_loaded');
}
public function register_resources($server)
{
$api_classes = apply_filters('woocommerce_api_classes', array('WC_API_Coupons', 'WC_API_Customers', 'WC_API_Orders', 'WC_API_Products', 'WC_API_Reports', 'WC_API_Taxes', 'WC_API_Webhooks'));
foreach ($api_classes as $api_class) {
$this->{$api_class} = new $api_class($server);
}
}
private function handle_v1_rest_api_request()
{
include_once dirname(__FILE__) . '/api/v1/class-wc-api-server.php';
include_once dirname(__FILE__) . '/api/v1/interface-wc-api-handler.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-json-handler.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-xml-handler.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-authentication.php';
$this->authentication = new WC_API_Authentication();
include_once dirname(__FILE__) . '/api/v1/class-wc-api-resource.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-coupons.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-customers.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-orders.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-products.php';
include_once dirname(__FILE__) . '/api/v1/class-wc-api-reports.php';
do_action('woocommerce_api_loaded');
$this->server = new WC_API_Server($GLOBALS['wp']->query_vars['wc-api-route']);
$api_classes = apply_filters('woocommerce_api_classes', array('WC_API_Customers', 'WC_API_Orders', 'WC_API_Products', 'WC_API_Coupons', 'WC_API_Reports'));
foreach ($api_classes as $api_class) {
$this->{$api_class} = new $api_class($this->server);
}
$this->server->serve_request();
}
private function handle_v2_rest_api_request()
{
include_once dirname(__FILE__) . '/api/v2/class-wc-api-exception.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-server.php';
include_once dirname(__FILE__) . '/api/v2/interface-wc-api-handler.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-json-handler.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-authentication.php';
$this->authentication = new WC_API_Authentication();
include_once dirname(__FILE__) . '/api/v2/class-wc-api-resource.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-coupons.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-customers.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-orders.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-products.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-reports.php';
include_once dirname(__FILE__) . '/api/v2/class-wc-api-webhooks.php';
do_action('woocommerce_api_loaded');
$this->server = new WC_API_Server($GLOBALS['wp']->query_vars['wc-api-route']);
$api_classes = apply_filters('woocommerce_api_classes', array('WC_API_Customers', 'WC_API_Orders', 'WC_API_Products', 'WC_API_Coupons', 'WC_API_Reports', 'WC_API_Webhooks'));
foreach ($api_classes as $api_class) {
$this->{$api_class} = new $api_class($this->server);
}
$this->server->serve_request();
}
public function rest_api_init()
{
}
public function rest_api_includes()
{
$this->rest_api_init();
}
public function register_rest_routes()
{
wc_deprecated_function('WC_Legacy_API::register_rest_routes', '3.7.0', '');
$this->register_wp_admin_settings();
}
}