WP_Style_Engine_CSS_Declarations::add_declaration
Adds a single declaration.
Method of the class: WP_Style_Engine_CSS_Declarations{}
No Hooks.
Returns
WP_Style_Engine_CSS_Declarations. Returns the object to allow chaining methods.
Usage
$WP_Style_Engine_CSS_Declarations = new WP_Style_Engine_CSS_Declarations(); $WP_Style_Engine_CSS_Declarations->add_declaration( $property, $value, $options );
- $property(string) (required)
- The CSS property.
- $value(string) (required)
- The CSS value.
- $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::add_declaration() WP Style Engine CSS Declarations::add declaration code WP 7.1
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;
}