Automattic\WooCommerce\Vendor\Pelago\Emogrifier\HtmlProcessor

CssToAttributeConverter::mapWidthOrHeightPropertyprivateWC 1.0

Method of the class: CssToAttributeConverter{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->mapWidthOrHeightProperty( $node, $value, $property ): void;
$node(DOMElement) (required)
node to apply styles to.
$value(string) (required)
the value of the style rule to map.
$property(string) (required)
the name of the CSS property to map.

CssToAttributeConverter::mapWidthOrHeightProperty() code WC 10.8.1

private function mapWidthOrHeightProperty(\DOMElement $node, string $value, string $property): void
{
    $preg = new Preg();

    // only parse values in px and %, but not values like "auto"
    if ($preg->match('/^(\\d+)(\\.(\\d+))?(px|%)$/', $value) === 0) {
        return;
    }

    $number = $preg->replace('/[^0-9.%]/', '', $value);
    $node->setAttribute($property, $number);
}