WP_Style_Engine_Processor::add_rules()publicWP 6.1.0

Adds rules to be processed.

Метод класса: WP_Style_Engine_Processor{}

Хуков нет.

Возвращает

WP_Style_Engine_Processor. Returns the object to allow chaining methods.

Использование

$WP_Style_Engine_Processor = new WP_Style_Engine_Processor();
$WP_Style_Engine_Processor->add_rules( $css_rules );
$css_rules(WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[]) (обязательный)
A single, or an array of, WP_Style_Engine_CSS_Rule objects from a store or otherwise.

Список изменений

С версии 6.1.0 Введена.
С версии 6.6.0 Added support for rules_group.

Код WP_Style_Engine_Processor::add_rules() WP 6.7.2

public function add_rules( $css_rules ) {
	if ( ! is_array( $css_rules ) ) {
		$css_rules = array( $css_rules );
	}

	foreach ( $css_rules as $rule ) {
		$selector    = $rule->get_selector();
		$rules_group = $rule->get_rules_group();

		/**
		 * If there is a rules_group and it already exists in the css_rules array,
		 * add the rule to it.
		 * Otherwise, create a new entry for the rules_group.
		 */
		if ( ! empty( $rules_group ) ) {
			if ( isset( $this->css_rules[ "$rules_group $selector" ] ) ) {
				$this->css_rules[ "$rules_group $selector" ]->add_declarations( $rule->get_declarations() );
				continue;
			}
			$this->css_rules[ "$rules_group $selector" ] = $rule;
			continue;
		}

		// If the selector already exists, add the declarations to it.
		if ( isset( $this->css_rules[ $selector ] ) ) {
			$this->css_rules[ $selector ]->add_declarations( $rule->get_declarations() );
			continue;
		}
		$this->css_rules[ $rule->get_selector() ] = $rule;
	}

	return $this;
}