Fixed coding standards
This commit is contained in:
parent
f8552ebbad
commit
c17fbf53b4
|
@ -89,7 +89,9 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'context' => $this->get_context_param( array(
|
||||
'default' => 'view',
|
||||
) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
|
@ -231,7 +233,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
}
|
||||
|
||||
if ( ! empty( $tax_query ) ) {
|
||||
$args['tax_query'] = $tax_query;
|
||||
$args['tax_query'] = $tax_query; // WPCS: slow query ok.
|
||||
}
|
||||
|
||||
// Filter featured.
|
||||
|
@ -251,7 +253,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
$skus[] = $request['sku'];
|
||||
}
|
||||
|
||||
$args['meta_query'] = $this->add_meta_query( $args, array(
|
||||
$args['meta_query'] = $this->add_meta_query( $args, array( // WPCS: slow query ok.
|
||||
'key' => '_sku',
|
||||
'value' => $skus,
|
||||
'compare' => 'IN',
|
||||
|
@ -260,7 +262,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
|
||||
// Filter by tax class.
|
||||
if ( ! empty( $request['tax_class'] ) ) {
|
||||
$args['meta_query'] = $this->add_meta_query( $args, array(
|
||||
$args['meta_query'] = $this->add_meta_query( $args, array( // WPCS: slow query ok.
|
||||
'key' => '_tax_class',
|
||||
'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '',
|
||||
) );
|
||||
|
@ -268,12 +270,12 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
|
||||
// Price filter.
|
||||
if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) {
|
||||
$args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) );
|
||||
$args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) ); // WPCS: slow query ok.
|
||||
}
|
||||
|
||||
// Filter product in stock or out of stock.
|
||||
if ( is_bool( $request['in_stock'] ) ) {
|
||||
$args['meta_query'] = $this->add_meta_query( $args, array(
|
||||
$args['meta_query'] = $this->add_meta_query( $args, array( // WPCS: slow query ok.
|
||||
'key' => '_stock_status',
|
||||
'value' => true === $request['in_stock'] ? 'instock' : 'outofstock',
|
||||
) );
|
||||
|
@ -485,7 +487,9 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
*/
|
||||
protected function get_attribute_options( $product_id, $attribute ) {
|
||||
if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) {
|
||||
return wc_get_product_terms( $product_id, $attribute['name'], array( 'fields' => 'names' ) );
|
||||
return wc_get_product_terms( $product_id, $attribute['name'], array(
|
||||
'fields' => 'names',
|
||||
) );
|
||||
} elseif ( isset( $attribute['value'] ) ) {
|
||||
return array_map( 'trim', explode( '|', $attribute['value'] ) );
|
||||
}
|
||||
|
@ -547,7 +551,8 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
* Get product data.
|
||||
*
|
||||
* @param WC_Product $product Product instance.
|
||||
* @param string $context 'view' or 'edit'
|
||||
* @param string $context Request context.
|
||||
* Options: 'view' and 'edit'.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_product_data( $product, $context = 'view' ) {
|
||||
|
@ -678,7 +683,9 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
}
|
||||
|
||||
if ( 'variation' === $product->get_type() ) {
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array(
|
||||
'status' => 404,
|
||||
) );
|
||||
}
|
||||
|
||||
// Post title.
|
||||
|
@ -1060,6 +1067,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
}
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
/* translators: %s: attachment id */
|
||||
throw new WC_REST_Exception( 'woocommerce_product_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
|
||||
}
|
||||
|
||||
|
@ -1076,7 +1084,10 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
|
||||
// Set the image name if present.
|
||||
if ( ! empty( $image['name'] ) ) {
|
||||
wp_update_post( array( 'ID' => $attachment_id, 'post_title' => $image['name'] ) );
|
||||
wp_update_post( array(
|
||||
'ID' => $attachment_id,
|
||||
'post_title' => $image['name'],
|
||||
) );
|
||||
}
|
||||
|
||||
// Set the image source if present, for future reference.
|
||||
|
@ -1273,11 +1284,15 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
$result = false;
|
||||
|
||||
if ( ! $object || 0 === $object->get_id() ) {
|
||||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array(
|
||||
'status' => 404,
|
||||
) );
|
||||
}
|
||||
|
||||
if ( 'variation' === $object->get_type() ) {
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array(
|
||||
'status' => 404,
|
||||
) );
|
||||
}
|
||||
|
||||
$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
|
||||
|
@ -1294,7 +1309,9 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
|
||||
if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
|
||||
/* translators: %s: post type */
|
||||
return new WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) );
|
||||
return new WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array(
|
||||
'status' => rest_authorization_required_code(),
|
||||
) );
|
||||
}
|
||||
|
||||
$request->set_param( 'context', 'edit' );
|
||||
|
@ -1321,14 +1338,18 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
// If we don't support trashing for this type, error out.
|
||||
if ( ! $supports_trash ) {
|
||||
/* translators: %s: post type */
|
||||
return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
|
||||
return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array(
|
||||
'status' => 501,
|
||||
) );
|
||||
}
|
||||
|
||||
// Otherwise, only trash if we haven't already.
|
||||
if ( is_callable( array( $object, 'get_status' ) ) ) {
|
||||
if ( 'trash' === $object->get_status() ) {
|
||||
/* translators: %s: post type */
|
||||
return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
|
||||
return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array(
|
||||
'status' => 410,
|
||||
) );
|
||||
}
|
||||
|
||||
$object->delete();
|
||||
|
@ -1338,7 +1359,9 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
|
||||
if ( ! $result ) {
|
||||
/* translators: %s: post type */
|
||||
return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
|
||||
return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array(
|
||||
'status' => 500,
|
||||
) );
|
||||
}
|
||||
|
||||
// Delete parent product transients.
|
||||
|
@ -1401,7 +1424,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the product was created, as GMT.", 'woocommerce' ),
|
||||
'description' => __( 'The date the product was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
@ -1413,7 +1436,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( "The date the product was last modified, as GMT.", 'woocommerce' ),
|
||||
'description' => __( 'The date the product was last modified, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
@ -1815,7 +1838,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the image was created, as GMT.", 'woocommerce' ),
|
||||
'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
@ -1827,7 +1850,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( "The date the image was last modified, as GMT.", 'woocommerce' ),
|
||||
'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
<description>WooCommerce dev PHP_CodeSniffer ruleset.</description>
|
||||
|
||||
<rule ref="WordPress"></rule>
|
||||
<rule ref="WordPress">
|
||||
<exclude name="WordPress.VIP.RestrictedFunctions.get_term_by_get_term_by" />
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.VIP.ValidatedSanitizedInput">
|
||||
<properties>
|
||||
|
|
Loading…
Reference in New Issue