WordPress.org

Make WordPress Core

Ticket #33959: 33959.diff

File 33959.diff, 2.4 KB (added by Rahe, 6 years ago)
  • src/wp-includes/post-functions.php

    diff --git i/src/wp-includes/post-functions.php w/src/wp-includes/post-functions.php
    index 3338447..58fe5f9 100644
    i w function wp_get_attachment_url( $post_id = 0 ) { 
    48574857 * Retrieve thumbnail for an attachment.
    48584858 *
    48594859 * @since 2.1.0
     4860 * @since 4.4.0 `$post` can be a post ID or WP_Post object. `$size` is a parameter.
     4861 * @since 4.4.0 `$size` is an optional parameter, allow to specify the attachment thumbnail.
    48604862 *
    4861  * @param int $post_id Optional. Attachment ID. Default 0.
    4862  * @return string|false False on failure. Thumbnail file path on success.
     4863 * @param null|int|WP_Post $post Optional. Attachment ID or WP_Post object. Default null.
     4864 * @param string $size Optional. Attachment size. Default thumb.
     4865 *
     4866 * @return false|string False on failure. Thumbnail file path on success.
    48634867 */
    4864 function wp_get_attachment_thumb_file( $post_id = 0 ) {
    4865         $post_id = (int) $post_id;
    4866         if ( !$post = get_post( $post_id ) )
     4868function wp_get_attachment_thumb_file( $post = null, $size = 'thumb' ) {
     4869        $post = get_post( $post );
     4870        if ( ! $post ) {
    48674871                return false;
    4868         if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) )
     4872        }
     4873
     4874        $image_data = wp_get_attachment_metadata( $post->ID );
     4875        if ( ! is_array( $image_data ) ) {
    48694876                return false;
     4877        }
    48704878
    48714879        $file = get_attached_file( $post->ID );
     4880        $thumb_file = '';
    48724881
    4873         if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) {
     4882        if( 'thumb' === $size ) {
     4883                $thumb_file = ! empty( $image_data['thumb'] ) ? str_replace( basename( $file ), $image_data['thumb'], $file ) : '';
     4884        } elseif( isset( $image_data['sizes'][$size] ) ) {
     4885                $thumb_file = str_replace( basename( $file ), $image_data['sizes'][$size]['file'], $file );
     4886        }
     4887
     4888        if ( ! empty( $thumb_file ) && file_exists( $thumb_file ) ) {
    48744889                /**
    48754890                 * Filter the attachment thumbnail file path.
    48764891                 *
    48774892                 * @since 2.1.0
     4893                 * @since 4.4.0 `$size` the specified size.
    48784894                 *
    4879                  * @param string $thumbfile File path to the attachment thumbnail.
     4895                 * @param string $thumb_file File path to the attachment thumbnail.
    48804896                 * @param int    $post_id   Attachment ID.
     4897                 * @param string $size   Attachment size.
    48814898                 */
    4882                 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     4899                return apply_filters( 'wp_get_attachment_thumb_file', $thumb_file, $post->ID, $size );
    48834900        }
     4901
    48844902        return false;
    48854903}
    48864904