From ee70d0a3579849d2498c59a1771b5c8ea2bea039 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 24 Oct 2018 19:06:49 -0400 Subject: [PATCH 01/10] try adding a simple check for numeric --- src/wp-includes/nav-menu.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 6a290bdaa9e31..855bf268cedaa 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -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 ( false === is_numeric( $new_location ) && false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) { + continue; + } elseif( is_numeric( $new_location ) && $new_location !== $slug ){ continue; } From c86d90ccc47eb377ed7d3c8893116cf0945f86b4 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 24 Oct 2018 21:43:14 -0400 Subject: [PATCH 02/10] remove groupby This has never existed. https://core.trac.wordpress.org/changeset/37894/ --- src/wp-includes/class-wp-network-query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-network-query.php b/src/wp-includes/class-wp-network-query.php index f8ca48f452ab0..c724e25192f79 100644 --- a/src/wp-includes/class-wp-network-query.php +++ b/src/wp-includes/class-wp-network-query.php @@ -393,7 +393,7 @@ protected function get_network_ids() { $where = implode( ' AND ', $this->sql_clauses['where'] ); - $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); + $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits' ); /** * Filters the network query clauses. From 5d9480bd6725a728243ed3aa1ebfd28de06180d8 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 24 Oct 2018 21:47:44 -0400 Subject: [PATCH 03/10] Actually, include groupby so it's easier to see everything that can be filtered --- src/wp-includes/class-wp-network-query.php | 4 +++- src/wp-includes/class-wp-site-query.php | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-network-query.php b/src/wp-includes/class-wp-network-query.php index c724e25192f79..4ede8b7a278c9 100644 --- a/src/wp-includes/class-wp-network-query.php +++ b/src/wp-includes/class-wp-network-query.php @@ -393,7 +393,9 @@ protected function get_network_ids() { $where = implode( ' AND ', $this->sql_clauses['where'] ); - $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits' ); + $groupby = ''; + + $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); /** * Filters the network query clauses. diff --git a/src/wp-includes/class-wp-site-query.php b/src/wp-includes/class-wp-site-query.php index cf2134d8a417f..ffedeba850a7e 100644 --- a/src/wp-includes/class-wp-site-query.php +++ b/src/wp-includes/class-wp-site-query.php @@ -525,6 +525,8 @@ protected function get_site_ids() { $where = implode( ' AND ', $this->sql_clauses['where'] ); + $groupby = ''; + $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); /** From 1d69cd0140776321e756c77dfe55d63546da9d1c Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 24 Oct 2018 22:11:30 -0400 Subject: [PATCH 04/10] fix more compat --- src/wp-admin/includes/ms.php | 2 +- src/wp-includes/class-wp-network-query.php | 1 + src/wp-includes/class-wp-site-query.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php index 220d6323e3562..4c0668494ec66 100644 --- a/src/wp-admin/includes/ms.php +++ b/src/wp-admin/includes/ms.php @@ -98,7 +98,7 @@ function wpmu_delete_blog( $blog_id, $drop = false ) { } // Don't destroy the initial, main, or root blog. - if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_network->path && $blog->domain == $current_network->domain ) ) ) { + if ( $drop && $blog && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_network->path && $blog->domain == $current_network->domain ) ) ) { $drop = false; } diff --git a/src/wp-includes/class-wp-network-query.php b/src/wp-includes/class-wp-network-query.php index 4ede8b7a278c9..398001513181c 100644 --- a/src/wp-includes/class-wp-network-query.php +++ b/src/wp-includes/class-wp-network-query.php @@ -283,6 +283,7 @@ public function get_networks() { protected function get_network_ids() { global $wpdb; + $limits = ''; $order = $this->parse_order( $this->query_vars['order'] ); // Disable ORDER BY with 'none', an empty array, or boolean false. diff --git a/src/wp-includes/class-wp-site-query.php b/src/wp-includes/class-wp-site-query.php index ffedeba850a7e..41f6ba9bd7647 100644 --- a/src/wp-includes/class-wp-site-query.php +++ b/src/wp-includes/class-wp-site-query.php @@ -327,6 +327,7 @@ public function get_sites() { protected function get_site_ids() { global $wpdb; + $limits = ''; $order = $this->parse_order( $this->query_vars['order'] ); // Disable ORDER BY with 'none', an empty array, or boolean false. From 215a38d1ff7a373a708e540b7476736e1912f9d4 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 25 Oct 2018 14:02:09 -0400 Subject: [PATCH 05/10] Move `$limits` default assignments closer to where their values can be changed. --- src/wp-includes/class-wp-network-query.php | 2 +- src/wp-includes/class-wp-site-query.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-network-query.php b/src/wp-includes/class-wp-network-query.php index 398001513181c..2b59e8a93b495 100644 --- a/src/wp-includes/class-wp-network-query.php +++ b/src/wp-includes/class-wp-network-query.php @@ -283,7 +283,6 @@ public function get_networks() { protected function get_network_ids() { global $wpdb; - $limits = ''; $order = $this->parse_order( $this->query_vars['order'] ); // Disable ORDER BY with 'none', an empty array, or boolean false. @@ -329,6 +328,7 @@ protected function get_network_ids() { $number = absint( $this->query_vars['number'] ); $offset = absint( $this->query_vars['offset'] ); + $limits = ''; if ( ! empty( $number ) ) { if ( $offset ) { diff --git a/src/wp-includes/class-wp-site-query.php b/src/wp-includes/class-wp-site-query.php index 41f6ba9bd7647..78fc59f58e823 100644 --- a/src/wp-includes/class-wp-site-query.php +++ b/src/wp-includes/class-wp-site-query.php @@ -327,7 +327,6 @@ public function get_sites() { protected function get_site_ids() { global $wpdb; - $limits = ''; $order = $this->parse_order( $this->query_vars['order'] ); // Disable ORDER BY with 'none', an empty array, or boolean false. @@ -373,6 +372,7 @@ protected function get_site_ids() { $number = absint( $this->query_vars['number'] ); $offset = absint( $this->query_vars['offset'] ); + $limits = ''; if ( ! empty( $number ) ) { if ( $offset ) { From 295abc0a2b32fb651fd898f6a26961e6ac5f8459 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 25 Oct 2018 16:55:05 -0400 Subject: [PATCH 06/10] Use `is_string()` instead of `is_numeric()` in the first check to be a little more readable. Add string checks for the second conditional further down. --- src/wp-includes/nav-menu.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 855bf268cedaa..fa97a4f6852df 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -1139,9 +1139,10 @@ 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 === is_numeric( $new_location ) && 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 ){ + } elseif ( is_numeric( $new_location ) && $new_location !== $slug ) { continue; } @@ -1152,7 +1153,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; } From 8af68b027757c467a35e315d92f7945f0cef51f9 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 25 Oct 2018 17:02:03 -0400 Subject: [PATCH 07/10] `is_numeric()` call should be superfluous now. --- src/wp-includes/nav-menu.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index fa97a4f6852df..35f6441e5b3b1 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -1142,7 +1142,7 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat if ( is_string( $new_location ) && false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) { continue; - } elseif ( is_numeric( $new_location ) && $new_location !== $slug ) { + } elseif ( $new_location !== $slug ) { continue; } @@ -1155,7 +1155,7 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat // ... have a match as well. if ( is_string( $location ) && false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) { continue; - } elseif ( is_numeric( $location ) && $location !== $slug ) { + } elseif ( $location !== $slug ) { continue; } From d2babea04db5e37aeec34c8da212751bc530a2d5 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 25 Oct 2018 17:15:05 -0400 Subject: [PATCH 08/10] Revert "`is_numeric()` call should be superfluous now." This reverts commit 8af68b027757c467a35e315d92f7945f0cef51f9. --- src/wp-includes/nav-menu.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 35f6441e5b3b1..fa97a4f6852df 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -1142,7 +1142,7 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat if ( is_string( $new_location ) && false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) { continue; - } elseif ( $new_location !== $slug ) { + } elseif ( is_numeric( $new_location ) && $new_location !== $slug ) { continue; } @@ -1155,7 +1155,7 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat // ... have a match as well. if ( is_string( $location ) && false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) { continue; - } elseif ( $location !== $slug ) { + } elseif ( is_numeric( $location ) && $location !== $slug ) { continue; } From 2a248e9a9f667d8a127319eb1763b2773cd09917 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Fri, 26 Oct 2018 15:29:34 -0400 Subject: [PATCH 09/10] Add test for when old theme locations were registered with an integer. --- src/wp-includes/nav-menu.php | 3 +-- tests/phpunit/tests/menu/nav-menu.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index fa97a4f6852df..74214c6636440 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -1139,8 +1139,7 @@ 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 ( is_string( $new_location ) && 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; diff --git a/tests/phpunit/tests/menu/nav-menu.php b/tests/phpunit/tests/menu/nav-menu.php index b0da967b8b9a3..ce13640602ed1 100644 --- a/tests/phpunit/tests/menu/nav-menu.php +++ b/tests/phpunit/tests/menu/nav-menu.php @@ -200,4 +200,28 @@ 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() + */ + function test_numerical_old_locations() { + $this->register_nav_menu_locations( array( 'primary', 1 ) ); + + $old_nav_menu_locations = array( + 'primary' => 1, + 1 => 2, + 'tertiary' => 3, + ); + + $old_next_theme_nav_menu_locations = array(); + $new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $old_next_theme_nav_menu_locations, $old_nav_menu_locations ); + + $expected_nav_menu_locations = array( + 'primary' => 1, + 1 => 2, + ); + $this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations ); + } } From b8abc8a02ab4a6e5a1c96a9135af69751556869e Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 15 Nov 2018 15:40:07 -0500 Subject: [PATCH 10/10] Update new test method. --- tests/phpunit/tests/menu/nav-menu.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/menu/nav-menu.php b/tests/phpunit/tests/menu/nav-menu.php index ce13640602ed1..d8fbd6b92fee9 100644 --- a/tests/phpunit/tests/menu/nav-menu.php +++ b/tests/phpunit/tests/menu/nav-menu.php @@ -206,22 +206,23 @@ function test_numerical_locations() { * * @covers wp_map_nav_menu_locations() */ - function test_numerical_old_locations() { + public function test_numerical_old_locations() { $this->register_nav_menu_locations( array( 'primary', 1 ) ); $old_nav_menu_locations = array( - 'primary' => 1, - 1 => 2, - 'tertiary' => 3, + 'primary' => 1, + 'tertiary' => 2, + 0 => 3, ); - $old_next_theme_nav_menu_locations = array(); - $new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $old_next_theme_nav_menu_locations, $old_nav_menu_locations ); + $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, - 1 => 2, + 0 => 3, ); + $this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations ); } }