Fix code sniffer errors in some files.

Fixed files:

includes/abstracts/abstract-wc-product.php
includes/class-wc-query.php
includes/wc-template-functions.php
includes/widgets/class-wc-widget-layered-nav.php
templates/loop/result-count.php
tests/unit-tests/util/class-wc-tests-wc-query.php
This commit is contained in:
Nestor Soriano 2020-04-21 15:52:40 +02:00
parent 578b205b4e
commit c27283dffe
6 changed files with 116 additions and 52 deletions

View File

@ -1990,8 +1990,13 @@ class WC_Product extends WC_Abstract_Legacy_Product {
public function get_price_suffix( $price = '', $qty = 1 ) {
$html = '';
<<<<<<< HEAD
$suffix = get_option( 'woocommerce_price_display_suffix' );
if ( $suffix && wc_tax_enabled() && 'taxable' === $this->get_tax_status() ) {
=======
// phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure, WordPress.CodeAnalysis.AssignmentInCondition.Found
if ( ( $suffix = get_option( 'woocommerce_price_display_suffix' ) ) && wc_tax_enabled() && 'taxable' === $this->get_tax_status() ) {
>>>>>>> cd077dfb6... Fix code sniffer errors in some files.
if ( '' === $price ) {
$price = $this->get_price();
}

View File

@ -32,7 +32,7 @@ class WC_Query {
*
* @var array
*/
private static $_chosen_attributes;
private static $chosen_attributes;
/**
* Constructor for the query class. Hooks in methods.
@ -54,7 +54,8 @@ class WC_Query {
* Get any errors from querystring.
*/
public function get_errors() {
$error = ! empty( $_GET['wc_error'] ) ? sanitize_text_field( wp_unslash( $_GET['wc_error'] ) ) : ''; // WPCS: input var ok, CSRF ok.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$error = ! empty( $_GET['wc_error'] ) ? sanitize_text_field( wp_unslash( $_GET['wc_error'] ) ) : '';
if ( $error && ! wc_has_notice( $error, 'error' ) ) {
wc_add_notice( $error, 'error' );
@ -217,14 +218,16 @@ class WC_Query {
public function parse_request() {
global $wp;
// phpcs:disable WordPress.Security.NonceVerification.Recommended
// Map query vars to their keys, or get them if endpoints are not supported.
foreach ( $this->get_query_vars() as $key => $var ) {
if ( isset( $_GET[ $var ] ) ) { // WPCS: input var ok, CSRF ok.
$wp->query_vars[ $key ] = sanitize_text_field( wp_unslash( $_GET[ $var ] ) ); // WPCS: input var ok, CSRF ok.
if ( isset( $_GET[ $var ] ) ) {
$wp->query_vars[ $key ] = sanitize_text_field( wp_unslash( $_GET[ $var ] ) );
} elseif ( isset( $wp->query_vars[ $var ] ) ) {
$wp->query_vars[ $key ] = $wp->query_vars[ $var ];
}
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
}
/**
@ -447,7 +450,8 @@ class WC_Query {
public function get_catalog_ordering_args( $orderby = '', $order = '' ) {
// Get ordering from query string unless defined.
if ( ! $orderby ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( (string) wp_unslash( $_GET['orderby'] ) ) : wc_clean( get_query_var( 'orderby' ) ); // WPCS: sanitization ok, input var ok, CSRF ok.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( (string) wp_unslash( $_GET['orderby'] ) ) : wc_clean( get_query_var( 'orderby' ) );
if ( ! $orderby_value ) {
if ( is_search() ) {
@ -522,12 +526,15 @@ class WC_Query {
public function price_filter_post_clauses( $args, $wp_query ) {
global $wpdb;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! $wp_query->is_main_query() || ( ! isset( $_GET['max_price'] ) && ! isset( $_GET['min_price'] ) ) ) {
return $args;
}
$current_min_price = isset( $_GET['min_price'] ) ? floatval( wp_unslash( $_GET['min_price'] ) ) : 0; // WPCS: input var ok, CSRF ok.
$current_max_price = isset( $_GET['max_price'] ) ? floatval( wp_unslash( $_GET['max_price'] ) ) : PHP_INT_MAX; // WPCS: input var ok, CSRF ok.
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$current_min_price = isset( $_GET['min_price'] ) ? floatval( wp_unslash( $_GET['min_price'] ) ) : 0;
$current_max_price = isset( $_GET['max_price'] ) ? floatval( wp_unslash( $_GET['max_price'] ) ) : PHP_INT_MAX;
// phpcs:enable WordPress.Security.NonceVerification.Recommended
/**
* Adjust if the store taxes are not displayed how they are stored.
@ -666,9 +673,11 @@ class WC_Query {
$product_visibility_not_in[] = $product_visibility_terms['outofstock'];
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
// Filter by rating.
if ( isset( $_GET['rating_filter'] ) ) { // WPCS: input var ok, CSRF ok.
$rating_filter = array_filter( array_map( 'absint', explode( ',', $_GET['rating_filter'] ) ) ); // WPCS: input var ok, CSRF ok, Sanitization ok.
if ( isset( $_GET['rating_filter'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$rating_filter = array_filter( array_map( 'absint', explode( ',', $_GET['rating_filter'] ) ) );
$rating_terms = array();
for ( $i = 1; $i <= 5; $i ++ ) {
if ( in_array( $i, $rating_filter, true ) && isset( $product_visibility_terms[ 'rated-' . $i ] ) ) {
@ -685,6 +694,7 @@ class WC_Query {
);
}
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
if ( ! empty( $product_visibility_not_in ) ) {
$tax_query[] = array(
@ -753,8 +763,9 @@ class WC_Query {
$term = substr( $term, 1 );
}
$like = '%' . $wpdb->esc_like( $term ) . '%';
$sql[] = $wpdb->prepare( "(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like ); // unprepared SQL ok.
$like = '%' . $wpdb->esc_like( $term ) . '%';
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$sql[] = $wpdb->prepare( "(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like );
}
if ( ! empty( $sql ) && ! is_user_logged_in() ) {
@ -770,11 +781,12 @@ class WC_Query {
* @return array
*/
public static function get_layered_nav_chosen_attributes() {
if ( ! is_array( self::$_chosen_attributes ) ) {
self::$_chosen_attributes = array();
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( ! is_array( self::$chosen_attributes ) ) {
self::$chosen_attributes = array();
if ( ! empty( $_GET ) ) { // WPCS: input var ok, CSRF ok.
foreach ( $_GET as $key => $value ) { // WPCS: input var ok, CSRF ok.
if ( ! empty( $_GET ) ) {
foreach ( $_GET as $key => $value ) {
if ( 0 === strpos( $key, 'filter_' ) ) {
$attribute = wc_sanitize_taxonomy_name( str_replace( 'filter_', '', $key ) );
$taxonomy = wc_attribute_taxonomy_name( $attribute );
@ -784,14 +796,15 @@ class WC_Query {
continue;
}
$query_type = ! empty( $_GET[ 'query_type_' . $attribute ] ) && in_array( $_GET[ 'query_type_' . $attribute ], array( 'and', 'or' ), true ) ? wc_clean( wp_unslash( $_GET[ 'query_type_' . $attribute ] ) ) : ''; // WPCS: sanitization ok, input var ok, CSRF ok.
self::$_chosen_attributes[ $taxonomy ]['terms'] = array_map( 'sanitize_title', $filter_terms ); // Ensures correct encoding.
self::$_chosen_attributes[ $taxonomy ]['query_type'] = $query_type ? $query_type : apply_filters( 'woocommerce_layered_nav_default_query_type', 'and' );
$query_type = ! empty( $_GET[ 'query_type_' . $attribute ] ) && in_array( $_GET[ 'query_type_' . $attribute ], array( 'and', 'or' ), true ) ? wc_clean( wp_unslash( $_GET[ 'query_type_' . $attribute ] ) ) : '';
self::$chosen_attributes[ $taxonomy ]['terms'] = array_map( 'sanitize_title', $filter_terms ); // Ensures correct encoding.
self::$chosen_attributes[ $taxonomy ]['query_type'] = $query_type ? $query_type : apply_filters( 'woocommerce_layered_nav_default_query_type', 'and' );
}
}
}
}
return self::$_chosen_attributes;
return self::$chosen_attributes;
// phpcs:disable WordPress.Security.NonceVerification.Recommended
}
/**
@ -804,7 +817,6 @@ class WC_Query {
return remove_query_arg( 'add-to-cart', $url );
}
// @codingStandardsIgnoreStart
/**
* Return a meta query for filtering by rating.
*
@ -819,7 +831,7 @@ class WC_Query {
* Returns a meta query to handle product visibility.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @param string $compare (default: 'IN')
* @param string $compare (default: 'IN').
* @return array
*/
public function visibility_meta_query( $compare = 'IN' ) {
@ -830,7 +842,7 @@ class WC_Query {
* Returns a meta query to handle product stock status.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @param string $status (default: 'instock')
* @param string $status (default: 'instock').
* @return array
*/
public function stock_status_meta_query( $status = 'instock' ) {
@ -869,6 +881,8 @@ class WC_Query {
/**
* Search post excerpt.
*
* @param string $where Where clause.
*
* @deprecated 3.2.0 - Not needed anymore since WordPress 4.5.
*/
public function search_post_excerpt( $where = '' ) {
@ -878,10 +892,10 @@ class WC_Query {
/**
* Remove the posts_where filter.
*
* @deprecated 3.2.0 - Nothing to remove anymore because search_post_excerpt() is deprecated.
*/
public function remove_posts_where() {
wc_deprecated_function( 'WC_Query::remove_posts_where', '3.2.0', 'Nothing to remove anymore because search_post_excerpt() is deprecated.' );
}
// @codingStandardsIgnoreEnd
}

View File

@ -8,6 +8,8 @@
* @version 2.5.0
*/
// phpcs:disable Generic.Commenting.Todo.TaskFound
use Automattic\Jetpack\Constants;
defined( 'ABSPATH' ) || exit;
@ -18,11 +20,13 @@ defined( 'ABSPATH' ) || exit;
function wc_template_redirect() {
global $wp_query, $wp;
// phpcs:disable WordPress.Security.NonceVerification.Recommended
// When default permalinks are enabled, redirect shop page to post type archive url.
if ( ! empty( $_GET['page_id'] ) && '' === get_option( 'permalink_structure' ) && wc_get_page_id( 'shop' ) === absint( $_GET['page_id'] ) && get_post_type_archive_link( 'product' ) ) { // WPCS: input var ok, CSRF ok.
if ( ! empty( $_GET['page_id'] ) && '' === get_option( 'permalink_structure' ) && wc_get_page_id( 'shop' ) === absint( $_GET['page_id'] ) && get_post_type_archive_link( 'product' ) ) {
wp_safe_redirect( get_post_type_archive_link( 'product' ) );
exit;
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
// When on the checkout with an empty cart, redirect to cart page.
if ( is_page( wc_get_page_id( 'checkout' ) ) && wc_get_page_id( 'checkout' ) !== wc_get_page_id( 'cart' ) && WC()->cart->is_empty() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) {
@ -33,7 +37,7 @@ function wc_template_redirect() {
}
// Logout.
if ( isset( $wp->query_vars['customer-logout'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'customer-logout' ) ) { // WPCS: input var ok, CSRF ok.
if ( isset( $wp->query_vars['customer-logout'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'customer-logout' ) ) {
wp_safe_redirect( str_replace( '&amp;', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
exit;
}
@ -96,9 +100,11 @@ add_action( 'template_redirect', 'wc_send_frame_options_header' );
* @since 2.5.3
*/
function wc_prevent_endpoint_indexing() {
if ( is_wc_endpoint_url() || isset( $_GET['download_file'] ) ) { // WPCS: input var ok, CSRF ok.
@header( 'X-Robots-Tag: noindex' ); // @codingStandardsIgnoreLine
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.PHP.NoSilencedErrors.Discouraged
if ( is_wc_endpoint_url() || isset( $_GET['download_file'] ) ) {
@header( 'X-Robots-Tag: noindex' );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.PHP.NoSilencedErrors.Discouraged
}
add_action( 'template_redirect', 'wc_prevent_endpoint_indexing' );
@ -704,7 +710,9 @@ function wc_product_class( $class = '', $product_id = null ) {
*/
function wc_query_string_form_fields( $values = null, $exclude = array(), $current_key = '', $return = false ) {
if ( is_null( $values ) ) {
$values = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$values = $_GET;
// phpcs:enable WordPress.Security.NonceVerification.Recommended
} elseif ( is_string( $values ) ) {
$url_parts = wp_parse_url( $values );
$values = array();
@ -1022,7 +1030,8 @@ if ( ! function_exists( 'woocommerce_demo_store' ) ) {
$notice_id = md5( $notice );
echo apply_filters( 'woocommerce_demo_store', '<p class="woocommerce-store-notice demo_store" data-notice-id="' . esc_attr( $notice_id ) . '" style="display:none;">' . wp_kses_post( $notice ) . ' <a href="#" class="woocommerce-store-notice__dismiss-link">' . esc_html__( 'Dismiss', 'woocommerce' ) . '</a></p>', $notice ); // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo apply_filters( 'woocommerce_demo_store', '<p class="woocommerce-store-notice demo_store" data-notice-id="' . esc_attr( $notice_id ) . '" style="display:none;">' . wp_kses_post( $notice ) . ' <a href="#" class="woocommerce-store-notice__dismiss-link">' . esc_html__( 'Dismiss', 'woocommerce' ) . '</a></p>', $notice );
}
}
@ -1062,7 +1071,8 @@ if ( ! function_exists( 'woocommerce_page_title' ) ) {
$page_title = apply_filters( 'woocommerce_page_title', $page_title );
if ( $echo ) {
echo $page_title; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $page_title;
} else {
return $page_title;
}
@ -1087,7 +1097,8 @@ if ( ! function_exists( 'woocommerce_product_loop_start' ) ) {
$loop_start = apply_filters( 'woocommerce_product_loop_start', ob_get_clean() );
if ( $echo ) {
echo $loop_start; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $loop_start;
} else {
return $loop_start;
}
@ -1110,7 +1121,8 @@ if ( ! function_exists( 'woocommerce_product_loop_end' ) ) {
$loop_end = apply_filters( 'woocommerce_product_loop_end', ob_get_clean() );
if ( $echo ) {
echo $loop_end; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $loop_end;
} else {
return $loop_end;
}
@ -1139,7 +1151,8 @@ if ( ! function_exists( 'woocommerce_template_loop_category_title' ) ) {
echo esc_html( $category->name );
if ( $category->count > 0 ) {
echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . esc_html( $category->count ) . ')</mark>', $category ); // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . esc_html( $category->count ) . ')</mark>', $category );
}
?>
</h2>
@ -1199,7 +1212,8 @@ if ( ! function_exists( 'woocommerce_taxonomy_archive_description' ) ) {
$term = get_queried_object();
if ( $term && ! empty( $term->description ) ) {
echo '<div class="term-description">' . wc_format_content( $term->description ) . '</div>'; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="term-description">' . wc_format_content( $term->description ) . '</div>';
}
}
}
@ -1220,7 +1234,8 @@ if ( ! function_exists( 'woocommerce_product_archive_description' ) ) {
if ( $shop_page ) {
$description = wc_format_content( $shop_page->post_content );
if ( $description ) {
echo '<div class="page-description">' . $description . '</div>'; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="page-description">' . $description . '</div>';
}
}
}
@ -1276,7 +1291,8 @@ if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
* Get the product thumbnail for the loop.
*/
function woocommerce_template_loop_product_thumbnail() {
echo woocommerce_get_product_thumbnail(); // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo woocommerce_get_product_thumbnail();
}
}
if ( ! function_exists( 'woocommerce_template_loop_price' ) ) {
@ -1368,7 +1384,9 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
);
$default_orderby = wc_get_loop_prop( 'is_search' ) ? 'relevance' : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby', '' ) );
$orderby = isset( $_GET['orderby'] ) ? wc_clean( wp_unslash( $_GET['orderby'] ) ) : $default_orderby; // WPCS: sanitization ok, input var ok, CSRF ok.
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$orderby = isset( $_GET['orderby'] ) ? wc_clean( wp_unslash( $_GET['orderby'] ) ) : $default_orderby;
// phpcs:enable WordPress.Security.NonceVerification.Recommended
if ( wc_get_loop_prop( 'is_search' ) ) {
$catalog_orderby_options = array_merge( array( 'relevance' => __( 'Relevance', 'woocommerce' ) ), $catalog_orderby_options );
@ -1700,7 +1718,8 @@ if ( ! function_exists( 'woocommerce_quantity_input' ) ) {
wc_get_template( 'global/quantity-input.php', $args );
if ( $echo ) {
echo ob_get_clean(); // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo ob_get_clean();
} else {
return ob_get_clean();
}
@ -1780,7 +1799,8 @@ if ( ! function_exists( 'woocommerce_sort_product_tabs' ) ) {
// Make sure the $tabs parameter is an array.
if ( ! is_array( $tabs ) ) {
trigger_error( 'Function woocommerce_sort_product_tabs() expects an array as the first parameter. Defaulting to empty array.' ); // @codingStandardsIgnoreLine
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error( 'Function woocommerce_sort_product_tabs() expects an array as the first parameter. Defaulting to empty array.' );
$tabs = array();
}
@ -1817,7 +1837,8 @@ if ( ! function_exists( 'woocommerce_comments' ) ) {
* @param int $depth Depth.
*/
function woocommerce_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment; // WPCS: override ok.
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$GLOBALS['comment'] = $comment;
wc_get_template(
'single-product/review.php',
array(
@ -2443,7 +2464,8 @@ if ( ! function_exists( 'woocommerce_output_product_categories' ) ) {
return false;
}
echo $args['before']; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $args['before'];
foreach ( $product_categories as $category ) {
wc_get_template(
@ -2454,7 +2476,8 @@ if ( ! function_exists( 'woocommerce_output_product_categories' ) ) {
);
}
echo $args['after']; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $args['after'];
return true;
}
@ -2839,7 +2862,8 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
if ( $args['return'] ) {
return $field;
} else {
echo $field; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $field;
}
}
}
@ -2882,7 +2906,8 @@ if ( ! function_exists( 'get_product_search_form' ) ) {
return $form;
}
echo $form; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $form;
}
}
@ -2951,8 +2976,10 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
// Get selected value.
if ( false === $args['selected'] && $args['attribute'] && $args['product'] instanceof WC_Product ) {
$selected_key = 'attribute_' . sanitize_title( $args['attribute'] );
$args['selected'] = isset( $_REQUEST[ $selected_key ] ) ? wc_clean( wp_unslash( $_REQUEST[ $selected_key ] ) ) : $args['product']->get_variation_default_attribute( $args['attribute'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
$selected_key = 'attribute_' . sanitize_title( $args['attribute'] );
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$args['selected'] = isset( $_REQUEST[ $selected_key ] ) ? wc_clean( wp_unslash( $_REQUEST[ $selected_key ] ) ) : $args['product']->get_variation_default_attribute( $args['attribute'] );
// phpcs:enable WordPress.Security.NonceVerification.Recommended
}
$options = $args['options'];
@ -2999,7 +3026,8 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
$html .= '</select>';
echo apply_filters( 'woocommerce_dropdown_variation_attribute_options_html', $html, $args ); // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo apply_filters( 'woocommerce_dropdown_variation_attribute_options_html', $html, $args );
}
}
@ -3236,7 +3264,8 @@ if ( ! function_exists( 'wc_display_item_meta' ) ) {
$html = apply_filters( 'woocommerce_display_item_meta', $html, $item, $args );
if ( $args['echo'] ) {
echo $html; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $html;
} else {
return $html;
}
@ -3290,7 +3319,8 @@ if ( ! function_exists( 'wc_display_item_downloads' ) ) {
$html = apply_filters( 'woocommerce_display_item_downloads', $html, $item, $args );
if ( $args['echo'] ) {
echo $html; // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $html;
} else {
return $html;
}
@ -3698,3 +3728,5 @@ function wc_get_pay_buttons() {
}
echo '</div>';
}
// phpcs:enable Generic.Commenting.Todo.TaskFound

View File

@ -442,8 +442,9 @@ class WC_Widget_Layered_Nav extends WC_Widget {
continue;
}
$filter_name = 'filter_' . wc_attribute_taxonomy_slug( $taxonomy );
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$filter_name = 'filter_' . wc_attribute_taxonomy_slug( $taxonomy );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array();
$current_filter = array_map( 'sanitize_title', $current_filter );
if ( ! in_array( $term->slug, $current_filter, true ) ) {
@ -487,7 +488,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$term_html .= ' ' . apply_filters( 'woocommerce_layered_nav_count', '<span class="count">(' . absint( $count ) . ')</span>', $count, $term );
echo '<li class="woocommerce-widget-layered-nav-list__item wc-layered-nav-term ' . ( $option_is_set ? 'woocommerce-widget-layered-nav-list__item--chosen chosen' : '' ) . '">';
echo apply_filters( 'woocommerce_layered_nav_term_html', $term_html, $term, $link, $count ); // WPCS: XSS ok.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.EscapeOutput.OutputNotEscaped
echo apply_filters( 'woocommerce_layered_nav_term_html', $term_html, $term, $link, $count );
echo '</li>';
}

View File

@ -23,6 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<p class="woocommerce-result-count">
<?php
// phpcs:disable WordPress.Security
if ( 1 === $total ) {
_e( 'Showing the single result', 'woocommerce' );
} elseif ( $total <= $per_page || -1 === $per_page ) {
@ -34,5 +35,6 @@ if ( ! defined( 'ABSPATH' ) ) {
/* translators: 1: first result 2: last result 3: total results */
printf( _nx( 'Showing %1$d&ndash;%2$d of %3$d result', 'Showing %1$d&ndash;%2$d of %3$d results', $total, 'with first and last result', 'woocommerce' ), $first, $last, $total );
}
// phpcs:enable WordPress.Security
?>
</p>

View File

@ -28,6 +28,7 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
$this->assertTrue( wc_has_notice( 'test', 'error' ) );
// Clean up.
// phpcs:disable WordPress.Security.NonceVerification.Recommended
unset( $_GET['wc_error'] );
wc_clear_notices();
@ -182,6 +183,7 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
* @group core-only
*/
public function test_get_catalog_ordering_args() {
// phpcs:disable WordPress.DB.SlowDBQuery
$data = array(
array(
'orderby' => 'menu_order',
@ -297,6 +299,7 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
),
),
);
// phpcs:enable WordPress.DB.SlowDBQuery
foreach ( $data as $test ) {
$result = WC()->query->get_catalog_ordering_args( $test['orderby'], $test['order'] );
@ -310,11 +313,13 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
public function test_get_catalog_ordering_args_GET() {
$_GET['orderby'] = 'price-desc';
// phpcs:disable WordPress.DB.SlowDBQuery
$expected = array(
'orderby' => 'price',
'order' => 'DESC',
'meta_key' => '',
);
// phpcs:enable WordPress.DB.SlowDBQuery
$this->assertEquals( $expected, WC()->query->get_catalog_ordering_args() );
@ -341,9 +346,11 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
'include_children' => true,
);
// phpcs:disable WordPress.DB.SlowDBQuery
$query_args = array(
'tax_query' => array( $tax_query ),
);
// phpcs:enable WordPress.DB.SlowDBQuery
WC()->query->product_query( new WP_Query( $query_args ) );
$tax_queries = WC_Query::get_main_tax_query();
@ -360,9 +367,11 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
'compare' => '=',
);
// phpcs:disable WordPress.DB.SlowDBQuery
$query_args = array(
'meta_query' => array( $meta_query ),
);
// phpcs:enable WordPress.DB.SlowDBQuery
WC()->query->product_query( new WP_Query( $query_args ) );
$meta_queries = WC_Query::get_main_meta_query();