From c2b8cc73c034e16c10cf13ec0c6313d3c1ac9d0d Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Mon, 20 Aug 2018 18:35:17 +0200 Subject: [PATCH 1/9] Added support for changing tabindex for notices. --- templates/notices/error.php | 15 ++++++++++++++- templates/notices/notice.php | 15 ++++++++++++++- templates/notices/success.php | 15 ++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/templates/notices/error.php b/templates/notices/error.php index 1b86a0fc93e..24f77482809 100644 --- a/templates/notices/error.php +++ b/templates/notices/error.php @@ -27,6 +27,19 @@ if ( ! $messages ) { ?> diff --git a/templates/notices/notice.php b/templates/notices/notice.php index fe92bbe9b11..bdd78a3efb0 100644 --- a/templates/notices/notice.php +++ b/templates/notices/notice.php @@ -27,5 +27,18 @@ if ( ! $messages ) { ?> -
+
+ array( + 'tabindex' => true, + ), + ) + ) // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound + ); + ?> +
diff --git a/templates/notices/success.php b/templates/notices/success.php index a36f862bd13..11b932b5e0c 100644 --- a/templates/notices/success.php +++ b/templates/notices/success.php @@ -27,5 +27,18 @@ if ( ! $messages ) { ?> - + From ac550e9d37802bdc9f511a6da616cb541034a719 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Mon, 20 Aug 2018 18:38:53 +0200 Subject: [PATCH 2/9] PHPCS. --- templates/notices/error.php | 6 +++--- templates/notices/notice.php | 8 ++++---- templates/notices/success.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/notices/error.php b/templates/notices/error.php index 24f77482809..af0ec12942a 100644 --- a/templates/notices/error.php +++ b/templates/notices/error.php @@ -10,9 +10,9 @@ * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * - * @see https://docs.woocommerce.com/document/template-structure/ - * @author WooThemes - * @package WooCommerce/Templates + * @see https://docs.woocommerce.com/document/template-structure/ + * @author WooThemes + * @package WooCommerce/Templates * @version 3.3.0 */ diff --git a/templates/notices/notice.php b/templates/notices/notice.php index bdd78a3efb0..ac6793418a7 100644 --- a/templates/notices/notice.php +++ b/templates/notices/notice.php @@ -10,14 +10,14 @@ * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * - * @see https://docs.woocommerce.com/document/template-structure/ - * @author WooThemes - * @package WooCommerce/Templates + * @see https://docs.woocommerce.com/document/template-structure/ + * @author WooThemes + * @package WooCommerce/Templates * @version 1.6.4 */ if ( ! defined( 'ABSPATH' ) ) { - exit; // Exit if accessed directly + exit; // Exit if accessed directly. } if ( ! $messages ) { diff --git a/templates/notices/success.php b/templates/notices/success.php index 11b932b5e0c..44658c2a813 100644 --- a/templates/notices/success.php +++ b/templates/notices/success.php @@ -10,9 +10,9 @@ * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * - * @see https://docs.woocommerce.com/document/template-structure/ - * @author WooThemes - * @package WooCommerce/Templates + * @see https://docs.woocommerce.com/document/template-structure/ + * @author WooThemes + * @package WooCommerce/Templates * @version 3.3.0 */ From 355d95db9d5b408c03003e82fc0e8b1fdfe42d6f Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Mon, 20 Aug 2018 18:39:31 +0200 Subject: [PATCH 3/9] Added tabindex 1 to Add to cart notices (View cart/Continue shopping). --- includes/wc-cart-functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index 1d7040fdf2f..54bd1ec2aa6 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -118,9 +118,9 @@ function wc_add_to_cart_message( $products, $show_qty = false, $return = false ) // Output success messages. if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) ); - $message = sprintf( '%s %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'woocommerce' ), esc_html( $added_text ) ); + $message = sprintf( '%s %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'woocommerce' ), esc_html( $added_text ) ); } else { - $message = sprintf( '%s %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', 'woocommerce' ), esc_html( $added_text ) ); + $message = sprintf( '%s %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', 'woocommerce' ), esc_html( $added_text ) ); } if ( has_filter( 'wc_add_to_cart_message' ) ) { From ae05d6e5ea7fb88cacd1c6af137cf30de3618ebf Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Tue, 21 Aug 2018 11:47:50 +0200 Subject: [PATCH 4/9] Removed author tag and bumped version of templates to 3.5.0, factored out function to one common place. --- includes/wc-template-functions.php | 20 ++++++++++++++++++++ templates/notices/error.php | 14 ++------------ templates/notices/notice.php | 14 ++------------ templates/notices/success.php | 14 ++------------ 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index ba3f3105a9f..5b49453e542 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -3397,3 +3397,23 @@ if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) { wc_deprecated_function( 'woocommerce_product_reviews_tab', '2.4' ); } } + +/** + * Filters out the same tags as wp_kses_post, but allows tabindex for element. + * + * @since 3.5.0 + * @param string $message Content to filter through kses. + * @return string + */ +function wc_kses_notice( $message ) { + return wp_kses( $message, + array_replace_recursive( // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound + wp_kses_allowed_html( 'post' ), + array( + 'a' => array( + 'tabindex' => true, + ), + ) + ) + ); +} diff --git a/templates/notices/error.php b/templates/notices/error.php index af0ec12942a..9713af69240 100644 --- a/templates/notices/error.php +++ b/templates/notices/error.php @@ -11,9 +11,8 @@ * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ - * @author WooThemes * @package WooCommerce/Templates - * @version 3.3.0 + * @version 3.5.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -29,16 +28,7 @@ if ( ! $messages ) {
  • array( - 'tabindex' => true, - ), - ) - ) // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound - ); + echo wc_kses_notice( $message ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
  • diff --git a/templates/notices/notice.php b/templates/notices/notice.php index ac6793418a7..db15456a303 100644 --- a/templates/notices/notice.php +++ b/templates/notices/notice.php @@ -11,9 +11,8 @@ * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ - * @author WooThemes * @package WooCommerce/Templates - * @version 1.6.4 + * @version 3.5.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -29,16 +28,7 @@ if ( ! $messages ) {
    array( - 'tabindex' => true, - ), - ) - ) // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound - ); + echo wc_kses_notice( $message ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
    diff --git a/templates/notices/success.php b/templates/notices/success.php index 44658c2a813..6850b292b64 100644 --- a/templates/notices/success.php +++ b/templates/notices/success.php @@ -11,9 +11,8 @@ * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ - * @author WooThemes * @package WooCommerce/Templates - * @version 3.3.0 + * @version 3.5.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -29,16 +28,7 @@ if ( ! $messages ) { From 9845c3c131e8170f321ff59235ea73b6091cfac9 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Tue, 21 Aug 2018 11:48:29 +0200 Subject: [PATCH 5/9] PHPCS. --- includes/wc-template-functions.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 5b49453e542..581ed259f12 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -237,11 +237,8 @@ function woocommerce_product_loop() { /** * Output generator tag to aid debugging. * - * @access public - * * @param string $gen Generator. * @param string $type Type. - * * @return string */ function wc_generator_tag( $gen, $type ) { From 5b0cc306a588d4a6549862f6dcc5a1151002294d Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Tue, 21 Aug 2018 12:00:48 +0200 Subject: [PATCH 6/9] Moved the wc_kses_notice to wc-notice-functions.php and applied it in wc_print_notices(). --- includes/wc-notice-functions.php | 22 +++++++++++++++++++++- includes/wc-template-functions.php | 20 -------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/includes/wc-notice-functions.php b/includes/wc-notice-functions.php index c8a3a7f21a6..db293034281 100644 --- a/includes/wc-notice-functions.php +++ b/includes/wc-notice-functions.php @@ -144,7 +144,7 @@ function wc_print_notices( $return = false ) { wc_clear_notices(); - $notices = wp_kses_post( ob_get_clean() ); + $notices = wc_kses_notice( ob_get_clean() ); if ( $return ) { return $notices; @@ -208,3 +208,23 @@ function wc_add_wp_error_notices( $errors ) { } } } + +/** + * Filters out the same tags as wp_kses_post, but allows tabindex for
    element. + * + * @since 3.5.0 + * @param string $message Content to filter through kses. + * @return string + */ +function wc_kses_notice( $message ) { + return wp_kses( $message, + array_replace_recursive( // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound + wp_kses_allowed_html( 'post' ), + array( + 'a' => array( + 'tabindex' => true, + ), + ) + ) + ); +} diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 581ed259f12..55dbcd69544 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -3394,23 +3394,3 @@ if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) { wc_deprecated_function( 'woocommerce_product_reviews_tab', '2.4' ); } } - -/** - * Filters out the same tags as wp_kses_post, but allows tabindex for element. - * - * @since 3.5.0 - * @param string $message Content to filter through kses. - * @return string - */ -function wc_kses_notice( $message ) { - return wp_kses( $message, - array_replace_recursive( // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound - wp_kses_allowed_html( 'post' ), - array( - 'a' => array( - 'tabindex' => true, - ), - ) - ) - ); -} From dde3c9fa7b533644504bc98073ba38d8f3a8ec8f Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Wed, 22 Aug 2018 10:12:32 +0200 Subject: [PATCH 7/9] Fixed unit tests. --- tests/unit-tests/cart/functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit-tests/cart/functions.php b/tests/unit-tests/cart/functions.php index 33f68fa8c6d..5446b616613 100644 --- a/tests/unit-tests/cart/functions.php +++ b/tests/unit-tests/cart/functions.php @@ -161,21 +161,21 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case { $product = WC_Helper_Product::create_simple_product(); $message = wc_add_to_cart_message( array( $product->get_id() => 1 ), false, true ); - $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); + $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); $message = wc_add_to_cart_message( array( $product->get_id() => 3 ), false, true ); - $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); + $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); $message = wc_add_to_cart_message( array( $product->get_id() => 1 ), true, true ); - $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); + $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); $message = wc_add_to_cart_message( array( $product->get_id() => 3 ), true, true ); - $this->assertEquals( 'View cart 3 × “Dummy Product” have been added to your cart.', $message ); + $this->assertEquals( 'View cart 3 × “Dummy Product” have been added to your cart.', $message ); $message = wc_add_to_cart_message( $product->get_id(), false, true ); - $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); + $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); $message = wc_add_to_cart_message( $product->get_id(), true, true ); - $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); + $this->assertEquals( 'View cart “Dummy Product” has been added to your cart.', $message ); } } From 2f0505a73f3f260394c4a9868f55b1544b347b20 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Thu, 23 Aug 2018 14:31:40 +0200 Subject: [PATCH 8/9] Added wc_kses_notice as escaping function to PHPCS. --- phpcs.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index 49e38714c91..2d1e0db01ce 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -49,7 +49,7 @@ - + From 0d29e5d88ff726a9558a88a99bfbe54446cab6e2 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Thu, 23 Aug 2018 14:31:53 +0200 Subject: [PATCH 9/9] PHPCS fix. --- templates/notices/error.php | 2 +- templates/notices/notice.php | 2 +- templates/notices/success.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/notices/error.php b/templates/notices/error.php index 9713af69240..2fdff091f6d 100644 --- a/templates/notices/error.php +++ b/templates/notices/error.php @@ -28,7 +28,7 @@ if ( ! $messages ) {
  • diff --git a/templates/notices/notice.php b/templates/notices/notice.php index db15456a303..5272526b214 100644 --- a/templates/notices/notice.php +++ b/templates/notices/notice.php @@ -28,7 +28,7 @@ if ( ! $messages ) {
    diff --git a/templates/notices/success.php b/templates/notices/success.php index 6850b292b64..146d61a583d 100644 --- a/templates/notices/success.php +++ b/templates/notices/success.php @@ -28,7 +28,7 @@ if ( ! $messages ) {