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