Make WordPress Core

Opened 4 years ago

Last modified 4 months ago

#57428 new defect (bug)

Walker_Nav_Menu::start_el() $data_object is not a WP_Post

Reported by: jdamner Owned by:
Priority: normal Milestone: Awaiting Review
Component: Menus Version: 6.1.1
Severity: minor Keywords: has-patch
Cc: Focuses: docs

Description

The inline docs for Walker_Nav_menu::start_el() state that the $data_object parameter is a WP_Post object. This isn't accurate as the object that comes in has various properties such as $title and $url which do not exist on a standard WP_Post object.

The docs were changed from object to WP_Post here https://core.trac.wordpress.org/changeset/38559, but it's not clear why.

Proposed solutions would be to revert this to an object parameter, leaving it to the developer to find out what type of object is being passed in, or an improvement would be to define an object type for a Walker_Nav_Menu_Data_Object (likely extending WP_Post) that documents all possible/acceptable properties that would be expected to be able to be used in a walker.

Change History (2)

This ticket was mentioned in ​PR #12335 on ​WordPress/wordpress-develop by ​@aveeshek.


4 months ago
#1

  • Keywords has-patch added

## Description

The inline docs for Walker_Nav_Menu::start_el() document the $data_object parameter as a WP_Post object. This is inaccurate: the menu item passed to the method is a decorated object produced by wp_setup_nav_menu_item(), which carries properties such as $title, $url, $xfn, $target, etc. that do not exist on a standard WP_Post.

The type was changed from object to WP_Post in [38559], but the underlying value is not a plain WP_Post.

## Fix

Document $data_object as object, which:

  • matches the parent Walker::start_el(), whose @param is object $data_object (the [5.9.0] rename was explicitly done "to match parent class");
  • matches wp_setup_nav_menu_item(), which documents the decorated menu item as object;
  • accurately reflects that the object carries menu-item properties not present on WP_Post.

This is a documentation-only change with no behavioral impact. phpcs passes on the modified file.

## Notes for reviewers

Scope is intentionally limited to start_el() per the ticket. A few filter docblocks in the same file (e.g. nav_menu_item_args, nav_menu_css_class) describe the same menu-item object as WP_Post; happy to align those in this PR or a follow-up if preferred.

​@apermo commented on ​PR #12335:


4 months ago
#2

Good catch, did you verify that there are no related phpdocs that can be fixed alongside?

cc @westonruter

Note: See TracTickets for help on using tickets.