[wp-trac] [WordPress Trac] #33878: New function: `get_attachment_image_url()`

WordPress Trac noreply at wordpress.org
Sun Nov 1 00:52:00 UTC 2015


#33878: New function: `get_attachment_image_url()`
------------------------------+-----------------------------
 Reporter:  sebastian.pisula  |       Owner:  wonderboymusic
     Type:  enhancement       |      Status:  reopened
 Priority:  normal            |   Milestone:  4.4
Component:  Media             |     Version:
 Severity:  minor             |  Resolution:
 Keywords:  has-patch         |     Focuses:
------------------------------+-----------------------------

Comment (by Frank Klein):

 I see three main reasons for introducing the function:
 1. '''Developer happiness.''' I don't know how often I've read or written
 similar code to that in `wp_get_attachment_image_url()`. So instead of
 jumping through those hoops, just calling a function for getting the URL
 is nice.
 2. '''More clarity.''' You are calling `wp_get_attachment_image_src()`,
 and then take the first element out of the returned array, which is the
 URL. If you use the second and third element, you get sizes. The last
 argument contains a boolean. That is pretty weird, I personally find the
 way that the function returns data very inelegant.
 `wp_get_attachment_image_url()` clearly states what you get, making code
 more readable.
 3. '''Ease of use.''' It's pretty impossible to know what the array
 returned by `wp_get_attachment_image_src()` contains without reading the
 documentation. It's also not super easy to know that you should use this
 function to retrieve an attachment URL, because what exactly does "source"
 mean? The new function is a lot more straightforward.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33878#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list