Make WordPress Core


Ignore:
Timestamp:
09/21/2013 06:48:20 AM (13 years ago)
Author:
dd32
Message:

Upgrader: Perform a MD5 file verification check on the files during upgrade. This ensures that both a Partial upgrade build can be used, and that all the files were copied into place correctly.
Props pento for initial patch. Fixes #18201

File:
1 edited

Legend:

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

    r25421 r25540  
    8888}
    8989
     90/**
     91 * Gets and caches the checksums for the given versions of WordPress
     92 *
     93 * @since 3.7.0
     94 *
     95 * @param $version string|array A single version, or an array of versions to fetch
     96 *
     97 * @return bool|array False on failure, otherwise the array of checksums, keyed by version
     98 */
     99function get_core_checksums( $version ) {
     100        if ( ! is_array( $version ) )
     101                $version = array( $version );
     102
     103        $return = array();
     104
     105        // Check to see if we have cached copies available, if we do, no need to request them
     106        foreach ( $version as $i => $v ) {
     107                if ( $checksums = get_site_transient( "core_checksums_$v" ) ) {
     108                        unset( $version[ $i ] );
     109                        $return[ $v ] = $checksums;
     110                }
     111        }
     112
     113        // We had cached copies for all of the versions!
     114        if ( empty( $version ) )
     115                return $return;
     116
     117        $url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( array( 'version' => $version ), null, '&' );
     118
     119        if ( wp_http_supports( array( 'ssl' ) ) )
     120                $url = set_url_scheme( $url, 'https' );
     121
     122        $options = array(
     123                'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
     124        );
     125
     126        $response = wp_remote_get( $url, $options );
     127
     128        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     129                return false;
     130
     131        $body = trim( wp_remote_retrieve_body( $response ) );
     132        $body = json_decode( $body, true );
     133
     134        if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
     135                return false;
     136
     137        // Cache the checksums for later
     138        foreach ( $version as $v ) {
     139                set_site_transient( "core_checksums_$v", $body['checksums'][ $v ], HOUR_IN_SECONDS );
     140                $return[ $v ] = $body['checksums'][ $v ];
     141        }
     142
     143        // If the API didn't return anything for a version, explicitly set it's return value to false
     144        foreach ( $return as $v => $r ) {
     145                if ( empty( $r ) )
     146                        $return[ $v ] = false;
     147        }
     148
     149        return $return;
     150}
     151
    90152function dismiss_core_update( $update ) {
    91153        $dismissed = get_site_option( 'dismissed_update_core' );
Note: See TracChangeset for help on using the changeset viewer.