Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r19246 r21064  
    375375                $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
    376376                $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
    377                 $this->strings['deactivate_plugin'] = __('Deactivating the plugin&#8230;');
    378377                $this->strings['remove_old'] = __('Removing the old version of the plugin&#8230;');
    379378                $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
    … …  
    413412                // Force refresh of plugin update information
    414413                delete_site_transient('update_plugins');
     414                wp_cache_delete( 'plugins', 'plugins' );
    415415
    416416                return true;
    … …  
    457457                // Force refresh of plugin update information
    458458                delete_site_transient('update_plugins');
     459                wp_cache_delete( 'plugins', 'plugins' );
    459460        }
    460461
    … …  
    538539                // Force refresh of plugin update information
    539540                delete_site_transient('update_plugins');
     541                wp_cache_delete( 'plugins', 'plugins' );
    540542
    541543                return $results;
    … …  
    595597
    596598                if ( is_plugin_active($plugin) ) {
    597                         $this->skin->feedback('deactivate_plugin');
    598599                        //Deactivate the plugin silently, Prevent deactivation hooks from running.
    599600                        deactivate_plugins($plugin, true);
    … …  
    663664                $this->strings['process_failed'] = __('Theme install failed.');
    664665                $this->strings['process_success'] = __('Theme installed successfully.');
     666                /* translators: 1: theme name, 2: version */
     667                $this->strings['process_success_specific'] = __('Successfully installed the theme <strong>%1$s %2$s</strong>.');
     668                $this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed&#8230;');
     669                /* translators: 1: theme name, 2: version */
     670                $this->strings['parent_theme_prepare_install'] = __('Preparing to install <strong>%1$s %2$s</strong>&#8230;');
     671                /* translators: 1: theme name, 2: version */
     672                $this->strings['parent_theme_currently_installed'] = __('The parent theme, <strong>%1$s %2$s</strong>, is currently installed.');
     673                /* translators: 1: theme name, 2: version */
     674                $this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, <strong>%1$s %2$s</strong>.');
     675                $this->strings['parent_theme_not_found'] = __('<strong>The parent theme could not be found.</strong> You will need to install the parent theme, <strong>%s</strong>, before you can use this child theme.');
     676        }
     677
     678        function check_parent_theme_filter($install_result, $hook_extra, $child_result) {
     679                // Check to see if we need to install a parent theme
     680                $theme_info = $this->theme_info();
     681
     682                if ( ! $theme_info->parent() )
     683                        return $install_result;
     684
     685                $this->skin->feedback( 'parent_theme_search' );
     686
     687                if ( ! $theme_info->parent()->errors() ) {
     688                        $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display('Name'), $theme_info->parent()->display('Version') );
     689                        // We already have the theme, fall through.
     690                        return $install_result;
     691                }
     692
     693                // We don't have the parent theme, lets install it
     694                $api = themes_api('theme_information', array('slug' => $theme_info->get('Template'), 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
     695
     696                if ( ! $api || is_wp_error($api) ) {
     697                        $this->skin->feedback( 'parent_theme_not_found', $theme_info->get('Template') );
     698                        // Don't show activate or preview actions after install
     699                        add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') );
     700                        return $install_result;
     701                }
     702
     703                // Backup required data we're going to override:
     704                $child_api = $this->skin->api;
     705                $child_success_message = $this->strings['process_success'];
     706
     707                // Override them
     708                $this->skin->api = $api;
     709                $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version);
     710
     711                $this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version);
     712
     713                add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme.
     714
     715                // Install the parent theme
     716                $parent_result = $this->run( array(
     717                        'package' => $api->download_link,
     718                        'destination' => WP_CONTENT_DIR . '/themes',
     719                        'clear_destination' => false, //Do not overwrite files.
     720                        'clear_working' => true
     721                ) );
     722
     723                if ( is_wp_error($parent_result) )
     724                        add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') );
     725
     726                // Start cleaning up after the parents installation
     727                remove_filter('install_theme_complete_actions', '__return_false', 999);
     728
     729                // Reset child's result and data
     730                $this->result = $child_result;
     731                $this->skin->api = $child_api;
     732                $this->strings['process_success'] = $child_success_message;
     733
     734                return $install_result;
     735        }
     736
     737        function hide_activate_preview_actions($actions) {
     738                unset($actions['activate'], $actions['preview']);
     739                return $actions;
    665740        }
    666741
    … …  
    671746
    672747                add_filter('upgrader_source_selection', array(&$this, 'check_package') );
     748                add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
    673749
    674750                $options = array(
    … …  
    682758
    683759                remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
     760                remove_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
    684761
    685762                if ( ! $this->result || is_wp_error($this->result) )
    … …  
    688765                // Force refresh of theme update information
    689766                delete_site_transient('update_themes');
     767                search_theme_directories( true );
     768                foreach ( wp_get_themes() as $theme )
     769                        $theme->cache_delete();
    690770
    691771                return true;
    … …  
    734814                // Force refresh of theme update information
    735815                delete_site_transient('update_themes');
     816                search_theme_directories( true );
     817                foreach ( wp_get_themes() as $theme )
     818                        $theme->cache_delete();
    736819
    737820                return true;
    … …  
    821904                // Force refresh of theme update information
    822905                delete_site_transient('update_themes');
     906                search_theme_directories( true );
     907                foreach ( wp_get_themes() as $theme )
     908                        $theme->cache_delete();
    823909
    824910                return $results;
    … …  
    836922                        return $source;
    837923
    838                 if ( ! file_exists( $working_directory . 'style.css' ) ) // A proper archive should have a style.css file in the single subdirectory
     924                // A proper archive should have a style.css file in the single subdirectory
     925                if ( ! file_exists( $working_directory . 'style.css' ) )
    839926                        return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
    840927
    841                 $info = get_theme_data( $working_directory . 'style.css' );
    842                 if ( empty($info['Name']) )
     928                $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
     929
     930                if ( empty( $info['Name'] ) )
    843931                        return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
    844932
    845                 if ( empty($info['Template']) && ! file_exists( $working_directory . 'index.php' ) ) // If no template is set, it must have at least an index.php to be legit.
     933                // If it's not a child theme, it must have at least an index.php to be legit.
     934                if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) )
    846935                        return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
    847936
    … …  
    871960                $theme = isset($theme['theme']) ? $theme['theme'] : '';
    872961
    873                 if ( $theme != get_stylesheet() ) //If not current
     962                if ( $theme != get_stylesheet() ) // If not current
    874963                        return $return;
    875964
    876                 //Ensure stylesheet name hasnt changed after the upgrade:
     965                // Ensure stylesheet name hasnt changed after the upgrade:
    877966                // @TODO: Note, This doesn't handle the Template changing, or the Template name changing.
    878967                if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
    879968                        $theme_info = $this->theme_info();
    880969                        $stylesheet = $this->result['destination_name'];
    881                         $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
     970                        $template = $theme_info->get_template();
    882971                        switch_theme($template, $stylesheet, true);
    883972                }
    … …  
    9121001                                return false;
    9131002                }
    914                 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
     1003                return wp_get_theme( $theme, WP_CONTENT_DIR . '/themes/' );
    9151004        }
    9161005
    … …  
    9341023                $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
    9351024                $this->strings['copy_failed'] = __('Could not copy files.');
     1025                $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' );
    9361026        }
    9371027
    … …  
    9861076                require(ABSPATH . 'wp-admin/includes/update-core.php');
    9871077
     1078                if ( ! function_exists( 'update_core' ) )
     1079                        return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] );
     1080
    9881081                return update_core($working_dir, $wp_dir);
    9891082        }
    … …  
    11071200                $this->plugin = $this->upgrader->plugin_info();
    11081201                if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
    1109                         show_message(__('Reactivating the plugin&#8230;'));
    11101202                        echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>';
    11111203                }
    … …  
    12911383
    12921384        function before() {
    1293                 parent::before($this->theme_info['Name']);
     1385                parent::before( $this->theme_info->display('Name') );
    12941386        }
    12951387
    12961388        function after() {
    1297                 parent::after($this->theme_info['Name']);
    1298         }
     1389                parent::after( $this->theme_info->display('Name') );
     1390        }
     1391
    12991392        function bulk_footer() {
    13001393                parent::bulk_footer();
    … …  
    13041397                );
    13051398
    1306                 $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info);
     1399                $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
    13071400                if ( ! empty($update_actions) )
    13081401                        $this->feedback(implode(' | ', (array)$update_actions));
    … …  
    13631456                        $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>';
    13641457
    1365 
    13661458                if ( ! $this->result || is_wp_error($this->result) ) {
    13671459                        unset( $install_actions['activate_plugin'] );
    … …  
    13981490
    13991491        function before() {
    1400                 if ( !empty($this->api) ) {
    1401                         /* translators: 1: theme name, 2: version */
    1402                         $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
    1403                 }
     1492                if ( !empty($this->api) )
     1493                        $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
    14041494        }
    14051495
    … …  
    14091499
    14101500                $theme_info = $this->upgrader->theme_info();
    1411                 if ( empty($theme_info) )
     1501                if ( empty( $theme_info ) )
    14121502                        return;
    1413                 $name = $theme_info['Name'];
     1503
     1504                $name       = $theme_info->display('Name');
    14141505                $stylesheet = $this->upgrader->result['destination_name'];
    1415                 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
    1416 
    1417                 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => 1, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
    1418                 $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
    1419 
    1420                 $install_actions = array(
    1421                         'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>',
    1422                         'activate' => '<a href="' . $activate_link .  '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>'
    1423                                                         );
     1506                $template   = $theme_info->get_template();
     1507
     1508                $preview_link = add_query_arg( array(
     1509                        'preview'    => 1,
     1510                        'template'   => $template,
     1511                        'stylesheet' => $stylesheet,
     1512                ), trailingslashit( get_home_url() ) );
     1513
     1514                $activate_link = add_query_arg( array(
     1515                        'action'     => 'activate',
     1516                        'template'   => $template,
     1517                        'stylesheet' => $stylesheet,
     1518                ), admin_url('themes.php') );
     1519                $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
     1520
     1521                $install_actions = array();
     1522                $install_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
     1523                $install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
     1524                $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
    14241525
    14251526                if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
    1426                         $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . $template, 'enable-theme_' . $template ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
     1527                        $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . $stylesheet, 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
    14271528
    14281529                if ( $this->type == 'web' )
    … …  
    14641565
    14651566                $update_actions = array();
    1466                 if ( !empty($this->upgrader->result['destination_name']) &&
    1467                         ($theme_info = $this->upgrader->theme_info()) &&
    1468                         !empty($theme_info) ) {
    1469 
    1470                         $name = $theme_info['Name'];
     1567                if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
     1568                        $name       = $theme_info->display('Name');
    14711569                        $stylesheet = $this->upgrader->result['destination_name'];
    1472                         $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
    1473 
    1474                         $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
    1475                         $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
    1476 
    1477                         $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>';
    1478                         $update_actions['activate'] = '<a href="' . $activate_link .  '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
    1479 
    1480                         if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
    1481                                 unset($update_actions['preview'], $update_actions['activate']);
     1570                        $template   = $theme_info->get_template();
     1571
     1572                        $preview_link = add_query_arg( array(
     1573                                'preview'    => 1,
     1574                                'template'   => $template,
     1575                                'stylesheet' => $stylesheet,
     1576                        ), trailingslashit( get_home_url() ) );
     1577
     1578                        $activate_link = add_query_arg( array(
     1579                                'action'     => 'activate',
     1580                                'template'   => $template,
     1581                                'stylesheet' => $stylesheet,
     1582                        ), admin_url('themes.php') );
     1583                        $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
     1584
     1585                        if ( get_stylesheet() == $stylesheet ) {
     1586                                $update_actions['preview']  = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Customize &#8220;%s&#8221;'), $name ) ) . '">' . __('Customize') . '</a>';
     1587                        } else {
     1588                                $update_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
     1589                                $update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
     1590                                $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
     1591                        }
     1592
     1593                        if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
     1594                                unset( $update_actions['preview'], $update_actions['activate'] );
    14821595                }
    14831596
Note: See TracChangeset for help on using the changeset viewer.