MenuEvents final readonly class
Minn\Runtime\MenuEvents · public/minn/src/Minn/Runtime/MenuEvents.php · 225 lines
Menus and their items saved as the reference saves them, telling plugins what it tells them (probe rest-menu-save). A menu is a nav_menu term: made or changed through wp_insert_term / wp_update_term (the term actions), then wp_create_nav_menu or wp_update_nav_menu; deleted, its items go through wp_delete_post, the term through wp_delete_term, then wp_delete_nav_menu. An item is written by the engine, with the post save actions around it, then wp_add_nav_menu_item (a new one) and wp_update_nav_menu_item, handed the reference's menu-item-* arguments.
Constants and properties
| private | ITEM_DEFAULTS = array ( 'menu-item-db-id' => 0, 'menu-item-object-id' => 0, 'menu-item-object' => '', 'menu-item-parent-id' => 0, 'menu-item-position' => 0, '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' => '', 'menu-item-post-date' => '', 'menu-item-post-date-gmt' => '', ) | The arguments an item is saved with, and their defaults, as the reference lists them. |
| private | readonly Minn\Content\Menus $menus | Promoted from the constructor. |
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
Public
| new | __construct(Minn\Content\Menus $menus, Minn\Content\Posts $posts)# | ||||
| method | saveMenu(int $menuId, array $data): WP_Error|int# | wp_update_nav_menu_object: a menu made (menu id 0) or changed, its id or the refusal. The name is checked first, as the reference checks it.
| |||
| method | deleteMenu(int $menuId): void# | wp_delete_nav_menu: the items through wp_delete_post, the term through wp_delete_term, the locations let go, then wp_delete_nav_menu. | |||
| method | saveItem(int $menuId, int $itemId, array $data, string $afterInsert = 'now'): WP_Error|int# | wp_update_nav_menu_item: an item made (id 0) or changed in a menu, its id or the refusal; the post save actions around the write, then the item actions, and wp_after_insert_post "now" or (a REST save, which fires it after its own actions) "later".
| |||
| method | restMenu(int $menuId, array $fields, Minn\Http\Request $request): int# | A menu saved over REST, as the reference's menus controller saves one: the request's fields (name, description, those given) through rest_pre_insert_nav_menu, then saveMenu(), then rest_insert_nav_menu and rest_after_insert_nav_menu.
| |||
| method | restDeleteMenu(int $menuId, array $previous, Minn\Http\Request $request): void# | A menu deleted over REST: deleteMenu(), then rest_delete_nav_menu with the menu as it was and the response. @param array<string, mixed> $previous
| |||
| method | restItem(int $itemId, array $args, Minn\Http\Request $request): int# | An item saved over REST, as the reference's menu-items controller saves one: its menu-id and menu-item-* arguments through rest_pre_insert_nav_menu_item, then saveItem(), then rest_insert_nav_menu_item, rest_after_insert_nav_menu_item and wp_after_insert_post.
| |||
| method | restDeleteItem(int $itemId, array $previous, Minn\Http\Request $request): void# | An item deleted over REST: wp_delete_post, then rest_delete_nav_menu_item with the item as it was and the response. @param array<string, mixed> $previous
| |||
| method | savedArgs(int $itemId): array# | An item's own saved values as menu-item-* arguments, which a REST update starts from: the reference's save resets to its default any argument it isn't handed. @return array<string, mixed> |
Internals 2
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | prepared(mixed $prepared): array# | What a rest_pre_insert filter handed back, as arguments; its refusal as the request's. @return array<string, mixed> @return array<string, mixed> | |||
| private | fields(array $args, int $menuId, int $authorId): array# | The menu-item-* arguments as the engine's item fields.
@return array<string, mixed> |
Nothing matches.