wp/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   131 	 * Retrieves a collection of widgets.
   131 	 * Retrieves a collection of widgets.
   132 	 *
   132 	 *
   133 	 * @since 5.8.0
   133 	 * @since 5.8.0
   134 	 *
   134 	 *
   135 	 * @param WP_REST_Request $request Full details about the request.
   135 	 * @param WP_REST_Request $request Full details about the request.
   136 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
   136 	 * @return WP_REST_Response Response object.
   137 	 */
   137 	 */
   138 	public function get_items( $request ) {
   138 	public function get_items( $request ) {
       
   139 		if ( $request->is_method( 'HEAD' ) ) {
       
   140 			// Return early as this handler doesn't add any response headers.
       
   141 			return new WP_REST_Response( array() );
       
   142 		}
       
   143 
   139 		$this->retrieve_widgets();
   144 		$this->retrieve_widgets();
   140 
   145 
   141 		$prepared          = array();
   146 		$prepared          = array();
   142 		$permissions_check = $this->permissions_check( $request );
   147 		$permissions_check = $this->permissions_check( $request );
   143 
   148 
   675 				__( 'The requested widget is invalid.' ),
   680 				__( 'The requested widget is invalid.' ),
   676 				array( 'status' => 500 )
   681 				array( 'status' => 500 )
   677 			);
   682 			);
   678 		}
   683 		}
   679 
   684 
   680 		$widget    = $wp_registered_widgets[ $widget_id ];
   685 		$widget = $wp_registered_widgets[ $widget_id ];
       
   686 		// Don't prepare the response body for HEAD requests.
       
   687 		if ( $request->is_method( 'HEAD' ) ) {
       
   688 			/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php */
       
   689 			return apply_filters( 'rest_prepare_widget', new WP_REST_Response( array() ), $widget, $request );
       
   690 		}
       
   691 
   681 		$parsed_id = wp_parse_widget_id( $widget_id );
   692 		$parsed_id = wp_parse_widget_id( $widget_id );
   682 		$fields    = $this->get_fields_for_response( $request );
   693 		$fields    = $this->get_fields_for_response( $request );
   683 
   694 
   684 		$prepared = array(
   695 		$prepared = array(
   685 			'id'            => $widget_id,
   696 			'id'            => $widget_id,