Completed
Push — renovate/history-4.x ( 8706da...6c1ea7 )
by
unknown
17:57 queued 11:18
created

....wpcom-json-api-site-settings-v1-3-endpoint.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
new WPCOM_JSON_API_Site_Settings_V1_3_Endpoint( array(
4
	'description' => 'Get detailed settings information about a site.',
5
	'group'       => '__do_not_document',
6
	'stat'        => 'sites:X',
7
	'min_version' => '1.3',
8
	'method'      => 'GET',
9
	'path'        => '/sites/%s/settings',
10
	'path_labels' => array(
11
		'$site' => '(int|string) Site ID or domain',
12
	),
13
14
	'query_parameters' => array(
15
		'context' => false,
16
	),
17
18
	'response_format' => WPCOM_JSON_API_Site_Settings_Endpoint::$site_format,
19
20
	'example_request' => 'https://public-api.wordpress.com/rest/v1.3/sites/en.blog.wordpress.com/settings?pretty=1',
21
) );
22
23
new WPCOM_JSON_API_Site_Settings_V1_3_Endpoint( array(
24
	'description' => 'Update settings for a site.',
25
	'group'       => '__do_not_document',
26
	'stat'        => 'sites:X',
27
	'min_version' => '1.3',
28
	'method'      => 'POST',
29
	'path'        => '/sites/%s/settings',
30
	'path_labels' => array(
31
		'$site' => '(int|string) Site ID or domain',
32
	),
33
34
	'request_format'  => array(
35
		'blogname'                             => '(string) Blog name',
36
		'blogdescription'                      => '(string) Blog description',
37
		'default_pingback_flag'                => '(bool) Notify blogs linked from article?',
38
		'default_ping_status'                  => '(bool) Allow link notifications from other blogs?',
39
		'default_comment_status'               => '(bool) Allow comments on new articles?',
40
		'blog_public'                          => '(string) Site visibility; -1: private, 0: discourage search engines, 1: allow search engines',
41
		'jetpack_sync_non_public_post_stati'   => '(bool) allow sync of post and pages with non-public posts stati',
42
		'jetpack_relatedposts_enabled'         => '(bool) Enable related posts?',
43
		'jetpack_relatedposts_show_headline'   => '(bool) Show headline in related posts?',
44
		'jetpack_relatedposts_show_thumbnails' => '(bool) Show thumbnails in related posts?',
45
		'jetpack_search_enabled'               => '(bool) Enable Jetpack Search',
46
		'jetpack_search_supported'             => '(bool) Jetpack Search supported',
47
		'jetpack_protect_whitelist'            => '(array) List of IP addresses to whitelist',
48
		'infinite_scroll'                      => '(bool) Support infinite scroll of posts?',
49
		'default_category'                     => '(int) Default post category',
50
		'default_post_format'                  => '(string) Default post format',
51
		'require_name_email'                   => '(bool) Require comment authors to fill out name and email?',
52
		'comment_registration'                 => '(bool) Require users to be registered and logged in to comment?',
53
		'close_comments_for_old_posts'         => '(bool) Automatically close comments on old posts?',
54
		'close_comments_days_old'              => '(int) Age at which to close comments',
55
		'thread_comments'                      => '(bool) Enable threaded comments?',
56
		'thread_comments_depth'                => '(int) Depth to thread comments',
57
		'page_comments'                        => '(bool) Break comments into pages?',
58
		'comments_per_page'                    => '(int) Number of comments to display per page',
59
		'default_comments_page'                => '(string) newest|oldest Which page of comments to display first',
60
		'comment_order'                        => '(string) asc|desc Order to display comments within page',
61
		'comments_notify'                      => '(bool) Email me when someone comments?',
62
		'moderation_notify'                    => '(bool) Email me when a comment is helf for moderation?',
63
		'social_notifications_like'            => '(bool) Email me when someone likes my post?',
64
		'social_notifications_reblog'          => '(bool) Email me when someone reblogs my post?',
65
		'social_notifications_subscribe'       => '(bool) Email me when someone follows my blog?',
66
		'comment_moderation'                   => '(bool) Moderate comments for manual approval?',
67
		'comment_whitelist'                    => '(bool) Moderate comments unless author has a previously-approved comment?',
68
		'comment_max_links'                    => '(int) Moderate comments that contain X or more links',
69
		'moderation_keys'                      => '(string) Words or phrases that trigger comment moderation, one per line',
70
		'blacklist_keys'                       => '(string) Words or phrases that mark comment spam, one per line',
71
		'lang_id'                              => '(int) ID for language blog is written in',
72
		'locale'                               => '(string) locale code for language blog is written in',
73
		'wga'                                  => '(array) Google Analytics Settings',
74
		'disabled_likes'                       => '(bool) Are likes globally disabled (they can still be turned on per post)?',
75
		'disabled_reblogs'                     => '(bool) Are reblogs disabled on posts?',
76
		'jetpack_comment_likes_enabled'        => '(bool) Are comment likes enabled for all comments?',
77
		'sharing_button_style'                 => '(string) Style to use for sharing buttons (icon-text, icon, text, or official)',
78
		'sharing_label'                        => '(string) Label to use for sharing buttons, e.g. "Share this:"',
79
		'sharing_show'                         => '(string|array:string) Post type or array of types where sharing buttons are to be displayed',
80
		'sharing_open_links'                   => '(string) Link target for sharing buttons (same or new)',
81
		'twitter_via'                          => '(string) Twitter username to include in tweets when people share using the Twitter button',
82
		'jetpack-twitter-cards-site-tag'       => '(string) The Twitter username of the owner of the site\'s domain.',
83
		'eventbrite_api_token'                 => '(int) The Keyring token ID for an Eventbrite token to associate with the site',
84
		'timezone_string'                      => '(string) PHP-compatible timezone string like \'UTC-5\'',
85
		'gmt_offset'                           => '(int) Site offset from UTC in hours',
86
		'date_format'                          => '(string) PHP Date-compatible date format',
87
		'time_format'                          => '(string) PHP Date-compatible time format',
88
		'start_of_week'                        => '(int) Starting day of week (0 = Sunday, 6 = Saturday)',
89
		'jetpack_testimonial'                  => '(bool) Whether testimonial custom post type is enabled for the site',
90
		'jetpack_testimonial_posts_per_page'   => '(int) Number of testimonials to show per page',
91
		'jetpack_portfolio'                    => '(bool) Whether portfolio custom post type is enabled for the site',
92
		'jetpack_portfolio_posts_per_page'     => '(int) Number of portfolio projects to show per page',
93
		Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION => '(string) The SEO meta description for the site.',
94
		Jetpack_SEO_Titles::TITLE_FORMATS_OPTION  => '(array) SEO meta title formats. Allowed keys: front_page, posts, pages, groups, archives',
95
		'verification_services_codes'          => '(array) Website verification codes. Allowed keys: google, pinterest, bing, yandex',
96
		'amp_is_enabled'                       => '(bool) Whether AMP is enabled for this site',
97
		'podcasting_archive'                   => '(string) The post category, if any, used for publishing podcasts',
98
		'site_icon'                            => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear',
99
		'api_cache'                            => '(bool) Turn on/off the Jetpack JSON API cache',
100
		'posts_per_page'                       => '(int) Number of posts to show on blog pages',
101
		'posts_per_rss'                        => '(int) Number of posts to show in the RSS feed',
102
		'rss_use_excerpt'                      => '(bool) Whether the RSS feed will use post excerpts',
103
	),
104
105
	'response_format' => array(
106
		'updated' => '(array)'
107
	),
108
109
	'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/settings?pretty=1',
110
) );
111
112
class WPCOM_JSON_API_Site_Settings_V1_3_Endpoint extends WPCOM_JSON_API_Site_Settings_V1_2_Endpoint {
113
	protected function get_defaults() {
114
		return array(
115
			'code'                 => '',
116
			'anonymize_ip'         => false,
117
			'ec_track_purchases'   => false,
118
			'ec_track_add_to_cart' => false
119
		);
120
	}
121
122
	function callback( $path = '', $blog_id = 0 ) {
123
		add_filter( 'site_settings_endpoint_get', array( $this, 'filter_site_settings_endpoint_get' ) );
124
		add_filter( 'site_settings_update_wga', array( $this, 'filter_update_google_analytics' ), 10, 2 );
125
		return parent::callback( $path, $blog_id );
126
	}
127
128
	/**
129
	 * Filter the parent's response to include the fields
130
	 * added to 1.3 (and their defaults)
131
	 */
132
	public function filter_site_settings_endpoint_get( $settings ) {
133
		$option_name = defined( 'IS_WPCOM' ) && IS_WPCOM ? 'wga' : 'jetpack_wga';
134
		$option = get_option( $option_name, array() );
135
		$settings[ 'wga' ] = wp_parse_args( $option, $this->get_defaults() );
0 ignored issues
show
$this->get_defaults() is of type array<string,string|fals..._add_to_cart":"false"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
136
		return $settings;
137
	}
138
139
	/**
140
	 * Filter the parent's response to consume our new fields
141
	 */
142
	public function filter_update_google_analytics( $wga, $new_values ) {
143
		$wga_keys = array_keys( $this->get_defaults() );
144
		foreach ( $wga_keys as $wga_key ) {
145
			// Skip code since the parent class has handled it
146
			if ( 'code' === $wga_key ) {
147
				continue;
148
			}
149
			// All our new keys are booleans, so let's coerce each key's value
150
			// before updating the value in settings
151
			if ( array_key_exists( $wga_key, $new_values ) ) {
152
				$wga[ $wga_key ] = WPCOM_JSON_API::is_truthy( $new_values[ $wga_key ] );
153
			}
154
		}
155
		return $wga;
156
	}
157
}
158