[wp-trac] [WordPress Trac] #14110: Expose height and width attributes to 'wp_get_attachment_image_attributes' filter
WordPress Trac
noreply at wordpress.org
Mon Jun 23 10:04:40 UTC 2025
#14110: Expose height and width attributes to 'wp_get_attachment_image_attributes'
filter
---------------------------------------------+-----------------------------
Reporter: divinenephron | Owner:
| adamsilverstein
Type: enhancement | Status: reopened
Priority: normal | Milestone: 6.8.2
Component: Media | Version: 3.0
Severity: minor | Resolution:
Keywords: has-patch commit has-unit-tests | Focuses:
---------------------------------------------+-----------------------------
Comment (by sandeepdahiya):
Replying to [comment:46 SirLouen]:
> Test info, in this case, are the steps of the protocol you used to test
this. In this case, for example, posting the code you used in `Image
Attributes Debugger` (with a GB repo, or directly here)
I created a short custom plugin to test the attributes passed to the
filter. Just replace the image_id (in third last line) in the shortcode
with the actual image id and add the shortcode to a post/page to check the
results.
{{{
<?php
/**
* Plugin Name: Image Attributes Debugger
* Description: Prints the attributes passed into the
wp_get_attachment_image_attributes filter in the browser.
* Version: 1.0
* Author: Sandeep Dahiya
*/
add_filter( 'wp_get_attachment_image_attributes',
'my_debug_image_attributes', 10, 2 );
function my_debug_image_attributes( $attr, $attachment ) {
// check if the user has the capability to manage options
if ( current_user_can ( 'manage_options' ) && is_admin() === false ) {
// print the attributes in a preformatted block
echo '<pre style="background: #eee; padding: 10px; border: 1px
solid #ccc; ">';
echo 'Image attributes passed to the filter: ' . "\n";
print_r($attr);
echo '</pre>';
}
return $attr;
}
add_shortcode( 'my_test_image', 'my_test_image_shortcode' );
function my_test_image_shortcode() {
$image_id = 7;
return wp_get_attachment_image( $image_id, 'medium' );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/14110#comment:47>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list