Make WordPress Core

Changeset 20267


Ignore:
Timestamp:
03/23/2012 10:10:06 AM (14 years ago)
Author:
nacin
Message:

Support child theme installation in the theme installer. props otto42, dd32. fixes #13774.

Location:
trunk/wp-admin
Files:
2 edited

Legend:

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

    r19684 r20267  
    663663                $this->strings['process_failed'] = __('Theme install failed.');
    664664                $this->strings['process_success'] = __('Theme installed successfully.');
     665                /* translators: 1: theme name, 2: version */
     666                $this->strings['process_success_specific'] = __('Successfully installed the theme <strong>%1$s %2$s</strong>.');
     667                $this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed&#8230;');
     668                /* translators: 1: theme name, 2: version */
     669                $this->strings['parent_theme_prepare_install'] = __('Preparing to install <strong>%1$s %2$s</strong>&#8230;');
     670                /* translators: 1: theme name, 2: version */
     671                $this->strings['parent_theme_currently_installed'] = __('The parent theme, <strong>%1$s %2$s</strong>, is currently installed.');
     672                /* translators: 1: theme name, 2: version */
     673                $this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, <strong>%1$s %2$s</strong>.');
     674                $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.');
     675        }
     676
     677        function check_parent_theme_filter($install_result, $hook_extra, $child_result) {
     678                // Check to see if we need to install a parent theme
     679                $theme_info = $this->theme_info();
     680
     681                // Do we have any business here?
     682                if ( empty($theme_info['Template']) )
     683                        return $install_result;
     684
     685                $this->skin->feedback('parent_theme_search', $theme_info['Template'] );
     686
     687                $parent_theme = wp_get_theme( $theme_info['Template'] );
     688                if ( ! $parent_theme->errors() ) {
     689                        $this->skin->feedback( 'parent_theme_currently_installed', $parent_theme['Name'], $parent_theme['Version'] );
     690                        // We already have the theme, fall through.
     691                        return $install_result;
     692                }
     693
     694                // We don't have the parent theme, lets install it
     695                $api = themes_api('theme_information', array('slug' => $theme_info['Template'], 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
     696
     697                if ( ! $api || is_wp_error($api) ) {
     698                        $this->skin->feedback('parent_theme_not_found', $theme_info['Template']);
     699                        // Don't show activate or preview actions after install
     700                        add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') );
     701                        return $install_result;
     702                }
     703
     704                // Backup required data we're going to override:
     705                $child_api = $this->skin->api;
     706                $child_success_message = $this->strings['process_success'];
     707
     708                // Override them
     709                $this->skin->api = $api;
     710                $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version);
     711
     712                $this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version);
     713               
     714                //@TODO: This is a DEBUG line! Only needed with the-common-blog line above.
     715                remove_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3); // This is only needed when we're forcing a template on line 676 above.
     716
     717                add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme.
     718
     719                // Install the parent theme
     720                $parent_result = $this->run( array(
     721                        'package' => $api->download_link,
     722                        'destination' => WP_CONTENT_DIR . '/themes',
     723                        'clear_destination' => false, //Do not overwrite files.
     724                        'clear_working' => true
     725                ) );
     726
     727                if ( is_wp_error($parent_result) )
     728                        add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') );
     729
     730                // Start cleaning up after the parents installation
     731                remove_filter('install_theme_complete_actions', '__return_false', 999);
     732
     733                // Reset child's result and data
     734                $this->result = $child_result;
     735                $this->skin->api = $child_api;
     736                $this->strings['process_success'] = $child_success_message;
     737
     738                return $install_result;
     739        }
     740       
     741        function hide_activate_preview_actions($actions) {
     742                unset($actions['activate'], $actions['preview']);
     743                return $actions;
    665744        }
    666745
     
    671750
    672751                add_filter('upgrader_source_selection', array(&$this, 'check_package') );
     752                add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
    673753
    674754                $options = array(
     
    682762
    683763                remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
     764                remove_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
    684765
    685766                if ( ! $this->result || is_wp_error($this->result) )
     
    13971478
    13981479        function before() {
    1399                 if ( !empty($this->api) ) {
    1400                         /* translators: 1: theme name, 2: version */
    1401                         $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
    1402                 }
     1480                if ( !empty($this->api) )
     1481                        $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
    14031482        }
    14041483
  • trunk/wp-admin/update.php

    r18617 r20267  
    200200
    201201                check_admin_referer('install-theme_' . $theme);
    202                 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
     202                $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
    203203
    204204                if ( is_wp_error($api) )
Note: See TracChangeset for help on using the changeset viewer.