Make WordPress Core


Ignore:
Timestamp:
04/23/2021 02:49:51 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-admin/includes/update-core.php.

Includes minor code layout fixes for better readability.

See #52627.

File:
1 edited

Legend:

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

    r50561 r50785  
    925925    $distro = '';
    926926    $roots  = array( '/wordpress/', '/wordpress-mu/' );
     927
    927928    foreach ( $roots as $root ) {
    928         if ( $wp_filesystem->exists( $from . $root . 'readme.html' ) && $wp_filesystem->exists( $from . $root . 'wp-includes/version.php' ) ) {
     929        if ( $wp_filesystem->exists( $from . $root . 'readme.html' )
     930            && $wp_filesystem->exists( $from . $root . 'wp-includes/version.php' )
     931        ) {
    929932            $distro = $root;
    930933            break;
    931934        }
    932935    }
     936
    933937    if ( ! $distro ) {
    934938        $wp_filesystem->delete( $from, true );
     939
    935940        return new WP_Error( 'insane_distro', __( 'The update could not be unpacked' ) );
    936941    }
     
    943948     */
    944949    $versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
     950
    945951    if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) {
    946952        $wp_filesystem->delete( $from, true );
    947         return new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' );
     953
     954        return new WP_Error(
     955            'copy_failed_for_version_file',
     956            __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ),
     957            'wp-includes/version.php'
     958        );
    948959    }
    949960
     
    966977    $development_build = ( false !== strpos( $old_wp_version . $wp_version, '-' ) ); // A dash in the version indicates a development release.
    967978    $php_compat        = version_compare( $php_version, $required_php_version, '>=' );
     979
    968980    if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
    969981        $mysql_compat = true;
     
    10581070
    10591071        $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
     1072
    10601073        if ( is_array( $checksums ) && isset( $checksums[ $wp_version ] ) ) {
    10611074            $checksums = $checksums[ $wp_version ]; // Compat code for 3.7-beta2.
    10621075        }
     1076
    10631077        if ( is_array( $checksums ) ) {
    10641078            foreach ( $checksums as $file => $checksum ) {
     
    10661080                    continue;
    10671081                }
     1082
    10681083                if ( ! file_exists( ABSPATH . $file ) ) {
    10691084                    continue;
    10701085                }
     1086
    10711087                if ( ! file_exists( $working_dir_local . $file ) ) {
    10721088                    continue;
    10731089                }
    1074                 if ( '.' === dirname( $file ) && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true ) ) {
     1090
     1091                if ( '.' === dirname( $file )
     1092                    && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true )
     1093                ) {
    10751094                    continue;
    10761095                }
     1096
    10771097                if ( md5_file( ABSPATH . $file ) === $checksum ) {
    10781098                    $skip[] = $file;
     
    10871107    if ( $check_is_writable && 'direct' === $wp_filesystem->method ) {
    10881108        $files_writable = array_filter( $check_is_writable, array( $wp_filesystem, 'is_writable' ) );
     1109
    10891110        if ( $files_writable !== $check_is_writable ) {
    10901111            $files_not_writable = array_diff_key( $check_is_writable, $files_writable );
     1112
    10911113            foreach ( $files_not_writable as $relative_file_not_writable => $file_not_writable ) {
    10921114                // If the writable check failed, chmod file to 0644 and try again, same as copy_dir().
    10931115                $wp_filesystem->chmod( $file_not_writable, FS_CHMOD_FILE );
     1116
    10941117                if ( $wp_filesystem->is_writable( $file_not_writable ) ) {
    10951118                    unset( $files_not_writable[ $relative_file_not_writable ] );
     
    11011124
    11021125            if ( $files_not_writable ) {
    1103                 return new WP_Error( 'files_not_writable', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), implode( ', ', $error_data ) );
     1126                return new WP_Error(
     1127                    'files_not_writable',
     1128                    __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ),
     1129                    implode( ', ', $error_data )
     1130                );
    11041131            }
    11051132        }
     
    11081135    /** This filter is documented in wp-admin/includes/update-core.php */
    11091136    apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) );
     1137
    11101138    // Create maintenance file to signal that we are upgrading.
    11111139    $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
     
    11161144    /** This filter is documented in wp-admin/includes/update-core.php */
    11171145    apply_filters( 'update_feedback', __( 'Copying the required files&#8230;' ) );
     1146
    11181147    // Copy new versions of WP files into place.
    11191148    $result = _copy_dir( $from . $distro, $to, $skip );
     1149
    11201150    if ( is_wp_error( $result ) ) {
    1121         $result = new WP_Error( $result->get_error_code(), $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) );
     1151        $result = new WP_Error(
     1152            $result->get_error_code(),
     1153            $result->get_error_message(),
     1154            substr( $result->get_error_data(), strlen( $to ) )
     1155        );
    11221156    }
    11231157
     
    11261160        if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $to . 'wp-includes/version.php', true /* overwrite */ ) ) {
    11271161            $wp_filesystem->delete( $from, true );
    1128             $result = new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' );
    1129         }
     1162            $result = new WP_Error(
     1163                'copy_failed_for_version_file',
     1164                __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ),
     1165                'wp-includes/version.php'
     1166            );
     1167        }
     1168
    11301169        $wp_filesystem->chmod( $to . 'wp-includes/version.php', FS_CHMOD_FILE );
    11311170
     
    11421181    $skip   = array( 'wp-content' );
    11431182    $failed = array();
     1183
    11441184    if ( isset( $checksums ) && is_array( $checksums ) ) {
    11451185        foreach ( $checksums as $file => $checksum ) {
     
    11471187                continue;
    11481188            }
     1189
    11491190            if ( ! file_exists( $working_dir_local . $file ) ) {
    11501191                continue;
    11511192            }
    1152             if ( '.' === dirname( $file ) && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true ) ) {
     1193
     1194            if ( '.' === dirname( $file )
     1195                && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true )
     1196            ) {
    11531197                $skip[] = $file;
    11541198                continue;
    11551199            }
    1156             if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) == $checksum ) {
     1200
     1201            if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) === $checksum ) {
    11571202                $skip[] = $file;
    11581203            } else {
     
    11651210    if ( ! empty( $failed ) ) {
    11661211        $total_size = 0;
     1212
    11671213        foreach ( $failed as $file ) {
    11681214            if ( file_exists( $working_dir_local . $file ) ) {
     
    11741220        // Unlikely to be hit due to the check in unzip_file().
    11751221        $available_space = @disk_free_space( ABSPATH );
     1222
    11761223        if ( $available_space && $total_size >= $available_space ) {
    11771224            $result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ) );
    11781225        } else {
    11791226            $result = _copy_dir( $from . $distro, $to, $skip );
     1227
    11801228            if ( is_wp_error( $result ) ) {
    1181                 $result = new WP_Error( $result->get_error_code() . '_retry', $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) );
     1229                $result = new WP_Error(
     1230                    $result->get_error_code() . '_retry',
     1231                    $result->get_error_message(),
     1232                    substr( $result->get_error_data(), strlen( $to ) )
     1233                );
    11821234            }
    11831235        }
     
    11871239    // Copy languages.
    11881240    if ( ! is_wp_error( $result ) && $wp_filesystem->is_dir( $from . $distro . 'wp-content/languages' ) ) {
    1189         if ( WP_LANG_DIR != ABSPATH . WPINC . '/languages' || @is_dir( WP_LANG_DIR ) ) {
     1241        if ( WP_LANG_DIR !== ABSPATH . WPINC . '/languages' || @is_dir( WP_LANG_DIR ) ) {
    11901242            $lang_dir = WP_LANG_DIR;
    11911243        } else {
     
    12021254        if ( @is_dir( $lang_dir ) ) {
    12031255            $wp_lang_dir = $wp_filesystem->find_folder( $lang_dir );
     1256
    12041257            if ( $wp_lang_dir ) {
    12051258                $result = copy_dir( $from . $distro . 'wp-content/languages/', $wp_lang_dir );
     1259
    12061260                if ( is_wp_error( $result ) ) {
    1207                     $result = new WP_Error( $result->get_error_code() . '_languages', $result->get_error_message(), substr( $result->get_error_data(), strlen( $wp_lang_dir ) ) );
     1261                    $result = new WP_Error(
     1262                        $result->get_error_code() . '_languages',
     1263                        $result->get_error_message(),
     1264                        substr( $result->get_error_data(), strlen( $wp_lang_dir ) )
     1265                    );
    12081266                }
    12091267            }
     
    12131271    /** This filter is documented in wp-admin/includes/update-core.php */
    12141272    apply_filters( 'update_feedback', __( 'Disabling Maintenance mode&#8230;' ) );
     1273
    12151274    // Remove maintenance file, we're done with potential site-breaking changes.
    12161275    $wp_filesystem->delete( $maintenance_file );
    12171276
    1218     // 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users, preventing installation of Twenty Twelve.
     1277    // 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users,
     1278    // preventing installation of Twenty Twelve.
    12191279    if ( '3.5' === $old_wp_version ) {
    1220         if ( is_dir( WP_CONTENT_DIR . '/themes/twentytwelve' ) && ! file_exists( WP_CONTENT_DIR . '/themes/twentytwelve/style.css' ) ) {
     1280        if ( is_dir( WP_CONTENT_DIR . '/themes/twentytwelve' )
     1281            && ! file_exists( WP_CONTENT_DIR . '/themes/twentytwelve/style.css' )
     1282        ) {
    12211283            $wp_filesystem->delete( $wp_filesystem->wp_themes_dir() . 'twentytwelve/' );
    12221284        }
     
    12291291     * $development_build controls us overwriting bundled themes and plugins when a non-stable release is being updated.
    12301292     */
    1231     if ( ! is_wp_error( $result ) && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
     1293    if ( ! is_wp_error( $result )
     1294        && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED )
     1295    ) {
    12321296        foreach ( (array) $_new_bundled_files as $file => $introduced_version ) {
    12331297            // If a $development_build or if $introduced version is greater than what the site was previously running.
     
    12721336                            $result = new WP_Error;
    12731337                        }
    1274                         $result->add( $_result->get_error_code() . "_$type", $_result->get_error_message(), substr( $_result->get_error_data(), strlen( $dest ) ) );
     1338
     1339                        $result->add(
     1340                            $_result->get_error_code() . "_$type",
     1341                            $_result->get_error_message(),
     1342                            substr( $_result->get_error_data(), strlen( $dest ) )
     1343                        );
    12751344                    }
    12761345                }
     
    12821351    if ( is_wp_error( $result ) ) {
    12831352        $wp_filesystem->delete( $from, true );
     1353
    12841354        return $result;
    12851355    }
     
    12881358    foreach ( $_old_files as $old_file ) {
    12891359        $old_file = $to . $old_file;
     1360
    12901361        if ( ! $wp_filesystem->exists( $old_file ) ) {
    12911362            continue;
     
    13071378    /** This filter is documented in wp-admin/includes/update-core.php */
    13081379    apply_filters( 'update_feedback', __( 'Upgrading database&#8230;' ) );
     1380
    13091381    $db_upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' );
    13101382    wp_remote_post( $db_upgrade_url, array( 'timeout' => 60 ) );
     
    13881460                // If copy failed, chmod file to 0644 and try again.
    13891461                $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
     1462
    13901463                if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
    13911464                    return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
     
    14121485             */
    14131486            $sub_skip_list = array();
     1487
    14141488            foreach ( $skip_list as $skip_item ) {
    14151489                if ( 0 === strpos( $skip_item, $filename . '/' ) ) {
     
    14191493
    14201494            $result = _copy_dir( $from . $filename, $to . $filename, $sub_skip_list );
     1495
    14211496            if ( is_wp_error( $result ) ) {
    14221497                return $result;
     
    14241499        }
    14251500    }
     1501
    14261502    return true;
    14271503}
     
    15171593    foreach ( $affected_files as $file ) {
    15181594        $gen_dir = $wp_filesystem->find_folder( trailingslashit( dirname( $file ) ) );
     1595
    15191596        if ( empty( $gen_dir ) ) {
    15201597            continue;
     
    15471624    $files     = array();
    15481625
    1549     if ( file_exists( "{$directory}example.html" ) && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) ) {
     1626    if ( file_exists( "{$directory}example.html" )
     1627        && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' )
     1628    ) {
    15501629        $files[] = "{$directory}example.html";
    15511630    }
    15521631
    15531632    $dirs = glob( $directory . '*', GLOB_ONLYDIR );
     1633
    15541634    if ( $dirs ) {
    15551635        foreach ( $dirs as $dir ) {
Note: See TracChangeset for help on using the changeset viewer.