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