-
Notifications
You must be signed in to change notification settings - Fork 3.2k
widgets: check if $wp_registered_widgets[ $widget ]['id'] exists #10710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
widgets: check if $wp_registered_widgets[ $widget ]['id'] exists #10710
Conversation
https://core.trac.wordpress.org/ticket/57518 This includes a test for this condition.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
There's one error: |
|
Thank you - I should have ran a broader set of the tests before pushing this. Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes a PHP warning that occurs when is_active_widget() attempts to access the 'id' key of an unregistered widget in the $wp_registered_widgets array. The issue arises when a widget exists in sidebars_widgets but hasn't been registered yet (e.g., during early plugin/theme loading).
Changes:
- Added an
isset()check before accessing$wp_registered_widgets[$widget]['id']to prevent warnings - Included a comprehensive test case to verify the fix handles unregistered widgets correctly
- Added defensive checks in existing sidebar tests to handle empty
$wp_registered_sidebarsarrays
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/wp-includes/widgets.php |
Adds isset() check to prevent accessing array offset on null when checking widget ID |
tests/phpunit/tests/widgets.php |
Adds test case to verify is_active_widget() handles unregistered widgets without warnings |
tests/phpunit/tests/widgets/wpBlockThemeRegisterClassicSidebar.php |
Adds safety guards to register test sidebars when none exist |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * This can happen when a widget is saved to a sidebar but the widget class | ||
| * has not yet been registered (e.g., during early plugin/theme loading). | ||
| * | ||
| * @ticket 58932 |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ticket number in the test's @ticket annotation is 58932, but the PR description references ticket 57518. Please verify which ticket number is correct and ensure consistency between the test annotation and the actual ticket being addressed.
| * @ticket 58932 | |
| * @ticket 57518 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josephscott Ah, this needs to be corrected, yes?
https://core.trac.wordpress.org/ticket/57518
This includes a test for this condition.
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.