WordPress.org

Make WordPress Core

Changeset 29792


Ignore:
Timestamp:
09/29/2014 03:44:26 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Change the default orderby value in wp_get_nav_menus() to 'name'.

props voldemortensen, igmoweb.
fixes #29460.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/nav-menus.php

    r29206 r29792  
    381381
    382382// Get all nav menus.
    383 $nav_menus = wp_get_nav_menus( array('orderby' => 'name') );
     383$nav_menus = wp_get_nav_menus();
    384384$menu_count = count( $nav_menus );
    385385
  • trunk/src/wp-includes/default-widgets.php

    r29338 r29792  
    13451345
    13461346        // Get menus
    1347         $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) );
     1347        $menus = wp_get_nav_menus();
    13481348
    13491349        // If no menus exists, direct the user to go and create some.
  • trunk/src/wp-includes/nav-menu-template.php

    r29293 r29792  
    278278    // get the first menu that has items if we still can't find a menu
    279279    if ( ! $menu && !$args->theme_location ) {
    280         $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) );
     280        $menus = wp_get_nav_menus();
    281281        foreach ( $menus as $menu_maybe ) {
    282282            if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) {
  • trunk/src/wp-includes/nav-menu.php

    r29717 r29792  
    466466 */
    467467function wp_get_nav_menus( $args = array() ) {
    468     $defaults = array( 'hide_empty' => false, 'orderby' => 'none' );
     468    $defaults = array( 'hide_empty' => false, 'orderby' => 'name' );
    469469    $args = wp_parse_args( $args, $defaults );
    470470
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r27556 r29792  
    117117
    118118    }
     119
     120    /**
     121     * @ticket 29460
     122     */
     123    function test_orderby_name_by_default() {
     124        // We are going to create a random number of menus (min 2, max 10)
     125        $menus_no = rand( 2, 10 );
     126
     127        for ( $i = 0; $i <= $menus_no; $i++ ) {
     128            wp_create_nav_menu( rand_str() );
     129        }
     130
     131        // This is the expected array of menu names
     132        $expected_nav_menus_names = wp_list_pluck(
     133            get_terms( 'nav_menu',  array( 'hide_empty' => false, 'orderby' => 'name' ) ),
     134            'name'
     135        );
     136
     137        // And this is what we got when calling wp_get_nav_menus()
     138        $nav_menus_names = wp_list_pluck( wp_get_nav_menus(), 'name' );
     139       
     140        $this->assertEquals( $nav_menus_names, $expected_nav_menus_names );
     141    }
    119142}
Note: See TracChangeset for help on using the changeset viewer.