[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/style-engine/ -> class-wp-style-engine-css-rules-store.php (source)

   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  #[AllowDynamicProperties]
  18  class WP_Style_Engine_CSS_Rules_Store {
  19  
  20      /**
  21       * An array of named WP_Style_Engine_CSS_Rules_Store objects.
  22       *
  23       * @static
  24       *
  25       * @since 6.1.0
  26       * @var WP_Style_Engine_CSS_Rules_Store[]
  27       */
  28      protected static $stores = array();
  29  
  30      /**
  31       * The store name.
  32       *
  33       * @since 6.1.0
  34       * @var string
  35       */
  36      protected $name = '';
  37  
  38      /**
  39       * An array of CSS Rules objects assigned to the store.
  40       *
  41       * @since 6.1.0
  42       * @var WP_Style_Engine_CSS_Rule[]
  43       */
  44      protected $rules = array();
  45  
  46      /**
  47       * Gets an instance of the store.
  48       *
  49       * @since 6.1.0
  50       *
  51       * @param string $store_name The name of the store.
  52       * @return WP_Style_Engine_CSS_Rules_Store|void
  53       */
  54  	public static function get_store( $store_name = 'default' ) {
  55          if ( ! is_string( $store_name ) || empty( $store_name ) ) {
  56              return;
  57          }
  58          if ( ! isset( static::$stores[ $store_name ] ) ) {
  59              static::$stores[ $store_name ] = new static();
  60              // Set the store name.
  61              static::$stores[ $store_name ]->set_name( $store_name );
  62          }
  63          return static::$stores[ $store_name ];
  64      }
  65  
  66      /**
  67       * Gets an array of all available stores.
  68       *
  69       * @since 6.1.0
  70       *
  71       * @return WP_Style_Engine_CSS_Rules_Store[]
  72       */
  73  	public static function get_stores() {
  74          return static::$stores;
  75      }
  76  
  77      /**
  78       * Clears all stores from static::$stores.
  79       *
  80       * @since 6.1.0
  81       */
  82  	public static function remove_all_stores() {
  83          static::$stores = array();
  84      }
  85  
  86      /**
  87       * Sets the store name.
  88       *
  89       * @since 6.1.0
  90       *
  91       * @param string $name The store name.
  92       */
  93  	public function set_name( $name ) {
  94          $this->name = $name;
  95      }
  96  
  97      /**
  98       * Gets the store name.
  99       *
 100       * @since 6.1.0
 101       *
 102       * @return string
 103       */
 104  	public function get_name() {
 105          return $this->name;
 106      }
 107  
 108      /**
 109       * Gets an array of all rules.
 110       *
 111       * @since 6.1.0
 112       *
 113       * @return WP_Style_Engine_CSS_Rule[]
 114       */
 115  	public function get_all_rules() {
 116          return $this->rules;
 117      }
 118  
 119      /**
 120       * Gets a WP_Style_Engine_CSS_Rule object by its selector.
 121       * If the rule does not exist, it will be created.
 122       *
 123       * @since 6.1.0
 124       *
 125       * @param string $selector The CSS selector.
 126       * @return WP_Style_Engine_CSS_Rule|void Returns a WP_Style_Engine_CSS_Rule object,
 127       *                                       or void if the selector is empty.
 128       */
 129  	public function add_rule( $selector ) {
 130          $selector = trim( $selector );
 131  
 132          // Bail early if there is no selector.
 133          if ( empty( $selector ) ) {
 134              return;
 135          }
 136  
 137          // Create the rule if it doesn't exist.
 138          if ( empty( $this->rules[ $selector ] ) ) {
 139              $this->rules[ $selector ] = new WP_Style_Engine_CSS_Rule( $selector );
 140          }
 141  
 142          return $this->rules[ $selector ];
 143      }
 144  
 145      /**
 146       * Removes a selector from the store.
 147       *
 148       * @since 6.1.0
 149       *
 150       * @param string $selector The CSS selector.
 151       */
 152  	public function remove_rule( $selector ) {
 153          unset( $this->rules[ $selector ] );
 154      }
 155  }


Generated : Fri Apr 26 08:20:02 2024 Cross-referenced by PHPXref