diff options
author | Yury German <blueknight@gentoo.org> | 2017-01-24 23:51:34 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2017-01-24 23:51:34 -0500 |
commit | 3c539a4713a80181af84c1fedc742436f75c92c4 (patch) | |
tree | e1896c286f3fb98337a6297465974c65f1fe8f26 /plugins/jetpack/json-endpoints/jetpack | |
parent | Update theme twentyfifteen to 1.7 (diff) | |
download | blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.tar.gz blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.tar.bz2 blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.zip |
updating jetpack plugin
Diffstat (limited to 'plugins/jetpack/json-endpoints/jetpack')
7 files changed, 253 insertions, 73 deletions
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php index 659ab23b..c440a3fa 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php @@ -25,6 +25,7 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi 'author_url' => '(url) The authors web site address', 'network' => '(boolean) Whether the plugin can only be activated network wide.', 'autoupdate' => '(boolean) Whether the plugin is automatically updated', + 'autoupdate_translation' => '(boolean) Whether the plugin is automatically updating translations', 'next_autoupdate' => '(string) Y-m-d H:i:s for next scheduled update event', 'log' => '(array:safehtml) An array of update log strings.', 'uninstallable' => '(boolean) Whether the plugin is unistallable.', @@ -68,7 +69,7 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi $this->bulk = false; $this->plugins[] = urldecode( $plugin ); } - + if ( is_wp_error( $error = $this->validate_plugins() ) ) { return $error; }; @@ -89,17 +90,19 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi $plugin = $plugin . '.php'; $this->plugins[ $index ] = $plugin; } - if ( is_wp_error( $error = $this->validate_plugin( $plugin ) ) ) { - return $error; + $valid = $this->validate_plugin( urldecode( $plugin ) ) ; + if ( is_wp_error( $valid ) ) { + return $valid; } } + return true; } protected function format_plugin( $plugin_file, $plugin_data ) { $plugin = array(); $plugin['id'] = preg_replace("/(.+)\.php$/", "$1", $plugin_file ); - $plugin['slug'] = $this->get_plugin_slug( $plugin_file ); + $plugin['slug'] = Jetpack_Autoupdate::get_plugin_slug( $plugin_file ); $plugin['active'] = Jetpack::is_plugin_active( $plugin_file ); $plugin['name'] = $plugin_data['Name']; $plugin['plugin_url'] = $plugin_data['PluginURI']; @@ -110,8 +113,15 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi $plugin['network'] = $plugin_data['Network']; $plugin['update'] = $this->get_plugin_updates( $plugin_file ); $plugin['next_autoupdate'] = date( 'Y-m-d H:i:s', wp_next_scheduled( 'wp_maybe_auto_update' ) ); - $plugin['autoupdate'] = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins', array() ) ); + + $autoupdate = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins', array() ) ); + $plugin['autoupdate'] = $autoupdate; + + $autoupdate_translation = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ) ); + $plugin['autoupdate_translation'] = $autoupdate || $autoupdate_translation; + $plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file ); + if ( ! empty ( $this->log[ $plugin_file ] ) ) { $plugin['log'] = $this->log[ $plugin_file ]; } @@ -159,7 +169,7 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi return new WP_Error( 'missing_plugin', __( 'You are required to specify a plugin to activate.', 'jetpack' ), 400 ); } - if ( is_wp_error( $error = validate_plugin( urldecode( $plugin ) ) ) ) { + if ( is_wp_error( $error = validate_plugin( $plugin ) ) ) { return new WP_Error( 'unknown_plugin', $error->get_error_messages() , 404 ); } @@ -173,28 +183,4 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi } return null; } - - protected function get_plugin_slug( $plugin_file ) { - $update_plugins = get_site_transient( 'update_plugins' ); - if ( isset( $update_plugins->no_update ) ) { - if ( isset( $update_plugins->no_update[ $plugin_file ] ) ) { - $slug = $update_plugins->no_update[ $plugin_file ]->slug; - } - } - - if ( empty( $slug ) && isset( $update_plugins->response ) ) { - if ( isset( $update_plugins->response[ $plugin_file ] ) ) { - $slug = $update_plugins->response[ $plugin_file ]->slug; - } - } - - // Try to infer from the plugin file if not cached - if ( empty( $slug) ) { - $slug = dirname( $plugin_file ); - if ( '.' === $slug ) { - $slug = preg_replace("/(.+)\.php$/", "$1", $plugin_file ); - } - } - return $slug; - } } diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php index fca8173e..2e675f7f 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php @@ -3,14 +3,17 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint { // POST /sites/%s/plugins/%s // POST /sites/%s/plugins - + protected $slug = null; protected $needed_capabilities = 'activate_plugins'; protected $action = 'default_action'; - protected $expected_actions = array( 'update', 'install', 'delete' ); + protected $expected_actions = array( 'update', 'install', 'delete', 'update_translations' ); public function callback( $path = '', $blog_id = 0, $object = null ) { Jetpack_JSON_API_Endpoint::validate_input( $object ); switch ( $this->action ) { + case 'delete': + $this->needed_capabilities = 'delete_plugins'; + case 'update_translations': case 'update' : $this->needed_capabilities = 'update_plugins'; break; @@ -18,7 +21,8 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ $this->needed_capabilities = 'install_plugins'; break; } - if ( isset( $args['autoupdate'] ) ) { + + if ( isset( $args['autoupdate'] ) || isset( $args['autoupdate_translations'] ) ) { $this->needed_capabilities = 'update_plugins'; } @@ -44,6 +48,14 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ } } + if ( isset( $args['autoupdate_translations'] ) && is_bool( $args['autoupdate_translations'] ) ) { + if ( $args['autoupdate_translations'] ) { + $this->autoupdate_translations_on(); + } else { + $this->autoupdate_translations_off(); + } + } + return true; } @@ -59,6 +71,18 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ Jetpack_Options::update_option( 'autoupdate_plugins', $autoupdate_plugins ); } + protected function autoupdate_translations_on() { + $autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ); + $autoupdate_plugins = array_unique( array_merge( $autoupdate_plugins, $this->plugins ) ); + Jetpack_Options::update_option( 'autoupdate_plugins_translations', $autoupdate_plugins ); + } + + protected function autoupdate_translations_off() { + $autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ); + $autoupdate_plugins = array_diff( $autoupdate_plugins, $this->plugins ); + Jetpack_Options::update_option( 'autoupdate_plugins_translations', $autoupdate_plugins ); + } + protected function activate() { foreach ( $this->plugins as $plugin ) { if ( ( ! $this->network_wide && Jetpack::is_plugin_active( $plugin ) ) || is_plugin_active_for_network( $plugin ) ) { @@ -151,7 +175,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ $result = false; foreach ( $this->plugins as $plugin ) { - + if ( ! in_array( $plugin, $plugin_updates_needed ) ) { $this->log[ $plugin ][] = __( 'No update needed', 'jetpack' ); continue; @@ -166,7 +190,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ * @param array $plugin Array of plugin objects * @param bool $updated_attempted false for the first update, true subsequently */ - do_action('jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted); + do_action( 'jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted ); $update_attempted = true; @@ -179,7 +203,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ defined( 'DOING_CRON' ) or define( 'DOING_CRON', true ); $result = $upgrader->upgrade( $plugin ); - $this->log[ $plugin ][] = $upgrader->skin->get_upgrade_messages(); + $this->log[ $plugin ] = $upgrader->skin->get_upgrade_messages(); } if ( ! $this->bulk && ! $result && $update_attempted ) { @@ -188,4 +212,62 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ return $this->default_action(); } + + 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; + } + + protected function get_translation( $translation ) { + return ( $translation['slug'] === $this->slug ); + } } diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php index b562d949..2c694896 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php @@ -52,29 +52,7 @@ class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint { // GET /sites/%s/sync/status class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { protected function result() { - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; - require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; - - $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' ); - $sender = Jetpack_Sync_Sender::get_instance(); - $queue = $sender->get_sync_queue(); - $full_queue = $sender->get_full_sync_queue(); - $cron_timestamps = array_keys( _get_cron_array() ); - $next_cron = $cron_timestamps[0] - time(); - - return array_merge( - $sync_module->get_status(), - array( - 'cron_size' => count( $cron_timestamps ), - 'next_cron' => $next_cron, - 'queue_size' => $queue->size(), - 'queue_lag' => $queue->lag(), - 'queue_next_sync' => ( $sender->get_next_sync_time( 'sync' ) - microtime( true ) ), - 'full_queue_size' => $full_queue->size(), - 'full_queue_lag' => $full_queue->lag(), - 'full_queue_next_sync' => ( $sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ), - ) - ); + return Jetpack_Sync_Actions::get_sync_status(); } } diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php index ff567113..97bcc58d 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php @@ -21,14 +21,33 @@ class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_En continue; } - $result = delete_theme( $theme ); + /** + * Filters whether to use an alternative process for deleting 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_delete_method Whether to use the alternative method of deleting + * 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_delete', false, $theme ); + + if ( ! $result ) { + $result = delete_theme( $theme ); + } if ( is_wp_error( $result ) ) { - $error = $this->log[ $theme ]['error'] = $result->get_error_messages; + $error = $this->log[ $theme ]['error'] = $result->get_error_messages(); } else { $this->log[ $theme ][] = 'Theme deleted'; } - } if( ! $this->bulk && isset( $error ) ) { diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php index 37a20800..d77d3ca4 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php @@ -25,6 +25,7 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin 'tags' => '(array) Tags indicating styles and features of the theme.', 'log' => '(array) An array of log strings', 'autoupdate' => '(bool) Whether the theme is automatically updated', + 'autoupdate_translation' => '(bool) Whether the theme is automatically updating translations', ); protected function result() { @@ -118,13 +119,13 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin $update_themes = get_site_transient( 'update_themes' ); $formatted_theme['update'] = ( isset( $update_themes->response[ $id ] ) ) ? $update_themes->response[ $id ] : null; - $autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() ); + $autoupdate = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes', array() ) ); + $formatted_theme['autoupdate'] = $autoupdate; - $autoupdate = in_array( $id, $autoupdate_themes ); + $autoupdate_translation = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ) ); + $formatted_theme['autoupdate_translation'] = $autoupdate || $autoupdate_translation; - $formatted_theme['autoupdate'] = $autoupdate; - - if( isset( $this->log[ $id ] ) ) { + if ( isset( $this->log[ $id ] ) ) { $formatted_theme['log'] = $this->log[ $id ]; } diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php index 1ac99e6f..3061a6f5 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php @@ -14,11 +14,36 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E foreach ( $this->themes as $theme ) { - $skin = new Jetpack_Automatic_Install_Skin(); - $upgrader = new Theme_Upgrader( $skin ); + /** + * 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 ); + $link = $this->download_links[ $theme ]; + $result = $upgrader->install( $link ); + } if ( file_exists( $link ) ) { // Delete if link was tmp local file @@ -37,7 +62,7 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E $error = $this->log[ $theme ]['error'] = __( 'There was an error installing your theme', 'jetpack' ); } - else { + elseif ( $upgrader ) { $this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages(); } } @@ -59,8 +84,34 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E return new WP_Error( 'theme_already_installed', __( 'The theme is already installed', 'jetpack' ) ); } + /** + * Filters whether to skip the standard method of downloading and validating a WordPress.com + * theme. An alternative method of WPCom theme download and validation 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 $skip_download_filter_result Whether to skip the standard method of downloading + * and validating a WPCom theme. + * @param string $theme_slug Theme name (slug). If it is a WPCom theme, + * it should be suffixed with `-wpcom`. + */ + $skip_download_filter_result = apply_filters( 'jetpack_wpcom_theme_skip_download', false, $theme ); + + if ( is_wp_error( $skip_download_filter_result ) ) { + return $skip_download_filter_result; + } elseif ( $skip_download_filter_result ) { + continue; + } + if ( wp_endswith( $theme, '-wpcom' ) ) { $file = self::download_wpcom_theme_to_file( $theme ); + if ( is_wp_error( $file ) ) { return $file; } diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php index cbf361ba..c041158b 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php @@ -6,7 +6,7 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En protected $needed_capabilities = 'update_themes'; protected $action = 'default_action'; - protected $expected_actions = array( 'update' ); + protected $expected_actions = array( 'update', 'update_translations' ); public function default_action() { $args = $this->input(); @@ -17,6 +17,13 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En $this->autoupdate_off(); } } + if ( isset( $args['autoupdate_translations'] ) && is_bool( $args['autoupdate_translations'] ) ) { + if ( $args['autoupdate_translations'] ) { + $this->autoupdate_translations_on(); + } else { + $this->autoupdate_translations_off(); + } + } return true; } @@ -33,6 +40,18 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes ); } + function autoupdate_translations_on() { + $autoupdate_themes_translations = Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ); + $autoupdate_themes_translations = array_unique( array_merge( $autoupdate_themes_translations, $this->themes ) ); + Jetpack_Options::update_option( 'autoupdate_themes_translations', $autoupdate_themes_translations ); + } + + function autoupdate_translations_off() { + $autoupdate_themes_translations = Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ); + $autoupdate_themes_translations = array_diff( $autoupdate_themes_translations, $this->themes ); + Jetpack_Options::update_option( 'autoupdate_themes_translations', $autoupdate_themes_translations ); + } + function update() { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; @@ -64,4 +83,48 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En 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; + } + } |