/**
  * @param Theme_Upgrader $upgrader
  * @param array $extra
  */
 public function hooks_theme_install_or_update($upgrader, $extra)
 {
     if (!isset($extra['type']) || 'theme' !== $extra['type']) {
         return;
     }
     if ('install' === $extra['action']) {
         $slug = $upgrader->theme_info();
         if (!$slug) {
             return;
         }
         wp_clean_themes_cache();
         $theme = wp_get_theme($slug);
         $name = $theme->name;
         $version = $theme->version;
         aal_insert_log(array('action' => 'installed', 'object_type' => 'Theme', 'object_name' => $name, 'object_subtype' => $version));
     }
     if ('update' === $extra['action']) {
         if (isset($extra['bulk']) && true == $extra['bulk']) {
             $slugs = $extra['themes'];
         } else {
             $slugs = array($upgrader->skin->theme);
         }
         foreach ($slugs as $slug) {
             $theme = wp_get_theme($slug);
             $stylesheet = $theme['Stylesheet Dir'] . '/style.css';
             $theme_data = get_file_data($stylesheet, array('Version' => 'Version'));
             $name = $theme['Name'];
             $version = $theme_data['Version'];
             aal_insert_log(array('action' => 'updated', 'object_type' => 'Theme', 'object_name' => $name, 'object_subtype' => $version));
         }
     }
 }
 function update()
 {
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     // Clear the cache.
     wp_update_themes();
     foreach ($this->themes as $theme) {
         /**
          * Pre-upgrade action
          * 
          * @since 3.9.3
          * 
          * @param object $theme WP_Theme object
          * @param array $themes Array of theme objects
          */
         do_action('jetpack_pre_theme_upgrade', $theme, $this->themes);
         // Objects created inside the for loop to clean the messages for each theme
         $skin = new Automatic_Upgrader_Skin();
         $upgrader = new Theme_Upgrader($skin);
         $upgrader->init();
         $result = $upgrader->upgrade($theme);
         $this->log[$theme][] = $upgrader->skin->get_upgrade_messages();
     }
     if (!$this->bulk && !$result) {
         return new WP_Error('update_fail', __('There was an error updating your theme', 'jetpack'), 400);
     }
     return true;
 }
 protected function install()
 {
     foreach ($this->themes as $theme) {
         $skin = new Jetpack_Automatic_Install_Skin();
         $upgrader = new Theme_Upgrader($skin);
         $link = $this->download_links[$theme];
         $result = $upgrader->install($link);
         if (file_exists($link)) {
             // Delete if link was tmp local file
             unlink($link);
         }
         if (!$this->bulk && is_wp_error($result)) {
             return $result;
         }
         if (!$result) {
             $error = $this->log[$theme]['error'] = __('An unknown error occurred during installation', 'jetpack');
         } elseif (!self::is_installed_theme($theme)) {
             $error = $this->log[$theme]['error'] = __('There was an error installing your theme', 'jetpack');
         } else {
             $this->log[$theme][] = $upgrader->skin->get_upgrade_messages();
         }
     }
     if (!$this->bulk && isset($error)) {
         return new WP_Error('install_error', $error, 400);
     }
     return true;
 }
Пример #4
0
/**
 * Updates the given list of themes.
 * 
 * Accepts an array of theme slugs such as 'twentyfourteen'
 * Returns a detailed array showing the status of each theme and a log of messages output during the process
 *
 * @param array $themes
 * @return array
 */
function bruteprotect_bulk_update_themes($themes)
{
    $skin = new Automatic_Upgrader_Skin();
    $upgrader = new Theme_Upgrader($skin);
    $results = $upgrader->bulk_upgrade($themes);
    $messages = $upgrader->skin->get_upgrade_messages();
    $o['results'] = $results;
    $o['messages'] = $messages;
    return $o;
}
Пример #5
0
/**
 * AJAX handler for updating a theme.
 *
 * @since 4.X.0
 */
function wp_ajax_update_theme()
{
    check_ajax_referer('updates');
    if (empty($_POST['slug'])) {
        wp_send_json_error(array('slug' => '', 'errorCode' => 'no_theme_specified', 'error' => __('No theme specified.')));
    }
    $stylesheet = sanitize_key($_POST['slug']);
    $status = array('update' => 'theme', 'slug' => $stylesheet, 'oldVersion' => sprintf(__('Version %s'), wp_get_theme($stylesheet)->get('Version')), 'newVersion' => '');
    if (!current_user_can('update_themes')) {
        $status['error'] = __('You do not have sufficient permissions to update themes on this site.');
        wp_send_json_error($status);
    }
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $current = get_site_transient('update_themes');
    if (empty($current)) {
        wp_update_themes();
    }
    $upgrader = new Theme_Upgrader(new Automatic_Upgrader_Skin());
    $result = $upgrader->bulk_upgrade(array($stylesheet));
    if (defined('WP_DEBUG') && WP_DEBUG) {
        $status['debug'] = $upgrader->skin->get_upgrade_messages();
    }
    if (is_array($result) && !empty($result[$stylesheet])) {
        // Theme is already at the latest version.
        if (true === $result[$stylesheet]) {
            $status['error'] = $upgrader->strings['up_to_date'];
            wp_send_json_error($status);
        }
        $theme = wp_get_theme($stylesheet);
        if ($theme->get('Version')) {
            $status['theme'] = wp_prepare_themes_for_js(array($theme));
            $status['newVersion'] = sprintf(__('Version %s'), $theme->get('Version'));
        }
        wp_send_json_success($status);
    } else {
        if (is_wp_error($result)) {
            $status['error'] = $result->get_error_message();
            wp_send_json_error($status);
        } else {
            if (is_bool($result) && !$result) {
                global $wp_filesystem;
                $status['errorCode'] = 'unable_to_connect_to_filesystem';
                $status['error'] = __('Unable to connect to the filesystem. Please confirm your credentials.');
                // Pass through the error from WP_Filesystem if one was raised.
                if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
                    $status['error'] = $wp_filesystem->errors->get_error_message();
                }
                wp_send_json_error($status);
            }
        }
    }
    // An unhandled error occurred.
    $status['error'] = __('Update failed.');
    wp_send_json_error($status);
}
 protected function install()
 {
     foreach ($this->themes as $theme) {
         /**
          * Filters whether to use an alternative process for installing a WordPress.com theme.
          * The alternative process can be executed during the filter.
          *
          * The filter can also return an instance of WP_Error; in which case the endpoint response will
          * contain this error.
          *
          * @module json-api
          *
          * @since 4.4.2
          *
          * @param bool   $use_alternative_install_method Whether to use the alternative method of installing
          *                                               a WPCom theme.
          * @param string $theme_slug                     Theme name (slug). If it is a WPCom theme,
          *                                               it should be suffixed with `-wpcom`.
          */
         $result = apply_filters('jetpack_wpcom_theme_install', false, $theme);
         $skin = null;
         $upgrader = null;
         $link = null;
         // If the alternative install method was not used, use the standard method.
         if (!$result) {
             $skin = new Jetpack_Automatic_Install_Skin();
             $upgrader = new Theme_Upgrader($skin);
             $link = $this->download_links[$theme];
             $result = $upgrader->install($link);
         }
         if (file_exists($link)) {
             // Delete if link was tmp local file
             unlink($link);
         }
         if (!$this->bulk && is_wp_error($result)) {
             return $result;
         }
         if (!$result) {
             $error = $this->log[$theme]['error'] = __('An unknown error occurred during installation', 'jetpack');
         } elseif (!self::is_installed_theme($theme)) {
             $error = $this->log[$theme]['error'] = __('There was an error installing your theme', 'jetpack');
         } elseif ($upgrader) {
             $this->log[$theme][] = $upgrader->skin->get_upgrade_messages();
         }
     }
     if (!$this->bulk && isset($error)) {
         return new WP_Error('install_error', $error, 400);
     }
     return true;
 }
Пример #7
0
 function install_package($args = array())
 {
     parent::upgrade_strings();
     // needed for the 'remove_old' string
     $args['clear_destination'] = true;
     $args['abort_if_destination_exists'] = false;
     return parent::install_package($args);
 }
 /**
  * If a requested theme/plugin is from wordpress.org -OR- from us, let it through
  * @param array $options
  */
 public function run($options)
 {
     $_options = get_option('gd_quicksetup_options');
     if (preg_match('/(?:(\\.)?wordpress\\.org|' . preg_quote(parse_url($_options['api_url'], PHP_URL_HOST)) . ')$/', parse_url($options['package'], PHP_URL_HOST))) {
         // Some older servers don't have our SSL certs in their bundle
         add_filter('https_ssl_verify', '__return_false');
         parent::run($options);
         remove_filter('https_local_ssl_verify', '__return_false');
     }
 }
Пример #9
0
 function upgrade_strings()
 {
     parent::upgrade_strings();
     $this->strings['skin_before_update_header'] = __('Updating %1$s (%2$d/%3$d)', 'tfuse');
     $this->strings['up_to_date'] = __('The package is at the latest version.', 'tfuse');
     $this->strings['remove_old'] = __('Removing the old version of the %s…', 'tfuse');
     $this->strings['remove_old_failed'] = __('Could not remove the old version of the ', 'tfuse');
     $this->strings['process_failed'] = __('Update failed.', 'tfuse');
     $this->strings['process_success'] = __('Package updated successfully.', 'tfuse');
     $this->strings['tf_backup'] = __('Backing up files…', 'tfuse');
     $this->strings['tf_bk_mkdir_failed'] = __('Could not create backup directory.', 'tfuse');
 }
 function install()
 {
     $args = $this->input();
     if (isset($args['zip'][0]['id'])) {
         $attachment_id = $args['zip'][0]['id'];
         $local_file = get_attached_file($attachment_id);
         if (!$local_file) {
             return new WP_Error('local-file-does-not-exist');
         }
         $skin = new Jetpack_Automatic_Install_Skin();
         $upgrader = new Theme_Upgrader($skin);
         $pre_install_list = wp_get_themes();
         $result = $upgrader->install($local_file);
         // clean up.
         wp_delete_attachment($attachment_id, true);
         if (is_wp_error($result)) {
             return $result;
         }
         $after_install_list = wp_get_themes();
         $plugin = array_values(array_diff(array_keys($after_install_list), array_keys($pre_install_list)));
         if (!$result) {
             $error_code = $upgrader->skin->get_main_error_code();
             $message = $upgrader->skin->get_main_error_message();
             if (empty($message)) {
                 $message = __('An unknown error occurred during installation', 'jetpack');
             }
             if ('download_failed' === $error_code) {
                 $error_code = 'no_package';
             }
             return new WP_Error($error_code, $message, 400);
         }
         if (empty($plugin)) {
             return new WP_Error('theme_already_installed');
         }
         $this->themes = $plugin;
         $this->log[$plugin[0]] = $upgrader->skin->get_upgrade_messages();
         return true;
     }
     return new WP_Error('no_theme_installed');
 }
Пример #11
0
/**
 * Refresh families from meteor function
 */
function autoupdater_refresh_theme()
{
    // refresh WordPress information of new theme versions
    get_transient('update_themes');
    global $wp_version, $theme_version, $theme_to_update, $api_url;
    log_me('checking the update and stuff...');
    if (function_exists('wp_get_theme')) {
        $theme_data = wp_get_theme($theme_to_update);
        $theme_version = $theme_data->Version;
    } else {
        $theme_data = get_theme_data(ABSPATH . '/wp-content/themes/' . $theme_to_update . '/style.css');
        $theme_version = $theme_data['Version'];
    }
    $request = array('slug' => $theme_to_update, 'version' => $theme_version);
    // Start checking for an update
    $send_for_check = array('body' => array('action' => 'theme_update', 'request' => serialize($request), 'api-key' => md5(get_bloginfo('url'))), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
    $raw_response = wp_remote_post($api_url, $send_for_check);
    if (!is_wp_error($raw_response) && $raw_response['response']['code'] == 200) {
        $response = unserialize($raw_response['body']);
    }
    // check if the new version is higher
    // if (version_compare($theme_version, $response['new_version']))
    if (version_compare($theme_version, $response['new_version'], '<')) {
        require ABSPATH . 'wp-admin/includes/screen.php';
        require ABSPATH . 'wp-admin/includes/plugin.php';
        require ABSPATH . 'wp-admin/includes/template.php';
        require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        require ABSPATH . 'wp-admin/includes/file.php';
        require ABSPATH . 'wp-admin/includes/misc.php';
        $theme = $theme_to_update;
        $title = __('Update Theme');
        $parent_file = 'themes.php';
        $submenu_file = 'themes.php';
        // require_once(ABSPATH . 'wp-admin/admin-header.php');
        $nonce = 'upgrade-theme_' . $theme_to_update;
        $url = 'update.php?action=upgrade-theme&theme=' . urlencode($theme_to_update);
        $upgrader = new Theme_Upgrader(new Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
        $upgrader->upgrade($theme_to_update);
    }
}
Пример #12
0
function puma_theme_update_callback()
{
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $update_data = array('theme_version' => get_transient('puma_latest'), 'update_link' => 'https://github.com/bigfa/Puma/archive/master.zip');
    $name = "Puma";
    $slug = "Puma";
    $version = $update_data['theme_version'];
    $download_link = $update_data['update_link'];
    delete_site_transient('update_themes');
    $themes = wp_get_themes();
    $current = (object) array("last_checked" => time(), "checked" => array(), "response" => array(), "translations" => array());
    foreach ($themes as $theme) {
        $current->checked[$theme->get('Slug')] = $theme->get('Version');
    }
    $current->response[$slug] = array('theme' => $slug, 'new_version' => $version, 'url' => '', 'package' => $download_link);
    set_site_transient('update_themes', $current);
    $title = __('Update Theme');
    $nonce = 'upgrade-theme_' . $slug;
    $url = 'update.php?action=upgrade-theme&theme=' . urlencode($slug);
    $upgrader = new Theme_Upgrader(new Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
    $upgrader->upgrade($slug);
    exit;
}
Пример #13
0
/**
 * Update a theme
 *
 * @param mixed $theme
 * @return array
 */
function _wprp_upgrade_theme($theme)
{
    include_once ABSPATH . 'wp-admin/includes/admin.php';
    if (!_wprp_supports_theme_upgrade()) {
        return array('status' => 'error', 'error' => 'WordPress version too old for theme upgrades');
    }
    $skin = new WPRP_Theme_Upgrader_Skin();
    $upgrader = new Theme_Upgrader($skin);
    // Do the upgrade
    ob_start();
    $result = $upgrader->upgrade($theme);
    $data = ob_get_contents();
    ob_clean();
    if (!$result && !is_null($result) || $data) {
        return array('status' => 'error', 'error' => 'file_permissions_error');
    } elseif (is_wp_error($result)) {
        return array('status' => 'error', 'error' => $result->get_error_code());
    }
    if ($skin->error) {
        return array('status' => 'error', 'error' => $skin->error);
    }
    return array('status' => 'success');
}
 public function clear_destination($destination)
 {
     global $wp_filesystem;
     if (!is_dir($destination) || !file_exists("{$destination}/style.css")) {
         // This is an installation not an upgrade.
         return parent::clear_destination($destination);
     }
     $backup_url = $this->create_backup($destination);
     if (!is_wp_error($backup_url)) {
         /* translators: 1: theme zip URL */
         $this->skin->feedback(sprintf(__('A backup zip file of the old theme version can be downloaded <a href="%1$s">here</a>.', 'easy-theme-and-plugin-upgrades'), $backup_url));
         // Restore default strings and display the original remove_old message.
         $this->upgrade_strings();
         $this->skin->feedback('remove_old');
         return parent::clear_destination($destination);
     }
     $this->skin->error($backup_url);
     $this->skin->feedback(__('Moving the old version of the theme to a new directory&#8230;', 'easy-theme-and-plugin-upgrades'));
     $headers = array('version' => 'Version');
     $data = get_file_data("{$destination}/style.css", $headers);
     $new_name = basename($destination) . "-{$data['version']}";
     $directory = dirname($destination);
     for ($x = 0; $x < 20; $x++) {
         $test_name = $new_name . '-' . $this->get_random_characters(10, 20);
         if (!is_dir("{$directory}/{$test_name}")) {
             $new_name = $test_name;
             break;
         }
     }
     if (is_dir("{$directory}/{$new_name}")) {
         // We gave it our best effort. Time to give up on the idea of having a backup.
         $this->skin->error(__('Unable to find a new directory name to move the old version of the theme to. No backup will be created.', 'easy-theme-and-plugin-upgrades'));
     } else {
         $result = $wp_filesystem->move($destination, "{$directory}/{$new_name}");
         if ($result) {
             /* translators: 1: new theme directory name */
             $this->skin->feedback(sprintf(__('Moved the old version of the theme to a new theme directory named %1$s. This directory should be backed up and removed from the site.', 'easy-theme-and-plugin-upgrades'), "<code>{$new_name}</code>"));
         } else {
             $this->skin->error(__('Unable to move the old version of the theme to a new directory. No backup will be created.', 'easy-theme-and-plugin-upgrades'));
         }
     }
     // Restore default strings and display the original remove_old message.
     $this->upgrade_strings();
     $this->skin->feedback('remove_old');
     return parent::clear_destination($destination);
 }
 function upgrade_bsf_product($request_product_id, $bundled_id)
 {
     global $bsf_product_validate_url, $bsf_support_url;
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update plugins for this site.', 'bsf'));
     }
     $brainstrom_users = get_option('brainstrom_users') ? get_option('brainstrom_users') : array();
     $brainstrom_products = get_option('brainstrom_products') ? get_option('brainstrom_products') : array();
     $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array();
     $plugins = $themes = $mix = array();
     if (!empty($brainstrom_products)) {
         $plugins = isset($brainstrom_products['plugins']) ? $brainstrom_products['plugins'] : array();
         $themes = isset($brainstrom_products['themes']) ? $brainstrom_products['themes'] : array();
     }
     $mix = array_merge($plugins, $themes);
     $bsf_username = $purchase_key = $type = $template = $name = '';
     if (!empty($brainstrom_users)) {
         foreach ($brainstrom_users as $bsf_user) {
             $bsf_username = $bsf_user['email'];
         }
     }
     $found_in_bsf_products = false;
     if ($bundled_id !== false) {
         $product_details_id = $bundled_id;
     } else {
         $product_details_id = $request_product_id;
     }
     foreach ($mix as $key => $product) {
         $pid = $product['id'];
         if ($pid === $product_details_id) {
             $purchase_key = $product['purchase_key'];
             $type = $product['type'];
             $template = $product['template'];
             $name = $product['product_name'];
             $found_in_bsf_products = true;
             break;
         }
     }
     if ($bundled_id !== false) {
         if (!empty($brainstrom_bundled_products)) {
             foreach ($brainstrom_bundled_products as $bp) {
                 if ($bp->id === $request_product_id) {
                     $type = $bp->type;
                     $template = $bp->init;
                     $name = $bp->name;
                 }
             }
         }
     }
     if ($bsf_username === '' || $purchase_key === '' || $request_product_id === '') {
         wp_die('Not valid to update product');
     }
     $path = base64_decode($bsf_product_validate_url);
     $data = array('action' => 'bsf_product_update_request', 'id' => $request_product_id, 'username' => $bsf_username, 'purchase_key' => $purchase_key, 'site_url' => get_site_url(), 'bundled' => $bundled_id);
     $request = @wp_remote_post($path, array('body' => $data, 'timeout' => '60', 'sslverify' => false));
     if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
         $result = json_decode($request['body']);
         if (isset($result->error) && !$result->error) {
             $download_path = $result->update_data->download_url;
             $timezone = date_default_timezone_get();
             $call = 'file=' . $download_path . '&hashtime=' . strtotime(date('d-m-Y h:i:s a')) . '&timezone=' . $timezone;
             $hash = base64_encode($call);
             $parse = parse_url($path);
             $download = $parse['scheme'] . '://' . $parse['host'];
             $get_path = 'http://downloads.brainstormforce.com/';
             $download_path = rtrim($get_path, '/') . '/download.php?hash=' . $hash;
             //echo $download_path;
             //die();
             require_once ABSPATH . '/wp-admin/includes/file.php';
             WP_Filesystem();
             global $wp_filesystem;
             require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
             $WP_Upgrader = new WP_Upgrader();
             $res = $WP_Upgrader->fs_connect(array(WP_CONTENT_DIR));
             if (!$res) {
                 wp_die(new WP_Error('Server error', __("Error! Can't connect to filesystem", 'bsf')));
             } else {
                 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package';
                 $package_filename = basename($download_path);
                 $plugin_folder = dirname($template);
                 if ($type === 'theme' && $bundled_id === false) {
                     $defaults = array('clear_update_cache' => true);
                     $args = array();
                     $parsed_args = wp_parse_args($args, $defaults);
                     $Theme_Upgrader = new Theme_Upgrader();
                     $Theme_Upgrader->init();
                     $Theme_Upgrader->upgrade_strings();
                     $Theme_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');
                     add_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before'), 10, 2);
                     add_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after'), 10, 2);
                     add_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme'), 10, 4);
                     $Theme_Upgrader->run(array('package' => $download_path, 'destination' => get_theme_root($template), 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'hook_extra' => array('theme' => $template, 'type' => 'theme', 'action' => 'update')));
                     remove_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before'));
                     remove_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after'));
                     remove_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme'));
                     if (!$Theme_Upgrader->result || is_wp_error($Theme_Upgrader->result)) {
                         return $Theme_Upgrader->result;
                     }
                     wp_clean_themes_cache($parsed_args['clear_update_cache']);
                     $response = array('status' => true, 'type' => 'theme', 'name' => $name);
                     return $response;
                 } elseif ($type === 'plugin') {
                     $Plugin_Upgrader = new Plugin_Upgrader();
                     $Plugin_Upgrader->init();
                     $Plugin_Upgrader->upgrade_strings();
                     $Plugin_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');
                     add_filter('upgrader_pre_install', array(&$Plugin_Upgrader, 'deactivate_plugin_before_upgrade'), 10, 2);
                     add_filter('upgrader_clear_destination', array(&$Plugin_Upgrader, 'delete_old_plugin'), 10, 4);
                     $Plugin_Upgrader->run(array('package' => $download_path, 'destination' => WP_PLUGIN_DIR, 'abort_if_destination_exists' => false, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin_folder)));
                     // Cleanup our hooks, in case something else does a upgrade on this connection.
                     remove_filter('upgrader_pre_install', array(&$Plugin_Upgrader, 'deactivate_plugin_before_upgrade'));
                     remove_filter('upgrader_clear_destination', array(&$Plugin_Upgrader, 'delete_old_plugin'));
                     if (!$Plugin_Upgrader->result || is_wp_error($Plugin_Upgrader->result)) {
                         return $Plugin_Upgrader->result;
                     }
                     if (is_dir($wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package')) {
                         $wp_filesystem->delete($wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package', true);
                     }
                     // Force refresh of plugin update information
                     delete_site_transient('update_plugins');
                     wp_cache_delete('plugins', 'plugins');
                     $response = array('status' => true, 'type' => 'plugin', 'name' => $name);
                     return $response;
                 }
             }
         } else {
             echo $result->message;
         }
     }
 }
 static function install_theme()
 {
     check_ajax_referer(self::AJAX_NONCE, 'nonce');
     $theme_id = $_REQUEST['themeId'];
     $theme = wp_get_theme($theme_id);
     if (!$theme->exists()) {
         include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         include_once ABSPATH . 'wp-admin/includes/theme-install.php';
         $theme_info = themes_api('theme_information', array('slug' => $theme_id, 'fields' => array('sections' => false, 'tags' => false)));
         error_log(print_r($theme_info, true));
         if (is_wp_error($theme_info)) {
             wp_send_json_error('Could not look up theme ' . $theme_id . ': ' . $theme_info->get_error_message());
             die;
         } else {
             $upgrader = new Theme_Upgrader(new Automatic_Upgrader_Skin());
             $install_response = $upgrader->install($theme_info->download_link);
             if (is_wp_error($install_response)) {
                 wp_send_json_error('Could not install theme: ' . $install_response->get_error_message());
                 die;
             } elseif (!$install_response) {
                 wp_send_json_error('Could not install theme (unspecified server error)');
                 die;
             }
         }
     }
     wp_send_json_success($theme_id);
 }
Пример #17
0
 function theme_action()
 {
     //Read form data
     $action = $_POST['action'];
     $theme = $_POST['theme'];
     if ('activate' === $action) {
         include_once ABSPATH . '/wp-admin/includes/theme.php';
         $theTheme = get_theme($theme);
         if (null !== $theTheme && '' !== $theTheme) {
             switch_theme($theTheme['Template'], $theTheme['Stylesheet']);
         }
     } else {
         if ('delete' === $action) {
             include_once ABSPATH . '/wp-admin/includes/theme.php';
             //            if (file_exists(ABSPATH . '/wp-admin/includes/deprecated.php')) include_once(ABSPATH . '/wp-admin/includes/deprecated.php');
             if (file_exists(ABSPATH . '/wp-admin/includes/screen.php')) {
                 include_once ABSPATH . '/wp-admin/includes/screen.php';
             }
             include_once ABSPATH . '/wp-admin/includes/file.php';
             include_once ABSPATH . '/wp-admin/includes/template.php';
             include_once ABSPATH . '/wp-admin/includes/misc.php';
             include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
             include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
             include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
             $wp_filesystem = $this->getWPFilesystem();
             if (empty($wp_filesystem)) {
                 $wp_filesystem = new WP_Filesystem_Direct(null);
             }
             $themeUpgrader = new Theme_Upgrader();
             $theme_name = wp_get_theme()->get('Name');
             $themes = explode('||', $theme);
             foreach ($themes as $idx => $themeToDelete) {
                 if ($themeToDelete !== $theme_name) {
                     $theTheme = get_theme($themeToDelete);
                     if (null !== $theTheme && '' !== $theTheme) {
                         $tmp['theme'] = $theTheme['Template'];
                         if (true === $themeUpgrader->delete_old_theme(null, null, null, $tmp)) {
                             $args = array('action' => 'delete', 'Name' => $theTheme['Name']);
                             do_action('mainwp_child_theme_action', $args);
                         }
                     }
                 }
             }
         } else {
             $information['status'] = 'FAIL';
         }
     }
     if (!isset($information['status'])) {
         $information['status'] = 'SUCCESS';
     }
     $information['sync'] = $this->getSiteStats(array(), false);
     MainWP_Helper::write($information);
 }
Пример #18
0
 /**
  * Theme install of update
  *
  * @since 0.1.0
  *
  * @param Theme_Upgrader $upgrader
  * @param array $extra
  */
 public function theme_install_or_update($upgrader, $extra)
 {
     // Bail if not a theme
     if (!isset($extra['type']) || 'theme' !== $extra['type']) {
         return;
     }
     // Install
     if ('install' === $extra['action']) {
         // Bail if no theme found
         $slug = $upgrader->theme_info();
         if (empty($slug)) {
             return;
         }
         wp_clean_themes_cache();
         $theme = wp_get_theme($slug);
         $name = $theme->name;
         $version = $theme->version;
         // Insert activity
         wp_insert_user_activity(array('object_type' => $this->object_type, 'object_subtype' => $version, 'object_name' => $name, 'action' => 'install'));
         // Update
     } elseif ('update' === $extra['action']) {
         // Get theme slugs
         if (isset($extra['bulk']) && true == $extra['bulk']) {
             $slugs = $extra['themes'];
         } else {
             $slugs = array($upgrader->skin->theme);
         }
         // Activity for each theme
         foreach ($slugs as $slug) {
             $theme = wp_get_theme($slug);
             $stylesheet = $theme['Stylesheet Dir'] . '/style.css';
             $theme_data = get_file_data($stylesheet, array('Version' => 'Version'));
             $name = $theme['Name'];
             $version = $theme_data['Version'];
             // Insert activity
             wp_insert_user_activity(array('object_type' => $this->object_type, 'object_subtype' => $version, 'object_name' => $name, 'action' => 'update'));
         }
     }
 }
 function install_strings()
 {
     parent::install_strings();
     $this->strings['downloading_package'] = __('Downloading install package from the Envato API&#8230;', 'envato');
 }
Пример #20
0
 private function _update_theme($theme)
 {
     global $wp_filesystem;
     $status = array('update' => 'theme', 'theme' => $theme, 'oldVersion' => '', 'newVersion' => '');
     if (false !== strpos($theme, '/') || false !== strpos($theme, '\\')) {
         $status['error'] = 'not_found';
         return $status;
     }
     $theme_version = $this->get_theme_version($theme);
     if (false === $theme_version) {
         $status['error'] = 'not_found';
         return $status;
     }
     $status['oldVersion'] = $theme_version;
     if (!current_user_can('update_themes')) {
         $status['error'] = 'updates_permission_denied';
         return $status;
     }
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     wp_update_themes();
     // WP < 3.7
     if (!class_exists('Automatic_Upgrader_Skin')) {
         require_once UPDRAFTPLUS_DIR . '/central/classes/class-automatic-upgrader-skin.php';
     }
     $skin = new Automatic_Upgrader_Skin();
     $upgrader = new Theme_Upgrader($skin);
     $upgrader->init();
     $result = $upgrader->bulk_upgrade(array($theme));
     if (is_array($result) && empty($result[$theme]) && is_wp_error($skin->result)) {
         $result = $skin->result;
     }
     $status['messages'] = $upgrader->skin->get_upgrade_messages();
     if (is_array($result) && !empty($result[$theme])) {
         $theme_update_data = current($result);
         /*
          * If the `update_themes` site transient is empty (e.g. when you update
          * two plugins in quick succession before the transient repopulates),
          * this may be the return.
          *
          * Preferably something can be done to ensure `update_themes` isn't empty.
          * For now, surface some sort of error here.
          */
         if ($theme_update_data === true) {
             $status['error'] = 'update_failed';
             return $status;
         }
         $new_theme_version = $this->get_theme_version($theme);
         if (false === $new_theme_version) {
             $status['error'] = 'update_failed';
             return $status;
         }
         $status['newVersion'] = $new_theme_version;
         return $status;
     } else {
         if (is_wp_error($result)) {
             $status['error'] = $result->get_error_code();
             $status['error_message'] = $result->get_error_message();
             return $status;
         } else {
             if (is_bool($result) && !$result) {
                 $status['error'] = 'unable_to_connect_to_filesystem';
                 // Pass through the error from WP_Filesystem if one was raised
                 if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
                     $status['error'] = $wp_filesystem->errors->get_error_code();
                     $status['error_message'] = $wp_filesystem->errors->get_error_message();
                 }
                 return $status;
             } else {
                 // An unhandled error occured
                 $status['error'] = 'update_failed';
                 return $status;
             }
         }
     }
 }
Пример #21
0
 private function do_bulk_upgrade($packages, $type)
 {
     if (!in_array($type, array('plugin', 'theme'))) {
         return new WP_Error('unrecognized-bulk-upgrade-type', "An unrecognized type ({$type}) was passed to do_bulk_upgrade().");
     }
     Ithemes_Sync_Functions::set_time_limit(300);
     $original_versions = array();
     foreach ($packages as $package) {
         if ('plugin' === $type) {
             $file_data = Ithemes_Sync_Functions::get_file_data(WP_PLUGIN_DIR . "/{$package}");
         } else {
             $file_data = Ithemes_Sync_Functions::get_file_data(WP_CONTENT_DIR . "/themes/{$package}/style.css");
         }
         $original_versions[$package] = $file_data['version'];
     }
     require_once ABSPATH . 'wp-admin/includes/file.php';
     require_once ABSPATH . 'wp-admin/includes/plugin.php';
     require_once ABSPATH . 'wp-admin/includes/misc.php';
     if ('plugin' === $type) {
         $upgrader = new Plugin_Upgrader($this->skin);
         $result = $upgrader->bulk_upgrade($packages);
         Ithemes_Sync_Functions::refresh_plugin_updates();
     } else {
         $upgrader = new Theme_Upgrader($this->skin);
         $result = $upgrader->bulk_upgrade($packages);
         Ithemes_Sync_Functions::refresh_theme_updates();
     }
     if (is_wp_error($result)) {
         return array('errors' => array($result->get_error_code() => $result->get_error_message()));
     } else {
         if (false === $result) {
             if ('plugin' === $type) {
                 $result = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
             } else {
                 $result = $upgrader->fs_connect(array(WP_CONTENT_DIR));
             }
             if (is_wp_error($result)) {
                 return array('errors' => array($result->get_error_code() => $result->get_error_message()));
             } else {
                 return array('errors' => array('non-connected-filesystem' => 'Unable to update due to a non-connected filesystem.'));
             }
         }
     }
     $update_details = Ithemes_Sync_Functions::get_update_details(array('verbose' => true));
     $response = array();
     $update_index = "{$type}s";
     foreach ($result as $package => $info) {
         if (false === $info) {
             $response[$package]['errors']['non-connected-filesystem'] = 'Unable to update due to a non-connected filesystem.';
         } else {
             if (is_wp_error($info)) {
                 $response[$package]['errors'][$info->get_error_code()] = $info->get_error_message();
             } else {
                 $response[$package]['wordpress_response'] = $info;
                 if ('plugin' === $type) {
                     $file_data = Ithemes_Sync_Functions::get_file_data(WP_PLUGIN_DIR . "/{$package}");
                 } else {
                     $file_data = Ithemes_Sync_Functions::get_file_data(WP_CONTENT_DIR . "/themes/{$package}/style.css");
                 }
                 $response[$package]['current_version'] = $file_data['version'];
                 if (isset($original_versions[$package])) {
                     $response[$package]['original_version'] = $original_versions[$package];
                 }
                 if (isset($update_details[$update_index][$package])) {
                     if ('plugin' === $type && isset($update_details[$update_index][$package]->new_version)) {
                         $response[$package]['current_update_version'] = $update_details[$update_index][$package]->new_version;
                     } else {
                         if ('theme' === $type && isset($update_details[$update_index][$package]['new_version'])) {
                             $response[$package]['current_update_version'] = $update_details[$update_index][$package]['new_version'];
                         }
                     }
                 }
                 if (isset($this->original_update_details[$update_index][$package])) {
                     if ('plugin' === $type && isset($this->original_update_details[$update_index][$package]->new_version)) {
                         $response[$package]['original_update_version'] = $this->original_update_details[$update_index][$package]->new_version;
                     } else {
                         if ('theme' === $type && isset($this->original_update_details[$update_index][$package]['new_version'])) {
                             $response[$package]['original_update_version'] = $this->original_update_details[$update_index][$package]['new_version'];
                         }
                     }
                 }
                 if ('plugin' === $type) {
                     $removed_old_update_data = $GLOBALS['ithemes_sync_request_handler']->remove_old_update_plugins_data($package);
                     if (!is_null($removed_old_update_data)) {
                         $response[$package]['removed_old_update_data'] = $removed_old_update_data;
                     }
                 }
                 if (!isset($response[$package]['original_update_version'])) {
                     $response[$package]['errors']['no-update'] = 'No update was available.';
                 } else {
                     if (version_compare($response[$package]['current_version'], $response[$package]['original_update_version'], '>=')) {
                         $response[$package]['success'] = 1;
                         if (isset($response[$package]['current_update_version'])) {
                             if (version_compare($response[$package]['current_version'], $response[$package]['current_update_version'], '>=')) {
                                 $response[$package]['errors']['old-update-remains-available'] = 'The original update is still listed despite the update working properly.';
                             } else {
                                 $response[$package]['errors']['new-update-available'] = 'An update is available.';
                             }
                         }
                     } else {
                         $response[$package]['errors']['unknown-error'] = 'An unknown error prevented the update from completing successfully.';
                     }
                 }
             }
         }
     }
     return $response;
 }
Пример #22
0
 function upgrade_themes($themes = false)
 {
     if (!$themes || empty($themes)) {
         return array('error' => 'No theme files for upgrade.', 'error_code' => 'no_theme_files_for_upgrade');
     }
     $current = $this->iwp_mmb_get_transient('update_themes');
     $versions = array();
     if (!empty($current)) {
         foreach ($themes as $theme) {
             if (isset($current->checked[$theme])) {
                 $versions[$current->checked[$theme]] = $theme;
             }
         }
     }
     if (class_exists('Theme_Upgrader') && class_exists('Bulk_Theme_Upgrader_Skin')) {
         $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
         $result = $upgrader->bulk_upgrade($themes);
         if (!function_exists('wp_update_themes')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_themes();
         $current = $this->iwp_mmb_get_transient('update_themes');
         $return = array();
         if (!empty($result)) {
             foreach ($result as $theme_tmp => $theme_info) {
                 if (is_wp_error($theme_info) || empty($theme_info)) {
                     $return[$theme_tmp] = array('error' => $this->iwp_mmb_get_error($theme_info), 'error_code' => 'upgrade_themes_wp_error');
                 } else {
                     if (!empty($result[$theme_tmp]) || isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true) {
                         $return[$theme_tmp] = 1;
                     } else {
                         update_option('iwp_client_forcerefresh', true);
                         $return[$theme_tmp] = array('error' => 'Could not refresh upgrade transients, please reload website data', 'error_code' => 'upgrade_themes_could_not_refresh_upgrade_transients_reload_website');
                     }
                 }
             }
             return array('upgraded' => $return);
         } else {
             return array('error' => 'Upgrade failed.', 'error_code' => 'upgrade_failed_upgrade_themes');
         }
     } else {
         ob_end_clean();
         return array('error' => 'WordPress update required first', 'error_code' => 'wordPress_update_required_first_upgrade_themes');
     }
 }
 function wp_install_themes($array)
 {
     require_once $this->data['dir'] . '/wp-admin/includes/class-wp-upgrader.php';
     global $WPQI_Installer_Skin;
     $WPQI_Installer_Skin();
     $first = true;
     foreach ($array as $name) {
         if (!$name) {
             continue;
         }
         $is_url = preg_match("/^(http|https):\\/\\//i", $name);
         $url = $is_url ? $name : "https://downloads.wordpress.org/theme/{$name}.zip";
         $upgrader = new Theme_Upgrader(new WPQI_Installer_Skin());
         $upgrader->install($url);
         if ($first) {
             switch_theme($name);
             $first = false;
         }
     }
     wp_clean_themes_cache();
 }
Пример #24
0
     if (!current_user_can('upload_themes')) {
         wp_die(__('You do not have sufficient permissions to install themes on this site.'));
     }
     check_admin_referer('theme-upload');
     $file_upload = new File_Upload_Upgrader('themezip', 'package');
     wp_enqueue_script('customize-loader');
     $title = __('Upload Theme');
     $parent_file = 'themes.php';
     $submenu_file = 'theme-install.php';
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $title = sprintf(__('Installing Theme from uploaded file: %s'), esc_html(basename($file_upload->filename)));
     $nonce = 'theme-upload';
     $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme');
     $type = 'upload';
     //Install plugin type, From Web or an Upload.
     $upgrader = new Theme_Upgrader(new Theme_Installer_Skin(compact('type', 'title', 'nonce', 'url')));
     $result = $upgrader->install($file_upload->package);
     if ($result || is_wp_error($result)) {
         $file_upload->cleanup();
     }
     include ABSPATH . 'wp-admin/admin-footer.php';
 } else {
     /**
      * Fires when a custom plugin or theme update request is received.
      *
      * The dynamic portion of the hook name, `$action`, refers to the action
      * provided in the request for wp-admin/update.php. Can be used to
      * provide custom update functionality for themes and plugins.
      *
      * @since 2.8.0
      */
Пример #25
0
 private function install_themes($themes)
 {
     require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     require_once ABSPATH . 'wp-admin/includes/file.php';
     require_once ABSPATH . 'wp-admin/includes/plugin.php';
     require_once ABSPATH . 'wp-admin/includes/theme.php';
     require_once $GLOBALS['ithemes_sync_path'] . '/upgrader-skin.php';
     $upgrader = new Theme_Upgrader(new Ithemes_Sync_Upgrader_Skin());
     $results = array();
     foreach ((array) $themes as $theme) {
         Ithemes_Sync_Functions::set_time_limit(300);
         if (preg_match('{^(http|https|ftp)://}i', $theme)) {
             $result = $upgrader->install($theme);
         } else {
             $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false)));
             if (is_wp_error($api)) {
                 $result = $api;
             } else {
                 $result = $upgrader->install($api->download_link);
             }
         }
         if (is_wp_error($result)) {
             $results[$theme]['error'] = array('error_code' => $result->get_error_code(), 'error_details' => $result->get_error_message());
         } else {
             $results[$theme]['result'] = $result;
             $theme_info = $upgrader->theme_info();
             $results[$theme]['name'] = $theme_info->get('Name');
             $results[$theme]['version'] = $theme_info->get('Version');
             if (is_object($theme_info) && is_callable(array($theme_info, 'get_stylesheet'))) {
                 $results[$theme]['slug'] = basename($theme_info->get_stylesheet());
             } else {
                 if (isset($upgrader->result) && !empty($upgrader->result['destination_name'])) {
                     $results[$theme]['slug'] = $upgrader->result['destination_name'];
                 }
             }
             if (true === $result) {
                 $results[$theme]['success'] = true;
             }
         }
     }
     Ithemes_Sync_Functions::refresh_theme_updates();
     return $results;
 }
Пример #26
0
 /**
  * Install remote plugin or theme.
  * @param $type
  *
  * @return bool
  */
 public function install($type)
 {
     if (isset($_POST['option_page']) && 'github_updater_install' == $_POST['option_page']) {
         if (empty($_POST['github_updater_branch'])) {
             $_POST['github_updater_branch'] = 'master';
         }
         /*
          * Exit early if no repo entered.
          */
         if (empty($_POST['github_updater_repo'])) {
             echo '<h3>';
             _e('A repository URI is required.', 'github-updater');
             echo '</h3>';
             return false;
         }
         /*
          * Transform URI to owner/repo
          */
         $headers = Base::parse_header_uri($_POST['github_updater_repo']);
         $_POST['github_updater_repo'] = $headers['owner_repo'];
         self::$install = Settings::sanitize($_POST);
         self::$install['repo'] = $headers['repo'];
         /*
          * Create GitHub endpoint.
          * Save Access Token if present.
          * Check for GitHub Self-Hosted.
          */
         if ('github' === self::$install['github_updater_api']) {
             if ('github.com' === $headers['host'] || empty($headers['host'])) {
                 $github_base = 'https://api.github.com';
                 $headers['host'] = 'github.com';
             } else {
                 $github_base = $headers['base_uri'] . '/api/v3';
             }
             self::$install['download_link'] = $github_base . '/repos/' . self::$install['github_updater_repo'] . '/zipball/' . self::$install['github_updater_branch'];
             /*
              * If asset is entered install it.
              */
             if (false !== stristr($headers['path'], 'releases/download')) {
                 self::$install['download_link'] = $headers['uri'];
             }
             if (!empty(self::$install['github_access_token'])) {
                 self::$install['download_link'] = add_query_arg('access_token', self::$install['github_access_token'], self::$install['download_link']);
                 parent::$options[self::$install['repo']] = self::$install['github_access_token'];
             } elseif (!empty(parent::$options['github_access_token']) && ('github.com' === $headers['host'] || empty($headers['host']))) {
                 self::$install['download_link'] = add_query_arg('access_token', parent::$options['github_access_token'], self::$install['download_link']);
             }
         }
         /*
          * Create Bitbucket endpoint and instantiate class Bitbucket_API.
          * Save private setting if present.
          * Ensures `maybe_authenticate_http()` is available.
          */
         if ('bitbucket' === self::$install['github_updater_api']) {
             self::$install['download_link'] = 'https://bitbucket.org/' . self::$install['github_updater_repo'] . '/get/' . self::$install['github_updater_branch'] . '.zip';
             if (isset(self::$install['is_private'])) {
                 parent::$options[self::$install['repo']] = 1;
             }
             new Bitbucket_API((object) $type);
         }
         /*
          * Create GitLab endpoint.
          * Check for GitLab Self-Hosted.
          */
         if ('gitlab' === self::$install['github_updater_api']) {
             if ('gitlab.com' === $headers['host'] || empty($headers['host'])) {
                 $gitlab_base = 'https://gitlab.com';
                 $headers['host'] = 'gitlab.com';
             } else {
                 $gitlab_base = $headers['base_uri'];
             }
             self::$install['download_link'] = implode('/', array($gitlab_base, self::$install['github_updater_repo'], 'repository/archive.zip'));
             self::$install['download_link'] = add_query_arg('ref', self::$install['github_updater_branch'], self::$install['download_link']);
             if (!empty(self::$install['gitlab_private_token'])) {
                 self::$install['download_link'] = add_query_arg('private_token', self::$install['gitlab_private_token'], self::$install['download_link']);
                 if ('gitlab.com' === $headers['host']) {
                     parent::$options['gitlab_private_token'] = self::$install['gitlab_private_token'];
                 } else {
                     parent::$options['gitlab_enterprise_token'] = self::$install['gitlab_private_token'];
                 }
             } elseif (!empty(parent::$options['gitlab_private_token'])) {
                 self::$install['download_link'] = add_query_arg('private_token', parent::$options['gitlab_private_token'], self::$install['download_link']);
             }
         }
         parent::$options['github_updater_install_repo'] = self::$install['repo'];
         if (defined('GITHUB_UPDATER_EXTENDED_NAMING') && GITHUB_UPDATER_EXTENDED_NAMING && 'plugin' === $type) {
             parent::$options['github_updater_install_repo'] = implode('-', array(self::$install['github_updater_api'], $headers['owner'], self::$install['repo']));
         }
         update_site_option('github_updater', parent::$options);
         $url = self::$install['download_link'];
         $nonce = wp_nonce_url($url);
         if ('plugin' === $type) {
             $plugin = self::$install['repo'];
             /*
              * Create a new instance of Plugin_Upgrader.
              */
             $upgrader = new \Plugin_Upgrader($skin = new \Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api')));
         }
         if ('theme' === $type) {
             $theme = self::$install['repo'];
             /*
              * Create a new instance of Theme_Upgrader.
              */
             $upgrader = new \Theme_Upgrader($skin = new \Theme_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'theme', 'api')));
         }
         /*
          * Perform the action and install the plugin from the $source urldecode().
          * Flush cache so we can make sure that the installed plugins/themes list is always up to date.
          */
         $upgrader->install($url);
         wp_cache_flush();
     }
     if (!isset($_POST['option_page']) || !('github_updater_install' === $_POST['option_page'])) {
         $this->create_form($type);
     }
 }
Пример #27
0
function wp_update_theme($theme, $feedback = '')
{
    if (!empty($feedback)) {
        add_filter('update_feedback', $feedback);
    }
    include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $upgrader = new Theme_Upgrader();
    return $upgrader->upgrade($theme);
}
Пример #28
0
 public function upgrade_themes($themes = false)
 {
     if (!$themes || empty($themes)) {
         return array('error' => 'No theme files for upgrade.');
     }
     $current = $this->mmb_get_transient('update_themes');
     $versions = array();
     if (!empty($current)) {
         foreach ($themes as $theme) {
             if (isset($current->checked[$theme])) {
                 $versions[$current->checked[$theme]] = $theme;
             }
         }
     }
     if (class_exists('Theme_Upgrader')) {
         /** @handled class */
         $upgrader = new Theme_Upgrader(mwp_container()->getUpdaterSkin());
         $result = $upgrader->bulk_upgrade($themes);
         if (!function_exists('wp_update_themes')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_themes();
         $current = $this->mmb_get_transient('update_themes');
         $return = array();
         if (!empty($result)) {
             foreach ($result as $theme_tmp => $theme_info) {
                 if (is_wp_error($theme_info) || empty($theme_info)) {
                     $return[$theme_tmp] = $this->mmb_get_error($theme_info);
                 } else {
                     if (!empty($result[$theme_tmp]) || isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true) {
                         $return[$theme_tmp] = 1;
                     } else {
                         $return[$theme_tmp] = 'Could not refresh upgrade transients, please reload website data';
                     }
                 }
             }
             return array('upgraded' => $return);
         } else {
             return array('error' => 'Upgrade failed.');
         }
     } else {
         return array('error' => 'WordPress update required first');
     }
 }
Пример #29
0
/**
 * This was once used to kick-off the Theme Updater.
 *
 * Deprecated in favor of instantating a Theme_Upgrader instance directly,
 * and calling the 'upgrade' method.
 * Unused since 2.8.0.
 *
 * @since 2.7.0
 * @deprecated 3.7.0
 * @see Theme_Upgrader
 */
function wp_update_theme($theme, $feedback = '')
{
    _deprecated_function(__FUNCTION__, '3.7', 'new Theme_Upgrader();');
    if (!empty($feedback)) {
        add_filter('update_feedback', $feedback);
    }
    include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $upgrader = new Theme_Upgrader();
    return $upgrader->upgrade($theme);
}
 /**
  * Install a new plugin.
  *
  * @since  4.0.0
  * @param  int    $pid The project ID.
  * @param  string $error Output parameter. Holds error message.
  * @param  bool   $die_on_error If set to false the function will return
  *                false instead of die().
  * @return bool True on success.
  */
 public function install_project($pid, &$error = false, $die_on_error = true)
 {
     if ($this->is_project_installed($pid)) {
         if ($die_on_error) {
             wp_send_json_error(array('message' => __('Already installed', 'wdpmudev')));
         } else {
             return false;
         }
     }
     $project = WPMUDEV_Dashboard::$site->get_project_infos($pid);
     // Make sure Upfront is available before an upfront theme is installed.
     if ($project->need_upfront && !$this->is_upfront_installed()) {
         $this->install_project($this->id_upfront, $error, false);
     }
     // For plugins_api..
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     ob_start();
     // Save on a bit of bandwidth.
     $api = plugins_api('plugin_information', array('slug' => 'wpmudev_install-' . $pid, 'fields' => array('sections' => false)));
     if (is_wp_error($api)) {
         if ($die_on_error) {
             wp_send_json_error(array('message' => __('No data found', 'wpmudev')));
         } else {
             return false;
         }
     }
     $skin = new Automatic_Upgrader_Skin();
     /*
      * Set before the update:
      * WP will refresh local cache via action-hook before the install()
      * method is finished. That refresh call must scan the FS again.
      */
     $this->flush_fs_cache = true;
     $this->flush_info_cache = true;
     switch ($project->type) {
         case 'plugin':
             $upgrader = new Plugin_Upgrader($skin);
             $upgrader->install($api->download_link);
             break;
         case 'theme':
             $upgrader = new Theme_Upgrader($skin);
             $upgrader->install($api->download_link);
             break;
     }
     $details = ob_get_clean();
     if (is_wp_error($skin->result)) {
         $error = $skin->result->get_error_message();
         $this->refresh_local_projects('remote');
         return false;
     }
     // API call to inform wpmudev site about the change.
     $this->refresh_local_projects('remote');
     // Fetch latest project details.
     $project = WPMUDEV_Dashboard::$site->get_project_infos($pid);
     if (!$project->is_installed && !$error) {
         $error = __('Installation failed. Maybe wrong folder permissions.', 'wpmudev');
     }
     return $project->is_installed;
 }