PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← 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 +}