Fixed class-wc-widget-products.php PHPCS violations
This commit is contained in:
parent
85aba0221a
commit
dfe3965fbb
|
@ -3,7 +3,7 @@
|
|||
* Tag Cloud Widget.
|
||||
*
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 2.3.0
|
||||
* @version 3.4.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* List products. One widget to rule them all.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Widgets
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 3.3.0
|
||||
* @extends WC_Widget
|
||||
* @package WooCommerce/Widgets
|
||||
* @version 3.3.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Widget products.
|
||||
*/
|
||||
class WC_Widget_Products extends WC_Widget {
|
||||
|
||||
|
@ -24,12 +22,12 @@ class WC_Widget_Products extends WC_Widget {
|
|||
$this->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', '<ul class="product_list_widget">' ) );
|
||||
|
@ -208,6 +208,6 @@ class WC_Widget_Products extends WC_Widget {
|
|||
|
||||
wp_reset_postdata();
|
||||
|
||||
echo $this->cache_widget( $args, ob_get_clean() );
|
||||
echo $this->cache_widget( $args, ob_get_clean() ); // WPCS: XSS ok.
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue