← All changes
|
json-endpoints/class.wpcom-json-api-get-customcss.php
+70
-0
16.2-beta
→
16.3
View file →
| @@ -1,0 +1,70 @@ | ||
| 1 | +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | |
| 2 | +/** | |
| 3 | + * Custom Css endpoint | |
| 4 | + * | |
| 5 | + * Endpoint: https://public-api.wordpress.com/rest/v1.1/sites/$site/customcss/ | |
| 6 | + */ | |
| 7 | + | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + exit( 0 ); | |
| 10 | +} | |
| 11 | + | |
| 12 | +new WPCOM_JSON_API_Get_CustomCss_Endpoint( | |
| 13 | + array( | |
| 14 | + 'description' => 'Retrieve custom-css data for a site.', | |
| 15 | + 'group' => '__do_not_document', | |
| 16 | + 'stat' => 'customcss:1:get', | |
| 17 | + 'method' => 'GET', | |
| 18 | + 'min_version' => '1.1', | |
| 19 | + 'path' => '/sites/%s/customcss', | |
| 20 | + 'path_labels' => array( | |
| 21 | + '$site' => '(string) Site ID or domain.', | |
| 22 | + ), | |
| 23 | + 'response_format' => array( | |
| 24 | + 'css' => '(string) The raw CSS.', | |
| 25 | + 'preprocessor' => '(string) The name of the preprocessor if any.', | |
| 26 | + 'add_to_existing' => '(bool) False to skip the existing styles.', | |
| 27 | + ), | |
| 28 | + 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/12345678/customcss', | |
| 29 | + 'example_response' => ' | |
| 30 | + { | |
| 31 | + "css": ".site-title { color: #fff; }", | |
| 32 | + "preprocessor": "sass", | |
| 33 | + "add_to_existing": "true" | |
| 34 | + }', | |
| 35 | + ) | |
| 36 | +); | |
| 37 | +/** | |
| 38 | + * GET Custom CSS Endpoint | |
| 39 | + * | |
| 40 | + * @phan-constructor-used-for-side-effects | |
| 41 | + */ | |
| 42 | +class WPCOM_JSON_API_Get_CustomCss_Endpoint extends WPCOM_JSON_API_Endpoint { | |
| 43 | + /** | |
| 44 | + * | |
| 45 | + * API callback. | |
| 46 | + * | |
| 47 | + * @param string $path - the path. | |
| 48 | + * @param int $blog_id - the blog ID. | |
| 49 | + */ | |
| 50 | + public function callback( $path = '', $blog_id = 0 ) { | |
| 51 | + // Switch to the given blog. | |
| 52 | + $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); | |
| 53 | + if ( is_wp_error( $blog_id ) ) { | |
| 54 | + return $blog_id; | |
| 55 | + } | |
| 56 | + | |
| 57 | + $args = array( | |
| 58 | + 'css' => Jetpack_Custom_CSS::get_css(), | |
| 59 | + 'preprocessor' => Jetpack_Custom_CSS::get_preprocessor_key(), | |
| 60 | + 'add_to_existing' => ! Jetpack_Custom_CSS::skip_stylesheet(), | |
| 61 | + ); | |
| 62 | + | |
| 63 | + $defaults = array( | |
| 64 | + 'css' => '', | |
| 65 | + 'preprocessor' => '', | |
| 66 | + 'add_to_existing' => true, | |
| 67 | + ); | |
| 68 | + return wp_parse_args( $args, $defaults ); | |
| 69 | + } | |
| 70 | +} | |