Skip to content

Commit d278f95

Browse files
authored
Fix: timber::get_menu(0) returns alphabetically first menu instead of nothing (#3070)
* fix: Timber::get_menu(int 0) will now return null instead of a alphabetically first menu available * docs: enhance menu retrieval example in the documentation
1 parent cbac2e0 commit d278f95

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

docs/v2/guides/menus.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,8 @@ add_filter('timber/context', 'add_to_context');
166166
function add_to_context($context)
167167
{
168168
// Set all nav menus in context.
169-
foreach (array_keys(get_registered_nav_menus()) as $location) {
170-
// Bail out if menu has no location.
171-
if (!has_nav_menu($location)) {
172-
continue;
173-
}
174-
169+
foreach (array_keys(get_nav_menu_locations()) as $location) {
175170
$menu = Timber::get_menu($location);
176-
177171
$context[$location] = $menu;
178172
}
179173

src/Factory/MenuFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public function from_location(string $location, array $args = []): ?Menu
105105
*/
106106
public function from_id(int $id, array $args = []): ?Menu
107107
{
108+
if (0 === $id) {
109+
return null;
110+
}
111+
108112
$term = \get_term_by('id', $id, 'nav_menu');
109113

110114
if (!$term) {

0 commit comments

Comments
 (0)