WordPress.org

Make WordPress Core

Ticket #13774: 13774.3.diff

File 13774.3.diff, 7.0 KB (added by dd32, 3 years ago)
  • wp-admin/includes/class-wp-upgrader.php

     
    661661                $this->strings['installing_package'] = __('Installing the theme…'); 
    662662                $this->strings['process_failed'] = __('Theme install failed.'); 
    663663                $this->strings['process_success'] = __('Theme installed successfully.'); 
     664                /* translators: 1: theme name, 2: version */ 
     665                $this->strings['process_success_specific'] = __('Successfully installed the theme <strong>%1$s %2$s</strong>.'); 
     666                $this->strings['parent_theme_search'] = __('This theme requires a parent theme, Checking if <strong>%s</strong> is installed&#8230;'); 
     667                /* translators: 1: theme name, 2: version */ 
     668                $this->strings['parent_theme_prepare_install'] = __('Preparing to install <strong>%1$s %2$s</strong>&#8230;'); 
     669                /* translators: 1: theme name, 2: version */ 
     670                $this->strings['parent_theme_currently_installed'] = __('The Parent theme, <strong>%1$s %2$s</strong>, is currently installed.'); 
     671                /* translators: 1: theme name, 2: version */ 
     672                $this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme <strong>%1$s %2$s</strong>.'); 
     673                $this->strings['parent_theme_not_found'] = __('<strong>The parent theme could not be found, You will need to install the parent theme %s before you can use this child theme.</strong>'); 
    664674        } 
    665675 
     676        function check_parent_theme_filter($install_result, $hook_extra, $child_result) { 
     677                // Check to see if we need to install a parent theme 
     678                $theme_info = $this->theme_info(); 
     679                $theme_info['Template'] = 'the-common-blog'; //@TODO: This is a DEBUG line 
     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                foreach ( get_themes() as $this_theme ) { 
     688                        if ( !empty($this_theme['Stylesheet']) && $this_theme['Stylesheet'] == $theme_info['Template'] ) { 
     689                                $this->skin->feedback('parent_theme_currently_installed', $this_theme['Name'], $this_theme['Version'] ); 
     690                                return $install_result; // Fall through, we already have the theme 
     691                        } 
     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 
     728                if ( is_wp_error($parent_result) ) { 
     729                        add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') ); 
     730                } 
     731 
     732                // Start cleaning up after the parents installation 
     733                remove_filter('install_theme_complete_actions', '__return_false', 999); 
     734 
     735                // Reset child's result and data 
     736                $this->result = $child_result; 
     737                $this->skin->api = $child_api; 
     738                $this->strings['process_success'] = $child_success_message; 
     739 
     740                return $install_result; 
     741        } 
     742         
     743        function hide_activate_preview_actions($actions) { 
     744                unset($actions['activate'], $actions['preview']); 
     745                return $actions; 
     746        } 
     747 
    666748        function install($package) { 
    667749 
    668750                $this->init(); 
    669751                $this->install_strings(); 
    670752 
    671753                add_filter('upgrader_source_selection', array(&$this, 'check_package') ); 
     754                add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3); 
    672755 
    673756                $options = array( 
    674757                                                'package' => $package, 
     
    680763                $this->run($options); 
    681764 
    682765                remove_filter('upgrader_source_selection', array(&$this, 'check_package') ); 
     766                remove_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3); 
    683767 
    684768                if ( ! $this->result || is_wp_error($this->result) ) 
    685769                        return $this->result; 
     
    13961480        } 
    13971481 
    13981482        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                 } 
     1483                if ( !empty($this->api) ) 
     1484                        $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); 
    14031485        } 
    14041486 
    14051487        function after() { 
     
    14191501                $install_actions = array( 
    14201502                        'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>', 
    14211503                        'activate' => '<a href="' . $activate_link .  '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>' 
    1422                                                         ); 
     1504                ); 
    14231505 
    14241506                if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) 
    14251507                        $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>'; 
     
    15621644 
    15631645                return true; 
    15641646        } 
    1565 } 
     1647} 
     1648 No newline at end of file 
  • wp-admin/update.php

     
    199199                include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api.. 
    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) ) 
    205205                        wp_die($api);