Automattic\WooCommerce\Vendor\Pelago\Emogrifier\HtmlProcessor
HtmlPruner::removeRedundantClassesAfterCssInlined
After CSS has been inlined, there will likely be some classes in class attributes that are no longer referenced by any remaining (uninlinable) CSS. This method removes such classes.
Note that it does not inspect the remaining CSS, but uses information readily available from the CssInliner instance about the CSS rules that could not be inlined.
Method of the class: HtmlPruner{}
No Hooks.
Returns
$this.
Usage
$HtmlPruner = new HtmlPruner(); $HtmlPruner->removeRedundantClassesAfterCssInlined( $cssInliner ): self;
- $cssInliner(CssInliner) (required)
- object instance that performed the CSS inlining.
HtmlPruner::removeRedundantClassesAfterCssInlined() HtmlPruner::removeRedundantClassesAfterCssInlined code WC 10.8.1
public function removeRedundantClassesAfterCssInlined(CssInliner $cssInliner): self
{
$preg = new Preg();
$classesToKeepAsKeys = [];
foreach ($cssInliner->getMatchingUninlinableSelectors() as $selector) {
$preg->matchAll('/\\.(-?+[_a-zA-Z][\\w\\-]*+)/', $selector, $matches);
$classesToKeepAsKeys += \array_fill_keys($matches[1], true);
}
$this->removeRedundantClasses(\array_keys($classesToKeepAsKeys));
return $this;
}