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.
importantboolWhether to output the declaration with !important. Default false.
Default:
array()
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 '';
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.