From b71d8c23c8194c593aa5867ad6aae643fb680fd7 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Fri, 2 Aug 2019 12:54:09 -0600 Subject: [PATCH] PSR4-ify core API subclasses. --- .../API/Coupons.php} | 4 +- .../API/Customers.php} | 4 +- .../API/Data.php} | 4 +- .../API/DataCountries.php} | 4 +- .../API/DataDownloadIPs.php} | 8 +- .../API/Leaderboards.php} | 16 ++-- .../API/OnboardingLevels.php} | 6 +- .../API/OnboardingPlugins.php} | 30 ++++--- .../API/OnboardingProfile.php} | 16 ++-- .../API/Orders.php} | 4 +- .../API/ProductCategories.php} | 4 +- .../API/ProductReviews.php} | 4 +- .../API/ProductVariations.php} | 4 +- .../API/Products.php} | 4 +- .../API/SettingOptions.php} | 4 +- .../API/Taxes.php} | 4 +- .../API/Themes.php} | 14 +-- .../src/API/WC_Admin_Api_Init.php | 88 +++++++++---------- .../tests/api/onboarding-profile.php | 4 +- 19 files changed, 131 insertions(+), 95 deletions(-) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-coupons-controller.php => src/API/Coupons.php} (95%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-customers-controller.php => src/API/Customers.php} (89%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-data-controller.php => src/API/Data.php} (90%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-data-countries-controller.php => src/API/DataCountries.php} (78%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-data-download-ips-controller.php => src/API/DataDownloadIPs.php} (91%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-leaderboards-controller.php => src/API/Leaderboards.php} (96%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-onboarding-levels-controller.php => src/API/OnboardingLevels.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-onboarding-plugins-controller.php => src/API/OnboardingPlugins.php} (88%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-onboarding-profile-controller.php => src/API/OnboardingProfile.php} (94%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-orders-controller.php => src/API/Orders.php} (95%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-product-categories-controller.php => src/API/ProductCategories.php} (76%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-product-reviews-controller.php => src/API/ProductReviews.php} (91%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-product-variations-controller.php => src/API/ProductVariations.php} (96%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-products-controller.php => src/API/Products.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-setting-options-controller.php => src/API/SettingOptions.php} (77%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-taxes-controller.php => src/API/Taxes.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-themes-controller.php => src/API/Themes.php} (89%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-coupons-controller.php b/plugins/woocommerce-admin/src/API/Coupons.php similarity index 95% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-coupons-controller.php rename to plugins/woocommerce-admin/src/API/Coupons.php index dfde5b3ae8a..5107077bf45 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-coupons-controller.php +++ b/plugins/woocommerce-admin/src/API/Coupons.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Coupons_Controller */ -class WC_Admin_REST_Coupons_Controller extends WC_REST_Coupons_Controller { +class Coupons extends \WC_REST_Coupons_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-customers-controller.php b/plugins/woocommerce-admin/src/API/Customers.php similarity index 89% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-customers-controller.php rename to plugins/woocommerce-admin/src/API/Customers.php index d7cc898c812..ee76e5fd42e 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-customers-controller.php +++ b/plugins/woocommerce-admin/src/API/Customers.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_Admin_REST_Reports_Customers_Controller */ -class WC_Admin_REST_Customers_Controller extends WC_Admin_REST_Reports_Customers_Controller { +class Customers extends \WC_Admin_REST_Reports_Customers_Controller { /** * Route base. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-controller.php b/plugins/woocommerce-admin/src/API/Data.php similarity index 90% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-controller.php rename to plugins/woocommerce-admin/src/API/Data.php index d83006728ce..729ca36b073 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-controller.php +++ b/plugins/woocommerce-admin/src/API/Data.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Data_Controller extends WC_REST_Data_Controller { +class Data extends \WC_REST_Data_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-countries-controller.php b/plugins/woocommerce-admin/src/API/DataCountries.php similarity index 78% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-countries-controller.php rename to plugins/woocommerce-admin/src/API/DataCountries.php index f4f7ea0bda8..4916f67cbd5 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-countries-controller.php +++ b/plugins/woocommerce-admin/src/API/DataCountries.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Countries_Controller */ -class WC_Admin_REST_Data_Countries_Controller extends WC_REST_Data_Countries_Controller { +class DataCountries extends \WC_REST_Data_Countries_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-download-ips-controller.php b/plugins/woocommerce-admin/src/API/DataDownloadIPs.php similarity index 91% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-download-ips-controller.php rename to plugins/woocommerce-admin/src/API/DataDownloadIPs.php index 8f264f0d417..b1a5a2c0563 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-download-ips-controller.php +++ b/plugins/woocommerce-admin/src/API/DataDownloadIPs.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller { +class DataDownloadIPs extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -41,7 +43,7 @@ class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), @@ -70,7 +72,7 @@ class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller ) ); } else { - return new WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce-admin' ), array( 'status' => 400 ) ); + return new \WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce-admin' ), array( 'status' => 400 ) ); } $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-leaderboards-controller.php b/plugins/woocommerce-admin/src/API/Leaderboards.php similarity index 96% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-leaderboards-controller.php rename to plugins/woocommerce-admin/src/API/Leaderboards.php index 514be3adb95..2d6839b52d2 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-leaderboards-controller.php +++ b/plugins/woocommerce-admin/src/API/Leaderboards.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { +class Leaderboards extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -39,7 +41,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -53,7 +55,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { '/' . $this->rest_base . '/allowed', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_allowed_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), @@ -71,7 +73,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { * @param string $persisted_query URL query string. */ public function get_coupons_leaderboard( $per_page, $after, $before, $persisted_query ) { - $coupons_data_store = new WC_Admin_Reports_Coupons_Data_Store(); + $coupons_data_store = new \WC_Admin_Reports_Coupons_Data_Store(); $coupons_data = $per_page > 0 ? $coupons_data_store->get_data( array( 'orderby' => 'orders_count', @@ -137,7 +139,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { * @param string $persisted_query URL query string. */ public function get_categories_leaderboard( $per_page, $after, $before, $persisted_query ) { - $categories_data_store = new WC_Admin_Reports_Categories_Data_Store(); + $categories_data_store = new \WC_Admin_Reports_Categories_Data_Store(); $categories_data = $per_page > 0 ? $categories_data_store->get_data( array( 'orderby' => 'items_sold', @@ -203,7 +205,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { * @param string $persisted_query URL query string. */ public function get_customers_leaderboard( $per_page, $after, $before, $persisted_query ) { - $customers_data_store = new WC_Admin_Reports_Customers_Data_Store(); + $customers_data_store = new \WC_Admin_Reports_Customers_Data_Store(); $customers_data = $per_page > 0 ? $customers_data_store->get_data( array( 'orderby' => 'total_spend', @@ -267,7 +269,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { * @param string $persisted_query URL query string. */ public function get_products_leaderboard( $per_page, $after, $before, $persisted_query ) { - $products_data_store = new WC_Admin_Reports_Products_Data_Store(); + $products_data_store = new \WC_Admin_Reports_Products_Data_Store(); $products_data = $per_page > 0 ? $products_data_store->get_data( array( 'orderby' => 'items_sold', diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-levels-controller.php b/plugins/woocommerce-admin/src/API/OnboardingLevels.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-levels-controller.php rename to plugins/woocommerce-admin/src/API/OnboardingLevels.php index 29622add12e..8a16c9bafdf 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-levels-controller.php +++ b/plugins/woocommerce-admin/src/API/OnboardingLevels.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Onboarding_Levels_Controller extends WC_REST_Data_Controller { +class OnboardingLevels extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -39,7 +41,7 @@ class WC_Admin_REST_Onboarding_Levels_Controller extends WC_REST_Data_Controller '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-plugins-controller.php b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php similarity index 88% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-plugins-controller.php rename to plugins/woocommerce-admin/src/API/OnboardingPlugins.php index b222447b6f0..e999d9d232d 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-plugins-controller.php +++ b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controller { +class OnboardingPlugins extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -39,7 +41,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base . '/install', array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'install_plugin' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), ), @@ -52,7 +54,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base . '/activate', array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'activate_plugin' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), ), @@ -65,7 +67,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base . '/connect-jetpack', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'connect_jetpack' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), ), @@ -108,7 +110,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle */ public function update_item_permissions_check( $request ) { if ( ! current_user_can( 'install_plugins' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot manage plugins.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot manage plugins.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } @@ -136,7 +138,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle $allowed_plugins = $this->get_allowed_plugins(); $plugin = sanitize_title_with_dashes( $request['plugin'] ); if ( ! in_array( $plugin, array_keys( $allowed_plugins ), true ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); } require_once ABSPATH . 'wp-admin/includes/plugin.php'; @@ -170,14 +172,14 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle ); if ( is_wp_error( $api ) ) { - return new WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); + return new \WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); } - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); + $upgrader = new \Plugin_Upgrader( new \Automatic_Upgrader_Skin() ); $result = $upgrader->install( $api->download_link ); if ( is_wp_error( $result ) || is_null( $result ) ) { - return new WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); + return new \WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); } return array( @@ -197,7 +199,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle $allowed_plugins = $this->get_allowed_plugins(); $plugin = sanitize_title_with_dashes( $request['plugin'] ); if ( ! in_array( $plugin, array_keys( $allowed_plugins ), true ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); } require_once ABSPATH . 'wp-admin/includes/plugin.php'; @@ -207,12 +209,12 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle $installed_plugins = get_plugins(); if ( ! in_array( $path, array_keys( $installed_plugins ), true ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); } $result = activate_plugin( $path ); if ( ! is_null( $result ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'The requested plugin could not be activated.', 'woocommerce-admin' ), 500 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'The requested plugin could not be activated.', 'woocommerce-admin' ), 500 ); } return( array( @@ -229,7 +231,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle */ public function connect_jetpack() { if ( ! class_exists( 'Jetpack' ) ) { - return new WP_Error( 'woocommerce_rest_jetpack_not_active', __( 'Jetpack is not installed or active.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_jetpack_not_active', __( 'Jetpack is not installed or active.', 'woocommerce-admin' ), 404 ); } $next_step_slug = apply_filters( 'woocommerce_onboarding_after_jetpack_step', 'store-details' ); @@ -243,7 +245,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle ) ); - $connect_url = Jetpack::init()->build_connect_url( true, $redirect_url, 'woocommerce-setup-wizard' ); + $connect_url = \Jetpack::init()->build_connect_url( true, $redirect_url, 'woocommerce-setup-wizard' ); // Redirect to local calypso instead of production. if ( defined( 'WOOCOMMERCE_CALYPSO_LOCAL' ) && WOOCOMMERCE_CALYPSO_LOCAL ) { diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php b/plugins/woocommerce-admin/src/API/OnboardingProfile.php similarity index 94% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php rename to plugins/woocommerce-admin/src/API/OnboardingProfile.php index 09acb7a202a..268ed3bf103 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php +++ b/plugins/woocommerce-admin/src/API/OnboardingProfile.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\Features\WC_Admin_Onboarding; @@ -17,7 +19,7 @@ use Automattic\WooCommerce\Admin\Features\WC_Admin_Onboarding; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controller { +class OnboardingProfile extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -41,7 +43,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), @@ -53,7 +55,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_items' ), 'permission_callback' => array( $this, 'update_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -71,7 +73,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle */ public function get_items_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -85,7 +87,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle */ public function update_items_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -234,7 +236,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle 'sanitize_callback' => 'wp_parse_slug_list', 'validate_callback' => 'rest_validate_request_arg', 'items' => array( - 'enum' => array_keys( WC_Admin_Onboarding::get_allowed_industries() ), + 'enum' => array_keys( \WC_Admin_Onboarding::get_allowed_industries() ), 'type' => 'string', ), ), @@ -246,7 +248,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle 'sanitize_callback' => 'wp_parse_slug_list', 'validate_callback' => 'rest_validate_request_arg', 'items' => array( - 'enum' => array_keys( WC_Admin_Onboarding::get_allowed_product_types() ), + 'enum' => array_keys( \WC_Admin_Onboarding::get_allowed_product_types() ), 'type' => 'string', ), ), diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-orders-controller.php b/plugins/woocommerce-admin/src/API/Orders.php similarity index 95% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-orders-controller.php rename to plugins/woocommerce-admin/src/API/Orders.php index e9f13eb08f3..e358202b407 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-orders-controller.php +++ b/plugins/woocommerce-admin/src/API/Orders.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Orders_Controller */ -class WC_Admin_REST_Orders_Controller extends WC_REST_Orders_Controller { +class Orders extends \WC_REST_Orders_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-categories-controller.php b/plugins/woocommerce-admin/src/API/ProductCategories.php similarity index 76% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-categories-controller.php rename to plugins/woocommerce-admin/src/API/ProductCategories.php index 672cd0c22ca..efa01a517bc 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-categories-controller.php +++ b/plugins/woocommerce-admin/src/API/ProductCategories.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Product_Categories_Controller */ -class WC_Admin_REST_Product_Categories_Controller extends WC_REST_Product_Categories_Controller { +class ProductCategories extends \WC_REST_Product_Categories_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-reviews-controller.php b/plugins/woocommerce-admin/src/API/ProductReviews.php similarity index 91% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-reviews-controller.php rename to plugins/woocommerce-admin/src/API/ProductReviews.php index ba3fc9245f4..7ce0a811c25 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-reviews-controller.php +++ b/plugins/woocommerce-admin/src/API/ProductReviews.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Product_Reviews_Controller */ -class WC_Admin_REST_Product_Reviews_Controller extends WC_REST_Product_Reviews_Controller { +class ProductReviews extends \WC_REST_Product_Reviews_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-variations-controller.php b/plugins/woocommerce-admin/src/API/ProductVariations.php similarity index 96% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-variations-controller.php rename to plugins/woocommerce-admin/src/API/ProductVariations.php index 92f4d866a28..0ec84ae0709 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-variations-controller.php +++ b/plugins/woocommerce-admin/src/API/ProductVariations.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Product_Variations_Controller */ -class WC_Admin_REST_Product_Variations_Controller extends WC_REST_Product_Variations_Controller { +class ProductVariations extends \WC_REST_Product_Variations_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-products-controller.php b/plugins/woocommerce-admin/src/API/Products.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-products-controller.php rename to plugins/woocommerce-admin/src/API/Products.php index 1ed532c6320..2c3b2363905 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-products-controller.php +++ b/plugins/woocommerce-admin/src/API/Products.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Products_Controller */ -class WC_Admin_REST_Products_Controller extends WC_REST_Products_Controller { +class Products extends \WC_REST_Products_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-setting-options-controller.php b/plugins/woocommerce-admin/src/API/SettingOptions.php similarity index 77% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-setting-options-controller.php rename to plugins/woocommerce-admin/src/API/SettingOptions.php index bfa1a2fe6ec..64567cbc492 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-setting-options-controller.php +++ b/plugins/woocommerce-admin/src/API/SettingOptions.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Setting_Options_Controller */ -class WC_Admin_REST_Setting_Options_Controller extends WC_REST_Setting_Options_Controller { +class SettingOptions extends \WC_REST_Setting_Options_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-taxes-controller.php b/plugins/woocommerce-admin/src/API/Taxes.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-taxes-controller.php rename to plugins/woocommerce-admin/src/API/Taxes.php index 06698aa8eb1..3a1560a7610 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-taxes-controller.php +++ b/plugins/woocommerce-admin/src/API/Taxes.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Taxes_Controller */ -class WC_Admin_REST_Taxes_Controller extends WC_REST_Taxes_Controller { +class Taxes extends \WC_REST_Taxes_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php b/plugins/woocommerce-admin/src/API/Themes.php similarity index 89% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php rename to plugins/woocommerce-admin/src/API/Themes.php index 9f5e2812bdb..82163b211a6 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php +++ b/plugins/woocommerce-admin/src/API/Themes.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader; @@ -18,7 +20,7 @@ use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader_Skin; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { +class Themes extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -42,7 +44,7 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'upload_theme' ), 'permission_callback' => array( $this, 'upload_theme_permissions_check' ), 'args' => $this->get_collection_params(), @@ -60,7 +62,7 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { */ public function upload_theme_permissions_check( $request ) { if ( ! current_user_can( 'upload_themes' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you are not allowed to install themes on this site.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you are not allowed to install themes on this site.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -74,7 +76,7 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { */ public function upload_theme( $request ) { if ( ! isset( $_FILES['pluginzip'] ) || ! is_uploaded_file( $_FILES['pluginzip']['tmp_name'] ) || ! is_file( $_FILES['pluginzip']['tmp_name'] ) ) { // WPCS: sanitization ok. - return new WP_Error( 'woocommerce_rest_invalid_file', __( 'Specified file failed upload test.', 'woocommerce-admin' ) ); + return new \WP_Error( 'woocommerce_rest_invalid_file', __( 'Specified file failed upload test.', 'woocommerce-admin' ) ); } include_once ABSPATH . 'wp-admin/includes/file.php'; @@ -83,8 +85,8 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { include_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-theme-upgrader-skin.php'; $_GET['package'] = true; - $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' ); - $upgrader = new WC_Admin_Theme_Upgrader( new WC_Admin_Theme_Upgrader_Skin() ); + $file_upload = new \File_Upload_Upgrader( 'pluginzip', 'package' ); + $upgrader = new \WC_Admin_Theme_Upgrader( new \WC_Admin_Theme_Upgrader_Skin() ); $install = $upgrader->install( $file_upload->package ); if ( $install || is_wp_error( $install ) ) { diff --git a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php index 47b1481e6a1..60f17b85c1c 100644 --- a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php +++ b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php @@ -35,20 +35,20 @@ class WC_Admin_Api_Init { $controllers = array( 'Automattic\WooCommerce\Admin\API\Notes', 'Automattic\WooCommerce\Admin\API\NoteActions', - 'WC_Admin_REST_Coupons_Controller', - 'WC_Admin_REST_Customers_Controller', - 'WC_Admin_REST_Data_Controller', - 'WC_Admin_REST_Data_Countries_Controller', - 'WC_Admin_REST_Data_Download_Ips_Controller', - 'WC_Admin_REST_Leaderboards_Controller', - 'WC_Admin_REST_Orders_Controller', - 'WC_Admin_REST_Products_Controller', - 'WC_Admin_REST_Product_Categories_Controller', - 'WC_Admin_REST_Product_Variations_Controller', - 'WC_Admin_REST_Product_Reviews_Controller', - 'WC_Admin_REST_Product_Variations_Controller', + 'Automattic\WooCommerce\Admin\API\Coupons', + 'Automattic\WooCommerce\Admin\API\Customers', + 'Automattic\WooCommerce\Admin\API\Data', + 'Automattic\WooCommerce\Admin\API\DataCountries', + 'Automattic\WooCommerce\Admin\API\DataDownloadIPs', + 'Automattic\WooCommerce\Admin\API\Leaderboards', + 'Automattic\WooCommerce\Admin\API\Orders', + 'Automattic\WooCommerce\Admin\API\Products', + 'Automattic\WooCommerce\Admin\API\ProductCategories', + 'Automattic\WooCommerce\Admin\API\ProductVariations', + 'Automattic\WooCommerce\Admin\API\ProductReviews', + 'Automattic\WooCommerce\Admin\API\ProductVariations', 'WC_Admin_REST_Reports_Controller', - 'WC_Admin_REST_Setting_Options_Controller', + 'Automattic\WooCommerce\Admin\API\SettingOptions', 'WC_Admin_REST_Reports_Import_Controller', 'WC_Admin_REST_Reports_Export_Controller', 'WC_Admin_REST_Reports_Products_Controller', @@ -68,17 +68,17 @@ class WC_Admin_Api_Init { 'WC_Admin_REST_Reports_Downloads_Stats_Controller', 'WC_Admin_REST_Reports_Customers_Controller', 'WC_Admin_REST_Reports_Customers_Stats_Controller', - 'WC_Admin_REST_Taxes_Controller', - 'WC_Admin_REST_Themes_Controller', + 'Automattic\WooCommerce\Admin\API\Taxes', + 'Automattic\WooCommerce\Admin\API\Themes', ); if ( \WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { $controllers = array_merge( $controllers, array( - 'WC_Admin_REST_Onboarding_Levels_Controller', - 'WC_Admin_REST_Onboarding_Profile_Controller', - 'WC_Admin_REST_Onboarding_Plugins_Controller', + 'Automattic\WooCommerce\Admin\API\OnboardingLevels', + 'Automattic\WooCommerce\Admin\API\OnboardingProfile', + 'Automattic\WooCommerce\Admin\API\OnboardingPlugins', ) ); } @@ -133,8 +133,8 @@ class WC_Admin_Api_Init { 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 + && $endpoints['/wc/v4/coupons'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/coupons'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/coupons'][0] = $endpoints['/wc/v4/coupons'][2]; $endpoints['/wc/v4/coupons'][1] = $endpoints['/wc/v4/coupons'][3]; @@ -144,8 +144,8 @@ class WC_Admin_Api_Init { 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 + && $endpoints['/wc/v4/customers'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Customers + && $endpoints['/wc/v4/customers'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Customers ) { $endpoints['/wc/v4/customers'][0] = $endpoints['/wc/v4/customers'][2]; $endpoints['/wc/v4/customers'][1] = $endpoints['/wc/v4/customers'][3]; @@ -156,9 +156,9 @@ class WC_Admin_Api_Init { && isset( $endpoints['/wc/v4/orders/(?P[\d]+)'][5] ) && isset( $endpoints['/wc/v4/orders/(?P[\d]+)'][4] ) && isset( $endpoints['/wc/v4/orders/(?P[\d]+)'][3] ) - && $endpoints['/wc/v4/orders/(?P[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller - && $endpoints['/wc/v4/orders/(?P[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Orders_Controller - && $endpoints['/wc/v4/orders/(?P[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Orders_Controller + && $endpoints['/wc/v4/orders/(?P[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/orders/(?P[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/orders/(?P[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/orders/(?P[\d]+)'][0] = $endpoints['/wc/v4/orders/(?P[\d]+)'][3]; $endpoints['/wc/v4/orders/(?P[\d]+)'][1] = $endpoints['/wc/v4/orders/(?P[\d]+)'][4]; @@ -169,8 +169,8 @@ class WC_Admin_Api_Init { 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 + && $endpoints['/wc/v4/orders'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/orders'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/orders'][0] = $endpoints['/wc/v4/orders'][2]; $endpoints['/wc/v4/orders'][1] = $endpoints['/wc/v4/orders'][3]; @@ -179,7 +179,7 @@ class WC_Admin_Api_Init { // 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 + && $endpoints['/wc/v4/data'][1]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Data ) { $endpoints['/wc/v4/data'][0] = $endpoints['/wc/v4/data'][1]; } @@ -188,8 +188,8 @@ class WC_Admin_Api_Init { 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 + && $endpoints['/wc/v4/products'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products + && $endpoints['/wc/v4/products'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products ) { $endpoints['/wc/v4/products'][0] = $endpoints['/wc/v4/products'][2]; $endpoints['/wc/v4/products'][1] = $endpoints['/wc/v4/products'][3]; @@ -200,9 +200,9 @@ class WC_Admin_Api_Init { && isset( $endpoints['/wc/v4/products/(?P[\d]+)'][5] ) && isset( $endpoints['/wc/v4/products/(?P[\d]+)'][4] ) && isset( $endpoints['/wc/v4/products/(?P[\d]+)'][3] ) - && $endpoints['/wc/v4/products/(?P[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller - && $endpoints['/wc/v4/products/(?P[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Products_Controller - && $endpoints['/wc/v4/products/(?P[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Products_Controller + && $endpoints['/wc/v4/products/(?P[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products + && $endpoints['/wc/v4/products/(?P[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products + && $endpoints['/wc/v4/products/(?P[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products ) { $endpoints['/wc/v4/products/(?P[\d]+)'][0] = $endpoints['/wc/v4/products/(?P[\d]+)'][3]; $endpoints['/wc/v4/products/(?P[\d]+)'][1] = $endpoints['/wc/v4/products/(?P[\d]+)'][4]; @@ -213,8 +213,8 @@ class WC_Admin_Api_Init { 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'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductCategories + && $endpoints['/wc/v4/products/categories'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductCategories ) { $endpoints['/wc/v4/products/categories'][0] = $endpoints['/wc/v4/products/categories'][2]; $endpoints['/wc/v4/products/categories'][1] = $endpoints['/wc/v4/products/categories'][3]; @@ -224,8 +224,8 @@ class WC_Admin_Api_Init { 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'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductReviews + && $endpoints['/wc/v4/products/reviews'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductReviews ) { $endpoints['/wc/v4/products/reviews'][0] = $endpoints['/wc/v4/products/reviews'][2]; $endpoints['/wc/v4/products/reviews'][1] = $endpoints['/wc/v4/products/reviews'][3]; @@ -235,8 +235,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['products/(?P[\d]+)/variations'] ) && isset( $endpoints['products/(?P[\d]+)/variations'][3] ) && isset( $endpoints['products/(?P[\d]+)/variations'][2] ) - && $endpoints['products/(?P[\d]+)/variations'][2]['callback'][0] instanceof WC_Admin_REST_Product_Variations_Controller - && $endpoints['products/(?P[\d]+)/variations'][3]['callback'][0] instanceof WC_Admin_REST_Product_Variations_Controller + && $endpoints['products/(?P[\d]+)/variations'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations + && $endpoints['products/(?P[\d]+)/variations'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations ) { $endpoints['products/(?P[\d]+)/variations'][0] = $endpoints['products/(?P[\d]+)/variations'][2]; $endpoints['products/(?P[\d]+)/variations'][1] = $endpoints['products/(?P[\d]+)/variations'][3]; @@ -246,8 +246,8 @@ class WC_Admin_Api_Init { 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'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/taxes'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/taxes'][0] = $endpoints['/wc/v4/taxes'][2]; $endpoints['/wc/v4/taxes'][1] = $endpoints['/wc/v4/taxes'][3]; @@ -258,9 +258,9 @@ class WC_Admin_Api_Init { && isset( $endpoints['/wc/v4/settings/(?P[\w-]+)'][5] ) && isset( $endpoints['/wc/v4/settings/(?P[\w-]+)'][4] ) && isset( $endpoints['/wc/v4/settings/(?P[\w-]+)'][3] ) - && $endpoints['/wc/v4/settings/(?P[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller - && $endpoints['/wc/v4/settings/(?P[\w-]+)'][4]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller - && $endpoints['/wc/v4/settings/(?P[\w-]+)'][5]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller + && $endpoints['/wc/v4/settings/(?P[\w-]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions + && $endpoints['/wc/v4/settings/(?P[\w-]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions + && $endpoints['/wc/v4/settings/(?P[\w-]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions ) { $endpoints['/wc/v4/settings/(?P[\w-]+)'][0] = $endpoints['/wc/v4/settings/(?P[\w-]+)'][3]; $endpoints['/wc/v4/settings/(?P[\w-]+)'][1] = $endpoints['/wc/v4/settings/(?P[\w-]+)'][4]; diff --git a/plugins/woocommerce-admin/tests/api/onboarding-profile.php b/plugins/woocommerce-admin/tests/api/onboarding-profile.php index cf75477a02a..1baf66c889e 100644 --- a/plugins/woocommerce-admin/tests/api/onboarding-profile.php +++ b/plugins/woocommerce-admin/tests/api/onboarding-profile.php @@ -5,6 +5,8 @@ * @package WooCommerce Admin\Tests\API */ +use \Automattic\WooCommerce\Admin\API\OnboardingProfile; + /** * WC Tests API Onboarding Profile */ @@ -42,7 +44,7 @@ class WC_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case { $this->assertEquals( 200, $response->get_status() ); - $properties = WC_Admin_REST_Onboarding_Profile_Controller::get_profile_properties(); + $properties = OnboardingProfile::get_profile_properties(); foreach ( $properties as $key => $property ) { $this->assertArrayHasKey( $key, $properties ); }