Title: WP_Style_Engine_Processor::add_rules
Published: November 2, 2022
Last modified: April 28, 2025

---

# WP_Style_Engine_Processor::add_rules( WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[] $css_rules ): 󠀁[WP_Style_Engine_Processor](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#wp--skip-link--target)

Adds rules to be processed.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#parameters)󠁿

 `$css_rules`[WP_Style_Engine_CSS_Rule](https://developer.wordpress.org/reference/classes/wp_style_engine_css_rule/)
|[WP_Style_Engine_CSS_Rule](https://developer.wordpress.org/reference/classes/wp_style_engine_css_rule/)[]
required

A single, or an array of, [WP_Style_Engine_CSS_Rule](https://developer.wordpress.org/reference/classes/wp_style_engine_css_rule/)
objects from a store or otherwise.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#return)󠁿

 [WP_Style_Engine_Processor](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/)
Returns the object to allow chaining methods.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#source)󠁿

    ```php
    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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-processor.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/style-engine/class-wp-style-engine-processor.php#L68)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/style-engine/class-wp-style-engine-processor.php#L68-L100)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Style_Engine_Processor::get_css()](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/get_css/)`wp-includes/style-engine/class-wp-style-engine-processor.php` |

Gets the CSS rules as a string.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_style_engine_processor/add_rules/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Added support for rules_group. | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_style_engine_processor%2Fadd_rules%2F)
before being able to contribute a note or feedback.