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
@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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
## Description
The inline docs for
Walker_Nav_Menu::start_el()document the$data_objectparameter as aWP_Postobject. This is inaccurate: the menu item passed to the method is a decorated object produced bywp_setup_nav_menu_item(), which carries properties such as$title,$url,$xfn,$target, etc. that do not exist on a standardWP_Post.The type was changed from
objecttoWP_Postin [38559], but the underlying value is not a plainWP_Post.## Fix
Document
$data_objectasobject, which:Walker::start_el(), whose@paramisobject $data_object(the [5.9.0] rename was explicitly done "to match parent class");wp_setup_nav_menu_item(), which documents the decorated menu item asobject;WP_Post.This is a documentation-only change with no behavioral impact.
phpcspasses 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 asWP_Post; happy to align those in this PR or a follow-up if preferred.