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.
Constants and properties
| private | LIST = array ( 'sidebar' => array ( 'description' => 'The sidebar to return widgets for.', 'type' => 'string', 'required' => false, ), ) | |
| private | BODY = 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, ), ) | |
| private | readonly Minn\Rest\WidgetObject $object | Promoted from the constructor. |
| private | readonly Minn\Rest\Caller $caller | Promoted from the constructor. |
Public
| new | __construct(Minn\Rest\WidgetObject $object, Minn\Rest\Caller $caller)# | |
| method | list(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/widgets (cap edit_theme_options)# | The registered widgets, sidebar by sidebar. |
| method | single(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/widgets/{id:[\w\-]+} (cap edit_theme_options)# | One widget. |
| method | create(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). |
| method | update(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. |
| method | delete(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.
| private | saveInstance(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.
| |||
| private | newInstance(WP_Widget $object, int $number, array $body): array# |
| |||
| private | sidebarOf(string $id): string# | The sidebar holding a widget; a widget no sidebar holds is no widget. |
Nothing matches.