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
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user