Skip to content

Commit

Permalink
Widgets: Improve performance of has_content method in WP_Widget_Media…
Browse files Browse the repository at this point in the history
…_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
  • Loading branch information
spacedmonkey committed Sep 4, 2023
1 parent fa9f839 commit 6be588c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/wp-includes/widgets/class-wp-widget-media-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public function render_control_template_scripts() {
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;
Expand Down

0 comments on commit 6be588c

Please sign in to comment.