本文整理汇总了PHP中Theme_Upgrader类的典型用法代码示例。如果您正苦于以下问题:PHP Theme_Upgrader类的具体用法?PHP Theme_Upgrader怎么用?PHP Theme_Upgrader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Theme_Upgrader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hooks_theme_install_or_update
/**
* @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));
}
}
}
示例2: update
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;
}
示例3: install
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: bruteprotect_bulk_update_themes
/**
* 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: wp_ajax_update_theme
/**
* 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);
}
示例6: install
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: install
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');
}
示例8: autoupdater_refresh_theme
/**
* 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);
}
}
示例9: puma_theme_update_callback
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;
}
示例10: _wprp_upgrade_theme
/**
* 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');
}
示例11: upgrade_bsf_product
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);
//.........这里部分代码省略.........
示例12: install_theme
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);
}
示例13: theme_action
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);
}
示例14: theme_install_or_update
/**
* 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'));
}
}
}
示例15: _update_theme
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;
}
}
}
}