Skip to content

Conversation

@josephscott
Copy link
Contributor

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.

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

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.

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

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@westonruter
Copy link
Member

There's one error:

1) Tests_Widgets_WpBlockThemeRegisterClassicSidebars::test_should_reregister_previous_theme_sidebar
PHPUnit\Framework\InvalidArgumentException: Argument #1 of PHPUnit\Framework\Assert::assertArrayNotHasKey() must be an integer or string

/var/www/tests/phpunit/tests/widgets/wpBlockThemeRegisterClassicSidebar.php:54
phpvfscomposer:///var/www/vendor/phpunit/phpunit/phpunit:106
/var/www/vendor/bin/phpunit:118

@josephscott
Copy link
Contributor Author

Thank you - I should have ran a broader set of the tests before pushing this. Updated.

Copy link

Copilot AI left a 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_sidebars arrays

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
Copy link

Copilot AI Jan 10, 2026

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.

Suggested change
* @ticket 58932
* @ticket 57518

Copilot uses AI. Check for mistakes.
Copy link
Member

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?

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.

2 participants