WP_Style_Engine_CSS_Declarations::filter_declaration( string $property, string $value, string $spacer = ”, array $options = array() ): string

In this article

Filters a CSS property + value pair.

Parameters

$propertystringrequired
The CSS property.
$valuestringrequired
The value to be filtered.
$spacerstringoptional
The spacer between the colon and the value.

Default:''

$optionsarrayoptional
An array of options.
  • important bool
    Whether to output the declaration with !important. Default false.

Default:array()

Return

string The filtered declaration or an empty string.

Source

protected static function filter_declaration( $property, $value, $spacer = '', $options = array() ) {
	$filtered_value = wp_strip_all_tags( $value, true );
	if ( '' !== $filtered_value ) {
		$options = wp_parse_args(
			$options,
			array(
				'important' => false,
			)
		);

		$filtered_declaration = safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" );

		// Only append !important in the presence of an option value and when sanitization returns a single declaration.
		if ( true === $options['important'] && '' !== $filtered_declaration && ! str_contains( $filtered_declaration, ';' ) ) {
			return "$filtered_declaration !important";
		}

		return $filtered_declaration;
	}
	return '';
}

Changelog

VersionDescription
7.1.0Added the $options parameter.
6.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.