WooCommerce Code Reference

DeclarationBlock extends RuleSet
in package

This class represents a `RuleSet` constrained by a `Selector`.

It contains an array of selector objects (comma-separated in the CSS) as well as the rules to be applied to the matching elements.

Declaration blocks usually appear directly inside a Document or another CSSList (mostly a MediaQuery).

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.
$aSelectors  : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
__construct()  : mixed
__toString()  : string
addComments()  : void
addRule()  : void
createBackgroundShorthand()  : void
createBorderShorthand()  : void
Combines `border-color`, `border-style` and `border-width` into `border`.
createDimensionsShorthand()  : void
Looks for long format CSS dimensional properties (margin, padding, border-color, border-style and border-width) and converts them into shorthand CSS properties.
createFontShorthand()  : void
Looks for long format CSS font properties (e.g. `font-weight`) and tries to convert them into a shorthand CSS `font` property.
createListStyleShorthand()  : void
createShorthandProperties()  : void
createShorthands()  : void
Creates shorthand declarations (e.g. `margin` or `font`) whenever possible.
expandBackgroundShorthand()  : void
Converts shorthand background declarations (e.g. `background: url("chess.png") gray 50% repeat fixed;`) into their constituent parts.
expandBorderShorthand()  : void
Splits shorthand border declarations (e.g. `border: 1px red;`).
expandDimensionsShorthand()  : void
Splits shorthand dimensional declarations (e.g. `margin: 0px auto;`) into their constituent parts.
expandFontShorthand()  : void
Converts shorthand font declarations (e.g. `font: 300 italic 11px/14px verdana, helvetica, sans-serif;`) into their constituent parts.
expandListStyleShorthand()  : void
expandShorthands()  : void
Splits shorthand declarations (e.g. `margin` or `font`) into their constituent parts.
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.
getSelector()  : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
getSelectors()  : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
removeAllRules()  : mixed
removeMatchingRules()  : mixed
Removes rules by property name or search pattern.
removeRule()  : mixed
Removes a `Rule` from this `RuleSet` by identity.
removeSelector()  : bool
Remove one of the selectors of the block.
render()  : string
setComments()  : void
setRules()  : void
Overrides all the rules of this set.
setSelector()  : void
setSelectors()  : mixed
renderRules()  : string

Properties

Methods

createBorderShorthand()

Combines `border-color`, `border-style` and `border-width` into `border`.

public createBorderShorthand() : void

Should be run after create_dimensions_shorthand!

Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

createDimensionsShorthand()

Looks for long format CSS dimensional properties (margin, padding, border-color, border-style and border-width) and converts them into shorthand CSS properties.

public createDimensionsShorthand() : void
Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

createFontShorthand()

Looks for long format CSS font properties (e.g. `font-weight`) and tries to convert them into a shorthand CSS `font` property.

public createFontShorthand() : void

At least font-size AND font-family must be present in order to create a shorthand declaration.

Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

createShorthandProperties()

public createShorthandProperties(array<array-key, string> $aProperties, string $sShorthand) : void
Parameters
$aProperties : array<array-key, string>
$sShorthand : string
Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

createShorthands()

Creates shorthand declarations (e.g. `margin` or `font`) whenever possible.

public createShorthands() : void
Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

expandBorderShorthand()

Splits shorthand border declarations (e.g. `border: 1px red;`).

public expandBorderShorthand() : void

Additional splitting happens in expandDimensionsShorthand.

Multiple borders are not yet supported as of 3.

Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

expandDimensionsShorthand()

Splits shorthand dimensional declarations (e.g. `margin: 0px auto;`) into their constituent parts.

public expandDimensionsShorthand() : void

Handles margin, padding, border-color, border-style and border-width.

Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

expandFontShorthand()

Converts shorthand font declarations (e.g. `font: 300 italic 11px/14px verdana, helvetica, sans-serif;`) into their constituent parts.

public expandFontShorthand() : void
Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

expandShorthands()

Splits shorthand declarations (e.g. `margin` or `font`) into their constituent parts.

public expandShorthands() : void
Tags
deprecated

since 8.7.0, will be removed without substitution in version 9.0 in #511

Return values
void

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>

getSelector()

public getSelector() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
Tags
deprecated

will be removed in version 9.0; use getSelectors() instead

Return values
array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>

getSelectors()

public getSelectors() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
Return values
array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>

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