2018-09-17 14:32:03 +00:00
|
|
|
<?php
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* REST API bootstrap.
|
|
|
|
*
|
|
|
|
* @package WooCommerce Admin/Classes
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* WC_Admin_Api_Init class.
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
class WC_Admin_Api_Init {
|
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* Boostrap REST API.
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
public function __construct() {
|
|
|
|
// Initialize classes.
|
2018-09-17 18:19:36 +00:00
|
|
|
add_action( 'plugins_loaded', array( $this, 'init_classes' ), 19 );
|
2018-09-17 14:32:03 +00:00
|
|
|
// Hook in data stores.
|
|
|
|
add_filter( 'woocommerce_data_stores', array( 'WC_Admin_Api_Init', 'add_data_stores' ) );
|
|
|
|
// REST API extensions init.
|
|
|
|
add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
|
2018-09-18 10:24:43 +00:00
|
|
|
add_filter( 'rest_endpoints', array( 'WC_Admin_Api_Init', 'filter_rest_endpoints' ), 10, 1 );
|
2019-01-17 07:01:09 +00:00
|
|
|
|
|
|
|
// Add currency symbol to orders endpoint response.
|
|
|
|
add_filter( 'woocommerce_rest_prepare_shop_order_object', array( __CLASS__, 'add_currency_symbol_to_order_response' ) );
|
2018-09-17 14:32:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* Init classes.
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
public function init_classes() {
|
|
|
|
// Interfaces.
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/interfaces/class-wc-admin-reports-data-store-interface.php';
|
2018-09-17 18:36:03 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-query.php';
|
|
|
|
|
2018-09-18 10:24:43 +00:00
|
|
|
// Common date time code.
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-interval.php';
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2019-01-29 11:13:52 +00:00
|
|
|
// Exceptions.
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-parameter-exception.php';
|
|
|
|
|
2019-01-29 18:57:04 +00:00
|
|
|
// WC Class extensions.
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-order.php';
|
|
|
|
|
2019-01-17 11:14:24 +00:00
|
|
|
// Segmentation.
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-segmenting.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-orders-stats-segmenting.php';
|
2019-01-18 10:41:15 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-products-stats-segmenting.php';
|
2019-01-18 16:11:46 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-coupons-stats-segmenting.php';
|
2019-01-30 17:36:20 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-taxes-stats-segmenting.php';
|
2019-01-17 11:14:24 +00:00
|
|
|
|
2018-09-17 14:32:03 +00:00
|
|
|
// Query classes for reports.
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-revenue-query.php';
|
2019-01-15 01:53:02 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-orders-query.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-orders-stats-query.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-products-query.php';
|
2018-11-26 02:58:19 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-variations-query.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-products-stats-query.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-categories-query.php';
|
2018-12-11 00:58:05 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-taxes-query.php';
|
2018-12-11 00:55:05 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-taxes-stats-query.php';
|
2018-12-06 09:40:59 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-coupons-query.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-coupons-stats-query.php';
|
2018-12-21 22:57:46 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-downloads-query.php';
|
2019-01-03 18:00:48 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-downloads-stats-query.php';
|
2018-12-20 01:19:12 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-customers-query.php';
|
2019-01-18 21:35:43 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-customers-stats-query.php';
|
2019-02-14 03:31:27 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-stock-stats-query.php';
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2018-09-20 23:56:35 +00:00
|
|
|
// Data stores.
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-data-store.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-orders-data-store.php';
|
2019-01-15 01:53:02 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-orders-stats-data-store.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-products-data-store.php';
|
2018-11-26 02:58:19 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-variations-data-store.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-products-stats-data-store.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-categories-data-store.php';
|
2018-12-11 00:58:05 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-taxes-data-store.php';
|
2018-12-11 00:55:05 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-taxes-stats-data-store.php';
|
2018-12-06 09:40:59 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-coupons-data-store.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-coupons-stats-data-store.php';
|
2018-12-21 22:57:46 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-downloads-data-store.php';
|
2019-01-03 18:00:48 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-downloads-stats-data-store.php';
|
2018-12-20 01:19:12 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-customers-data-store.php';
|
2019-01-18 21:35:43 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-customers-stats-data-store.php';
|
2019-02-14 03:31:27 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-reports-stock-stats-data-store.php';
|
2018-09-24 17:16:10 +00:00
|
|
|
|
|
|
|
// Data triggers.
|
2018-09-20 23:56:35 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/data-stores/class-wc-admin-notes-data-store.php';
|
|
|
|
|
|
|
|
// CRUD classes.
|
2018-09-21 23:44:04 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-note.php';
|
2018-09-20 23:56:35 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/class-wc-admin-notes.php';
|
2018-09-17 14:32:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* Init REST API.
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
public function rest_api_init() {
|
2018-10-10 23:46:08 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-admin-notes-controller.php';
|
2019-01-18 02:52:58 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-coupons-controller.php';
|
2018-12-22 00:40:41 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-data-controller.php';
|
2019-01-18 19:17:12 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-data-countries-controller.php';
|
2018-12-22 00:40:41 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-data-download-ips-controller.php';
|
2019-01-18 02:52:58 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-orders-controller.php';
|
2018-12-12 13:35:56 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-products-controller.php';
|
2019-01-21 17:12:00 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-product-categories-controller.php';
|
2019-02-05 18:12:58 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-product-variations-controller.php';
|
2018-12-12 13:35:56 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-product-reviews-controller.php';
|
2019-02-04 02:49:58 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-product-variations-controller.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-controller.php';
|
2019-01-31 01:04:11 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-setting-options-controller.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-system-status-tools-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-categories-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-coupons-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-coupons-stats-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-customers-controller.php';
|
2019-01-18 21:35:43 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-customers-stats-controller.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-downloads-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-downloads-files-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-downloads-stats-controller.php';
|
2019-01-15 01:53:02 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-orders-controller.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-orders-stats-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-products-controller.php';
|
2018-11-26 02:58:19 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-variations-controller.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-products-stats-controller.php';
|
2019-01-09 21:08:39 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-performance-indicators-controller.php';
|
2018-09-17 14:54:31 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-revenue-stats-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-taxes-controller.php';
|
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-taxes-stats-controller.php';
|
2018-12-14 15:43:39 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-stock-controller.php';
|
2019-02-14 03:31:27 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-stock-stats-controller.php';
|
2019-01-30 09:43:30 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-taxes-controller.php';
|
2019-02-12 19:06:22 +00:00
|
|
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-customers-controller.php';
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2019-01-09 21:08:39 +00:00
|
|
|
$controllers = apply_filters(
|
|
|
|
'woocommerce_admin_rest_controllers',
|
|
|
|
array(
|
|
|
|
'WC_Admin_REST_Admin_Notes_Controller',
|
2019-01-18 02:52:58 +00:00
|
|
|
'WC_Admin_REST_Coupons_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_Customers_Controller',
|
|
|
|
'WC_Admin_REST_Data_Controller',
|
2019-01-18 19:17:12 +00:00
|
|
|
'WC_Admin_REST_Data_Countries_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_Data_Download_Ips_Controller',
|
2019-01-18 02:52:58 +00:00
|
|
|
'WC_Admin_REST_Orders_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_Products_Controller',
|
2019-01-21 17:12:00 +00:00
|
|
|
'WC_Admin_REST_Product_Categories_Controller',
|
2019-02-05 18:12:58 +00:00
|
|
|
'WC_Admin_REST_Product_Variations_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_Product_Reviews_Controller',
|
2019-02-04 02:49:58 +00:00
|
|
|
'WC_Admin_REST_Product_Variations_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_Reports_Controller',
|
2019-01-31 01:04:11 +00:00
|
|
|
'WC_Admin_REST_Setting_Options_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_System_Status_Tools_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Products_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Variations_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Products_Stats_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Revenue_Stats_Controller',
|
2019-01-15 01:53:02 +00:00
|
|
|
'WC_Admin_REST_Reports_Orders_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_Reports_Orders_Stats_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Categories_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Taxes_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Taxes_Stats_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Coupons_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Coupons_Stats_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Stock_Controller',
|
2019-02-14 03:31:27 +00:00
|
|
|
'WC_Admin_REST_Reports_Stock_Stats_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
'WC_Admin_REST_Reports_Downloads_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Downloads_Stats_Controller',
|
|
|
|
'WC_Admin_REST_Reports_Customers_Controller',
|
2019-01-18 21:35:43 +00:00
|
|
|
'WC_Admin_REST_Reports_Customers_Stats_Controller',
|
2019-01-30 09:43:30 +00:00
|
|
|
'WC_Admin_REST_Taxes_Controller',
|
2019-01-09 21:08:39 +00:00
|
|
|
)
|
2018-09-17 14:32:03 +00:00
|
|
|
);
|
|
|
|
|
2019-01-09 21:08:39 +00:00
|
|
|
// The performance indicators controller must be registered last, after other /stats endpoints have been registered.
|
|
|
|
$controllers[] = 'WC_Admin_REST_Reports_Performance_Indicators_Controller';
|
|
|
|
|
2018-09-17 14:32:03 +00:00
|
|
|
foreach ( $controllers as $controller ) {
|
|
|
|
$this->$controller = new $controller();
|
|
|
|
$this->$controller->register_routes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* Filter REST API endpoints.
|
|
|
|
*
|
|
|
|
* @param array $endpoints List of endpoints.
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-09-18 10:24:43 +00:00
|
|
|
public static function filter_rest_endpoints( $endpoints ) {
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override GET /wc/v4/system_status/tools.
|
|
|
|
if ( isset( $endpoints['/wc/v4/system_status/tools'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools'][1] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools'][0] )
|
|
|
|
&& $endpoints['/wc/v4/system_status/tools'][1]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
2018-09-18 10:24:43 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/system_status/tools'][0] = $endpoints['/wc/v4/system_status/tools'][1];
|
2018-09-18 10:24:43 +00:00
|
|
|
}
|
2019-01-18 02:52:58 +00:00
|
|
|
// // Override GET & PUT for /wc/v4/system_status/tools.
|
|
|
|
if ( isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2] )
|
|
|
|
&& $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
|
|
|
&& $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
2018-09-18 10:24:43 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][0] = $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2];
|
|
|
|
$endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][1] = $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3];
|
2018-09-18 10:24:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override GET /wc/v4/reports.
|
|
|
|
if ( isset( $endpoints['/wc/v4/reports'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/reports'][1] )
|
|
|
|
&& isset( $endpoints['/wc/v4/reports'][0] )
|
|
|
|
&& $endpoints['/wc/v4/reports'][1]['callback'][0] instanceof WC_Admin_REST_Reports_Controller
|
2018-09-18 10:24:43 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/reports'][0] = $endpoints['/wc/v4/reports'][1];
|
2018-09-18 10:24:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/coupons.
|
|
|
|
if ( isset( $endpoints['/wc/v4/coupons'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/coupons'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/coupons'][2] )
|
|
|
|
&& $endpoints['/wc/v4/coupons'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
|
|
|
&& $endpoints['/wc/v4/coupons'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
2018-12-17 16:20:11 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/coupons'][0] = $endpoints['/wc/v4/coupons'][2];
|
|
|
|
$endpoints['/wc/v4/coupons'][1] = $endpoints['/wc/v4/coupons'][3];
|
2018-12-17 16:20:11 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/customers.
|
|
|
|
if ( isset( $endpoints['/wc/v4/customers'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/customers'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/customers'][2] )
|
|
|
|
&& $endpoints['/wc/v4/customers'][2]['callback'][0] instanceof WC_Admin_REST_Customers_Controller
|
|
|
|
&& $endpoints['/wc/v4/customers'][3]['callback'][0] instanceof WC_Admin_REST_Customers_Controller
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/customers'][0] = $endpoints['/wc/v4/customers'][2];
|
|
|
|
$endpoints['/wc/v4/customers'][1] = $endpoints['/wc/v4/customers'][3];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/orders/$id.
|
|
|
|
if ( isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3] )
|
|
|
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
|
|
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
|
|
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][0] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3];
|
|
|
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][1] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4];
|
|
|
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][2] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/orders.
|
|
|
|
if ( isset( $endpoints['/wc/v4/orders'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders'][2] )
|
|
|
|
&& $endpoints['/wc/v4/orders'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
|
|
|
&& $endpoints['/wc/v4/orders'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/orders'][0] = $endpoints['/wc/v4/orders'][2];
|
|
|
|
$endpoints['/wc/v4/orders'][1] = $endpoints['/wc/v4/orders'][3];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/data.
|
|
|
|
if ( isset( $endpoints['/wc/v4/data'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/data'][1] )
|
|
|
|
&& $endpoints['/wc/v4/data'][1]['callback'][0] instanceof WC_Admin_REST_Data_Controller
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/data'][0] = $endpoints['/wc/v4/data'][1];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/products.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products'][2] )
|
|
|
|
&& $endpoints['/wc/v4/products'][2]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
|
|
|
&& $endpoints['/wc/v4/products'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
2018-12-12 13:35:56 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/products'][0] = $endpoints['/wc/v4/products'][2];
|
|
|
|
$endpoints['/wc/v4/products'][1] = $endpoints['/wc/v4/products'][3];
|
2018-12-12 13:35:56 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/products/$id.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3] )
|
|
|
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
|
|
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
|
|
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
2018-12-12 13:35:56 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][0] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3];
|
|
|
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][1] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4];
|
|
|
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][2] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5];
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:12:00 +00:00
|
|
|
// Override /wc/v4/products/categories.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products/categories'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/categories'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/categories'][2] )
|
|
|
|
&& $endpoints['/wc/v4/products/categories'][2]['callback'][0] instanceof WC_Admin_REST_Product_categories_Controller
|
|
|
|
&& $endpoints['/wc/v4/products/categories'][3]['callback'][0] instanceof WC_Admin_REST_Product_categories_Controller
|
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/products/categories'][0] = $endpoints['/wc/v4/products/categories'][2];
|
|
|
|
$endpoints['/wc/v4/products/categories'][1] = $endpoints['/wc/v4/products/categories'][3];
|
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/products/reviews.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products/reviews'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/reviews'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/reviews'][2] )
|
|
|
|
&& $endpoints['/wc/v4/products/reviews'][2]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller
|
|
|
|
&& $endpoints['/wc/v4/products/reviews'][3]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller
|
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/products/reviews'][0] = $endpoints['/wc/v4/products/reviews'][2];
|
|
|
|
$endpoints['/wc/v4/products/reviews'][1] = $endpoints['/wc/v4/products/reviews'][3];
|
2018-12-12 13:35:56 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 02:49:58 +00:00
|
|
|
// Override /wc/v4/products/$product_id/variations.
|
|
|
|
if ( isset( $endpoints['products/(?P<product_id>[\d]+)/variations'] )
|
|
|
|
&& isset( $endpoints['products/(?P<product_id>[\d]+)/variations'][3] )
|
|
|
|
&& isset( $endpoints['products/(?P<product_id>[\d]+)/variations'][2] )
|
|
|
|
&& $endpoints['products/(?P<product_id>[\d]+)/variations'][2]['callback'][0] instanceof WC_Admin_REST_Product_Variations_Controller
|
|
|
|
&& $endpoints['products/(?P<product_id>[\d]+)/variations'][3]['callback'][0] instanceof WC_Admin_REST_Product_Variations_Controller
|
|
|
|
) {
|
|
|
|
$endpoints['products/(?P<product_id>[\d]+)/variations'][0] = $endpoints['products/(?P<product_id>[\d]+)/variations'][2];
|
|
|
|
$endpoints['products/(?P<product_id>[\d]+)/variations'][1] = $endpoints['products/(?P<product_id>[\d]+)/variations'][3];
|
|
|
|
}
|
|
|
|
|
2019-01-30 09:43:30 +00:00
|
|
|
// Override /wc/v4/taxes.
|
|
|
|
if ( isset( $endpoints['/wc/v4/taxes'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/taxes'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/taxes'][2] )
|
|
|
|
&& $endpoints['/wc/v4/taxes'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
|
|
|
&& $endpoints['/wc/v4/taxes'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/taxes'][0] = $endpoints['/wc/v4/taxes'][2];
|
|
|
|
$endpoints['/wc/v4/taxes'][1] = $endpoints['/wc/v4/taxes'][3];
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:04:11 +00:00
|
|
|
// Override /wc/v4/settings/$group_id.
|
|
|
|
if ( isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][5] )
|
|
|
|
&& isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][4] )
|
|
|
|
&& isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][3] )
|
|
|
|
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller
|
|
|
|
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][4]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller
|
|
|
|
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][5]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller
|
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][0] = $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][3];
|
|
|
|
$endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][1] = $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][4];
|
|
|
|
$endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][2] = $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][5];
|
|
|
|
}
|
|
|
|
|
2018-09-18 10:24:43 +00:00
|
|
|
return $endpoints;
|
|
|
|
}
|
|
|
|
|
2018-09-21 10:24:15 +00:00
|
|
|
/**
|
2018-09-18 19:41:45 +00:00
|
|
|
* Adds data stores.
|
|
|
|
*
|
|
|
|
* @param array $data_stores List of data stores.
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
public static function add_data_stores( $data_stores ) {
|
|
|
|
return array_merge(
|
|
|
|
$data_stores,
|
|
|
|
array(
|
2019-02-14 03:31:27 +00:00
|
|
|
'report-revenue-stats' => 'WC_Admin_Reports_Orders_Stats_Data_Store',
|
|
|
|
'report-orders' => 'WC_Admin_Reports_Orders_Data_Store',
|
|
|
|
'report-orders-stats' => 'WC_Admin_Reports_Orders_Stats_Data_Store',
|
|
|
|
'report-products' => 'WC_Admin_Reports_Products_Data_Store',
|
|
|
|
'report-variations' => 'WC_Admin_Reports_Variations_Data_Store',
|
|
|
|
'report-products-stats' => 'WC_Admin_Reports_Products_Stats_Data_Store',
|
|
|
|
'report-categories' => 'WC_Admin_Reports_Categories_Data_Store',
|
|
|
|
'report-taxes' => 'WC_Admin_Reports_Taxes_Data_Store',
|
|
|
|
'report-taxes-stats' => 'WC_Admin_Reports_Taxes_Stats_Data_Store',
|
|
|
|
'report-coupons' => 'WC_Admin_Reports_Coupons_Data_Store',
|
|
|
|
'report-coupons-stats' => 'WC_Admin_Reports_Coupons_Stats_Data_Store',
|
|
|
|
'report-downloads' => 'WC_Admin_Reports_Downloads_Data_Store',
|
2019-01-03 18:00:48 +00:00
|
|
|
'report-downloads-stats' => 'WC_Admin_Reports_Downloads_Stats_Data_Store',
|
2019-01-09 21:08:39 +00:00
|
|
|
'admin-note' => 'WC_Admin_Notes_Data_Store',
|
|
|
|
'report-customers' => 'WC_Admin_Reports_Customers_Data_Store',
|
2019-01-18 21:35:43 +00:00
|
|
|
'report-customers-stats' => 'WC_Admin_Reports_Customers_Stats_Data_Store',
|
2019-02-14 03:31:27 +00:00
|
|
|
'report-stock-stats' => 'WC_Admin_Reports_Stock_Stats_Data_Store',
|
2018-09-17 14:32:03 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-17 07:01:09 +00:00
|
|
|
/**
|
|
|
|
* Add the currency symbol (in addition to currency code) to each Order
|
|
|
|
* object in REST API responses. For use in formatCurrency().
|
|
|
|
*
|
|
|
|
* @param {WP_REST_Response} $response REST response object.
|
|
|
|
* @returns {WP_REST_Response}
|
|
|
|
*/
|
|
|
|
public static function add_currency_symbol_to_order_response( $response ) {
|
|
|
|
$response_data = $response->get_data();
|
|
|
|
$currency_code = $response_data['currency'];
|
|
|
|
$currency_symbol = get_woocommerce_currency_symbol( $currency_code );
|
|
|
|
$response_data['currency_symbol'] = html_entity_decode( $currency_symbol );
|
|
|
|
$response->set_data( $response_data );
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2018-09-17 14:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
new WC_Admin_Api_Init();
|