wppaste
WordPress

WP_Style_Engine_CSS_Declarations

Since
6.1.0
Source
wp-includes/style-engine/class-wp-style-engine-css-declarations.php:17
Core class used for style engine CSS declarations.

Description

Holds, sanitizes, processes, and prints CSS declarations for the style engine.

Compatibility

WordPress
since 6.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 2

$declarationsstring[]protected
An array of CSS declarations (property => value pairs).
$declaration_optionsarrayprotected
CSS declaration options keyed by property name.

Methods · 10

Source code

#[AllowDynamicProperties]class WP_Style_Engine_CSS_Declarations { 	/**	 * An array of CSS declarations (property => value pairs).	 *	 * @since 6.1.0	 *	 * @var string[]	 */	protected $declarations = array(); 	/**	 * CSS declaration options keyed by property name.	 *	 * @since 7.1.0	 *	 * @var array	 */	protected $declaration_options = array(); 	/**	 * Constructor for this object.	 *	 * If a `$declarations` array is passed, it will be used to populate	 * the initial `$declarations` prop of the object by calling add_declarations().	 *	 * @since 6.1.0	 *	 * @param string[] $declarations Optional. An associative array of CSS definitions,	 *                               e.g. `array( "$property" => "$value", "$property" => "$value" )`.	 *                               Default empty array.	 */	public function __construct( $declarations = array() ) {		$this->add_declarations( $declarations );	} 	/**	 * Adds a single declaration.	 *	 * @since 6.1.0	 * @since 7.1.0 Added the `$options` parameter.	 *	 * @param string $property The CSS property.	 * @param string $value    The CSS value.	 * @param array  $options  {	 *     Optional. An array of options. Default empty array.	 *	 *     @type bool $important Whether to output the declaration with !important. Default false.	 * }	 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.	 */	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.

Changelog

Introduced in 6.1.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Method get_declaration_options() added.verified against source
6.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.