| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Style Engine: WP_Style_Engine_CSS_Rules_Store class 4 * 5 * @package WordPress 6 * @subpackage StyleEngine 7 * @since 6.1.0 8 */ 9 10 /** 11 * Core class used as a store for WP_Style_Engine_CSS_Rule objects. 12 * 13 * Holds, sanitizes, processes, and prints CSS declarations for the style engine. 14 * 15 * @since 6.1.0 16 * 17 * @phpstan-consistent-constructor 18 */ 19 #[AllowDynamicProperties] 20 class WP_Style_Engine_CSS_Rules_Store { 21 22 /** 23 * An array of named WP_Style_Engine_CSS_Rules_Store objects. 24 * 25 * @static 26 * 27 * @since 6.1.0 28 * @var WP_Style_Engine_CSS_Rules_Store[] 29 */ 30 protected static $stores = array(); 31 32 /** 33 * The store name. 34 * 35 * @since 6.1.0 36 * @var string 37 */ 38 protected $name = ''; 39 40 /** 41 * An array of CSS Rules objects assigned to the store. 42 * 43 * @since 6.1.0 44 * @var WP_Style_Engine_CSS_Rule[] 45 */ 46 protected $rules = array(); 47 48 /** 49 * Gets an instance of the store. 50 * 51 * @since 6.1.0 52 * 53 * @param string $store_name The name of the store. 54 * @return WP_Style_Engine_CSS_Rules_Store|null 55 */ 56 public static function get_store( $store_name = 'default' ) { 57 if ( ! is_string( $store_name ) || empty( $store_name ) ) { 58 return null; 59 } 60 if ( ! isset( static::$stores[ $store_name ] ) ) { 61 static::$stores[ $store_name ] = new static(); 62 // Set the store name. 63 static::$stores[ $store_name ]->set_name( $store_name ); 64 } 65 return static::$stores[ $store_name ]; 66 } 67 68 /** 69 * Gets an array of all available stores. 70 * 71 * @since 6.1.0 72 * 73 * @return WP_Style_Engine_CSS_Rules_Store[] 74 */ 75 public static function get_stores() { 76 return static::$stores; 77 } 78 79 /** 80 * Clears all stores from static::$stores. 81 * 82 * @since 6.1.0 83 */ 84 public static function remove_all_stores() { 85 static::$stores = array(); 86 } 87 88 /** 89 * Sets the store name. 90 * 91 * @since 6.1.0 92 * 93 * @param string $name The store name. 94 */ 95 public function set_name( $name ) { 96 $this->name = $name; 97 } 98 99 /** 100 * Gets the store name. 101 * 102 * @since 6.1.0 103 * 104 * @return string 105 */ 106 public function get_name() { 107 return $this->name; 108 } 109 110 /** 111 * Gets an array of all rules. 112 * 113 * @since 6.1.0 114 * 115 * @return WP_Style_Engine_CSS_Rule[] 116 */ 117 public function get_all_rules() { 118 return $this->rules; 119 } 120 121 /** 122 * Gets a WP_Style_Engine_CSS_Rule object by its selector. 123 * If the rule does not exist, it will be created. 124 * 125 * @since 6.1.0 126 * @since 6.6.0 Added the $rules_group parameter. 127 * 128 * @param string $selector The CSS selector. 129 * @param string $rules_group A parent CSS selector in the case of nested CSS, or a CSS nested @rule, 130 * such as `@media (min-width: 80rem)` or `@layer module`. 131 * @return WP_Style_Engine_CSS_Rule|null Returns a WP_Style_Engine_CSS_Rule object, 132 * or null if the selector is empty. 133 */ 134 public function add_rule( $selector, $rules_group = '' ) { 135 $selector = $selector ? trim( $selector ) : ''; 136 $rules_group = $rules_group ? trim( $rules_group ) : ''; 137 138 // Bail early if there is no selector. 139 if ( empty( $selector ) ) { 140 return null; 141 } 142 143 if ( ! empty( $rules_group ) ) { 144 if ( empty( $this->rules[ "$rules_group $selector" ] ) ) { 145 $this->rules[ "$rules_group $selector" ] = new WP_Style_Engine_CSS_Rule( $selector, array(), $rules_group ); 146 } 147 return $this->rules[ "$rules_group $selector" ]; 148 } 149 150 // Create the rule if it doesn't exist. 151 if ( empty( $this->rules[ $selector ] ) ) { 152 $this->rules[ $selector ] = new WP_Style_Engine_CSS_Rule( $selector ); 153 } 154 155 return $this->rules[ $selector ]; 156 } 157 158 /** 159 * Removes a selector from the store. 160 * 161 * @since 6.1.0 162 * 163 * @param string $selector The CSS selector. 164 */ 165 public function remove_rule( $selector ) { 166 unset( $this->rules[ $selector ] ); 167 } 168 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Jun 15 08:20:09 2026 | Cross-referenced by PHPXref |