Adds rules to be processed.
Parameters
$css_rules
WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[]required- A single, or an array of, WP_Style_Engine_CSS_Rule objects from a store or otherwise.
Source
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;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.