Commit 04ef63aedc for wordpress.org
commit 04ef63aedc96745c5601c5b8fbcba37e5374cc59
Author: SergeyBiryukov <sergeybiryukov@git.wordpress.org>
Date: Tue Sep 22 23:45:45 2026 +0000
Rewrite Rules: Avoid repeated `page_on_front` lookups in `WP_Rewrite`.
The `get_option( 'page_on_front' )` value is constant for the duration of the call. Resolving it once before the loop avoids the overhead of extra function calls and filter applications.
Developed in https://github.com/WordPress/wordpress-develop/pull/13624.
Follow-up to r11419.
Props mukesh27.
Fixes #66147.
Built from https://develop.svn.wordpress.org/trunk@63884
git-svn-id: http://core.svn.wordpress.org/trunk@63056 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/class-wp-rewrite.php b/wp-includes/class-wp-rewrite.php
index 8b75fa5c36..a33604d3d0 100644
--- a/wp-includes/class-wp-rewrite.php
+++ b/wp-includes/class-wp-rewrite.php
@@ -951,6 +951,9 @@ class WP_Rewrite {
// Strip slashes from the front of $front.
$front = preg_replace( '|^/+|', '', $front );
+ // Read the front page ID.
+ $page_on_front = get_option( 'page_on_front' );
+
// The main workhorse loop.
$post_rewrite = array();
$struct = $front;
@@ -991,10 +994,10 @@ class WP_Rewrite {
$commentmatch = $match . $commentregex;
$commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index( $num_toks + 1 );
- if ( get_option( 'page_on_front' ) ) {
+ if ( $page_on_front ) {
// Create query for Root /comment-page-xx.
$rootcommentmatch = $match . $commentregex;
- $rootcommentquery = $index . '?' . $query . '&page_id=' . get_option( 'page_on_front' ) . '&cpage=' . $this->preg_index( $num_toks + 1 );
+ $rootcommentquery = $index . '?' . $query . '&page_id=' . $page_on_front . '&cpage=' . $this->preg_index( $num_toks + 1 );
}
// Create query for /feed/(feed|atom|rss|rss2|rdf).
@@ -1035,7 +1038,7 @@ class WP_Rewrite {
// Only on pages with comments add ../comment-page-xx/.
if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) {
$rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) );
- } elseif ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) {
+ } elseif ( EP_ROOT & $ep_mask && $page_on_front ) {
$rewrite = array_merge( $rewrite, array( $rootcommentmatch => $rootcommentquery ) );
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index f9eadd9341..9a4cf7e8eb 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63883';
+$wp_version = '7.2-alpha-63884';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.