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.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3).

Properties · 1

$declarationsstring[]protected
An array of CSS declarations (property => value pairs).

Methods · 9

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(); 	/**	 * 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	 *	 * @param string $property The CSS property.	 * @param string $value    The CSS value.	 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.	 */	public function add_declaration( $property, $value ) {		// Sanitizes the property.		$property = $this->sanitize_property( $property );		// Bails early if the property is empty.		if ( empty( $property ) ) {			return $this;		} 		// Trims the value. If empty, bail early.		$value = trim( $value );		if ( '' === $value ) {			return $this;		} 		// Adds the declaration property/value pair.		$this->declarations[ $property ] = $value; 		return $this;	} 	/**	 * Removes a single declaration.	 *	 * @since 6.1.0	 *	 * @param string $property The CSS property.	 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.	 */	public function remove_declaration( $property ) {		unset( $this->declarations[ $property ] );		return $this;	} 	/**	 * Adds multiple declarations.	 *	 * @since 6.1.0	 *	 * @param string[] $declarations An array of declarations.	 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.	 */	public function add_declarations( $declarations ) {		foreach ( $declarations as $property => $value ) {

Changelog

Introduced in 6.1.0. One change between 6.7.10 and 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

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

7.1.3
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 6.8.11 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.