Merge pull request #19344 from woocommerce/update/widgets-phpcs

Fixed includes/widgets PHPCS violations
This commit is contained in:
Mike Jolley 2018-03-10 10:38:44 +00:00 committed by GitHub
commit 0f7568b68f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 349 additions and 312 deletions

View File

@ -1,19 +1,17 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Shopping Cart Widget. * Shopping Cart Widget.
* *
* Displays shopping cart widget. * Displays shopping cart widget.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 2.3.0
* @package WooCommerce/Widgets */
* @version 2.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget cart class.
*/ */
class WC_Widget_Cart extends WC_Widget { class WC_Widget_Cart extends WC_Widget {
@ -22,11 +20,11 @@ class WC_Widget_Cart extends WC_Widget {
*/ */
public function __construct() { public function __construct() {
$this->widget_cssclass = 'woocommerce widget_shopping_cart'; $this->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_id = 'woocommerce_widget_cart';
$this->widget_name = __( 'Cart', 'woocommerce' ); $this->widget_name = __( 'Cart', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Cart', 'woocommerce' ), 'std' => __( 'Cart', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
@ -46,8 +44,8 @@ class WC_Widget_Cart extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( apply_filters( 'woocommerce_widget_cart_is_hidden', is_cart() || is_checkout() ) ) { if ( apply_filters( 'woocommerce_widget_cart_is_hidden', is_cart() || is_checkout() ) ) {
@ -62,7 +60,7 @@ class WC_Widget_Cart extends WC_Widget {
echo '<div class="hide_cart_widget_if_empty">'; echo '<div class="hide_cart_widget_if_empty">';
} }
// 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 '<div class="widget_shopping_cart_content"></div>'; echo '<div class="widget_shopping_cart_content"></div>';
if ( $hide_if_empty ) { if ( $hide_if_empty ) {

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Layered Navigation Filters Widget. * Layered Navigation Filters Widget.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 2.3.0
* @package WooCommerce/Widgets */
* @version 2.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget layered nav filters.
*/ */
class WC_Widget_Layered_Nav_Filters extends WC_Widget { class WC_Widget_Layered_Nav_Filters extends WC_Widget {
@ -24,7 +22,7 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
$this->widget_id = 'woocommerce_layered_nav_filters'; $this->widget_id = 'woocommerce_layered_nav_filters';
$this->widget_name = __( 'Active Product Filters', 'woocommerce' ); $this->widget_name = __( 'Active Product Filters', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Active filters', 'woocommerce' ), 'std' => __( 'Active filters', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
@ -38,8 +36,8 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( ! is_shop() && ! is_product_taxonomy() ) { 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(); $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
$min_price = isset( $_GET['min_price'] ) ? wc_clean( $_GET['min_price'] ) : 0; $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( $_GET['max_price'] ) : 0; $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( ',', $_GET['rating_filter'] ) ) ) : array(); $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(); $base_link = $this->get_current_page_url();
if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price || ! empty( $rating_filter ) ) { 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 '<ul>'; echo '<ul>';
// Attributes // Attributes.
if ( ! empty( $_chosen_attributes ) ) { if ( ! empty( $_chosen_attributes ) ) {
foreach ( $_chosen_attributes as $taxonomy => $data ) { foreach ( $_chosen_attributes as $taxonomy => $data ) {
foreach ( $data['terms'] as $term_slug ) { foreach ( $data['terms'] as $term_slug ) {
if ( ! $term = get_term_by( 'slug', $term_slug, $taxonomy ) ) { $term = get_term_by( 'slug', $term_slug, $taxonomy );
if ( ! $term ) {
continue; continue;
} }
$filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) ); $filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) );
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( $_GET[ $filter_name ] ) ) : array(); $current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$current_filter = array_map( 'sanitize_title', $current_filter ); $current_filter = array_map( 'sanitize_title', $current_filter );
$new_filter = array_diff( $current_filter, array( $term_slug ) ); $new_filter = array_diff( $current_filter, array( $term_slug ) );
$link = remove_query_arg( array( 'add-to-cart', $filter_name ), $base_link ); $link = remove_query_arg( array( 'add-to-cart', $filter_name ), $base_link );
if ( sizeof( $new_filter ) > 0 ) { if ( count( $new_filter ) > 0 ) {
$link = add_query_arg( $filter_name, implode( ',', $new_filter ), $link ); $link = add_query_arg( $filter_name, implode( ',', $new_filter ), $link );
} }
@ -84,18 +83,22 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
if ( $min_price ) { if ( $min_price ) {
$link = remove_query_arg( 'min_price', $base_link ); $link = remove_query_arg( 'min_price', $base_link );
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Min %s', 'woocommerce' ), wc_price( $min_price ) ) . '</a></li>'; /* translators: %s: minimum price */
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Min %s', 'woocommerce' ), wc_price( $min_price ) ) . '</a></li>'; // WPCS: XSS ok.
} }
if ( $max_price ) { if ( $max_price ) {
$link = remove_query_arg( 'max_price', $base_link ); $link = remove_query_arg( 'max_price', $base_link );
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Max %s', 'woocommerce' ), wc_price( $max_price ) ) . '</a></li>'; /* translators: %s: maximum price */
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Max %s', 'woocommerce' ), wc_price( $max_price ) ) . '</a></li>'; // WPCS: XSS ok.
} }
if ( ! empty( $rating_filter ) ) { if ( ! empty( $rating_filter ) ) {
foreach ( $rating_filter as $rating ) { foreach ( $rating_filter as $rating ) {
$link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) ); $link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) );
$link = $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter', $base_link ); $link = $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter', $base_link );
/* translators: %s: rating */
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), esc_html( $rating ) ) . '</a></li>'; echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), esc_html( $rating ) ) . '</a></li>';
} }
} }

View File

@ -3,20 +3,13 @@
* Layered nav widget * Layered nav widget
* *
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.6.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { defined( 'ABSPATH' ) || exit;
exit;
}
/** /**
* Layered Navigation Widget. * Widget layered nav class.
*
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets
* @version 2.6.0
* @extends WC_Widget
*/ */
class WC_Widget_Layered_Nav extends WC_Widget { class WC_Widget_Layered_Nav extends WC_Widget {
@ -74,12 +67,12 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Filter by', 'woocommerce' ), 'std' => __( 'Filter by', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
), ),
'attribute' => array( 'attribute' => array(
'type' => 'select', 'type' => 'select',
'std' => '', 'std' => '',
'label' => __( 'Attribute', 'woocommerce' ), 'label' => __( 'Attribute', 'woocommerce' ),
@ -94,7 +87,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
'dropdown' => __( 'Dropdown', 'woocommerce' ), 'dropdown' => __( 'Dropdown', 'woocommerce' ),
), ),
), ),
'query_type' => array( 'query_type' => array(
'type' => 'select', 'type' => 'select',
'std' => 'and', 'std' => 'and',
'label' => __( 'Query type', 'woocommerce' ), 'label' => __( 'Query type', 'woocommerce' ),
@ -133,18 +126,18 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$orderby = wc_attribute_orderby( $taxonomy ); $orderby = wc_attribute_orderby( $taxonomy );
switch ( $orderby ) { switch ( $orderby ) {
case 'name' : case 'name':
$get_terms_args['orderby'] = 'name'; $get_terms_args['orderby'] = 'name';
$get_terms_args['menu_order'] = false; $get_terms_args['menu_order'] = false;
break; break;
case 'id' : case 'id':
$get_terms_args['orderby'] = 'id'; $get_terms_args['orderby'] = 'id';
$get_terms_args['order'] = 'ASC'; $get_terms_args['order'] = 'ASC';
$get_terms_args['menu_order'] = false; $get_terms_args['menu_order'] = false;
break; break;
case 'menu_order' : case 'menu_order':
$get_terms_args['menu_order'] = 'ASC'; $get_terms_args['menu_order'] = 'ASC';
break; break;
} }
$terms = get_terms( $taxonomy, $get_terms_args ); $terms = get_terms( $taxonomy, $get_terms_args );
@ -154,12 +147,12 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
switch ( $orderby ) { switch ( $orderby ) {
case 'name_num' : case 'name_num':
usort( $terms, '_wc_get_product_terms_name_num_usort_callback' ); usort( $terms, '_wc_get_product_terms_name_num_usort_callback' );
break; break;
case 'parent' : case 'parent':
usort( $terms, '_wc_get_product_terms_parent_usort_callback' ); usort( $terms, '_wc_get_product_terms_parent_usort_callback' );
break; break;
} }
ob_start(); ob_start();
@ -232,9 +225,11 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
$taxonomy_filter_name = str_replace( 'pa_', '', $taxonomy ); $taxonomy_filter_name = str_replace( 'pa_', '', $taxonomy );
$taxonomy_label = wc_attribute_label( $taxonomy ); $taxonomy_label = wc_attribute_label( $taxonomy );
$any_label = apply_filters( 'woocommerce_layered_nav_any_label', sprintf( __( 'Any %s', 'woocommerce' ), $taxonomy_label ), $taxonomy_label, $taxonomy );
$multiple = 'or' === $query_type; /* translators: %s: taxonomy name */
$current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array(); $any_label = apply_filters( 'woocommerce_layered_nav_any_label', sprintf( __( 'Any %s', 'woocommerce' ), $taxonomy_label ), $taxonomy_label, $taxonomy );
$multiple = 'or' === $query_type;
$current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array();
if ( '' === get_option( 'permalink_structure' ) ) { if ( '' === get_option( 'permalink_structure' ) ) {
$form_action = remove_query_arg( array( 'page', 'paged' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) ); $form_action = remove_query_arg( array( 'page', 'paged' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
@ -254,8 +249,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
// Get count based on current view. // Get count based on current view.
$option_is_set = in_array( $term->slug, $current_values ); $option_is_set = in_array( $term->slug, $current_values, true );
$count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0; $count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0;
// Only show options with count > 0. // Only show options with count > 0.
if ( 0 < $count ) { if ( 0 < $count ) {
@ -281,7 +276,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
echo wc_query_string_form_fields( null, array( 'filter_' . $taxonomy_filter_name, 'query_type_' . $taxonomy_filter_name ), '', true ); // @codingStandardsIgnoreLine echo wc_query_string_form_fields( null, array( 'filter_' . $taxonomy_filter_name, 'query_type_' . $taxonomy_filter_name ), '', true ); // @codingStandardsIgnoreLine
echo '</form>'; echo '</form>';
wc_enqueue_js( " wc_enqueue_js(
"
// Update value on change. // Update value on change.
jQuery( '.dropdown_layered_nav_" . esc_js( $taxonomy_filter_name ) . "' ).change( function() { jQuery( '.dropdown_layered_nav_" . esc_js( $taxonomy_filter_name ) . "' ).change( function() {
var slug = jQuery( this ).val(); var slug = jQuery( this ).val();
@ -310,7 +306,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
}; };
wc_layered_nav_select(); wc_layered_nav_select();
} }
" ); "
);
} }
return $found; return $found;
@ -340,10 +337,10 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
} }
$meta_query = new WP_Meta_Query( $meta_query ); $meta_query = new WP_Meta_Query( $meta_query );
$tax_query = new WP_Tax_Query( $tax_query ); $tax_query = new WP_Tax_Query( $tax_query );
$meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' ); $meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
$tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' ); $tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
// Generate query. // Generate query.
$query = array(); $query = array();
@ -355,13 +352,14 @@ class WC_Widget_Layered_Nav extends WC_Widget {
INNER JOIN {$wpdb->terms} AS terms USING( term_id ) INNER JOIN {$wpdb->terms} AS terms USING( term_id )
" . $tax_query_sql['join'] . $meta_query_sql['join']; " . $tax_query_sql['join'] . $meta_query_sql['join'];
$query['where'] = " $query['where'] = "
WHERE {$wpdb->posts}.post_type IN ( 'product' ) WHERE {$wpdb->posts}.post_type IN ( 'product' )
AND {$wpdb->posts}.post_status = 'publish'" AND {$wpdb->posts}.post_status = 'publish'"
. $tax_query_sql['where'] . $meta_query_sql['where'] . . $tax_query_sql['where'] . $meta_query_sql['where'] .
'AND terms.term_id IN (' . implode( ',', array_map( 'absint', $term_ids ) ) . ')'; 'AND terms.term_id IN (' . implode( ',', array_map( 'absint', $term_ids ) ) . ')';
if ( $search = WC_Query::get_main_search_query_sql() ) { $search = WC_Query::get_main_search_query_sql();
if ( $search ) {
$query['where'] .= ' AND ' . $search; $query['where'] .= ' AND ' . $search;
} }
@ -401,7 +399,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
foreach ( $terms as $term ) { foreach ( $terms as $term ) {
$current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array(); $current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array();
$option_is_set = in_array( $term->slug, $current_values ); $option_is_set = in_array( $term->slug, $current_values, true );
$count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0; $count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0;
// Skip the term for the current archive. // Skip the term for the current archive.
@ -417,10 +415,10 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
$filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) ); $filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) );
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); $current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$current_filter = array_map( 'sanitize_title', $current_filter ); $current_filter = array_map( 'sanitize_title', $current_filter );
if ( ! in_array( $term->slug, $current_filter ) ) { if ( ! in_array( $term->slug, $current_filter, true ) ) {
$current_filter[] = $term->slug; $current_filter[] = $term->slug;
} }

View File

@ -1,19 +1,17 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Price Filter Widget and related functions. * Price Filter Widget and related functions.
* *
* Generates a range slider to filter products by price. * Generates a range slider to filter products by price.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 2.3.0
* @package WooCommerce/Widgets */
* @version 2.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget price filter class.
*/ */
class WC_Widget_Price_Filter extends WC_Widget { class WC_Widget_Price_Filter extends WC_Widget {
@ -26,23 +24,25 @@ class WC_Widget_Price_Filter extends WC_Widget {
$this->widget_id = 'woocommerce_price_filter'; $this->widget_id = 'woocommerce_price_filter';
$this->widget_name = __( 'Filter Products by Price', 'woocommerce' ); $this->widget_name = __( 'Filter Products by Price', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Filter by price', 'woocommerce' ), 'std' => __( 'Filter by price', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
), ),
); );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' ); wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' );
wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), WC_VERSION, true ); wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), WC_VERSION, true );
wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), WC_VERSION, true ); wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), WC_VERSION, true );
wp_localize_script( 'wc-price-slider', 'woocommerce_price_slider_params', array( wp_localize_script(
'currency_format_num_decimals' => 0, 'wc-price-slider', 'woocommerce_price_slider_params', array(
'currency_format_symbol' => get_woocommerce_currency_symbol(), 'currency_format_num_decimals' => 0,
'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), 'currency_format_symbol' => get_woocommerce_currency_symbol(),
'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ),
'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ),
) ); 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ),
)
);
if ( is_customize_preview() ) { if ( is_customize_preview() ) {
wp_enqueue_script( 'wc-price-slider' ); wp_enqueue_script( 'wc-price-slider' );
@ -56,8 +56,8 @@ class WC_Widget_Price_Filter extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
global $wp; global $wp;
@ -89,8 +89,8 @@ class WC_Widget_Price_Filter extends WC_Widget {
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) ); $form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) );
} }
$min_price = isset( $_GET['min_price'] ) ? esc_attr( $_GET['min_price'] ) : apply_filters( 'woocommerce_price_filter_widget_min_amount', $min ); $min_price = isset( $_GET['min_price'] ) ? wc_clean( wp_unslash( $_GET['min_price'] ) ) : apply_filters( 'woocommerce_price_filter_widget_min_amount', $min ); // WPCS: input var ok, CSRF ok.
$max_price = isset( $_GET['max_price'] ) ? esc_attr( $_GET['max_price'] ) : apply_filters( 'woocommerce_price_filter_widget_max_amount', $max ); $max_price = isset( $_GET['max_price'] ) ? wc_clean( wp_unslash( $_GET['max_price'] ) ) : apply_filters( 'woocommerce_price_filter_widget_max_amount', $max ); // WPCS: input var ok, CSRF ok.
echo '<form method="get" action="' . esc_url( $form_action ) . '"> echo '<form method="get" action="' . esc_url( $form_action ) . '">
<div class="price_slider_wrapper"> <div class="price_slider_wrapper">
@ -106,13 +106,14 @@ class WC_Widget_Price_Filter extends WC_Widget {
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</div> </div>
</form>'; </form>'; // WPCS: XSS ok.
$this->widget_end( $args ); $this->widget_end( $args );
} }
/** /**
* Get filtered min price for current products. * Get filtered min price for current products.
*
* @return int * @return int
*/ */
protected function get_filtered_price() { 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 = "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 .= " 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' ) ) ) ) . "') $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 {$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_key IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) ) . "')
AND price_meta.meta_value > '' "; AND price_meta.meta_value > '' ";
$sql .= $tax_query_sql['where'] . $meta_query_sql['where']; $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; $sql .= ' AND ' . $search;
} }
return $wpdb->get_row( $sql ); return $wpdb->get_row( $sql ); // WPCS: unprepared SQL ok.
} }
} }

View File

@ -2,15 +2,11 @@
/** /**
* Product Categories Widget * Product Categories Widget
* *
* @author Automattic * @package WooCommerce/Widgets
* @category Widgets * @version 2.3.0
* @package WooCommerce/Widgets
* @version 2.3.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { defined( 'ABSPATH' ) || exit;
exit;
}
/** /**
* Product categories widget class. * Product categories widget class.
@ -42,31 +38,31 @@ class WC_Widget_Product_Categories extends WC_Widget {
$this->widget_id = 'woocommerce_product_categories'; $this->widget_id = 'woocommerce_product_categories';
$this->widget_name = __( 'Product Categories', 'woocommerce' ); $this->widget_name = __( 'Product Categories', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Product categories', 'woocommerce' ), 'std' => __( 'Product categories', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
), ),
'orderby' => array( 'orderby' => array(
'type' => 'select', 'type' => 'select',
'std' => 'name', 'std' => 'name',
'label' => __( 'Order by', 'woocommerce' ), 'label' => __( 'Order by', 'woocommerce' ),
'options' => array( 'options' => array(
'order' => __( 'Category order', 'woocommerce' ), 'order' => __( 'Category order', 'woocommerce' ),
'name' => __( 'Name', 'woocommerce' ), 'name' => __( 'Name', 'woocommerce' ),
), ),
), ),
'dropdown' => array( 'dropdown' => array(
'type' => 'checkbox', 'type' => 'checkbox',
'std' => 0, 'std' => 0,
'label' => __( 'Show as dropdown', 'woocommerce' ), 'label' => __( 'Show as dropdown', 'woocommerce' ),
), ),
'count' => array( 'count' => array(
'type' => 'checkbox', 'type' => 'checkbox',
'std' => 0, 'std' => 0,
'label' => __( 'Show product counts', 'woocommerce' ), 'label' => __( 'Show product counts', 'woocommerce' ),
), ),
'hierarchical' => array( 'hierarchical' => array(
'type' => 'checkbox', 'type' => 'checkbox',
'std' => 1, 'std' => 1,
'label' => __( 'Show hierarchy', 'woocommerce' ), 'label' => __( 'Show hierarchy', 'woocommerce' ),
@ -76,12 +72,12 @@ class WC_Widget_Product_Categories extends WC_Widget {
'std' => 0, 'std' => 0,
'label' => __( 'Only show children of the current category', 'woocommerce' ), 'label' => __( 'Only show children of the current category', 'woocommerce' ),
), ),
'hide_empty' => array( 'hide_empty' => array(
'type' => 'checkbox', 'type' => 'checkbox',
'std' => 0, 'std' => 0,
'label' => __( 'Hide empty categories', 'woocommerce' ), 'label' => __( 'Hide empty categories', 'woocommerce' ),
), ),
'max_depth' => array( 'max_depth' => array(
'type' => 'text', 'type' => 'text',
'std' => '', 'std' => '',
'label' => __( 'Maximum depth', 'woocommerce' ), 'label' => __( 'Maximum depth', 'woocommerce' ),
@ -125,7 +121,7 @@ class WC_Widget_Product_Categories extends WC_Widget {
if ( 'order' === $orderby ) { if ( 'order' === $orderby ) {
$list_args['menu_order'] = 'asc'; $list_args['menu_order'] = 'asc';
} else { } else {
$list_args['orderby'] = 'title'; $list_args['orderby'] = 'title';
} }
$this->current_cat = false; $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' ); $this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
} elseif ( is_singular( 'product' ) ) { } elseif ( is_singular( 'product' ) ) {
$terms = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_product_categories_widget_product_terms_args', array( $terms = wc_get_product_terms(
'orderby' => 'parent', $post->ID, 'product_cat', apply_filters(
'order' => 'DESC', 'woocommerce_product_categories_widget_product_terms_args', array(
) ) ); 'orderby' => 'parent',
'order' => 'DESC',
)
)
);
if ( $terms ) { 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->current_cat = $main_term;
$this->cat_ancestors = get_ancestors( $main_term->term_id, 'product_cat' ); $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. // Gather siblings of ancestors.
if ( $this->cat_ancestors ) { if ( $this->cat_ancestors ) {
foreach ( $this->cat_ancestors as $ancestor ) { foreach ( $this->cat_ancestors as $ancestor ) {
$include = array_merge( $include, get_terms( $include = array_merge(
'product_cat', $include, get_terms(
array( 'product_cat',
'fields' => 'ids', array(
'parent' => $ancestor, 'fields' => 'ids',
'hierarchical' => false, 'parent' => $ancestor,
'hide_empty' => false, 'hierarchical' => false,
'hide_empty' => false,
)
) )
) ); );
} }
} }
} else { } else {
@ -198,7 +200,7 @@ class WC_Widget_Product_Categories extends WC_Widget {
'hide_empty' => false, 'hide_empty' => false,
) )
); );
} // End if(). }
$list_args['include'] = implode( ',', $include ); $list_args['include'] = implode( ',', $include );
$dropdown_args['include'] = $list_args['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['depth'] = 1;
$list_args['child_of'] = 0; $list_args['child_of'] = 0;
$list_args['hierarchical'] = 1; $list_args['hierarchical'] = 1;
} // End if(). }
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
if ( $dropdown ) { if ( $dropdown ) {
wc_product_dropdown_categories( apply_filters( 'woocommerce_product_categories_widget_dropdown_args', wp_parse_args( $dropdown_args, array( wc_product_dropdown_categories(
'show_count' => $count, apply_filters(
'hierarchical' => $hierarchical, 'woocommerce_product_categories_widget_dropdown_args', wp_parse_args(
'show_uncategorized' => 0, $dropdown_args, array(
'orderby' => $orderby, 'show_count' => $count,
'selected' => $this->current_cat ? $this->current_cat->slug : '', 'hierarchical' => $hierarchical,
) ) ) ); 'show_uncategorized' => 0,
wc_enqueue_js( " 'orderby' => $orderby,
'selected' => $this->current_cat ? $this->current_cat->slug : '',
)
)
)
);
wc_enqueue_js(
"
jQuery( '.dropdown_product_cat' ).change( function() { jQuery( '.dropdown_product_cat' ).change( function() {
if ( jQuery(this).val() != '' ) { if ( jQuery(this).val() != '' ) {
var this_page = ''; var this_page = '';
@ -238,11 +247,12 @@ class WC_Widget_Product_Categories extends WC_Widget {
location.href = this_page; location.href = this_page;
} }
}); });
" ); "
);
} else { } 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['title_li'] = '';
$list_args['pad_counts'] = 1; $list_args['pad_counts'] = 1;
$list_args['show_option_none'] = __( 'No product categories exist.', 'woocommerce' ); $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 ) ); wp_list_categories( apply_filters( 'woocommerce_product_categories_widget_args', $list_args ) );
echo '</ul>'; echo '</ul>';
} // End if(). }
$this->widget_end( $args ); $this->widget_end( $args );
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Product Search Widget. * Product Search Widget.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 2.3.0
* @package WooCommerce/Widgets */
* @version 2.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget product search class.
*/ */
class WC_Widget_Product_Search extends WC_Widget { class WC_Widget_Product_Search extends WC_Widget {
@ -24,7 +22,7 @@ class WC_Widget_Product_Search extends WC_Widget {
$this->widget_id = 'woocommerce_product_search'; $this->widget_id = 'woocommerce_product_search';
$this->widget_name = __( 'Product Search', 'woocommerce' ); $this->widget_name = __( 'Product Search', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => '', 'std' => '',
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
@ -39,8 +37,8 @@ class WC_Widget_Product_Search extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );

View File

@ -1,17 +1,17 @@
<?php <?php
/**
* Tag Cloud Widget.
*
* @package WooCommerce/Widgets
* @version 3.4.0
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
/** /**
* Tag Cloud Widget. * Widget product tag cloud
*
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets
* @version 2.3.0
* @extends WC_Widget
*/ */
class WC_Widget_Product_Tag_Cloud extends WC_Widget { class WC_Widget_Product_Tag_Cloud extends WC_Widget {
@ -24,7 +24,7 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
$this->widget_id = 'woocommerce_product_tag_cloud'; $this->widget_id = 'woocommerce_product_tag_cloud';
$this->widget_name = __( 'Product Tag Cloud', 'woocommerce' ); $this->widget_name = __( 'Product Tag Cloud', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Product tags', 'woocommerce' ), 'std' => __( 'Product tags', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
@ -39,14 +39,14 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
$current_taxonomy = $this->_get_current_taxonomy( $instance ); $current_taxonomy = $this->get_current_taxonomy( $instance );
if ( empty( $instance['title'] ) ) { if ( empty( $instance['title'] ) ) {
$taxonomy = get_taxonomy( $current_taxonomy ); $taxonomy = get_taxonomy( $current_taxonomy );
$instance['title'] = $taxonomy->labels->name; $instance['title'] = $taxonomy->labels->name;
} }
@ -54,10 +54,14 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
echo '<div class="tagcloud">'; echo '<div class="tagcloud">';
wp_tag_cloud( apply_filters( 'woocommerce_product_tag_cloud_widget_args', array( wp_tag_cloud(
'taxonomy' => $current_taxonomy, apply_filters(
'topic_count_text_callback' => array( $this, '_topic_count_text' ), 'woocommerce_product_tag_cloud_widget_args', array(
) ) ); 'taxonomy' => $current_taxonomy,
'topic_count_text_callback' => array( $this, 'topic_count_text' ),
)
)
);
echo '</div>'; echo '</div>';
@ -67,22 +71,50 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
/** /**
* Return the taxonomy being displayed. * Return the taxonomy being displayed.
* *
* @param object $instance * @param object $instance Widget instance.
* @return string * @return string
*/ */
public function _get_current_taxonomy( $instance ) { public function get_current_taxonomy( $instance ) {
return 'product_tag'; return 'product_tag';
} }
/** /**
* Returns topic count text. * Returns topic count text.
* *
* @since 2.6.0 * @since 3.4.0
* @param int $count * @param int $count Count text.
* @return string * @return string
*/ */
public function _topic_count_text( $count ) { public function topic_count_text( $count ) {
/* translators: %s: product count */ /* translators: %s: product count */
return sprintf( _n( '%s product', '%s products', $count, 'woocommerce' ), number_format_i18n( $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
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* List products. One widget to rule them all. * List products. One widget to rule them all.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 3.3.0
* @package WooCommerce/Widgets */
* @version 3.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget products.
*/ */
class WC_Widget_Products extends WC_Widget { 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_id = 'woocommerce_products';
$this->widget_name = __( 'Products', 'woocommerce' ); $this->widget_name = __( 'Products', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Products', 'woocommerce' ), 'std' => __( 'Products', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
), ),
'number' => array( 'number' => array(
'type' => 'number', 'type' => 'number',
'step' => 1, 'step' => 1,
'min' => 1, 'min' => 1,
@ -37,37 +35,37 @@ class WC_Widget_Products extends WC_Widget {
'std' => 5, 'std' => 5,
'label' => __( 'Number of products to show', 'woocommerce' ), 'label' => __( 'Number of products to show', 'woocommerce' ),
), ),
'show' => array( 'show' => array(
'type' => 'select', 'type' => 'select',
'std' => '', 'std' => '',
'label' => __( 'Show', 'woocommerce' ), 'label' => __( 'Show', 'woocommerce' ),
'options' => array( 'options' => array(
'' => __( 'All products', 'woocommerce' ), '' => __( 'All products', 'woocommerce' ),
'featured' => __( 'Featured products', 'woocommerce' ), 'featured' => __( 'Featured products', 'woocommerce' ),
'onsale' => __( 'On-sale products', 'woocommerce' ), 'onsale' => __( 'On-sale products', 'woocommerce' ),
), ),
), ),
'orderby' => array( 'orderby' => array(
'type' => 'select', 'type' => 'select',
'std' => 'date', 'std' => 'date',
'label' => __( 'Order by', 'woocommerce' ), 'label' => __( 'Order by', 'woocommerce' ),
'options' => array( 'options' => array(
'date' => __( 'Date', 'woocommerce' ), 'date' => __( 'Date', 'woocommerce' ),
'price' => __( 'Price', 'woocommerce' ), 'price' => __( 'Price', 'woocommerce' ),
'rand' => __( 'Random', 'woocommerce' ), 'rand' => __( 'Random', 'woocommerce' ),
'sales' => __( 'Sales', 'woocommerce' ), 'sales' => __( 'Sales', 'woocommerce' ),
), ),
), ),
'order' => array( 'order' => array(
'type' => 'select', 'type' => 'select',
'std' => 'desc', 'std' => 'desc',
'label' => _x( 'Order', 'Sorting order', 'woocommerce' ), 'label' => _x( 'Order', 'Sorting order', 'woocommerce' ),
'options' => array( 'options' => array(
'asc' => __( 'ASC', 'woocommerce' ), 'asc' => __( 'ASC', 'woocommerce' ),
'desc' => __( 'DESC', 'woocommerce' ), 'desc' => __( 'DESC', 'woocommerce' ),
), ),
), ),
'hide_free' => array( 'hide_free' => array(
'type' => 'checkbox', 'type' => 'checkbox',
'std' => 0, 'std' => 0,
'label' => __( 'Hide free products', 'woocommerce' ), 'label' => __( 'Hide free products', 'woocommerce' ),
@ -84,15 +82,16 @@ class WC_Widget_Products extends WC_Widget {
/** /**
* Query the products and return them. * Query the products and return them.
* @param array $args *
* @param array $instance * @param array $args Arguments.
* @param array $instance Widget instance.
* @return WP_Query * @return WP_Query
*/ */
public function get_products( $args, $instance ) { public function get_products( $args, $instance ) {
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
$show = ! empty( $instance['show'] ) ? sanitize_title( $instance['show'] ) : $this->settings['show']['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']; $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(); $product_visibility_term_ids = wc_get_product_visibility_term_ids();
$query_args = array( $query_args = array(
@ -105,7 +104,7 @@ class WC_Widget_Products extends WC_Widget {
'tax_query' => array( 'tax_query' => array(
'relation' => 'AND', 'relation' => 'AND',
), ),
); ); // WPCS: slow query ok.
if ( empty( $instance['show_hidden'] ) ) { if ( empty( $instance['show_hidden'] ) ) {
$query_args['tax_query'][] = array( $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'], 'terms' => is_search() ? $product_visibility_term_ids['exclude-from-search'] : $product_visibility_term_ids['exclude-from-catalog'],
'operator' => 'NOT IN', 'operator' => 'NOT IN',
); );
$query_args['post_parent'] = 0; $query_args['post_parent'] = 0;
} }
if ( ! empty( $instance['hide_free'] ) ) { if ( ! empty( $instance['hide_free'] ) ) {
@ -134,18 +133,18 @@ class WC_Widget_Products extends WC_Widget {
'terms' => $product_visibility_term_ids['outofstock'], 'terms' => $product_visibility_term_ids['outofstock'],
'operator' => 'NOT IN', 'operator' => 'NOT IN',
), ),
); ); // WPCS: slow query ok.
} }
switch ( $show ) { switch ( $show ) {
case 'featured' : case 'featured':
$query_args['tax_query'][] = array( $query_args['tax_query'][] = array(
'taxonomy' => 'product_visibility', 'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id', 'field' => 'term_taxonomy_id',
'terms' => $product_visibility_term_ids['featured'], 'terms' => $product_visibility_term_ids['featured'],
); );
break; break;
case 'onsale' : case 'onsale':
$product_ids_on_sale = wc_get_product_ids_on_sale(); $product_ids_on_sale = wc_get_product_ids_on_sale();
$product_ids_on_sale[] = 0; $product_ids_on_sale[] = 0;
$query_args['post__in'] = $product_ids_on_sale; $query_args['post__in'] = $product_ids_on_sale;
@ -153,19 +152,19 @@ class WC_Widget_Products extends WC_Widget {
} }
switch ( $orderby ) { switch ( $orderby ) {
case 'price' : case 'price':
$query_args['meta_key'] = '_price'; $query_args['meta_key'] = '_price'; // WPCS: slow query ok.
$query_args['orderby'] = 'meta_value_num'; $query_args['orderby'] = 'meta_value_num';
break; break;
case 'rand' : case 'rand':
$query_args['orderby'] = 'rand'; $query_args['orderby'] = 'rand';
break; break;
case 'sales' : case 'sales':
$query_args['meta_key'] = 'total_sales'; $query_args['meta_key'] = 'total_sales'; // WPCS: slow query ok.
$query_args['orderby'] = 'meta_value_num'; $query_args['orderby'] = 'meta_value_num';
break; break;
default : default:
$query_args['orderby'] = 'date'; $query_args['orderby'] = 'date';
} }
return new WP_Query( apply_filters( 'woocommerce_products_widget_query_args', $query_args ) ); 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 * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( $this->get_cached_widget( $args ) ) { if ( $this->get_cached_widget( $args ) ) {
@ -186,7 +185,8 @@ class WC_Widget_Products extends WC_Widget {
ob_start(); 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 ); $this->widget_start( $args, $instance );
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) ); 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(); wp_reset_postdata();
echo $this->cache_widget( $args, ob_get_clean() ); echo $this->cache_widget( $args, ob_get_clean() ); // WPCS: XSS ok.
} }
} }

View File

@ -1,18 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Rating Filter Widget and related functions. * Rating Filter Widget and related functions.
* *
* * @package WooCommerce/Widgets
* @author WooThemes * @version 2.6.0
* @category Widgets */
* @package WooCommerce/Widgets
* @version 2.6.0 defined( 'ABSPATH' ) || exit;
* @extends WC_Widget
/**
* Widget rating filter class.
*/ */
class WC_Widget_Rating_Filter extends WC_Widget { class WC_Widget_Rating_Filter extends WC_Widget {
@ -25,7 +22,7 @@ class WC_Widget_Rating_Filter extends WC_Widget {
$this->widget_id = 'woocommerce_rating_filter'; $this->widget_id = 'woocommerce_rating_filter';
$this->widget_name = __( 'Filter Products by Rating', 'woocommerce' ); $this->widget_name = __( 'Filter Products by Rating', 'woocommerce' );
$this->settings = array( $this->settings = array(
'title' => array( 'title' => array(
'type' => 'text', 'type' => 'text',
'std' => __( 'Average rating', 'woocommerce' ), 'std' => __( 'Average rating', 'woocommerce' ),
'label' => __( 'Title', 'woocommerce' ), 'label' => __( 'Title', 'woocommerce' ),
@ -36,7 +33,8 @@ class WC_Widget_Rating_Filter extends WC_Widget {
/** /**
* Count products after other filters have occurred by adjusting the main query. * Count products after other filters have occurred by adjusting the main query.
* @param int $rating *
* @param int $rating Rating.
* @return int * @return int
*/ */
protected function get_filtered_product_count( $rating ) { protected function get_filtered_product_count( $rating ) {
@ -55,7 +53,7 @@ class WC_Widget_Rating_Filter extends WC_Widget {
// Set new rating filter. // Set new rating filter.
$product_visibility_terms = wc_get_product_visibility_term_ids(); $product_visibility_terms = wc_get_product_visibility_term_ids();
$tax_query[] = array( $tax_query[] = array(
'taxonomy' => 'product_visibility', 'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id', 'field' => 'term_taxonomy_id',
'terms' => $product_visibility_terms[ 'rated-' . $rating ], 'terms' => $product_visibility_terms[ 'rated-' . $rating ],
@ -73,20 +71,20 @@ class WC_Widget_Rating_Filter extends WC_Widget {
$sql .= " WHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish' "; $sql .= " WHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish' ";
$sql .= $tax_query_sql['where'] . $meta_query_sql['where']; $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; $sql .= ' AND ' . $search;
} }
return absint( $wpdb->get_var( $sql ) ); return absint( $wpdb->get_var( $sql ) ); // WPCS: unprepared SQL ok.
} }
/** /**
* widget function. * Widget function.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( ! is_shop() && ! is_product_taxonomy() ) { if ( ! is_shop() && ! is_product_taxonomy() ) {
@ -100,7 +98,7 @@ class WC_Widget_Rating_Filter extends WC_Widget {
ob_start(); ob_start();
$found = false; $found = false;
$rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', $_GET['rating_filter'] ) ) ) : array(); $rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', wp_unslash( $_GET['rating_filter'] ) ) ) ) : array(); // WPCS: input var ok, CSRF ok, sanitization ok.
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
@ -114,18 +112,18 @@ class WC_Widget_Rating_Filter extends WC_Widget {
$found = true; $found = true;
$link = $this->get_current_page_url(); $link = $this->get_current_page_url();
if ( in_array( $rating, $rating_filter ) ) { if ( in_array( $rating, $rating_filter, true ) ) {
$link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) ); $link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) );
} else { } else {
$link_ratings = implode( ',', array_merge( $rating_filter, array( $rating ) ) ); $link_ratings = implode( ',', array_merge( $rating_filter, array( $rating ) ) );
} }
$class = in_array( $rating, $rating_filter ) ? 'wc-layered-nav-rating chosen' : 'wc-layered-nav-rating'; $class = in_array( $rating, $rating_filter, true ) ? 'wc-layered-nav-rating chosen' : 'wc-layered-nav-rating';
$link = apply_filters( 'woocommerce_rating_filter_link', $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter' ) ); $link = apply_filters( 'woocommerce_rating_filter_link', $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter' ) );
$rating_html = wc_get_star_rating_html( $rating ); $rating_html = wc_get_star_rating_html( $rating );
$count_html = esc_html( apply_filters( 'woocommerce_rating_filter_count', "({$count})", $count, $rating ) ); $count_html = esc_html( apply_filters( 'woocommerce_rating_filter_count', "({$count})", $count, $rating ) );
printf( '<li class="%s"><a href="%s"><span class="star-rating">%s</span> %s</a></li>', esc_attr( $class ), esc_url( $link ), $rating_html, $count_html ); printf( '<li class="%s"><a href="%s"><span class="star-rating">%s</span> %s</a></li>', esc_attr( $class ), esc_url( $link ), $rating_html, $count_html ); // WPCS: XSS ok.
} }
echo '</ul>'; echo '</ul>';
@ -135,7 +133,7 @@ class WC_Widget_Rating_Filter extends WC_Widget {
if ( ! $found ) { if ( ! $found ) {
ob_end_clean(); ob_end_clean();
} else { } else {
echo ob_get_clean(); echo ob_get_clean(); // WPCS: XSS ok.
} }
} }
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Recent Reviews Widget. * Recent Reviews Widget.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 2.3.0
* @package WooCommerce/Widgets */
* @version 2.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget recent reviews class.
*/ */
class WC_Widget_Recent_Reviews extends WC_Widget { class WC_Widget_Recent_Reviews extends WC_Widget {
@ -46,11 +44,10 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
global $comments, $comment; global $comments, $comment;
if ( $this->get_cached_widget( $args ) ) { if ( $this->get_cached_widget( $args ) ) {
@ -60,7 +57,15 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
ob_start(); ob_start();
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; $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 ) { if ( $comments ) {
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
@ -77,12 +82,12 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">'; echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . '</a>'; echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . '</a>'; // WPCS: XSS ok.
echo $rating_html; echo $rating_html; // WPCS: XSS ok.
/* translators: %s: review author */ /* translators: %s: review author */
echo '<span class="reviewer">' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . '</span>'; echo '<span class="reviewer">' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . '</span>'; // WPCS: XSS ok.
echo '</li>'; echo '</li>';
} }
@ -94,7 +99,7 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
$content = ob_get_clean(); $content = ob_get_clean();
echo $content; echo $content; // WPCS: XSS ok.
$this->cache_widget( $args, $content ); $this->cache_widget( $args, $content );
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Recent Products Widget. * Recent Products Widget.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 3.3.0
* @package WooCommerce/Widgets */
* @version 3.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget recently viewed.
*/ */
class WC_Widget_Recently_Viewed extends WC_Widget { class WC_Widget_Recently_Viewed extends WC_Widget {
@ -46,13 +44,11 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', wp_unslash( $_COOKIE['woocommerce_recently_viewed'] ) ) : array(); // @codingStandardsIgnoreLine
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ) : array();
$viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) ); $viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );
if ( empty( $viewed_products ) ) { if ( empty( $viewed_products ) ) {
@ -80,7 +76,7 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
'terms' => 'outofstock', 'terms' => 'outofstock',
'operator' => 'NOT IN', 'operator' => 'NOT IN',
), ),
); ); // WPCS: slow query ok.
} }
$r = new WP_Query( apply_filters( 'woocommerce_recently_viewed_products_widget_query_args', $query_args ) ); $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(); $content = ob_get_clean();
echo $content; echo $content; // WPCS: XSS ok.
} }
} }

View File

@ -1,18 +1,16 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Top Rated Products Widget. * Top Rated Products Widget.
* Gets and displays top rated products in an unordered list. * Gets and displays top rated products in an unordered list.
* *
* @author WooThemes * @package WooCommerce/Widgets
* @category Widgets * @version 3.3.0
* @package WooCommerce/Widgets */
* @version 3.3.0
* @extends WC_Widget defined( 'ABSPATH' ) || exit;
/**
* Widget top rated products class.
*/ */
class WC_Widget_Top_Rated_Products extends WC_Widget { class WC_Widget_Top_Rated_Products extends WC_Widget {
@ -47,9 +45,8 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
@ -71,7 +68,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
'order' => 'DESC', 'order' => 'DESC',
'meta_query' => WC()->query->get_meta_query(), 'meta_query' => WC()->query->get_meta_query(),
'tax_query' => WC()->query->get_tax_query(), 'tax_query' => WC()->query->get_tax_query(),
); ); // WPCS: slow query ok.
$r = new WP_Query( $query_args ); $r = new WP_Query( $query_args );
@ -100,7 +97,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
$content = ob_get_clean(); $content = ob_get_clean();
echo $content; echo $content; // WPCS: XSS ok.
$this->cache_widget( $args, $content ); $this->cache_widget( $args, $content );
} }