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