Adds a single declaration.
Parameters
$propertystringrequired- The CSS property.
$valuestringrequired- The CSS value.
$optionsarrayoptional- An array of options.
importantboolWhether to output the declaration with !important. Default false.
Default:
array()
Source
public function add_declaration( $property, $value, $options = array() ) {
// Sanitizes the property.
$property = $this->sanitize_property( $property );
// Bails early if the property is empty.
if ( empty( $property ) ) {
return $this;
}
// Bail early if value is not a string. Prevents fatal errors from malformed block markup.
if ( ! is_string( $value ) ) {
return $this;
}
// Trims the value. If empty, bail early.
$value = trim( $value );
if ( '' === $value ) {
return $this;
}
$options = wp_parse_args(
$options,
array(
'important' => false,
)
);
$options = array_filter( $options );
// Adds the declaration property/value pair.
$this->declarations[ $property ] = $value;
if ( $options ) {
$this->declaration_options[ $property ] = $options;
} else {
unset( $this->declaration_options[ $property ] );
}
return $this;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.