wp_sanitize_script_attributes( array $attributes )
Sanitizes an attributes array into an attributes string to be placed inside a <script>
tag.
Description
Automatically injects type attribute if needed.
Used by wp_get_script_tag() and wp_get_inline_script_tag().
Parameters
- $attributes
-
(Required) Key-value pairs representing
<script>
tag attributes.
Return
(string) String made of sanitized <script>
tag attributes.
Source
File: wp-includes/script-loader.php
function wp_sanitize_script_attributes( $attributes ) {
$attributes_string = '';
// Only the attribute name is added to $attributes_string for entries with a boolean value
// and that are true. Otherwise, use both name an value.
foreach ( $attributes as $attribute_name => $attribute_value ) {
if ( is_bool( $attribute_value ) ) {
if ( $attribute_value ) {
$attributes_string .= ' ' . esc_attr( $attribute_name );
}
} else {
$attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
}
}
return $attributes_string;
}
Changelog
Version | Description |
---|---|
5.7.0 | Introduced. |