Make WordPress Core

Changeset 58119


Ignore:
Timestamp:
05/08/2024 06:35:10 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r56192 r58119  
    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                }
    … …  
    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(
    … …  
    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
    … …  
    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.
    … …  
    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' ) ) {
    … …  
    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;
    … …  
    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                        }
Note: See TracChangeset for help on using the changeset viewer.