WordPress.org

Make WordPress Core

Changeset 43899


Ignore:
Timestamp:
11/15/2018 11:19:40 PM (12 months ago)
Author:
pento
Message:

Nav Menus: Fix a PHP 7.3 error when switching themes.

When switching themes, wp_map_nav_menu_locations() is used to ensure nav menus are placed in the relevant menu location. Occasionally, menus are registered to locations with numeric slugs, rather than strings. wp_map_nav_menu_locations() assumed it would be the latter, and ran stripos() on those numeric slugs. This behaviour is deprecated in PHP 7.3.

As this is the last known PHP 7.3 incompatibility, this commit also removes PHP 7.3 from Travis' allowed_failures list.

Props desrosj, jorbin.
See #45018.

Location:
branches/5.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/.travis.yml

    r43853 r43899  
    3232  allow_failures:
    3333  - php: nightly
    34   - php: 7.3
    3534before_install:
    3635- |
  • branches/5.0/src/wp-includes/nav-menu.php

    r42026 r43899  
    11401140
    11411141                // ...actually match!
    1142                 if ( false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) {
     1142                if ( is_string( $new_location ) && false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) {
     1143                    continue;
     1144                } elseif ( is_numeric( $new_location ) && $new_location !== $slug ) {
    11431145                    continue;
    11441146                }
     
    11511153
    11521154                        // ... have a match as well.
    1153                         if ( false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) {
     1155                        if ( is_string( $location ) && false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) {
     1156                            continue;
     1157                        } elseif ( is_numeric( $location ) && $location !== $slug ) {
    11541158                            continue;
    11551159                        }
  • branches/5.0/tests/phpunit/tests/menu/nav-menu.php

    r42026 r43899  
    201201        $this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
    202202    }
     203
     204    /**
     205     * Technically possible old nav menu locations were registered numerically.
     206     *
     207     * @covers wp_map_nav_menu_locations()
     208     */
     209    public function test_numerical_old_locations() {
     210        $this->register_nav_menu_locations( array( 'primary', 1 ) );
     211
     212        $old_nav_menu_locations = array(
     213            'primary'  => 1,
     214            'tertiary' => 2,
     215            0          => 3,
     216        );
     217
     218        $next_theme_nav_menu_locations     = array();
     219        $new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $next_theme_nav_menu_locations, $old_nav_menu_locations );
     220
     221        $expected_nav_menu_locations = array(
     222            'primary' => 1,
     223            0         => 3,
     224        );
     225
     226        $this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
     227    }
    203228}
Note: See TracChangeset for help on using the changeset viewer.