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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user