Changeset 53377 for trunk/src/wp-includes/blocks/cover.php
- Timestamp:
- 05/10/2022 02:47:10 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/cover.php
r53329 r53377 15 15 */ 16 16 function render_block_core_cover( $attributes, $content ) { 17 if ( false === $attributes['useFeaturedImage'] ) {17 if ( 'image' !== $attributes['backgroundType'] || false === $attributes['useFeaturedImage'] ) { 18 18 return $content; 19 19 } 20 20 21 $current_featured_image = get_the_post_thumbnail_url(); 21 if ( ! ( $attributes['hasParallax'] || $attributes['isRepeated'] ) ) { 22 $attr = array( 23 'class' => 'wp-block-cover__image-background', 24 'data-object-fit' => 'cover', 25 ); 22 26 23 if ( false === $current_featured_image ) {24 return $content;25 }26 27 $is_img_element = ! ( $attributes['hasParallax'] || $attributes['isRepeated'] );28 $is_image_background = 'image' === $attributes['backgroundType'];29 30 if ( $is_image_background && ! $is_img_element ) {31 $content = preg_replace(32 '/class=\".*?\"/',33 '${0} style="background-image:url(' . esc_url( $current_featured_image ) . ')"',34 $content,35 136 );37 }38 39 if ( $is_image_background && $is_img_element ) {40 $object_position = '';41 27 if ( isset( $attributes['focalPoint'] ) ) { 42 $object_position = round( $attributes['focalPoint']['x'] * 100 ) . '%' . ' ' . 43 round( $attributes['focalPoint']['y'] * 100 ) . '%'; 28 $object_position = round( $attributes['focalPoint']['x'] * 100 ) . '%' . ' ' . round( $attributes['focalPoint']['y'] * 100 ) . '%'; 29 $attr['data-object-position'] = $object_position; 30 $attr['style'] = 'object-position: ' . $object_position; 44 31 } 45 32 46 $image_template = '<img 47 class="wp-block-cover__image-background" 48 alt="%s" 49 src="%s" 50 style="object-position: %s" 51 data-object-fit="cover" 52 data-object-position="%s" 53 />'; 54 55 $image = sprintf( 56 $image_template, 57 esc_attr( get_the_post_thumbnail_caption() ), 58 esc_url( $current_featured_image ), 59 esc_attr( $object_position ), 60 esc_attr( $object_position ) 61 ); 33 $image = get_the_post_thumbnail( null, 'post-thumbnail', $attr ); 62 34 63 35 $content = str_replace( … … 67 39 ); 68 40 41 } else { 42 if ( in_the_loop() ) { 43 update_post_thumbnail_cache(); 44 } 45 $current_featured_image = get_the_post_thumbnail_url(); 46 $content = preg_replace( 47 '/class=\".*?\"/', 48 '${0} style="background-image:url(' . esc_url( $current_featured_image ) . ')"', 49 $content, 50 1 51 ); 69 52 } 70 53
Note: See TracChangeset
for help on using the changeset viewer.