PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 14.7.1
Jetpack – WP Security, Backup, Speed, & Growth v14.7.1
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 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.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 1 year ago class.wpcom-json-api-add-widget-endpoint.php 2 years ago class.wpcom-json-api-autosave-post-v1-1-endpoint.php 5 years ago class.wpcom-json-api-bulk-delete-post-endpoint.php 4 years ago class.wpcom-json-api-bulk-restore-post-endpoint.php 2 years ago class.wpcom-json-api-bulk-update-comments-endpoint.php 3 years ago class.wpcom-json-api-comment-endpoint.php 1 year ago class.wpcom-json-api-delete-media-endpoint.php 4 years ago class.wpcom-json-api-delete-media-v1-1-endpoint.php 4 years ago class.wpcom-json-api-edit-media-v1-2-endpoint.php 2 years ago class.wpcom-json-api-get-autosave-v1-1-endpoint.php 5 years ago class.wpcom-json-api-get-comment-counts-endpoint.php 1 year ago class.wpcom-json-api-get-comment-endpoint.php 4 years ago class.wpcom-json-api-get-comment-history-endpoint.php 1 year ago class.wpcom-json-api-get-comments-tree-endpoint.php 4 years ago class.wpcom-json-api-get-comments-tree-v1-1-endpoint.php 4 years ago class.wpcom-json-api-get-comments-tree-v1-2-endpoint.php 4 years ago class.wpcom-json-api-get-customcss.php 2 years ago class.wpcom-json-api-get-media-endpoint.php 4 years ago class.wpcom-json-api-get-media-v1-1-endpoint.php 4 years ago class.wpcom-json-api-get-media-v1-2-endpoint.php 2 years ago class.wpcom-json-api-get-post-counts-v1-1-endpoint.php 2 years ago class.wpcom-json-api-get-post-endpoint.php 2 years ago class.wpcom-json-api-get-post-v1-1-endpoint.php 2 years ago class.wpcom-json-api-get-site-endpoint.php 1 year ago class.wpcom-json-api-get-site-v1-2-endpoint.php 1 year ago class.wpcom-json-api-get-taxonomies-endpoint.php 2 years ago class.wpcom-json-api-get-taxonomy-endpoint.php 4 years ago class.wpcom-json-api-get-term-endpoint.php 4 years ago class.wpcom-json-api-list-comments-endpoint.php 1 year ago class.wpcom-json-api-list-dropdown-pages-endpoint.php 3 years ago class.wpcom-json-api-list-embeds-endpoint.php 4 years ago class.wpcom-json-api-list-media-endpoint.php 2 years ago class.wpcom-json-api-list-media-v1-1-endpoint.php 2 years ago class.wpcom-json-api-list-media-v1-2-endpoint.php 2 years ago class.wpcom-json-api-list-post-type-taxonomies-endpoint.php 4 years ago class.wpcom-json-api-list-post-types-endpoint.php 3 years ago class.wpcom-json-api-list-posts-endpoint.php 1 year ago class.wpcom-json-api-list-posts-v1-1-endpoint.php 1 year ago class.wpcom-json-api-list-posts-v1-2-endpoint.php 1 year ago class.wpcom-json-api-list-roles-endpoint.php 1 year ago class.wpcom-json-api-list-shortcodes-endpoint.php 4 years ago class.wpcom-json-api-list-terms-endpoint.php 2 years ago class.wpcom-json-api-list-users-endpoint.php 1 year ago class.wpcom-json-api-menus-v1-1-endpoint.php 1 year ago class.wpcom-json-api-post-endpoint.php 2 years ago class.wpcom-json-api-post-v1-1-endpoint.php 2 years ago class.wpcom-json-api-render-embed-endpoint.php 2 years ago class.wpcom-json-api-render-embed-reversal-endpoint.php 2 years ago class.wpcom-json-api-render-endpoint.php 3 years ago class.wpcom-json-api-render-shortcode-endpoint.php 3 years ago class.wpcom-json-api-sharing-buttons-endpoint.php 2 years ago class.wpcom-json-api-site-settings-endpoint.php 1 year ago class.wpcom-json-api-site-settings-v1-2-endpoint.php 2 years ago class.wpcom-json-api-site-settings-v1-3-endpoint.php 2 years ago class.wpcom-json-api-site-settings-v1-4-endpoint.php 1 year ago class.wpcom-json-api-site-user-endpoint.php 1 year ago class.wpcom-json-api-taxonomy-endpoint.php 4 years ago class.wpcom-json-api-update-comment-endpoint.php 2 years ago class.wpcom-json-api-update-customcss.php 2 years ago class.wpcom-json-api-update-media-endpoint.php 4 years ago class.wpcom-json-api-update-media-v1-1-endpoint.php 2 years ago class.wpcom-json-api-update-post-endpoint.php 1 year ago class.wpcom-json-api-update-post-v1-1-endpoint.php 1 year ago class.wpcom-json-api-update-post-v1-2-endpoint.php 1 year ago class.wpcom-json-api-update-site-homepage-endpoint.php 4 years ago class.wpcom-json-api-update-site-logo-endpoint.php 2 years ago class.wpcom-json-api-update-taxonomy-endpoint.php 4 years ago class.wpcom-json-api-update-term-endpoint.php 4 years ago class.wpcom-json-api-update-user-endpoint.php 1 year ago class.wpcom-json-api-upload-media-endpoint.php 3 years ago class.wpcom-json-api-upload-media-v1-1-endpoint.php 1 year ago
class.wpcom-json-api-get-site-endpoint.php
1160 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 new WPCOM_JSON_API_GET_Site_Endpoint(
4 array(
5 'description' => 'Get information about a site.',
6 'group' => 'sites',
7 'stat' => 'sites:X',
8 'allowed_if_flagged' => true,
9 'method' => 'GET',
10 'max_version' => '1.1',
11 'new_version' => '1.2',
12 'path' => '/sites/%s',
13 'path_labels' => array(
14 '$site' => '(int|string) Site ID or domain',
15 ),
16 'rest_route' => '/site',
17 'rest_min_jp_version' => '14.5-a.2',
18 'allow_jetpack_site_auth' => true,
19
20 'allow_fallback_to_jetpack_blog_token' => true,
21
22 'query_parameters' => array(
23 'context' => false,
24 'options' => '(string) Optional. Returns specified options only. Comma-separated list. Example: options=login_url,timezone',
25 ),
26
27 'response_format' => WPCOM_JSON_API_GET_Site_Endpoint::$site_format,
28
29 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/',
30 )
31 );
32
33 /**
34 * GET Site endpoint class.
35 */
36 class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
37
38 /**
39 * Site meta data.
40 *
41 * @var array $site_format
42 */
43 public static $site_format = array(
44 'ID' => '(int) Site ID',
45 'slug' => '(string) Slug of site',
46 'name' => '(string) Title of site',
47 'description' => '(string) Tagline or description of site',
48 'URL' => '(string) Full URL to the site',
49 'user_can_manage' => '(bool) The current user can manage this site', // deprecated.
50 'capabilities' => '(array) Array of capabilities for the current user on this site.',
51 'jetpack' => '(bool) Whether the site is a Jetpack site or not',
52 'jetpack_connection' => '(bool) Whether the site is connected to WP.com via `jetpack-connection`',
53 'is_multisite' => '(bool) Whether the site is a Multisite site or not. Always true for WP.com sites.',
54 'site_owner' => '(int) User ID of the site owner',
55 'post_count' => '(int) The number of posts the site has',
56 'subscribers_count' => '(int) The number of subscribers the site has',
57 'lang' => '(string) Primary language code of the site',
58 'icon' => '(array) An array of icon formats for the site',
59 'logo' => '(array) The site logo, set in the Customizer',
60 'visible' => '(bool) If this site is visible in the user\'s site list',
61 'is_private' => '(bool) If the site is a private site or not',
62 'is_coming_soon' => '(bool) If the site is marked as "coming soon" or not',
63 '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.',
64 'is_vip' => '(bool) If the site is a VIP site or not.',
65 'is_following' => '(bool) If the current user is subscribed to this site in the reader',
66 'organization_id' => '(int) P2 Organization identifier.',
67 '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/',
68 'p2_thumbnail_elements' => '(array) Details used to render a thumbnail of the site. P2020 themed sites only.',
69 'plan' => '(array) Details of the current plan for this site.',
70 'products' => '(array) Details of the current products for this site.',
71 'zendesk_site_meta' => '(array) Site meta data for Zendesk.',
72 'updates' => '(array) An array of available updates for plugins, themes, wordpress, and languages.',
73 'jetpack_modules' => '(array) A list of active Jetpack modules.',
74 'meta' => '(object) Meta data',
75 'quota' => '(array) An array describing how much space a user has left for uploads',
76 'launch_status' => '(string) A string describing the launch status of a site',
77 'site_migration' => '(array) Data about any migration into the site.',
78 'is_fse_active' => '(bool) If the site has Full Site Editing active or not.',
79 'is_fse_eligible' => '(bool) If the site is capable of Full Site Editing or not',
80 'is_core_site_editor_enabled' => '(bool) If the site has the core site editor enabled.',
81 'is_wpcom_atomic' => '(bool) If the site is a WP.com Atomic one.',
82 'is_wpcom_staging_site' => '(bool) If the site is a WP.com staging site.',
83 'user_interactions' => '(array) An array of user interactions with a site.',
84 'was_ecommerce_trial' => '(bool) If the site ever used an eCommerce trial.',
85 'was_upgraded_from_trial' => '(bool) If the site ever upgraded to a paid plan from a trial.',
86 'was_migration_trial' => '(bool) If the site ever used a migration trial.',
87 'was_hosting_trial' => '(bool) If the site ever used a hosting trial.',
88 'wpcom_site_setup' => '(string) The WP.com site setup identifier.',
89 'is_deleted' => '(bool) If the site flagged as deleted.',
90 'is_a4a_client' => '(bool) If the site is an A4A client site.',
91 'is_a4a_dev_site' => '(bool) If the site is an A4A dev site.',
92 );
93
94 /**
95 * No member fields.
96 *
97 * @var array $no_member_fields
98 */
99 protected static $no_member_fields = array(
100 'ID',
101 'name',
102 'description',
103 'URL',
104 'jetpack',
105 'jetpack_connection',
106 'post_count',
107 'subscribers_count',
108 'lang',
109 'locale',
110 'icon',
111 'logo',
112 'visible',
113 'is_private',
114 'is_coming_soon',
115 'is_following',
116 'organization_id',
117 'meta',
118 'launch_status',
119 'site_migration',
120 'is_fse_active',
121 'is_fse_eligible',
122 'is_core_site_editor_enabled',
123 'is_wpcom_atomic',
124 'is_wpcom_staging_site',
125 'is_deleted',
126 'is_a4a_client',
127 'is_a4a_dev_site',
128 );
129
130 /**
131 * Site options.
132 *
133 * @var array $site_options_format
134 */
135 protected static $site_options_format = array(
136 'timezone',
137 'gmt_offset',
138 'blog_public',
139 'videopress_enabled',
140 'upgraded_filetypes_enabled',
141 'login_url',
142 'admin_url',
143 'is_mapped_domain',
144 'is_redirect',
145 'unmapped_url',
146 'featured_images_enabled',
147 'theme_slug',
148 'theme_errors',
149 'header_image',
150 'background_color',
151 'image_default_link_type',
152 'image_thumbnail_width',
153 'image_thumbnail_height',
154 'image_thumbnail_crop',
155 'image_medium_width',
156 'image_medium_height',
157 'image_large_width',
158 'image_large_height',
159 'permalink_structure',
160 'post_formats',
161 'default_post_format',
162 'default_category',
163 'allowed_file_types',
164 'show_on_front',
165 /** This filter is documented in modules/likes.php */
166 'default_likes_enabled',
167 'default_sharing_status',
168 'default_comment_status',
169 'default_ping_status',
170 'software_version',
171 'created_at',
172 'updated_at',
173 'wordads',
174 'publicize_permanently_disabled',
175 'frame_nonce',
176 'jetpack_frame_nonce',
177 'page_on_front',
178 'page_for_posts',
179 'headstart',
180 'headstart_is_fresh',
181 'ak_vp_bundle_enabled',
182 Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION,
183 Jetpack_SEO_Titles::TITLE_FORMATS_OPTION,
184 'verification_services_codes',
185 'podcasting_archive',
186 'is_domain_only',
187 'is_automated_transfer',
188 'is_wpcom_atomic',
189 'is_wpcom_store',
190 'signup_is_store',
191 'has_pending_automated_transfer',
192 'woocommerce_is_active',
193 'editing_toolkit_is_active',
194 'design_type',
195 'site_goals',
196 'site_segment',
197 'site_source_slug',
198 'import_engine',
199 'is_pending_plan',
200 'is_wpforteams_site',
201 'p2_hub_blog_id',
202 'site_creation_flow',
203 'is_cloud_eligible',
204 'selected_features',
205 'anchor_podcast',
206 'was_created_with_blank_canvas_design',
207 'videopress_storage_used',
208 'is_difm_lite_in_progress',
209 'site_intent',
210 'site_partner_bundle',
211 'onboarding_segment',
212 'site_vertical_id',
213 'blogging_prompts_settings',
214 'launchpad_screen',
215 'launchpad_checklist_tasks_statuses',
216 'migration_source_site_domain',
217 'wpcom_production_blog_id',
218 'wpcom_staging_blog_ids',
219 'can_blaze',
220 'wpcom_site_setup',
221 'is_commercial',
222 'is_commercial_reasons',
223 'wpcom_admin_interface',
224 'wpcom_classic_early_release',
225 );
226
227 /**
228 * Jetpack response fields.
229 *
230 * @var array $jetpack_response_field_additions
231 */
232 protected static $jetpack_response_field_additions = array(
233 'slug',
234 'subscribers_count',
235 'site_migration',
236 'site_owner',
237 'is_wpcom_staging_site',
238 'was_ecommerce_trial',
239 'was_migration_trial',
240 'was_hosting_trial',
241 'was_upgraded_from_trial',
242 'is_a4a_dev_site',
243 );
244
245 /**
246 * Jetpack response field member additions.
247 *
248 * @var array $jetpack_response_field_member_additions
249 */
250 protected static $jetpack_response_field_member_additions = array(
251 'capabilities',
252 'plan',
253 'products',
254 'zendesk_site_meta',
255 );
256
257 /**
258 * Jetpack response option additions.
259 *
260 * @var array $jetpack_response_field_member_additions
261 */
262 protected static $jetpack_response_option_additions = array(
263 'publicize_permanently_disabled',
264 'ak_vp_bundle_enabled',
265 'is_automated_transfer',
266 'is_wpcom_atomic',
267 'is_wpcom_store',
268 'woocommerce_is_active',
269 'editing_toolkit_is_active',
270 'frame_nonce',
271 'jetpack_frame_nonce',
272 'design_type',
273 'wordads',
274 // Use the site registered date from wpcom, since it is only available in a multisite context
275 // and defaults to `0000-00-00T00:00:00+00:00` from the Jetpack site.
276 // See https://github.com/Automattic/jetpack/blob/58638f46094b36f5df9cbc4570006544f0ad300c/sal/class.json-api-site-base.php#L387.
277 'created_at',
278 'updated_at',
279 'is_pending_plan',
280 'is_cloud_eligible',
281 'videopress_storage_used',
282 'blogging_prompts_settings',
283 'wpcom_production_blog_id',
284 'wpcom_staging_blog_ids',
285 'is_commercial',
286 'is_commercial_reasons',
287 'wpcom_admin_interface',
288 'wpcom_classic_early_release',
289 );
290
291 /**
292 * Current enabled trials.
293 *
294 * @var array $jetpack_enabled_trials
295 */
296 public static $jetpack_enabled_trials = array(
297 'was_ecommerce_trial' => 'ecommerce',
298 'was_migration_trial' => 'migration',
299 'was_hosting_trial' => 'hosting',
300 );
301
302 /**
303 * Site
304 *
305 * @var SAL_Site $site.
306 */
307 private $site;
308
309 /**
310 * Fields to include.
311 *
312 * @var $fields_to_include
313 */
314 protected $fields_to_include = '_all';
315
316 /**
317 * Options to include.
318 *
319 * @var $options_to_include
320 */
321 protected $options_to_include = '_all';
322
323 /**
324 *
325 * API callback.
326 *
327 * /sites/mine
328 * /sites/%s -> $blog_id\
329 *
330 * @param string $path - the path.
331 * @param int $blog_id - the blog ID.
332 */
333 public function callback( $path = '', $blog_id = 0 ) {
334 if ( 'mine' === $blog_id ) {
335 $api = WPCOM_JSON_API::init();
336 if ( ! $api->token_details || empty( $api->token_details['blog_id'] ) ) {
337 return new WP_Error( 'authorization_required', 'An active access token must be used to query information about the current blog.', 403 );
338 }
339 $blog_id = $api->token_details['blog_id'];
340 }
341
342 add_filter( 'wpcom_allow_jetpack_blog_token', '__return_true' );
343 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
344 if ( is_wp_error( $blog_id ) ) {
345 return $blog_id;
346 }
347
348 $this->filter_fields_and_options();
349
350 $response = $this->build_current_site_response();
351
352 /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
353 do_action( 'wpcom_json_api_objects', 'sites' );
354
355 return $response;
356 }
357
358 /**
359 * Filter fields and options.
360 */
361 public function filter_fields_and_options() {
362 $query_args = $this->query_args();
363
364 $this->fields_to_include = empty( $query_args['fields'] ) ? '_all' : array_map( 'trim', explode( ',', $query_args['fields'] ) );
365 $this->options_to_include = empty( $query_args['options'] ) ? '_all' : array_map( 'trim', explode( ',', $query_args['options'] ) );
366 }
367
368 /**
369 * Collects the necessary information to return for a site's response.
370 *
371 * @return array
372 */
373 public function build_current_site_response() {
374
375 $blog_id = (int) $this->api->get_blog_id_for_output();
376
377 $this->site = $this->get_platform()->get_site( $blog_id );
378
379 /**
380 * Filter the structure of information about the site to return.
381 *
382 * @module json-api
383 *
384 * @since 3.9.3
385 *
386 * @param array $site_format Data structure.
387 */
388 $default_fields = array_keys( apply_filters( 'sites_site_format', self::$site_format ) );
389
390 $response_keys = is_array( $this->fields_to_include ) ?
391 array_intersect( $default_fields, $this->fields_to_include ) :
392 $default_fields;
393
394 $has_blog_access = $this->has_blog_access( $this->api->token_details );
395 $has_user_access = $this->has_user_access();
396
397 if ( ! $has_user_access && ! $has_blog_access ) {
398 // Public access without user or blog auth, only return `$no_member_fields`.
399 $response_keys = array_intersect( $response_keys, self::$no_member_fields );
400 } elseif ( $has_user_access && ! current_user_can( 'edit_posts' ) ) {
401 // Subscriber level user, don't return site options.
402 $response_keys = array_diff( $response_keys, array( 'options' ) );
403 }
404
405 return $this->render_response_keys( $response_keys );
406 }
407
408 /**
409 * Checks that the current user has access to the current blog.
410 *
411 * @return bool Whether or not the current user can access the current blog.
412 */
413 private function has_user_access() {
414 return is_user_member_of_blog( get_current_user_id(), get_current_blog_id() );
415 }
416
417 /**
418 * Checks if the request has a valid blog token for the current blog.
419 *
420 * @param array $token_details Access token for the api request.
421 * @return bool
422 */
423 private function has_blog_access( $token_details ) {
424 $token_details = (array) $token_details;
425 if ( ! isset( $token_details['access'] ) || ! isset( $token_details['auth'] ) || ! isset( $token_details['blog_id'] ) ) {
426 return false;
427 }
428
429 return 'jetpack' === $token_details['auth'] &&
430 'blog' === $token_details['access'] &&
431 get_current_blog_id() === $token_details['blog_id'];
432 }
433
434 /**
435 * Render response keys.
436 *
437 * @param array $response_keys - the response keys.
438 */
439 private function render_response_keys( &$response_keys ) {
440 $response = array();
441
442 $is_user_logged_in = is_user_logged_in();
443
444 $this->site->before_render();
445
446 foreach ( $response_keys as $key ) {
447 $this->render_response_key( $key, $response, $is_user_logged_in );
448 }
449
450 $this->site->after_render( $response );
451
452 return $response;
453 }
454
455 /**
456 * Render response key.
457 *
458 * @param string $key - the key.
459 * @param array $response - the response.
460 * @param boolean $is_user_logged_in - if the user is logged in.
461 */
462 protected function render_response_key( $key, &$response, $is_user_logged_in ) {
463 do_action( 'pre_render_site_response_key', $key );
464
465 switch ( $key ) {
466 case 'ID':
467 $response[ $key ] = $this->site->blog_id;
468 break;
469 case 'slug':
470 $response[ $key ] = $this->site->get_slug();
471 break;
472 case 'name':
473 $response[ $key ] = $this->site->get_name();
474 break;
475 case 'description':
476 $response[ $key ] = $this->site->get_description();
477 break;
478 case 'URL':
479 $response[ $key ] = $this->site->get_url();
480 break;
481 case 'user_can_manage':
482 $response[ $key ] = $this->site->user_can_manage();
483 // fall through is intentional.
484 case 'is_private':
485 $response[ $key ] = $this->site->is_private();
486 break;
487 case 'is_coming_soon':
488 // This option is stored on wp.com for both simple and atomic sites. @see mu-plugins/private-blog.php.
489 $response[ $key ] = $this->site->is_coming_soon();
490
491 break;
492 case 'launch_status':
493 $response[ $key ] = $this->site->get_launch_status();
494 break;
495 case 'visible':
496 $response[ $key ] = $this->site->is_visible();
497 break;
498 case 'subscribers_count':
499 $response[ $key ] = $this->site->get_subscribers_count();
500 break;
501 case 'post_count':
502 if ( $is_user_logged_in ) {
503 $response[ $key ] = $this->site->get_post_count();
504 }
505 break;
506 case 'icon':
507 $icon = $this->site->get_icon();
508
509 if ( $icon !== null ) {
510 $response[ $key ] = $icon;
511 }
512 break;
513 case 'logo':
514 $response[ $key ] = $this->site->get_logo();
515 break;
516 case 'is_following':
517 $response[ $key ] = $this->site->is_following();
518 break;
519 case 'options':
520 // small optimisation - don't recalculate.
521 $all_options = apply_filters( 'sites_site_options_format', self::$site_options_format );
522
523 $options_response_keys = is_array( $this->options_to_include ) ?
524 array_intersect( $all_options, $this->options_to_include ) :
525 $all_options;
526
527 $options = $this->render_option_keys( $options_response_keys );
528
529 $this->site->after_render_options( $options );
530
531 $response[ $key ] = (object) $options;
532 break;
533 case 'meta':
534 $this->build_meta_response( $response );
535 break;
536 case 'lang':
537 $response[ $key ] = $is_user_logged_in ? $this->site->get_locale() : false;
538 break;
539 case 'locale':
540 $response[ $key ] = $is_user_logged_in ? $this->site->get_locale() : false;
541 break;
542 case 'jetpack':
543 $response[ $key ] = $this->site->is_jetpack();
544 break;
545 case 'jetpack_connection':
546 $response[ $key ] = $this->site->is_jetpack_connection();
547 break;
548 case 'single_user_site':
549 $response[ $key ] = $this->site->is_single_user_site();
550 break;
551 case 'is_vip':
552 $response[ $key ] = $this->site->is_vip();
553 break;
554 case 'is_multisite':
555 $response[ $key ] = $this->site->is_multisite();
556 break;
557 case 'site_owner':
558 $response[ $key ] = $this->site->get_site_owner();
559 break;
560 case 'organization_id':
561 $response[ $key ] = $this->site->get_p2_organization_id();
562 break;
563
564 case 'capabilities':
565 $response[ $key ] = $this->site->get_capabilities();
566 break;
567 case 'jetpack_modules':
568 if ( is_user_member_of_blog() ) {
569 $response[ $key ] = $this->site->get_jetpack_modules();
570 }
571 break;
572 case 'plan':
573 $response[ $key ] = $this->site->get_plan();
574 break;
575 case 'products':
576 $response[ $key ] = $this->site->get_products();
577 break;
578 case 'zendesk_site_meta':
579 $response[ $key ] = $this->site->get_zendesk_site_meta();
580 break;
581 case 'quota':
582 $response[ $key ] = $this->site->get_quota();
583 break;
584 case 'site_migration':
585 $response[ $key ] = $this->site->get_migration_meta();
586 break;
587 case 'is_fse_active':
588 $response[ $key ] = $this->site->is_fse_active();
589 break;
590 case 'is_fse_eligible':
591 $response[ $key ] = $this->site->is_fse_eligible();
592 break;
593 case 'is_core_site_editor_enabled':
594 $response[ $key ] = $this->site->is_core_site_editor_enabled();
595 break;
596 case 'is_wpcom_atomic':
597 $response[ $key ] = $this->site->is_wpcom_atomic();
598 break;
599 case 'is_wpcom_staging_site':
600 $response[ $key ] = $this->site->is_wpcom_staging_site();
601 break;
602 case 'user_interactions':
603 $response[ $key ] = $this->site->get_user_interactions();
604 break;
605 case 'p2_thumbnail_elements':
606 $response[ $key ] = $this->site->get_p2_thumbnail_elements();
607 break;
608 case 'was_ecommerce_trial':
609 $response[ $key ] = $this->site->was_trial( self::$jetpack_enabled_trials['was_ecommerce_trial'] );
610 break;
611 case 'was_migration_trial':
612 $response[ $key ] = $this->site->was_trial( self::$jetpack_enabled_trials['was_migration_trial'] );
613 break;
614 case 'was_hosting_trial':
615 $response[ $key ] = $this->site->was_trial( self::$jetpack_enabled_trials['was_hosting_trial'] );
616 break;
617 case 'was_upgraded_from_trial':
618 $response[ $key ] = $this->site->was_upgraded_from_trial();
619 break;
620 case 'is_deleted':
621 $response[ $key ] = $this->site->is_deleted();
622 break;
623 case 'is_a4a_client':
624 $response[ $key ] = $this->site->is_a4a_client();
625 break;
626 case 'is_a4a_dev_site':
627 $response[ $key ] = $this->site->is_a4a_dev_site();
628 break;
629 }
630
631 do_action( 'post_render_site_response_key', $key );
632 }
633
634 /**
635 * Render option keys.
636 *
637 * @param array $options_response_keys - the response keys.
638 */
639 protected function render_option_keys( &$options_response_keys ) {
640 $options = array();
641 $site = $this->site;
642
643 $custom_front_page = $site->is_custom_front_page();
644
645 foreach ( $options_response_keys as $key ) {
646 switch ( $key ) {
647 case 'timezone':
648 $options[ $key ] = $site->get_timezone();
649 break;
650 case 'gmt_offset':
651 $options[ $key ] = $site->get_gmt_offset();
652 break;
653 case 'videopress_enabled':
654 $options[ $key ] = $site->has_videopress();
655 break;
656 case 'upgraded_filetypes_enabled':
657 $options[ $key ] = $site->upgraded_filetypes_enabled();
658 break;
659 case 'login_url':
660 $options[ $key ] = $site->get_login_url();
661 break;
662 case 'admin_url':
663 $options[ $key ] = $site->get_admin_url();
664 break;
665 case 'is_mapped_domain':
666 $options[ $key ] = $site->is_mapped_domain();
667 break;
668 case 'is_redirect':
669 $options[ $key ] = $site->is_redirect();
670 break;
671 case 'unmapped_url':
672 $options[ $key ] = $site->get_unmapped_url();
673 break;
674 case 'featured_images_enabled':
675 $options[ $key ] = $site->featured_images_enabled();
676 break;
677 case 'theme_slug':
678 $options[ $key ] = $site->get_theme_slug();
679 break;
680 case 'theme_errors':
681 $options[ $key ] = $site->get_theme_errors();
682 break;
683 case 'header_image':
684 $options[ $key ] = $site->get_header_image();
685 break;
686 case 'background_color':
687 $options[ $key ] = $site->get_background_color();
688 break;
689 case 'image_default_link_type':
690 $options[ $key ] = $site->get_image_default_link_type();
691 break;
692 case 'image_thumbnail_width':
693 $options[ $key ] = $site->get_image_thumbnail_width();
694 break;
695 case 'image_thumbnail_height':
696 $options[ $key ] = $site->get_image_thumbnail_height();
697 break;
698 case 'image_thumbnail_crop':
699 $options[ $key ] = $site->get_image_thumbnail_crop();
700 break;
701 case 'image_medium_width':
702 $options[ $key ] = $site->get_image_medium_width();
703 break;
704 case 'image_medium_height':
705 $options[ $key ] = $site->get_image_medium_height();
706 break;
707 case 'image_large_width':
708 $options[ $key ] = $site->get_image_large_width();
709 break;
710 case 'image_large_height':
711 $options[ $key ] = $site->get_image_large_height();
712 break;
713 case 'permalink_structure':
714 $options[ $key ] = $site->get_permalink_structure();
715 break;
716 case 'post_formats':
717 $options[ $key ] = $site->get_post_formats();
718 break;
719 case 'default_post_format':
720 $options[ $key ] = $site->get_default_post_format();
721 break;
722 case 'default_category':
723 $options[ $key ] = $site->get_default_category();
724 break;
725 case 'allowed_file_types':
726 $options[ $key ] = $site->allowed_file_types();
727 break;
728 case 'show_on_front':
729 $options[ $key ] = $site->get_show_on_front();
730 break;
731 /** This filter is documented in modules/likes.php */
732 case 'default_likes_enabled':
733 $options[ $key ] = $site->get_default_likes_enabled();
734 break;
735 case 'default_sharing_status':
736 $options[ $key ] = $site->get_default_sharing_status();
737 break;
738 case 'default_comment_status':
739 $options[ $key ] = $site->get_default_comment_status();
740 break;
741 case 'default_ping_status':
742 $options[ $key ] = $site->default_ping_status();
743 break;
744 case 'software_version':
745 $options[ $key ] = $site->get_wordpress_version();
746 break;
747 case 'created_at':
748 $options[ $key ] = $site->get_registered_date();
749 break;
750 case 'updated_at':
751 $options[ $key ] = $site->get_last_update_date();
752 break;
753 case 'wordads':
754 $options[ $key ] = $site->has_wordads();
755 break;
756 case 'publicize_permanently_disabled':
757 $options[ $key ] = $site->is_publicize_permanently_disabled();
758 break;
759 case 'frame_nonce':
760 $options[ $key ] = $site->get_frame_nonce();
761 break;
762 case 'jetpack_frame_nonce':
763 $options[ $key ] = $site->get_jetpack_frame_nonce();
764 break;
765 case 'page_on_front':
766 if ( $custom_front_page ) {
767 $options[ $key ] = $site->get_page_on_front();
768 }
769 break;
770 case 'page_for_posts':
771 if ( $custom_front_page ) {
772 $options[ $key ] = $site->get_page_for_posts();
773 }
774 break;
775 case 'headstart':
776 $options[ $key ] = $site->is_headstart();
777 break;
778 case 'headstart_is_fresh':
779 $options[ $key ] = $site->is_headstart_fresh();
780 break;
781 case 'ak_vp_bundle_enabled':
782 $options[ $key ] = $site->get_ak_vp_bundle_enabled();
783 break;
784 case Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION:
785 $options[ $key ] = $site->get_jetpack_seo_front_page_description();
786 break;
787 case Jetpack_SEO_Titles::TITLE_FORMATS_OPTION:
788 $options[ $key ] = $site->get_jetpack_seo_title_formats();
789 break;
790 case 'verification_services_codes':
791 $options[ $key ] = $site->get_verification_services_codes();
792 break;
793 case 'podcasting_archive':
794 $options[ $key ] = $site->get_podcasting_archive();
795 break;
796 case 'is_domain_only':
797 $options[ $key ] = $site->is_domain_only();
798 break;
799 case 'is_automated_transfer':
800 $options[ $key ] = $site->is_automated_transfer();
801 break;
802 case 'blog_public':
803 $options[ $key ] = $site->get_blog_public();
804 break;
805 case 'is_wpcom_atomic':
806 $options[ $key ] = $site->is_wpcom_atomic();
807 break;
808 case 'is_wpcom_store':
809 $options[ $key ] = $site->is_wpcom_store();
810 break;
811 case 'signup_is_store':
812 $signup_is_store = $site->signup_is_store();
813
814 if ( $signup_is_store ) {
815 $options[ $key ] = $site->signup_is_store();
816 }
817
818 break;
819 case 'has_pending_automated_transfer':
820 $has_pending_automated_transfer = $site->has_pending_automated_transfer();
821
822 if ( $has_pending_automated_transfer ) {
823 $options[ $key ] = true;
824 }
825
826 break;
827 case 'woocommerce_is_active':
828 $options[ $key ] = $site->woocommerce_is_active();
829 break;
830 case 'editing_toolkit_is_active':
831 $options[ $key ] = $site->editing_toolkit_is_active();
832 break;
833 case 'design_type':
834 $options[ $key ] = $site->get_design_type();
835 break;
836 case 'site_segment':
837 $options[ $key ] = $site->get_site_segment();
838 break;
839 case 'import_engine':
840 $options[ $key ] = $site->get_import_engine();
841 break;
842 case 'is_pending_plan':
843 $options[ $key ] = $site->is_pending_plan();
844 break;
845
846 case 'is_wpforteams_site':
847 $options[ $key ] = $site->is_wpforteams_site();
848 break;
849 case 'p2_hub_blog_id':
850 $options[ $key ] = $site->get_p2_hub_blog_id();
851 break;
852
853 case 'site_creation_flow':
854 $site_creation_flow = $site->get_site_creation_flow();
855 if ( $site_creation_flow ) {
856 $options[ $key ] = $site_creation_flow;
857 }
858 break;
859 case 'site_source_slug':
860 $site_source_slug = $site->get_site_source_slug();
861 if ( $site_source_slug ) {
862 $options[ $key ] = $site_source_slug;
863 }
864 break;
865 case 'is_cloud_eligible':
866 $options[ $key ] = $site->is_cloud_eligible();
867 break;
868 case 'selected_features':
869 $selected_features = $site->get_selected_features();
870 if ( $selected_features ) {
871 $options[ $key ] = $selected_features;
872 }
873 break;
874 case 'anchor_podcast':
875 $options[ $key ] = $site->get_anchor_podcast();
876 break;
877 case 'was_created_with_blank_canvas_design':
878 $options[ $key ] = $site->was_created_with_blank_canvas_design();
879 break;
880 case 'videopress_storage_used':
881 $options[ $key ] = $this->site->get_videopress_storage_used();
882 break;
883 case 'is_difm_lite_in_progress':
884 $options[ $key ] = $site->is_difm_lite_in_progress();
885 break;
886 case 'site_intent':
887 $options[ $key ] = $site->get_site_intent();
888 break;
889 case 'site_partner_bundle':
890 $options[ $key ] = $site->get_site_partner_bundle();
891 break;
892 case 'site_goals':
893 $options[ $key ] = $site->get_site_goals();
894 break;
895 case 'onboarding_segment':
896 $options[ $key ] = $site->get_onboarding_segment();
897 break;
898 case 'site_vertical_id':
899 $options[ $key ] = $site->get_site_vertical_id();
900 break;
901 case 'blogging_prompts_settings':
902 if ( current_user_can( 'edit_posts' ) ) {
903 $options[ $key ] = $site->get_blogging_prompts_settings( get_current_user_id(), $site->blog_id );
904 }
905 break;
906 case 'launchpad_screen':
907 $options[ $key ] = $site->get_launchpad_screen();
908 break;
909 case 'launchpad_checklist_tasks_statuses':
910 $options[ $key ] = $site->get_launchpad_checklist_tasks_statuses();
911 break;
912 case 'migration_source_site_domain':
913 $options[ $key ] = $site->get_migration_source_site_domain();
914 break;
915 case 'wpcom_production_blog_id':
916 $options[ $key ] = $site->get_wpcom_production_blog_id();
917 break;
918 case 'wpcom_staging_blog_ids':
919 $options[ $key ] = $site->get_wpcom_staging_blog_ids();
920 break;
921 case 'can_blaze':
922 $options[ $key ] = $site->can_blaze();
923 break;
924 case 'wpcom_site_setup':
925 $options[ $key ] = $site->get_wpcom_site_setup();
926 break;
927 case 'is_commercial':
928 $options[ $key ] = $site->is_commercial();
929 break;
930 case 'is_commercial_reasons':
931 $options[ $key ] = $site->get_is_commercial_reasons();
932 break;
933 case 'wpcom_admin_interface':
934 $options[ $key ] = $site->get_wpcom_admin_interface();
935 break;
936 case 'wpcom_classic_early_release':
937 $options[ $key ] = $site->get_wpcom_classic_early_release();
938 break;
939 }
940 }
941
942 return $options;
943 }
944
945 /**
946 * Build meta response.
947 *
948 * @param array $response - the response.
949 */
950 protected function build_meta_response( &$response ) {
951 $links = array(
952 'self' => (string) $this->links->get_site_link( $this->site->blog_id ),
953 'help' => (string) $this->links->get_site_link( $this->site->blog_id, 'help' ),
954 'posts' => (string) $this->links->get_site_link( $this->site->blog_id, 'posts/' ),
955 'comments' => (string) $this->links->get_site_link( $this->site->blog_id, 'comments/' ),
956 'xmlrpc' => (string) $this->site->get_xmlrpc_url(),
957 );
958
959 $icon = $this->site->get_icon();
960 if ( ! empty( $icon ) && ! empty( $icon['media_id'] ) ) {
961 $links['site_icon'] = (string) $this->links->get_site_link( $this->site->blog_id, 'media/' . $icon['media_id'] );
962 }
963
964 $response['meta'] = (object) array(
965 'links' => (object) $links,
966 );
967 }
968
969 /**
970 * Apply any WPCOM-only response components to a Jetpack site response.
971 *
972 * @param array $response - the response.
973 */
974 public function decorate_jetpack_response( &$response ) {
975 $this->site = $this->get_platform()->get_site( $response->ID );
976 switch_to_blog( $this->site->get_id() );
977
978 $wpcom_response = $this->render_response_keys( self::$jetpack_response_field_additions );
979
980 foreach ( $wpcom_response as $key => $value ) {
981 $response->{ $key } = $value;
982 }
983
984 if ( $this->has_user_access() || $this->has_blog_access( $this->api->token_details ) ) {
985 $wpcom_member_response = $this->render_response_keys( self::$jetpack_response_field_member_additions );
986
987 foreach ( $wpcom_member_response as $key => $value ) {
988 $response->{ $key } = $value;
989 }
990 } else {
991 // ensure private data is not rendered for non members of the site.
992 unset( $response->options );
993 unset( $response->is_vip );
994 unset( $response->single_user_site );
995 unset( $response->is_private );
996 unset( $response->is_coming_soon );
997 unset( $response->capabilities );
998 unset( $response->lang );
999 unset( $response->user_can_manage );
1000 unset( $response->is_multisite );
1001 unset( $response->site_owner );
1002 unset( $response->plan );
1003 unset( $response->products );
1004 unset( $response->zendesk_site_meta );
1005 }
1006
1007 // render additional options.
1008 if ( isset( $response->options ) && $response->options ) {
1009 $wpcom_options_response = $this->render_option_keys( self::$jetpack_response_option_additions );
1010
1011 // Remove heic from jetpack (and atomic) sites so that the iOS app know to convert the file format into a JPEG.
1012 // heic fromat is currently not supported by for uploading.
1013 // See https://jetpackp2.wordpress.com/2020/08/19/image-uploads-in-the-wp-ios-app-broken
1014 if ( $this->site->is_jetpack() && isset( $response->options['allowed_file_types'] ) ) {
1015 $remove_file_types = array(
1016 'heic',
1017 );
1018 $response->options['allowed_file_types'] = array_values( array_diff( $response->options['allowed_file_types'], $remove_file_types ) );
1019 }
1020
1021 foreach ( $wpcom_options_response as $key => $value ) {
1022 $response->options[ $key ] = $value;
1023 }
1024 }
1025
1026 restore_current_blog();
1027 return $response; // possibly no need since it's modified in place.
1028 }
1029 }
1030
1031 new WPCOM_JSON_API_List_Post_Formats_Endpoint(
1032 array(
1033 'description' => 'Get a list of post formats supported by a site.',
1034 'group' => '__do_not_document',
1035 'stat' => 'sites:X:post-formats',
1036
1037 'method' => 'GET',
1038 'path' => '/sites/%s/post-formats',
1039 'path_labels' => array(
1040 '$site' => '(int|string) Site ID or domain',
1041 ),
1042
1043 'query_parameters' => array(
1044 'context' => false,
1045 ),
1046
1047 'allow_fallback_to_jetpack_blog_token' => true,
1048
1049 'response_format' => array(
1050 'formats' => '(object) An object of supported post formats, each key a supported format slug mapped to its display string.',
1051 ),
1052 )
1053 );
1054
1055 /**
1056 * List Post Formates endpoint class.
1057 */
1058 class WPCOM_JSON_API_List_Post_Formats_Endpoint extends WPCOM_JSON_API_Endpoint { // phpcs:ignore
1059 /**
1060 *
1061 * API callback.
1062 *
1063 * /sites/%s/post-formats -> $blog_id
1064 *
1065 * @param string $path - the path.
1066 * @param int $blog_id - the blog ID.
1067 */
1068 public function callback( $path = '', $blog_id = 0 ) {
1069 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
1070 if ( is_wp_error( $blog_id ) ) {
1071 return $blog_id;
1072 }
1073
1074 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
1075 $this->load_theme_functions();
1076 }
1077
1078 // Get a list of supported post formats.
1079 $all_formats = get_post_format_strings();
1080 $supported = get_theme_support( 'post-formats' );
1081
1082 $response = array(
1083 'formats' => array(),
1084 );
1085 $supported_formats = $response['formats'];
1086
1087 if ( isset( $supported[0] ) ) {
1088 foreach ( $supported[0] as $format ) {
1089 $supported_formats[ $format ] = $all_formats[ $format ];
1090 }
1091 }
1092
1093 $response['formats'] = (object) $supported_formats;
1094
1095 return $response;
1096 }
1097 }
1098
1099 new WPCOM_JSON_API_List_Page_Templates_Endpoint(
1100 array(
1101 'description' => 'Get a list of page templates supported by a site.',
1102 'group' => 'sites',
1103 'stat' => 'sites:X:post-templates',
1104
1105 'method' => 'GET',
1106 'path' => '/sites/%s/page-templates',
1107 'path_labels' => array(
1108 '$site' => '(int|string) Site ID or domain',
1109 ),
1110 'query_parameters' => array(
1111 'context' => false,
1112 ),
1113 'response_format' => array(
1114 'templates' => '(array) A list of supported page templates. Contains label and file.',
1115 ),
1116 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/33534099/page-templates',
1117 )
1118 );
1119
1120 /**
1121 * List page templates endpoint class.
1122 */
1123 class WPCOM_JSON_API_List_Page_Templates_Endpoint extends WPCOM_JSON_API_Endpoint { // phpcs:ignore
1124 /**
1125 *
1126 * API callback.
1127 * /sites/%s/page-templates -> $blog_id
1128 *
1129 * @param string $path - the path.
1130 * @param int $blog_id - the blog ID.
1131 */
1132 public function callback( $path = '', $blog_id = 0 ) {
1133 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
1134 if ( is_wp_error( $blog_id ) ) {
1135 return $blog_id;
1136 }
1137
1138 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
1139 $this->load_theme_functions();
1140 }
1141
1142 $response = array();
1143 $page_templates = array();
1144
1145 $templates = get_page_templates();
1146 ksort( $templates );
1147
1148 foreach ( array_keys( $templates ) as $label ) {
1149 $page_templates[] = array(
1150 'label' => $label,
1151 'file' => $templates[ $label ],
1152 );
1153 }
1154
1155 $response['templates'] = $page_templates;
1156
1157 return $response;
1158 }
1159 }
1160