Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Post_Template::count_media_descendants │ private │ WC 1.0

Count the media elements (images and embeds) contained within an element.

Method of the class: Post_Template{}

No Hooks.

Returns

int.

Usage

// private - for code of main (parent) class only
$result = $this->count_media_descendants( $element ): int;
$element(DOMElement) (required)
The element to inspect.

Post_Template::count_media_descendants() code WC 11.1.2

private function count_media_descendants( \DOMElement $element ): int {
	$count = $element->getElementsByTagName( 'img' )->length;
	foreach ( array( 'video', 'audio', 'iframe', 'svg' ) as $tag_name ) {
		$count += $element->getElementsByTagName( $tag_name )->length;
	}
	return $count;
}