Compare commits
2 Commits
f9d2d65931
...
5b2d677d17
Author | SHA1 | Date |
---|---|---|
buttle | 5b2d677d17 | |
buttle | 9d3976c1cb |
|
@ -10,11 +10,16 @@ $items = new ArrayObject;
|
|||
$items[0] = new ArrayObject(); // top level menu items go here
|
||||
|
||||
if ($wordpress_endpoint) {
|
||||
try {
|
||||
$client = new Client($wordpress_endpoint);
|
||||
$client->setOptions(array("timeout"=>1));
|
||||
$response = $client->send();
|
||||
}
|
||||
catch (exception $e) {
|
||||
$response = null;
|
||||
}
|
||||
if ($response) {
|
||||
$response_data = json_decode($response->getBody());
|
||||
|
||||
if (!$response->isClientError() && $response_data) {
|
||||
foreach ($response_data as $menu_item) {
|
||||
$lowered_title = strtolower($menu_item->title);
|
||||
|
@ -39,9 +44,29 @@ if ($wordpress_endpoint) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($items[0]) == 0) {
|
||||
// we did not retrieve a menu from the wordpress site
|
||||
// let's create a default menu
|
||||
if ($wordpress_site) {
|
||||
$project_item = [
|
||||
"id" => 2,
|
||||
"title" => "Project",
|
||||
"url" => $wordpress_site
|
||||
];
|
||||
$items[0][2] = $project_item;
|
||||
}
|
||||
$login_item = [
|
||||
"id" => 1,
|
||||
"title" => "Login",
|
||||
"url" => "/login"
|
||||
];
|
||||
$items[0][1] = $login_item;
|
||||
}
|
||||
//print_r($items);
|
||||
|
||||
if (!function_exists('render_menu')) {
|
||||
function render_menu($items, $level_id) {
|
||||
echo '<ul>' . PHP_EOL;
|
||||
foreach ($items[$level_id] as $menu_item) {
|
||||
|
@ -54,9 +79,8 @@ function render_menu($items, $level_id) {
|
|||
}
|
||||
echo '</ul>' . PHP_EOL;
|
||||
}
|
||||
|
||||
if (count($items[0]) > 0) {
|
||||
render_menu($items, 0);
|
||||
}
|
||||
|
||||
render_menu($items, 0);
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue