/json-endpoints/class.wpcom-json-api-update-customcss.php

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