|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Custom Css endpoint |
|
4
|
|
|
* |
|
5
|
|
|
* https://public-api.wordpress.com/rest/v1.1/sites/$site/customcss/ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
new WPCOM_JSON_API_Get_CustomCss_Endpoint( array ( |
|
9
|
|
|
'description' => 'Retrieve custom-css data for a site.', |
|
10
|
|
|
'group' => '__do_not_document', |
|
11
|
|
|
'stat' => 'customcss:1:get', |
|
12
|
|
|
'method' => 'GET', |
|
13
|
|
|
'min_version' => '1.1', |
|
14
|
|
|
'path' => '/sites/%s/customcss', |
|
15
|
|
|
'path_labels' => array( |
|
16
|
|
|
'$site' => '(string) Site ID or domain.', |
|
17
|
|
|
), |
|
18
|
|
|
'response_format' => array( |
|
19
|
|
|
'css' => '(string) The raw CSS.', |
|
20
|
|
|
'preprocessor' => '(string) The name of the preprocessor if any.', |
|
21
|
|
|
'add_to_existing' => '(bool) False to skip the existing styles.', |
|
22
|
|
|
), |
|
23
|
|
|
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/12345678/customcss', |
|
24
|
|
|
'example_response' => ' |
|
25
|
|
|
{ |
|
26
|
|
|
"css": ".site-title { color: #fff; }", |
|
27
|
|
|
"preprocessor": "sass", |
|
28
|
|
|
"add_to_existing": "true" |
|
29
|
|
|
}' |
|
30
|
|
|
) ); |
|
31
|
|
|
|
|
32
|
|
|
class WPCOM_JSON_API_Get_CustomCss_Endpoint extends WPCOM_JSON_API_Endpoint { |
|
33
|
|
|
/** |
|
34
|
|
|
* API callback. |
|
35
|
|
|
*/ |
|
36
|
|
|
function callback( $path = '', $blog_id = 0 ) { |
|
37
|
|
|
// Switch to the given blog. |
|
38
|
|
|
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
|
39
|
|
|
if ( is_wp_error( $blog_id ) ) { |
|
40
|
|
|
return $blog_id; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$args = array( |
|
44
|
|
|
'css' => Jetpack_Custom_CSS::get_css(), |
|
45
|
|
|
'preprocessor' => Jetpack_Custom_CSS::get_preprocessor_key(), |
|
46
|
|
|
'add_to_existing' => ! Jetpack_Custom_CSS::skip_stylesheet(), |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$defaults = array( |
|
50
|
|
|
'css' => '', |
|
51
|
|
|
'preprocessor' => '', |
|
52
|
|
|
'add_to_existing' => true, |
|
53
|
|
|
); |
|
54
|
|
|
return wp_parse_args( $args, $defaults ); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: