/**
  * Automatically download translations for WC ( when user install WCML ( from 3.3.3) / add new language in WPML )
  *
  * @param  string $lang_code Language code
  *
  */
 function download_woocommerce_translations($lang_code, $wc_version)
 {
     global $sitepress;
     $locale = $sitepress->get_locale($lang_code);
     if ($locale != 'en_US' && $this->has_available_update($locale)) {
         $wc_version = $wc_version ? $wc_version : WC_VERSION;
         include_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/template.php';
         $url = 'update-core.php?action=do-translation-upgrade';
         $nonce = 'upgrade-translations';
         $title = '';
         $context = WP_LANG_DIR;
         $upgrader = new Language_Pack_Upgrader(new Automatic_Upgrader_Skin(compact('url', 'nonce', 'title', 'context')));
         // use Language_Pack_Upgrader_Skin instead of Automatic_Upgrader_Skin to display upgrade process
         $upgr_object = array();
         $upgr_object[0] = new stdClass();
         $upgr_object[0]->type = 'plugin';
         $upgr_object[0]->slug = 'woocommerce';
         $upgr_object[0]->language = $locale;
         $upgr_object[0]->version = $wc_version;
         $upgr_object[0]->updated = date('Y-m-d H:i:s');
         $upgr_object[0]->package = $this->get_language_pack_uri($locale, $wc_version);
         $upgr_object[0]->autoupdate = 1;
         $upgrader->bulk_upgrade($upgr_object);
         $this->save_translation_version($locale, false, $wc_version);
     }
 }
/**
 * 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;
}
Пример #3
0
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;
    }
}
/**
 * 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;
}
Пример #5
0
 /**
  * Update language packs for plugins & themes
  *
  * @return array|bool
  */
 private function update_language_packs()
 {
     if ('en_US' === get_locale()) {
         return false;
     }
     if (!function_exists('wp_clean_update_cache')) {
         require_once ABSPATH . 'wp-includes/update.php';
     }
     if (!class_exists('\\Language_Pack_Upgrader')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     if (!class_exists('\\Automatic_Upgrader_Skin')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skins.php';
     }
     wp_clean_update_cache();
     wp_update_themes();
     wp_update_plugins();
     $upgrader = new \Language_Pack_Upgrader(new \Automatic_Upgrader_Skin());
     return $upgrader->bulk_upgrade();
 }
 public function wp_oracle_get_translation_upgrade()
 {
     include_once ABSPATH . 'wp-admin/includes/admin.php';
     require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordpress-oracle-language-upgrader-skin.php';
     $skin = new Wordpress_Oracle_Language_Pack_Upgrader_Skin();
     $upgrader = new Language_Pack_Upgrader($skin);
     // Do the upgrade
     ob_start();
     $result = $upgrader->bulk_upgrade();
     $data = ob_get_contents();
     ob_clean();
     if (is_wp_error($result)) {
         return $result;
     }
     return array('status' => 'success');
 }
Пример #7
0
/**
 * Check if WordPress has access to the filesystem without asking for
 * credentials.
 *
 * @since 4.0.0
 *
 * @return bool Returns true on success, false on failure.
 */
function wp_can_install_language_pack()
{
    if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
        return false;
    }
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $skin = new Automatic_Upgrader_Skin();
    $upgrader = new Language_Pack_Upgrader($skin);
    $upgrader->init();
    $check = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_LANG_DIR));
    if (!$check || is_wp_error($check)) {
        return false;
    }
    return true;
}
Пример #8
0
    ?>
" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0"></iframe>
	</div>
	<?php 
    include ABSPATH . 'wp-admin/admin-footer.php';
} elseif ('do-translation-upgrade' == $action) {
    if (!current_user_can('update_core') && !current_user_can('update_plugins') && !current_user_can('update_themes')) {
        wp_die(__('You do not have sufficient permissions to update this site.'));
    }
    check_admin_referer('upgrade-translations');
    require_once ABSPATH . 'wp-admin/admin-header.php';
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $url = 'update-core.php?action=do-translation-upgrade';
    $nonce = 'upgrade-translations';
    $title = __('Update Translations');
    $context = WP_LANG_DIR;
    $upgrader = new Language_Pack_Upgrader(new Language_Pack_Upgrader_Skin(compact('url', 'nonce', 'title', 'context')));
    $result = $upgrader->bulk_upgrade();
    require_once ABSPATH . 'wp-admin/admin-footer.php';
} else {
    /**
     * Fires for each custom update action on the WordPress Updates screen.
     *
     * The dynamic portion of the hook name, `$action`, refers to the
     * passed update action. The hook fires in lieu of all available
     * default update actions.
     *
     * @since 3.2.0
     */
    do_action("update-core-custom_{$action}");
}
 /**
  * Asynchronously upgrades language packs after other upgrades have been made.
  *
  * Hooked to the {@see 'upgrader_process_complete'} action by default.
  *
  * @since 3.7.0
  * @access public
  * @static
  *
  * @param false|WP_Upgrader $upgrader Optional. WP_Upgrader instance or false. If `$upgrader` is
  *                                    a Language_Pack_Upgrader instance, the method will bail to
  *                                    avoid recursion. Otherwise unused. Default false.
  */
 public static function async_upgrade($upgrader = false)
 {
     // Avoid recursion.
     if ($upgrader && $upgrader instanceof Language_Pack_Upgrader) {
         return;
     }
     // Nothing to do?
     $language_updates = wp_get_translation_updates();
     if (!$language_updates) {
         return;
     }
     /*
      * Avoid messing with VCS installs, at least for now.
      * Noted: this is not the ideal way to accomplish this.
      */
     $check_vcs = new WP_Automatic_Updater();
     if ($check_vcs->is_vcs_checkout(WP_CONTENT_DIR)) {
         return;
     }
     foreach ($language_updates as $key => $language_update) {
         $update = !empty($language_update->autoupdate);
         /**
          * Filters whether to asynchronously update translation for core, a plugin, or a theme.
          *
          * @since 4.0.0
          *
          * @param bool   $update          Whether to update.
          * @param object $language_update The update offer.
          */
         $update = apply_filters('async_update_translation', $update, $language_update);
         if (!$update) {
             unset($language_updates[$key]);
         }
     }
     if (empty($language_updates)) {
         return;
     }
     // Re-use the automatic upgrader skin if the parent upgrader is using it.
     if ($upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin) {
         $skin = $upgrader->skin;
     } else {
         $skin = new Language_Pack_Upgrader_Skin(array('skip_header_footer' => true));
     }
     $lp_upgrader = new Language_Pack_Upgrader($skin);
     $lp_upgrader->bulk_upgrade($language_updates);
 }
Пример #10
0
/**
 * Check if WordPress has access to the filesystem without asking for
 * credentials.
 *
 * @since 4.0.0
 *
 * @return bool Returns true on success, false on failure.
 */
function wp_can_install_language_pack()
{
    if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
        return false;
    }
    $skin = new Automatic_Upgrader_Skin();
    $upgrader = new Language_Pack_Upgrader($skin);
    $upgrader->init();
    $check = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_LANG_DIR));
    if (!$check || is_wp_error($check)) {
        return false;
    }
    return true;
}
Пример #11
0
/**
 * Install all available updates.
 *
 * Updates themes, plugins, core and translations.
 */
function su_update_all()
{
    if (!current_user_can('update_core') && !current_user_can('update_plugins') && !current_user_can('update_themes')) {
        wp_die(__('You do not have sufficient permissions to update this site.'));
    }
    check_admin_referer('upgrade-core');
    require_once ABSPATH . 'wp-admin/admin-header.php';
    // Update themes.
    $themes = array_keys(get_theme_updates());
    if (!empty($themes)) {
        $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
        $url = wp_nonce_url($url, 'bulk-update-themes');
        ?>
		<div class="wrap">
			<h1><?php 
        _e('Update Themes');
        ?>
</h1>
			<iframe src="<?php 
        echo $url;
        ?>
" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php 
        esc_attr_e('Update progress');
        ?>
"></iframe>
		</div>
		<?php 
    }
    // Update plugins.
    $plugins = array_keys(get_plugin_updates());
    if (!empty($plugins)) {
        $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
        $url = wp_nonce_url($url, 'bulk-update-plugins');
        ?>
		<div class="wrap">
			<h1><?php 
        _e('Update Plugins');
        ?>
</h1>
			<iframe src="<?php 
        echo $url;
        ?>
" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php 
        esc_attr_e('Update progress');
        ?>
"></iframe>
		</div>
		<?php 
    }
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    // Update translations.
    $url = 'update-core.php?action=do-translation-upgrade';
    $nonce = 'upgrade-translations';
    $title = __('Update Translations');
    $context = WP_LANG_DIR;
    $upgrader = new Language_Pack_Upgrader(new Language_Pack_Upgrader_Skin(compact('url', 'nonce', 'title', 'context')));
    $upgrader->bulk_upgrade();
    // Update core.
    do_core_upgrade();
    include ABSPATH . 'wp-admin/admin-footer.php';
}
 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;
 }
Пример #13
0
/**
 * AJAX handler for updating translations.
 *
 * @since 4.6.0
 *
 * @see Language_Pack_Upgrader
 */
function wp_ajax_update_translations()
{
    check_ajax_referer('updates');
    if (!current_user_can('update_core') && !current_user_can('update_plugins') && !current_user_can('update_themes')) {
        $status['error'] = __('You do not have sufficient permissions to update this site.');
        wp_send_json_error($status);
    }
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $url = 'update-core.php?action=do-translation-upgrade';
    $nonce = 'upgrade-translations';
    $title = __('Update Translations');
    $context = WP_CONTENT_DIR;
    $skin = new Automatic_Upgrader_Skin(compact('url', 'nonce', 'title', 'context'));
    $upgrader = new Language_Pack_Upgrader($skin);
    $result = $upgrader->bulk_upgrade();
    $status = array('update' => 'translation');
    if (is_array($result) && is_wp_error($skin->result)) {
        $result = $skin->result;
    }
    if (is_array($result) && !empty($result[0])) {
        wp_send_json_success($status);
    } else {
        if (is_wp_error($result)) {
            $status['error'] = $result->get_error_message();
            wp_send_json_error($status);
        } else {
            if (false === $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 (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'] = __('Translations update failed.');
    wp_send_json_error($status);
}
Пример #14
0
 /**
  * Upgrades WordPress locally
  *
  */
 function upgrade_translations($current)
 {
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     $upgrader = new Language_Pack_Upgrader(new Language_Pack_Upgrader_Skin(compact('url', 'nonce', 'title', 'context')));
     $result = $upgrader->bulk_upgrade();
     $upgradeFailed = false;
     if (!empty($result)) {
         foreach ($result as $translate_tmp => $translate_info) {
             if (is_wp_error($translate_info) || empty($translate_info)) {
                 $upgradeFailed = true;
                 $return = array('error' => $this->iwp_mmb_get_error($translate_info), 'error_code' => 'upgrade_translations_wp_error');
                 break;
             }
         }
         if (!$upgradeFailed) {
             $return = 'updated';
         }
         return array('upgraded' => $return);
     } else {
         return array('error' => 'Upgrade failed.', 'error_code' => 'unable_to_update_translations_files');
     }
 }
Пример #15
0
 /**
  * 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;
 }
 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;
 }
Пример #17
0
 /**
  * Upgrades WordPress locally
  *
  */
 function upgrade_translations($current, $userid)
 {
     global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
     $GLOBALS['iwp_client_plugin_translations'] = 1;
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     $upgrader = new Language_Pack_Upgrader(new Language_Pack_Upgrader_Skin(compact('url', 'nonce', 'title', 'context')));
     $result = $upgrader->bulk_upgrade();
     $upgradeFailed = false;
     if (!empty($result)) {
         foreach ($result as $translate_tmp => $translate_info) {
             if (is_wp_error($translate_info) || empty($translate_info)) {
                 $upgradeFailed = true;
                 $return = array('error' => $this->iwp_mmb_get_error($translate_info), 'error_code' => 'upgrade_translations_wp_error');
                 break;
             }
         }
         if (!$upgradeFailed) {
             $details = array();
             $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('translations', 'update', $iwp_activities_log_post_type, (object) $details, $userid);
             $return = 'updated';
         }
         return array('upgraded' => $return);
     } else {
         return array('error' => 'Upgrade failed.', 'error_code' => 'unable_to_update_translations_files');
     }
 }
 static function download_language_packs()
 {
     $languages = pll_languages_list(array('fields' => 'locale'));
     // prevents upgrade if the .po file is already here. Let WP manage the upgrades :)
     foreach ($languages as $key => $locale) {
         if (file_exists(WP_LANG_DIR . "/{$locale}.po")) {
             unset($languages[$key]);
         }
     }
     if (empty($languages)) {
         return;
     }
     require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     $translations = wp_get_available_translations();
     if (!$translations) {
         return;
     }
     foreach ($translations as $translation) {
         if (in_array($translation['language'], $languages)) {
             $translation['type'] = 'core';
             $translations_to_load[] = (object) $translation;
         }
     }
     if (!empty($translations_to_load)) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         $upgrader = new Language_Pack_Upgrader(new Automatic_Upgrader_Skin());
         $upgrader->bulk_upgrade($translations_to_load, array('clear_update_cache' => false));
     }
 }
Пример #19
0
 /**
  * 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);
         }
     }
 }
Пример #20
0
 /**
  * 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)&#8230;'), $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;
 }
 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;
 }