diff --git a/src/wp-admin/nav-menus.php b/src/wp-admin/nav-menus.php index 0dd34cf9e6..66590be119 100644 --- a/src/wp-admin/nav-menus.php +++ b/src/wp-admin/nav-menus.php @@ -380,7 +380,7 @@ switch ( $action ) { } // Get all nav menus. -$nav_menus = wp_get_nav_menus( array('orderby' => 'name') ); +$nav_menus = wp_get_nav_menus(); $menu_count = count( $nav_menus ); // Are we on the add new screen? diff --git a/src/wp-includes/default-widgets.php b/src/wp-includes/default-widgets.php index d54dbc732c..f4a6790711 100644 --- a/src/wp-includes/default-widgets.php +++ b/src/wp-includes/default-widgets.php @@ -1344,7 +1344,7 @@ class WP_Widget_Tag_Cloud extends WP_Widget { $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; // Get menus - $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) ); + $menus = wp_get_nav_menus(); // If no menus exists, direct the user to go and create some. if ( !$menus ) { diff --git a/src/wp-includes/nav-menu-template.php b/src/wp-includes/nav-menu-template.php index 4d380a25ee..6db82b1e8f 100644 --- a/src/wp-includes/nav-menu-template.php +++ b/src/wp-includes/nav-menu-template.php @@ -277,7 +277,7 @@ function wp_nav_menu( $args = array() ) { // get the first menu that has items if we still can't find a menu if ( ! $menu && !$args->theme_location ) { - $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) ); + $menus = wp_get_nav_menus(); foreach ( $menus as $menu_maybe ) { if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { $menu = $menu_maybe; diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 8a0ee77a4d..6c6af4b8a7 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -465,7 +465,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item * @return array menu objects */ function wp_get_nav_menus( $args = array() ) { - $defaults = array( 'hide_empty' => false, 'orderby' => 'none' ); + $defaults = array( 'hide_empty' => false, 'orderby' => 'name' ); $args = wp_parse_args( $args, $defaults ); /** diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php index 35504d2b4f..07fa939477 100644 --- a/tests/phpunit/tests/post/nav-menu.php +++ b/tests/phpunit/tests/post/nav-menu.php @@ -116,4 +116,27 @@ class Test_Nav_Menus extends WP_UnitTestCase { $this->assertEquals( 'WordPress.org', $custom_item->title ); } + + /** + * @ticket 29460 + */ + function test_orderby_name_by_default() { + // We are going to create a random number of menus (min 2, max 10) + $menus_no = rand( 2, 10 ); + + for ( $i = 0; $i <= $menus_no; $i++ ) { + wp_create_nav_menu( rand_str() ); + } + + // This is the expected array of menu names + $expected_nav_menus_names = wp_list_pluck( + get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'name' ) ), + 'name' + ); + + // And this is what we got when calling wp_get_nav_menus() + $nav_menus_names = wp_list_pluck( wp_get_nav_menus(), 'name' ); + + $this->assertEquals( $nav_menus_names, $expected_nav_menus_names ); + } }