From b29101aca055d24abbabf3bd9b6e6e0f2e12f0dc Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Tue, 28 Jul 2020 04:08:56 +0000 Subject: [PATCH] REST API: Remove assets field from block directory controller. Gutenberg no longer uses the assets field to fetch the assets for the installed block so this field can be dropped from the endpoint. This allows us to reintroduce it at a later point without needing to worry about backward compatibility. See #50732. git-svn-id: https://develop.svn.wordpress.org/trunk@48656 602fd350-edb4-49c9-b593-d223f7449a82 --- ...ass-wp-rest-block-directory-controller.php | 26 ------------------- .../rest-block-directory-controller.php | 9 +------ 2 files changed, 1 insertion(+), 34 deletions(-) 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 bc81da184a..4dc0f17fbe 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 @@ -129,7 +129,6 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller { 'author_block_count' => intval( $plugin['author_block_count'] ), 'author' => wp_strip_all_tags( $plugin['author'] ), 'icon' => ( isset( $plugin['icons']['1x'] ) ? $plugin['icons']['1x'] : 'block-default' ), - 'assets' => array(), 'last_updated' => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ), 'humanized_updated' => sprintf( /* translators: %s: Human-readable time difference. */ @@ -138,21 +137,6 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller { ), ); - foreach ( $plugin['block_assets'] as $asset ) { - // Allow for fully qualified URLs in future - if ( 'https' === wp_parse_url( $asset, PHP_URL_SCHEME ) && ! empty( wp_parse_url( $asset, PHP_URL_HOST ) ) ) { - $block['assets'][] = esc_url_raw( - $asset, - array( 'https' ) - ); - } else { - $block['assets'][] = esc_url_raw( - add_query_arg( 'v', strtotime( $block['last_updated'] ), 'https://ps.w.org/' . $plugin['slug'] . $asset ), - array( 'https' ) - ); - } - } - $this->add_additional_fields_to_object( $block, $request ); $response = new WP_REST_Response( $block ); @@ -296,16 +280,6 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller { 'type' => 'string', 'context' => array( 'view' ), ), - 'assets' => array( - 'description' => __( 'An object representing the block CSS and JavaScript assets.' ), - 'type' => 'array', - 'context' => array( 'view' ), - 'readonly' => true, - 'items' => array( - 'type' => 'string', - 'format' => 'uri', - ), - ), ), ); diff --git a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php index cfbfff4374..ee8d21aa89 100644 --- a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php @@ -162,12 +162,6 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te 'author_block_count' => 1, 'author' => 'sorta brilliant', 'icon' => 'https://ps.w.org/guidepost/assets/icon-128x128.jpg?rev=2235512', - 'assets' => array( - 'https://ps.w.org/guidepost/tags/1.2.1/build/index.js?v=1584940380', - 'https://ps.w.org/guidepost/tags/1.2.1/build/guidepost-editor.css?v=1584940380', - 'https://ps.w.org/guidepost/tags/1.2.1/build/guidepost-style.css?v=1584940380', - 'https://ps.w.org/guidepost/tags/1.2.1/build/guidepost-theme.js?v=1584940380', - ), 'last_updated' => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ), 'humanized_updated' => sprintf( '%s ago', human_time_diff( strtotime( $plugin['last_updated'] ) ) ), ); @@ -192,7 +186,7 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te $properties = $data['schema']['properties']; - $this->assertCount( 14, $properties ); + $this->assertCount( 13, $properties ); $this->assertArrayHasKey( 'name', $properties ); $this->assertArrayHasKey( 'title', $properties ); $this->assertArrayHasKey( 'description', $properties ); @@ -206,7 +200,6 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te $this->assertArrayHasKey( 'icon', $properties ); $this->assertArrayHasKey( 'last_updated', $properties ); $this->assertArrayHasKey( 'humanized_updated', $properties ); - $this->assertArrayHasKey( 'assets', $properties ); } /**