feat: menu list, get, create and location tools

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 00:00:30 +02:00
co-authored by Claude Opus 5.5
parent 236d25325d
commit 1d59d1d2ad
13 changed files with 828 additions and 0 deletions
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\WordPress\Menus;
/**
* Theme menu locations (theme mod nav_menu_locations).
*/
final class MenuLocations
{
/** @return array<string, string> Location slug => description. */
public static function registered(): array
{
return array_map('strval', (array) get_registered_nav_menus());
}
/** @return array<string, int> Location slug => menu ID. */
public static function assigned(): array
{
$locations = get_nav_menu_locations();
return is_array($locations) ? array_map('intval', $locations) : [];
}
/** @return list<string> */
public static function of(int $menuId): array
{
return array_map('strval', array_keys(array_filter(
self::assigned(),
static fn (int $id): bool => $id === $menuId
)));
}
public static function assign(string $location, int $menuId): void
{
$locations = self::assigned();
if ($menuId > 0) {
$locations[$location] = $menuId;
} else {
unset($locations[$location]);
}
set_theme_mod('nav_menu_locations', $locations);
}
}