Make WordPress Core

Changeset 58124


Ignore:
Timestamp:
05/09/2024 03:14:46 PM (6 weeks ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-includes/nav-menu-template.php.

Includes correcting a conditional in _wp_menu_item_classes_by_context() where $parent_item->object, which contains a string like page, was erroneously compared to the queried object's ID. The correct property to compare is $parent_item->object_id.

Follow-up to [14876], [14923], [14942], [15302], [16731], [16742], [22302], [47550], [47557], [47808].

Props aristath, poena, afercia, SergeyBiryukov.
See #60700.

File:
1 edited

Legend:

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

    r57987 r58124  
    419419            // If the menu item corresponds to the currently queried post or taxonomy object.
    420420        } elseif (
    421             $menu_item->object_id == $queried_object_id
     421            (int) $menu_item->object_id === $queried_object_id
    422422            && (
    423423                ( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
    424                     && $wp_query->is_home && $home_page_id == $menu_item->object_id )
     424                    && $wp_query->is_home && $home_page_id === (int) $menu_item->object_id )
    425425                || ( 'post_type' === $menu_item->type && $wp_query->is_singular )
    426426                || ( 'taxonomy' === $menu_item->type
    427427                    && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
    428                     && $queried_object->taxonomy == $menu_item->object )
     428                    && $queried_object->taxonomy === $menu_item->object )
    429429            )
    430430        ) {
     
    513513
    514514                // Give front page item the 'current-menu-item' class when extra query arguments are involved.
    515             } elseif ( $item_url == $front_page_url && is_front_page() ) {
     515            } elseif ( $item_url === $front_page_url && is_front_page() ) {
    516516                $classes[] = 'current-menu-item';
    517517            }
    518518
    519             if ( untrailingslashit( $item_url ) == home_url() ) {
     519            if ( untrailingslashit( $item_url ) === home_url() ) {
    520520                $classes[] = 'menu-item-home';
    521521            }
     
    524524        // Back-compat with wp_page_menu(): add "current_page_parent" to static home page link for any non-page query.
    525525        if ( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
    526             && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id
     526            && empty( $wp_query->is_page ) && $home_page_id === (int) $menu_item->object_id
    527527        ) {
    528528            $classes[] = 'current_page_parent';
     
    550550                    && is_post_type_hierarchical( $queried_object->post_type )
    551551                    && in_array( (int) $parent_item->object_id, $queried_object->ancestors, true )
    552                     && $parent_item->object != $queried_object->ID
     552                    && (int) $parent_item->object_id !== $queried_object->ID
    553553                ) ||
    554554
     
    560560                    && (
    561561                        ! isset( $queried_object->term_id ) ||
    562                         $parent_item->object_id != $queried_object->term_id
     562                        (int) $parent_item->object_id !== $queried_object->term_id
    563563                    )
    564564                )
Note: See TracChangeset for help on using the changeset viewer.