Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Gallery::extract_images_from_gallery_content
Extract all images from gallery content with their links and captions.
Method of the class: Gallery{}
No Hooks.
Returns
Array. Array of sanitized image HTML strings.
Usage
// private - for code of main (parent) class only $result = $this->extract_images_from_gallery_content( $block_content, $parsed_block ): array;
- $block_content(string) (required)
- The rendered gallery block HTML.
- $parsed_block(array) (required)
- The parsed block data.
Gallery::extract_images_from_gallery_content() Gallery::extract images from gallery content code WC 10.5.0
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;
}