WP_Style_Engine_CSS_Rules_Store::add_rule()publicWP 6.1.0

Gets a WP_Style_Engine_CSS_Rule object by its selector. If the rule does not exist, it will be created.

Method of the class: WP_Style_Engine_CSS_Rules_Store{}

No Hooks.

Return

WP_Style_Engine_CSS_Rule|null. Returns a WP_Style_Engine_CSS_Rule object, or void if the selector is empty.

Usage

$WP_Style_Engine_CSS_Rules_Store = new WP_Style_Engine_CSS_Rules_Store();
$WP_Style_Engine_CSS_Rules_Store->add_rule( $selector );
$selector(string) (required)
The CSS selector.

Changelog

Since 6.1.0 Introduced.

WP_Style_Engine_CSS_Rules_Store::add_rule() code WP 6.5.4

public function add_rule( $selector ) {
	$selector = trim( $selector );

	// Bail early if there is no selector.
	if ( empty( $selector ) ) {
		return;
	}

	// Create the rule if it doesn't exist.
	if ( empty( $this->rules[ $selector ] ) ) {
		$this->rules[ $selector ] = new WP_Style_Engine_CSS_Rule( $selector );
	}

	return $this->rules[ $selector ];
}