wp-includes/blocks/image.php:180Adds the directives and layout needed for the lightbox behavior.
$block_contentstring$blockarray$block_instancearraystringfunction block_core_image_render_lightbox( $block_content, $block, $block_instance ) { /* * If there's no IMG tag in the block then return the given block content * as-is. There's nothing that this code can knowingly modify to add the * lightbox behavior. */ $processor = new WP_HTML_Tag_Processor( $block_content ); if ( $processor->next_tag( 'figure' ) ) { $processor->set_bookmark( 'figure' ); } if ( ! $processor->next_tag( 'img' ) ) { return $block_content; } $alt = $processor->get_attribute( 'alt' ); $img_uploaded_src = $processor->get_attribute( 'src' ); $img_class_names = $processor->get_attribute( 'class' ); $img_styles = $processor->get_attribute( 'style' ); $img_width = 'none'; $img_height = 'none'; $img_srcset = false; wp_interactivity_config( 'core/image', array( 'defaultAriaLabel' => __( 'Enlarged image' ), 'closeButtonText' => esc_html__( 'Close' ), 'prevButtonText' => esc_html_x( 'Previous', 'previous image in lightbox' ), 'nextButtonText' => esc_html_x( 'Next', 'next image in lightbox' ), ) ); if ( $alt ) { /* translators: %s: Image alt text. */ $custom_aria_label = sprintf( __( 'Enlarged image: %s' ), $alt ); } if ( isset( $block['attrs']['id'] ) ) { $img_uploaded_src = wp_get_attachment_url( $block['attrs']['id'] ); $img_metadata = wp_get_attachment_metadata( $block['attrs']['id'] ); $has_dimensions = ( $img_metadata['width'] ?? '' ) && ( $img_metadata['height'] ?? '' ); $srcset_size = $has_dimensions ? array( $img_metadata['width'], $img_metadata['height'] ) : 'large'; $img_srcset = wp_get_attachment_image_srcset( $block['attrs']['id'], $srcset_size ); $img_width = $img_metadata['width'] ?? 'none'; $img_height = $img_metadata['height'] ?? 'none'; } // Figure. $processor->seek( 'figure' ); $figure_class_names = $processor->get_attribute( 'class' ); $figure_styles = $processor->get_attribute( 'style' ); // Create unique id and set the image metadata in the state. $unique_image_id = uniqid(); wp_interactivity_state( 'core/image', array( 'metadata' => array( $unique_image_id => array( 'uploadedSrc' => $img_uploaded_src, 'lightboxSrcset' => $img_srcset, 'figureClassNames' => $figure_class_names, 'figureStyles' => $figure_styles, 'imgClassNames' => $img_class_names, 'imgStyles' => $img_styles, 'targetWidth' => $img_width, 'targetHeight' => $img_height, 'scaleAttr' => $block['attrs']['scale'] ?? false, 'alt' => $alt, 'galleryId' => $block_instance->context['galleryId'] ?? null, 'customAriaLabel' => $custom_aria_label ?? null, 'navigationButtonType' => $block_instance->context['navigationButtonType'] ?? 'icon', 'triggerButtonAriaLabel' => __( 'Enlarge' ), ), ), ) ); $processor->add_class( 'wp-lightbox-container' );Introduced in 6.4.0. 2 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$block_instance retyped from array to WP_Block.verified against source$block_instance added.verified against sourcesrc/wp-includes/blocks/image.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.