Automattic\WooCommerce\Vendor\Pelago\Emogrifier\Css

CssDocument::isValidAtRuleToRenderprivateWC 1.0

Tests if a CSS rule is an at-rule that should be passed though and copied to a <style> element unmodified:

  • @charset rules are discarded - only UTF-8 is supported - false is returned;
  • @import rules are passed through only if they satisfy the specification ("user agents must ignore any '@import' rule that occurs inside a block or after any non-ignored statement other than an '@charset' or an '@import' rule");
  • @media rules are processed separately to see if their nested rules apply - false is returned;
  • @font-face rules are checked for validity - they must contain both a src and font-family property;
  • other at-rules are assumed to be valid and treated as a black box - true is returned.

Method of the class: CssDocument{}

No Hooks.

Returns

true|false.

Usage

// private - for code of main (parent) class only
$result = $this->isValidAtRuleToRender( $rule ): bool;
$rule(CssRenderable) (required)
.

CssDocument::isValidAtRuleToRender() code WC 10.4.3

private function isValidAtRuleToRender(CssRenderable $rule): bool
{
    if ($rule instanceof CssCharset) {
        return false;
    }

    if ($rule instanceof CssImport) {
        return $this->isImportRuleAllowed;
    }

    $this->isImportRuleAllowed = false;

    if (!$rule instanceof CssAtRule) {
        return false;
    }

    switch ($rule->atRuleName()) {
        case 'media':
            $result = false;
            break;
        case 'font-face':
            $result = $rule instanceof CssRuleSet
                && $rule->getRules('font-family') !== []
                && $rule->getRules('src') !== [];
            break;
        default:
            $result = true;
    }

    return $result;
}