Ejemplo n.º 1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     // This MUST come before we get details about the themes so the headers are correctly retrieved
     GitHub_Updater_GitHub_API::add_headers();
     // Get details of git sourced themes
     $this->config = $this->get_theme_meta();
     if (empty($this->config)) {
         return false;
     }
     if (isset($_GET['force-check']) && '1' === $_GET['force-check']) {
         $this->delete_all_transients('themes');
     }
     foreach ((array) $this->config as $theme) {
         switch ($theme->type) {
             case 'github_theme':
                 $repo_api = new GitHub_Updater_GitHub_API($theme);
                 break;
             case 'bitbucket_theme':
                 $repo_api = new GitHub_Updater_BitBucket_API($theme);
                 break;
         }
         $this->{$theme->type} = $theme;
         $this->set_defaults($theme->type);
         if ($repo_api->get_remote_info('style.css')) {
             $repo_api->get_repo_meta();
             $repo_api->get_remote_tag();
             $changelog = $this->get_changelog_filename($theme->type);
             if ($changelog) {
                 $repo_api->get_remote_changes($changelog);
             }
             $theme->download_link = $repo_api->construct_download_link();
         }
         // Update theme transient with rollback data for single install
         if (!empty($_GET['rollback']) && $_GET['theme'] === $theme->repo && !is_multisite()) {
             $this->tag = $_GET['rollback'];
             $updates_transient = get_site_transient('update_themes');
             $rollback = array('new_version' => $this->tag, 'url' => $theme->uri, 'package' => $repo_api->construct_download_link($this->tag));
             $updates_transient->response[$theme->repo] = $rollback;
             set_site_transient('update_themes', $updates_transient);
         }
         // Remove WordPress update row in theme row, only in multisite
         // Add update row to theme row, only in multisite for WP < 3.8
         if (is_multisite() || get_bloginfo('version') < 3.8) {
             add_action('after_theme_row', array($this, 'remove_after_theme_row'), 10, 2);
             if (!$this->tag) {
                 add_action("after_theme_row_{$theme->repo}", array($this, 'wp_theme_update_row'), 10, 2);
             }
         }
     }
     $this->make_force_check_transient('themes');
     $update = array('do-core-reinstall', 'do-core-upgrade');
     if (empty($_GET['action']) || !in_array($_GET['action'], $update, true)) {
         add_filter('pre_set_site_transient_update_themes', array($this, 'pre_set_site_transient_update_themes'));
     }
     add_filter('themes_api', array($this, 'themes_api'), 99, 3);
     add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 3);
     add_filter('http_request_args', array($this, 'no_ssl_http_request_args'), 10, 2);
     if (!is_multisite()) {
         add_filter('wp_prepare_themes_for_js', array($this, 'customize_theme_update_html'));
     }
     GitHub_Updater_Settings::$ghu_themes = $this->config;
 }