diff --git a/class.jetpack-autoupdate.php b/class.jetpack-autoupdate.php index c118dd5b94d2c..5b540d09cd23e 100644 --- a/class.jetpack-autoupdate.php +++ b/class.jetpack-autoupdate.php @@ -52,6 +52,11 @@ public function autoupdate_plugin( $update, $item ) { } public function autoupdate_translation( $update, $item ) { + // Autoupdate all translations + if ( Jetpack_Options::get_option( 'autoupdate_translations', false ) ) { + return true; + } + // Themes $autoupdate_themes_translations = Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ); $autoupdate_theme_list = Jetpack_Options::get_option( 'autoupdate_themes', array() ); diff --git a/class.jetpack-options.php b/class.jetpack-options.php index 8486b197a8722..7482dbaf3dc02 100644 --- a/class.jetpack-options.php +++ b/class.jetpack-options.php @@ -39,6 +39,7 @@ public static function get_option_names( $type = 'compact' ) { 'autoupdate_themes', // (array) An array of theme ids ( eg. twentyfourteen ) that should be autoupdated 'autoupdate_themes_translations', // (array) An array of theme ids ( eg. twentyfourteen ) that should autoupdated translation files. 'autoupdate_core', // (bool) Whether or not to autoupdate core + 'autoupdate_translations', // (bool) Whether or not to autoupdate all translations 'json_api_full_management', // (bool) Allow full management (eg. Activate, Upgrade plugins) of the site via the JSON API. 'sync_non_public_post_stati', // (bool) Allow synchronisation of posts and pages with non-public status. 'site_icon_url', // (string) url to the full site icon diff --git a/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php b/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php index c440a3fa853d2..30c083b4560cd 100644 --- a/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php +++ b/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php @@ -118,7 +118,7 @@ protected function format_plugin( $plugin_file, $plugin_data ) { $plugin['autoupdate'] = $autoupdate; $autoupdate_translation = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ) ); - $plugin['autoupdate_translation'] = $autoupdate || $autoupdate_translation; + $plugin['autoupdate_translation'] = $autoupdate || $autoupdate_translation || Jetpack_Options::get_option( 'autoupdate_translations', false ); $plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file ); diff --git a/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php b/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php index d77d3ca438d23..40edabdd60450 100644 --- a/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php +++ b/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php @@ -123,7 +123,7 @@ protected function format_theme( $theme ) { $formatted_theme['autoupdate'] = $autoupdate; $autoupdate_translation = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ) ); - $formatted_theme['autoupdate_translation'] = $autoupdate || $autoupdate_translation; + $formatted_theme['autoupdate_translation'] = $autoupdate || $autoupdate_translation || Jetpack_Options::get_option( 'autoupdate_translations', false ); if ( isset( $this->log[ $id ] ) ) { $formatted_theme['log'] = $this->log[ $id ]; diff --git a/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php b/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php new file mode 100644 index 0000000000000..65b6e725e2120 --- /dev/null +++ b/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php @@ -0,0 +1,20 @@ + wp_get_translation_updates(), + 'autoupdate' => Jetpack_Options::get_option( 'autoupdate_translations', false ), + 'log' => $this->log, + 'success' => $this->success, + ); + } +} diff --git a/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php b/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php new file mode 100644 index 0000000000000..fd5f6a565e34b --- /dev/null +++ b/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php @@ -0,0 +1,29 @@ +input(); + + if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) { + Jetpack_Options::update_option( 'autoupdate_translations', $args['autoupdate'] ); + } + + return true; + } + + protected function update() { + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + + $upgrader = new Language_Pack_Upgrader( new Automatic_Upgrader_Skin() ); + $result = $upgrader->bulk_upgrade(); + + $this->log = $upgrader->skin->get_upgrade_messages(); + $this->success = ( ! is_wp_error( $result ) ) ? (bool) $result : false; + } +} diff --git a/json-endpoints/jetpack/json-api-jetpack-endpoints.php b/json-endpoints/jetpack/json-api-jetpack-endpoints.php index b560874763e1e..7333e4c9402c3 100644 --- a/json-endpoints/jetpack/json-api-jetpack-endpoints.php +++ b/json-endpoints/jetpack/json-api-jetpack-endpoints.php @@ -896,6 +896,76 @@ ) ); +require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-translations-endpoint.php' ); +require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-translations-modify-endpoint.php' ); + +new Jetpack_JSON_API_Translations_Endpoint( array( + 'description' => 'Gets info about a Jetpack blog\'s core installation', + 'method' => 'GET', + 'path' => '/sites/%s/translations', + 'stat' => 'translations', + 'path_labels' => array( + '$site' => '(int|string) The site ID, The site domain' + ), + 'response_format' => array( + 'translations' => '(array) A list of translations that are available', + 'autoupdate' => '(bool) Whether or not we automatically update translations', + 'log' => '(array:safehtml) An array of log strings.', + ), + 'example_request_data' => array( + 'headers' => array( + 'authorization' => 'Bearer YOUR_API_TOKEN' + ), + ), + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations' +) ); + +new Jetpack_JSON_API_Translations_Modify_Endpoint( array( + 'description' => 'Toggle automatic core updates for a Jetpack blog', + 'method' => 'POST', + 'path' => '/sites/%s/translations', + 'stat' => 'translations', + 'path_labels' => array( + '$site' => '(int|string) The site ID, The site domain' + ), + 'request_format' => array( + 'autoupdate' => '(bool) Whether or not we automatically update translations', + ), + 'response_format' => array( + 'translations' => '(array) A list of translations that are available', + 'autoupdate' => '(bool) Whether or not we automatically update translations', + ), + 'example_request_data' => array( + 'headers' => array( + 'authorization' => 'Bearer YOUR_API_TOKEN' + ), + 'body' => array( + 'autoupdate' => true, + ), + ), + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations' +) ); + +new Jetpack_JSON_API_Translations_Modify_Endpoint( array( + 'description' => 'Update All Translations installation on a Jetpack blog', + 'method' => 'POST', + 'path' => '/sites/%s/translations/update', + 'stat' => 'translations:update', + 'path_labels' => array( + '$site' => '(int|string) The site ID, The site domain' + ), + 'response_format' => array( + 'log' => '(array:safehtml) An array of log strings.', + 'success' => '(bool) Was the operation successful' + ), + 'example_request_data' => array( + 'headers' => array( + 'authorization' => 'Bearer YOUR_API_TOKEN' + ), + ), + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations/update' +) ); + // Options require_once( $json_jetpack_endpoints_dir . 'class.wpcom-json-api-get-option-endpoint.php' ); diff --git a/sync/class.jetpack-sync-defaults.php b/sync/class.jetpack-sync-defaults.php index 5dd5896ad230a..13a691f3f27b1 100644 --- a/sync/class.jetpack-sync-defaults.php +++ b/sync/class.jetpack-sync-defaults.php @@ -82,6 +82,7 @@ class Jetpack_Sync_Defaults { 'jetpack_autoupdate_themes', 'jetpack_autoupdate_themes_translations', 'jetpack_autoupdate_core', + 'jetpack_autoupdate_translations', 'carousel_background_color', 'carousel_display_exif', 'jetpack_portfolio', diff --git a/tests/php/sync/test_class.jetpack-sync-options.php b/tests/php/sync/test_class.jetpack-sync-options.php index e3a5a71db492d..f3165fcc83b05 100644 --- a/tests/php/sync/test_class.jetpack-sync-options.php +++ b/tests/php/sync/test_class.jetpack-sync-options.php @@ -142,6 +142,7 @@ public function test_sync_default_options() { 'jetpack_autoupdate_themes' => 'pineapple', 'jetpack_autoupdate_themes_translations' => 'pineapple', 'jetpack_autoupdate_core' => 'pineapple', + 'jetpack_autoupdate_translations' => 'pineapple', 'carousel_background_color' => 'pineapple', 'carousel_display_exif' => 'pineapple', 'jetpack_portfolio' => 'pineapple',