Changeset 59072 for trunk/src/wp-includes/blocks/media-text.php
- Timestamp:
- 09/20/2024 01:53:52 AM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/media-text.php
r58565 r59072 30 30 } 31 31 32 $has_media_on_right = isset( $attributes['mediaPosition'] ) && 'right' === $attributes['mediaPosition']; 33 $image_fill = isset( $attributes['imageFill'] ) && $attributes['imageFill']; 34 $focal_point = isset( $attributes['focalPoint'] ) ? round( $attributes['focalPoint']['x'] * 100 ) . '% ' . round( $attributes['focalPoint']['y'] * 100 ) . '%' : '50% 50%'; 35 $unique_id = 'wp-block-media-text__media-' . wp_unique_id(); 36 37 $block_tag_processor = new WP_HTML_Tag_Processor( $content ); 38 $block_query = array( 39 'tag_name' => 'div', 40 'class_name' => 'wp-block-media-text', 41 ); 42 43 while ( $block_tag_processor->next_tag( $block_query ) ) { 44 if ( $image_fill ) { 45 // The markup below does not work with the deprecated `is-image-fill` class. 46 $block_tag_processor->remove_class( 'is-image-fill' ); 47 $block_tag_processor->add_class( 'is-image-fill-element' ); 48 } 49 } 50 51 $content = $block_tag_processor->get_updated_html(); 52 32 53 $media_tag_processor = new WP_HTML_Tag_Processor( $content ); 33 54 $wrapping_figure_query = array( … … 35 56 'class_name' => 'wp-block-media-text__media', 36 57 ); 37 $has_media_on_right = isset( $attributes['mediaPosition'] ) && 'right' === $attributes['mediaPosition'];38 $image_fill = isset( $attributes['imageFill'] ) && $attributes['imageFill'];39 $focal_point = isset( $attributes['focalPoint'] ) ? round( $attributes['focalPoint']['x'] * 100 ) . '% ' . round( $attributes['focalPoint']['y'] * 100 ) . '%' : '50% 50%';40 $unique_id = 'wp-block-media-text__media-' . wp_unique_id();41 58 42 59 if ( $has_media_on_right ) { … … 47 64 if ( $media_tag_processor->has_bookmark( 'last_figure' ) ) { 48 65 $media_tag_processor->seek( 'last_figure' ); 49 if ( $image_fill ) { 50 $media_tag_processor->set_attribute( 'style', 'background-image:url(' . esc_url( $current_featured_image ) . ');background-position:' . $focal_point . ';' ); 51 } else { 52 // Insert a unique ID to identify the figure tag. 53 $media_tag_processor->set_attribute( 'id', $unique_id ); 54 } 66 // Insert a unique ID to identify the figure tag. 67 $media_tag_processor->set_attribute( 'id', $unique_id ); 55 68 } 56 69 } else { 57 70 if ( $media_tag_processor->next_tag( $wrapping_figure_query ) ) { 58 if ( $image_fill ) { 59 $media_tag_processor->set_attribute( 'style', 'background-image:url(' . esc_url( $current_featured_image ) . ');background-position:' . $focal_point . ';' ); 60 } else { 61 // Insert a unique ID to identify the figure tag. 62 $media_tag_processor->set_attribute( 'id', $unique_id ); 63 } 71 // Insert a unique ID to identify the figure tag. 72 $media_tag_processor->set_attribute( 'id', $unique_id ); 64 73 } 65 74 } … … 67 76 $content = $media_tag_processor->get_updated_html(); 68 77 69 // If the image is not set to fill, add the image tag inside the figure tag, 70 // and update the image attributes in order to display the featured image. 71 if ( ! $image_fill ) { 72 $media_size_slug = isset( $attributes['mediaSizeSlug'] ) ? $attributes['mediaSizeSlug'] : 'full'; 73 $image_tag = '<img class="wp-block-media-text__featured_image">'; 74 $content = preg_replace( 75 '/(<figure\s+id="' . preg_quote( $unique_id, '/' ) . '"\s+class="wp-block-media-text__media"\s*>)/', 76 '$1' . $image_tag, 77 $content 78 ); 78 // Add the image tag inside the figure tag, and update the image attributes 79 // in order to display the featured image. 80 $media_size_slug = isset( $attributes['mediaSizeSlug'] ) ? $attributes['mediaSizeSlug'] : 'full'; 81 $image_tag = '<img class="wp-block-media-text__featured_image">'; 82 $content = preg_replace( 83 '/(<figure\s+id="' . preg_quote( $unique_id, '/' ) . '"\s+class="wp-block-media-text__media"\s*>)/', 84 '$1' . $image_tag, 85 $content 86 ); 79 87 80 $image_tag_processor = new WP_HTML_Tag_Processor( $content ); 88 $image_tag_processor = new WP_HTML_Tag_Processor( $content ); 89 if ( $image_tag_processor->next_tag( 90 array( 91 'tag_name' => 'figure', 92 'id' => $unique_id, 93 ) 94 ) ) { 95 // The ID is only used to ensure that the correct figure tag is selected, 96 // and can now be removed. 97 $image_tag_processor->remove_attribute( 'id' ); 81 98 if ( $image_tag_processor->next_tag( 82 99 array( 83 'tag_name' => 'figure',84 ' id' => $unique_id,100 'tag_name' => 'img', 101 'class_name' => 'wp-block-media-text__featured_image', 85 102 ) 86 103 ) ) { 87 // The ID is only used to ensure that the correct figure tag is selected, 88 // and can now be removed. 89 $image_tag_processor->remove_attribute( 'id' ); 90 if ( $image_tag_processor->next_tag( 91 array( 92 'tag_name' => 'img', 93 'class_name' => 'wp-block-media-text__featured_image', 94 ) 95 ) ) { 96 $image_tag_processor->set_attribute( 'src', esc_url( $current_featured_image ) ); 97 $image_tag_processor->set_attribute( 'class', 'wp-image-' . get_post_thumbnail_id() . ' size-' . $media_size_slug ); 98 $image_tag_processor->set_attribute( 'alt', trim( strip_tags( get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ) ) ) ); 104 $image_tag_processor->set_attribute( 'src', esc_url( $current_featured_image ) ); 105 $image_tag_processor->set_attribute( 'class', 'wp-image-' . get_post_thumbnail_id() . ' size-' . $media_size_slug ); 106 $image_tag_processor->set_attribute( 'alt', trim( strip_tags( get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ) ) ) ); 107 if ( $image_fill ) { 108 $image_tag_processor->set_attribute( 'style', 'object-position:' . $focal_point . ';' ); 109 } 99 110 100 $content = $image_tag_processor->get_updated_html(); 101 } 111 $content = $image_tag_processor->get_updated_html(); 102 112 } 103 113 }
Note: See TracChangeset
for help on using the changeset viewer.