WP_REST_Menus_Controller::get_menu_locations()protectedWP 5.9.0

Returns the names of the locations assigned to the menu.

{} It's a method of the class: WP_REST_Menus_Controller{}

No Hooks.

Return

String[]. The locations assigned to the menu.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_menu_locations( $menu_id );
$menu_id(int) (required)
The menu id.

Changelog

Since 5.9.0 Introduced.

Code of WP_REST_Menus_Controller::get_menu_locations() WP 6.0

protected function get_menu_locations( $menu_id ) {
	$locations      = get_nav_menu_locations();
	$menu_locations = array();

	foreach ( $locations as $location => $assigned_menu_id ) {
		if ( $menu_id === $assigned_menu_id ) {
			$menu_locations[] = $location;
		}
	}

	return $menu_locations;
}