Open Underdawgq opened 8 years ago
@Underdawgq Could you explain what this does and how do you indent someone to use it?
Instead of returning the menu as a tree these routes return the menu in html. If someone wanted to simply mirror a menu from one WordPress site to another this is much easier than setting up a loop to transform the tree into html.
So if site B wanted the same menu as site A then all they would have to do is edit the theme for site B from something like this:
wp_nav_menu( array ( 'menu_class' => 'nav-menu', 'menu' => 'menu-slug' ) );
to use something like:
// Get json file content
$siteAmenu_jsoncontent=file_get_contents('http://www.siteA.com/wp-json/wp-api-menus/v2/menu-html/menu-slug');
//Decode json content into an array
$siteAmenu_json=json_decode($siteAmenu_jsoncontent, true);
// Optional: Replace generic id and/or class attributes with id and class attributes for this specific menu
$siteAmenu_json['html']=str_replace('ul class="menu"', 'ul class="nav-menu"', $siteAmenu_json['html']);
// Display menu on screen/in browser
echo $siteAmenu_json['html'];
I did not test the code for v1 of the REST API.