-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Autoupdate Translations Add a new api endpoint that will allow us to enable translation autoupdates. As well as update all translations.
- Loading branch information
Showing
9 changed files
with
129 additions
and
2 deletions.
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
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