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 color in color: red.

$property_value

(string)(Required)Value in a CSS declaration, i.e. the red in color: red.


Top ↑

Return

(bool)


Top ↑

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


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.