Jetpack_JSON_API_Themes_Modify_Endpoint

The Jetpack by WordPress.com Jetpack JSON API Themes Modify Endpoint class.

Defined (1)

The class is defined in the following location(s).

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