-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Autoupdate Translations #5953
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
// Translations | ||
class Jetpack_JSON_API_Translations_Endpoint extends Jetpack_JSON_API_Endpoint { | ||
// GET /sites/%s/translations | ||
// POST /sites/%s/translations | ||
// POST /sites/%s/translations/update | ||
protected $needed_capabilities = array( 'update_core', 'update_plugins', 'update_themes' ); | ||
protected $log; | ||
protected $success; | ||
|
||
public function result() { | ||
return array( | ||
'translations' => wp_get_translation_updates(), | ||
'autoupdate' => Jetpack_Options::get_option( 'autoupdate_translations', false ), | ||
'log' => $this->log, | ||
'success' => $this->success, | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
class Jetpack_JSON_API_Translations_Modify_Endpoint extends Jetpack_JSON_API_Translations_Endpoint { | ||
// POST /sites/%s/translations | ||
// POST /sites/%s/translations/update | ||
protected $action = 'default_action'; | ||
protected $new_version; | ||
protected $log; | ||
|
||
public function default_action() { | ||
$args = $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we also return |
||
'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' ); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be
result
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No result is defined in
Jetpack_JSON_API_Translations_Endpoint
class.