Skip to content

Commit

Permalink
Merge pull request #44 from darylldoyle/fix/error-when-menu-term-is-m…
Browse files Browse the repository at this point in the history
…issing

Fix fatal error issue when menu term is missing
  • Loading branch information
thebatclaudio authored Nov 9, 2022
2 parents 4ea466b + bc41fc4 commit 8ac6258
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion wp-rest-api-v2-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ function wp_api_v2_locations_get_menu_data( $data ) {
// this could be replaced with `if (has_nav_menu($data['id']))`
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $data['id'] ] ) ) {
// Replace default empty object with the location object
$menu = get_term( $locations[ $data['id'] ] );
$menu = get_term( $locations[ $data['id'] ] );

if ( is_wp_error( $menu ) || null === $menu ) {
return new WP_Error( 'not_found', 'No location has been found with this id or slug: `' . $data['id'] . '`. Please ensure you passed an existing location ID or location slug.', array( 'status' => 404 ) );
}

$menu->items = wp_api_v2_menus_get_menu_items( $locations[ $data['id'] ] );
} else {
return new WP_Error( 'not_found', 'No location has been found with this id or slug: `' . $data['id'] . '`. Please ensure you passed an existing location ID or location slug.', array( 'status' => 404 ) );
Expand Down

0 comments on commit 8ac6258

Please sign in to comment.