Sanitize HTML attributes from array to string.
beans_esc_attributes( array $attributes )
Return: (string) The escaped attributes.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
$attributes | array | true | - | The array key defines the attribute name and the array value define the attribute value. |
Source
function beans_esc_attributes( $attributes ) {
/**
* Filter attributes escaping methods.
*
* For all unspecified selectors, values are automatically escaped using
* {@link http://codex.wordpress.org/Function_Reference/esc_attr esc_attr()}.
*
* @since 1.3.1
*
* @param array $method Associative array of selectors as keys and escaping method as values.
*/
$methods = apply_filters( 'beans_escape_attributes_methods', array(
'href' => 'esc_url',
'src' => 'esc_url',
'itemtype' => 'esc_url',
'onclick' => 'esc_js',
) );
$string = '';
foreach ( (array) $attributes as $attribute => $value ) {
if ( null !== $value ) {
if ( $method = beans_get( $attribute, $methods ) ) {
$value = call_user_func( $method, $value );
} else {
$value = esc_attr( $value );
}
$string .= $attribute . '="' . $value . '" ';
}
}
return trim( $string );
}