[wp-trac] [WordPress Trac] #37920: `the_title` filter called in 2 places inconsistently
WordPress Trac
noreply at wordpress.org
Fri Sep 2 14:20:22 UTC 2016
#37920: `the_title` filter called in 2 places inconsistently
--------------------------+-----------------------------
Reporter: joelworsham | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
This is a follow-up to #35317.
When calling `wp_nav_menu()` to build a frontend nav menu, the filter
`the_title` ends up being called 2 times on page links, due to the above
ticket.
It is called here https://github.com/WordPress/WordPress/blob/master/wp-
includes/nav-menu.php#L754
and then here https://github.com/WordPress/WordPress/blob/master/wp-
includes/class-walker-nav-menu.php#L169.
So it is called once when getting the post object title and then again
when actually outputting the nav menu.
I think this is negative for 2 reasons:
1) Anyone who wants to filter `the_title` for nav menu items will end up
having it called 2 different times, which is odd and can provide
inconsistency
2) In both cases, an object ID is included, but the first call the object
ID is the Post that the menu item links to (where the title comes from)
and the second call the object ID is the nav menu item ID. This means, if
a developer anticipates the 2 calls, they cannot check against the
supplied object ID to confirm operations only happen once.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37920>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list