WPCOM_JSON_API_Update_CustomCss_Endpoint

Custom Css update endpoint.

Defined (1)

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

/json-endpoints/class.wpcom-json-api-update-customcss.php  
  1. class WPCOM_JSON_API_Update_CustomCss_Endpoint extends WPCOM_JSON_API_Endpoint { 
  2. /** 
  3. * API callback. 
  4. */ 
  5. function callback( $path = '', $blog_id = 0 ) { 
  6. // Switch to the given blog. 
  7. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  8. if ( is_wp_error( $blog_id ) ) { 
  9. return $blog_id; 
  10.  
  11. if ( ! current_user_can( 'edit_theme_options' ) ) { 
  12. return new WP_Error( 'unauthorized', 'User is not authorized to access custom css', 403 ); 
  13.  
  14. $args = $this->input(); 
  15. if ( empty( $args ) || ! is_array( $args ) ) { 
  16. return new WP_Error( 'no_data', 'No data was provided.', 400 ); 
  17. $save_args = array( 
  18. 'css' => $args['css'],  
  19. 'preprocessor' => $args['preprocessor'],  
  20. 'add_to_existing' => $args['add_to_existing'],  
  21. ); 
  22. Jetpack_Custom_CSS::save( $save_args ); 
  23.  
  24. $current = array( 
  25. 'css' => Jetpack_Custom_CSS::get_css(),  
  26. 'preprocessor' => Jetpack_Custom_CSS::get_preprocessor_key(),  
  27. 'add_to_existing' => ! Jetpack_Custom_CSS::skip_stylesheet(),  
  28. ); 
  29.  
  30. $defaults = array( 
  31. 'css' => '',  
  32. 'preprocessor' => '',  
  33. 'add_to_existing' => true,  
  34. ); 
  35. return wp_parse_args( $current, $defaults );