WordPress.org

Make WordPress Core

Changeset 46102


Ignore:
Timestamp:
09/13/2019 05:57:57 PM (3 months ago)
Author:
desrosj
Message:

Menus: Nav menu locations should not be integers.

When nav menu location slugs are integers, some hard to debug results can occur. register_nav_menus() utilizes array_merge() which renumbers numeric indexes, starting from 0. Because of this, numeric menu locations will almost always be changed.

This change introduces a _doing_it_wrong() notice to inform developers that nav menu locations should always be strings.

Props audrasjb, desrosj, welcher.
Fixes #45361.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r45932 r46102  
    9292
    9393    add_theme_support( 'menus' );
     94
     95    foreach ( $locations as $key => $value ) {
     96        if ( is_int( $key ) ) {
     97            _doing_it_wrong( __FUNCTION__, __( 'Nav menu locations must be strings.' ), '5.3' );
     98            break;
     99        }
     100    }
    94101
    95102    $_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations );
  • trunk/tests/phpunit/tests/menu/nav-menu.php

    r45588 r46102  
    183183     * Technically possible to register menu locations numerically.
    184184     *
     185     * @expectedIncorrectUsage register_nav_menus
     186     *
    185187     * @covers ::wp_map_nav_menu_locations()
    186188     */
     
    205207    /**
    206208     * Technically possible old nav menu locations were registered numerically.
     209     *
     210     * @expectedIncorrectUsage register_nav_menus
    207211     *
    208212     * @covers wp_map_nav_menu_locations()
Note: See TracChangeset for help on using the changeset viewer.