← All changes
|
build/scripts/block-library/post-featured-image.php
+23
-28
23.6.2
→
22.7.0
View file →
| @@ -39,31 +39,18 @@ | ||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $extra_styles = ''; |
| 43 | - $has_width = array_key_exists( 'width', $attributes ) && null !== $attributes['width'] && '' !== $attributes['width']; | |
| 44 | - $has_height = array_key_exists( 'height', $attributes ) && null !== $attributes['height'] && '' !== $attributes['height']; | |
| 45 | 43 | |
| 44 | + // Aspect ratio with a height set needs to override the default width/height. | |
| 46 | 45 | if ( ! empty( $attributes['aspectRatio'] ) ) { |
| 47 | - // If there's no non-default value set, let the image's width and height attributes determine its intrinsic aspect ratio. | |
| 48 | - if ( 'auto' !== $attributes['aspectRatio'] ) { | |
| 49 | - $extra_styles .= esc_attr( safecss_filter_attr( 'aspect-ratio:' . $attributes['aspectRatio'] ) ) . ';'; | |
| 50 | - } | |
| 51 | - $extra_styles .= 'width:100%;'; | |
| 46 | + $extra_styles .= 'width:100%;height:100%;'; | |
| 47 | + } elseif ( ! empty( $attributes['height'] ) ) { | |
| 48 | + $extra_styles .= "height:{$attributes['height']};"; | |
| 52 | 49 | } |
| 53 | 50 | |
| 54 | - if ( $has_height ) { | |
| 55 | - $extra_styles .= esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';'; | |
| 56 | - } elseif ( $has_width ) { | |
| 57 | - $extra_styles .= 'height:auto;'; | |
| 58 | - } | |
| 59 | - | |
| 60 | - if ( $has_width ) { | |
| 61 | - $extra_styles .= esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';'; | |
| 62 | - } | |
| 63 | - | |
| 64 | 51 | if ( ! empty( $attributes['scale'] ) ) { |
| 65 | - $extra_styles .= esc_attr( safecss_filter_attr( 'object-fit:' . $attributes['scale'] ) ) . ';'; | |
| 52 | + $extra_styles .= "object-fit:{$attributes['scale']};"; | |
| 66 | 53 | } |
| 67 | 54 | if ( ! empty( $attributes['style']['shadow'] ) ) { |
| 68 | 55 | $shadow_styles = gutenberg_style_engine_get_styles( array( 'shadow' => $attributes['style']['shadow'] ) ); |
| 69 | 56 | |
| @@ -102,15 +89,8 @@ | ||
| 102 | 89 | $tag_html->next_tag(); |
| 103 | 90 | foreach ( $processor->get_attribute_names_with_prefix( '' ) as $name ) { |
| 104 | 91 | $tag_html->set_attribute( $name, $processor->get_attribute( $name ) ); |
| 105 | 92 | } |
| 106 | - if ( ! empty( $attr['style'] ) ) { | |
| 107 | - $existing_style = $tag_html->get_attribute( 'style' ); | |
| 108 | - $style = is_string( $existing_style ) && '' !== $existing_style | |
| 109 | - ? rtrim( $existing_style, ';' ) . ';' . $attr['style'] | |
| 110 | - : $attr['style']; | |
| 111 | - $tag_html->set_attribute( 'style', $style ); | |
| 112 | - } | |
| 113 | 93 | $featured_image = $tag_html->get_updated_html(); |
| 114 | 94 | } |
| 115 | 95 | } |
| 116 | 96 | |
| @@ -120,13 +100,15 @@ | ||
| 120 | 100 | |
| 121 | 101 | if ( $is_link ) { |
| 122 | 102 | $link_target = $attributes['linkTarget']; |
| 123 | 103 | $rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : ''; |
| 104 | + $height = ! empty( $attributes['height'] ) ? 'style="' . esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . '"' : ''; | |
| 124 | 105 | $featured_image = sprintf( |
| 125 | - '<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>', | |
| 126 | - esc_url( get_the_permalink( $post_ID ) ), | |
| 106 | + '<a href="%1$s" target="%2$s" %3$s %4$s>%5$s%6$s</a>', | |
| 107 | + get_the_permalink( $post_ID ), | |
| 127 | 108 | esc_attr( $link_target ), |
| 128 | 109 | $rel, |
| 110 | + $height, | |
| 129 | 111 | $featured_image, |
| 130 | 112 | $overlay_markup |
| 131 | 113 | ); |
| 132 | 114 | } else { |
| @@ -132,9 +114,22 @@ | ||
| 132 | 114 | } else { |
| 133 | 115 | $featured_image = $featured_image . $overlay_markup; |
| 134 | 116 | } |
| 135 | 117 | |
| 136 | - $wrapper_attributes = get_block_wrapper_attributes(); | |
| 118 | + $aspect_ratio = ! empty( $attributes['aspectRatio'] ) | |
| 119 | + ? esc_attr( safecss_filter_attr( 'aspect-ratio:' . $attributes['aspectRatio'] ) ) . ';' | |
| 120 | + : ''; | |
| 121 | + $width = ! empty( $attributes['width'] ) | |
| 122 | + ? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';' | |
| 123 | + : ''; | |
| 124 | + $height = ! empty( $attributes['height'] ) | |
| 125 | + ? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';' | |
| 126 | + : ''; | |
| 127 | + if ( ! $height && ! $width && ! $aspect_ratio ) { | |
| 128 | + $wrapper_attributes = get_block_wrapper_attributes(); | |
| 129 | + } else { | |
| 130 | + $wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $aspect_ratio . $width . $height ) ); | |
| 131 | + } | |
| 137 | 132 | return "<figure {$wrapper_attributes}>{$featured_image}</figure>"; |
| 138 | 133 | } |
| 139 | 134 | |
| 140 | 135 | /** |