WP_REST_Widgets_Controller::get_items()publicWP 5.8.0

Retrieves a collection of widgets.

{} Это метод класса: WP_REST_Widgets_Controller{}

Хуков нет.

Возвращает

WP_REST_Response|WP_Error. Response object on success, or WP_Error object on failure.

Использование

$WP_REST_Widgets_Controller = new WP_REST_Widgets_Controller();
$WP_REST_Widgets_Controller->get_items( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Список изменений

С версии 5.8.0 Введена.

Код WP_REST_Widgets_Controller::get_items() WP 6.0.2

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 );
}