class.wpcom-json-api-get-customcss.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Custom Css endpoint
  4. *
  5. * https://public-api.wordpress.com/rest/v1.1/sites/$site/customcss/
  6. */
  7. new WPCOM_JSON_API_Get_CustomCss_Endpoint( array (
  8. 'description' => 'Retrieve custom-css data for a site.',
  9. 'group' => '__do_not_document',
  10. 'stat' => 'customcss:1:get',
  11. 'method' => 'GET',
  12. 'min_version' => '1.1',
  13. 'path' => '/sites/%s/customcss',
  14. 'path_labels' => array(
  15. '$site' => '(string) Site ID or domain.',
  16. ),
  17. 'response_format' => array(
  18. 'css' => '(string) The raw CSS.',
  19. 'preprocessor' => '(string) The name of the preprocessor if any.',
  20. 'add_to_existing' => '(bool) False to skip the existing styles.',
  21. ),
  22. 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/12345678/customcss',
  23. 'example_response' => '
  24. {
  25. "css": ".site-title { color: #fff; }",
  26. "preprocessor": "sass",
  27. "add_to_existing": "true"
  28. }'
  29. ) );
  30. class WPCOM_JSON_API_Get_CustomCss_Endpoint extends WPCOM_JSON_API_Endpoint {
  31. /**
  32. * API callback.
  33. */
  34. function callback( $path = '', $blog_id = 0 ) {
  35. // Switch to the given blog.
  36. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
  37. if ( is_wp_error( $blog_id ) ) {
  38. return $blog_id;
  39. }
  40. $args = array(
  41. 'css' => Jetpack_Custom_CSS::get_css(),
  42. 'preprocessor' => Jetpack_Custom_CSS::get_preprocessor_key(),
  43. 'add_to_existing' => ! Jetpack_Custom_CSS::skip_stylesheet(),
  44. );
  45. $defaults = array(
  46. 'css' => '',
  47. 'preprocessor' => '',
  48. 'add_to_existing' => true,
  49. );
  50. return wp_parse_args( $args, $defaults );
  51. }
  52. }