Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#56295 new defect (bug)

filter wp_content_img_tag runs multiple times

Reported by: gigito78's profile gigito78 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.0
Component: Media Keywords: needs-testing-info
Focuses: Cc:

Description

Filter wp_content_img_tag seem (in a block theme) seem to run 3 times on content images and 2 times on custom logo image. Simple code to expose the problem:

add_filter( $hook_name='wp_content_img_tag', function( $filtered_image, $context, $attachment_id ){ return 'a:'.$filtered_image; },$priority=21, $accepted_args=3 );

Change History (4)

#1 @ocean90
2 years ago

  • Component changed from General to Media
  • Focuses coding-standards removed

Hello @gigito78, welcome to WordPress Trac!

I haven't verified this yet, but this seems to be related to #55996.

This ticket was mentioned in Slack in #core-test by ironprogrammer. View the logs.


2 years ago

#3 follow-up: @ironprogrammer
2 years ago

  • Keywords needs-testing-info added

Welcome to Trac, and thank you for the report, @gigito78!

Would you be able to include test instructions on where/how the filter is applied, and how it quantifies/proves the repeated calls to wp_content_img_tag? This will help other contributors reproduce the issue condition.

#4 in reply to: ↑ 3 @gigito78
2 years ago

Hello @ironprogrammer!

Tried to setup a site to help you to reproduce the problem:

  1. https://www.gigitopcinformatica.it/test4/hello-world/

theme active: wordpress twenty-twentytwo, inserted in function.php the code:

add_filter( $hook_name='wp_content_img_tag', function( $filtered_image, $context, $attachment_id ){ 	
	
$timestamp_mediapost = get_post_modified_time( $format='U', $gmt=true, $post=$attachment_id, $translate=false );	
$filtered_image = str_replace( $search='.webp', $replace='.webp?='.$timestamp_mediapost, $subject=$filtered_image, $count);
echo $count.'-';
	
return $filtered_image; },$priority=21, $accepted_args=3 );

Objective: add query strings to webp files. Please use console to look at filtered images code ad look to the top the echoed $count parameter. Seem that the order is: custom logo image, then content image, then custom logo image again, the, content image again.

Note: See TracTickets for help on using tickets.