WP_REST_Widgets_Controller::get_items() WordPress Method
This method is responsible for fetching all the widgets for a given site. It makes an HTTP GET request to the WordPress REST API and expects a JSON response. The response body is an array of widget objects, each with an id, name, and description.
WP_REST_Widgets_Controller::get_items( WP_REST_Request $request ) #
Retrieves a collection of widgets.
Parameters
- $request
(WP_REST_Request)(Required)Full details about the request.
Return
(WP_REST_Response|WP_Error) Response object on success, or WP_Error object on failure.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
public function get_items( $request ) { $this->retrieve_widgets(); $prepared = array(); $permissions_check = $this->permissions_check( $request ); foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) { if ( isset( $request['sidebar'] ) && $sidebar_id !== $request['sidebar'] ) { continue; } if ( is_wp_error( $permissions_check ) && ! $this->check_read_sidebar_permission( $sidebar_id ) ) { continue; } foreach ( $widget_ids as $widget_id ) { $response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' ), $request ); if ( ! is_wp_error( $response ) ) { $prepared[] = $this->prepare_response_for_collection( $response ); } } } return new WP_REST_Response( $prepared ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |