Make WordPress Core

Changeset 51601


Ignore:
Timestamp:
08/11/2021 01:00:46 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Themes: Make sure the theme API response is not an error before operating on it in themes_api().

This fixes a potential bug and avoids PHP warnings when themes_api( 'query_themes' ) is called and a successful API response is not received.

Follow-up to [42632].

Props pierlo.
Fixes #53913.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r51510 r51601  
    603603                }
    604604
    605                 // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects.
    606                 if ( 'query_themes' === $action ) {
    607                         foreach ( $res->themes as $i => $theme ) {
    608                                 $res->themes[ $i ] = (object) $theme;
     605                if ( ! is_wp_error( $res ) ) {
     606                        // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects.
     607                        if ( 'query_themes' === $action ) {
     608                                foreach ( $res->themes as $i => $theme ) {
     609                                        $res->themes[ $i ] = (object) $theme;
     610                                }
    609611                        }
    610                 }
    611                 // Back-compat for info/1.2 API, downgrade the feature_list result back to an array.
    612                 if ( 'feature_list' === $action ) {
    613                         $res = (array) $res;
     612
     613                        // Back-compat for info/1.2 API, downgrade the feature_list result back to an array.
     614                        if ( 'feature_list' === $action ) {
     615                                $res = (array) $res;
     616                        }
    614617                }
    615618        }
Note: See TracChangeset for help on using the changeset viewer.