diff --git a/includes/widgets/class-wc-widget-cart.php b/includes/widgets/class-wc-widget-cart.php index 1089882dbc4..e699476d135 100644 --- a/includes/widgets/class-wc-widget-cart.php +++ b/includes/widgets/class-wc-widget-cart.php @@ -1,19 +1,17 @@ widget_cssclass = 'woocommerce widget_shopping_cart'; - $this->widget_description = __( "Display the customer shopping cart.", 'woocommerce' ); + $this->widget_description = __( 'Display the customer shopping cart.', 'woocommerce' ); $this->widget_id = 'woocommerce_widget_cart'; $this->widget_name = __( 'Cart', 'woocommerce' ); $this->settings = array( - 'title' => array( + 'title' => array( 'type' => 'text', 'std' => __( 'Cart', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ), @@ -46,8 +44,8 @@ class WC_Widget_Cart extends WC_Widget { * * @see WP_Widget * - * @param array $args - * @param array $instance + * @param array $args Arguments. + * @param array $instance Widget instance. */ public function widget( $args, $instance ) { if ( apply_filters( 'woocommerce_widget_cart_is_hidden', is_cart() || is_checkout() ) ) { @@ -62,7 +60,7 @@ class WC_Widget_Cart extends WC_Widget { echo '
'; } - // Insert cart widget placeholder - code in woocommerce.js will update this on page load + // Insert cart widget placeholder - code in woocommerce.js will update this on page load. echo '
'; if ( $hide_if_empty ) { diff --git a/includes/widgets/class-wc-widget-layered-nav-filters.php b/includes/widgets/class-wc-widget-layered-nav-filters.php index a36e551e693..1f9d1df071d 100644 --- a/includes/widgets/class-wc-widget-layered-nav-filters.php +++ b/includes/widgets/class-wc-widget-layered-nav-filters.php @@ -1,17 +1,15 @@ widget_id = 'woocommerce_layered_nav_filters'; $this->widget_name = __( 'Active Product Filters', 'woocommerce' ); $this->settings = array( - 'title' => array( + 'title' => array( 'type' => 'text', 'std' => __( 'Active filters', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ), @@ -38,8 +36,8 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget { * Output widget. * * @see WP_Widget - * @param array $args - * @param array $instance + * @param array $args Arguments. + * @param array $instance Widget instance. */ public function widget( $args, $instance ) { if ( ! is_shop() && ! is_product_taxonomy() ) { @@ -47,9 +45,9 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget { } $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); - $min_price = isset( $_GET['min_price'] ) ? wc_clean( $_GET['min_price'] ) : 0; - $max_price = isset( $_GET['max_price'] ) ? wc_clean( $_GET['max_price'] ) : 0; - $rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', $_GET['rating_filter'] ) ) ) : array(); + $min_price = isset( $_GET['min_price'] ) ? wc_clean( wp_unslash( $_GET['min_price'] ) ) : 0; // WPCS: input var ok, CSRF ok. + $max_price = isset( $_GET['max_price'] ) ? wc_clean( wp_unslash( $_GET['max_price'] ) ) : 0; // WPCS: input var ok, CSRF ok. + $rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', wp_unslash( $_GET['rating_filter'] ) ) ) ) : array(); // WPCS: sanitization ok, input var ok, CSRF ok. $base_link = $this->get_current_page_url(); if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price || ! empty( $rating_filter ) ) { @@ -58,22 +56,23 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget { echo '
- '; + '; // WPCS: XSS ok. $this->widget_end( $args ); } /** * Get filtered min price for current products. + * * @return int */ protected function get_filtered_price() { @@ -145,15 +146,16 @@ class WC_Widget_Price_Filter extends WC_Widget { $sql = "SELECT min( FLOOR( price_meta.meta_value ) ) as min_price, max( CEILING( price_meta.meta_value ) ) as max_price FROM {$wpdb->posts} "; $sql .= " LEFT JOIN {$wpdb->postmeta} as price_meta ON {$wpdb->posts}.ID = price_meta.post_id " . $tax_query_sql['join'] . $meta_query_sql['join']; $sql .= " WHERE {$wpdb->posts}.post_type IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_post_type', array( 'product' ) ) ) ) . "') - AND {$wpdb->posts}.post_status = 'publish' - AND price_meta.meta_key IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) ) . "') - AND price_meta.meta_value > '' "; + AND {$wpdb->posts}.post_status = 'publish' + AND price_meta.meta_key IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) ) . "') + AND price_meta.meta_value > '' "; $sql .= $tax_query_sql['where'] . $meta_query_sql['where']; - if ( $search = WC_Query::get_main_search_query_sql() ) { + $search = WC_Query::get_main_search_query_sql(); + if ( $search ) { $sql .= ' AND ' . $search; } - return $wpdb->get_row( $sql ); + return $wpdb->get_row( $sql ); // WPCS: unprepared SQL ok. } } diff --git a/includes/widgets/class-wc-widget-product-categories.php b/includes/widgets/class-wc-widget-product-categories.php index 1bc4e5129ee..ed09be88921 100644 --- a/includes/widgets/class-wc-widget-product-categories.php +++ b/includes/widgets/class-wc-widget-product-categories.php @@ -2,15 +2,11 @@ /** * Product Categories Widget * - * @author Automattic - * @category Widgets - * @package WooCommerce/Widgets - * @version 2.3.0 + * @package WooCommerce/Widgets + * @version 2.3.0 */ -if ( ! defined( 'ABSPATH' ) ) { - exit; -} +defined( 'ABSPATH' ) || exit; /** * Product categories widget class. @@ -42,31 +38,31 @@ class WC_Widget_Product_Categories extends WC_Widget { $this->widget_id = 'woocommerce_product_categories'; $this->widget_name = __( 'Product Categories', 'woocommerce' ); $this->settings = array( - 'title' => array( + 'title' => array( 'type' => 'text', 'std' => __( 'Product categories', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ), ), - 'orderby' => array( - 'type' => 'select', - 'std' => 'name', - 'label' => __( 'Order by', 'woocommerce' ), + 'orderby' => array( + 'type' => 'select', + 'std' => 'name', + 'label' => __( 'Order by', 'woocommerce' ), 'options' => array( 'order' => __( 'Category order', 'woocommerce' ), 'name' => __( 'Name', 'woocommerce' ), ), ), - 'dropdown' => array( + 'dropdown' => array( 'type' => 'checkbox', 'std' => 0, 'label' => __( 'Show as dropdown', 'woocommerce' ), ), - 'count' => array( + 'count' => array( 'type' => 'checkbox', 'std' => 0, 'label' => __( 'Show product counts', 'woocommerce' ), ), - 'hierarchical' => array( + 'hierarchical' => array( 'type' => 'checkbox', 'std' => 1, 'label' => __( 'Show hierarchy', 'woocommerce' ), @@ -76,12 +72,12 @@ class WC_Widget_Product_Categories extends WC_Widget { 'std' => 0, 'label' => __( 'Only show children of the current category', 'woocommerce' ), ), - 'hide_empty' => array( + 'hide_empty' => array( 'type' => 'checkbox', 'std' => 0, 'label' => __( 'Hide empty categories', 'woocommerce' ), ), - 'max_depth' => array( + 'max_depth' => array( 'type' => 'text', 'std' => '', 'label' => __( 'Maximum depth', 'woocommerce' ), @@ -125,7 +121,7 @@ class WC_Widget_Product_Categories extends WC_Widget { if ( 'order' === $orderby ) { $list_args['menu_order'] = 'asc'; } else { - $list_args['orderby'] = 'title'; + $list_args['orderby'] = 'title'; } $this->current_cat = false; @@ -136,13 +132,17 @@ class WC_Widget_Product_Categories extends WC_Widget { $this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' ); } elseif ( is_singular( 'product' ) ) { - $terms = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_product_categories_widget_product_terms_args', array( - 'orderby' => 'parent', - 'order' => 'DESC', - ) ) ); + $terms = wc_get_product_terms( + $post->ID, 'product_cat', apply_filters( + 'woocommerce_product_categories_widget_product_terms_args', array( + 'orderby' => 'parent', + 'order' => 'DESC', + ) + ) + ); if ( $terms ) { - $main_term = apply_filters( 'woocommerce_product_categories_widget_main_term', $terms[0], $terms ); + $main_term = apply_filters( 'woocommerce_product_categories_widget_main_term', $terms[0], $terms ); $this->current_cat = $main_term; $this->cat_ancestors = get_ancestors( $main_term->term_id, 'product_cat' ); } @@ -176,15 +176,17 @@ class WC_Widget_Product_Categories extends WC_Widget { // Gather siblings of ancestors. if ( $this->cat_ancestors ) { foreach ( $this->cat_ancestors as $ancestor ) { - $include = array_merge( $include, get_terms( - 'product_cat', - array( - 'fields' => 'ids', - 'parent' => $ancestor, - 'hierarchical' => false, - 'hide_empty' => false, + $include = array_merge( + $include, get_terms( + 'product_cat', + array( + 'fields' => 'ids', + 'parent' => $ancestor, + 'hierarchical' => false, + 'hide_empty' => false, + ) ) - ) ); + ); } } } else { @@ -198,7 +200,7 @@ class WC_Widget_Product_Categories extends WC_Widget { 'hide_empty' => false, ) ); - } // End if(). + } $list_args['include'] = implode( ',', $include ); $dropdown_args['include'] = $list_args['include']; @@ -213,19 +215,26 @@ class WC_Widget_Product_Categories extends WC_Widget { $list_args['depth'] = 1; $list_args['child_of'] = 0; $list_args['hierarchical'] = 1; - } // End if(). + } $this->widget_start( $args, $instance ); if ( $dropdown ) { - wc_product_dropdown_categories( apply_filters( 'woocommerce_product_categories_widget_dropdown_args', wp_parse_args( $dropdown_args, array( - 'show_count' => $count, - 'hierarchical' => $hierarchical, - 'show_uncategorized' => 0, - 'orderby' => $orderby, - 'selected' => $this->current_cat ? $this->current_cat->slug : '', - ) ) ) ); - wc_enqueue_js( " + wc_product_dropdown_categories( + apply_filters( + 'woocommerce_product_categories_widget_dropdown_args', wp_parse_args( + $dropdown_args, array( + 'show_count' => $count, + 'hierarchical' => $hierarchical, + 'show_uncategorized' => 0, + 'orderby' => $orderby, + 'selected' => $this->current_cat ? $this->current_cat->slug : '', + ) + ) + ) + ); + wc_enqueue_js( + " jQuery( '.dropdown_product_cat' ).change( function() { if ( jQuery(this).val() != '' ) { var this_page = ''; @@ -238,11 +247,12 @@ class WC_Widget_Product_Categories extends WC_Widget { location.href = this_page; } }); - " ); + " + ); } else { - include_once( WC()->plugin_path() . '/includes/walkers/class-product-cat-list-walker.php' ); + include_once WC()->plugin_path() . '/includes/walkers/class-product-cat-list-walker.php'; - $list_args['walker'] = new WC_Product_Cat_List_Walker; + $list_args['walker'] = new WC_Product_Cat_List_Walker(); $list_args['title_li'] = ''; $list_args['pad_counts'] = 1; $list_args['show_option_none'] = __( 'No product categories exist.', 'woocommerce' ); @@ -255,7 +265,7 @@ class WC_Widget_Product_Categories extends WC_Widget { wp_list_categories( apply_filters( 'woocommerce_product_categories_widget_args', $list_args ) ); echo ''; - } // End if(). + } $this->widget_end( $args ); } diff --git a/includes/widgets/class-wc-widget-product-search.php b/includes/widgets/class-wc-widget-product-search.php index 6935cb5c32d..2df11926494 100644 --- a/includes/widgets/class-wc-widget-product-search.php +++ b/includes/widgets/class-wc-widget-product-search.php @@ -1,17 +1,15 @@ widget_id = 'woocommerce_product_search'; $this->widget_name = __( 'Product Search', 'woocommerce' ); $this->settings = array( - 'title' => array( + 'title' => array( 'type' => 'text', 'std' => '', 'label' => __( 'Title', 'woocommerce' ), @@ -39,8 +37,8 @@ class WC_Widget_Product_Search extends WC_Widget { * * @see WP_Widget * - * @param array $args - * @param array $instance + * @param array $args Arguments. + * @param array $instance Widget instance. */ public function widget( $args, $instance ) { $this->widget_start( $args, $instance ); diff --git a/includes/widgets/class-wc-widget-product-tag-cloud.php b/includes/widgets/class-wc-widget-product-tag-cloud.php index 9f7f591e5b6..d934366a096 100644 --- a/includes/widgets/class-wc-widget-product-tag-cloud.php +++ b/includes/widgets/class-wc-widget-product-tag-cloud.php @@ -1,17 +1,17 @@ widget_id = 'woocommerce_product_tag_cloud'; $this->widget_name = __( 'Product Tag Cloud', 'woocommerce' ); $this->settings = array( - 'title' => array( + 'title' => array( 'type' => 'text', 'std' => __( 'Product tags', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ), @@ -39,14 +39,14 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget { * * @see WP_Widget * - * @param array $args - * @param array $instance + * @param array $args Arguments. + * @param array $instance Widget instance. */ public function widget( $args, $instance ) { - $current_taxonomy = $this->_get_current_taxonomy( $instance ); + $current_taxonomy = $this->get_current_taxonomy( $instance ); if ( empty( $instance['title'] ) ) { - $taxonomy = get_taxonomy( $current_taxonomy ); + $taxonomy = get_taxonomy( $current_taxonomy ); $instance['title'] = $taxonomy->labels->name; } @@ -54,10 +54,14 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget { echo '
'; - wp_tag_cloud( apply_filters( 'woocommerce_product_tag_cloud_widget_args', array( - 'taxonomy' => $current_taxonomy, - 'topic_count_text_callback' => array( $this, '_topic_count_text' ), - ) ) ); + wp_tag_cloud( + apply_filters( + 'woocommerce_product_tag_cloud_widget_args', array( + 'taxonomy' => $current_taxonomy, + 'topic_count_text_callback' => array( $this, 'topic_count_text' ), + ) + ) + ); echo '
'; @@ -67,22 +71,50 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget { /** * Return the taxonomy being displayed. * - * @param object $instance + * @param object $instance Widget instance. * @return string */ - public function _get_current_taxonomy( $instance ) { + public function get_current_taxonomy( $instance ) { return 'product_tag'; } /** * Returns topic count text. * - * @since 2.6.0 - * @param int $count + * @since 3.4.0 + * @param int $count Count text. * @return string */ - public function _topic_count_text( $count ) { + public function topic_count_text( $count ) { /* translators: %s: product count */ return sprintf( _n( '%s product', '%s products', $count, 'woocommerce' ), number_format_i18n( $count ) ); } + + // Ignore whole block to avoid warnings about PSR2.Methods.MethodDeclaration.Underscore violation. + // @codingStandardsIgnoreStart + /** + * Return the taxonomy being displayed. + * + * @deprecated 3.4.0 + * @param object $instance Widget instance. + * @return string + */ + public function _get_current_taxonomy( $instance ) { + wc_deprecated_function( '_get_current_taxonomy', '3.4.0', 'WC_Widget_Product_Tag_Cloud->get_current_taxonomy' ); + return $this->get_current_taxonomy( $instance ); + } + + /** + * Returns topic count text. + * + * @deprecated 3.4.0 + * @since 2.6.0 + * @param int $count Count text. + * @return string + */ + public function _topic_count_text( $count ) { + wc_deprecated_function( '_topic_count_text', '3.4.0', 'WC_Widget_Product_Tag_Cloud->topic_count_text' ); + return $this->topic_count_text( $count ); + } + // @codingStandardsIgnoreEnd } diff --git a/includes/widgets/class-wc-widget-products.php b/includes/widgets/class-wc-widget-products.php index 751233bbdbf..d3e5334594a 100644 --- a/includes/widgets/class-wc-widget-products.php +++ b/includes/widgets/class-wc-widget-products.php @@ -1,17 +1,15 @@ widget_id = 'woocommerce_products'; $this->widget_name = __( 'Products', 'woocommerce' ); $this->settings = array( - 'title' => array( + 'title' => array( 'type' => 'text', 'std' => __( 'Products', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ), ), - 'number' => array( + 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, @@ -37,37 +35,37 @@ class WC_Widget_Products extends WC_Widget { 'std' => 5, 'label' => __( 'Number of products to show', 'woocommerce' ), ), - 'show' => array( - 'type' => 'select', - 'std' => '', - 'label' => __( 'Show', 'woocommerce' ), + 'show' => array( + 'type' => 'select', + 'std' => '', + 'label' => __( 'Show', 'woocommerce' ), 'options' => array( '' => __( 'All products', 'woocommerce' ), 'featured' => __( 'Featured products', 'woocommerce' ), 'onsale' => __( 'On-sale products', 'woocommerce' ), ), ), - 'orderby' => array( - 'type' => 'select', - 'std' => 'date', - 'label' => __( 'Order by', 'woocommerce' ), + 'orderby' => array( + 'type' => 'select', + 'std' => 'date', + 'label' => __( 'Order by', 'woocommerce' ), 'options' => array( - 'date' => __( 'Date', 'woocommerce' ), - 'price' => __( 'Price', 'woocommerce' ), - 'rand' => __( 'Random', 'woocommerce' ), - 'sales' => __( 'Sales', 'woocommerce' ), + 'date' => __( 'Date', 'woocommerce' ), + 'price' => __( 'Price', 'woocommerce' ), + 'rand' => __( 'Random', 'woocommerce' ), + 'sales' => __( 'Sales', 'woocommerce' ), ), ), - 'order' => array( - 'type' => 'select', - 'std' => 'desc', - 'label' => _x( 'Order', 'Sorting order', 'woocommerce' ), + 'order' => array( + 'type' => 'select', + 'std' => 'desc', + 'label' => _x( 'Order', 'Sorting order', 'woocommerce' ), 'options' => array( 'asc' => __( 'ASC', 'woocommerce' ), 'desc' => __( 'DESC', 'woocommerce' ), ), ), - 'hide_free' => array( + 'hide_free' => array( 'type' => 'checkbox', 'std' => 0, 'label' => __( 'Hide free products', 'woocommerce' ), @@ -84,15 +82,16 @@ class WC_Widget_Products extends WC_Widget { /** * Query the products and return them. - * @param array $args - * @param array $instance + * + * @param array $args Arguments. + * @param array $instance Widget instance. * @return WP_Query */ public function get_products( $args, $instance ) { - $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; - $show = ! empty( $instance['show'] ) ? sanitize_title( $instance['show'] ) : $this->settings['show']['std']; + $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; + $show = ! empty( $instance['show'] ) ? sanitize_title( $instance['show'] ) : $this->settings['show']['std']; $orderby = ! empty( $instance['orderby'] ) ? sanitize_title( $instance['orderby'] ) : $this->settings['orderby']['std']; - $order = ! empty( $instance['order'] ) ? sanitize_title( $instance['order'] ) : $this->settings['order']['std']; + $order = ! empty( $instance['order'] ) ? sanitize_title( $instance['order'] ) : $this->settings['order']['std']; $product_visibility_term_ids = wc_get_product_visibility_term_ids(); $query_args = array( @@ -105,7 +104,7 @@ class WC_Widget_Products extends WC_Widget { 'tax_query' => array( 'relation' => 'AND', ), - ); + ); // WPCS: slow query ok. if ( empty( $instance['show_hidden'] ) ) { $query_args['tax_query'][] = array( @@ -114,7 +113,7 @@ class WC_Widget_Products extends WC_Widget { 'terms' => is_search() ? $product_visibility_term_ids['exclude-from-search'] : $product_visibility_term_ids['exclude-from-catalog'], 'operator' => 'NOT IN', ); - $query_args['post_parent'] = 0; + $query_args['post_parent'] = 0; } if ( ! empty( $instance['hide_free'] ) ) { @@ -134,18 +133,18 @@ class WC_Widget_Products extends WC_Widget { 'terms' => $product_visibility_term_ids['outofstock'], 'operator' => 'NOT IN', ), - ); + ); // WPCS: slow query ok. } switch ( $show ) { - case 'featured' : + case 'featured': $query_args['tax_query'][] = array( 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', 'terms' => $product_visibility_term_ids['featured'], ); break; - case 'onsale' : + case 'onsale': $product_ids_on_sale = wc_get_product_ids_on_sale(); $product_ids_on_sale[] = 0; $query_args['post__in'] = $product_ids_on_sale; @@ -153,19 +152,19 @@ class WC_Widget_Products extends WC_Widget { } switch ( $orderby ) { - case 'price' : - $query_args['meta_key'] = '_price'; + case 'price': + $query_args['meta_key'] = '_price'; // WPCS: slow query ok. $query_args['orderby'] = 'meta_value_num'; break; - case 'rand' : - $query_args['orderby'] = 'rand'; + case 'rand': + $query_args['orderby'] = 'rand'; break; - case 'sales' : - $query_args['meta_key'] = 'total_sales'; + case 'sales': + $query_args['meta_key'] = 'total_sales'; // WPCS: slow query ok. $query_args['orderby'] = 'meta_value_num'; break; - default : - $query_args['orderby'] = 'date'; + default: + $query_args['orderby'] = 'date'; } return new WP_Query( apply_filters( 'woocommerce_products_widget_query_args', $query_args ) ); @@ -176,8 +175,8 @@ class WC_Widget_Products extends WC_Widget { * * @see WP_Widget * - * @param array $args - * @param array $instance + * @param array $args Arguments. + * @param array $instance Widget instance. */ public function widget( $args, $instance ) { if ( $this->get_cached_widget( $args ) ) { @@ -186,7 +185,8 @@ class WC_Widget_Products extends WC_Widget { ob_start(); - if ( ( $products = $this->get_products( $args, $instance ) ) && $products->have_posts() ) { + $products = $this->get_products( $args, $instance ); + if ( $products && $products->have_posts() ) { $this->widget_start( $args, $instance ); echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', ''; @@ -135,7 +133,7 @@ class WC_Widget_Rating_Filter extends WC_Widget { if ( ! $found ) { ob_end_clean(); } else { - echo ob_get_clean(); + echo ob_get_clean(); // WPCS: XSS ok. } } } diff --git a/includes/widgets/class-wc-widget-recent-reviews.php b/includes/widgets/class-wc-widget-recent-reviews.php index a049c9ff331..da6fef7fd4d 100644 --- a/includes/widgets/class-wc-widget-recent-reviews.php +++ b/includes/widgets/class-wc-widget-recent-reviews.php @@ -1,17 +1,15 @@ get_cached_widget( $args ) ) { @@ -60,7 +57,15 @@ class WC_Widget_Recent_Reviews extends WC_Widget { ob_start(); $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; - $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product', 'parent' => 0 ) ); + $comments = get_comments( + array( + 'number' => $number, + 'status' => 'approve', + 'post_status' => 'publish', + 'post_type' => 'product', + 'parent' => 0, + ) + ); // WPCS: override ok. if ( $comments ) { $this->widget_start( $args, $instance ); @@ -77,12 +82,12 @@ class WC_Widget_Recent_Reviews extends WC_Widget { echo '
  • '; - echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . ''; + echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . ''; // WPCS: XSS ok. - echo $rating_html; + echo $rating_html; // WPCS: XSS ok. /* translators: %s: review author */ - echo '' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . ''; + echo '' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . ''; // WPCS: XSS ok. echo '
  • '; } @@ -94,7 +99,7 @@ class WC_Widget_Recent_Reviews extends WC_Widget { $content = ob_get_clean(); - echo $content; + echo $content; // WPCS: XSS ok. $this->cache_widget( $args, $content ); } diff --git a/includes/widgets/class-wc-widget-recently-viewed.php b/includes/widgets/class-wc-widget-recently-viewed.php index bd525807141..e5a8db3dc6a 100644 --- a/includes/widgets/class-wc-widget-recently-viewed.php +++ b/includes/widgets/class-wc-widget-recently-viewed.php @@ -1,17 +1,15 @@ 'outofstock', 'operator' => 'NOT IN', ), - ); + ); // WPCS: slow query ok. } $r = new WP_Query( apply_filters( 'woocommerce_recently_viewed_products_widget_query_args', $query_args ) ); @@ -109,6 +105,6 @@ class WC_Widget_Recently_Viewed extends WC_Widget { $content = ob_get_clean(); - echo $content; + echo $content; // WPCS: XSS ok. } } diff --git a/includes/widgets/class-wc-widget-top-rated-products.php b/includes/widgets/class-wc-widget-top-rated-products.php index 30693af466f..1717e6a1336 100644 --- a/includes/widgets/class-wc-widget-top-rated-products.php +++ b/includes/widgets/class-wc-widget-top-rated-products.php @@ -1,18 +1,16 @@ 'DESC', 'meta_query' => WC()->query->get_meta_query(), 'tax_query' => WC()->query->get_tax_query(), - ); + ); // WPCS: slow query ok. $r = new WP_Query( $query_args ); @@ -100,7 +97,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget { $content = ob_get_clean(); - echo $content; + echo $content; // WPCS: XSS ok. $this->cache_widget( $args, $content ); }