From 05a80e2d4f674914e365abc7fa44cb63e3f391f9 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 Jan 2018 15:03:01 -0200 Subject: [PATCH 01/11] [REST API] Fixed typos on products schema --- includes/api/class-wc-rest-product-variations-controller.php | 2 +- includes/api/class-wc-rest-products-controller.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/api/class-wc-rest-product-variations-controller.php b/includes/api/class-wc-rest-product-variations-controller.php index 6d8ac587506..9d554b1e823 100644 --- a/includes/api/class-wc-rest-product-variations-controller.php +++ b/includes/api/class-wc-rest-product-variations-controller.php @@ -674,7 +674,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller 'context' => array( 'view', 'edit' ), ), 'date_on_sale_to_gmt' => array( - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), + 'description' => __( 'End date of sale price, as GMT.', 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), ), diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index 8aff2e376ce..91abef18524 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -4,8 +4,6 @@ * * Handles requests to the /products endpoint. * - * @author WooThemes - * @category API * @package WooCommerce/API * @since 2.6.0 */ @@ -1823,7 +1821,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), 'images' => array( 'description' => __( 'List of images.', 'woocommerce' ), - 'type' => 'object', + 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', From e6597cd351b8c405fd8c1941bd523dad098c6a0b Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 30 Jan 2018 15:05:25 -0200 Subject: [PATCH 02/11] Fixed coding standards --- .../api/class-wc-rest-products-controller.php | 454 ++++++++++-------- 1 file changed, 243 insertions(+), 211 deletions(-) diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index 91abef18524..30455b5941e 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -4,8 +4,8 @@ * * Handles requests to the /products endpoint. * - * @package WooCommerce/API - * @since 2.6.0 + * @package WooCommerce/API + * @since 2.6.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -59,69 +59,77 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { * Register the routes for products. */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'create_item' ), - 'permission_callback' => array( $this, 'create_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'create_item' ), + 'permission_callback' => array( $this, 'create_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( - 'id' => array( - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), - 'type' => 'integer', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( - 'default' => 'view', - ) ), - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - array( - 'methods' => WP_REST_Server::DELETABLE, - 'callback' => array( $this, 'delete_item' ), - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), - 'args' => array( - 'force' => array( - 'default' => false, - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), - 'type' => 'boolean', + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( + 'args' => array( + 'id' => array( + 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), + 'type' => 'integer', ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => array( + 'context' => $this->get_context_param( + array( + 'default' => 'view', + ) + ), + ), + ), + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_item' ), + 'permission_callback' => array( $this, 'update_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + array( + 'methods' => WP_REST_Server::DELETABLE, + 'callback' => array( $this, 'delete_item' ), + 'permission_callback' => array( $this, 'delete_item_permissions_check' ), + 'args' => array( + 'force' => array( + 'default' => false, + 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), + 'type' => 'boolean', + ), + ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'batch_items' ), - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - 'schema' => array( $this, 'get_public_batch_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/batch', array( + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'batch_items' ), + 'permission_callback' => array( $this, 'batch_items_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + 'schema' => array( $this, 'get_public_batch_schema' ), + ) + ); } /** @@ -144,8 +152,8 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { * @return WP_REST_Response */ public function prepare_object_for_response( $object, $request ) { - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->get_product_data( $object, $context ); + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; + $data = $this->get_product_data( $object, $context ); // Add variations to variable products. if ( $object->is_type( 'variable' ) && $object->has_child() ) { @@ -251,19 +259,23 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { $skus[] = $request['sku']; } - $args['meta_query'] = $this->add_meta_query( $args, array( // WPCS: slow query ok. - 'key' => '_sku', - 'value' => $skus, - 'compare' => 'IN', - ) ); + $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. + $args, array( + 'key' => '_sku', + 'value' => $skus, + 'compare' => 'IN', + ) + ); } // Filter by tax class. if ( ! empty( $request['tax_class'] ) ) { - $args['meta_query'] = $this->add_meta_query( $args, array( // WPCS: slow query ok. - 'key' => '_tax_class', - 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '', - ) ); + $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. + $args, array( + 'key' => '_tax_class', + 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '', + ) + ); } // Price filter. @@ -273,10 +285,12 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { // Filter product in stock or out of stock. if ( is_bool( $request['in_stock'] ) ) { - $args['meta_query'] = $this->add_meta_query( $args, array( // WPCS: slow query ok. - 'key' => '_stock_status', - 'value' => true === $request['in_stock'] ? 'instock' : 'outofstock', - ) ); + $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. + $args, array( + 'key' => '_stock_status', + 'value' => true === $request['in_stock'] ? 'instock' : 'outofstock', + ) + ); } // Filter by on sale products. @@ -350,7 +364,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { * @return array */ protected function get_images( $product ) { - $images = array(); + $images = array(); $attachment_ids = array(); // Add featured image. @@ -485,9 +499,11 @@ 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'] ) ); } @@ -515,7 +531,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`. if ( 0 === strpos( $attribute_name, 'attribute_pa_' ) ) { - $option_term = get_term_by( 'slug', $attribute, $name ); + $option_term = get_term_by( 'slug', $attribute, $name ); $attributes[] = array( 'id' => wc_attribute_taxonomy_id_by_name( $name ), 'name' => $this->get_attribute_taxonomy_name( $name, $_product ), @@ -638,7 +654,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { */ protected function prepare_links( $object, $request ) { $links = array( - 'self' => array( + 'self' => array( 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), ), 'collection' => array( @@ -681,9 +697,11 @@ 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. @@ -1084,10 +1102,12 @@ 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. @@ -1284,15 +1304,19 @@ 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' ) ); @@ -1308,10 +1332,12 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object ); 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( + /* translators: %s: post type */ + "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' ); @@ -1337,19 +1363,23 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { } else { // 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( + /* translators: %s: post type */ + '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( + /* translators: %s: post type */ + 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( + 'status' => 410, + ) + ); } $object->delete(); @@ -1358,10 +1388,12 @@ 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( + /* translators: %s: post type */ + 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( + 'status' => 500, + ) + ); } // Delete parent product transients. @@ -1394,112 +1426,112 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { 'title' => $this->post_type, 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'name' => array( + 'name' => array( 'description' => __( 'Product name.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'slug' => array( + 'slug' => array( 'description' => __( 'Product slug.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'permalink' => array( + 'permalink' => array( 'description' => __( 'Product URL.', 'woocommerce' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'date_created' => array( + 'date_created' => array( 'description' => __( "The date the product was created, in the site's timezone.", 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'date_created_gmt' => array( + 'date_created_gmt' => array( 'description' => __( 'The date the product was created, as GMT.', 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'date_modified' => array( + 'date_modified' => array( 'description' => __( "The date the product was last modified, in the site's timezone.", 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'date_modified_gmt' => array( + 'date_modified_gmt' => array( 'description' => __( 'The date the product was last modified, as GMT.', 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'type' => array( + 'type' => array( 'description' => __( 'Product type.', 'woocommerce' ), 'type' => 'string', 'default' => 'simple', 'enum' => array_keys( wc_get_product_types() ), 'context' => array( 'view', 'edit' ), ), - 'status' => array( + 'status' => array( 'description' => __( 'Product status (post status).', 'woocommerce' ), 'type' => 'string', 'default' => 'publish', 'enum' => array_keys( get_post_statuses() ), 'context' => array( 'view', 'edit' ), ), - 'featured' => array( + 'featured' => array( 'description' => __( 'Featured product.', 'woocommerce' ), 'type' => 'boolean', 'default' => false, 'context' => array( 'view', 'edit' ), ), - 'catalog_visibility' => array( + 'catalog_visibility' => array( 'description' => __( 'Catalog visibility.', 'woocommerce' ), 'type' => 'string', 'default' => 'visible', 'enum' => array( 'visible', 'catalog', 'search', 'hidden' ), 'context' => array( 'view', 'edit' ), ), - 'description' => array( + 'description' => array( 'description' => __( 'Product description.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'short_description' => array( + 'short_description' => array( 'description' => __( 'Product short description.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'sku' => array( + 'sku' => array( 'description' => __( 'Unique identifier.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'price' => array( + 'price' => array( 'description' => __( 'Current product price.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'regular_price' => array( + 'regular_price' => array( 'description' => __( 'Product regular price.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'sale_price' => array( + 'sale_price' => array( 'description' => __( 'Product sale price.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'date_on_sale_from' => array( + 'date_on_sale_from' => array( 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), @@ -1509,60 +1541,60 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { 'type' => 'date-time', 'context' => array( 'view', 'edit' ), ), - 'date_on_sale_to' => array( + 'date_on_sale_to' => array( 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), ), - 'date_on_sale_to_gmt' => array( + 'date_on_sale_to_gmt' => array( 'description' => __( 'End date of sale price, as GMT.', 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), ), - 'price_html' => array( + 'price_html' => array( 'description' => __( 'Price formatted in HTML.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'on_sale' => array( + 'on_sale' => array( 'description' => __( 'Shows if the product is on sale.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'purchasable' => array( + 'purchasable' => array( 'description' => __( 'Shows if the product can be bought.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'total_sales' => array( + 'total_sales' => array( 'description' => __( 'Amount of sales.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'virtual' => array( + 'virtual' => array( 'description' => __( 'If the product is virtual.', 'woocommerce' ), 'type' => 'boolean', 'default' => false, 'context' => array( 'view', 'edit' ), ), - 'downloadable' => array( + 'downloadable' => array( 'description' => __( 'If the product is downloadable.', 'woocommerce' ), 'type' => 'boolean', 'default' => false, 'context' => array( 'view', 'edit' ), ), - 'downloads' => array( + 'downloads' => array( 'description' => __( 'List of downloadable files.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'File MD5 hash.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), @@ -1581,90 +1613,90 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), ), ), - 'download_limit' => array( + 'download_limit' => array( 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), 'type' => 'integer', 'default' => -1, 'context' => array( 'view', 'edit' ), ), - 'download_expiry' => array( + 'download_expiry' => array( 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), 'type' => 'integer', 'default' => -1, 'context' => array( 'view', 'edit' ), ), - 'external_url' => array( + 'external_url' => array( 'description' => __( 'Product external URL. Only for external products.', 'woocommerce' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit' ), ), - 'button_text' => array( + 'button_text' => array( 'description' => __( 'Product external button text. Only for external products.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'tax_status' => array( + 'tax_status' => array( 'description' => __( 'Tax status.', 'woocommerce' ), 'type' => 'string', 'default' => 'taxable', 'enum' => array( 'taxable', 'shipping', 'none' ), 'context' => array( 'view', 'edit' ), ), - 'tax_class' => array( + 'tax_class' => array( 'description' => __( 'Tax class.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'manage_stock' => array( + 'manage_stock' => array( 'description' => __( 'Stock management at product level.', 'woocommerce' ), 'type' => 'boolean', 'default' => false, 'context' => array( 'view', 'edit' ), ), - 'stock_quantity' => array( + 'stock_quantity' => array( 'description' => __( 'Stock quantity.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), - 'in_stock' => array( + 'in_stock' => array( 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ), 'type' => 'boolean', 'default' => true, 'context' => array( 'view', 'edit' ), ), - 'backorders' => array( + 'backorders' => array( 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), 'type' => 'string', 'default' => 'no', 'enum' => array( 'no', 'notify', 'yes' ), 'context' => array( 'view', 'edit' ), ), - 'backorders_allowed' => array( + 'backorders_allowed' => array( 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'backordered' => array( + 'backordered' => array( 'description' => __( 'Shows if the product is on backordered.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'sold_individually' => array( + 'sold_individually' => array( 'description' => __( 'Allow one item to be bought in a single order.', 'woocommerce' ), 'type' => 'boolean', 'default' => false, 'context' => array( 'view', 'edit' ), ), - 'weight' => array( + 'weight' => array( /* translators: %s: weight unit */ 'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'dimensions' => array( + 'dimensions' => array( 'description' => __( 'Product dimensions.', 'woocommerce' ), 'type' => 'object', 'context' => array( 'view', 'edit' ), @@ -1675,7 +1707,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'width' => array( + 'width' => array( /* translators: %s: dimension unit */ 'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ), 'type' => 'string', @@ -1689,90 +1721,90 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), ), ), - 'shipping_required' => array( + 'shipping_required' => array( 'description' => __( 'Shows if the product need to be shipped.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'shipping_taxable' => array( + 'shipping_taxable' => array( 'description' => __( 'Shows whether or not the product shipping is taxable.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'shipping_class' => array( + 'shipping_class' => array( 'description' => __( 'Shipping class slug.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'shipping_class_id' => array( + 'shipping_class_id' => array( 'description' => __( 'Shipping class ID.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'reviews_allowed' => array( + 'reviews_allowed' => array( 'description' => __( 'Allow reviews.', 'woocommerce' ), 'type' => 'boolean', 'default' => true, 'context' => array( 'view', 'edit' ), ), - 'average_rating' => array( + 'average_rating' => array( 'description' => __( 'Reviews average rating.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'rating_count' => array( + 'rating_count' => array( 'description' => __( 'Amount of reviews that the product have.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'related_ids' => array( + 'related_ids' => array( 'description' => __( 'List of related products IDs.', 'woocommerce' ), 'type' => 'array', 'items' => array( - 'type' => 'integer', + 'type' => 'integer', ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'upsell_ids' => array( + 'upsell_ids' => array( 'description' => __( 'List of up-sell products IDs.', 'woocommerce' ), 'type' => 'array', 'items' => array( - 'type' => 'integer', + 'type' => 'integer', ), 'context' => array( 'view', 'edit' ), ), - 'cross_sell_ids' => array( + 'cross_sell_ids' => array( 'description' => __( 'List of cross-sell products IDs.', 'woocommerce' ), 'type' => 'array', 'items' => array( - 'type' => 'integer', + 'type' => 'integer', ), 'context' => array( 'view', 'edit' ), ), - 'parent_id' => array( + 'parent_id' => array( 'description' => __( 'Product parent ID.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), - 'purchase_note' => array( + 'purchase_note' => array( 'description' => __( 'Optional note to send the customer after purchase.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'categories' => array( + 'categories' => array( 'description' => __( 'List of categories.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Category ID.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), @@ -1792,14 +1824,14 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), ), ), - 'tags' => array( + 'tags' => array( 'description' => __( 'List of tags.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Tag ID.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), @@ -1819,31 +1851,31 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), ), ), - 'images' => array( + 'images' => array( 'description' => __( 'List of images.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Image ID.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), - 'date_created' => array( + 'date_created' => array( 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'date_created_gmt' => array( + 'date_created_gmt' => array( 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'date_modified' => array( + 'date_modified' => array( 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), 'type' => 'date-time', 'context' => array( 'view', 'edit' ), @@ -1855,23 +1887,23 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'src' => array( + 'src' => array( 'description' => __( 'Image URL.', 'woocommerce' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit' ), ), - 'name' => array( + 'name' => array( 'description' => __( 'Image name.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'alt' => array( + 'alt' => array( 'description' => __( 'Image alternative text.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'position' => array( + 'position' => array( 'description' => __( 'Image position. 0 means that the image is featured.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), @@ -1879,29 +1911,29 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), ), ), - 'attributes' => array( + 'attributes' => array( 'description' => __( 'List of attributes.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Attribute ID.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), - 'name' => array( + 'name' => array( 'description' => __( 'Attribute name.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'position' => array( + 'position' => array( 'description' => __( 'Attribute position.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), - 'visible' => array( + 'visible' => array( 'description' => __( "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce' ), 'type' => 'boolean', 'default' => false, @@ -1913,7 +1945,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { 'default' => false, 'context' => array( 'view', 'edit' ), ), - 'options' => array( + 'options' => array( 'description' => __( 'List of available term names of the attribute.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), @@ -1924,19 +1956,19 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), ), ), - 'default_attributes' => array( + 'default_attributes' => array( 'description' => __( 'Defaults variation attributes.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Attribute ID.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), - 'name' => array( + 'name' => array( 'description' => __( 'Attribute name.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), @@ -1949,42 +1981,42 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ), ), ), - 'variations' => array( + 'variations' => array( 'description' => __( 'List of variations IDs.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( - 'type' => 'integer', + 'type' => 'integer', ), 'readonly' => true, ), - 'grouped_products' => array( + 'grouped_products' => array( 'description' => __( 'List of grouped products ID.', 'woocommerce' ), 'type' => 'array', 'items' => array( - 'type' => 'integer', + 'type' => 'integer', ), 'context' => array( 'view', 'edit' ), ), - 'menu_order' => array( + 'menu_order' => array( 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), - 'meta_data' => array( + 'meta_data' => array( 'description' => __( 'Meta data.', 'woocommerce' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'items' => array( 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Meta ID.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'key' => array( + 'key' => array( 'description' => __( 'Meta key.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), @@ -2011,12 +2043,12 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { public function get_collection_params() { $params = parent::get_collection_params(); - $params['slug'] = array( + $params['slug'] = array( 'description' => __( 'Limit result set to products with a specific slug.', 'woocommerce' ), 'type' => 'string', 'validate_callback' => 'rest_validate_request_arg', ); - $params['status'] = array( + $params['status'] = array( 'default' => 'any', 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ), 'type' => 'string', @@ -2024,32 +2056,32 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ); - $params['type'] = array( + $params['type'] = array( 'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ), 'type' => 'string', 'enum' => array_keys( wc_get_product_types() ), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ); - $params['sku'] = array( + $params['sku'] = array( 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg', ); - $params['featured'] = array( + $params['featured'] = array( 'description' => __( 'Limit result set to featured products.', 'woocommerce' ), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg', ); - $params['category'] = array( + $params['category'] = array( 'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg', ); - $params['tag'] = array( + $params['tag'] = array( 'description' => __( 'Limit result set to products assigned a specific tag ID.', 'woocommerce' ), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', @@ -2061,7 +2093,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg', ); - $params['attribute'] = array( + $params['attribute'] = array( 'description' => __( 'Limit result set to products with a specific attribute.', 'woocommerce' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', @@ -2084,13 +2116,13 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller { ); } - $params['in_stock'] = array( + $params['in_stock'] = array( 'description' => __( 'Limit result set to products in stock or out of stock.', 'woocommerce' ), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg', ); - $params['on_sale'] = array( + $params['on_sale'] = array( 'description' => __( 'Limit result set to products on sale.', 'woocommerce' ), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', From 96982cd31849277d923e345fe811ec0a20d1bae2 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 30 Jan 2018 23:32:52 +0000 Subject: [PATCH 03/11] Min columns must be 1, not 0 --- includes/wc-template-functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 11fac9dd3d4..a75013547ca 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -323,7 +323,9 @@ function wc_get_default_products_per_row() { $columns = apply_filters( 'loop_shop_columns', $columns ); } - return absint( $columns ); + $columns = absint( $columns ); + + return max( 1, $columns ); } /** From 6a7f00ce89d17f3c2d533fcfd8da0f7587baaa71 Mon Sep 17 00:00:00 2001 From: Gerhard Potgieter Date: Wed, 31 Jan 2018 08:06:51 +0200 Subject: [PATCH 04/11] Fix grammer --- includes/api/class-wc-rest-webhooks-controller.php | 2 +- includes/api/v1/class-wc-rest-webhooks-controller.php | 2 +- includes/customizer/class-wc-shop-customizer.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/api/class-wc-rest-webhooks-controller.php b/includes/api/class-wc-rest-webhooks-controller.php index c8bc7626c27..790a74ab8e4 100644 --- a/includes/api/class-wc-rest-webhooks-controller.php +++ b/includes/api/class-wc-rest-webhooks-controller.php @@ -148,7 +148,7 @@ class WC_REST_Webhooks_Controller extends WC_REST_Webhooks_V1_Controller { 'readonly' => true, ), 'secret' => array( - 'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default is a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ), + 'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ), 'type' => 'string', 'context' => array( 'edit' ), ), diff --git a/includes/api/v1/class-wc-rest-webhooks-controller.php b/includes/api/v1/class-wc-rest-webhooks-controller.php index 941bccc7f7a..3f045e755ab 100644 --- a/includes/api/v1/class-wc-rest-webhooks-controller.php +++ b/includes/api/v1/class-wc-rest-webhooks-controller.php @@ -644,7 +644,7 @@ class WC_REST_Webhooks_V1_Controller extends WC_REST_Controller { 'readonly' => true, ), 'secret' => array( - 'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default is a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ), + 'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ), 'type' => 'string', 'context' => array( 'edit' ), ), diff --git a/includes/customizer/class-wc-shop-customizer.php b/includes/customizer/class-wc-shop-customizer.php index 7b46b53671c..b11220801c1 100644 --- a/includes/customizer/class-wc-shop-customizer.php +++ b/includes/customizer/class-wc-shop-customizer.php @@ -357,7 +357,7 @@ class WC_Shop_Customizer { 'woocommerce_default_catalog_orderby', array( 'label' => __( 'Default product sorting', 'woocommerce' ), - 'description' => __( 'How should products by sorted in the catalog by default?', 'woocommerce' ), + 'description' => __( 'How should products be sorted in the catalog by default?', 'woocommerce' ), 'section' => 'woocommerce_product_catalog', 'settings' => 'woocommerce_default_catalog_orderby', 'type' => 'select', From a0b89fdda3e732337283823cc1201a4aaf897224 Mon Sep 17 00:00:00 2001 From: Gerhard Potgieter Date: Wed, 31 Jan 2018 08:07:27 +0200 Subject: [PATCH 05/11] PHPCS fixes --- includes/api/v1/class-wc-rest-webhooks-controller.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/api/v1/class-wc-rest-webhooks-controller.php b/includes/api/v1/class-wc-rest-webhooks-controller.php index 3f045e755ab..97fa4c5215e 100644 --- a/includes/api/v1/class-wc-rest-webhooks-controller.php +++ b/includes/api/v1/class-wc-rest-webhooks-controller.php @@ -4,8 +4,6 @@ * * Handles requests to the /webhooks endpoint. * - * @author WooThemes - * @category API * @package WooCommerce/API * @since 3.0.0 */ From b230d6be4c6b5b7e8ae7752dc8fd5b5e8c3b5e30 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 31 Jan 2018 10:40:06 +0000 Subject: [PATCH 06/11] Error checking --- includes/api/class-wc-rest-webhooks-controller.php | 5 +++++ includes/api/v1/class-wc-rest-webhooks-controller.php | 11 ++++++++--- includes/wc-webhook-functions.php | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/includes/api/class-wc-rest-webhooks-controller.php b/includes/api/class-wc-rest-webhooks-controller.php index c8bc7626c27..188bdbb167a 100644 --- a/includes/api/class-wc-rest-webhooks-controller.php +++ b/includes/api/class-wc-rest-webhooks-controller.php @@ -38,6 +38,11 @@ class WC_REST_Webhooks_Controller extends WC_REST_Webhooks_V1_Controller { */ public function prepare_item_for_response( $id, $request ) { $webhook = wc_get_webhook( $id ); + + if ( empty( $webhook ) || is_null( $webhook ) ) { + return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); + } + $data = array( 'id' => $webhook->get_id(), 'name' => $webhook->get_name(), diff --git a/includes/api/v1/class-wc-rest-webhooks-controller.php b/includes/api/v1/class-wc-rest-webhooks-controller.php index 941bccc7f7a..06f3b971bd0 100644 --- a/includes/api/v1/class-wc-rest-webhooks-controller.php +++ b/includes/api/v1/class-wc-rest-webhooks-controller.php @@ -362,7 +362,7 @@ class WC_REST_Webhooks_V1_Controller extends WC_REST_Controller { $id = (int) $request['id']; $webhook = wc_get_webhook( $id ); - if ( empty( $id ) || is_null( $webhook->get_id() ) ) { + if ( empty( $webhook ) || is_null( $webhook ) ) { return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); } @@ -521,12 +521,17 @@ class WC_REST_Webhooks_V1_Controller extends WC_REST_Controller { /** * Prepare a single webhook output for response. * - * @param int $id Webhook ID. + * @param int $id Webhook ID or object. * @param WP_REST_Request $request Request object. * @return WP_REST_Response $response Response data. */ public function prepare_item_for_response( $id, $request ) { - $webhook = wc_get_webhook( (int) $id ); + $webhook = wc_get_webhook( $id ); + + if ( empty( $webhook ) || is_null( $webhook ) ) { + return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); + } + $data = array( 'id' => $webhook->get_id(), 'name' => $webhook->get_name(), diff --git a/includes/wc-webhook-functions.php b/includes/wc-webhook-functions.php index 17ec3702b01..3bc63729269 100644 --- a/includes/wc-webhook-functions.php +++ b/includes/wc-webhook-functions.php @@ -117,11 +117,11 @@ function wc_load_webhooks() { /** * Get webhook. * - * @param int $id Webhook ID. + * @param int|WC_Webhook $id Webhook ID or object. * @return WC_Webhook|null */ function wc_get_webhook( $id ) { - $webhook = new WC_Webhook( (int) $id ); + $webhook = new WC_Webhook( $id ); return 0 !== $webhook->get_id() ? $webhook : null; } From 57c00701e67cb8ac2fb941388cf43bf9a184f749 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 31 Jan 2018 11:30:10 +0000 Subject: [PATCH 07/11] Ensure the table handler is only loaded once. Prevents multiple loads if a plugin calls check_ajax_referer many times. --- includes/admin/class-wc-admin-post-types.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index edd83082118..a2027556696 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -101,6 +101,10 @@ class WC_Admin_Post_Types { new WC_Admin_List_Table_Products(); break; } + + // Ensure the table handler is only loaded once. Prevents multiple loads if a plugin calls check_ajax_referer many times. + remove_action( 'current_screen', array( $this, 'setup_screen' ) ); + remove_action( 'check_ajax_referer', array( $this, 'setup_screen' ) ); } /** From 0f33d446e30f1f9ea40d72e3a573d4e4fe52a964 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 31 Jan 2018 11:59:40 +0000 Subject: [PATCH 08/11] Before getting wc_get_loop_prop, setup the loop. Closes #18687 --- includes/wc-template-functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index a75013547ca..9b0c1d65a99 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -204,6 +204,8 @@ add_action( 'woocommerce_after_shop_loop', 'woocommerce_reset_loop', 999 ); * @return mixed */ function wc_get_loop_prop( $prop, $default = '' ) { + wc_setup_loop(); // Ensure shop loop is setup. + return isset( $GLOBALS['woocommerce_loop'], $GLOBALS['woocommerce_loop'][ $prop ] ) ? $GLOBALS['woocommerce_loop'][ $prop ] : $default; } From 55c664d2d76df784c4b34b5ccb57af33df4eb9b5 Mon Sep 17 00:00:00 2001 From: Jason Kytros Date: Wed, 31 Jan 2018 14:53:44 +0200 Subject: [PATCH 09/11] Remove filter 'woocommerce_order_item_product' from class-wc-structured-data.php --- includes/class-wc-structured-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-structured-data.php b/includes/class-wc-structured-data.php index bc384a441f6..1dc9e456f08 100644 --- a/includes/class-wc-structured-data.php +++ b/includes/class-wc-structured-data.php @@ -390,7 +390,7 @@ class WC_Structured_Data { continue; } - $product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item ); + $product = $order->get_product_from_item( $item ); $product_exists = is_object( $product ); $is_visible = $product_exists && $product->is_visible(); From a08c00325405a3fe24ec4a900e7b91a5cb3a4374 Mon Sep 17 00:00:00 2001 From: Jason Kytros Date: Wed, 31 Jan 2018 14:54:51 +0200 Subject: [PATCH 10/11] Remove filter 'woocommerce_order_item_product' from order-details.php --- templates/order/order-details.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/order/order-details.php b/templates/order/order-details.php index 1b79b772c51..b3c3d5af810 100644 --- a/templates/order/order-details.php +++ b/templates/order/order-details.php @@ -52,7 +52,7 @@ if ( $show_downloads ) { do_action( 'woocommerce_order_details_before_order_table_items', $order ); foreach ( $order_items as $item_id => $item ) { - $product = apply_filters( 'woocommerce_order_item_product', $item->get_product(), $item ); + $product = $item->get_product(); wc_get_template( 'order/order-details-item.php', array( 'order' => $order, From 211ec9b89632ffb518fe0a0c698b7f05aaf8e937 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Wed, 31 Jan 2018 11:21:17 -0200 Subject: [PATCH 11/11] phpcs fixes --- includes/api/class-wc-rest-webhooks-controller.php | 2 -- includes/wc-webhook-functions.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/includes/api/class-wc-rest-webhooks-controller.php b/includes/api/class-wc-rest-webhooks-controller.php index 188bdbb167a..d02d686db48 100644 --- a/includes/api/class-wc-rest-webhooks-controller.php +++ b/includes/api/class-wc-rest-webhooks-controller.php @@ -4,8 +4,6 @@ * * Handles requests to the /webhooks endpoint. * - * @author WooThemes - * @category API * @package WooCommerce/API * @since 2.6.0 */ diff --git a/includes/wc-webhook-functions.php b/includes/wc-webhook-functions.php index 3bc63729269..4c6148f1b91 100644 --- a/includes/wc-webhook-functions.php +++ b/includes/wc-webhook-functions.php @@ -2,8 +2,6 @@ /** * WooCommerce Webhook functions * - * @author Automattic - * @category Core * @package WooCommerce/Functions * @version 3.3.0 */