Commit 5ed0dea06d for wordpress.org
commit 5ed0dea06d1f05d60d3bf4b04992b88777c3b398
Author: SergeyBiryukov <sergeybiryukov@git.wordpress.org>
Date: Sat Sep 19 09:39:48 2026 +0000
Feeds: Hoist option lookups out of `get_the_category_rss()` loop.
The `get_bloginfo_rss( 'url' )` and `get_option( 'blog_charset' )` values are constant for the duration of the call. Resolving them once before the loop leaves the emitted markup byte-for-byte identical while avoiding the overhead of extra function calls and filter applications. The saving scales with taxonomy-heavy posts and applies to every item in a feed response.
The values are computed only when there is at least one term to render, so posts with no categories or tags do no extra work.
Developed in https://github.com/WordPress/wordpress-develop/pull/13576.
Follow-up to r5548, r10688, r28258, r63757.
Props mukesh27, westonruter.
Fixes #66126.
Built from https://develop.svn.wordpress.org/trunk@63761
git-svn-id: http://core.svn.wordpress.org/trunk@62933 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/feed.php b/wp-includes/feed.php
index 453cc9063c..7f9988b29f 100644
--- a/wp-includes/feed.php
+++ b/wp-includes/feed.php
@@ -406,13 +406,24 @@ function get_the_category_rss( $type = null ) {
$cat_names = array_unique( $cat_names );
+ $atom_scheme = '';
+ $blog_charset = '';
+
+ if ( $cat_names ) {
+ if ( 'atom' === $type ) {
+ $atom_scheme = get_bloginfo_rss( 'url' );
+ } elseif ( 'rdf' !== $type ) {
+ $blog_charset = get_option( 'blog_charset' );
+ }
+ }
+
foreach ( $cat_names as $cat_name ) {
if ( 'rdf' === $type ) {
$the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
} elseif ( 'atom' === $type ) {
- $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) );
+ $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( $atom_scheme ), esc_attr( $cat_name ) );
} else {
- $the_list .= "\t\t<category><![CDATA[" . html_entity_decode( $cat_name, ENT_COMPAT, get_option( 'blog_charset' ) ) . "]]></category>\n";
+ $the_list .= "\t\t<category><![CDATA[" . html_entity_decode( $cat_name, ENT_COMPAT, $blog_charset ) . "]]></category>\n";
}
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index beeb1393ae..27b6e60dff 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63760';
+$wp_version = '7.2-alpha-63761';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.