From fadb4e1ea3d47e6cc2ea4c3bccc8e33220e22806 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 12 Apr 2022 05:18:08 +0000 Subject: [PATCH] Media: Run the `wp_content_img_tag` filter once per image. Prevent multiple identical `img` tags in a block of content causing the `wp_content_img_tag` filter to fire multiple times for that image. Follow up to [53028]. Props superpoincare, flixos90, pbearne, peterwilsoncc. Fixes #55510. See #55347. Built from https://develop.svn.wordpress.org/trunk@53149 git-svn-id: http://core.svn.wordpress.org/trunk@52738 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 12 ++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 260db26cac..2b46167afc 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1857,6 +1857,12 @@ function wp_filter_content_tags( $content, $context = null ) { if ( $filtered_image !== $match[0] ) { $content = str_replace( $match[0], $filtered_image, $content ); } + + /* + * Unset image lookup to not run the same logic again unnecessarily if the same image tag is used more than + * once in the same blob of content. + */ + unset( $images[ $match[0] ] ); } // Filter an iframe match. @@ -1871,6 +1877,12 @@ function wp_filter_content_tags( $content, $context = null ) { if ( $filtered_iframe !== $match[0] ) { $content = str_replace( $match[0], $filtered_iframe, $content ); } + + /* + * Unset iframe lookup to not run the same logic again unnecessarily if the same iframe tag is used more + * than once in the same blob of content. + */ + unset( $iframes[ $match[0] ] ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 2caf2499c6..a1c93a42b5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-53148'; +$wp_version = '6.0-alpha-53149'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.