wp/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
   116 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
   116 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
   117 	 */
   117 	 */
   118 	public function prepare_item_for_response( $item, $request ) {
   118 	public function prepare_item_for_response( $item, $request ) {
   119 		// Restores the more descriptive, specific name for use within this method.
   119 		// Restores the more descriptive, specific name for use within this method.
   120 		$plugin = $item;
   120 		$plugin = $item;
       
   121 
       
   122 		$fields = $this->get_fields_for_response( $request );
   121 
   123 
   122 		// There might be multiple blocks in a plugin. Only the first block is mapped.
   124 		// There might be multiple blocks in a plugin. Only the first block is mapped.
   123 		$block_data = reset( $plugin['blocks'] );
   125 		$block_data = reset( $plugin['blocks'] );
   124 
   126 
   125 		// A data array containing the properties we'll return.
   127 		// A data array containing the properties we'll return.
   144 		);
   146 		);
   145 
   147 
   146 		$this->add_additional_fields_to_object( $block, $request );
   148 		$this->add_additional_fields_to_object( $block, $request );
   147 
   149 
   148 		$response = new WP_REST_Response( $block );
   150 		$response = new WP_REST_Response( $block );
   149 		$response->add_links( $this->prepare_links( $plugin ) );
   151 
       
   152 		if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
       
   153 			$response->add_links( $this->prepare_links( $plugin ) );
       
   154 		}
   150 
   155 
   151 		return $response;
   156 		return $response;
   152 	}
   157 	}
   153 
   158 
   154 	/**
   159 	/**