Making WordPress.org


Ignore:
Timestamp:
07/03/2023 06:13:56 PM (22 months ago)
Author:
coffee2code
Message:

Photo Directory: Show formatted filesize for each image size in the download dropdown.

Props nayanchamp7, coffee2code.
Fixes #7042.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-photos/template-parts/photo-single.php

    r12544 r12686  
    1111use WordPressdotorg\Photo_Directory\Template_Tags;
    1212
     13$photo_id = get_post_thumbnail_id();
    1314?>
    1415
     
    3233                    'full'         => [ 'label' => __( 'Original Size %s', 'wporg-photos' ) ],
    3334                ];
     35
     36                $photo_meta = wp_get_attachment_metadata( $photo_id );
    3437                foreach ( array_keys( $photo_sizes ) as $size ) {
    35                     $src = wp_get_attachment_image_src( get_post_thumbnail_id(), $size );
     38                    $src = wp_get_attachment_image_src( $photo_id, $size );
     39                    if ( 'full' === $size ) {
     40                        $filesize = $photo_meta['filesize'] ?? '';
     41                    } else {
     42                        $filesize = $photo_meta['sizes'][ $size ]['filesize'] ?? '';
     43                    }
    3644                    $photo_sizes[ $size ] = array_merge( $photo_sizes[ $size ], [
    37                         'width'  => $src[ 1 ],
    38                         'height' => $src[ 2 ],
    39                         'url'    => $src[ 0 ],
     45                        'filesize' => size_format( $filesize ),
     46                        'width'    => $src[ 1 ],
     47                        'height'   => $src[ 2 ],
     48                        'url'      => $src[ 0 ],
    4049                    ] );
    4150                }
     
    4554                    foreach ( $photo_sizes as $size => $info ) {
    4655                        printf(
    47                             '<li><a href="%s" rel="nofollow" download target="_blank">%s</a></li>',
    48                             $info[ 'url' ],
    49                             sprintf( $info[ 'label' ], sprintf( '<span class="photo-dimensions">(%s&times;%s)</span>', $info['width'], $info['height'] ) )
     56                            '<li><a href="%s" rel="nofollow" download target="_blank">%s<span class="photo-filesize">%s</span></a></li>',
     57                            esc_url( $info[ 'url' ] ),
     58                            sprintf( $info[ 'label' ], sprintf( '<span class="photo-dimensions">(%s&times;%s)</span>', $info['width'], $info['height'] ) ),
     59                            $info['filesize']
    5060                        );
    5161                    }
     
    5868        <?php $alt_text = get_the_content(); ?>
    5969
    60         <a href="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>">
     70        <a href="<?php echo wp_get_attachment_url( $photo_id ); ?>">
    6171            <?php
    6272            printf(
    6373                '<img class="single-photo" src="%s" srcset="%s" alt="%s">',
    6474                esc_url( get_the_post_thumbnail_url( get_the_ID(), 'medium') ),
    65                 esc_attr( wp_get_attachment_image_srcset( get_post_thumbnail_id() ) ),
     75                esc_attr( wp_get_attachment_image_srcset( $photo_id ) ),
    6676                sprintf(
    6777                    /* translators: %s: The alternative text for the photo. */
Note: See TracChangeset for help on using the changeset viewer.