Skip to content

Commit 0eac55a

Browse files
committed
1 parent 90e84b6 commit 0eac55a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Function.HTML-Build-Attributes.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*
88
* @param array $attr Associative array of attribute names and values.
99
* @param callable $callback Callback function to escape values for HTML attributes.
10-
* Defaults to the WordPress' 'esc_attr' function.
10+
* Defaults to `htmlspecialchars()`.
1111
* @return string Returns a string of HTML attributes.
1212
*/
13-
function html_build_attributes( $attr = [], $callback = 'esc_attr' )
13+
function html_build_attributes( $attr = [], $callback = null )
1414
{
1515
$html = '';
1616

@@ -26,6 +26,10 @@ function ( $val, $key ) {
2626

2727
if ( is_callable( $callback ) ) {
2828
$val = call_user_func( $callback, $val );
29+
} elseif ( function_exists('esc_attr') ) {
30+
$val = esc_attr( $val );
31+
} else {
32+
$val = htmlspecialchars( $val, ENT_QUOTES );
2933
}
3034

3135
return sprintf( '%1$s="%2$s"', $key, $val );

0 commit comments

Comments
 (0)