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.

* $wp_registered_widgets[ $widget ] exists, then tries to access
* $wp_registered_widgets[ $widget ]['id'] on the next line.
*/
$result = is_active_widget( false, 'search-2', 'search', true );
Copy link
Member

Choose a reason for hiding this comment

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

Confirmed that this causes a warning when the fix is not applied:

There was 1 error:

1) Tests_Widgets::test_is_active_widget_with_unregistered_widget_and_id_base_match
Undefined array key "search-2"

/var/www/src/wp-includes/widgets.php:928
/var/www/tests/phpunit/tests/widgets.php:1452

pento pushed a commit that referenced this pull request Jan 10, 2026
…s_active_widget()`.

This avoids a possible PHP warning due to an undefined array key.

Developed in #10710

Follow-up to [11090], [7080].
  
Props sageth, josephscott, Ipstenu, mindctrl, westonruter.
See #8441, #6023.
Fixes #57518.


git-svn-id: https://develop.svn.wordpress.org/trunk@61466 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions
Copy link

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 61466
GitHub commit: 376539e

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Jan 10, 2026
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jan 10, 2026
…s_active_widget()`.

This avoids a possible PHP warning due to an undefined array key.

Developed in WordPress/wordpress-develop#10710

Follow-up to [11090], [7080].
  
Props sageth, josephscott, Ipstenu, mindctrl, westonruter.
See #8441, #6023.
Fixes #57518.

Built from https://develop.svn.wordpress.org/trunk@61466


git-svn-id: http://core.svn.wordpress.org/trunk@60778 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Jan 10, 2026
…s_active_widget()`.

This avoids a possible PHP warning due to an undefined array key.

Developed in WordPress/wordpress-develop#10710

Follow-up to [11090], [7080].
  
Props sageth, josephscott, Ipstenu, mindctrl, westonruter.
See #8441, #6023.
Fixes #57518.

Built from https://develop.svn.wordpress.org/trunk@61466


git-svn-id: https://core.svn.wordpress.org/trunk@60778 1a063a9b-81f0-0310-95a4-ce76da25c4cd
aaronjorbin pushed a commit to aaronjorbin/wordpress-develop that referenced this pull request Jan 12, 2026
…s_active_widget()`.

This avoids a possible PHP warning due to an undefined array key.

Developed in WordPress#10710

Follow-up to [11090], [7080].
  
Props sageth, josephscott, Ipstenu, mindctrl, westonruter.
See WordPress#8441, WordPress#6023.
Fixes #57518.


git-svn-id: https://develop.svn.wordpress.org/trunk@61466 602fd350-edb4-49c9-b593-d223f7449a82
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