/**
 * 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;
}
 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;
 }
/**
 * 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;
}
 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;
 }