Automattic\WooCommerce\Vendor\Pelago\Emogrifier\HtmlProcessor

HtmlPruner::removeRedundantClassespublicWC 1.0

Removes classes that are no longer required (e.g. because there are no longer any CSS rules that reference them) from class attributes.

Note that this does not inspect the CSS, but expects to be provided with a list of classes that are still in use.

This method also has the (presumably beneficial) side-effect of minifying (removing superfluous whitespace from) class attributes.

Method of the class: HtmlPruner{}

No Hooks.

Returns

$this.

Usage

$HtmlPruner = new HtmlPruner();
$HtmlPruner->removeRedundantClasses( $classesToKeep ): self;
$classesToKeep(array)
.
Default: []

HtmlPruner::removeRedundantClasses() code WC 10.4.3

public function removeRedundantClasses(array $classesToKeep = []): self
{
    $elementsWithClassAttribute = $this->getXPath()->query('//*[@class]');

    if ($classesToKeep !== []) {
        $this->removeClassesFromElements($elementsWithClassAttribute, $classesToKeep);
    } else {
        // Avoid unnecessary processing if there are no classes to keep.
        $this->removeClassAttributeFromElements($elementsWithClassAttribute);
    }

    return $this;
}