Skip to content

Check that menu items are objects in _wp_menu_item_classes_by_context() - #13721

Open
josephscott wants to merge 2 commits into
WordPress:trunkfrom
josephscott:66177/wp-nav-menu-object-check
Open

josephscott wants to merge 2 commits into
WordPress:trunkfrom
josephscott:66177/wp-nav-menu-object-check

Conversation

@josephscott

Copy link
Copy Markdown
Contributor

https://core.trac.wordpress.org/ticket/66177

AI assistance: Yes
Tool(s): Claude Code
Model(s): Fable 5.1
Used for: Review of the problem and solution. Claude wrote the test.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props josephscott, westonruter, therssoftware.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

…enu_item_id_use_once blanks for already-rendered items in a full test run.

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should do this.

See Trac comment.

@robelsust

Copy link
Copy Markdown

Tested and Verified ✅

Environment:

  • WordPress: 7.2-alpha (trunk)
  • PHP: 8.3

Reproduction & Verification:

  1. Before patch (trunk):
    Hooked into wp_get_nav_menu_items and returned an array with a null item:
    add_filter( 'wp_get_nav_menu_items', function ( $items ) {
        if ( ! empty( $items ) ) {
            $items[0] = null;
        }
        return $items;
    } );

Calling wp_nav_menu() fails with fatal error:
Fatal error: Uncaught Error: Attempt to assign property "current" on null in src/wp-includes/nav-menu-template.php:399

  1. After applying PR Check that menu items are objects in _wp_menu_item_classes_by_context() #13721:
    The fatal error is eliminated; non-object entries are safely stripped from $menu_items.
    The navigation menu renders as expected with the remaining valid items intact.
    Ran vendor/bin/phpunit --filter test_wp_nav_menu_should_skip_non_object_menu_items: Pass (OK (1 test, 2 assertions)).
    Ran full menu test suite vendor/bin/phpunit --group menu: Pass (OK (106 tests, 238 assertions)).
    PHPCS check: 0 errors, 0 warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants