You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request attempts to fix an undefined key warning.
Why?
At a few WordPress websites I manage, I've been regularly seeing these kinds of errors generated for a while now:
[18-Apr-2025 07:53:08 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[18-Apr-2025 07:53:08 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[18-Apr-2025 21:45:39 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[18-Apr-2025 21:45:39 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[18-Apr-2025 21:49:35 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[18-Apr-2025 21:49:35 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 00:17:29 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 00:17:29 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 00:17:29 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 00:17:29 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 08:46:34 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 08:46:34 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 10:20:02 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 10:20:02 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 10:58:54 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
[19-Apr-2025 10:58:54 UTC] PHP Warning: Undefined array key "url" in /home/[REDACTED]/public_html/wp-includes/blocks/navigation-submenu.php on line 91
Seeing as the solution seems simple enough and hasn't yet been implemented, I decided to try submitting a pull request here to address it (which, if accepted, I assume will eventually find its way upstream and into some future WordPress update at some point in the future).
Although I'm not entirely sure of the exact state and circumstances of the implementation at the time when the error occurs (i.e., the elements available to $attributes, as populated at the points where the function is called/invoked), a simple isset() check feels the most simple, direct, and logical solution for the problem. At most other points in the affected function where an element of $attributes is used, its use is similarly preceded by an isset() check; the exception which this pull request addresses is one of the very few exceptions. This pull request brings that exception into line with the various other points of use which are preceded by isset().
How?
Uses isset() to check the existence of the key before attempting to compare it.
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.
If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
đź‘‹ Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Maikuolan! In case you missed it, we'd love to have you join us in our Slack community.
If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
AFAIK, there is no way to empty url attribute from the UI, but we can remove the attribute from the block via the code editor, which causes the issue reported.
This PR makes sense to me, but do you mind updating the Navigation Link block as well?
Sorry, I found the more ideal logic. The current PR executes get_post_type_archive_link() even though $attributes['url'] is not set. Additionally, I think the empty() is better than isset() to skip the check when the URL is empty,
For better performance, I'd suggest the following logic:
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This pull request attempts to fix an undefined key warning.
Why?
At a few WordPress websites I manage, I've been regularly seeing these kinds of errors generated for a while now:
Seeing as the solution seems simple enough and hasn't yet been implemented, I decided to try submitting a pull request here to address it (which, if accepted, I assume will eventually find its way upstream and into some future WordPress update at some point in the future).
Although I'm not entirely sure of the exact state and circumstances of the implementation at the time when the error occurs (i.e., the elements available to
$attributes
, as populated at the points where the function is called/invoked), a simpleisset()
check feels the most simple, direct, and logical solution for the problem. At most other points in the affected function where an element of$attributes
is used, its use is similarly preceded by anisset()
check; the exception which this pull request addresses is one of the very few exceptions. This pull request brings that exception into line with the various other points of use which are preceded byisset()
.How?
Uses
isset()
to check the existence of the key before attempting to compare it.