WP_Style_Engine_CSS_Declarations::filter_declaration
Filters a CSS property + value pair.
Method of the class: WP_Style_Engine_CSS_Declarations{}
No Hooks.
Returns
string. The filtered declaration or an empty string.
Usage
$result = WP_Style_Engine_CSS_Declarations::filter_declaration( $property, $value, $spacer, $options );
- $property(string) (required)
- The CSS property.
- $value(string) (required)
- The value to be filtered.
- $spacer(string)
- The spacer between the colon and the value.
Default:empty string - $options(array)
An array of options.
Default:
empty array- important(true|false)
Whether to output the declaration with !important.
Default: false
- important(true|false)
Changelog
| Since 6.1.0 | Introduced. |
| Since 7.1.0 | Added the $options parameter. |
WP_Style_Engine_CSS_Declarations::filter_declaration() WP Style Engine CSS Declarations::filter declaration code WP 7.1.2
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 '';
}