Make WordPress Core

Opened 2 years ago

Last modified 7 months ago

#24548 new defect (bug)

_wp_menu_item_classes_by_context assumes $queried_object->ancestors is an array

Reported by: wpsmith Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-patch dev-feedback
Focuses: Cc:


Recently, on a site using CPT-onomies, I ran into an interesting error with _wp_menu_item_classes_by_context().

In this function, when setting the parent class, there is a large if statement that assumes that $queried_object->ancestors and $possible_taxonomy_ancestors[ $parent_item->object ] are arrays.

Attachments (1)

nav-menu-template.php.24548.patch (948 bytes) - added by wpsmith 2 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 @wonderboymusic20 months ago

  • Milestone changed from Awaiting Review to 3.9

This function...

comment:2 follow-up: @nacin19 months ago

  • Keywords reporter-feedback added; dev-feedback removed
  • Milestone changed from 3.9 to Awaiting Review

When are either of these not arrays?

For the first one, post objects always return get_post_ancestors(), which always returns an array. (It briefly did not: #22882.)

For the second one, that array must be set (the line above it) before it is treated as an array. It is set to be an array within the function.

comment:3 in reply to: ↑ 2 @wpsmith12 months ago

  • Keywords dev-feedback added; reporter-feedback removed

Replying to nacin:

When are either of these not arrays?

In WP_Query::get_queried_object() it is initialized as null: $this->queried_object = null; in wp-includes/query.php.

comment:4 @DrewAPicture7 months ago

#31630 was marked as a duplicate.

Note: See TracTickets for help on using tickets.