WordPress.org

Make WordPress Core

Changeset 8989


Ignore:
Timestamp:
09/26/08 06:43:53 (6 years ago)
Author:
westi
Message:

Theme update UI first pass. See #7519 props DD32.

Location:
trunk
Files:
6 edited

Legend:

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

    r8892 r8989  
    457457    if ( !empty( $role ) ) { 
    458458        $role->add_cap( 'install_plugins' ); 
     459        $role->add_cap( 'update_themes' ); 
    459460    } 
    460461} 
  • trunk/wp-admin/includes/update.php

    r8852 r8989  
    171171    $result = copy_dir($working_dir, $plugins_dir); 
    172172    if ( is_wp_error($result) ) { 
    173         //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. 
     173        $wp_filesystem->delete($working_dir, true); 
    174174        return $result; 
    175175    } 
     
    193193    return  $folder . '/' . $pluginfiles[0]; 
    194194} 
     195 
     196function wp_update_theme($theme, $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_themes' ); 
     204    if ( !isset( $current->response[ $theme ] ) ) 
     205        return new WP_Error('up_to_date', __('The theme is at the latest version.')); 
     206 
     207    $r = $current->response[ $theme ]; 
     208     
     209    $themes = get_themes(); 
     210    foreach ( (array) $themes as $this_theme ) { 
     211        if ( $this_theme['Stylesheet'] == $theme ) { 
     212            $theme_directory = preg_replace('!^/themes/!i', '', $this_theme['Stylesheet Dir']); 
     213            break; 
     214        } 
     215    } 
     216    unset($themes); 
     217 
     218    if ( empty($theme_directory) ) 
     219        return new WP_Error('theme_non_existant', __('Theme does not exist.')); 
     220 
     221    // Is a filesystem accessor setup? 
     222    if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) 
     223        WP_Filesystem(); 
     224 
     225    if ( ! is_object($wp_filesystem) ) 
     226        return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 
     227 
     228    if ( $wp_filesystem->errors->get_error_code() ) 
     229        return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 
     230 
     231    //Get the base plugin folder 
     232    $themes_dir = $wp_filesystem->wp_themes_dir(); 
     233    if ( empty($themes_dir) ) 
     234        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress Theme directory.')); 
     235 
     236    //And the same for the Content directory. 
     237    $content_dir = $wp_filesystem->wp_content_dir(); 
     238    if( empty($content_dir) ) 
     239        return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); 
     240 
     241    $themes_dir = trailingslashit( $themes_dir ); 
     242    $content_dir = trailingslashit( $content_dir ); 
     243 
     244    if ( empty($r->package) ) 
     245        return new WP_Error('no_package', __('Upgrade package not available.')); 
     246 
     247    // Download the package 
     248    apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $r['package'])); 
     249    $download_file = download_url($r['package']); 
     250 
     251    if ( is_wp_error($download_file) ) 
     252        return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message()); 
     253 
     254    $working_dir = $content_dir . 'upgrade/' . basename($theme_directory); 
     255 
     256    // Clean up working directory 
     257    if ( $wp_filesystem->is_dir($working_dir) ) 
     258        $wp_filesystem->delete($working_dir, true); 
     259 
     260    apply_filters('update_feedback', __('Unpacking the update')); 
     261    // Unzip package to working directory 
     262    $result = unzip_file($download_file, $working_dir); 
     263 
     264    // Once extracted, delete the package 
     265    unlink($download_file); 
     266 
     267    if ( is_wp_error($result) ) { 
     268        $wp_filesystem->delete($working_dir, true); 
     269        return $result; 
     270    } 
     271 
     272    //TODO: Is theme currently active? If so, set default theme 
     273    /* 
     274    if ( is_plugin_active($plugin) ) { 
     275        //Deactivate the plugin silently, Prevent deactivation hooks from running. 
     276        apply_filters('update_feedback', __('Deactivating the plugin')); 
     277        deactivate_plugins($plugin, true); 
     278    }*/ 
     279 
     280    // Remove the existing plugin. 
     281    apply_filters('update_feedback', __('Removing the old version of the theme')); 
     282    $deleted = $wp_filesystem->delete($themes_dir . $theme_directory, true); 
     283 
     284    if ( ! $deleted ) { 
     285        $wp_filesystem->delete($working_dir, true); 
     286        return new WP_Error('delete_failed', __('Could not remove the old plugin')); 
     287    } 
     288 
     289    apply_filters('update_feedback', __('Installing the latest version')); 
     290    // Copy new version of plugin into place. 
     291    $result = copy_dir($working_dir, $themes_dir); 
     292    if ( is_wp_error($result) ) { 
     293        $wp_filesystem->delete($working_dir, true); 
     294        return $result; 
     295    } 
     296 
     297    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 
     298    //$filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 
     299 
     300    // Remove working directory 
     301    $wp_filesystem->delete($working_dir, true); 
     302 
     303    // Force refresh of plugin update information 
     304    delete_option('update_themes'); 
     305 
     306    /*if( empty($filelist) ) 
     307        return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 
     308 
     309    $folder = $filelist[0]; 
     310    $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 
     311    $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 
     312 
     313    return  $folder . '/' . $pluginfiles[0];*/ 
     314} 
     315 
    195316 
    196317function wp_update_core($feedback = '') { 
  • trunk/wp-admin/includes/upgrade.php

    r8921 r8989  
    211211        upgrade_260(); 
    212212 
    213     if ( $wp_current_db_version < 8921 ) 
     213    if ( $wp_current_db_version < 8989 ) 
    214214        upgrade_270(); 
    215215 
     
    767767    global $wpdb, $wp_current_db_version; 
    768768 
    769     if ( $wp_current_db_version < 8530 ) 
     769    if ( $wp_current_db_version < 8980 ) 
    770770        populate_roles_270(); 
    771771 
  • trunk/wp-admin/themes.php

    r8656 r8989  
    5959 
    6060$themes = array_slice( $themes, $start, $per_page ); 
     61 
     62function theme_update_available( $theme ) { 
     63    static $themes_update; 
     64    if ( !isset($themes_update) ) 
     65        $themes_update = get_option('update_themes'); 
     66 
     67    if ( isset($theme->stylesheet) ) 
     68        $stylesheet = $theme->stylesheet; 
     69    elseif ( isset($theme['Stylesheet']) ) 
     70        $stylesheet = $theme['Stylesheet']; 
     71    else 
     72        return false; //No valid info passed. 
     73 
     74    if ( isset($themes_update->response[ $stylesheet ]) ) { 
     75        $update = $themes_update->response[ $stylesheet ]; 
     76        $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list. 
     77        $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet); 
     78 
     79        if ( ! current_user_can('update_themes') ) 
     80            printf( __('<p>There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.</p>'), $ct->name, $details_url, $update['new_version']); 
     81        else if ( empty($update->package) ) 
     82            printf( __('<p>There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this theme</em>.</p>'), $ct->name, $details_url, $update['new_version']); 
     83        else 
     84            printf( __('<p>There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s">upgrade automatically</a>.</p>'), $ct->name, $details_url, $update['new_version'], $update_url ); 
     85    } 
     86} 
    6187 
    6288?> 
     
    78104<p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p> 
    79105<?php endif; ?> 
     106<?php theme_update_available($ct); ?> 
     107 
    80108</div> 
    81109 
     
    142170<?php if ( $tags ) : ?> 
    143171        <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p> 
     172<?php endif; ?> 
     173        <?php theme_update_available( $themes[$theme_name] ); ?> 
    144174        <noscript><p class="themeactions"><a href="<?php echo $preview_link; ?>" title="<?php echo $preview_text; ?>"><?php _e('Preview'); ?></a> <a href="<?php echo $activate_link; ?>" title="<?php echo $activate_text; ?>"><?php _e('Activate'); ?></a></p></noscript> 
    145 <?php endif; ?> 
    146175        <div style="display:none;"><a class="previewlink" href="<?php echo $preview_link; ?>"><?php echo $preview_text; ?></a> <a class="activatelink" href="<?php echo $activate_link; ?>"><?php echo $activate_text; ?></a></div> 
    147176<?php endif; // end if not empty theme_name ?> 
  • trunk/wp-admin/update.php

    r8885 r8989  
    5757            show_message(__('Attempting reactivation of the plugin')); 
    5858            echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>'; 
     59        } 
     60    } 
     61    echo '</div>'; 
     62} 
     63 
     64/** 
     65 * Theme upgrade display. 
     66 * 
     67 * @since 2.5 
     68 * 
     69 * @param string $plugin Plugin 
     70 */ 
     71function do_theme_upgrade($theme) { 
     72    global $wp_filesystem; 
     73 
     74    $url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($theme), 'upgrade-plugin_' . urlencode($theme)); 
     75    if ( false === ($credentials = request_filesystem_credentials($url)) ) 
     76        return; 
     77 
     78    if ( ! WP_Filesystem($credentials) ) { 
     79        $error = true; 
     80        if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() ) 
     81            $error = $wp_filesystem->errors; 
     82        request_filesystem_credentials($url, '', $error); //Failed to connect, Error and request again 
     83        return; 
     84    } 
     85 
     86    echo '<div class="wrap">'; 
     87    echo '<h2>' . __('Upgrade Theme') . '</h2>'; 
     88    if ( $wp_filesystem->errors->get_error_code() ) { 
     89        foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 
     90            show_message($message); 
     91        echo '</div>'; 
     92        return; 
     93    } 
     94 
     95    //TODO: Is theme currently active? 
     96    $was_current = false; //is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is 
     97 
     98    $result = wp_update_theme($theme, 'show_message'); 
     99 
     100    if ( is_wp_error($result) ) { 
     101        show_message($result); 
     102        show_message( __('Installation Failed') ); 
     103    } else { 
     104        //Result is the new plugin file relative to WP_PLUGIN_DIR 
     105        show_message( __('Theme upgraded successfully') ); 
     106        if( $result && $was_current ){ 
     107            show_message(__('Setting theme as Current')); 
     108            //TODO: Actually set it as active again. 
     109            //echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>'; 
    59110        } 
    60111    } 
     
    145196if ( isset($_GET['action']) ) { 
    146197    $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : ''; 
    147  
    148     if ( 'upgrade-plugin' == $_GET['action'] ) { 
     198    $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : ''; 
     199    $action = isset($_GET['action']) ? $_GET['action'] : ''; 
     200     
     201    if ( 'upgrade-plugin' == $action ) { 
    149202        check_admin_referer('upgrade-plugin_' . $plugin); 
    150203        $title = __('Upgrade Plugin'); 
     
    153206        do_plugin_upgrade($plugin); 
    154207        include('admin-footer.php'); 
    155     } elseif ('activate-plugin' == $_GET['action'] ) { 
     208    } elseif ('activate-plugin' == $action ) { 
    156209        check_admin_referer('activate-plugin_' . $plugin); 
    157210        if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) { 
     
    183236        } 
    184237        echo "</body></html>"; 
    185     } elseif ( 'upgrade-core' == $_GET['action'] ) { 
     238    } elseif ( 'upgrade-core' == $action ) { 
    186239        $title = __('Upgrade WordPress'); 
    187240        $parent_file = 'index.php'; 
     
    189242        core_upgrade_preamble(); 
    190243        include('admin-footer.php'); 
    191     } elseif ( 'do-core-upgrade' ) { 
     244    } elseif ( 'do-core-upgrade' == $action ) { 
    192245        check_admin_referer('upgrade-core'); 
    193246        $title = __('Upgrade WordPress'); 
     
    196249        do_core_upgrade(); 
    197250        include('admin-footer.php'); 
     251    } elseif ( 'upgrade-theme' == $action ) {    
     252        check_admin_referer('upgrade-theme_' . $theme); 
     253        $title = __('Upgrade Theme'); 
     254        $parent_file = 'themes.php'; 
     255        require_once('admin-header.php'); 
     256        do_theme_upgrade($theme); 
     257        include('admin-footer.php'); 
    198258    } 
    199259} 
  • trunk/wp-includes/version.php

    r8921 r8989  
    1616 * @global int $wp_db_version 
    1717 */ 
    18 $wp_db_version = 8921; 
     18$wp_db_version = 8989; 
    1919 
    2020?> 
Note: See TracChangeset for help on using the changeset viewer.