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