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

  1. <?php 
  2.  
  3. class Jetpack_JSON_API_Core_Modify_Endpoint extends Jetpack_JSON_API_Core_Endpoint { 
  4. // POST /sites/%s/core 
  5. // POST /sites/%s/core/update 
  6. protected $needed_capabilities = 'update_core'; 
  7. protected $action = 'default_action'; 
  8. protected $new_version; 
  9. protected $log; 
  10.  
  11. public function default_action() { 
  12. $args = $this->input(); 
  13.  
  14. if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) { 
  15. Jetpack_Options::update_option( 'autoupdate_core', $args['autoupdate'] ); 
  16.  
  17. return true; 
  18.  
  19. protected function update( $version, $locale ) { 
  20. $args = $this->input(); 
  21. $version = isset( $args['version'] ) ? $args['version'] : false; 
  22. $locale = isset( $args['locale'] ) ? $args['locale'] : get_locale(); 
  23.  
  24. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
  25.  
  26. delete_site_transient( 'update_core' ); 
  27. wp_version_check( array(), true ); 
  28.  
  29. if ( $version ) { 
  30. $update = find_core_update( $version, $locale ); 
  31. } else { 
  32. $update = $this->find_latest_update_offer(); 
  33.  
  34. $skin = new Automatic_Upgrader_Skin(); 
  35. $upgrader = new Core_Upgrader( $skin ); 
  36.  
  37. $this->new_version = $upgrader->upgrade( $update ); 
  38.  
  39. $this->log = $upgrader->skin->get_upgrade_messages(); 
  40.  
  41. if ( is_wp_error( $this->new_version ) ) { 
  42. return $this->new_version; 
  43.  
  44. return $this->new_version; 
  45.  
  46. protected function find_latest_update_offer() { 
  47. // Select the latest update. 
  48. // Remove filters to bypass automattic updates. 
  49. add_filter( 'request_filesystem_credentials', '__return_true' ); 
  50. add_filter( 'automatic_updates_is_vcs_checkout', '__return_false' ); 
  51. add_filter( 'allow_major_auto_core_updates', '__return_true' ); 
  52. add_filter( 'send_core_update_notification_email', '__return_false' ); 
  53. $update = find_core_auto_update(); 
  54. remove_filter( 'request_filesystem_credentials', '__return_true' ); 
  55. remove_filter( 'automatic_updates_is_vcs_checkout', '__return_false' ); 
  56. remove_filter( 'allow_major_auto_core_updates', '__return_true' ); 
  57. remove_filter( 'send_core_update_notification_email', '__return_false' ); 
  58. return $update; 
  59.  
.