Skip to content

Fix undefined variables and do_enclose bug - #12721

Open
murshed wants to merge 1 commit into
WordPress:trunkfrom
murshed:trunk
Open

Fix undefined variables and do_enclose bug#12721
murshed wants to merge 1 commit into
WordPress:trunkfrom
murshed:trunk

Conversation

@murshed

@murshed murshed commented Jul 27, 2026

Copy link
Copy Markdown

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:

  1. PHP 8.2+ Compatibility & Undefined Variable Fixes:

    • single_month_title(): Initialized $my_year and $my_month to prevent E_WARNING notices when $monthnum is supplied without $year.
    • get_the_generator(): Initialized $gen to an empty string before switch ( $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 = null prior to traversing open element stack to avoid undefined variable access when stack is empty.
    • wp_mime_type_icon(): Initialized $icon = false before mime type matching loop to guarantee definition when passed to wp_mime_type_icon filter.
    • _wp_privacy_send_request_confirmation_notification(): Initialized $manage_url to avoid undefined variable warnings when custom privacy request actions are used.
  2. Fix do_enclose() Bug:

    • Updated do_enclose() in wp-includes/functions.php to use $type instead of undefined $mime when setting the enclosure postmeta value. This resolves an E_WARNING notice under PHP 8+ and ensures the HTTP Content-Type header (e.g. video/mp4) is correctly persisted for URLs without extension mapping.
  3. Accessibility Improvements:

    • Added aria-hidden="true" to decorative <span class="dashicons dashicons-warning"></span> element in recovery mode notices within class-wp-plugins-list-table.php to improve screen reader accessibility.
  4. Test Coverage:

    • Added test dataset header-type-no-extension and HTTP response mocking in tests/phpunit/tests/functions/doEnclose.php to verify do_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.

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.
Copilot AI review requested due to automatic review settings July 27, 2026 16:55
@github-actions

Copy link
Copy Markdown

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 fahimmurshed.

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

@github-actions

Copy link
Copy Markdown

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

  • 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 the enclosure post 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.

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