WP_Theme_JSON::is_safe_css_declaration() WordPress Method
The WP_Theme_JSON::is_safe_css_declaration() method is a safety check to ensure that a given CSS declaration is not going to cause any problems when included in a WordPress theme. This is important because some CSS declarations can conflict with other parts of the WordPress code, or cause unexpected results. By checking to see if a declaration is safe before including it in a theme, we can avoid these problems.
WP_Theme_JSON::is_safe_css_declaration( string $property_name, string $property_value ) #
Checks that a declaration provided by the user is safe.
Parameters
- $property_name
(string)(Required)Property name in a CSS declaration, i.e. the
colorincolor: red.- $property_value
(string)(Required)Value in a CSS declaration, i.e. the
redincolor: red.
Return
(bool)
Source
File: wp-includes/class-wp-theme-json.php
protected static function is_safe_css_declaration( $property_name, $property_value ) {
$style_to_validate = $property_name . ': ' . $property_value;
$filtered = esc_html( safecss_filter_attr( $style_to_validate ) );
return ! empty( trim( $filtered ) );
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |