WordPress.org

Make WordPress Core

Ticket #13774: 13774.2.diff

File 13774.2.diff, 5.1 KB (added by dd32, 7 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                $this->strings['parent_theme_required'] = __('Preparing to install the parent theme <strong>%s</strong>&#8230;');
    664665        }
    665666
     667        function check_parent_theme_filter($res, $hook_extra, $child_result) {
     668                // Check to see if we need to install a
     669                $theme_info = $this->theme_info();
     670                $theme_info['Template'] = 'the-common-blog';
     671                if ( !empty($theme_info['Template']) ) {
     672
     673                        $themes = get_themes();
     674                        if ( isset($themes[ $theme_info['Template'] ]) )
     675                                return $res; // Fall through, we already have the theme
     676
     677                        foreach ( (array)$themes as $this_theme ) {
     678                                if ( !empty($this_theme['Stylesheet']) && $this_theme['Stylesheet'] == $theme_info['Template'] )
     679                                        return $res; // Fall through, we already have the theme
     680                        }
     681
     682                        // We don't have the parent theme, lets install it
     683                        // First, We'll need to take over the information the skin is displaying..
     684                        $child_api = $this->skin->api;
     685                        $child_success_message = $this->strings['process_success'];
     686
     687                        $api = themes_api('theme_information', array('slug' => $theme_info['Template'], 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
     688                        $this->skin->api = $api;
     689                        /* translators: 1: theme name, 2: version */
     690                        $this->strings['process_success'] = sprintf( __('Successfully installed the parent theme <strong>%1$s %2$s</strong>.'), $api->name, $api->version);
     691
     692                        // Override the
     693                        $this->skin->feedback('parent_theme_required', $api->name . ' ' . $api->version);
     694                        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 670 above.
     695                        add_filter('install_theme_complete_actions', '__return_false'); // Don't show any actions after installing the theme.
     696
     697                        // Install the parent theme
     698                        $this->run( array(
     699                                                        'package' => $api->download_link,
     700                                                        'destination' => WP_CONTENT_DIR . '/themes',
     701                                                        'clear_destination' => false, //Do not overwrite files.
     702                                                        'clear_working' => true
     703                                                        )
     704                                           );
     705
     706                        //Add error handling here for the parent installation failure.
     707                        $parent_result = $this->result;
     708
     709                        // Start cleaning up after the parents installation
     710                        remove_filter('install_theme_complete_actions', '__return_false');
     711
     712                        // Reset child's result and data
     713                        $this->result = $child_result;
     714                        $this->skin->api = $child_api;
     715//                      $this->skin->set_result($this->result);
     716                        $this->strings['process_success'] = $child_success_message;
     717                }
     718                return $res;
     719        }
     720
    666721        function install($package) {
    667722
    668723                $this->init();
    669724                $this->install_strings();
    670725
    671726                add_filter('upgrader_source_selection', array(&$this, 'check_package') );
     727                add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
    672728
    673729                $options = array(
    674730                                                'package' => $package,
     
    680736                $this->run($options);
    681737
    682738                remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
     739                remove_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
    683740
    684741                if ( ! $this->result || is_wp_error($this->result) )
    685742                        return $this->result;
     
    14191476                $install_actions = array(
    14201477                        'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>',
    14211478                        'activate' => '<a href="' . $activate_link .  '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>'
    1422                                                         );
     1479                );
    14231480
    14241481                if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
    14251482                        $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>';
     
    15621619
    15631620                return true;
    15641621        }
    1565 }
     1622}
     1623 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);