{"id":5842,"date":"2026-02-12T20:45:33","date_gmt":"2026-02-13T01:45:33","guid":{"rendered":"https:\/\/chubes.net\/?documentation=wp_style_engine_processor"},"modified":"2026-03-13T03:29:30","modified_gmt":"2026-03-13T07:29:30","slug":"wp_style_engine_processor","status":"publish","type":"documentation","link":"https:\/\/chubes.net\/docs\/wordpress-core\/style-engine\/wp_style_engine_processor\/","title":{"rendered":"WP_Style_Engine_Processor"},"content":{"rendered":"<p>Compiles styles from stores or collections of CSS rules into a stylesheet.<\/p><p><strong>Source:<\/strong> <code>wp-includes\/style-engine\/class-wp-style-engine-processor.php<\/code><br \/>\n<strong>Since:<\/strong> 6.1.0<\/p><h2 class=\"wp-block-heading\">Properties<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Type<\/th><th>Visibility<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$stores<\/code><\/td><td>array<\/td><td>protected<\/td><td>Collection of <code>WP_Style_Engine_CSS_Rules_Store<\/code> objects<\/td><\/tr><tr><td><code>$css_rules<\/code><\/td><td>array<\/td><td>protected<\/td><td>Set of <code>WP_Style_Engine_CSS_Rule<\/code> objects to process<\/td><\/tr><\/tbody><\/table><\/figure><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Methods<\/h2><h3 class=\"wp-block-heading\">add_store()<\/h3><p>Adds a store to the processor.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function add_store( WP_Style_Engine_CSS_Rules_Store $store ): WP_Style_Engine_Processor<\/code><\/pre><\/div><h4 class=\"wp-block-heading\">Parameters<\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$store<\/code><\/td><td>WP_Style_Engine_CSS_Rules_Store<\/td><td>Store to add<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\">Returns<\/h4><p><code>$this<\/code> for method chaining.<\/p><h4 class=\"wp-block-heading\">Notes<\/h4><p>Triggers <code>_doing_it_wrong()<\/code> if <code>$store<\/code> is not a <code>WP_Style_Engine_CSS_Rules_Store<\/code> instance.<\/p><h4 class=\"wp-block-heading\">Example<\/h4><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$processor = new WP_Style_Engine_Processor();\n$store = WP_Style_Engine_CSS_Rules_Store::get_store( &#039;my-context&#039; );\n$processor-&gt;add_store( $store );<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\">add_rules()<\/h3><p>Adds rules to be processed.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function add_rules( \n    WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[] $css_rules \n): WP_Style_Engine_Processor<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.1.0<br \/>\n<strong>Since:<\/strong> 6.6.0 Added support for rules_group<\/p><h4 class=\"wp-block-heading\">Parameters<\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$css_rules<\/code><\/td><td>WP_Style_Engine_CSS_Rule|array<\/td><td>Single rule or array of rules<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\">Returns<\/h4><p><code>$this<\/code> for method chaining.<\/p><h4 class=\"wp-block-heading\">Behavior<\/h4><ul class=\"wp-block-list\"><li>Rules with the same selector are merged (declarations combined)<\/li><li>Rules with a <code>rules_group<\/code> are keyed by <code>&quot;$rules_group $selector&quot;<\/code> to maintain separation<\/li><li>Existing rules are updated with new declarations rather than duplicated<\/li><\/ul><h4 class=\"wp-block-heading\">Example<\/h4><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$processor = new WP_Style_Engine_Processor();\n\n\/\/ Add single rule\n$processor-&gt;add_rules( new WP_Style_Engine_CSS_Rule( &#039;.a&#039;, array( &#039;color&#039; =&gt; &#039;red&#039; ) ) );\n\n\/\/ Add multiple rules\n$processor-&gt;add_rules( array(\n    new WP_Style_Engine_CSS_Rule( &#039;.b&#039;, array( &#039;color&#039; =&gt; &#039;blue&#039; ) ),\n    new WP_Style_Engine_CSS_Rule( &#039;.c&#039;, array( &#039;color&#039; =&gt; &#039;green&#039; ) ),\n) );\n\n\/\/ Merge declarations into existing selector\n$processor-&gt;add_rules( new WP_Style_Engine_CSS_Rule( &#039;.a&#039;, array( &#039;font-size&#039; =&gt; &#039;16px&#039; ) ) );\n\/\/ .a now has both color:red and font-size:16px<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h3 class=\"wp-block-heading\">get_css()<\/h3><p>Gets the compiled CSS string.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function get_css( array $options = array() ): string<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.1.0<br \/>\n<strong>Since:<\/strong> 6.4.0 Optimization no longer the default<\/p><h4 class=\"wp-block-heading\">Parameters<\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$options<\/code><\/td><td>array<\/td><td>Configuration options<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\">Options<\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Key<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>optimize<\/code><\/td><td>bool<\/td><td><code>false<\/code><\/td><td>Combine rules with identical declarations<\/td><\/tr><tr><td><code>prettify<\/code><\/td><td>bool<\/td><td><code>SCRIPT_DEBUG<\/code><\/td><td>Add newlines and indentation<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\">Returns<\/h4><p>Compiled CSS string.<\/p><h4 class=\"wp-block-heading\">Process<\/h4><ol class=\"wp-block-list\"><li>Collects rules from all added stores<\/li><li>If <code>optimize<\/code> is true, combines selectors with identical declarations<\/li><li>Compiles each rule to CSS<\/li><li>Concatenates all rules<\/li><\/ol><h4 class=\"wp-block-heading\">Example<\/h4><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">$processor = new WP_Style_Engine_Processor();\n\n$processor-&gt;add_rules( array(\n    new WP_Style_Engine_CSS_Rule( &#039;.a&#039;, array( &#039;color&#039; =&gt; &#039;red&#039; ) ),\n    new WP_Style_Engine_CSS_Rule( &#039;.b&#039;, array( &#039;color&#039; =&gt; &#039;red&#039; ) ),\n    new WP_Style_Engine_CSS_Rule( &#039;.c&#039;, array( &#039;font-size&#039; =&gt; &#039;16px&#039; ) ),\n) );\n\n\/\/ Without optimization\necho $processor-&gt;get_css();\n\/\/ Output: &#039;.a{color:red}.b{color:red}.c{font-size:16px}&#039;\n\n\/\/ With optimization (combine .a and .b)\necho $processor-&gt;get_css( array( &#039;optimize&#039; =&gt; true ) );\n\/\/ Output: &#039;.a,.b{color:red}.c{font-size:16px}&#039;\n\n\/\/ Prettified\necho $processor-&gt;get_css( array( &#039;prettify&#039; =&gt; true ) );\n\/\/ Output:\n\/\/ .a {\n\/\/ \tcolor: red;\n\/\/ }\n\/\/ .b {\n\/\/ \tcolor: red;\n\/\/ }\n\/\/ .c {\n\/\/ \tfont-size: 16px;\n\/\/ }<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">Private Methods<\/h2><h3 class=\"wp-block-heading\">combine_rules_selectors()<\/h3><p>Combines selectors from rules when they have identical declarations.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">private function combine_rules_selectors(): void<\/code><\/pre><\/div><h4 class=\"wp-block-heading\">Behavior<\/h4><ol class=\"wp-block-list\"><li>Serializes each rule&#8217;s declarations to JSON for comparison<\/li><li>Finds rules with identical declaration sets<\/li><li>Merges their selectors (comma-separated)<\/li><li>Removes duplicate rules, keeping combined version<\/li><\/ol><h4 class=\"wp-block-heading\">Example Effect<\/h4><p>Before:<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">css<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-css\"><code class=\"language-css\">.a { color: red; }\n.b { color: red; }\n.c { color: blue; }<\/code><\/pre><\/div><p>After optimization:<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">css<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-css\"><code class=\"language-css\">.a, .b { color: red; }\n.c { color: blue; }<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Compiles styles from stores or collections of CSS rules into a stylesheet. Source: wp-includes\/style-engine\/class-wp-style-engine-processor.php Since: 6.1.0 Properties Property Type Visibility Description $stores array protected Collection of WP_Style_Engine_CSS_Rules_Store objects $css_rules array&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"footnotes":""},"tags":[],"project":[663],"project_type":[749],"class_list":["post-5842","documentation","type-documentation","status-publish","hentry","project-style-engine","project_type-wordpress-reference"],"project_info":{"id":589,"name":"WordPress Core","slug":"wordpress-core"},"project_type_info":{"id":749,"name":"WordPress Reference","slug":"wordpress-reference"},"_links":{"self":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/types\/documentation"}],"version-history":[{"count":3,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5842\/revisions"}],"predecessor-version":[{"id":11018,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5842\/revisions\/11018"}],"wp:attachment":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/media?parent=5842"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/tags?post=5842"},{"taxonomy":"project","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project?post=5842"},{"taxonomy":"project_type","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project_type?post=5842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}