Skip to content

Commit

Permalink
Add support for external urls in the lightbox (WordPress#51278)
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot authored and sethrubenstein committed Jul 13, 2023
1 parent 59fd047 commit ee5acb9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/block-supports/behaviors.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {
// Add directive to expand modal image if appropriate.
$m = new WP_HTML_Tag_Processor( $content );
$m->next_tag( 'img' );
$m->set_attribute( 'data-wp-context', '{ "core": { "image": { "imageSrc": "' . wp_get_attachment_url( $block['attrs']['id'] ) . '"} } }' );
if ( isset( $block['attrs']['id'] ) ) {
$img_src = wp_get_attachment_url( $block['attrs']['id'] );
} else {
$img_src = $m->get_attribute( 'src' );
}
$m->set_attribute( 'data-wp-context', '{ "core": { "image": { "imageSrc": "' . $img_src . '"} } }' );
$m->set_attribute( 'data-wp-bind--src', 'selectors.core.image.imageSrc' );
$modal_content = $m->get_updated_html();

Expand Down

0 comments on commit ee5acb9

Please sign in to comment.