Make WordPress Core


Ignore:
Timestamp:
03/06/2026 06:02:38 PM (3 months ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php

    r61429 r61856  
    198198        $themes = array();
    199199
    200         $active_themes = wp_get_themes();
    201200        $current_theme = wp_get_theme();
    202201        $status        = $request['status'];
    203202
    204         foreach ( $active_themes as $theme ) {
    205             $theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive';
    206             if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) {
    207                 continue;
    208             }
    209 
    210             $prepared = $this->prepare_item_for_response( $theme, $request );
     203        if ( array( 'active' ) === $status ) {
     204            $prepared = $this->prepare_item_for_response( $current_theme, $request );
    211205            $themes[] = $this->prepare_response_for_collection( $prepared );
     206        } else {
     207            foreach ( wp_get_themes() as $theme ) {
     208                $theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive';
     209                if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) {
     210                    continue;
     211                }
     212
     213                $prepared = $this->prepare_item_for_response( $theme, $request );
     214                $themes[] = $this->prepare_response_for_collection( $prepared );
     215            }
    212216        }
    213217
Note: See TracChangeset for help on using the changeset viewer.