From 5e21330e7da44c3eee54749e203b6365323ba5a3 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Mon, 4 Sep 2023 16:33:17 +0000 Subject: [PATCH] Widgets: Improve performance of has_content method in WP_Widget_Media_Gallery class. In the method `WP_Widget_Media_Gallery::has_content` call `_prime_post_caches` before the foreach loop. This ensures that the post objects are primed in memory before trying to access the post object in `get_post_type`. Props niravsherasiya7707, spacedmonkey, mukesh27. Fixes #58757. Built from https://develop.svn.wordpress.org/trunk@56512 git-svn-id: http://core.svn.wordpress.org/trunk@56024 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/widgets/class-wp-widget-media-gallery.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index 7c58d52fad..21232c649e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56511'; +$wp_version = '6.4-alpha-56512'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets/class-wp-widget-media-gallery.php b/wp-includes/widgets/class-wp-widget-media-gallery.php index 40cc5c2ba4..ecc446c221 100644 --- a/wp-includes/widgets/class-wp-widget-media-gallery.php +++ b/wp-includes/widgets/class-wp-widget-media-gallery.php @@ -248,6 +248,8 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media { protected function has_content( $instance ) { if ( ! empty( $instance['ids'] ) ) { $attachments = wp_parse_id_list( $instance['ids'] ); + // Prime attachment post caches. + _prime_post_caches( $attachments, false, false ); foreach ( $attachments as $attachment ) { if ( 'attachment' !== get_post_type( $attachment ) ) { return false;