Convert all notice data into HTML data

This commit is contained in:
Claudio Sanches 2019-11-07 20:34:49 -03:00
parent 830e612420
commit d8fed95403
2 changed files with 13 additions and 3 deletions

View File

@ -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;
}

View File

@ -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' ) );
}