@@ -49,31 +49,32 @@ function render_block_core_image( $attributes, $content ) {
4949
5050 if ( ! empty ( $ experiments ['gutenberg-interactivity-api-core-blocks ' ] ) && 'none ' === $ link_destination && $ lightbox ) {
5151
52- $ aria_label = 'Open image lightbox ' ;
53- if ( $ processor ->get_attribute ( 'alt ' ) ) {
54- $ aria_label .= ' : ' . $ processor ->get_attribute ( 'alt ' );
52+ $ aria_label = __ ( 'Enlarge image ' );
53+
54+ $ alt_attribute = trim ( $ processor ->get_attribute ( 'alt ' ) );
55+
56+ if ( $ alt_attribute ) {
57+ /* translators: %s: Image alt text. */
58+ $ aria_label = sprintf ( __ ( 'Enlarge image: %s ' ), $ alt_attribute );
5559 }
5660 $ content = $ processor ->get_updated_html ();
5761
5862 // Wrap the image in the body content with a button.
5963 $ img = null ;
6064 preg_match ( '/<img[^>]+>/ ' , $ content , $ img );
6165 $ button = '<div class="img-container">
62- <button aria-haspopup="dialog" aria-label=" ' . $ aria_label . '" data-wp-on.click="actions.core.image.showLightbox"></button> '
66+ <button type="button" aria-haspopup="dialog" aria-label=" ' . esc_attr ( $ aria_label ) . '" data-wp-on.click="actions.core.image.showLightbox"></button> '
6367 . $ img [0 ] .
6468 '</div> ' ;
6569 $ body_content = preg_replace ( '/<img[^>]+>/ ' , $ button , $ content );
6670
67- // For the modal, set an ID on the image to be used for an aria-labelledby attribute.
68- $ modal_content = new WP_HTML_Tag_Processor ( $ content );
69- $ modal_content ->next_tag ( 'img ' );
70- $ image_lightbox_id = $ modal_content ->get_attribute ( 'class ' ) . '-lightbox ' ;
71- $ modal_content ->set_attribute ( 'id ' , $ image_lightbox_id );
72- $ modal_content = $ modal_content ->get_updated_html ();
73-
7471 $ background_color = wp_get_global_styles ( array ( 'color ' , 'background ' ) );
7572 $ close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="30" height="30" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg> ' ;
7673
74+ $ dialog_label = $ alt_attribute ? $ alt_attribute : __ ( 'Image ' );
75+
76+ $ close_button_label = __ ( 'Close ' );
77+
7778 return
7879 <<<HTML
7980 <div class="wp-lightbox-container"
@@ -82,7 +83,7 @@ function render_block_core_image( $attributes, $content ) {
8283 $ body_content
8384 <div data-wp-body="" class="wp-lightbox-overlay"
8485 data-wp-bind.role="selectors.core.image.roleAttribute"
85- aria-labelledby =" $ image_lightbox_id "
86+ aria-label =" $ dialog_label "
8687 data-wp-class.initialized="context.core.image.initialized"
8788 data-wp-class.active="context.core.image.lightboxEnabled"
8889 data-wp-bind.aria-hidden="!context.core.image.lightboxEnabled"
@@ -92,10 +93,10 @@ function render_block_core_image( $attributes, $content ) {
9293 data-wp-on.mousewheel="actions.core.image.hideLightbox"
9394 data-wp-on.click="actions.core.image.hideLightbox"
9495 >
95- <button aria-label="Close lightbox " class="close-button" data-wp-on.click="actions.core.image.hideLightbox">
96+ <button type="button" aria-label=" $ close_button_label " class="close-button" data-wp-on.click="actions.core.image.hideLightbox">
9697 $ close_button_icon
9798 </button>
98- $ modal_content
99+ $ content
99100 <div class="scrim" style="background-color: $ background_color"></div>
100101 </div>
101102 </div>
0 commit comments