[wp-trac] [WordPress Trac] #30180: wp_get_attachment_image_src does not return alt or meta

WordPress Trac noreply at wordpress.org
Wed Dec 12 05:32:27 UTC 2018


#30180: wp_get_attachment_image_src does not return alt or meta
--------------------------------------+-----------------------------
 Reporter:  joedolson                 |       Owner:  joedolson
     Type:  enhancement               |      Status:  accepted
 Priority:  normal                    |   Milestone:  Future Release
Component:  Media                     |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  accessibility
--------------------------------------+-----------------------------

Comment (by ryanshoover):

 @birgire Providing responses to your comments below one-by-one.

 > The patch uses shorthand array notation [] that's only supported in PHP
 5.4+.
 Fixed!

 > The concatenation in the PHP code example uses the Javascript plus +
 instead of the dot ., i.e. $alt = $alt + ' Extra content';
 Fixed!

 > Shouldn't we use null type in the @return as null is a primitive type in
 PHPDoc?
 Fixed!

 > The patch does not contain all the changes made in the patch
 30180.1.diff​. Is there a reason for that?
 Not particularly. The unit test patch contained only the code necessary
 for the new tests to pass. I've included both the new code and the new
 tests in a single patch this time.

 > @joemcgill suggested above the function name
 wp_get_attachment_image_attributes() but the patch uses
 wp_get_attachment_image_attr() and same for the filter.
 Discussed this with @bamadesigner at WCUS18 contributor day. My opinion is
 that `wp_get_attachment_image_attr()` is more inline with the other
 function names that use the abbreviated verbiage for the values they
 retrieve. i.e. `wp_get_attachment_image_src()` and
 `wp_get_attachment_image_srcset()`. But if you feel the function should
 spell out `attributes` I'm happy to make that change.

 > @joemcgill mentioned above that the wp_get_attachement_image() could be
 a wrapper for wp_get_attachment_image_attributes(), but I didn't see that
 in the patch.
 Good call. I've reworked `wp_get_attachment_image` to simply piece
 together the attributes from the new function rather than generating them
 itself.

 > It would be nice to have test cases for all the supported nine
 attributes. Maybe there's a way to use a @dataProvider?
 Good idea! I've added tests for the other attributes using an image stored
 in the `tests/phpunit/data/images` directory. Is there a better practice I
 should follow to provide a real file to the factory?

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


More information about the wp-trac mailing list