Make WordPress Core

Ticket #33878: 33878.diff

File 33878.diff, 2.0 KB (added by swissspidy, 10 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index a7db321..a090471 100644
    function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa 
    793793}
    794794
    795795/**
     796 * Get the URL of an image attachment.
     797 *
     798 * @since 4.4.0
     799 *
     800 * @param int          $attachment_id Image attachment ID.
     801 * @param string|array $size          Optional. Registered image size to retrieve the source for or a flat
     802 *                                    array of height and width dimensions. Default 'thumbnail'.
     803 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
     804 * @return string|false Attachment URL or false if no image is available.
     805 */
     806function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
     807        $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     808        return isset( $image['0'] ) ? $image['0'] : false;
     809}
     810
     811/**
    796812 * Adds a 'wp-post-image' class to post thumbnails. Internal use only.
    797813 *
    798814 * Uses the 'begin_fetch_post_thumbnail_html' and 'end_fetch_post_thumbnail_html' action hooks to
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 34f1281..cdfb6cb 100644
    EOF; 
    718718
    719719                remove_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
    720720        }
     721
     722        function test_wp_get_attachment_image_url() {
     723                $this->assertFalse( wp_get_attachment_image_url( 0 ) );
     724
     725                $post_id = $this->factory->post->create();
     726                $attachment_id = $this->factory->attachment->create_object( $this->img_name, $post_id, array(
     727                        'post_mime_type' => 'image/jpeg',
     728                        'post_type' => 'attachment',
     729                ) );
     730
     731                $image = wp_get_attachment_image_src( $attachment_id, 'thumbnail', false );
     732
     733                $this->assertEquals( $image[0], wp_get_attachment_image_url( $attachment_id ) );
     734        }
    721735}