[wp-trac] [WordPress Trac] #58932: wp_setup_nav_menu_item() throws PHP warning when using virtual menu-items

WordPress Trac noreply at wordpress.org
Fri Jan 9 18:47:30 UTC 2026


#58932: wp_setup_nav_menu_item() throws PHP warning when using virtual menu-items
-------------------------------------------------+-------------------------
 Reporter:  apedog                               |       Owner:  joemcgill
     Type:  defect (bug)                         |      Status:  reviewing
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Menus                                |     Version:  5.4
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch reporter-feedback has-     |     Focuses:
  unit-tests                                     |
-------------------------------------------------+-------------------------

Comment (by josephscott):

 I've got a PR at https://github.com/WordPress/wordpress-develop/pull/10706
 that addresses this.

 - Adds a test for `get_post_states()` that checks to see if it does the
 right thing when given something other than a `WP_Post` object
 - Adds a check to `get_post_states()` that makes sure `$post` is an object
 before using it as one, in cases where it gets something else it now
 returns an empty array
 - Defense in depth, add a return value check from `get_post()` in `wp-
 includes/nav-menu.php` so that we only call `get_post_states()` when we
 have a `WP_Post` object

 There are other existing calls to `get_post_states()`, but they appear to
 safe because of other checks that happen before that point.

 This provides more defensive layers for existing and future code that
 makes use of `get_post_states()`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58932#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list