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