diff --git a/plugins/woocommerce/src/Admin/API/Reports/AbstractController.php b/plugins/woocommerce/src/Admin/API/Reports/AbstractController.php index bcb58a914cd..4af587c7e75 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/AbstractController.php +++ b/plugins/woocommerce/src/Admin/API/Reports/AbstractController.php @@ -57,4 +57,67 @@ abstract class AbstractController extends \WC_REST_Reports_Controller { return $response; } + + /** + * Get the query params for collections. + * + * @return array + */ + public function get_collection_params() { + $params = array(); + $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); + $params['page'] = array( + 'description' => __( 'Current page of the collection.', 'woocommerce' ), + 'type' => 'integer', + 'default' => 1, + 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', + 'minimum' => 1, + ); + $params['per_page'] = array( + 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), + 'type' => 'integer', + 'default' => 10, + 'minimum' => 1, + 'maximum' => 100, + 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', + ); + $params['after'] = array( + 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), + 'type' => 'string', + 'format' => 'date-time', + 'validate_callback' => 'rest_validate_request_arg', + ); + $params['before'] = array( + 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), + 'type' => 'string', + 'format' => 'date-time', + 'validate_callback' => 'rest_validate_request_arg', + ); + $params['order'] = array( + 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), + 'type' => 'string', + 'default' => 'desc', + 'enum' => array( 'asc', 'desc' ), + 'validate_callback' => 'rest_validate_request_arg', + ); + $params['orderby'] = array( + 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), + 'type' => 'string', + 'default' => 'date', + 'enum' => array( + 'date', + ), + 'validate_callback' => 'rest_validate_request_arg', + ); + $params['force_cache_refresh'] = array( + 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), + 'type' => 'boolean', + 'sanitize_callback' => 'wp_validate_boolean', + 'validate_callback' => 'rest_validate_request_arg', + ); + + return $params; + } } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Coupons/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Coupons/Controller.php index 6c6f9b27d36..9705868edc0 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Coupons/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Coupons/Controller.php @@ -201,55 +201,13 @@ class Controller extends AbstractController implements ExportableInterface { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'coupon_id', - 'enum' => array( - 'coupon_id', - 'code', - 'amount', - 'orders_count', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params = parent::get_collection_params(); + $params['orderby']['default'] = 'coupon_id'; + $params['orderby']['enum'] = array( + 'coupon_id', + 'code', + 'amount', + 'orders_count', ); $params['coupons'] = array( 'description' => __( 'Limit result set to coupons assigned specific coupon IDs.', 'woocommerce' ), @@ -267,12 +225,6 @@ class Controller extends AbstractController implements ExportableInterface { 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg', ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Coupons/Stats/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Coupons/Stats/Controller.php index 055c60d35ae..2e4cd0badc1 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Coupons/Stats/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Coupons/Stats/Controller.php @@ -247,55 +247,12 @@ class Controller extends AbstractController { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( - 'date', - 'amount', - 'coupons_count', - 'orders_count', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params = parent::get_collection_params(); + $params['orderby']['enum'] = array( + 'date', + 'amount', + 'coupons_count', + 'orders_count', ); $params['interval'] = array( 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), @@ -340,12 +297,6 @@ class Controller extends AbstractController { 'type' => 'string', ), ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php index 5b3dd6b7d6d..d50d8878a41 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php @@ -304,8 +304,7 @@ class Controller extends AbstractController implements ExportableInterface { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); + $params = parent::get_collection_params(); $params['registered_before'] = array( 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ), 'type' => 'string', @@ -318,60 +317,19 @@ class Controller extends AbstractController implements ExportableInterface { 'format' => 'date-time', 'validate_callback' => 'rest_validate_request_arg', ); - $params['after'] = array( - 'description' => __( 'Limit response to resources with orders published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources with orders published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date_registered', - 'enum' => array( - 'username', - 'name', - 'country', - 'city', - 'state', - 'postcode', - 'date_registered', - 'date_last_active', - 'orders_count', - 'total_spend', - 'avg_order_value', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params['orderby']['default'] = 'date_registered'; + $params['orderby']['enum'] = array( + 'username', + 'name', + 'country', + 'city', + 'state', + 'postcode', + 'date_registered', + 'date_last_active', + 'orders_count', + 'total_spend', + 'avg_order_value', ); $params['match'] = array( 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ), @@ -564,12 +522,6 @@ class Controller extends AbstractController implements ExportableInterface { 'type' => 'integer', ), ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Downloads/Stats/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Downloads/Stats/Controller.php index 6c04c6e694c..90a7fc6dc2f 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Downloads/Stats/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Downloads/Stats/Controller.php @@ -205,53 +205,10 @@ class Controller extends AbstractController { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( - 'date', - 'download_count', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params = parent::get_collection_params(); + $params['orderby']['enum'] = array( + 'date', + 'download_count', ); $params['interval'] = array( 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), @@ -358,12 +315,6 @@ class Controller extends AbstractController { 'type' => 'string', ), ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Products/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Products/Controller.php index 7a18981a7e9..14514315abb 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Products/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Products/Controller.php @@ -235,58 +235,15 @@ class Controller extends AbstractController implements ExportableInterface { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( - 'date', - 'net_revenue', - 'orders_count', - 'items_sold', - 'product_name', - 'variations', - 'sku', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params = parent::get_collection_params(); + $params['orderby']['enum'] = array( + 'date', + 'net_revenue', + 'orders_count', + 'items_sold', + 'product_name', + 'variations', + 'sku', ); $params['categories'] = array( 'description' => __( 'Limit result to items from the specified categories.', 'woocommerce' ), @@ -324,12 +281,6 @@ class Controller extends AbstractController implements ExportableInterface { 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg', ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/Controller.php index fc84659a8fd..442d0c8242c 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/Controller.php @@ -289,60 +289,17 @@ class Controller extends AbstractController { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( - 'date', - 'net_revenue', - 'coupons', - 'refunds', - 'shipping', - 'taxes', - 'net_revenue', - 'orders_count', - 'items_sold', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params = parent::get_collection_params(); + $params['orderby']['enum'] = array( + 'date', + 'net_revenue', + 'coupons', + 'refunds', + 'shipping', + 'taxes', + 'net_revenue', + 'orders_count', + 'items_sold', ); $params['interval'] = array( 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), @@ -404,12 +361,6 @@ class Controller extends AbstractController { 'type' => 'string', ), ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Revenue/Stats/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Revenue/Stats/Controller.php index 0c0c55616b7..2d8825f7fb5 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Revenue/Stats/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Revenue/Stats/Controller.php @@ -333,61 +333,18 @@ class Controller extends AbstractController implements ExportableInterface { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( - 'date', - 'total_sales', - 'coupons', - 'refunds', - 'shipping', - 'taxes', - 'net_revenue', - 'orders_count', - 'items_sold', - 'gross_sales', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params = parent::get_collection_params(); + $params['orderby']['enum'] = array( + 'date', + 'total_sales', + 'coupons', + 'refunds', + 'shipping', + 'taxes', + 'net_revenue', + 'orders_count', + 'items_sold', + 'gross_sales', ); $params['interval'] = array( 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), @@ -415,12 +372,6 @@ class Controller extends AbstractController implements ExportableInterface { ), 'validate_callback' => 'rest_validate_request_arg', ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Stock/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Stock/Controller.php index 206c10d8393..401e534ff07 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Stock/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Stock/Controller.php @@ -418,25 +418,8 @@ class Controller extends AbstractController implements ExportableInterface { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); + $params = parent::get_collection_params(); + unset( $params['after'], $params['before'], $params['force_cache_refresh'] ); $params['exclude'] = array( 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), 'type' => 'array', @@ -461,27 +444,16 @@ class Controller extends AbstractController implements ExportableInterface { 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg', ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'asc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'stock_status', - 'enum' => array( - 'stock_status', - 'stock_quantity', - 'date', - 'id', - 'include', - 'title', - 'sku', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params['order']['default'] = 'asc'; + $params['orderby']['default'] = 'stock_status'; + $params['orderby']['enum'] = array( + 'stock_status', + 'stock_quantity', + 'date', + 'id', + 'include', + 'title', + 'sku', ); $params['parent'] = array( 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ), diff --git a/plugins/woocommerce/src/Admin/API/Reports/Taxes/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Taxes/Controller.php index 292f8efde7c..8c9f8b37e95 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Taxes/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Taxes/Controller.php @@ -206,59 +206,17 @@ class Controller extends AbstractController implements ExportableInterface { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'tax_rate_id', - 'enum' => array( - 'name', - 'tax_rate_id', - 'tax_code', - 'rate', - 'order_tax', - 'total_tax', - 'shipping_tax', - 'orders_count', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params = parent::get_collection_params(); + $params['orderby']['default'] = 'tax_rate_id'; + $params['orderby']['enum'] = array( + 'name', + 'tax_rate_id', + 'tax_code', + 'rate', + 'order_tax', + 'total_tax', + 'shipping_tax', + 'orders_count', ); $params['taxes'] = array( 'description' => __( 'Limit result set to items assigned one or more tax rates.', 'woocommerce' ), @@ -269,12 +227,6 @@ class Controller extends AbstractController implements ExportableInterface { 'type' => 'string', ), ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/Controller.php index a148e8abe6d..17e867149dd 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Taxes/Stats/Controller.php @@ -286,56 +286,14 @@ class Controller extends AbstractController { * @return array */ public function get_collection_params() { + $params = parent::get_collection_params(); $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( - 'date', - 'items_sold', - 'total_sales', - 'orders_count', - 'products_count', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params['orderby']['enum'] = array( + 'date', + 'items_sold', + 'total_sales', + 'orders_count', + 'products_count', ); $params['interval'] = array( 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), @@ -377,12 +335,6 @@ class Controller extends AbstractController { 'type' => 'string', ), ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Variations/Stats/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Variations/Stats/Controller.php index 766823cc536..d8ba166f57f 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Variations/Stats/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Variations/Stats/Controller.php @@ -292,37 +292,7 @@ class Controller extends AbstractController { * @return array */ public function get_collection_params() { - $params = array(); - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $params['page'] = array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, - ); - $params['per_page'] = array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['after'] = array( - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['before'] = array( - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), - 'type' => 'string', - 'format' => 'date-time', - 'validate_callback' => 'rest_validate_request_arg', - ); + $params = parent::get_collection_params(); $params['match'] = array( 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ), 'type' => 'string', @@ -333,29 +303,16 @@ class Controller extends AbstractController { ), 'validate_callback' => 'rest_validate_request_arg', ); - $params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), - 'validate_callback' => 'rest_validate_request_arg', - ); - $params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( - 'date', - 'net_revenue', - 'coupons', - 'refunds', - 'shipping', - 'taxes', - 'net_revenue', - 'orders_count', - 'items_sold', - ), - 'validate_callback' => 'rest_validate_request_arg', + $params['orderby']['enum'] = array( + 'date', + 'net_revenue', + 'coupons', + 'refunds', + 'shipping', + 'taxes', + 'net_revenue', + 'orders_count', + 'items_sold', ); $params['interval'] = array( 'description' => __( 'Time interval to use for buckets in the returned data.', 'woocommerce' ), @@ -455,12 +412,6 @@ class Controller extends AbstractController { 'default' => array(), 'validate_callback' => 'rest_validate_request_arg', ); - $params['force_cache_refresh'] = array( - 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), - 'type' => 'boolean', - 'sanitize_callback' => 'wp_validate_boolean', - 'validate_callback' => 'rest_validate_request_arg', - ); return $params; }