Make WordPress Core


Ignore:
Timestamp:
09/13/2019 05:57:57 PM (5 years 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.

File:
1 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 );
Note: See TracChangeset for help on using the changeset viewer.