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.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / json-endpoints / class.wpcom-json-api-get-site-endpoint.php
jetpack / json-endpoints Last commit date
jetpack 5 years ago class.wpcom-json-api-add-widget-endpoint.php 8 years ago class.wpcom-json-api-autosave-post-v1-1-endpoint.php 6 years ago class.wpcom-json-api-bulk-delete-post-endpoint.php 8 years ago class.wpcom-json-api-bulk-restore-post-endpoint.php 8 years ago class.wpcom-json-api-bulk-update-comments-endpoint.php 7 years ago class.wpcom-json-api-comment-endpoint.php 7 years ago class.wpcom-json-api-delete-media-endpoint.php 8 years ago class.wpcom-json-api-delete-media-v1-1-endpoint.php 8 years ago class.wpcom-json-api-edit-media-v1-2-endpoint.php 3 years ago class.wpcom-json-api-get-autosave-v1-1-endpoint.php 6 years ago class.wpcom-json-api-get-comment-counts-endpoint.php 5 years ago class.wpcom-json-api-get-comment-endpoint.php 5 years ago class.wpcom-json-api-get-comment-history-endpoint.php 5 years ago class.wpcom-json-api-get-comments-tree-endpoint.php 5 years ago class.wpcom-json-api-get-comments-tree-v1-1-endpoint.php 5 years ago class.wpcom-json-api-get-comments-tree-v1-2-endpoint.php 5 years ago class.wpcom-json-api-get-customcss.php 8 years ago class.wpcom-json-api-get-media-endpoint.php 8 years ago class.wpcom-json-api-get-media-v1-1-endpoint.php 8 years ago class.wpcom-json-api-get-media-v1-2-endpoint.php 8 years ago class.wpcom-json-api-get-post-counts-v1-1-endpoint.php 6 years ago class.wpcom-json-api-get-post-endpoint.php 5 years ago class.wpcom-json-api-get-post-v1-1-endpoint.php 5 years ago class.wpcom-json-api-get-site-endpoint.php 5 years ago class.wpcom-json-api-get-site-v1-2-endpoint.php 5 years ago class.wpcom-json-api-get-taxonomies-endpoint.php 5 years ago class.wpcom-json-api-get-taxonomy-endpoint.php 5 years ago class.wpcom-json-api-get-term-endpoint.php 5 years ago class.wpcom-json-api-list-comments-endpoint.php 5 years ago class.wpcom-json-api-list-embeds-endpoint.php 8 years ago class.wpcom-json-api-list-media-endpoint.php 8 years ago class.wpcom-json-api-list-media-v1-1-endpoint.php 8 years ago class.wpcom-json-api-list-media-v1-2-endpoint.php 8 years ago class.wpcom-json-api-list-post-type-taxonomies-endpoint.php 8 years ago class.wpcom-json-api-list-post-types-endpoint.php 5 years ago class.wpcom-json-api-list-posts-endpoint.php 5 years ago class.wpcom-json-api-list-posts-v1-1-endpoint.php 5 years ago class.wpcom-json-api-list-posts-v1-2-endpoint.php 5 years ago class.wpcom-json-api-list-roles-endpoint.php 5 years ago class.wpcom-json-api-list-shortcodes-endpoint.php 8 years ago class.wpcom-json-api-list-terms-endpoint.php 5 years ago class.wpcom-json-api-list-users-endpoint.php 8 years ago class.wpcom-json-api-menus-v1-1-endpoint.php 8 years ago class.wpcom-json-api-post-endpoint.php 5 years ago class.wpcom-json-api-post-v1-1-endpoint.php 5 years ago class.wpcom-json-api-render-embed-endpoint.php 6 years ago class.wpcom-json-api-render-embed-reversal-endpoint.php 8 years ago class.wpcom-json-api-render-endpoint.php 5 years ago class.wpcom-json-api-render-shortcode-endpoint.php 8 years ago class.wpcom-json-api-sharing-buttons-endpoint.php 8 years ago class.wpcom-json-api-site-settings-endpoint.php 5 years ago class.wpcom-json-api-site-settings-v1-2-endpoint.php 5 years ago class.wpcom-json-api-site-settings-v1-3-endpoint.php 5 years ago class.wpcom-json-api-site-settings-v1-4-endpoint.php 5 years ago class.wpcom-json-api-site-user-endpoint.php 8 years ago class.wpcom-json-api-taxonomy-endpoint.php 7 years ago class.wpcom-json-api-update-comment-endpoint.php 5 years ago class.wpcom-json-api-update-customcss.php 8 years ago class.wpcom-json-api-update-media-endpoint.php 8 years ago class.wpcom-json-api-update-media-v1-1-endpoint.php 8 years ago class.wpcom-json-api-update-post-endpoint.php 5 years ago class.wpcom-json-api-update-post-v1-1-endpoint.php 5 years ago class.wpcom-json-api-update-post-v1-2-endpoint.php 5 years ago class.wpcom-json-api-update-site-homepage-endpoint.php 5 years ago class.wpcom-json-api-update-site-logo-endpoint.php 5 years ago class.wpcom-json-api-update-taxonomy-endpoint.php 8 years ago class.wpcom-json-api-update-term-endpoint.php 7 years ago class.wpcom-json-api-update-user-endpoint.php 5 years ago class.wpcom-json-api-upload-media-endpoint.php 8 years ago class.wpcom-json-api-upload-media-v1-1-endpoint.php 5 years ago
class.wpcom-json-api-get-site-endpoint.php
827 lines
1 <?php
2
3 new WPCOM_JSON_API_GET_Site_Endpoint( array(
4 'description' => 'Get information about a site.',
5 'group' => 'sites',
6 'stat' => 'sites:X',
7 'allowed_if_flagged' => true,
8 'method' => 'GET',
9 'max_version' => '1.1',
10 'new_version' => '1.2',
11 'path' => '/sites/%s',
12 'path_labels' => array(
13 '$site' => '(int|string) Site ID or domain',
14 ),
15 'allow_jetpack_site_auth' => true,
16
17 'allow_fallback_to_jetpack_blog_token' => true,
18
19 'query_parameters' => array(
20 'context' => false,
21 'options' => '(string) Optional. Returns specified options only. Comma-separated list. Example: options=login_url,timezone',
22 ),
23
24 'response_format' => WPCOM_JSON_API_GET_Site_Endpoint::$site_format,
25
26 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/',
27 ) );
28
29 class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
30
31 public static $site_format = array(
32 'ID' => '(int) Site ID',
33 'name' => '(string) Title of site',
34 'description' => '(string) Tagline or description of site',
35 'URL' => '(string) Full URL to the site',
36 'user_can_manage' => '(bool) The current user can manage this site', // deprecated.
37 'capabilities' => '(array) Array of capabilities for the current user on this site.',
38 'jetpack' => '(bool) Whether the site is a Jetpack site or not',
39 'jetpack_connection' => '(bool) Whether the site is connected to WP.com via `jetpack-connection`',
40 'is_multisite' => '(bool) Whether the site is a Multisite site or not. Always true for WP.com sites.',
41 'post_count' => '(int) The number of posts the site has',
42 'subscribers_count' => '(int) The number of subscribers the site has',
43 'lang' => '(string) Primary language code of the site',
44 'icon' => '(array) An array of icon formats for the site',
45 'logo' => '(array) The site logo, set in the Customizer',
46 'visible' => '(bool) If this site is visible in the user\'s site list',
47 'is_private' => '(bool) If the site is a private site or not',
48 'is_coming_soon' => '(bool) If the site is marked as "coming soon" or not',
49 'single_user_site' => '(bool) Whether the site is single user. Only returned for WP.com sites and for Jetpack sites with version 3.4 or higher.',
50 'is_vip' => '(bool) If the site is a VIP site or not.',
51 'is_following' => '(bool) If the current user is subscribed to this site in the reader',
52 'organization_id' => '(int) P2 Organization identifier.',
53 'options' => '(array) An array of options/settings for the blog. Only viewable by users with post editing rights to the site. Note: Post formats is deprecated, please see /sites/$id/post-formats/',
54 'plan' => '(array) Details of the current plan for this site.',
55 'updates' => '(array) An array of available updates for plugins, themes, wordpress, and languages.',
56 'jetpack_modules' => '(array) A list of active Jetpack modules.',
57 'meta' => '(object) Meta data',
58 'quota' => '(array) An array describing how much space a user has left for uploads',
59 'launch_status' => '(string) A string describing the launch status of a site',
60 'site_migration' => '(array) Data about any migration into the site.',
61 'is_fse_active' => '(bool) If the site has Full Site Editing active or not.',
62 'is_fse_eligible' => '(bool) If the site is capable of Full Site Editing or not',
63 'is_core_site_editor_enabled' => '(bool) If the site has the core site editor enabled.',
64 );
65
66 protected static $no_member_fields = array(
67 'ID',
68 'name',
69 'description',
70 'URL',
71 'jetpack',
72 'jetpack_connection',
73 'post_count',
74 'subscribers_count',
75 'lang',
76 'locale',
77 'icon',
78 'logo',
79 'visible',
80 'is_private',
81 'is_coming_soon',
82 'is_following',
83 'meta',
84 'launch_status',
85 'site_migration',
86 'is_fse_active',
87 'is_fse_eligible',
88 'is_core_site_editor_enabled',
89 );
90
91 protected static $site_options_format = array(
92 'timezone',
93 'gmt_offset',
94 'blog_public',
95 'videopress_enabled',
96 'upgraded_filetypes_enabled',
97 'login_url',
98 'admin_url',
99 'is_mapped_domain',
100 'is_redirect',
101 'unmapped_url',
102 'featured_images_enabled',
103 'theme_slug',
104 'header_image',
105 'background_color',
106 'image_default_link_type',
107 'image_thumbnail_width',
108 'image_thumbnail_height',
109 'image_thumbnail_crop',
110 'image_medium_width',
111 'image_medium_height',
112 'image_large_width',
113 'image_large_height',
114 'permalink_structure',
115 'post_formats',
116 'default_post_format',
117 'default_category',
118 'allowed_file_types',
119 'show_on_front',
120 /** This filter is documented in modules/likes.php */
121 'default_likes_enabled',
122 'default_sharing_status',
123 'default_comment_status',
124 'default_ping_status',
125 'software_version',
126 'created_at',
127 'wordads',
128 'publicize_permanently_disabled',
129 'frame_nonce',
130 'jetpack_frame_nonce',
131 'page_on_front',
132 'page_for_posts',
133 'headstart',
134 'headstart_is_fresh',
135 'ak_vp_bundle_enabled',
136 Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION,
137 Jetpack_SEO_Titles::TITLE_FORMATS_OPTION,
138 'verification_services_codes',
139 'podcasting_archive',
140 'is_domain_only',
141 'is_automated_transfer',
142 'is_wpcom_atomic',
143 'is_wpcom_store',
144 'signup_is_store',
145 'has_pending_automated_transfer',
146 'woocommerce_is_active',
147 'design_type',
148 'site_goals',
149 'site_segment',
150 'import_engine',
151 'is_wpforteams_site',
152 'site_creation_flow',
153 'is_cloud_eligible',
154 'selected_features',
155 'anchor_podcast',
156 );
157
158 protected static $jetpack_response_field_additions = array(
159 'subscribers_count',
160 'site_migration',
161 );
162
163 protected static $jetpack_response_field_member_additions = array(
164 'capabilities',
165 'plan',
166 'products',
167 );
168
169 protected static $jetpack_response_option_additions = array(
170 'publicize_permanently_disabled',
171 'ak_vp_bundle_enabled',
172 'is_automated_transfer',
173 'is_wpcom_atomic',
174 'is_wpcom_store',
175 'woocommerce_is_active',
176 'frame_nonce',
177 'jetpack_frame_nonce',
178 'design_type',
179 'wordads',
180 // Use the site registered date from wpcom, since it is only available in a multisite context
181 // and defaults to `0000-00-00T00:00:00+00:00` from the Jetpack site.
182 // See https://github.com/Automattic/jetpack/blob/58638f46094b36f5df9cbc4570006544f0ad300c/sal/class.json-api-site-base.php#L387.
183 'created_at',
184 );
185
186 private $site;
187
188 // protected $compact = null;
189 protected $fields_to_include = '_all';
190 protected $options_to_include = '_all';
191
192 // /sites/mine
193 // /sites/%s -> $blog_id
194 function callback( $path = '', $blog_id = 0 ) {
195 if ( 'mine' === $blog_id ) {
196 $api = WPCOM_JSON_API::init();
197 if ( ! $api->token_details || empty( $api->token_details['blog_id'] ) ) {
198 return new WP_Error( 'authorization_required', 'An active access token must be used to query information about the current blog.', 403 );
199 }
200 $blog_id = $api->token_details['blog_id'];
201 }
202
203 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
204 if ( is_wp_error( $blog_id ) ) {
205 return $blog_id;
206 }
207
208 $this->filter_fields_and_options();
209
210 $response = $this->build_current_site_response();
211
212 /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
213 do_action( 'wpcom_json_api_objects', 'sites' );
214
215 return $response;
216 }
217
218 public function filter_fields_and_options() {
219 $query_args = $this->query_args();
220
221 $this->fields_to_include = empty( $query_args['fields'] ) ? '_all' : array_map( 'trim', explode( ',', $query_args['fields'] ) );
222 $this->options_to_include = empty( $query_args['options'] ) ? '_all' : array_map( 'trim', explode( ',', $query_args['options'] ) );
223 }
224
225 /**
226 * Collects the necessary information to return for a site's response.
227 *
228 * @return array
229 */
230 public function build_current_site_response() {
231
232 $blog_id = (int) $this->api->get_blog_id_for_output();
233
234 $this->site = $this->get_platform()->get_site( $blog_id );
235
236 /**
237 * Filter the structure of information about the site to return.
238 *
239 * @module json-api
240 *
241 * @since 3.9.3
242 *
243 * @param array $site_format Data structure.
244 */
245 $default_fields = array_keys( apply_filters( 'sites_site_format', self::$site_format ) );
246
247 $response_keys = is_array( $this->fields_to_include ) ?
248 array_intersect( $default_fields, $this->fields_to_include ) :
249 $default_fields;
250
251 $has_blog_access = $this->has_blog_access( $this->api->token_details );
252 $has_user_access = $this->has_user_access();
253
254 if ( ! $has_user_access && ! $has_blog_access ) {
255 // Public access without user or blog auth, only return `$no_member_fields`.
256 $response_keys = array_intersect( $response_keys, self::$no_member_fields );
257 } elseif ( $has_user_access && ! current_user_can( 'edit_posts' ) ) {
258 // Subscriber level user, don't return site options.
259 $response_keys = array_diff( $response_keys, array( 'options' ) );
260 }
261
262 return $this->render_response_keys( $response_keys );
263 }
264
265 /**
266 * Checks that the current user has access to the current blog.
267 *
268 * @return bool Whether or not the current user can access the current blog.
269 */
270 private function has_user_access() {
271 return is_user_member_of_blog( get_current_user_id(), get_current_blog_id() );
272 }
273
274 /**
275 * Checks if the request has a valid blog token for the current blog.
276 *
277 * @param array $token_details Access token for the api request.
278 * @return bool
279 */
280 private function has_blog_access( $token_details ) {
281 $token_details = (array) $token_details;
282 if ( ! isset( $token_details['access'], $token_details['auth'], $token_details['blog_id'] ) ) {
283 return false;
284 }
285
286 return 'jetpack' === $token_details['auth'] &&
287 'blog' === $token_details['access'] &&
288 get_current_blog_id() === $token_details['blog_id'];
289 }
290
291 private function render_response_keys( &$response_keys ) {
292 $response = array();
293
294 $is_user_logged_in = is_user_logged_in();
295
296 $this->site->before_render();
297
298 foreach ( $response_keys as $key ) {
299 $this->render_response_key( $key, $response, $is_user_logged_in );
300 }
301
302 $this->site->after_render( $response );
303
304 return $response;
305 }
306
307 protected function render_response_key( $key, &$response, $is_user_logged_in ) {
308 do_action( 'pre_render_site_response_key', $key );
309
310 switch ( $key ) {
311 case 'ID' :
312 $response[ $key ] = $this->site->blog_id;
313 break;
314 case 'name' :
315 $response[ $key ] = $this->site->get_name();
316 break;
317 case 'description' :
318 $response[ $key ] = $this->site->get_description();
319 break;
320 case 'URL' :
321 $response[ $key ] = $this->site->get_url();
322 break;
323 case 'user_can_manage' :
324 $response[ $key ] = $this->site->user_can_manage();
325 case 'is_private' :
326 $response[ $key ] = $this->site->is_private();
327 break;
328 case 'is_coming_soon' :
329 // This option is stored on wp.com for both simple and atomic sites. @see mu-plugins/private-blog.php
330 $response[ $key ] = $this->site->is_coming_soon();;
331 break;
332 case 'launch_status' :
333 $response[ $key ] = $this->site->get_launch_status();
334 break;
335 case 'visible' :
336 $response[ $key ] = $this->site->is_visible();
337 break;
338 case 'subscribers_count' :
339 $response[ $key ] = $this->site->get_subscribers_count();
340 break;
341 case 'post_count' :
342 if ( $is_user_logged_in ) {
343 $response[ $key ] = $this->site->get_post_count();
344 }
345 break;
346 case 'icon' :
347 $icon = $this->site->get_icon();
348
349 if ( ! is_null( $icon ) ) {
350 $response[ $key ] = $icon;
351 }
352 break;
353 case 'logo' :
354 $response[ $key ] = $this->site->get_logo();
355 break;
356 case 'is_following':
357 $response[ $key ] = $this->site->is_following();
358 break;
359 case 'options':
360 // small optimisation - don't recalculate
361 $all_options = apply_filters( 'sites_site_options_format', self::$site_options_format );
362
363 $options_response_keys = is_array( $this->options_to_include ) ?
364 array_intersect( $all_options, $this->options_to_include ) :
365 $all_options;
366
367 $options = $this->render_option_keys( $options_response_keys );
368
369 $this->site->after_render_options( $options );
370
371 $response[ $key ] = (object) $options;
372 break;
373 case 'meta':
374 $this->build_meta_response( $response );
375 break;
376 case 'lang' :
377 $response[ $key ] = $is_user_logged_in ? $this->site->get_locale() : false;
378 break;
379 case 'locale' :
380 $response[ $key ] = $is_user_logged_in ? $this->site->get_locale() : false;
381 break;
382 case 'jetpack':
383 $response[ $key ] = $this->site->is_jetpack();
384 break;
385 case 'jetpack_connection':
386 $response[ $key ] = $this->site->is_jetpack_connection();
387 break;
388 case 'single_user_site' :
389 $response[ $key ] = $this->site->is_single_user_site();
390 break;
391 case 'is_vip' :
392 $response[ $key ] = $this->site->is_vip();
393 break;
394 case 'is_multisite' :
395 $response[ $key ] = $this->site->is_multisite();
396 break;
397
398 case 'organization_id':
399 $response[ $key ] = $this->site->get_p2_organization_id();
400 break;
401
402 case 'capabilities' :
403 $response[ $key ] = $this->site->get_capabilities();
404 break;
405 case 'jetpack_modules':
406 if ( is_user_member_of_blog() ) {
407 $response[ $key ] = $this->site->get_jetpack_modules();
408 }
409 break;
410 case 'plan' :
411 $response[ $key ] = $this->site->get_plan();
412 break;
413 case 'products' :
414 $response[ $key ] = $this->site->get_products();
415 break;
416 case 'quota' :
417 $response[ $key ] = $this->site->get_quota();
418 break;
419 case 'site_migration' :
420 $response[ $key ] = $this->site->get_migration_meta();
421 break;
422 case 'is_fse_active':
423 $response[ $key ] = $this->site->is_fse_active();
424 break;
425 case 'is_fse_eligible':
426 $response[ $key ] = $this->site->is_fse_eligible();
427 break;
428 case 'is_core_site_editor_enabled':
429 $response[ $key ] = $this->site->is_core_site_editor_enabled();
430 break;
431 }
432
433 do_action( 'post_render_site_response_key', $key );
434 }
435
436 protected function render_option_keys( &$options_response_keys ) {
437 $options = array();
438 $site = $this->site;
439
440 $custom_front_page = $site->is_custom_front_page();
441
442 foreach ( $options_response_keys as $key ) {
443 switch ( $key ) {
444 case 'timezone' :
445 $options[ $key ] = $site->get_timezone();
446 break;
447 case 'gmt_offset' :
448 $options[ $key ] = $site->get_gmt_offset();
449 break;
450 case 'videopress_enabled' :
451 $options[ $key ] = $site->has_videopress();
452 break;
453 case 'upgraded_filetypes_enabled' :
454 $options[ $key ] = $site->upgraded_filetypes_enabled();
455 break;
456 case 'login_url' :
457 $options[ $key ] = $site->get_login_url();
458 break;
459 case 'admin_url' :
460 $options[ $key ] = $site->get_admin_url();
461 break;
462 case 'is_mapped_domain' :
463 $options[ $key ] = $site->is_mapped_domain();
464 break;
465 case 'is_redirect' :
466 $options[ $key ] = $site->is_redirect();
467 break;
468 case 'unmapped_url' :
469 $options[ $key ] = $site->get_unmapped_url();
470 break;
471 case 'featured_images_enabled' :
472 $options[ $key ] = $site->featured_images_enabled();
473 break;
474 case 'theme_slug' :
475 $options[ $key ] = $site->get_theme_slug();
476 break;
477 case 'header_image' :
478 $options[ $key ] = $site->get_header_image();
479 break;
480 case 'background_color' :
481 $options[ $key ] = $site->get_background_color();
482 break;
483 case 'image_default_link_type' :
484 $options[ $key ] = $site->get_image_default_link_type();
485 break;
486 case 'image_thumbnail_width' :
487 $options[ $key ] = $site->get_image_thumbnail_width();
488 break;
489 case 'image_thumbnail_height' :
490 $options[ $key ] = $site->get_image_thumbnail_height();
491 break;
492 case 'image_thumbnail_crop' :
493 $options[ $key ] = $site->get_image_thumbnail_crop();
494 break;
495 case 'image_medium_width' :
496 $options[ $key ] = $site->get_image_medium_width();
497 break;
498 case 'image_medium_height' :
499 $options[ $key ] = $site->get_image_medium_height();
500 break;
501 case 'image_large_width' :
502 $options[ $key ] = $site->get_image_large_width();
503 break;
504 case 'image_large_height' :
505 $options[ $key ] = $site->get_image_large_height();
506 break;
507 case 'permalink_structure' :
508 $options[ $key ] = $site->get_permalink_structure();
509 break;
510 case 'post_formats' :
511 $options[ $key ] = $site->get_post_formats();
512 break;
513 case 'default_post_format' :
514 $options[ $key ] = $site->get_default_post_format();
515 break;
516 case 'default_category' :
517 $options[ $key ] = $site->get_default_category();
518 break;
519 case 'allowed_file_types' :
520 $options[ $key ] = $site->allowed_file_types();
521 break;
522 case 'show_on_front' :
523 $options[ $key ] = $site->get_show_on_front();
524 break;
525 /** This filter is documented in modules/likes.php */
526 case 'default_likes_enabled' :
527 $options[ $key ] = $site->get_default_likes_enabled();
528 break;
529 case 'default_sharing_status' :
530 $options[ $key ] = $site->get_default_sharing_status();
531 break;
532 case 'default_comment_status' :
533 $options[ $key ] = $site->get_default_comment_status();
534 break;
535 case 'default_ping_status' :
536 $options[ $key ] = $site->default_ping_status();
537 break;
538 case 'software_version' :
539 $options[ $key ] = $site->get_wordpress_version();
540 break;
541 case 'created_at' :
542 $options[ $key ] = $site->get_registered_date();
543 break;
544 case 'wordads' :
545 $options[ $key ] = $site->has_wordads();
546 break;
547 case 'publicize_permanently_disabled' :
548 $options[ $key ] = $site->is_publicize_permanently_disabled();
549 break;
550 case 'frame_nonce' :
551 $options[ $key ] = $site->get_frame_nonce();
552 break;
553 case 'jetpack_frame_nonce' :
554 $options[ $key ] = $site->get_jetpack_frame_nonce();
555 break;
556 case 'page_on_front' :
557 if ( $custom_front_page ) {
558 $options[ $key ] = $site->get_page_on_front();
559 }
560 break;
561 case 'page_for_posts' :
562 if ( $custom_front_page ) {
563 $options[ $key ] = $site->get_page_for_posts();
564 }
565 break;
566 case 'headstart' :
567 $options[ $key ] = $site->is_headstart();
568 break;
569 case 'headstart_is_fresh' :
570 $options[ $key ] = $site->is_headstart_fresh();
571 break;
572 case 'ak_vp_bundle_enabled' :
573 $options[ $key ] = $site->get_ak_vp_bundle_enabled();
574 break;
575 case Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION :
576 $options[ $key ] = $site->get_jetpack_seo_front_page_description();
577 break;
578 case Jetpack_SEO_Titles::TITLE_FORMATS_OPTION :
579 $options[ $key ] = $site->get_jetpack_seo_title_formats();
580 break;
581 case 'verification_services_codes' :
582 $options[ $key ] = $site->get_verification_services_codes();
583 break;
584 case 'podcasting_archive':
585 $options[ $key ] = $site->get_podcasting_archive();
586 break;
587 case 'is_domain_only':
588 $options[ $key ] = $site->is_domain_only();
589 break;
590 case 'is_automated_transfer':
591 $options[ $key ] = $site->is_automated_transfer();
592 break;
593 case 'blog_public':
594 $options[ $key ] = $site->get_blog_public();
595 break;
596 case 'is_wpcom_atomic':
597 $options[ $key ] = $site->is_wpcom_atomic();
598 break;
599 case 'is_wpcom_store':
600 $options[ $key ] = $site->is_wpcom_store();
601 break;
602 case 'signup_is_store':
603 $signup_is_store = $site->signup_is_store();
604
605 if ( $signup_is_store ) {
606 $options[ $key ] = $site->signup_is_store();
607 }
608
609 break;
610 case 'has_pending_automated_transfer':
611 $has_pending_automated_transfer = $site->has_pending_automated_transfer();
612
613 if ( $has_pending_automated_transfer ) {
614 $options[ $key ] = true;
615 }
616
617 break;
618 case 'woocommerce_is_active':
619 $options[ $key ] = $site->woocommerce_is_active();
620 break;
621 case 'design_type':
622 $options[ $key ] = $site->get_design_type();
623 break;
624 case 'site_goals':
625 $options[ $key ] = $site->get_site_goals();
626 break;
627 case 'site_segment':
628 $options[ $key ] = $site->get_site_segment();
629 break;
630 case 'import_engine':
631 $options[ $key ] = $site->get_import_engine();
632 break;
633
634 case 'is_wpforteams_site':
635 $options[ $key ] = $site->is_wpforteams_site();
636 break;
637 case 'site_creation_flow':
638 $site_creation_flow = $site->get_site_creation_flow();
639 if ( $site_creation_flow ) {
640 $options[ $key ] = $site_creation_flow;
641 }
642 break;
643 case 'is_cloud_eligible':
644 $options[ $key ] = $site->is_cloud_eligible();
645 break;
646 case 'selected_features':
647 $selected_features = $site->get_selected_features();
648 if ( $selected_features ) {
649 $options[ $key ] = $selected_features;
650 }
651 break;
652 case 'anchor_podcast':
653 $options[ $key ] = $site->get_anchor_podcast();
654 break;
655 }
656 }
657
658 return $options;
659 }
660
661 protected function build_meta_response( &$response ) {
662 $links = array(
663 'self' => (string) $this->links->get_site_link( $this->site->blog_id ),
664 'help' => (string) $this->links->get_site_link( $this->site->blog_id, 'help' ),
665 'posts' => (string) $this->links->get_site_link( $this->site->blog_id, 'posts/' ),
666 'comments' => (string) $this->links->get_site_link( $this->site->blog_id, 'comments/' ),
667 'xmlrpc' => (string) $this->site->get_xmlrpc_url(),
668 );
669
670 $icon = $this->site->get_icon();
671 if ( ! empty( $icon ) && ! empty( $icon['media_id'] ) ) {
672 $links['site_icon'] = (string) $this->links->get_site_link( $this->site->blog_id, 'media/' . $icon['media_id'] );
673 }
674
675 $response['meta'] = (object) array(
676 'links' => (object) $links
677 );
678 }
679
680 // apply any WPCOM-only response components to a Jetpack site response
681 public function decorate_jetpack_response( &$response ) {
682 $this->site = $this->get_platform()->get_site( $response->ID );
683 switch_to_blog( $this->site->get_id() );
684
685 $wpcom_response = $this->render_response_keys( self::$jetpack_response_field_additions );
686
687 foreach( $wpcom_response as $key => $value ) {
688 $response->{ $key } = $value;
689 }
690
691 if ( $this->has_user_access() || $this->has_blog_access( $this->api->token_details ) ) {
692 $wpcom_member_response = $this->render_response_keys( self::$jetpack_response_field_member_additions );
693
694 foreach( $wpcom_member_response as $key => $value ) {
695 $response->{ $key } = $value;
696 }
697 } else {
698 // ensure private data is not rendered for non members of the site
699 unset( $response->options );
700 unset( $response->is_vip );
701 unset( $response->single_user_site );
702 unset( $response->is_private );
703 unset( $response->is_coming_soon );
704 unset( $response->capabilities );
705 unset( $response->lang );
706 unset( $response->user_can_manage );
707 unset( $response->is_multisite );
708 unset( $response->plan );
709 unset( $response->products );
710 }
711
712 // render additional options
713 if ( $response->options ) {
714 $wpcom_options_response = $this->render_option_keys( self::$jetpack_response_option_additions );
715
716 foreach ( $wpcom_options_response as $key => $value ) {
717 $response->options[ $key ] = $value;
718 }
719 }
720
721 restore_current_blog();
722 return $response; // possibly no need since it's modified in place
723 }
724 }
725
726 new WPCOM_JSON_API_List_Post_Formats_Endpoint( array(
727 'description' => 'Get a list of post formats supported by a site.',
728 'group' => '__do_not_document',
729 'stat' => 'sites:X:post-formats',
730
731 'method' => 'GET',
732 'path' => '/sites/%s/post-formats',
733 'path_labels' => array(
734 '$site' => '(int|string) Site ID or domain',
735 ),
736
737 'query_parameters' => array(
738 'context' => false,
739 ),
740
741 'allow_fallback_to_jetpack_blog_token' => true,
742
743 'response_format' => array(
744 'formats' => '(object) An object of supported post formats, each key a supported format slug mapped to its display string.',
745 )
746 ) );
747
748 class WPCOM_JSON_API_List_Post_Formats_Endpoint extends WPCOM_JSON_API_Endpoint {
749 // /sites/%s/post-formats -> $blog_id
750 function callback( $path = '', $blog_id = 0 ) {
751 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
752 if ( is_wp_error( $blog_id ) ) {
753 return $blog_id;
754 }
755
756 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
757 $this->load_theme_functions();
758 }
759
760 // Get a list of supported post formats.
761 $all_formats = get_post_format_strings();
762 $supported = get_theme_support( 'post-formats' );
763
764 $supported_formats = $response['formats'] = array();
765
766 if ( isset( $supported[0] ) ) {
767 foreach ( $supported[0] as $format ) {
768 $supported_formats[ $format ] = $all_formats[ $format ];
769 }
770 }
771
772 $response['formats'] = (object) $supported_formats;
773
774 return $response;
775 }
776 }
777
778 new WPCOM_JSON_API_List_Page_Templates_Endpoint( array(
779 'description' => 'Get a list of page templates supported by a site.',
780 'group' => 'sites',
781 'stat' => 'sites:X:post-templates',
782
783 'method' => 'GET',
784 'path' => '/sites/%s/page-templates',
785 'path_labels' => array(
786 '$site' => '(int|string) Site ID or domain',
787 ),
788 'query_parameters' => array(
789 'context' => false,
790 ),
791 'response_format' => array(
792 'templates' => '(array) A list of supported page templates. Contains label and file.',
793 ),
794 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/33534099/page-templates'
795 ) );
796
797 class WPCOM_JSON_API_List_Page_Templates_Endpoint extends WPCOM_JSON_API_Endpoint {
798 // /sites/%s/page-templates -> $blog_id
799 function callback( $path = '', $blog_id = 0 ) {
800 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
801 if ( is_wp_error( $blog_id ) ) {
802 return $blog_id;
803 }
804
805 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
806 $this->load_theme_functions();
807 }
808
809 $response = array();
810 $page_templates = array();
811
812 $templates = get_page_templates();
813 ksort( $templates );
814
815 foreach ( array_keys( $templates ) as $label ) {
816 $page_templates[] = array(
817 'label' => $label,
818 'file' => $templates[ $label ]
819 );
820 }
821
822 $response['templates'] = $page_templates;
823
824 return $response;
825 }
826 }
827