Make WordPress Core


Ignore:
Timestamp:
09/22/2015 04:12:44 AM (9 years ago)
Author:
wonderboymusic
Message:

Media: Add a new function, wp_get_attachment_image_url(), which is a shortcut for wp_get_attachment_image_src() - same function signature, but returns just the URL based on $size.

Adds unit test.

Props dipesh.kakadiya, swissspidy, sebastian.pisula.
Fixes #33878.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r34362 r34372  
    792792
    793793    return $html;
     794}
     795
     796/**
     797 * Get the URL of an image attachment.
     798 *
     799 * @since 4.4.0
     800 *
     801 * @param int          $attachment_id Image attachment ID.
     802 * @param string|array $size          Optional. Registered image size to retrieve the source for or a flat
     803 *                                    array of height and width dimensions. Default 'thumbnail'.
     804 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
     805 * @return string|false Attachment URL or false if no image is available.
     806 */
     807function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
     808    $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     809    return isset( $image['0'] ) ? $image['0'] : false;
    794810}
    795811
Note: See TracChangeset for help on using the changeset viewer.