[wp-trac] [WordPress Trac] #29443: wp_get_attachment_image 4st. parameter $attr should be reference &$attr
WordPress Trac
noreply at wordpress.org
Sun Aug 31 19:36:52 UTC 2014
#29443: wp_get_attachment_image 4st. parameter $attr should be reference &$attr
-------------------------+-------------------------------------------------
Reporter: | Owner:
heddesheimer | Status: new
Type: defect | Milestone: Awaiting Review
(bug) | Version: 3.9.2
Priority: normal | Keywords: media, thumbnail,
Component: Media | wp_get_attachment_image, attr
Severity: normal |
Focuses: |
-------------------------+-------------------------------------------------
When I tried to hook in to wp_get_attachment_image() in media.php to
override the html of the post_thumbnail, I found that the $attr variable
never passed any values to the hooked callback function.
This makes sense, as arrays are created as copies in PHP functions,
therefore the 4st. parameter must be &$attr instead of just $attr. When I
changes that in the function, my $attr values all gets passed fine to the
intercepting function that uses the hook.
To reproduce the problem:
add a filter like this to your plugin/theme:
add_filter( 'post_thumbnail_html', 'my_post_thumbnail_html', 10, 5 );
Then try to show the passed attributes in the callback function like this:
function my_post_thumbnail_html($html, $post_id, $post_thumbnail_id,
$size, $attr)
{
print_r($attr); exit;
}
You will see that nothing is displayed. When you change the 4st. parameter
of wp_get_attachment_image in wp-includes/media.php to &$attr, it will
show the attributes like this:
Array ( [src] => http://testing.local/wordpress296/wp-
content/uploads/2014/08/about-image.jpg [class] => attachment-450x300 wp-
post-image [alt] => alternative text )
which is the expected result for the filter.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29443>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list