Skip to content

Commit

Permalink
Coding Standards: Use strict comparison in `wp-includes/nav-menu-temp…
Browse files Browse the repository at this point in the history
…late.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.

git-svn-id: https://develop.svn.wordpress.org/trunk@58124 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed May 9, 2024
1 parent 08b4dd3 commit 9c39283
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/wp-includes/nav-menu-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,14 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {

// If the menu item corresponds to the currently queried post or taxonomy object.
} elseif (
$menu_item->object_id == $queried_object_id
(int) $menu_item->object_id === $queried_object_id
&& (
( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
&& $wp_query->is_home && $home_page_id == $menu_item->object_id )
&& $wp_query->is_home && $home_page_id === (int) $menu_item->object_id )
|| ( 'post_type' === $menu_item->type && $wp_query->is_singular )
|| ( 'taxonomy' === $menu_item->type
&& ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
&& $queried_object->taxonomy == $menu_item->object )
&& $queried_object->taxonomy === $menu_item->object )
)
) {
$classes[] = 'current-menu-item';
Expand Down Expand Up @@ -512,18 +512,18 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
$active_object = $menu_item->object;

// Give front page item the 'current-menu-item' class when extra query arguments are involved.
} elseif ( $item_url == $front_page_url && is_front_page() ) {
} elseif ( $item_url === $front_page_url && is_front_page() ) {
$classes[] = 'current-menu-item';
}

if ( untrailingslashit( $item_url ) == home_url() ) {
if ( untrailingslashit( $item_url ) === home_url() ) {
$classes[] = 'menu-item-home';
}
}

// Back-compat with wp_page_menu(): add "current_page_parent" to static home page link for any non-page query.
if ( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
&& empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id
&& empty( $wp_query->is_page ) && $home_page_id === (int) $menu_item->object_id
) {
$classes[] = 'current_page_parent';
}
Expand All @@ -549,7 +549,7 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
&& ! empty( $queried_object->post_type )
&& is_post_type_hierarchical( $queried_object->post_type )
&& in_array( (int) $parent_item->object_id, $queried_object->ancestors, true )
&& $parent_item->object != $queried_object->ID
&& (int) $parent_item->object_id !== $queried_object->ID
) ||

// Ancestral term.
Expand All @@ -559,7 +559,7 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
&& in_array( (int) $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ], true )
&& (
! isset( $queried_object->term_id ) ||
$parent_item->object_id != $queried_object->term_id
(int) $parent_item->object_id !== $queried_object->term_id
)
)
)
Expand Down

0 comments on commit 9c39283

Please sign in to comment.