WooCommerce Code Reference

RuleSet
in package
implements CSSElement, Commentable, Positionable Uses Position

This class is a container for individual 'Rule's.

The most common form of a rule set is one constrained by a selector, i.e., a DeclarationBlock. However, unknown AtRules (like @font-face) are rule sets as well.

If you want to manipulate a RuleSet, use the methods addRule(Rule $rule), getRules() and removeRule($rule) (which accepts either a Rule or a rule name; optionally suffixed by a dash to remove all related rules).

Interfaces, Classes and Traits

CSSElement
Represents any entity in the CSS that is encapsulated by a class.
Commentable
Positionable
Represents a CSS item that may have a position in the source CSS document (line number and possibly column number).

Table of Contents

$aRules  : array<string, array<int<0, max>, Rule>>
the rules in this rule set, using the property name as the key, with potentially multiple rules per property name.
__construct()  : mixed
__toString()  : string
addComments()  : void
addRule()  : void
getComments()  : array<string, Comment>
getRules()  : array<int, Rule>
Returns all rules matching the given rule name
getRulesAssoc()  : array<string, Rule>
Returns all rules matching the given pattern and returns them in an associative array with the rule’s name as keys. This method exists mainly for backwards-compatibility and is really only partially useful.
removeAllRules()  : mixed
removeMatchingRules()  : mixed
Removes rules by property name or search pattern.
removeRule()  : mixed
Removes a `Rule` from this `RuleSet` by identity.
setComments()  : void
setRules()  : void
Overrides all the rules of this set.
renderRules()  : string

Properties

Methods

getRules()

Returns all rules matching the given rule name

public getRules([Rule|string|null $mRule = null ]) : array<int, Rule>
Parameters
$mRule : Rule|string|null = null

Pattern to search for. If null, returns all rules. If the pattern ends with a dash, all rules starting with the pattern are returned as well as one matching the pattern with the dash excluded. Passing a Rule for this parameter is deprecated in version 8.9.0, and will not work from v9.0. Call getRules($rule->getRule()) instead.

Tags
example

$oRuleSet->getRules('font') // returns array(0 => $oRule, …) or array().

example

$oRuleSet->getRules('font-') //returns an array of all rules either beginning with font- or matching font.

Return values
array<int, Rule>

getRulesAssoc()

Returns all rules matching the given pattern and returns them in an associative array with the rule’s name as keys. This method exists mainly for backwards-compatibility and is really only partially useful.

public getRulesAssoc([Rule|string|null $mRule = null ]) : array<string, Rule>

Note: This method loses some information: Calling this (with an argument of background-) on a declaration block like { background-color: green; background-color; rgba(0, 127, 0, 0.7); } will only yield an associative array containing the rgba-valued rule while getRules() would yield an indexed array containing both.

Parameters
$mRule : Rule|string|null = null

$mRule Pattern to search for. If null, returns all rules. If the pattern ends with a dash, all rules starting with the pattern are returned as well as one matching the pattern with the dash excluded. Passing a Rule for this parameter is deprecated in version 8.9.0, and will not work from v9.0. Call getRulesAssoc($rule->getRule()) instead.

Return values
array<string, Rule>

removeMatchingRules()

Removes rules by property name or search pattern.

public removeMatchingRules(string $searchPattern) : mixed
Parameters
$searchPattern : string

pattern to remove. If the pattern ends in a dash, all rules starting with the pattern are removed as well as one matching the pattern with the dash excluded.

Return values
mixed

removeRule()

Removes a `Rule` from this `RuleSet` by identity.

public removeRule(Rule|string|null $mRule) : mixed
Parameters
$mRule : Rule|string|null

Rule to remove. Passing a string or null is deprecated in version 8.9.0, and will no longer work from v9.0. Use removeMatchingRules() or removeAllRules() instead.

Return values
mixed