wp/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   104 
   104 
   105 		return rest_ensure_response( $result );
   105 		return rest_ensure_response( $result );
   106 	}
   106 	}
   107 
   107 
   108 	/**
   108 	/**
   109 	 * Parse block metadata for a block, and prepare it for an API repsonse.
   109 	 * Parse block metadata for a block, and prepare it for an API response.
   110 	 *
   110 	 *
   111 	 * @since 5.5.0
   111 	 * @since 5.5.0
   112 	 *
   112 	 * @since 5.9.0 Renamed `$plugin` to `$item` to match parent class for PHP 8 named parameter support.
   113 	 * @param array           $plugin  The plugin metadata.
   113 	 *
       
   114 	 * @param array           $item    The plugin metadata.
   114 	 * @param WP_REST_Request $request Request object.
   115 	 * @param WP_REST_Request $request Request object.
   115 	 * @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.
   116 	 */
   117 	 */
   117 	public function prepare_item_for_response( $plugin, $request ) {
   118 	public function prepare_item_for_response( $item, $request ) {
       
   119 		// Restores the more descriptive, specific name for use within this method.
       
   120 		$plugin = $item;
       
   121 
   118 		// There might be multiple blocks in a plugin. Only the first block is mapped.
   122 		// There might be multiple blocks in a plugin. Only the first block is mapped.
   119 		$block_data = reset( $plugin['blocks'] );
   123 		$block_data = reset( $plugin['blocks'] );
   120 
   124 
   121 		// A data array containing the properties we'll return.
   125 		// A data array containing the properties we'll return.
   122 		$block = array(
   126 		$block = array(
   233 					'type'        => 'string',
   237 					'type'        => 'string',
   234 					'context'     => array( 'view' ),
   238 					'context'     => array( 'view' ),
   235 				),
   239 				),
   236 				'rating'              => array(
   240 				'rating'              => array(
   237 					'description' => __( 'The star rating of the block.' ),
   241 					'description' => __( 'The star rating of the block.' ),
   238 					'type'        => 'integer',
   242 					'type'        => 'number',
   239 					'context'     => array( 'view' ),
   243 					'context'     => array( 'view' ),
   240 				),
   244 				),
   241 				'rating_count'        => array(
   245 				'rating_count'        => array(
   242 					'description' => __( 'The number of ratings.' ),
   246 					'description' => __( 'The number of ratings.' ),
   243 					'type'        => 'integer',
   247 					'type'        => 'integer',
   244 					'context'     => array( 'view' ),
   248 					'context'     => array( 'view' ),
   245 				),
   249 				),
   246 				'active_installs'     => array(
   250 				'active_installs'     => array(
   247 					'description' => __( 'The number sites that have activated this block.' ),
   251 					'description' => __( 'The number sites that have activated this block.' ),
   248 					'type'        => 'string',
   252 					'type'        => 'integer',
   249 					'context'     => array( 'view' ),
   253 					'context'     => array( 'view' ),
   250 				),
   254 				),
   251 				'author_block_rating' => array(
   255 				'author_block_rating' => array(
   252 					'description' => __( 'The average rating of blocks published by the same author.' ),
   256 					'description' => __( 'The average rating of blocks published by the same author.' ),
   253 					'type'        => 'integer',
   257 					'type'        => 'number',
   254 					'context'     => array( 'view' ),
   258 					'context'     => array( 'view' ),
   255 				),
   259 				),
   256 				'author_block_count'  => array(
   260 				'author_block_count'  => array(
   257 					'description' => __( 'The number of blocks published by the same author.' ),
   261 					'description' => __( 'The number of blocks published by the same author.' ),
   258 					'type'        => 'integer',
   262 					'type'        => 'integer',
   268 					'type'        => 'string',
   272 					'type'        => 'string',
   269 					'format'      => 'uri',
   273 					'format'      => 'uri',
   270 					'context'     => array( 'view' ),
   274 					'context'     => array( 'view' ),
   271 				),
   275 				),
   272 				'last_updated'        => array(
   276 				'last_updated'        => array(
   273 					'description' => __( 'The date when the block was last updated, in fuzzy human readable format.' ),
   277 					'description' => __( 'The date when the block was last updated.' ),
   274 					'type'        => 'string',
   278 					'type'        => 'string',
   275 					'format'      => 'date-time',
   279 					'format'      => 'date-time',
   276 					'context'     => array( 'view' ),
   280 					'context'     => array( 'view' ),
   277 				),
   281 				),
   278 				'humanized_updated'   => array(
   282 				'humanized_updated'   => array(