Make WordPress Core


Ignore:
Timestamp:
10/24/2026 10:55:37 PM (4 days ago)
Author:
SergeyBiryukov
Message:

Code Quality: Remove a redundant is_wp_error() check after uploading 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 ​https://github.com/WordPress/wordpress-develop/pull/14778.

Props Soean.
See #65817.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/update.php

    r64352 r64694  
    180180                $result   = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) );
    181181
    182                 if ( $result || is_wp_error( $result ) ) {
     182                if ( $result ) {
    183183                        $file_upload->cleanup();
    184184                }
    … …  
    332332                $result   = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) );
    333333
    334                 if ( $result || is_wp_error( $result ) ) {
     334                if ( $result ) {
    335335                        $file_upload->cleanup();
    336336                }
Note: See TracChangeset for help on using the changeset viewer.