Skip to content
Permalink
Browse files

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.



git-svn-id: https://develop.svn.wordpress.org/branches/5.0@43899 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
pento committed Nov 15, 2018
1 parent 07736dc commit 61ee6d9fa7cdb8a49a9a57aadffa3087b6a4405b
Showing with 31 additions and 3 deletions.
  1. +0 −1 .travis.yml
  2. +6 −2 src/wp-includes/nav-menu.php
  3. +25 −0 tests/phpunit/tests/menu/nav-menu.php
@@ -31,7 +31,6 @@ matrix:
- php: nightly
allow_failures:
- php: nightly
- php: 7.3
before_install:
- |
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
@@ -1139,7 +1139,9 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat
foreach ( $registered_nav_menus as $new_location => $name ) {
// ...actually match!
if ( false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) {
if ( is_string( $new_location ) && false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) {
continue;
} elseif ( is_numeric( $new_location ) && $new_location !== $slug ) {
continue;
}
@@ -1150,7 +1152,9 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat
foreach ( $slug_group as $slug ) {
// ... have a match as well.
if ( false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) {
if ( is_string( $location ) && false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) {
continue;
} elseif ( is_numeric( $location ) && $location !== $slug ) {
continue;
}
@@ -200,4 +200,29 @@ function test_numerical_locations() {
);
$this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
}
/**
* Technically possible old nav menu locations were registered numerically.
*
* @covers wp_map_nav_menu_locations()
*/
public function test_numerical_old_locations() {
$this->register_nav_menu_locations( array( 'primary', 1 ) );
$old_nav_menu_locations = array(
'primary' => 1,
'tertiary' => 2,
0 => 3,
);
$next_theme_nav_menu_locations = array();
$new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $next_theme_nav_menu_locations, $old_nav_menu_locations );
$expected_nav_menu_locations = array(
'primary' => 1,
0 => 3,
);
$this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
}
}

0 comments on commit 61ee6d9

Please sign in to comment.
You can’t perform that action at this time.