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

Post_Template::find_post_template_list │ private │ WC 1.0

Locate the post-template list within the rendered content.

The list is matched by its wp-block-post-template class rather than by being the first <ul>, so a sibling list that happens to appear earlier in the markup can't be mistaken for the repeater. Returns null when no such list is present.

Method of the class: Post_Template{}

No Hooks.

Returns

\DOMElement|null.

Usage

// private - for code of main (parent) class only
$result = $this->find_post_template_list( $dom ): ?\DOMElement;
$dom(Dom_Document_Helper) (required)
Parsed block content.

Post_Template::find_post_template_list() code WC 11.1.2

private function find_post_template_list( Dom_Document_Helper $dom ): ?\DOMElement {
	foreach ( $dom->find_elements( 'ul' ) as $list_element ) {
		// Match `wp-block-post-template` as a whole class token, not a substring, so an unrelated
		// list whose class merely contains the string (e.g. `my-wp-block-post-template-wrapper`)
		// isn't mistaken for the repeater and rebuilt.
		$classes = preg_split( '/\s+/', trim( $dom->get_attribute_value( $list_element, 'class' ) ) );
		if ( is_array( $classes ) && in_array( 'wp-block-post-template', $classes, true ) ) {
			return $list_element;
		}
	}
	return null;
}