From 4526ed3e71b8b8cf317d9821426780fccd64dd4a Mon Sep 17 00:00:00 2001 From: Ryan Geddert Date: Mon, 6 Jul 2026 15:41:13 -0700 Subject: [PATCH] perf: Do not perform unnecessary query in wp-embed --- src/wp-includes/class-wp-embed.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class-wp-embed.php b/src/wp-includes/class-wp-embed.php index bf13f187dfbe9..bd1d8d4dcda5b 100644 --- a/src/wp-includes/class-wp-embed.php +++ b/src/wp-includes/class-wp-embed.php @@ -251,7 +251,7 @@ public function shortcode( $attr, $url = '' ) { $cache = ''; $cache_time = 0; - $cached_post_id = $this->find_oembed_post_id( $key_suffix ); + $cached_post_id = 0; if ( $post_id ) { $cache = get_post_meta( $post_id, $cachekey, true ); @@ -260,11 +260,14 @@ public function shortcode( $attr, $url = '' ) { if ( ! $cache_time ) { $cache_time = 0; } - } elseif ( $cached_post_id ) { - $cached_post = get_post( $cached_post_id ); + } else { + $cached_post_id = $this->find_oembed_post_id( $key_suffix ); + if ( $cached_post_id ) { + $cached_post = get_post( $cached_post_id ); - $cache = $cached_post->post_content; - $cache_time = strtotime( $cached_post->post_modified_gmt ); + $cache = $cached_post->post_content; + $cache_time = strtotime( $cached_post->post_modified_gmt ); + } } $cached_recently = ( time() - $cache_time ) < $ttl;