Skip to content

Commit 45a3d53

Browse files
Coding Standards: Use strict comparison in wp-includes/nav-menu.php.
Follow-up to [14248], [14285], [14878], [15008], [22235], [23897], [23941], [27150]. Props dhruvang21, aristath, poena, afercia, SergeyBiryukov. Fixes #61160. See #60700. git-svn-id: https://develop.svn.wordpress.org/trunk@58119 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 15e4edb commit 45a3d53

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

src/wp-includes/nav-menu.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function wp_delete_nav_menu( $menu ) {
280280
// Remove this menu from any locations.
281281
$locations = get_nav_menu_locations();
282282
foreach ( $locations as $location => $menu_id ) {
283-
if ( $menu_id == $menu->term_id ) {
283+
if ( $menu_id === $menu->term_id ) {
284284
$locations[ $location ] = 0;
285285
}
286286
}
@@ -331,7 +331,7 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
331331
$_possible_existing &&
332332
! is_wp_error( $_possible_existing ) &&
333333
isset( $_possible_existing->term_id ) &&
334-
$_possible_existing->term_id != $menu_id
334+
$_possible_existing->term_id !== $menu_id
335335
) {
336336
return new WP_Error(
337337
'menu_exists',
@@ -458,12 +458,22 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
458458

459459
$args = wp_parse_args( $menu_item_data, $defaults );
460460

461-
if ( 0 == $menu_id ) {
461+
if ( 0 === $menu_id ) {
462462
$args['menu-item-position'] = 1;
463-
} elseif ( 0 == (int) $args['menu-item-position'] ) {
464-
$menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
465-
$last_item = array_pop( $menu_items );
466-
$args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items );
463+
} elseif ( 0 === (int) $args['menu-item-position'] ) {
464+
$menu_items = array();
465+
466+
if ( 0 !== $menu_id ) {
467+
$menu_items = (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
468+
}
469+
470+
$last_item = array_pop( $menu_items );
471+
472+
if ( $last_item && isset( $last_item->menu_order ) ) {
473+
$args['menu-item-position'] = 1 + $last_item->menu_order;
474+
} else {
475+
$args['menu-item-position'] = count( $menu_items );
476+
}
467477
}
468478

469479
$original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;
@@ -522,7 +532,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
522532
$post['post_date'] = $post_date;
523533
}
524534

525-
$update = 0 != $menu_item_db_id;
535+
$update = 0 !== $menu_item_db_id;
526536

527537
// New menu item. Default is draft status.
528538
if ( ! $update ) {
@@ -582,7 +592,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
582592
update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );
583593
update_post_meta( $menu_item_db_id, '_menu_item_url', sanitize_url( $args['menu-item-url'] ) );
584594

585-
if ( 0 == $menu_id ) {
595+
if ( 0 === $menu_id ) {
586596
update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() );
587597
} elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) {
588598
delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' );
@@ -1059,7 +1069,7 @@ function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_
10591069
} elseif (
10601070
'taxonomy' === $object_type &&
10611071
'taxonomy' === $menu_item_type &&
1062-
get_post_meta( $menu_item->ID, '_menu_item_object', true ) == $taxonomy
1072+
get_post_meta( $menu_item->ID, '_menu_item_object', true ) === $taxonomy
10631073
) {
10641074
$menu_item_ids[] = (int) $menu_item->ID;
10651075
}
@@ -1146,7 +1156,7 @@ function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
11461156
continue;
11471157
}
11481158
foreach ( $items as $item ) {
1149-
if ( $post->ID == $item->object_id ) {
1159+
if ( $post->ID === (int) $item->object_id ) {
11501160
continue 2;
11511161
}
11521162
}

0 commit comments

Comments
 (0)