Merge pull request #21108 from woocommerce/fix/21025
Set tabindex=1 for notices
This commit is contained in:
commit
babfacd6bb
|
@ -118,9 +118,9 @@ function wc_add_to_cart_message( $products, $show_qty = false, $return = false )
|
||||||
// Output success messages.
|
// Output success messages.
|
||||||
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
|
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' ) );
|
$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( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'woocommerce' ), esc_html( $added_text ) );
|
$message = sprintf( '<a href="%s" tabindex="1" class="button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'woocommerce' ), esc_html( $added_text ) );
|
||||||
} else {
|
} else {
|
||||||
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', 'woocommerce' ), esc_html( $added_text ) );
|
$message = sprintf( '<a href="%s" tabindex="1" class="button wc-forward">%s</a> %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' ) ) {
|
if ( has_filter( 'wc_add_to_cart_message' ) ) {
|
||||||
|
|
|
@ -144,7 +144,7 @@ function wc_print_notices( $return = false ) {
|
||||||
|
|
||||||
wc_clear_notices();
|
wc_clear_notices();
|
||||||
|
|
||||||
$notices = wp_kses_post( ob_get_clean() );
|
$notices = wc_kses_notice( ob_get_clean() );
|
||||||
|
|
||||||
if ( $return ) {
|
if ( $return ) {
|
||||||
return $notices;
|
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 <a> 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,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -237,11 +237,8 @@ function woocommerce_product_loop() {
|
||||||
/**
|
/**
|
||||||
* Output generator tag to aid debugging.
|
* Output generator tag to aid debugging.
|
||||||
*
|
*
|
||||||
* @access public
|
|
||||||
*
|
|
||||||
* @param string $gen Generator.
|
* @param string $gen Generator.
|
||||||
* @param string $type Type.
|
* @param string $type Type.
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function wc_generator_tag( $gen, $type ) {
|
function wc_generator_tag( $gen, $type ) {
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
</rule>
|
</rule>
|
||||||
<rule ref="WordPress.XSS.EscapeOutput">
|
<rule ref="WordPress.XSS.EscapeOutput">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="customEscapingFunctions" type="array" value="wc_help_tip,wc_sanitize_tooltip,wc_selected" />
|
<property name="customEscapingFunctions" type="array" value="wc_help_tip,wc_sanitize_tooltip,wc_selected,wc_kses_notice" />
|
||||||
</properties>
|
</properties>
|
||||||
</rule>
|
</rule>
|
||||||
<rule ref="WordPress.WP.I18n">
|
<rule ref="WordPress.WP.I18n">
|
||||||
|
|
|
@ -11,9 +11,8 @@
|
||||||
* the readme will list any important changes.
|
* the readme will list any important changes.
|
||||||
*
|
*
|
||||||
* @see https://docs.woocommerce.com/document/template-structure/
|
* @see https://docs.woocommerce.com/document/template-structure/
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 3.3.0
|
* @version 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
@ -27,6 +26,10 @@ if ( ! $messages ) {
|
||||||
?>
|
?>
|
||||||
<ul class="woocommerce-error" role="alert">
|
<ul class="woocommerce-error" role="alert">
|
||||||
<?php foreach ( $messages as $message ) : ?>
|
<?php foreach ( $messages as $message ) : ?>
|
||||||
<li><?php echo wp_kses_post( $message ); ?></li>
|
<li>
|
||||||
|
<?php
|
||||||
|
echo wc_kses_notice( $message );
|
||||||
|
?>
|
||||||
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -11,13 +11,12 @@
|
||||||
* the readme will list any important changes.
|
* the readme will list any important changes.
|
||||||
*
|
*
|
||||||
* @see https://docs.woocommerce.com/document/template-structure/
|
* @see https://docs.woocommerce.com/document/template-structure/
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 1.6.4
|
* @version 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit; // Exit if accessed directly
|
exit; // Exit if accessed directly.
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $messages ) {
|
if ( ! $messages ) {
|
||||||
|
@ -27,5 +26,9 @@ if ( ! $messages ) {
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php foreach ( $messages as $message ) : ?>
|
<?php foreach ( $messages as $message ) : ?>
|
||||||
<div class="woocommerce-info"><?php echo wp_kses_post( $message ); ?></div>
|
<div class="woocommerce-info">
|
||||||
|
<?php
|
||||||
|
echo wc_kses_notice( $message );
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
|
@ -11,9 +11,8 @@
|
||||||
* the readme will list any important changes.
|
* the readme will list any important changes.
|
||||||
*
|
*
|
||||||
* @see https://docs.woocommerce.com/document/template-structure/
|
* @see https://docs.woocommerce.com/document/template-structure/
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 3.3.0
|
* @version 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
@ -27,5 +26,9 @@ if ( ! $messages ) {
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php foreach ( $messages as $message ) : ?>
|
<?php foreach ( $messages as $message ) : ?>
|
||||||
<div class="woocommerce-message" role="alert"><?php echo wp_kses_post( $message ); ?></div>
|
<div class="woocommerce-message" role="alert">
|
||||||
|
<?php
|
||||||
|
echo wc_kses_notice( $message );
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
|
@ -161,21 +161,21 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
|
||||||
$product = WC_Helper_Product::create_simple_product();
|
$product = WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$message = wc_add_to_cart_message( array( $product->get_id() => 1 ), false, true );
|
$message = wc_add_to_cart_message( array( $product->get_id() => 1 ), false, true );
|
||||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
$this->assertEquals( '<a href="http://example.org" tabindex="1" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||||
|
|
||||||
$message = wc_add_to_cart_message( array( $product->get_id() => 3 ), false, true );
|
$message = wc_add_to_cart_message( array( $product->get_id() => 3 ), false, true );
|
||||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
$this->assertEquals( '<a href="http://example.org" tabindex="1" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||||
|
|
||||||
$message = wc_add_to_cart_message( array( $product->get_id() => 1 ), true, true );
|
$message = wc_add_to_cart_message( array( $product->get_id() => 1 ), true, true );
|
||||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
$this->assertEquals( '<a href="http://example.org" tabindex="1" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||||
|
|
||||||
$message = wc_add_to_cart_message( array( $product->get_id() => 3 ), true, true );
|
$message = wc_add_to_cart_message( array( $product->get_id() => 3 ), true, true );
|
||||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View cart</a> 3 × “Dummy Product” have been added to your cart.', $message );
|
$this->assertEquals( '<a href="http://example.org" tabindex="1" class="button wc-forward">View cart</a> 3 × “Dummy Product” have been added to your cart.', $message );
|
||||||
|
|
||||||
$message = wc_add_to_cart_message( $product->get_id(), false, true );
|
$message = wc_add_to_cart_message( $product->get_id(), false, true );
|
||||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
$this->assertEquals( '<a href="http://example.org" tabindex="1" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||||
|
|
||||||
$message = wc_add_to_cart_message( $product->get_id(), true, true );
|
$message = wc_add_to_cart_message( $product->get_id(), true, true );
|
||||||
$this->assertEquals( '<a href="http://example.org" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
$this->assertEquals( '<a href="http://example.org" tabindex="1" class="button wc-forward">View cart</a> “Dummy Product” has been added to your cart.', $message );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue