wp/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    76 	 * Retrieves all block pattern categories.
    76 	 * Retrieves all block pattern categories.
    77 	 *
    77 	 *
    78 	 * @since 6.0.0
    78 	 * @since 6.0.0
    79 	 *
    79 	 *
    80 	 * @param WP_REST_Request $request Full details about the request.
    80 	 * @param WP_REST_Request $request Full details about the request.
    81 	 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
    81 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
    82 	 */
    82 	 */
    83 	public function get_items( $request ) {
    83 	public function get_items( $request ) {
       
    84 		if ( $request->is_method( 'HEAD' ) ) {
       
    85 			// Return early as this handler doesn't add any response headers.
       
    86 			return new WP_REST_Response( array() );
       
    87 		}
       
    88 
    84 		$response   = array();
    89 		$response   = array();
    85 		$categories = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
    90 		$categories = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
    86 		foreach ( $categories as $category ) {
    91 		foreach ( $categories as $category ) {
    87 			$prepared_category = $this->prepare_item_for_response( $category, $request );
    92 			$prepared_category = $this->prepare_item_for_response( $category, $request );
    88 			$response[]        = $this->prepare_response_for_collection( $prepared_category );
    93 			$response[]        = $this->prepare_response_for_collection( $prepared_category );