本文整理汇总了PHP中Theme_Upgrader::bulk_upgrade方法的典型用法代码示例。如果您正苦于以下问题:PHP Theme_Upgrader::bulk_upgrade方法的具体用法?PHP Theme_Upgrader::bulk_upgrade怎么用?PHP Theme_Upgrader::bulk_upgrade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Theme_Upgrader
的用法示例。
在下文中一共展示了Theme_Upgrader::bulk_upgrade方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: explode
}
check_admin_referer('bulk-update-themes');
if (isset($_GET['themes'])) {
$themes = explode(',', stripslashes($_GET['themes']));
} elseif (isset($_POST['checked'])) {
$themes = (array) $_POST['checked'];
} else {
$themes = array();
}
$themes = array_map('urldecode', $themes);
$url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
$nonce = 'bulk-update-themes';
wp_enqueue_script('updates');
iframe_header();
$upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('nonce', 'url')));
$upgrader->bulk_upgrade($themes);
iframe_footer();
} elseif ('install-theme' == $action) {
if (!current_user_can('install_themes')) {
wp_die(__('You do not have sufficient permissions to install themes on this site.'));
}
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
//for themes_api..
check_admin_referer('install-theme_' . $theme);
$api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false)));
//Save on a bit of bandwidth.
if (is_wp_error($api)) {
wp_die($api);
}
wp_enqueue_script('customize-loader');
$title = __('Install Themes');
示例4: upgradePluginTheme
/**
* Expects $_POST['type'] == plugin/theme
* $_POST['list'] == 'theme1,theme2' or 'plugin1,plugin2'
*/
function upgradePluginTheme()
{
//Prevent disable/re-enable at upgrade
define('DOING_CRON', true);
MainWP_Helper::getWPFilesystem();
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.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';
}
if (file_exists(ABSPATH . '/wp-admin/includes/template.php')) {
include_once ABSPATH . '/wp-admin/includes/template.php';
}
if (file_exists(ABSPATH . '/wp-admin/includes/misc.php')) {
include_once ABSPATH . '/wp-admin/includes/misc.php';
}
include_once ABSPATH . '/wp-admin/includes/file.php';
include_once ABSPATH . '/wp-admin/includes/plugin.php';
$information = array();
$information['upgrades'] = array();
$mwp_premium_updates_todo = array();
$mwp_premium_updates_todo_slugs = array();
if (isset($_POST['type']) && 'plugin' === $_POST['type']) {
include_once ABSPATH . '/wp-admin/includes/update.php';
if (null !== $this->filterFunction) {
add_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
}
$plugins = explode(',', urldecode($_POST['list']));
// To fix: backupbuddy update
if (in_array('backupbuddy/backupbuddy.php', $plugins)) {
if (isset($GLOBALS['ithemes_updater_path'])) {
if (!class_exists('Ithemes_Updater_Settings')) {
require $GLOBALS['ithemes_updater_path'] . '/settings.php';
}
if (class_exists('Ithemes_Updater_Settings')) {
$ithemes_updater = new Ithemes_Updater_Settings();
$ithemes_updater->update();
}
}
}
////
global $wp_current_filter;
$wp_current_filter[] = 'load-plugins.php';
@wp_update_plugins();
$information['plugin_updates'] = get_plugin_updates();
$plugins = explode(',', urldecode($_POST['list']));
$premiumPlugins = array();
$premiumUpdates = get_option('mainwp_premium_updates');
if (is_array($premiumUpdates)) {
$newPlugins = array();
foreach ($plugins as $plugin) {
if (in_array($plugin, $premiumUpdates)) {
$premiumPlugins[] = $plugin;
} else {
$newPlugins[] = $plugin;
}
}
$plugins = $newPlugins;
}
if (count($plugins) > 0) {
//@see wp-admin/update.php
$upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
$result = $upgrader->bulk_upgrade($plugins);
if (!empty($result)) {
foreach ($result as $plugin => $info) {
if (empty($info)) {
$information['upgrades'][$plugin] = false;
} else {
$information['upgrades'][$plugin] = true;
}
}
} else {
MainWP_Helper::error(__('Bad request', 'mainwp-child'));
}
}
if (count($premiumPlugins) > 0) {
$mwp_premium_updates = apply_filters('mwp_premium_perform_update', array());
if (is_array($mwp_premium_updates) && is_array($premiumPlugins)) {
foreach ($premiumPlugins as $premiumPlugin) {
foreach ($mwp_premium_updates as $key => $update) {
$slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
if (0 === strcmp($slug, $premiumPlugin)) {
$mwp_premium_updates_todo[$key] = $update;
$mwp_premium_updates_todo_slugs[] = $premiumPlugin;
}
}
}
}
unset($mwp_premium_updates);
$premiumUpgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
}
if (count($plugins) <= 0 && count($premiumPlugins) <= 0) {
MainWP_Helper::error(__('Bad request', 'mainwp-child'));
}
if (null !== $this->filterFunction) {
remove_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
//.........这里部分代码省略.........
示例5: upgrade_themes
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');
}
}
示例6: do_bulk_upgrade
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 {
//.........这里部分代码省略.........
示例7: array
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');
}
}
示例8: _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;
}
}
}
}
示例9: ajax_upgrade_theme
/**
* AJAX handler for upgrading a theme.
*
* @since 1.0.0
*
* @see Theme_Upgrader
* @codeCoverageIgnore
*/
public function ajax_upgrade_theme()
{
check_ajax_referer('updates');
global $wp_filesystem;
$theme = urldecode(sanitize_file_name(trim($_POST['theme'])));
$status = array('update' => 'theme', 'slug' => $theme, 'oldVersion' => '', 'newVersion' => '');
$theme_data = wp_get_theme($theme);
if ($theme_data->exists() && $theme_data->get('Version')) {
$status['oldVersion'] = sprintf(__('Version %s', 'envato-market'), $theme_data->get('Version'));
}
if (!current_user_can('update_themes')) {
$status['error'] = __('You do not have sufficient permissions to update themes for this site.', 'envato-market');
wp_send_json_error($status);
}
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Theme_Upgrader($skin);
$result = $upgrader->bulk_upgrade(array($theme));
if (is_array($result) && empty($result[$theme]) && is_wp_error($skin->result)) {
$result = $skin->result;
}
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 themes 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 (true === $theme_update_data) {
wp_send_json_error($result);
}
$theme_data = wp_get_theme($result[$theme]['destination_name']);
if ($theme_data->exists() && $theme_data->get('Version')) {
$status['newVersion'] = sprintf(__('Version %s', 'envato-market'), $theme_data->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) {
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['error'] = __('Unable to connect to the filesystem. Please confirm your credentials.', 'envato-market');
// 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_message();
}
wp_send_json_error($status);
}
}
}
}
示例10: array
function upgrade_themes($themes = false, $theme_details = false, $userid)
{
global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
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) {
foreach ($theme_details as $key => $theme_detail) {
if ($theme_tmp == $theme_detail['theme_tmp']) {
$current_theme = array();
$current_theme['name'] = $current_theme['slug'] = $theme_detail['name'];
// slug is used to get short description. Here theme name as slug.
$current_theme['old_version'] = $theme_detail['old_version'];
$current_theme['updated_version'] = $theme_detail['new_version'];
$iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('themes', 'update', $iwp_activities_log_post_type, (object) $current_theme, $userid);
unset($current_theme);
break;
}
}
$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');
}
}
示例11: wp_ajax_update_theme
/**
* Ajax handler for updating a theme.
*
* @since 4.6.0
*
* @see Theme_Upgrader
*/
function wp_ajax_update_theme()
{
check_ajax_referer('updates');
if (empty($_POST['slug'])) {
wp_send_json_error(array('slug' => '', 'errorCode' => 'no_theme_specified', 'errorMessage' => __('No theme specified.')));
}
$stylesheet = preg_replace('/[^A-z0-9_\\-]/', '', wp_unslash($_POST['slug']));
$status = array('update' => 'theme', 'slug' => $stylesheet, 'newVersion' => '');
if (!current_user_can('update_themes')) {
$status['errorMessage'] = __('Sorry, you are not allowed to update themes for 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();
}
$skin = new WP_Ajax_Upgrader_Skin();
$upgrader = new Theme_Upgrader($skin);
$result = $upgrader->bulk_upgrade(array($stylesheet));
if (defined('WP_DEBUG') && WP_DEBUG) {
$status['debug'] = $skin->get_upgrade_messages();
}
if (is_wp_error($skin->result)) {
$status['errorCode'] = $skin->result->get_error_code();
$status['errorMessage'] = $skin->result->get_error_message();
wp_send_json_error($status);
} elseif ($skin->get_errors()->get_error_code()) {
$status['errorMessage'] = $skin->get_error_messages();
wp_send_json_error($status);
} elseif (is_array($result) && !empty($result[$stylesheet])) {
// Theme is already at the latest version.
if (true === $result[$stylesheet]) {
$status['errorMessage'] = $upgrader->strings['up_to_date'];
wp_send_json_error($status);
}
$theme = wp_get_theme($stylesheet);
if ($theme->get('Version')) {
$status['newVersion'] = $theme->get('Version');
}
wp_send_json_success($status);
} elseif (false === $result) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessage'] = __('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['errorMessage'] = esc_html($wp_filesystem->errors->get_error_message());
}
wp_send_json_error($status);
}
// An unhandled error occurred.
$status['errorMessage'] = __('Update failed.');
wp_send_json_error($status);
}
示例12: define
define("ABSPATH", dirname(__FILE__) . "/");
include_once ABSPATH . "wp-config.php";
include_once ABSPATH . "wp-admin/includes/file.php";
include_once ABSPATH . "wp-admin/includes/plugin.php";
include_once ABSPATH . "wp-admin/includes/theme.php";
include_once ABSPATH . "wp-admin/includes/misc.php";
include_once ABSPATH . "wp-admin/includes/template.php";
include_once ABSPATH . "wp-admin/includes/class-wp-upgrader.php";
include_once ABSPATH . "wp-includes/update.php";
if (!class_exists("Theme_Upgrader") || !class_exists("Bulk_Theme_Upgrader_Skin")) {
echo '__CLIENT__RESPONCE__START__' . serialize(array(2, $GLOBALS["__i_client_error_stack"])) . "__CLIENT__RESPONCE__END__";
exit;
}
$themes = $_POST["id"];
$upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact("nonce", "url")));
$result = $upgrader->bulk_upgrade($themes);
@wp_update_themes();
echo '__CLIENT__RESPONCE__START__' . serialize(array($result, $GLOBALS["__i_client_error_stack"])) . "__CLIENT__RESPONCE__END__";
} else {
if ($_POST["cmd"] === "disable") {
define("ABSPATH", dirname(__FILE__) . "/");
include_once ABSPATH . "wp-config.php";
include_once ABSPATH . "wp-admin/includes/file.php";
include_once ABSPATH . "wp-admin/includes/plugin.php";
include_once ABSPATH . "wp-admin/includes/theme.php";
include_once ABSPATH . "wp-admin/includes/misc.php";
include_once ABSPATH . "wp-admin/includes/template.php";
$list = is_array($_POST["id"]) ? $_POST["id"] : array($_POST["id"]);
deactivate_plugins($list);
echo '__CLIENT__RESPONCE__START__' . serialize(array(true, $GLOBALS["__i_client_error_stack"])) . "__CLIENT__RESPONCE__END__";
}