PSR4-ify core API subclasses.

This commit is contained in:
Jeff Stieler 2019-08-02 12:54:09 -06:00
parent fe3dc0dd7c
commit b71d8c23c8
19 changed files with 131 additions and 95 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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();

View File

@ -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',

View File

@ -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' ),
),

View File

@ -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 ) {

View File

@ -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',
),
),

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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 ) ) {

View File

@ -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<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
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
) {
$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];
@ -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<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
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
) {
$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];
@ -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<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'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations
&& $endpoints['products/(?P<product_id>[\d]+)/variations'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations
) {
$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];
@ -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<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-]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions
) {
$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];

View File

@ -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 );
}