Automattic\WooCommerce\Vendor\Pelago\Emogrifier
CssInliner::copyUninlinableCssToStyleNode
Applies $this->matchingUninlinableCssRules to $this->domDocument by placing them as CSS in a <style> element. If there are no uninlinable CSS rules to copy there, a <style> element will be created containing only the applicable at-rules from $parsedCss. If there are none of either, an empty <style> element will not be created.
Method of the class: CssInliner{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->copyUninlinableCssToStyleNode( $parsedCss ): void;
- $parsedCss(CssDocument) (required)
- This may contain various at-rules whose content
CssInlinerdoes not currently attempt to inline or process in any other way, such as@import,@font-face,@keyframes, etc., and which should precede the processed but found-to-be-uninlinable CSS placed in the<style>element. Note thatCssInlinerprocesses@mediarules so that they can be ordered correctly with respect to other uninlinable rules; these will not be duplicated from$parsedCss.
CssInliner::copyUninlinableCssToStyleNode() CssInliner::copyUninlinableCssToStyleNode code WC 10.8.1
private function copyUninlinableCssToStyleNode(CssDocument $parsedCss): void
{
$css = $parsedCss->renderNonConditionalAtRules();
// avoid including unneeded class dependency if there are no rules
if ($this->getMatchingUninlinableCssRules() !== []) {
$cssConcatenator = new CssConcatenator();
foreach ($this->getMatchingUninlinableCssRules() as $cssRule) {
$cssConcatenator->append([$cssRule['selector']], $cssRule['declarationsBlock'], $cssRule['media']);
}
$css .= $cssConcatenator->getCss();
}
// avoid adding empty style element
if ($css !== '') {
$this->addStyleElementToDocument($css);
}
}