Skip to content

Commit 6be588c

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@56512 602fd350-edb4-49c9-b593-d223f7449a82
1 parent fa9f839 commit 6be588c

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/wp-includes/widgets/class-wp-widget-media-gallery.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ public function render_control_template_scripts() {
248248
protected function has_content( $instance ) {
249249
if ( ! empty( $instance['ids'] ) ) {
250250
$attachments = wp_parse_id_list( $instance['ids'] );
251+
// Prime attachment post caches.
252+
_prime_post_caches( $attachments, false, false );
251253
foreach ( $attachments as $attachment ) {
252254
if ( 'attachment' !== get_post_type( $attachment ) ) {
253255
return false;

0 commit comments

Comments
 (0)