Make WordPress Core

Changeset 56512


Ignore:
Timestamp:
09/04/2023 04:31:30 PM (12 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-media-gallery.php

    r47055 r56512  
    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 ) ) {
Note: See TracChangeset for help on using the changeset viewer.