From 08b57eb0e96c43d3a0660081e9cd1bf6e54ef27a Mon Sep 17 00:00:00 2001 From: Ricardo Artemio Morales Date: Tue, 30 May 2023 11:55:23 +0200 Subject: [PATCH 1/4] Put directives on
element and insert lightbox as its child --- packages/block-library/src/image/index.php | 58 ++++++++++++---------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php index ab990bc7a0d27..6469d41685551 100644 --- a/packages/block-library/src/image/index.php +++ b/packages/block-library/src/image/index.php @@ -59,6 +59,17 @@ function render_block_core_image( $attributes, $content ) { } $content = $processor->get_updated_html(); + $w = new WP_HTML_Tag_Processor( $content ); + $w->next_tag( + array( + 'tag_name' => 'figure', + ) + ); + $w->add_class( 'wp-lightbox-container' ); + $w->set_attribute( 'data-wp-island', '' ); + $w->set_attribute( 'data-wp-context', '{ "core": { "image": { "initialized": false, "lightboxEnabled": false } } }' ); + $content = $w->get_updated_html(); + // Wrap the image in the body content with a button. $img = null; preg_match( '/]+>/', $content, $img ); @@ -72,35 +83,30 @@ function render_block_core_image( $attributes, $content ) { $close_button_icon = ''; $dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' ); - $close_button_label = esc_attr__( 'Close' ); - return - << - $body_content - - + $lightbox_html = << + + $content +
+ HTML; + + return preg_replace( '/<\/figure>/', $lightbox_html . '
', $body_content ); } return $processor->get_updated_html(); From dfd0efd6ae8e68da208d232ef1f051a2e7190c2a Mon Sep 17 00:00:00 2001 From: Ricardo Artemio Morales Date: Tue, 30 May 2023 12:12:18 +0200 Subject: [PATCH 2/4] Fix PHP spacing --- packages/block-library/src/image/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php index 6469d41685551..2f812ddf5a376 100644 --- a/packages/block-library/src/image/index.php +++ b/packages/block-library/src/image/index.php @@ -62,7 +62,7 @@ function render_block_core_image( $attributes, $content ) { $w = new WP_HTML_Tag_Processor( $content ); $w->next_tag( array( - 'tag_name' => 'figure', + 'tag_name' => 'figure', ) ); $w->add_class( 'wp-lightbox-container' ); @@ -82,7 +82,7 @@ function render_block_core_image( $attributes, $content ) { $background_color = esc_attr( wp_get_global_styles( array( 'color', 'background' ) ) ); $close_button_icon = ''; - $dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' ); + $dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' ); $close_button_label = esc_attr__( 'Close' ); $lightbox_html = << Date: Mon, 29 May 2023 19:58:25 +0200 Subject: [PATCH 3/4] Add duotone class to nested figure elements --- lib/class-wp-duotone-gutenberg.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index b18121086bae0..f5e04bf840788 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -881,7 +881,12 @@ public static function render_duotone_support( $block_content, $block ) { // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper. $tags = new WP_HTML_Tag_Processor( $block_content ); - if ( $tags->next_tag() ) { + while ( $tags->next_tag( + array( + 'tag_name' => 'figure', + 'class_name' => 'wp-block-image', + ) + ) ) { $tags->add_class( $filter_id ); } From 78b3967ee8a023e398c8ba42ce18cdd175b7356d Mon Sep 17 00:00:00 2001 From: Ricardo Artemio Morales Date: Tue, 30 May 2023 18:43:18 +0200 Subject: [PATCH 4/4] Revert "Add duotone class to nested figure elements" This reverts commit ee4e7767db1f1e980f7c894c350469dbc41b2f41. --- lib/class-wp-duotone-gutenberg.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index f5e04bf840788..b18121086bae0 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -881,12 +881,7 @@ public static function render_duotone_support( $block_content, $block ) { // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper. $tags = new WP_HTML_Tag_Processor( $block_content ); - while ( $tags->next_tag( - array( - 'tag_name' => 'figure', - 'class_name' => 'wp-block-image', - ) - ) ) { + if ( $tags->next_tag() ) { $tags->add_class( $filter_id ); }