本文整理汇总了PHP中Language_Pack_Upgrader::upgrade方法的典型用法代码示例。如果您正苦于以下问题:PHP Language_Pack_Upgrader::upgrade方法的具体用法?PHP Language_Pack_Upgrader::upgrade怎么用?PHP Language_Pack_Upgrader::upgrade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Language_Pack_Upgrader
的用法示例。
在下文中一共展示了Language_Pack_Upgrader::upgrade方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: qtranxf_updateGettextDatabasesEx
/**
* return 'true', if no update needed,
* or 'false', if update is impossible to do,
* or 0, if all languages were updated successfully,
* or positive integer number of errors occurred on languages update.
*/
function qtranxf_updateGettextDatabasesEx($force = false, $only_for_language = '')
{
global $q_config;
if ($only_for_language && !qtranxf_isEnabled($only_for_language)) {
return false;
}
if (!is_dir(WP_LANG_DIR)) {
if (!@mkdir(WP_LANG_DIR)) {
return false;
}
}
$next_update = get_option('qtranslate_next_update_mo');
if (time() < $next_update && !$force) {
return true;
}
update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
include ABSPATH . WPINC . '/version.php';
// include an unmodified $wp_version
$result = translations_api('core', array('version' => $wp_version));
if (is_wp_error($result)) {
qtranxf_add_error(__('Gettext databases <strong>not</strong> updated:', 'qtranslate') . ' ' . $result->get_error_message());
return false;
}
set_time_limit(300);
$langs = empty($only_for_language) ? $q_config['enabled_languages'] : array($only_for_language);
$errcnt = 0;
foreach ($result['translations'] as $translation) {
$locale = $translation['language'];
$lang = null;
foreach ($langs as $lng) {
if ($q_config['locale'][$lng] != $locale) {
continue;
}
$lang = $lng;
break;
}
if (!$lang) {
continue;
}
$translation = (object) $translation;
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$translation->type = 'core';
$result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
if (is_wp_error($result)) {
qtranxf_add_error(sprintf(__('Failed to update gettext database for "%s": %s', 'qtranslate'), $q_config['language_name'][$lang], $result->get_error_message()));
++$errcnt;
}
}
return $errcnt;
}
示例2: qtranxf_updateGettextDatabasesEx
function qtranxf_updateGettextDatabasesEx($force = false, $only_for_language = '')
{
global $q_config;
if ($only_for_language && !qtranxf_isEnabled($only_for_language)) {
return false;
}
if (!is_dir(WP_LANG_DIR)) {
if (!@mkdir(WP_LANG_DIR)) {
return false;
}
}
$next_update = get_option('qtranslate_next_update_mo');
if (time() < $next_update && !$force) {
return true;
}
update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
include ABSPATH . WPINC . '/version.php';
// include an unmodified $wp_version
$result = translations_api('core', array('version' => $wp_version));
if (is_wp_error($result)) {
return $result;
} else {
foreach ($result['translations'] as $translation) {
$locale = substr($translation['language'], 0, 2);
if (isset($q_config['locale'][$locale]) && $q_config['locale'][$locale] == $translation['language'] && qtranxf_isEnabled($locale)) {
$translation = (object) $translation;
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$translation->type = 'core';
$result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
}
}
return true;
}
}
示例3: update
/**
* Update an item, if appropriate.
*
* @since 3.7.0
*
* @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
* @param object $item The update offer.
*/
public function update($type, $item)
{
$skin = new Automatic_Upgrader_Skin();
switch ($type) {
case 'core':
// The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter.
add_filter('update_feedback', array($skin, 'feedback'));
$upgrader = new Core_Upgrader($skin);
$context = ABSPATH;
break;
case 'plugin':
$upgrader = new Plugin_Upgrader($skin);
$context = WP_PLUGIN_DIR;
// We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR
break;
case 'theme':
$upgrader = new Theme_Upgrader($skin);
$context = get_theme_root($item->theme);
break;
case 'translation':
$upgrader = new Language_Pack_Upgrader($skin);
$context = WP_CONTENT_DIR;
// WP_LANG_DIR;
break;
}
// Determine whether we can and should perform this update.
if (!$this->should_update($type, $item, $context)) {
return false;
}
$upgrader_item = $item;
switch ($type) {
case 'core':
$skin->feedback(__('Updating to WordPress %s'), $item->version);
$item_name = sprintf(__('WordPress %s'), $item->version);
break;
case 'theme':
$upgrader_item = $item->theme;
$theme = wp_get_theme($upgrader_item);
$item_name = $theme->Get('Name');
$skin->feedback(__('Updating theme: %s'), $item_name);
break;
case 'plugin':
$upgrader_item = $item->plugin;
$plugin_data = get_plugin_data($context . '/' . $upgrader_item);
$item_name = $plugin_data['Name'];
$skin->feedback(__('Updating plugin: %s'), $item_name);
break;
case 'translation':
$language_item_name = $upgrader->get_name_for_update($item);
$item_name = sprintf(__('Translations for %s'), $language_item_name);
$skin->feedback(sprintf(__('Updating translations for %1$s (%2$s)…'), $language_item_name, $item->language));
break;
}
$allow_relaxed_file_ownership = false;
if ('core' == $type && isset($item->new_files) && !$item->new_files) {
$allow_relaxed_file_ownership = true;
}
// Boom, This sites about to get a whole new splash of paint!
$upgrade_result = $upgrader->upgrade($upgrader_item, array('clear_update_cache' => false, 'pre_check_md5' => false, 'attempt_rollback' => true, 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership));
// If the filesystem is unavailable, false is returned.
if (false === $upgrade_result) {
$upgrade_result = new WP_Error('fs_unavailable', __('Could not access filesystem.'));
}
// Core doesn't output this, so let's append it so we don't get confused.
if ('core' == $type) {
if (is_wp_error($upgrade_result)) {
$skin->error(__('Installation Failed'), $upgrade_result);
} else {
$skin->feedback(__('WordPress updated successfully'));
}
}
$this->update_results[$type][] = (object) array('item' => $item, 'result' => $upgrade_result, 'name' => $item_name, 'messages' => $skin->get_upgrade_messages());
return $upgrade_result;
}
示例4: wp_download_language_pack
/**
* Download a language pack.
*
* @since 4.0.0
*
* @see wp_get_available_translations()
*
* @param string $download Language code to download.
* @return string|bool Returns the language code if successfully downloaded
* (or already installed), or false on failure.
*/
function wp_download_language_pack($download)
{
// Check if the translation is already installed.
if (in_array($download, get_available_languages())) {
return $download;
}
if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
return false;
}
// Confirm the translation is one we can download.
$translations = wp_get_available_translations();
if (!$translations) {
return false;
}
foreach ($translations as $translation) {
if ($translation['language'] === $download) {
$translation_to_load = true;
break;
}
}
if (empty($translation_to_load)) {
return false;
}
$translation = (object) $translation;
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$translation->type = 'core';
$result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
if (!$result || is_wp_error($result)) {
return false;
}
return $translation->language;
}
示例5: upgrade
static function upgrade($type, $item)
{
$skin = new Automatic_Upgrader_Skin();
switch ($type) {
case 'core':
// The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter
add_filter('update_feedback', array($skin, 'feedback'));
$upgrader = new Core_Upgrader($skin);
$context = ABSPATH;
break;
case 'plugin':
$upgrader = new Plugin_Upgrader($skin);
$context = WP_PLUGIN_DIR;
// We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR
break;
case 'theme':
$upgrader = new Theme_Upgrader($skin);
$context = get_theme_root($item);
break;
case 'language':
$upgrader = new Language_Pack_Upgrader($skin);
$context = WP_CONTENT_DIR;
// WP_LANG_DIR;
break;
}
// Determine if we can perform this upgrade or not
if (!self::should_auto_update($type, $item, $context) || !self::can_auto_update($context, $skin)) {
return false;
}
switch ($type) {
case 'core':
$skin->feedback(__('Updating to WordPress %s'), $item->version);
$item_name = sprintf(__('WordPress %s'), $item->version);
break;
case 'theme':
$theme = wp_get_theme($item);
$item_name = $theme->Get('Name');
$skin->feedback(__('Updating theme: %s'), $item_name);
break;
case 'plugin':
$plugin_data = get_plugin_data($context . '/' . $item);
$item_name = $plugin_data['Name'];
$skin->feedback(__('Updating plugin: %s'), $item_name);
break;
case 'language':
if ('theme' == $item->type) {
$theme = wp_get_theme($item->slug);
$skin->feedback(sprintf(__('Updating the %1$s translation for the %2$s theme'), $item->language, $theme->Get('Name')));
$item_name = sprintf(__('%1$s translation for the %2$s theme'), $item->language, $theme->Get('Name'));
} elseif ('plugin' == $item->type) {
$plugin_data = get_plugins('/' . $item->slug);
$plugin_data = array_shift($plugin_data);
$skin->feedback(sprintf(__('Updating the %1$s translation for the %2$s plugin'), $item->language, $plugin_data['Name']));
$item_name = sprintf(__('%1$s translation for the %2$s plugin'), $item->language, $plugin_data['Name']);
} else {
$skin->feedback(sprintf(__('Updating %s translation'), $item->language));
$item_name = sprintf(__('%s translation'), $item->language);
}
break;
}
// Boom, This sites about to get a whole new splash of paint!
$upgrade_result = $upgrader->upgrade($item, array('clear_update_cache' => false, 'pre_check_md5' => false, 'attempt_rollback' => true));
// Core doesn't output this, so lets append it so we don't get confused
if ('core' == $type) {
if (is_wp_error($upgrade_result)) {
$skin->error(__('Installation Failed'), $upgrade_result);
} else {
$skin->feedback(__('WordPress updated successfully'));
}
}
self::$upgrade_results[$type][] = (object) array('item' => $item, 'result' => $upgrade_result, 'name' => $item_name, 'messages' => $skin->get_upgrade_messages());
return $upgrade_result;
}
示例6: qtranxf_updateGettextDatabasesEx
/**
* return 'true', if no update needed,
* or 'false', if update is impossible to do,
* or 0, if all languages were updated successfully,
* or positive integer number of errors occurred on languages update.
*/
function qtranxf_updateGettextDatabasesEx($force = false, $only_for_language = '')
{
if (empty($only_for_language)) {
if (!$force) {
$next_update = get_option('qtranslate_next_update_mo');
if (time() < $next_update) {
return true;
}
}
update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
}
if (!is_dir(WP_LANG_DIR)) {
if (!@mkdir(WP_LANG_DIR)) {
return false;
}
}
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
//include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
//$result = translations_api( 'core', array( 'version' => $wp_version ));
//if ( is_wp_error( $result ) ){
// qtranxf_add_warning(__('Gettext databases <strong>not</strong> updated:', 'qtranslate') . ' ' . $result->get_error_message());
// return false;
//}
//$translations = $result['translations'];
$translations = wp_get_available_translations();
if (empty($translations)) {
qtranxf_add_warning(__('Gettext databases <strong>not</strong> updated:', 'qtranslate') . ' ' . __('Failed to fetch the list of available translations.', 'qtranslate'));
return false;
}
set_time_limit(300);
if (empty($only_for_language)) {
global $q_config;
$langs = $q_config['enabled_languages'];
$locales = $q_config['locale'];
} else {
$langs = array($only_for_language);
$locales = qtranxf_language_configured('locale');
}
$errcnt = 0;
/*
//qtranxf_dbg_log('qtranxf_updateGettextDatabasesEx: count($translations): ',count($translations));
//qtranxf_dbg_log('qtranxf_updateGettextDatabasesEx: $translations: ',$translations);
foreach ( $translations as $loc => $translation ) {
$locale = $translation['language'];
$lang = null;
foreach($langs as $lng) {
if(!isset($locales[$lng])){
$locales = qtranxf_language_configured('locale');
if(!isset($locales[$lng])) continue;
}
if($locales[$lng] != $locale) continue;
$lang = $lng;
break;
}
if(!$lang) continue;
*/
foreach ($langs as $lang) {
$loc = $locales[$lang];
if (!isset($translations[$loc])) {
continue;
}
$mo = WP_LANG_DIR . '/' . $loc . '.mo';
$mo_ok = file_exists($mo);
//qtranxf_dbg_log('qtranxf_updateGettextDatabasesEx: $mo_ok for '.$mo.': ',$mo_ok);
if ($mo_ok) {
continue;
}
//WP now takes care of translations updates on its own
$translation = (object) $translations[$loc];
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$translation->type = 'core';
$result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
if (is_wp_error($result)) {
qtranxf_add_warning(sprintf(__('Failed to update gettext database for "%s": %s', 'qtranslate'), $lang, $result->get_error_message()));
++$errcnt;
}
}
return $errcnt;
}
示例7: update
/**
* Updates the active translation of core, plugins, and themes.
*
* [--dry-run]
* : Preview which translations would be updated.
*
* @subcommand update
*/
public function update($args, $assoc_args)
{
// Ignore updates for the default locale.
if ('en_US' == get_locale()) {
\WP_CLI::success("Translations updates are not needed for the 'English (US)' locale.");
return;
}
$this->wp_clean_update_cache();
// Clear existing update caches.
wp_version_check();
// Check for Core translation updates.
wp_update_themes();
// Check for Theme translation updates.
wp_update_plugins();
// Check for Plugin translation updates.
$updates = wp_get_translation_updates();
// Retrieves a list of all translations updates available.
if (empty($updates)) {
\WP_CLI::success('Translations are up to date.');
return;
}
// Gets a list of all languages.
$all_languages = $this->get_all_languages();
// Formats the updates list.
foreach ($updates as $update) {
if ('plugin' == $update->type) {
$plugin_data = array_shift(get_plugins('/' . $update->slug));
$name = $plugin_data['Name'];
} elseif ('theme' == $update->type) {
$theme_data = wp_get_theme($update->slug);
$name = $theme_data['Name'];
} else {
// Core
$name = 'WordPress';
}
// Gets the translation data.
$translation = (object) reset(wp_list_filter($all_languages, array('language' => $update->language)));
$update->Type = ucfirst($update->type);
$update->Name = $name;
$update->Version = $update->version;
$update->Language = $translation->english_name;
}
// Only preview which translations would be updated.
if (\WP_CLI\Utils\get_flag_value($assoc_args, 'dry-run')) {
\WP_CLI::line(sprintf('Available %d translations updates:', count($updates)));
\WP_CLI\Utils\format_items('table', $updates, array('Type', 'Name', 'Version', 'Language'));
return;
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new \Language_Pack_Upgrader(new \Automatic_Upgrader_Skin());
$results = array();
// Update translations.
foreach ($updates as $update) {
\WP_CLI::line("Updating '{$update->Language}' translation for {$update->Name} {$update->Version}...");
\WP_CLI::line("Downloading translation from {$update->package}...");
$result = $upgrader->upgrade($update);
if ($result) {
\WP_CLI::line('Translation updated successfully.');
} else {
\WP_CLI::line('Translation update failed.');
}
$results[] = $result;
}
$num_to_update = count($updates);
$num_updated = count(array_filter($results));
$line = "Updated {$num_updated}/{$num_to_update} translations.";
if ($num_to_update == $num_updated) {
\WP_CLI::success($line);
} else {
if ($num_updated > 0) {
\WP_CLI::warning($line);
} else {
\WP_CLI::error($line);
}
}
}
示例8: download_language_pack
/**
* Download a language pack.
*
* @see wp_download_language_pack()
*
* @param string $download Language code to download.
* @return string|WP_Error Returns the language code if successfully downloaded, or a WP_Error object on failure.
*/
private function download_language_pack($download)
{
$translations = $this->get_all_languages();
foreach ($translations as $translation) {
if ($translation['language'] === $download) {
$translation_to_load = true;
break;
}
}
if (empty($translation_to_load)) {
return new \WP_Error('not_found', "Language '{$download}' not found.");
}
$translation = (object) $translation;
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new \Automatic_Upgrader_Skin();
$upgrader = new \Language_Pack_Upgrader($skin);
$translation->type = 'core';
$result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
if (is_wp_error($result)) {
return $result;
} else {
if (!$result) {
return new \WP_Error('not_installed', "Could not install language '{$download}'.");
}
}
return $translation->language;
}
示例9: foreach
function update_translations()
{
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// Clear the cache.
wp_update_themes();
$available_themes_updates = get_site_transient('update_themes');
if (!isset($available_themes_updates->translations) || empty($available_themes_updates->translations)) {
return new WP_Error('nothing_to_translate');
}
foreach ($available_themes_updates->translations as $translation) {
$theme = $translation['slug'];
if (!in_array($translation['slug'], $this->themes)) {
$this->log[$theme][] = __('No update needed', 'jetpack');
continue;
}
/**
* Pre-upgrade action
*
* @since 4.4
*
* @param object $theme WP_Theme object
* @param array $themes Array of theme objects
*/
do_action('jetpack_pre_theme_upgrade_translations', $theme, $this->themes);
// Objects created inside the for loop to clean the messages for each theme
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$upgrader->init();
$result = $upgrader->upgrade((object) $translation);
$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;
}
示例10: foreach
function update_translations()
{
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// Clear the cache.
wp_clean_plugins_cache();
ob_start();
wp_update_plugins();
// Check for Plugin updates
ob_end_clean();
$available_updates = get_site_transient('update_plugins');
if (!isset($available_updates->translations) || empty($available_updates->translations)) {
return new WP_Error('nothing_to_translate');
}
$update_attempted = false;
$result = false;
foreach ($this->plugins as $plugin) {
$this->slug = Jetpack_Autoupdate::get_plugin_slug($plugin);
$translation = array_filter($available_updates->translations, array($this, 'get_translation'));
if (empty($translation)) {
$this->log[$plugin][] = __('No update needed', 'jetpack');
continue;
}
/**
* Pre-upgrade action
*
* @since 4.4
*
* @param array $plugin Plugin data
* @param array $plugin Array of plugin objects
* @param bool $updated_attempted false for the first update, true subsequently
*/
do_action('jetpack_pre_plugin_upgrade_translations', $plugin, $this->plugins, $update_attempted);
$update_attempted = true;
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$upgrader->init();
$result = $upgrader->upgrade((object) $translation[0]);
$this->log[$plugin] = $upgrader->skin->get_upgrade_messages();
}
if (!$this->bulk && !$result) {
return new WP_Error('update_fail', __('There was an error updating your plugin', 'jetpack'), 400);
}
return true;
}