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

Gallery::extract_images_from_gallery_contentprivateWC 1.0

Extract all images from gallery content with their links and captions.

Метод класса: Gallery{}

Хуков нет.

Возвращает

Массив. Array of sanitized image HTML strings.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->extract_images_from_gallery_content( $block_content, $parsed_block ): array;
$block_content(строка) (обязательный)
The rendered gallery block HTML.
$parsed_block(массив) (обязательный)
The parsed block data.

Код Gallery::extract_images_from_gallery_content() WC 10.4.3

private function extract_images_from_gallery_content( string $block_content, array $parsed_block ): array {
	$gallery_images = array();
	$inner_blocks   = $parsed_block['innerBlocks'] ?? array();

	// Extract images from inner blocks data where the actual image HTML is stored.
	foreach ( $inner_blocks as $block ) {
		if ( 'core/image' === $block['blockName'] && isset( $block['innerHTML'] ) ) {
			$extracted_image = $this->extract_image_from_html( $block['innerHTML'] );
			if ( ! empty( $extracted_image ) ) {
				$gallery_images[] = $extracted_image;
			}
		}
	}

	return $gallery_images;
}