Repository navigation
Conversation
Covers `is_registered_sidebar()`, `wp_widget_description()`, `wp_sidebar_description()`, `wp_get_sidebar()` and `wp_get_widget_defaults()`, which had no tests. See #66502.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the sidebar and widget lookup test additions.
No open issues 🎉
What changed in this PR
Adds unit tests for five sidebar and widget lookup functions in src/wp-includes/widgets.php, covering the first group of work for ticket #66502. No production behavior changes.
Changes:
- Covers registration lookups, description escaping and filtering, sidebar retrieval, and widget defaults.
- Tests edge cases including missing registrations, non-scalar IDs, strict ID matching, and the inactive-sidebar fallback.
- Saves and restores registered sidebar and widget state around each test.
| File | Description |
|---|---|
tests/phpunit/tests/widgets/wpWidgetDescription.php |
Tests widget descriptions, HTML escaping, and missing or invalid inputs. |
tests/phpunit/tests/widgets/wpSidebarDescription.php |
Tests sidebar descriptions, markup filtering, and missing or invalid inputs. |
tests/phpunit/tests/widgets/wpGetWidgetDefaults.php |
Tests empty defaults, registration order, and exclusion of assigned widgets. |
tests/phpunit/tests/widgets/wpGetSidebar.php |
Tests sidebar retrieval, strict ID matching, and inactive-sidebar fallback precedence. |
tests/phpunit/tests/widgets/isRegisteredSidebar.php |
Tests registration status, unregistration, case sensitivity, and numeric IDs. |
Review effort: Balanced
Adds unit tests for five functions in
src/wp-includes/widgets.phpthat were not referenced by any test. This is the first of two groups of the work described in the ticket: it covers the functions that read the registered sidebars and widgets.is_active_sidebar(),is_dynamic_sidebar(),wp_find_widgets_sidebar()andwp_assign_widget_to_sidebar()follow in a second pull request. No behavior is changed.Functions covered, each in its own test class in
tests/phpunit/tests/widgets/:is_registered_sidebar()wp_widget_description()wp_sidebar_description()wp_kses_allowed_htmlfilter allows for thesidebar_descriptioncontext.wp_get_sidebar()wp_get_widget_defaults()The tests reset the registered sidebars and widgets, and restore them afterwards.
Testing:
vendor/bin/phpunit --filter 'Tests_Widgets_(IsRegisteredSidebar|WpWidgetDescription|WpSidebarDescription|WpGetSidebar|WpGetWidgetDefaults)'vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Widgets_(IsRegisteredSidebar|WpWidgetDescription|WpSidebarDescription|WpGetSidebar|WpGetWidgetDefaults)'vendor/bin/phpcs tests/phpunit/tests/widgets/I also temporarily broke these functions in
src/wp-includes/widgets.php(always returning true, the escaping of the widget description, the check of a scalar ID in both description functions, the call towp_kses()and its context, the strict comparison of the ID, the fallback for the inactive widgets sidebar and its priority over registered sidebars, and the contents and the order of the defaults) and confirmed that a new test fails for each one.Trac ticket: https://core.trac.wordpress.org/ticket/66502
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.
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.