Convert all notice data into HTML data
This commit is contained in:
parent
830e612420
commit
d8fed95403
|
@ -264,9 +264,19 @@ function wc_kses_notice( $message ) {
|
|||
* @return string
|
||||
*/
|
||||
function wc_get_notice_data_attr( $notice ) {
|
||||
if ( ! isset( $notice['data']['id'] ) ) {
|
||||
if ( empty( $notice['data'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
return sprintf( ' data-element-id="%s"', esc_attr( $notice['data']['id'] ) );
|
||||
$attr = '';
|
||||
|
||||
foreach ( $notice['data'] as $key => $value ) {
|
||||
$attr .= sprintf(
|
||||
' data-%1$s="%2$s"',
|
||||
sanitize_title( $key ),
|
||||
esc_attr( $value )
|
||||
);
|
||||
}
|
||||
|
||||
return $attr;
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
|
|||
public function test_wc_print_notice_data() {
|
||||
|
||||
// Specific type.
|
||||
$this->expectOutputString( '<ul class="woocommerce-error" role="alert"><li data-element-id="billing_postcode">Error!</li></ul>' );
|
||||
$this->expectOutputString( '<ul class="woocommerce-error" role="alert"><li data-id="billing_postcode">Error!</li></ul>' );
|
||||
|
||||
wc_print_notice( 'Error!', 'error', array( 'id' => 'billing_postcode' ) );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue