From 07e6dc15298a03b910ee29af44870eee83856e7f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 6 Mar 2026 18:03:36 +0000 Subject: [PATCH] REST API: Optimize themes collection response when querying active theme. This updates `WP_REST_Themes_Controller::get_items()` to shortcut returning the current theme when the request explicitly queries for the active theme, avoiding expensive call to `wp_get_themes()`. Developed in https://github.com/WordPress/wordpress-develop/pull/11032 Follow up to r49925. Props aduth, mukesh27, westonruter. See #50152. Fixes #64719. Built from https://develop.svn.wordpress.org/trunk@61856 git-svn-id: http://core.svn.wordpress.org/trunk@61143 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-themes-controller.php | 20 +++++++++++-------- wp-includes/version.php | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 94b3e5c264..472e8dc12c 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -197,18 +197,22 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { public function get_items( $request ) { $themes = array(); - $active_themes = wp_get_themes(); $current_theme = wp_get_theme(); $status = $request['status']; - foreach ( $active_themes as $theme ) { - $theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive'; - if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) { - continue; - } - - $prepared = $this->prepare_item_for_response( $theme, $request ); + if ( array( 'active' ) === $status ) { + $prepared = $this->prepare_item_for_response( $current_theme, $request ); $themes[] = $this->prepare_response_for_collection( $prepared ); + } else { + foreach ( wp_get_themes() as $theme ) { + $theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive'; + if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) { + continue; + } + + $prepared = $this->prepare_item_for_response( $theme, $request ); + $themes[] = $this->prepare_response_for_collection( $prepared ); + } } $response = rest_ensure_response( $themes ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 50b07fe05b..a9fc3cf5d6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '7.0-beta3-61855'; +$wp_version = '7.0-beta3-61856'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.