WP_REST_Menus_Controller::get_menu_locations()protectedWP 5.9.0

Returns the names of the locations assigned to the menu.

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.

WP_REST_Menus_Controller::get_menu_locations() code WP 6.6.2

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;
}