API / Minn\Rest / WidgetsController

WidgetsController final readonly class

Minn\Rest\WidgetsController · public/minn/src/Minn/Rest/WidgetsController.php · 169 lines

wp/v2/widgets as the reference answers it (probe rest-widgets), for anyone who can edit theme options: the registered widgets of every sidebar (or one), a widget created under the next free number for its type, its settings saved through the widget's own update (raw when the widget shows its instance in REST, encoded with a matching hash, or from its form's fields) and registered at once, a widget moved between sidebars, and a widget deleted, or without force sent to the inactive widgets.

Used by 1

Constants and properties

privateLIST = array ( 'sidebar' => array ( 'description' => 'The sidebar to return widgets for.', 'type' => 'string', 'required' => false, ), )
privateBODY = array ( 'id_base' => array ( 'description' => 'The type of the widget. Corresponds to ID in widget-types endpoint.', 'type' => 'string', 'required' => false, ), 'sidebar' => array ( 'description' => 'The sidebar the widget belongs to.', 'type' => 'string', 'required' => false, ), 'instance' => array ( 'description' => 'Instance settings of the widget, if supported.', 'type' => 'object', 'required' => false, ), 'form_data' => array ( 'description' => 'URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only.', 'type' => 'string', 'required' => false, ), )
privatereadonly Minn\Rest\WidgetObject $object

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

Public

new__construct(Minn\Rest\WidgetObject $object, Minn\Rest\Caller $caller)#
methodlist(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/widgets (cap edit_theme_options)#

The registered widgets, sidebar by sidebar.

methodsingle(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/widgets/{id:[\w\-]+} (cap edit_theme_options)#

One widget.

methodcreate(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/widgets (cap edit_theme_options)#

Creates a widget in a sidebar (the inactive widgets unless one is named).

methodupdate(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/widgets/{id:[\w\-]+} (cap edit_theme_options)PUT /wp/v2/widgets/{id:[\w\-]+} (cap edit_theme_options)PATCH /wp/v2/widgets/{id:[\w\-]+} (cap edit_theme_options)#

Saves a widget's settings and moves it, as the body asks.

methoddelete(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/widgets/{id:[\w\-]+} (cap edit_theme_options)#

Deletes a widget with force; without, sends it to the inactive widgets.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatesaveInstance(WP_Widget $object, int $number, array $body): string#

Saves a widget's settings through its own update and registers it: raw settings (when it shows them), encoded ones with their hash, or its form's fields. The widget's id.

$bodyarray<string, mixed>
privatenewInstance(WP_Widget $object, int $number, array $body): array#
$bodyarray<string, mixed>@return array<string, mixed>
privatesidebarOf(string $id): string#

The sidebar holding a widget; a widget no sidebar holds is no widget.