Skip to content

Code Quality: Remove a redundant is_wp_error() check after uploading a plugin or theme - #14778

Open
Soean wants to merge 1 commit into
WordPress:trunkfrom
Soean:code-quality/update-php-redundant-is-wp-error
Open

Soean wants to merge 1 commit into
WordPress:trunkfrom
Soean:code-quality/update-php-redundant-is-wp-error

Conversation

@Soean

@Soean Soean commented Oct 23, 2026

Copy link
Copy Markdown
Member

After a plugin or theme is installed from an uploaded ZIP file in wp-admin/update.php, the upload is cleaned up when $result || is_wp_error( $result ). A WP_Error is an object and therefore always truthy, so the first operand already covers it and the is_wp_error() call can never return true. PHPStan reports this as function.impossibleType.

The condition is reduced to if ( $result ), which behaves identically: a failed installation still cleans up the upload, and only false, which WP_Upgrader::run() returns when filesystem credentials are requested, keeps the upload so it is still there once the credentials are entered.

This empties the function.impossibleType baseline, so the file and its entry in phpstan.neon.dist are removed.

Trac ticket: https://core.trac.wordpress.org/ticket/65817


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.

…g a plugin or theme.

After a plugin or theme is installed from an uploaded ZIP file, the upload is cleaned up when `$result || is_wp_error( $result )`. A `WP_Error` is an object and so always truthy, which means the first operand already covers it and the `is_wp_error()` call can never return `true`. The condition is therefore reduced to `$result`, which behaves identically: the upload is still cleaned up after a failed installation, and only kept when `false` is returned because filesystem credentials are requested, so it is still there once they are entered.

This resolves the `function.impossibleType` errors reported by PHPStan, so that baseline is removed.

See #65817.
@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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props soean.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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

🟢 Approval recommended

Both conditions preserve existing behavior, and the baseline removal matches the two resolved warnings.

No open issues 🎉

What changed in this PR

Simplifies upload cleanup conditions for plugin and theme installations without changing behavior, and removes the resolved PHPStan baseline.

Changes:

  • Removes redundant is_wp_error() checks from both upload cleanup conditions.
  • Deletes the baseline covering the two resolved warnings and removes its configuration entry.
File Description
tests/​phpstan/​baselines/​function.impossibleType.neon Deletes the baseline for the two resolved warnings.
src/​wp-admin/​update.php Simplifies plugin and theme upload cleanup conditions.
phpstan.neon.dist Removes the deleted baseline’s include entry.

Review effort: Balanced

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! The changes look good to me, and CI passes.

wporg-sync pushed a commit that referenced this pull request Oct 24, 2026
…g a plugin or theme.

After a plugin or theme is installed from an uploaded ZIP file in `wp-admin/update.php`, the upload is cleaned up when `$result || is_wp_error( $result )`. A `WP_Error` is an object and therefore always truthy, so the first operand already covers it and the `is_wp_error()` call can never return `true`. PHPStan reports this as `function.impossibleType`.

The condition is reduced to `if ( $result )`, which behaves identically: a failed installation still cleans up the upload, and only `false`, which `WP_Upgrader::run()` returns when filesystem credentials are requested, keeps the upload so it is still there once the credentials are entered.

This empties the `function.impossibleType` baseline, so the file and its entry in `phpstan.neon.dist` are removed.

Developed in #14778.

Props Soean.
See #65817.

git-svn-id: https://develop.svn.wordpress.org/trunk@64694 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 24, 2026
…g a plugin or theme.

After a plugin or theme is installed from an uploaded ZIP file in `wp-admin/update.php`, the upload is cleaned up when `$result || is_wp_error( $result )`. A `WP_Error` is an object and therefore always truthy, so the first operand already covers it and the `is_wp_error()` call can never return `true`. PHPStan reports this as `function.impossibleType`.

The condition is reduced to `if ( $result )`, which behaves identically: a failed installation still cleans up the upload, and only `false`, which `WP_Upgrader::run()` returns when filesystem credentials are requested, keeps the upload so it is still there once the credentials are entered.

This empties the `function.impossibleType` baseline, so the file and its entry in `phpstan.neon.dist` are removed.

Developed in WordPress/wordpress-develop#14778.

Props Soean.
See #65817.
Built from https://develop.svn.wordpress.org/trunk@64694


git-svn-id: http://core.svn.wordpress.org/trunk@63844 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

3 participants