From 153d07b93a903acd4e661165619ecb5da533738d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 22 Aug 2020 01:52:42 +0000 Subject: [PATCH] REST API: In `WP_REST_Block_Directory_Controller::get_items()`, make sure the blocks data for a plugin is not empty before proceeding. This avoids a PHP notice if the API returns a plugin with empty data for `blocks` key. Props khag7, TwentyZeroTwo, justinahinon, TimothyBlynJacobs, dd32, SergeyBiryukov. Fixes #51018. git-svn-id: https://develop.svn.wordpress.org/trunk@48842 602fd350-edb4-49c9-b593-d223f7449a82 --- .../endpoints/class-wp-rest-block-directory-controller.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php index c2069b21bc..089a5215ba 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php @@ -95,6 +95,11 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller { $result = array(); foreach ( $response->plugins as $plugin ) { + // If the API returned a plugin with empty data for 'blocks', skip it. + if ( empty( $plugin['blocks'] ) ) { + continue; + } + $data = $this->prepare_item_for_response( $plugin, $request ); $result[] = $this->prepare_response_for_collection( $data ); }