MenusController final readonly class
Minn\Rest\MenusController · public/minn/src/Minn/Rest/MenusController.php · 305 lines
wp/v2/menus, menu-items, and menu-locations. Viewing needs edit_posts; writes need edit_theme_options. Anonymous callers get 401.
Constants and properties
| private | NEW_ITEM = array ( 'menu-id' => 0, 'menu-item-db-id' => 0, 'menu-item-object-id' => 0, 'menu-item-object' => '', 'menu-item-parent-id' => 0, 'menu-item-position' => 1, 'menu-item-type' => 'custom', 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', 'menu-item-attr-title' => '', 'menu-item-target' => '', 'menu-item-classes' => '', 'menu-item-xfn' => '', 'menu-item-status' => 'publish', ) | The arguments a new item starts from, as the reference's REST controller prepares them. |
| private | readonly Minn\Content\Menus $menus | Promoted from the constructor. |
| private | readonly Minn\Rest\MenuObject $menuObject | Promoted from the constructor. |
| private | readonly Minn\Rest\MenuItemObject $itemObject | Promoted from the constructor. |
| private | readonly Minn\Rest\Caller $caller | Promoted from the constructor. |
| private | readonly Minn\Rest\RestUrl $url | Promoted from the constructor. |
Public
| new | __construct(Minn\Content\Menus $menus, Minn\Rest\MenuObject $menuObject, Minn\Rest\MenuItemObject $itemObject, Minn\Rest\Caller $caller, Minn\Rest\RestUrl $url)# | |
| method | listMenus(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/menus (cap edit_posts; or anyone, when rest_menu_read_access opens it)# | Every classic menu. |
| method | singleMenu(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/menus/{id:[\d]+} (cap edit_posts; menu {id} must exist; or anyone, when rest_menu_read_access opens it)# | One menu. |
| method | createMenu(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/menus (cap edit_theme_options)# | Creates a menu. |
| method | updateMenu(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)PUT /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)PATCH /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)# | Renames or re-describes a menu. |
| method | deleteMenu(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/menus/{id:[\d]+} (cap edit_theme_options; menu {id} must exist)# | Deletes a menu and its items. |
| method | listItems(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/menu-items (cap edit_posts; or anyone, when rest_menu_read_access opens it)# | The items of a menu. |
| method | singleItem(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/menu-items/{id:[\d]+} (cap edit_posts; menu item {id} must exist; or anyone, when rest_menu_read_access opens it)# | One menu item. |
| method | createItem(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/menu-items (cap edit_theme_options)# | Creates a menu item. |
| method | updateItem(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)PUT /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)PATCH /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)# | Updates a menu item. |
| method | deleteItem(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/menu-items/{id:[\d]+} (cap edit_theme_options; menu item {id} must exist)# | Deletes a menu item. |
| method | locations(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/menu-locations (cap edit_theme_options; or anyone, when rest_menu_read_access opens it)# | The menu locations the theme and plugins register (none for a block theme without plugins), keyed by name; edit_theme_options to view. |
| method | oneLocation(Minn\Http\Request $request, string $location): Minn\Http\ResponseGET /wp/v2/menu-locations/{location:[\w-]+} (cap edit_theme_options; or anyone, when rest_menu_read_access opens it)# | One menu location. |
Internals 6
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | locationItem(string $name, string $description): array# | A location, the menu assigned to it (0 for none), and links to it and its menu when that exists. @return array<string, mixed> @return array<string, mixed> | ||||||
| private | argsFrom(array $body, array $args): array# | The request's item fields as the reference's menu-item-* save arguments, over the ones given.
@return array<string, mixed> | ||||||
| private | titleFrom(array $body): string# |
| ||||||
| private | urlFrom(array $body): string# |
| ||||||
| private | refuse(?Minn\Runtime\Refusal $refusal): void# | A refused menu name, in the shape the reference's REST error carries. | ||||||
| private | plain(string $value): string# |
Nothing matches.