Jetpack_JSON_API_Themes_Install_Endpoint

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

Defined (1)

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

/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php  
  1. class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_Endpoint { 
  2.  
  3. // POST /sites/%s/themes/%s/install 
  4. protected $needed_capabilities = 'install_themes'; 
  5. protected $action = 'install'; 
  6. protected $download_links = array(); 
  7.  
  8. protected function install() { 
  9.  
  10. foreach ( $this->themes as $theme ) { 
  11.  
  12. $skin = new Automatic_Upgrader_Skin(); 
  13. $upgrader = new Theme_Upgrader( $skin ); 
  14.  
  15. $result = $upgrader->install( $this->download_links[ $theme ] ); 
  16.  
  17. if ( ! $this->bulk && is_wp_error( $result ) ) { 
  18. return $result; 
  19.  
  20. if ( ! $result ) { 
  21. $error = $this->log[ $theme ]['error'] = __( 'An unknown error occurred during installation', 'jetpack' ); 
  22.  
  23. elseif ( ! self::is_installed_theme( $theme ) ) { 
  24. $error = $this->log[ $theme ]['error'] = __( 'There was an error installing your theme', 'jetpack' ); 
  25.  
  26. else { 
  27. $this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages(); 
  28.  
  29. if ( ! $this->bulk && isset( $error ) ) { 
  30. return new WP_Error( 'install_error', $error, 400 ); 
  31.  
  32. return true; 
  33.  
  34. protected function validate_themes() { 
  35. if ( empty( $this->themes ) || ! is_array( $this->themes ) ) { 
  36. return new WP_Error( 'missing_themes', __( 'No themes found.', 'jetpack' ) ); 
  37. foreach( $this->themes as $index => $theme ) { 
  38.  
  39. if ( self::is_installed_theme( $theme ) ) { 
  40. return new WP_Error( 'theme_already_installed', __( 'The theme is already installed', 'jetpack' ) ); 
  41.  
  42. $params = (object) array( 'slug' => $theme ); 
  43. $url = 'https://api.wordpress.org/themes/info/1.0/'; 
  44. $args = array( 
  45. 'body' => array( 
  46. 'action' => 'theme_information',  
  47. 'request' => serialize( $params ),  
  48. ); 
  49. $response = wp_remote_post( $url, $args ); 
  50. $theme_data = unserialize( $response['body'] ); 
  51. if ( is_wp_error( $theme_data ) ) { 
  52. return $theme_data; 
  53. $this->download_links[ $theme ] = $theme_data->download_link; 
  54.  
  55. return true; 
  56.  
  57. protected static function is_installed_theme( $theme ) { 
  58. $wp_theme = wp_get_theme( $theme ); 
  59. return $wp_theme->exists(); 
  60.  
  61.