Changes between Initial Version and Version 1 of Ticket #63261
- Timestamp:
- 04/10/2025 09:16:26 PM (7 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #63261
- Property Focuses coding-standards removed
-
Ticket #63261 – Description
initial v1 1 1 == Description == 2 If a page and a taxonomy term (e.g., product_cat) share the same numeric ID, both can be incorrectly marked as active in menus (current-menu-item, aria-current="page").2 If a page and a taxonomy term (e.g., `product_cat`) share the same numeric ID, both can be incorrectly marked as active in menus (`current-menu-item`, `aria-current="page"`). 3 3 4 This occurs because WordPress checks only the object_idwhen determining the active menu item, without verifying that the object types match.4 This occurs because WordPress checks only the `object_id` when determining the active menu item, without verifying that the object types match. 5 5 6 6 == Steps to Reproduce == … … 8 8 Create a WordPress page (e.g., "About") — assume it has ID 23. 9 9 10 Create a WooCommerce product category that also ends up with term_id= 23.10 Create a WooCommerce product category that also ends up with `term_id` = 23. 11 11 12 12 Add both items to a navigation menu. 13 13 14 Visit the product category archive ( /product-category/boots/).14 Visit the product category archive (`/product-category/boots/`). 15 15 16 16 Observe that ''both'' menu items ("About" and "Boots") are marked as current. … … 23 23 24 24 == Cause == 25 In wp-includes/nav-menu-template.php, this comparison is made:25 In `wp-includes/nav-menu-template.php`, this comparison is made: 26 26 27 {{{php if ( $menu_item->object_id === $queried_object_id ) { $menu_item->current = true; } }}} 27 {{{#!php 28 if ( $menu_item->object_id === $queried_object_id ) { $menu_item->current = true; } 29 }}} 28 30 29 This does not check if the object type (e.g. page, product_cat) also matches.31 This does not check if the object type (e.g. `page`, `product_cat`) also matches. 30 32 31 33 == Proposed Fix == 32 34 Enhance the condition to ensure both ID and object type match: 33 35 34 {{{php $queried_object_type = ''; if ( isset( $queried_object->post_type ) ) { $queried_object_type = $queried_object->post_type; } elseif ( isset( $queried_object->taxonomy ) ) { $queried_object_type = $queried_object->taxonomy; } if ( (int) $menu_item->object_id === (int) $queried_object_id && $menu_item->object === $queried_object_type ) { $menu_item->current = true; } }}} 36 {{{#!php 37 $queried_object_type = ''; 38 if ( isset( $queried_object->post_type ) ) { 39 $queried_object_type = $queried_object->post_type; 40 } elseif ( isset( $queried_object->taxonomy ) ) { 41 $queried_object_type = $queried_object->taxonomy; 42 } 43 if ( (int) $menu_item->object_id === (int) $queried_object_id 44 && $menu_item->object === $queried_object_type ) { 45 $menu_item->current = true; 46 } 47 }}} 35 48 36 49 == Environment ==