From 9eefc4b0d96a3b89aa6944c16d218a8aa445fab8 Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Tue, 23 Jun 2020 23:32:14 +0000 Subject: [PATCH] Cache API: Cache the results of `get_uploaded_header_images()`. Fixes #49446. Props pbiron, SergeyBiryukov, desrosj. git-svn-id: https://develop.svn.wordpress.org/trunk@48152 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/template.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 9ee8e557f6..1017e41417 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -2200,6 +2200,8 @@ function get_post_states( $post ) { * @return string Media states string. */ function _media_states( $post ) { + static $header_images; + $media_states = array(); $stylesheet = get_option( 'stylesheet' ); @@ -2207,7 +2209,9 @@ function _media_states( $post ) { $meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true ); if ( is_random_header_image() ) { - $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' ); + if ( ! isset( $header_images ) ) { + $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' ); + } if ( $meta_header === $stylesheet && in_array( $post->ID, $header_images, true ) ) { $media_states[] = __( 'Header Image' );