/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php

  1. <?php 
  2.  
  3. class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_Endpoint { 
  4. // POST /sites/%s/themes/%s 
  5. // POST /sites/%s/themes 
  6.  
  7. protected $needed_capabilities = 'update_themes'; 
  8. protected $action = 'default_action'; 
  9. protected $expected_actions = array( 'update' ); 
  10.  
  11. public function default_action() { 
  12. $args = $this->input(); 
  13. if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) { 
  14. if ( $args['autoupdate'] ) { 
  15. $this->autoupdate_on(); 
  16. } else { 
  17. $this->autoupdate_off(); 
  18.  
  19. return true; 
  20.  
  21. function autoupdate_on() { 
  22. $autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() ); 
  23. $autoupdate_themes = array_unique( array_merge( $autoupdate_themes, $this->themes ) ); 
  24. Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes ); 
  25.  
  26. function autoupdate_off() { 
  27. $autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() ); 
  28. $autoupdate_themes = array_diff( $autoupdate_themes, $this->themes ); 
  29. Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes ); 
  30.  
  31. function update() { 
  32. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
  33.  
  34. // Clear the cache. 
  35. wp_update_themes(); 
  36.  
  37. foreach ( $this->themes as $theme ) { 
  38. // Objects created inside the for loop to clean the messages for each theme 
  39. $skin = new Automatic_Upgrader_Skin(); 
  40. $upgrader = new Theme_Upgrader( $skin ); 
  41. $upgrader->init(); 
  42. $result = $upgrader->upgrade( $theme ); 
  43. $this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages(); 
  44.  
  45. if ( ! $this->bulk && ! $result ) { 
  46. return new WP_Error( 'update_fail', __( 'There was an error updating your theme', 'jetpack' ), 400 ); 
  47.  
  48. return true; 
  49.  
.