Make WordPress Core

Ticket #45985: 45985-all-images.patch

File 45985-all-images.patch, 1.9 KB (added by kjellr, 4 years ago)
  • src/wp-content/themes/twentynineteen/inc/template-functions.php

     
    132132add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
    133133
    134134/**
     135 * Add custom sizes attribute to responsive image functionality for post content images.
     136 *
     137 * @origin Twenty Nineteen 1.0
     138 *
     139 * @param string       $sizes         A source size value for use in a 'sizes' attribute.
     140 * @param array|string $size          Requested size. Image size or array of width and height values
     141 *                                    in pixels (in that order).
     142 * @param string|null  $image_src     The URL to the image file or null.
     143 * @param array|null   $image_meta    The image meta data as returned by wp_get_attachment_metadata() or null.
     144 * @param int          $attachment_id Image attachment ID of the original image or 0.
     145 * @param array        $block_attr    Attributes from the parent block.
     146 */
     147function twentynineteen_calculate_image_sizes_attr( $sizes, $size, $image_src, $image_meta, $attachment_id, $block_attr ) {
     148        if ( is_admin() ) {
     149                return $sizes;
     150        }
     151
     152        $align = $block_attr[align];
     153        if ( '' === $align ) {
     154                $sizes = '(min-width: 768px) calc(8 * (100vw / 12) - 28px), (min-width: 1168) calc(6 * 100vw/12) - 28px), calc(100% - (2 * 1rem))';
     155        } elseif ( 'wide' === $align ) {
     156                $sizes = '(min-width: 768px) 80%, calc(100% - (2 * 1rem))';
     157        } elseif ( 'full' === $align ) {
     158                $sizes = '100vw';
     159        }
     160        return $sizes;
     161}
     162add_filter( 'wp_calculate_image_sizes', 'twentynineteen_calculate_image_sizes_attr', 10, 6 );
     163
     164/**
    135165 * Returns the size for avatars used in the theme.
    136166 */
    137167function twentynineteen_get_avatar_size() {