Fix undefined variables and do_enclose bug - #12721
Conversation
Initialize undefined variables in several functions to prevent PHP 8.2+ warnings (in single_month_title, get_the_generator, WP_HTML_Processor, wp_mime_type_icon, and _wp_privacy_send_request_confirmation_notification). Fix a bug in do_enclose() where the enclosure meta was storing the variable name 'mime' instead of the actual MIME type variable '$type'. Add aria-hidden attribute to dashicons span for improved accessibility, and add test coverage for the do_enclose fix with no-extension content types.
|
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 was a problem hiding this comment.
Pull request overview
This PR improves WordPress core’s PHP 8.2+ compatibility by eliminating undefined-variable warnings in several functions, fixes an enclosure metadata bug in do_enclose(), adds a small accessibility enhancement in the plugins list table, and extends PHPUnit coverage for the enclosure fix.
Changes:
- Initialize variables to avoid undefined-variable warnings in
single_month_title(),get_the_generator(),WP_HTML_Processor,wp_mime_type_icon(), and_wp_privacy_send_request_confirmation_notification(). - Fix
do_enclose()to persist the actual detected MIME type ($type) into theenclosurepost meta instead of the incorrect/undefined$mime. - Add
aria-hidden="true"to a decorative dashicon span and add a PHPUnit dataset/mocking to cover extensionless media URLs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/phpunit/tests/functions/doEnclose.php | Adds coverage for do_enclose() handling of URLs without file extensions by mocking headers based on path content. |
| src/wp-includes/user.php | Initializes $manage_url to avoid undefined-variable warnings for non-standard privacy actions. |
| src/wp-includes/post.php | Initializes $icon before MIME matching to avoid undefined-variable warnings when filtered. |
| src/wp-includes/html-api/class-wp-html-processor.php | Initializes $node prior to stack traversal to avoid undefined-variable warnings. |
| src/wp-includes/general-template.php | Initializes $my_year/$my_month and $gen to avoid undefined-variable warnings in date title and generator output. |
| src/wp-includes/functions.php | Fixes enclosure postmeta to store $type (actual MIME type) rather than the incorrect $mime. |
| src/wp-admin/includes/class-wp-plugins-list-table.php | Improves accessibility by marking a decorative dashicon as aria-hidden. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Initialize undefined variables in several functions to prevent PHP 8.2+ warnings (in single_month_title, get_the_generator, WP_HTML_Processor, wp_mime_type_icon, and _wp_privacy_send_request_confirmation_notification).
Fix a bug in do_enclose() where the enclosure meta was storing the variable name 'mime' instead of the actual MIME type variable '$type'.
Add aria-hidden attribute to dashicons span for improved accessibility, and add test coverage for the do_enclose fix with no-extension content types.
Description
This PR addresses multiple PHP 8.2+ compatibility issues, undefined variable warnings, a bug in enclosure postmeta creation, accessibility improvements, and unit test coverage:
PHP 8.2+ Compatibility & Undefined Variable Fixes:
single_month_title(): Initialized$my_yearand$my_monthto preventE_WARNINGnotices when$monthnumis supplied without$year.get_the_generator(): Initialized$gento an empty string beforeswitch ( $type )to handle custom generator types passed via filters without throwing undefined variable warnings.WP_HTML_Processor::in_body_any_other_end_tag(): Initialized$node = nullprior to traversing open element stack to avoid undefined variable access when stack is empty.wp_mime_type_icon(): Initialized$icon = falsebefore mime type matching loop to guarantee definition when passed towp_mime_type_iconfilter._wp_privacy_send_request_confirmation_notification(): Initialized$manage_urlto avoid undefined variable warnings when custom privacy request actions are used.Fix
do_enclose()Bug:do_enclose()inwp-includes/functions.phpto use$typeinstead of undefined$mimewhen setting theenclosurepostmeta value. This resolves anE_WARNINGnotice under PHP 8+ and ensures the HTTPContent-Typeheader (e.g.video/mp4) is correctly persisted for URLs without extension mapping.Accessibility Improvements:
aria-hidden="true"to decorative<span class="dashicons dashicons-warning"></span>element in recovery mode notices withinclass-wp-plugins-list-table.phpto improve screen reader accessibility.Test Coverage:
header-type-no-extensionand HTTP response mocking intests/phpunit/tests/functions/doEnclose.phpto verifydo_enclose()processes extensionless media URLs without PHP 8 warnings.Trac ticket: https://core.trac.wordpress.org/ticket/65674
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity AI
Model(s): Gemini 3.6 Flash
Used for: Identifying PHP 8.2+ undefined variable warnings and
do_enclose()bug, generating unit test dataset, and assisting with code formatting. All code changes and tests were verified against static analysis tools and unit tests.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.