-
-
Save terence1990/64ac107521142f2e65d8bf9053f7934f to your computer and use it in GitHub Desktop.
Add Menu endpoint in wp-kit/rest-kit, if you don't want to use plugins/wp-rest-api-v2-menus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#resources/controllers/ApiController.php | |
public static function getMenu($request) { | |
$menu = []; | |
foreach(get_nav_menu_items_by_location($request->get_param('menu')) as $item) { | |
$item->path = parse_url($item->url, PHP_URL_PATH); | |
array_push($menu, $item); | |
} | |
return $menu; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#resources/routes.php | |
rest_route( 'wp/v2', '/menu', [Theme\Controllers\ApiController::class, 'getMenu'] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment