Commit b22570ae16 for wordpress.org
commit b22570ae160145b4d1208bafa2c86956b731b216
Author: SergeyBiryukov <sergeybiryukov@git.wordpress.org>
Date: Sat Oct 31 23:40:54 2026 +0000
Menus: Simplify redundant conditions in `wp-includes/nav-menu.php`
Simplifies redundant conditional logic:
1. In `wp_update_nav_menu_object()`: The preceding `if ( ! $_menu || is_wp_error( $_menu ) )` block handles non-existing menu creation and returns, so $_menu is guaranteed truthy. Dropped the redundant `! $_menu` check before `isset( $_menu->term_id )`.
2. In `wp_update_nav_menu_item()`: In the `elseif ( 0 === (int) $args['menu-item-position'] )` block, `$menu_id` is guaranteed non-zero because the preceding `if ( 0 === $menu_id )` block already handled `$menu_id === 0`. Removed the redundant `if ( 0 !== $menu_id )` check.
3. In `wp_map_nav_menu_locations()`: $slug is an alphanumeric theme location key string; comparing non-string types with $slug is strictly always true. Simplified `is_numeric(...) && ... !== $slug` to `! is_string(...)`.
This resolves all `notIdentical.alwaysTrue` and `booleanNot.alwaysFalse` occurrences in `wp-includes/nav-menu.php`.
Developed in https://github.com/WordPress/wordpress-develop/pull/14931.
Props huzaifaalmesbah.
See #65817.
Built from https://develop.svn.wordpress.org/trunk@65159
git-svn-id: http://core.svn.wordpress.org/trunk@64308 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php
index ed49892ac0..40612d5b8d 100644
--- a/wp-includes/nav-menu.php
+++ b/wp-includes/nav-menu.php
@@ -374,7 +374,7 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
return (int) $_menu['term_id'];
}
- if ( ! $_menu || ! isset( $_menu->term_id ) ) {
+ if ( ! isset( $_menu->term_id ) ) {
return 0;
}
@@ -458,11 +458,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
if ( 0 === $menu_id ) {
$args['menu-item-position'] = 1;
} elseif ( 0 === (int) $args['menu-item-position'] ) {
- $menu_items = array();
-
- if ( 0 !== $menu_id ) {
- $menu_items = (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
- }
+ $menu_items = (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
$last_item = array_pop( $menu_items );
@@ -1281,7 +1277,7 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat
// ...actually match!
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_string( $new_location ) ) {
continue;
}
@@ -1294,7 +1290,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 ( ! is_string( $location ) ) {
continue;
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 12cd9b900c..da3cc34cf5 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-beta3-65158';
+$wp_version = '7.2-beta3-65159';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.