Make WordPress Core


Ignore:
Timestamp:
08/08/2008 10:49:35 PM (17 years ago)
Author:
ryan
Message:

Automatic upgrade, first cut. see #5560

File:
1 edited

Legend:

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

    r8589 r8595  
    1616    switch ( $cur->response ) {
    1717    case 'development' :
    18         return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please <a href="%s">stay updated</a>.' ), $GLOBALS['wp_version'], $cur->url, $cur->current );
     18        return sprintf( '| '.__( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), $GLOBALS['wp_version'], wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core'));
    1919    break;
    2020
    2121    case 'upgrade' :
    2222        if ( current_user_can('manage_options') ) {
    23             return sprintf( '| <strong>'.__( '<a href="%2$s">Get Version %3$s</a>' ).'</strong>', $GLOBALS['wp_version'], $cur->url, $cur->current );
     23            return sprintf( '| <strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core'), $cur->current);
    2424            break;
    2525        }
     
    2727    case 'latest' :
    2828    default :
    29         return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'], $cur->url, $cur->current );
     29        return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
    3030    break;
    3131    }
     
    4040
    4141    if ( current_user_can('manage_options') )
    42         $msg = sprintf( __('WordPress %2$s is available! <a href="%1$s">Please update now</a>.'), $cur->url, $cur->current );
     42        $msg = sprintf( __('WordPress %1$s is available! <a href="%2$s">Please update now</a>.'), $cur->current, wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') );
    4343    else
    44         $msg = sprintf( __('WordPress %2$s is available! Please notify the site administrator.'), $cur->url, $cur->current );
     44        $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current );
    4545
    4646    echo "<div id='update-nag'>$msg</div>";
     
    5454    $msg = sprintf( __('This is WordPress version %s.'), $GLOBALS['wp_version'] );
    5555    if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') )
    56         $msg .= " <a href='$cur->url' class='rbutton'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>';
     56        $msg .= " <a href='" . wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') . "' class='rbutton'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>';
    5757
    5858    echo "<span id='wp-version-message'>$msg</span>";
     
    194194}
    195195
     196function wp_update_core($feedback = '') {
     197    global $wp_filesystem;
     198
     199    if ( !empty($feedback) )
     200        add_filter('update_feedback', $feedback);
     201
     202    // Is an update available?
     203    $current = get_option( 'update_core' );
     204    if ( !isset( $current->response ) || $current->response == 'latest' )
     205        return new WP_Error('up_to_date', __('WordPress is at the latest version.'));
     206
     207    // Is a filesystem accessor setup?
     208    if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
     209        WP_Filesystem();
     210
     211    if ( ! is_object($wp_filesystem) )
     212        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
     213
     214    if ( $wp_filesystem->errors->get_error_code() )
     215        return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
     216
     217    // Get the base WP folder
     218    $wp_dir = $wp_filesystem->abspath();
     219    if ( empty($wp_dir) )
     220        return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.'));
     221
     222    // And the same for the Content directory.
     223    $content_dir = $wp_filesystem->wp_content_dir();
     224    if( empty($content_dir) )
     225        return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
     226   
     227    $wp_dir = trailingslashit( $wp_dir );
     228    $content_dir = trailingslashit( $content_dir );
     229
     230    // Get the URL to the zip file
     231    $package = $current->package;
     232
     233    // Download the package
     234    apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
     235    $download_file = download_url($package);
     236
     237    if ( is_wp_error($download_file) )
     238        return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
     239
     240    $working_dir = $content_dir . 'upgrade/core';
     241
     242    // Clean up working directory
     243    if ( $wp_filesystem->is_dir($working_dir) )
     244        $wp_filesystem->delete($working_dir, true);
     245
     246    apply_filters('update_feedback', __('Unpacking the update'));
     247    // Unzip package to working directory
     248    $result = unzip_file($download_file, $working_dir);
     249
     250    // Once extracted, delete the package
     251    unlink($download_file);
     252
     253    if ( is_wp_error($result) ) {
     254        $wp_filesystem->delete($working_dir, true);
     255        return $result;
     256    }
     257
     258    // Copy update-core.php from the new version into place.
     259    if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
     260        $wp_filesystem->delete($working_dir, true);
     261        return new WP_Error('copy_failed', __('Could not copy files'));
     262    }
     263
     264    require(ABSPATH . 'wp-admin/includes/update-core.php');
     265
     266    return update_core($working_dir, $wp_dir);
     267}
     268
    196269?>
Note: See TracChangeset for help on using the changeset viewer.