Jetpack_JSON_API_Themes_Active_Endpoint

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

Defined (1)

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

/json-endpoints/jetpack/class.jetpack-json-api-themes-active-endpoint.php  
  1. class Jetpack_JSON_API_Themes_Active_Endpoint extends Jetpack_JSON_API_Themes_Endpoint { 
  2. // GET /sites/%s/themes/mine => current theme 
  3. // POST /sites/%s/themes/mine => switch theme 
  4. public function callback( $path = '', $blog_id = 0 ) { 
  5.  
  6. if ( is_wp_error( $error = $this->validate_call( $blog_id, 'switch_themes', true ) ) ) { 
  7. return $error; 
  8.  
  9. if ( 'POST' === $this->api->method ) 
  10. return $this->switch_theme(); 
  11. else 
  12. return $this->get_current_theme(); 
  13.  
  14. protected function switch_theme() { 
  15. $args = $this->input(); 
  16.  
  17. if ( ! isset( $args['theme'] ) || empty( $args['theme'] ) ) { 
  18. return new WP_Error( 'missing_theme', __( 'You are required to specify a theme to switch to.', 'jetpack' ), 400 ); 
  19.  
  20. $theme_slug = $args['theme']; 
  21.  
  22. if ( ! $theme_slug ) { 
  23. return new WP_Error( 'theme_not_found', __( 'Theme is empty.', 'jetpack' ), 404 ); 
  24.  
  25. $theme = wp_get_theme( $theme_slug ); 
  26.  
  27. if ( ! $theme->exists() ) { 
  28. return new WP_Error( 'theme_not_found', __( 'The specified theme was not found.', 'jetpack' ), 404 ); 
  29.  
  30. if ( ! $theme->is_allowed() ) { 
  31. return new WP_Error( 'theme_not_found', __( 'You are not allowed to switch to this theme', 'jetpack' ), 403 ); 
  32.  
  33. switch_theme( $theme_slug ); 
  34.  
  35. return $this->get_current_theme(); 
  36.  
  37. protected function get_current_theme() { 
  38. return $this->format_theme( wp_get_theme() );