WP_Style_Engine_CSS_Rules_Store::add_rule( string $selector, string $rules_group =  ): WP_Style_Engine_CSS_Rule|void

Gets a WP_Style_Engine_CSS_Rule object by its selector.

Description

If the rule does not exist, it will be created.

Parameters

$selectorstringrequired
The CSS selector.
$rules_groupstringoptional
A parent CSS selector in the case of nested CSS, or a CSS nested @rule, such as @media (min-width: 80rem) or @layer module.

Default:''

Return

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

Source

public function add_rule( $selector, $rules_group = '' ) {
	$selector    = $selector ? trim( $selector ) : '';
	$rules_group = $rules_group ? trim( $rules_group ) : '';

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

	if ( ! empty( $rules_group ) ) {
		if ( empty( $this->rules[ "$rules_group $selector" ] ) ) {
			$this->rules[ "$rules_group $selector" ] = new WP_Style_Engine_CSS_Rule( $selector, array(), $rules_group );
		}
		return $this->rules[ "$rules_group $selector" ];
	}

	// 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 ];
}

Changelog

VersionDescription
6.6.0Added the $rules_group parameter.
6.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.