2022-04-02 10:26:41 +02:00
< ? php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2025-08-27 08:44:30 +02:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ( 0 );
}
2022-04-02 10:26:41 +02:00
new WPCOM_JSON_API_GET_Site_Endpoint (
array (
'description' => 'Get information about a site.' ,
'group' => 'sites' ,
'stat' => 'sites:X' ,
'allowed_if_flagged' => true ,
'method' => 'GET' ,
'max_version' => '1.1' ,
'new_version' => '1.2' ,
'path' => '/sites/%s' ,
'path_labels' => array (
'$site' => '(int|string) Site ID or domain' ,
),
2025-04-25 12:30:07 +02:00
'rest_route' => '/site' ,
'rest_min_jp_version' => '14.5-a.2' ,
2022-04-02 10:26:41 +02:00
'allow_jetpack_site_auth' => true ,
'allow_fallback_to_jetpack_blog_token' => true ,
'query_parameters' => array (
'context' => false ,
'options' => '(string) Optional. Returns specified options only. Comma-separated list. Example: options=login_url,timezone' ,
),
'response_format' => WPCOM_JSON_API_GET_Site_Endpoint :: $site_format ,
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/' ,
)
);
2019-11-15 23:26:29 +01:00
2022-04-02 10:26:41 +02:00
/**
* GET Site endpoint class .
2025-08-27 08:44:30 +02:00
*
* @ phan - constructor - used - for - side - effects
2022-04-02 10:26:41 +02:00
*/
2019-11-15 23:26:29 +01:00
class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
2022-04-02 10:26:41 +02:00
/**
* Site meta data .
*
* @ var array $site_format
*/
2019-11-15 23:26:29 +01:00
public static $site_format = array (
2020-09-15 14:30:05 +02:00
'ID' => '(int) Site ID' ,
2025-05-07 06:48:41 +02:00
'slug' => '(string) Slug of site' ,
2020-09-15 14:30:05 +02:00
'name' => '(string) Title of site' ,
'description' => '(string) Tagline or description of site' ,
'URL' => '(string) Full URL to the site' ,
'user_can_manage' => '(bool) The current user can manage this site' , // deprecated.
'capabilities' => '(array) Array of capabilities for the current user on this site.' ,
'jetpack' => '(bool) Whether the site is a Jetpack site or not' ,
'jetpack_connection' => '(bool) Whether the site is connected to WP.com via `jetpack-connection`' ,
'is_multisite' => '(bool) Whether the site is a Multisite site or not. Always true for WP.com sites.' ,
2022-04-02 10:26:41 +02:00
'site_owner' => '(int) User ID of the site owner' ,
2020-09-15 14:30:05 +02:00
'post_count' => '(int) The number of posts the site has' ,
'subscribers_count' => '(int) The number of subscribers the site has' ,
'lang' => '(string) Primary language code of the site' ,
'icon' => '(array) An array of icon formats for the site' ,
'logo' => '(array) The site logo, set in the Customizer' ,
'visible' => '(bool) If this site is visible in the user\'s site list' ,
'is_private' => '(bool) If the site is a private site or not' ,
'is_coming_soon' => '(bool) If the site is marked as "coming soon" or not' ,
'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.' ,
'is_vip' => '(bool) If the site is a VIP site or not.' ,
'is_following' => '(bool) If the current user is subscribed to this site in the reader' ,
2021-04-27 08:32:47 +02:00
'organization_id' => '(int) P2 Organization identifier.' ,
2020-09-15 14:30:05 +02:00
'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/' ,
2022-12-15 17:41:53 +01:00
'p2_thumbnail_elements' => '(array) Details used to render a thumbnail of the site. P2020 themed sites only.' ,
2020-09-15 14:30:05 +02:00
'plan' => '(array) Details of the current plan for this site.' ,
2022-12-15 17:41:53 +01:00
'products' => '(array) Details of the current products for this site.' ,
'zendesk_site_meta' => '(array) Site meta data for Zendesk.' ,
2020-09-15 14:30:05 +02:00
'updates' => '(array) An array of available updates for plugins, themes, wordpress, and languages.' ,
'jetpack_modules' => '(array) A list of active Jetpack modules.' ,
'meta' => '(object) Meta data' ,
'quota' => '(array) An array describing how much space a user has left for uploads' ,
'launch_status' => '(string) A string describing the launch status of a site' ,
'site_migration' => '(array) Data about any migration into the site.' ,
'is_fse_active' => '(bool) If the site has Full Site Editing active or not.' ,
'is_fse_eligible' => '(bool) If the site is capable of Full Site Editing or not' ,
'is_core_site_editor_enabled' => '(bool) If the site has the core site editor enabled.' ,
2021-07-23 11:58:50 +02:00
'is_wpcom_atomic' => '(bool) If the site is a WP.com Atomic one.' ,
2023-04-26 17:39:43 +02:00
'is_wpcom_staging_site' => '(bool) If the site is a WP.com staging site.' ,
2022-12-15 17:41:53 +01:00
'user_interactions' => '(array) An array of user interactions with a site.' ,
2023-04-26 17:39:43 +02:00
'was_ecommerce_trial' => '(bool) If the site ever used an eCommerce trial.' ,
2024-02-16 11:03:01 +01:00
'was_upgraded_from_trial' => '(bool) If the site ever upgraded to a paid plan from a trial.' ,
2023-09-26 10:24:36 +02:00
'was_migration_trial' => '(bool) If the site ever used a migration trial.' ,
2023-12-07 09:44:11 +01:00
'was_hosting_trial' => '(bool) If the site ever used a hosting trial.' ,
2023-09-26 10:24:36 +02:00
'wpcom_site_setup' => '(string) The WP.com site setup identifier.' ,
2025-02-28 08:42:11 +01:00
'is_deleted' => '(bool) If the site flagged as deleted.' ,
'is_a4a_client' => '(bool) If the site is an A4A client site.' ,
'is_a4a_dev_site' => '(bool) If the site is an A4A dev site.' ,
2025-12-12 13:13:07 +01:00
'is_garden' => '(bool) If the site is a Garden site.' ,
'garden_name' => '(string) The name of the Garden site.' ,
'garden_partner' => '(string) The partner of the Garden site.' ,
'garden_is_provisioned' => '(bool) If the Garden site is provisioned.' ,
'is_wpcom_flex' => '(bool) If the site is a Flex site' ,
2019-11-15 23:26:29 +01:00
);
2022-04-02 10:26:41 +02:00
/**
* No member fields .
*
* @ var array $no_member_fields
*/
2019-11-15 23:26:29 +01:00
protected static $no_member_fields = array (
'ID' ,
'name' ,
'description' ,
'URL' ,
'jetpack' ,
2020-09-15 14:30:05 +02:00
'jetpack_connection' ,
2019-11-15 23:26:29 +01:00
'post_count' ,
'subscribers_count' ,
'lang' ,
'locale' ,
'icon' ,
'logo' ,
'visible' ,
'is_private' ,
2020-03-03 18:49:45 +01:00
'is_coming_soon' ,
2019-11-15 23:26:29 +01:00
'is_following' ,
2022-12-15 17:41:53 +01:00
'organization_id' ,
2019-11-15 23:26:29 +01:00
'meta' ,
'launch_status' ,
2020-03-03 18:49:45 +01:00
'site_migration' ,
2019-11-15 23:26:29 +01:00
'is_fse_active' ,
2020-01-26 12:53:20 +01:00
'is_fse_eligible' ,
2020-05-06 17:20:49 +02:00
'is_core_site_editor_enabled' ,
2021-07-23 11:58:50 +02:00
'is_wpcom_atomic' ,
2023-04-26 17:39:43 +02:00
'is_wpcom_staging_site' ,
2025-02-28 08:42:11 +01:00
'is_deleted' ,
2025-12-12 13:13:07 +01:00
'is_wpcom_flex' ,
2025-02-28 08:42:11 +01:00
'is_a4a_client' ,
'is_a4a_dev_site' ,
2019-11-15 23:26:29 +01:00
);
2022-04-02 10:26:41 +02:00
/**
* Site options .
*
* @ var array $site_options_format
*/
2019-11-15 23:26:29 +01:00
protected static $site_options_format = array (
'timezone' ,
'gmt_offset' ,
'blog_public' ,
'videopress_enabled' ,
'upgraded_filetypes_enabled' ,
'login_url' ,
'admin_url' ,
'is_mapped_domain' ,
'is_redirect' ,
'unmapped_url' ,
'featured_images_enabled' ,
'theme_slug' ,
2025-02-28 08:42:11 +01:00
'theme_errors' ,
2019-11-15 23:26:29 +01:00
'header_image' ,
'background_color' ,
'image_default_link_type' ,
'image_thumbnail_width' ,
'image_thumbnail_height' ,
'image_thumbnail_crop' ,
'image_medium_width' ,
'image_medium_height' ,
'image_large_width' ,
'image_large_height' ,
'permalink_structure' ,
'post_formats' ,
'default_post_format' ,
'default_category' ,
'allowed_file_types' ,
'show_on_front' ,
/** This filter is documented in modules/likes.php */
'default_likes_enabled' ,
'default_sharing_status' ,
'default_comment_status' ,
'default_ping_status' ,
'software_version' ,
'created_at' ,
2022-12-15 17:41:53 +01:00
'updated_at' ,
2019-11-15 23:26:29 +01:00
'wordads' ,
'publicize_permanently_disabled' ,
'frame_nonce' ,
'jetpack_frame_nonce' ,
'page_on_front' ,
'page_for_posts' ,
'headstart' ,
'headstart_is_fresh' ,
'ak_vp_bundle_enabled' ,
Jetpack_SEO_Utils :: FRONT_PAGE_META_OPTION ,
Jetpack_SEO_Titles :: TITLE_FORMATS_OPTION ,
'verification_services_codes' ,
'podcasting_archive' ,
'is_domain_only' ,
'is_automated_transfer' ,
'is_wpcom_atomic' ,
'is_wpcom_store' ,
'signup_is_store' ,
'has_pending_automated_transfer' ,
'woocommerce_is_active' ,
2022-12-15 17:41:53 +01:00
'editing_toolkit_is_active' ,
2019-11-15 23:26:29 +01:00
'design_type' ,
'site_goals' ,
'site_segment' ,
2023-04-26 17:39:43 +02:00
'site_source_slug' ,
2019-11-15 23:26:29 +01:00
'import_engine' ,
2022-12-15 17:41:53 +01:00
'is_pending_plan' ,
2020-05-06 17:20:49 +02:00
'is_wpforteams_site' ,
2021-07-23 11:58:50 +02:00
'p2_hub_blog_id' ,
2020-05-06 17:20:49 +02:00
'site_creation_flow' ,
2020-09-15 14:30:05 +02:00
'is_cloud_eligible' ,
2020-10-20 18:05:12 +02:00
'selected_features' ,
2021-04-27 08:32:47 +02:00
'anchor_podcast' ,
2022-12-15 17:41:53 +01:00
'was_created_with_blank_canvas_design' ,
'videopress_storage_used' ,
2022-04-02 10:26:41 +02:00
'is_difm_lite_in_progress' ,
2025-08-27 08:44:30 +02:00
'is_summer_special_2025' ,
2022-04-02 10:26:41 +02:00
'site_intent' ,
2025-02-28 08:42:11 +01:00
'site_partner_bundle' ,
'onboarding_segment' ,
2022-12-15 17:41:53 +01:00
'site_vertical_id' ,
'blogging_prompts_settings' ,
'launchpad_screen' ,
'launchpad_checklist_tasks_statuses' ,
2025-02-28 08:42:11 +01:00
'migration_source_site_domain' ,
2023-04-26 17:39:43 +02:00
'wpcom_production_blog_id' ,
'wpcom_staging_blog_ids' ,
'can_blaze' ,
2023-09-26 10:24:36 +02:00
'wpcom_site_setup' ,
'is_commercial' ,
2024-04-17 11:32:24 +02:00
'is_commercial_reasons' ,
2023-12-07 09:44:11 +01:00
'wpcom_admin_interface' ,
2024-04-17 11:32:24 +02:00
'wpcom_classic_early_release' ,
2022-12-15 17:41:53 +01:00
);
2022-04-02 10:26:41 +02:00
/**
* Jetpack response fields .
*
* @ var array $jetpack_response_field_additions
*/
2019-11-15 23:26:29 +01:00
protected static $jetpack_response_field_additions = array (
2025-05-07 06:48:41 +02:00
'slug' ,
2019-11-15 23:26:29 +01:00
'subscribers_count' ,
2020-03-03 18:49:45 +01:00
'site_migration' ,
2022-12-15 17:41:53 +01:00
'site_owner' ,
2023-04-26 17:39:43 +02:00
'is_wpcom_staging_site' ,
'was_ecommerce_trial' ,
2023-09-26 10:24:36 +02:00
'was_migration_trial' ,
2023-12-07 09:44:11 +01:00
'was_hosting_trial' ,
2024-02-16 11:03:01 +01:00
'was_upgraded_from_trial' ,
2025-02-28 08:42:11 +01:00
'is_a4a_dev_site' ,
2025-12-12 13:13:07 +01:00
'is_garden' ,
'garden_name' ,
'garden_partner' ,
'garden_is_provisioned' ,
'is_wpcom_flex' ,
2019-11-15 23:26:29 +01:00
);
2022-04-02 10:26:41 +02:00
/**
* Jetpack response field member additions .
*
* @ var array $jetpack_response_field_member_additions
*/
2019-11-15 23:26:29 +01:00
protected static $jetpack_response_field_member_additions = array (
'capabilities' ,
'plan' ,
2020-09-15 14:30:05 +02:00
'products' ,
2021-08-17 08:33:07 +02:00
'zendesk_site_meta' ,
2019-11-15 23:26:29 +01:00
);
2022-04-02 10:26:41 +02:00
/**
* Jetpack response option additions .
*
2025-12-12 13:13:07 +01:00
* @ var array $jetpack_response_option_additions
2022-04-02 10:26:41 +02:00
*/
2019-11-15 23:26:29 +01:00
protected static $jetpack_response_option_additions = array (
'publicize_permanently_disabled' ,
'ak_vp_bundle_enabled' ,
'is_automated_transfer' ,
'is_wpcom_atomic' ,
'is_wpcom_store' ,
'woocommerce_is_active' ,
2022-12-15 17:41:53 +01:00
'editing_toolkit_is_active' ,
2019-11-15 23:26:29 +01:00
'frame_nonce' ,
'jetpack_frame_nonce' ,
'design_type' ,
'wordads' ,
// Use the site registered date from wpcom, since it is only available in a multisite context
// and defaults to `0000-00-00T00:00:00+00:00` from the Jetpack site.
// See https://github.com/Automattic/jetpack/blob/58638f46094b36f5df9cbc4570006544f0ad300c/sal/class.json-api-site-base.php#L387.
'created_at' ,
2022-12-15 17:41:53 +01:00
'updated_at' ,
'is_pending_plan' ,
'is_cloud_eligible' ,
'videopress_storage_used' ,
'blogging_prompts_settings' ,
2023-05-23 23:18:12 +02:00
'wpcom_production_blog_id' ,
'wpcom_staging_blog_ids' ,
2023-09-26 10:24:36 +02:00
'is_commercial' ,
2024-04-17 11:32:24 +02:00
'is_commercial_reasons' ,
2023-12-07 09:44:11 +01:00
'wpcom_admin_interface' ,
2024-04-17 11:32:24 +02:00
'wpcom_classic_early_release' ,
2023-09-26 10:24:36 +02:00
);
/**
* Current enabled trials .
*
* @ var array $jetpack_enabled_trials
*/
public static $jetpack_enabled_trials = array (
'was_ecommerce_trial' => 'ecommerce' ,
'was_migration_trial' => 'migration' ,
2023-12-07 09:44:11 +01:00
'was_hosting_trial' => 'hosting' ,
2019-11-15 23:26:29 +01:00
);
2022-04-02 10:26:41 +02:00
/**
2025-12-12 13:13:07 +01:00
* Site .
2022-04-02 10:26:41 +02:00
*
2025-02-28 08:42:11 +01:00
* @ var SAL_Site $site .
2022-04-02 10:26:41 +02:00
*/
2019-11-15 23:26:29 +01:00
private $site ;
2022-04-02 10:26:41 +02:00
/**
* Fields to include .
*
* @ var $fields_to_include
*/
2019-11-15 23:26:29 +01:00
protected $fields_to_include = '_all' ;
2022-04-02 10:26:41 +02:00
/**
* Options to include .
*
* @ var $options_to_include
*/
2019-11-15 23:26:29 +01:00
protected $options_to_include = '_all' ;
2022-04-02 10:26:41 +02:00
/**
*
* API callback .
*
* / sites / mine
* / sites /% s -> $blog_id\
*
2025-12-12 13:13:07 +01:00
* @ param string $path - the path .
* @ param int | string $blog_id - the blog ID or the string 'mine' .
*
* @ return array | \WP_Error Site response array on success , or WP_Error on failure .
2022-04-02 10:26:41 +02:00
*/
public function callback ( $path = '' , $blog_id = 0 ) {
2019-11-15 23:26:29 +01:00
if ( 'mine' === $blog_id ) {
$api = WPCOM_JSON_API :: init ();
if ( ! $api -> token_details || empty ( $api -> token_details [ 'blog_id' ] ) ) {
return new WP_Error ( 'authorization_required' , 'An active access token must be used to query information about the current blog.' , 403 );
}
$blog_id = $api -> token_details [ 'blog_id' ];
}
2022-12-15 17:41:53 +01:00
add_filter ( 'wpcom_allow_jetpack_blog_token' , '__return_true' );
2019-11-15 23:26:29 +01:00
$blog_id = $this -> api -> switch_to_blog_and_validate_user ( $this -> api -> get_blog_id ( $blog_id ) );
if ( is_wp_error ( $blog_id ) ) {
return $blog_id ;
}
$this -> filter_fields_and_options ();
$response = $this -> build_current_site_response ();
/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
do_action ( 'wpcom_json_api_objects' , 'sites' );
return $response ;
}
2022-04-02 10:26:41 +02:00
/**
* Filter fields and options .
*/
2019-11-15 23:26:29 +01:00
public function filter_fields_and_options () {
$query_args = $this -> query_args ();
$this -> fields_to_include = empty ( $query_args [ 'fields' ] ) ? '_all' : array_map ( 'trim' , explode ( ',' , $query_args [ 'fields' ] ) );
$this -> options_to_include = empty ( $query_args [ 'options' ] ) ? '_all' : array_map ( 'trim' , explode ( ',' , $query_args [ 'options' ] ) );
}
/**
* Collects the necessary information to return for a site ' s response .
*
* @ return array
*/
public function build_current_site_response () {
$blog_id = ( int ) $this -> api -> get_blog_id_for_output ();
$this -> site = $this -> get_platform () -> get_site ( $blog_id );
/**
2022-04-02 10:26:41 +02:00
* Filter the structure of information about the site to return .
*
* @ module json - api
*
* @ since 3.9 . 3
*
* @ param array $site_format Data structure .
*/
2019-11-15 23:26:29 +01:00
$default_fields = array_keys ( apply_filters ( 'sites_site_format' , self :: $site_format ) );
$response_keys = is_array ( $this -> fields_to_include ) ?
array_intersect ( $default_fields , $this -> fields_to_include ) :
$default_fields ;
2020-01-26 12:53:20 +01:00
$has_blog_access = $this -> has_blog_access ( $this -> api -> token_details );
$has_user_access = $this -> has_user_access ();
if ( ! $has_user_access && ! $has_blog_access ) {
// Public access without user or blog auth, only return `$no_member_fields`.
2019-11-15 23:26:29 +01:00
$response_keys = array_intersect ( $response_keys , self :: $no_member_fields );
2020-01-26 12:53:20 +01:00
} elseif ( $has_user_access && ! current_user_can ( 'edit_posts' ) ) {
// Subscriber level user, don't return site options.
$response_keys = array_diff ( $response_keys , array ( 'options' ) );
2019-11-15 23:26:29 +01:00
}
return $this -> render_response_keys ( $response_keys );
}
/**
2020-01-26 12:53:20 +01:00
* Checks that the current user has access to the current blog .
2019-11-15 23:26:29 +01:00
*
2020-01-26 12:53:20 +01:00
* @ return bool Whether or not the current user can access the current blog .
*/
private function has_user_access () {
return is_user_member_of_blog ( get_current_user_id (), get_current_blog_id () );
}
/**
* Checks if the request has a valid blog token for the current blog .
2019-11-15 23:26:29 +01:00
*
2020-01-26 12:53:20 +01:00
* @ param array $token_details Access token for the api request .
2019-11-15 23:26:29 +01:00
* @ return bool
*/
2020-01-26 12:53:20 +01:00
private function has_blog_access ( $token_details ) {
2019-11-15 23:26:29 +01:00
$token_details = ( array ) $token_details ;
2023-09-26 10:24:36 +02:00
if ( ! isset ( $token_details [ 'access' ] ) || ! isset ( $token_details [ 'auth' ] ) || ! isset ( $token_details [ 'blog_id' ] ) ) {
2019-11-15 23:26:29 +01:00
return false ;
}
2020-01-26 12:53:20 +01:00
return 'jetpack' === $token_details [ 'auth' ] &&
2019-11-15 23:26:29 +01:00
'blog' === $token_details [ 'access' ] &&
2020-01-26 12:53:20 +01:00
get_current_blog_id () === $token_details [ 'blog_id' ];
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Render response keys .
*
* @ param array $response_keys - the response keys .
*/
2019-11-15 23:26:29 +01:00
private function render_response_keys ( & $response_keys ) {
$response = array ();
$is_user_logged_in = is_user_logged_in ();
$this -> site -> before_render ();
foreach ( $response_keys as $key ) {
$this -> render_response_key ( $key , $response , $is_user_logged_in );
}
$this -> site -> after_render ( $response );
return $response ;
}
2022-04-02 10:26:41 +02:00
/**
* Render response key .
*
* @ param string $key - the key .
* @ param array $response - the response .
* @ param boolean $is_user_logged_in - if the user is logged in .
*/
2019-11-15 23:26:29 +01:00
protected function render_response_key ( $key , & $response , $is_user_logged_in ) {
do_action ( 'pre_render_site_response_key' , $key );
switch ( $key ) {
2022-04-02 10:26:41 +02:00
case 'ID' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> blog_id ;
break ;
2025-05-07 06:48:41 +02:00
case 'slug' :
$response [ $key ] = $this -> site -> get_slug ();
break ;
2022-04-02 10:26:41 +02:00
case 'name' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_name ();
break ;
2022-04-02 10:26:41 +02:00
case 'description' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_description ();
break ;
2022-04-02 10:26:41 +02:00
case 'URL' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_url ();
break ;
2022-04-02 10:26:41 +02:00
case 'user_can_manage' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> user_can_manage ();
2022-04-02 10:26:41 +02:00
// fall through is intentional.
case 'is_private' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> is_private ();
break ;
2022-04-02 10:26:41 +02:00
case 'is_coming_soon' :
// This option is stored on wp.com for both simple and atomic sites. @see mu-plugins/private-blog.php.
$response [ $key ] = $this -> site -> is_coming_soon ();
2020-05-06 17:20:49 +02:00
break ;
2022-04-02 10:26:41 +02:00
case 'launch_status' :
2020-05-06 17:20:49 +02:00
$response [ $key ] = $this -> site -> get_launch_status ();
2020-03-03 18:49:45 +01:00
break ;
2022-04-02 10:26:41 +02:00
case 'visible' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> is_visible ();
break ;
2022-04-02 10:26:41 +02:00
case 'subscribers_count' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_subscribers_count ();
break ;
2022-04-02 10:26:41 +02:00
case 'post_count' :
2019-11-15 23:26:29 +01:00
if ( $is_user_logged_in ) {
$response [ $key ] = $this -> site -> get_post_count ();
}
break ;
2022-04-02 10:26:41 +02:00
case 'icon' :
2019-11-15 23:26:29 +01:00
$icon = $this -> site -> get_icon ();
2022-06-16 14:01:47 +02:00
if ( $icon !== null ) {
2019-11-15 23:26:29 +01:00
$response [ $key ] = $icon ;
}
break ;
2022-04-02 10:26:41 +02:00
case 'logo' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_logo ();
break ;
case 'is_following' :
$response [ $key ] = $this -> site -> is_following ();
break ;
case 'options' :
2022-04-02 10:26:41 +02:00
// small optimisation - don't recalculate.
2019-11-15 23:26:29 +01:00
$all_options = apply_filters ( 'sites_site_options_format' , self :: $site_options_format );
$options_response_keys = is_array ( $this -> options_to_include ) ?
array_intersect ( $all_options , $this -> options_to_include ) :
$all_options ;
$options = $this -> render_option_keys ( $options_response_keys );
$this -> site -> after_render_options ( $options );
$response [ $key ] = ( object ) $options ;
break ;
case 'meta' :
$this -> build_meta_response ( $response );
break ;
2022-04-02 10:26:41 +02:00
case 'lang' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $is_user_logged_in ? $this -> site -> get_locale () : false ;
break ;
2022-04-02 10:26:41 +02:00
case 'locale' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $is_user_logged_in ? $this -> site -> get_locale () : false ;
break ;
2020-09-15 14:30:05 +02:00
case 'jetpack' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> is_jetpack ();
break ;
2020-09-15 14:30:05 +02:00
case 'jetpack_connection' :
$response [ $key ] = $this -> site -> is_jetpack_connection ();
break ;
2022-04-02 10:26:41 +02:00
case 'single_user_site' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> is_single_user_site ();
break ;
2022-04-02 10:26:41 +02:00
case 'is_vip' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> is_vip ();
break ;
2022-04-02 10:26:41 +02:00
case 'is_multisite' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> is_multisite ();
break ;
2022-04-02 10:26:41 +02:00
case 'site_owner' :
$response [ $key ] = $this -> site -> get_site_owner ();
break ;
2021-04-27 08:32:47 +02:00
case 'organization_id' :
$response [ $key ] = $this -> site -> get_p2_organization_id ();
break ;
2022-04-02 10:26:41 +02:00
case 'capabilities' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_capabilities ();
break ;
case 'jetpack_modules' :
if ( is_user_member_of_blog () ) {
$response [ $key ] = $this -> site -> get_jetpack_modules ();
}
break ;
2022-04-02 10:26:41 +02:00
case 'plan' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_plan ();
break ;
2022-04-02 10:26:41 +02:00
case 'products' :
2020-09-15 14:30:05 +02:00
$response [ $key ] = $this -> site -> get_products ();
break ;
2021-07-23 11:58:50 +02:00
case 'zendesk_site_meta' :
2025-02-28 08:42:11 +01:00
$response [ $key ] = $this -> site -> get_zendesk_site_meta ();
2021-07-23 11:58:50 +02:00
break ;
2022-04-02 10:26:41 +02:00
case 'quota' :
2019-11-15 23:26:29 +01:00
$response [ $key ] = $this -> site -> get_quota ();
break ;
2022-04-02 10:26:41 +02:00
case 'site_migration' :
2020-03-03 18:49:45 +01:00
$response [ $key ] = $this -> site -> get_migration_meta ();
2020-01-26 12:53:20 +01:00
break ;
2019-11-15 23:26:29 +01:00
case 'is_fse_active' :
$response [ $key ] = $this -> site -> is_fse_active ();
break ;
2020-01-26 12:53:20 +01:00
case 'is_fse_eligible' :
$response [ $key ] = $this -> site -> is_fse_eligible ();
break ;
2020-05-06 17:20:49 +02:00
case 'is_core_site_editor_enabled' :
$response [ $key ] = $this -> site -> is_core_site_editor_enabled ();
break ;
2021-07-23 11:58:50 +02:00
case 'is_wpcom_atomic' :
$response [ $key ] = $this -> site -> is_wpcom_atomic ();
break ;
2023-04-26 17:39:43 +02:00
case 'is_wpcom_staging_site' :
$response [ $key ] = $this -> site -> is_wpcom_staging_site ();
break ;
2022-12-15 17:41:53 +01:00
case 'user_interactions' :
$response [ $key ] = $this -> site -> get_user_interactions ();
break ;
case 'p2_thumbnail_elements' :
$response [ $key ] = $this -> site -> get_p2_thumbnail_elements ();
break ;
2023-04-26 17:39:43 +02:00
case 'was_ecommerce_trial' :
2023-09-26 10:24:36 +02:00
$response [ $key ] = $this -> site -> was_trial ( self :: $jetpack_enabled_trials [ 'was_ecommerce_trial' ] );
break ;
case 'was_migration_trial' :
$response [ $key ] = $this -> site -> was_trial ( self :: $jetpack_enabled_trials [ 'was_migration_trial' ] );
2023-04-26 17:39:43 +02:00
break ;
2023-12-07 09:44:11 +01:00
case 'was_hosting_trial' :
$response [ $key ] = $this -> site -> was_trial ( self :: $jetpack_enabled_trials [ 'was_hosting_trial' ] );
break ;
2024-02-16 11:03:01 +01:00
case 'was_upgraded_from_trial' :
$response [ $key ] = $this -> site -> was_upgraded_from_trial ();
break ;
2025-02-28 08:42:11 +01:00
case 'is_deleted' :
$response [ $key ] = $this -> site -> is_deleted ();
break ;
case 'is_a4a_client' :
$response [ $key ] = $this -> site -> is_a4a_client ();
break ;
case 'is_a4a_dev_site' :
$response [ $key ] = $this -> site -> is_a4a_dev_site ();
break ;
2025-12-12 13:13:07 +01:00
case 'is_garden' :
$response [ $key ] = $this -> site -> is_garden ();
break ;
case 'garden_name' :
$response [ $key ] = $this -> site -> garden_name ();
break ;
case 'garden_partner' :
$response [ $key ] = $this -> site -> garden_partner ();
break ;
case 'garden_is_provisioned' :
$response [ $key ] = $this -> site -> garden_is_provisioned ();
break ;
case 'is_wpcom_flex' :
$response [ $key ] = $this -> site -> is_wpcom_flex ();
break ;
2019-11-15 23:26:29 +01:00
}
do_action ( 'post_render_site_response_key' , $key );
}
2022-04-02 10:26:41 +02:00
/**
* Render option keys .
*
* @ param array $options_response_keys - the response keys .
*/
2019-11-15 23:26:29 +01:00
protected function render_option_keys ( & $options_response_keys ) {
$options = array ();
2022-04-02 10:26:41 +02:00
$site = $this -> site ;
2019-11-15 23:26:29 +01:00
$custom_front_page = $site -> is_custom_front_page ();
foreach ( $options_response_keys as $key ) {
switch ( $key ) {
2022-04-02 10:26:41 +02:00
case 'timezone' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_timezone ();
break ;
2022-04-02 10:26:41 +02:00
case 'gmt_offset' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_gmt_offset ();
break ;
2022-04-02 10:26:41 +02:00
case 'videopress_enabled' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> has_videopress ();
break ;
2022-04-02 10:26:41 +02:00
case 'upgraded_filetypes_enabled' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> upgraded_filetypes_enabled ();
break ;
2022-04-02 10:26:41 +02:00
case 'login_url' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_login_url ();
break ;
2022-04-02 10:26:41 +02:00
case 'admin_url' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_admin_url ();
break ;
2022-04-02 10:26:41 +02:00
case 'is_mapped_domain' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> is_mapped_domain ();
break ;
2022-04-02 10:26:41 +02:00
case 'is_redirect' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> is_redirect ();
break ;
2022-04-02 10:26:41 +02:00
case 'unmapped_url' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_unmapped_url ();
break ;
2022-04-02 10:26:41 +02:00
case 'featured_images_enabled' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> featured_images_enabled ();
break ;
2022-04-02 10:26:41 +02:00
case 'theme_slug' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_theme_slug ();
break ;
2025-02-28 08:42:11 +01:00
case 'theme_errors' :
$options [ $key ] = $site -> get_theme_errors ();
break ;
2022-04-02 10:26:41 +02:00
case 'header_image' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_header_image ();
break ;
2022-04-02 10:26:41 +02:00
case 'background_color' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_background_color ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_default_link_type' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_default_link_type ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_thumbnail_width' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_thumbnail_width ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_thumbnail_height' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_thumbnail_height ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_thumbnail_crop' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_thumbnail_crop ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_medium_width' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_medium_width ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_medium_height' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_medium_height ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_large_width' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_large_width ();
break ;
2022-04-02 10:26:41 +02:00
case 'image_large_height' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_image_large_height ();
break ;
2022-04-02 10:26:41 +02:00
case 'permalink_structure' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_permalink_structure ();
break ;
2022-04-02 10:26:41 +02:00
case 'post_formats' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_post_formats ();
break ;
2022-04-02 10:26:41 +02:00
case 'default_post_format' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_default_post_format ();
break ;
2022-04-02 10:26:41 +02:00
case 'default_category' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_default_category ();
break ;
2022-04-02 10:26:41 +02:00
case 'allowed_file_types' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> allowed_file_types ();
break ;
2022-04-02 10:26:41 +02:00
case 'show_on_front' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_show_on_front ();
break ;
/** This filter is documented in modules/likes.php */
2022-04-02 10:26:41 +02:00
case 'default_likes_enabled' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_default_likes_enabled ();
break ;
2022-04-02 10:26:41 +02:00
case 'default_sharing_status' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_default_sharing_status ();
break ;
2022-04-02 10:26:41 +02:00
case 'default_comment_status' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_default_comment_status ();
break ;
2022-04-02 10:26:41 +02:00
case 'default_ping_status' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> default_ping_status ();
break ;
2022-04-02 10:26:41 +02:00
case 'software_version' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_wordpress_version ();
break ;
2022-04-02 10:26:41 +02:00
case 'created_at' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_registered_date ();
break ;
2022-12-15 17:41:53 +01:00
case 'updated_at' :
$options [ $key ] = $site -> get_last_update_date ();
break ;
2022-04-02 10:26:41 +02:00
case 'wordads' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> has_wordads ();
break ;
2022-04-02 10:26:41 +02:00
case 'publicize_permanently_disabled' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> is_publicize_permanently_disabled ();
break ;
2022-04-02 10:26:41 +02:00
case 'frame_nonce' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_frame_nonce ();
break ;
2022-04-02 10:26:41 +02:00
case 'jetpack_frame_nonce' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_jetpack_frame_nonce ();
break ;
2022-04-02 10:26:41 +02:00
case 'page_on_front' :
2019-11-15 23:26:29 +01:00
if ( $custom_front_page ) {
$options [ $key ] = $site -> get_page_on_front ();
}
break ;
2022-04-02 10:26:41 +02:00
case 'page_for_posts' :
2019-11-15 23:26:29 +01:00
if ( $custom_front_page ) {
$options [ $key ] = $site -> get_page_for_posts ();
}
break ;
2022-04-02 10:26:41 +02:00
case 'headstart' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> is_headstart ();
break ;
2022-04-02 10:26:41 +02:00
case 'headstart_is_fresh' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> is_headstart_fresh ();
break ;
2022-04-02 10:26:41 +02:00
case 'ak_vp_bundle_enabled' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_ak_vp_bundle_enabled ();
break ;
2022-04-02 10:26:41 +02:00
case Jetpack_SEO_Utils :: FRONT_PAGE_META_OPTION :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_jetpack_seo_front_page_description ();
break ;
2022-04-02 10:26:41 +02:00
case Jetpack_SEO_Titles :: TITLE_FORMATS_OPTION :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_jetpack_seo_title_formats ();
break ;
2022-04-02 10:26:41 +02:00
case 'verification_services_codes' :
2019-11-15 23:26:29 +01:00
$options [ $key ] = $site -> get_verification_services_codes ();
break ;
case 'podcasting_archive' :
$options [ $key ] = $site -> get_podcasting_archive ();
break ;
case 'is_domain_only' :
$options [ $key ] = $site -> is_domain_only ();
break ;
case 'is_automated_transfer' :
$options [ $key ] = $site -> is_automated_transfer ();
break ;
case 'blog_public' :
$options [ $key ] = $site -> get_blog_public ();
break ;
case 'is_wpcom_atomic' :
$options [ $key ] = $site -> is_wpcom_atomic ();
break ;
case 'is_wpcom_store' :
$options [ $key ] = $site -> is_wpcom_store ();
break ;
case 'signup_is_store' :
$signup_is_store = $site -> signup_is_store ();
if ( $signup_is_store ) {
$options [ $key ] = $site -> signup_is_store ();
}
break ;
case 'has_pending_automated_transfer' :
$has_pending_automated_transfer = $site -> has_pending_automated_transfer ();
if ( $has_pending_automated_transfer ) {
$options [ $key ] = true ;
}
break ;
case 'woocommerce_is_active' :
$options [ $key ] = $site -> woocommerce_is_active ();
break ;
2022-12-15 17:41:53 +01:00
case 'editing_toolkit_is_active' :
$options [ $key ] = $site -> editing_toolkit_is_active ();
break ;
2019-11-15 23:26:29 +01:00
case 'design_type' :
$options [ $key ] = $site -> get_design_type ();
break ;
case 'site_segment' :
$options [ $key ] = $site -> get_site_segment ();
break ;
case 'import_engine' :
$options [ $key ] = $site -> get_import_engine ();
break ;
2022-12-15 17:41:53 +01:00
case 'is_pending_plan' :
2025-02-28 08:42:11 +01:00
$options [ $key ] = $site -> is_pending_plan ();
2022-12-15 17:41:53 +01:00
break ;
2020-05-06 17:20:49 +02:00
case 'is_wpforteams_site' :
$options [ $key ] = $site -> is_wpforteams_site ();
break ;
2021-07-23 11:58:50 +02:00
case 'p2_hub_blog_id' :
$options [ $key ] = $site -> get_p2_hub_blog_id ();
break ;
2020-05-06 17:20:49 +02:00
case 'site_creation_flow' :
$site_creation_flow = $site -> get_site_creation_flow ();
if ( $site_creation_flow ) {
$options [ $key ] = $site_creation_flow ;
}
break ;
2023-04-26 17:39:43 +02:00
case 'site_source_slug' :
$site_source_slug = $site -> get_site_source_slug ();
if ( $site_source_slug ) {
$options [ $key ] = $site_source_slug ;
}
break ;
2020-09-15 14:30:05 +02:00
case 'is_cloud_eligible' :
$options [ $key ] = $site -> is_cloud_eligible ();
break ;
2020-10-20 18:05:12 +02:00
case 'selected_features' :
$selected_features = $site -> get_selected_features ();
if ( $selected_features ) {
$options [ $key ] = $selected_features ;
}
break ;
2021-04-27 08:32:47 +02:00
case 'anchor_podcast' :
$options [ $key ] = $site -> get_anchor_podcast ();
break ;
2022-12-15 17:41:53 +01:00
case 'was_created_with_blank_canvas_design' :
$options [ $key ] = $site -> was_created_with_blank_canvas_design ();
break ;
case 'videopress_storage_used' :
$options [ $key ] = $this -> site -> get_videopress_storage_used ();
break ;
2022-04-02 10:26:41 +02:00
case 'is_difm_lite_in_progress' :
$options [ $key ] = $site -> is_difm_lite_in_progress ();
break ;
2025-08-27 08:44:30 +02:00
case 'is_summer_special_2025' :
$options [ $key ] = $site -> is_summer_special_2025 ();
break ;
2022-04-02 10:26:41 +02:00
case 'site_intent' :
$options [ $key ] = $site -> get_site_intent ();
break ;
2025-02-28 08:42:11 +01:00
case 'site_partner_bundle' :
$options [ $key ] = $site -> get_site_partner_bundle ();
break ;
case 'site_goals' :
$options [ $key ] = $site -> get_site_goals ();
break ;
case 'onboarding_segment' :
$options [ $key ] = $site -> get_onboarding_segment ();
break ;
2022-12-15 17:41:53 +01:00
case 'site_vertical_id' :
$options [ $key ] = $site -> get_site_vertical_id ();
break ;
case 'blogging_prompts_settings' :
if ( current_user_can ( 'edit_posts' ) ) {
$options [ $key ] = $site -> get_blogging_prompts_settings ( get_current_user_id (), $site -> blog_id );
}
break ;
case 'launchpad_screen' :
$options [ $key ] = $site -> get_launchpad_screen ();
break ;
case 'launchpad_checklist_tasks_statuses' :
$options [ $key ] = $site -> get_launchpad_checklist_tasks_statuses ();
break ;
2025-02-28 08:42:11 +01:00
case 'migration_source_site_domain' :
$options [ $key ] = $site -> get_migration_source_site_domain ();
break ;
2023-04-26 17:39:43 +02:00
case 'wpcom_production_blog_id' :
$options [ $key ] = $site -> get_wpcom_production_blog_id ();
break ;
case 'wpcom_staging_blog_ids' :
$options [ $key ] = $site -> get_wpcom_staging_blog_ids ();
break ;
case 'can_blaze' :
$options [ $key ] = $site -> can_blaze ();
break ;
2023-09-26 10:24:36 +02:00
case 'wpcom_site_setup' :
$options [ $key ] = $site -> get_wpcom_site_setup ();
break ;
case 'is_commercial' :
$options [ $key ] = $site -> is_commercial ();
break ;
2024-04-17 11:32:24 +02:00
case 'is_commercial_reasons' :
$options [ $key ] = $site -> get_is_commercial_reasons ();
break ;
2023-12-07 09:44:11 +01:00
case 'wpcom_admin_interface' :
$options [ $key ] = $site -> get_wpcom_admin_interface ();
break ;
2024-04-17 11:32:24 +02:00
case 'wpcom_classic_early_release' :
$options [ $key ] = $site -> get_wpcom_classic_early_release ();
break ;
2019-11-15 23:26:29 +01:00
}
}
return $options ;
}
2022-04-02 10:26:41 +02:00
/**
* Build meta response .
*
* @ param array $response - the response .
*/
2019-11-15 23:26:29 +01:00
protected function build_meta_response ( & $response ) {
$links = array (
'self' => ( string ) $this -> links -> get_site_link ( $this -> site -> blog_id ),
2022-04-02 10:26:41 +02:00
'help' => ( string ) $this -> links -> get_site_link ( $this -> site -> blog_id , 'help' ),
'posts' => ( string ) $this -> links -> get_site_link ( $this -> site -> blog_id , 'posts/' ),
2019-11-15 23:26:29 +01:00
'comments' => ( string ) $this -> links -> get_site_link ( $this -> site -> blog_id , 'comments/' ),
'xmlrpc' => ( string ) $this -> site -> get_xmlrpc_url (),
);
$icon = $this -> site -> get_icon ();
if ( ! empty ( $icon ) && ! empty ( $icon [ 'media_id' ] ) ) {
$links [ 'site_icon' ] = ( string ) $this -> links -> get_site_link ( $this -> site -> blog_id , 'media/' . $icon [ 'media_id' ] );
}
$response [ 'meta' ] = ( object ) array (
2022-04-02 10:26:41 +02:00
'links' => ( object ) $links ,
2019-11-15 23:26:29 +01:00
);
}
2022-04-02 10:26:41 +02:00
/**
* Apply any WPCOM - only response components to a Jetpack site response .
*
* @ param array $response - the response .
*/
2019-11-15 23:26:29 +01:00
public function decorate_jetpack_response ( & $response ) {
$this -> site = $this -> get_platform () -> get_site ( $response -> ID );
switch_to_blog ( $this -> site -> get_id () );
$wpcom_response = $this -> render_response_keys ( self :: $jetpack_response_field_additions );
2022-04-02 10:26:41 +02:00
foreach ( $wpcom_response as $key => $value ) {
2019-11-15 23:26:29 +01:00
$response -> { $key } = $value ;
}
2020-01-26 12:53:20 +01:00
if ( $this -> has_user_access () || $this -> has_blog_access ( $this -> api -> token_details ) ) {
2019-11-15 23:26:29 +01:00
$wpcom_member_response = $this -> render_response_keys ( self :: $jetpack_response_field_member_additions );
2022-04-02 10:26:41 +02:00
foreach ( $wpcom_member_response as $key => $value ) {
2019-11-15 23:26:29 +01:00
$response -> { $key } = $value ;
}
} else {
2022-04-02 10:26:41 +02:00
// ensure private data is not rendered for non members of the site.
2019-11-15 23:26:29 +01:00
unset ( $response -> options );
unset ( $response -> is_vip );
unset ( $response -> single_user_site );
unset ( $response -> is_private );
2020-03-03 18:49:45 +01:00
unset ( $response -> is_coming_soon );
2019-11-15 23:26:29 +01:00
unset ( $response -> capabilities );
unset ( $response -> lang );
unset ( $response -> user_can_manage );
unset ( $response -> is_multisite );
2022-04-02 10:26:41 +02:00
unset ( $response -> site_owner );
2019-11-15 23:26:29 +01:00
unset ( $response -> plan );
2020-09-15 14:30:05 +02:00
unset ( $response -> products );
2021-08-17 08:33:07 +02:00
unset ( $response -> zendesk_site_meta );
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
// render additional options.
2024-04-17 11:32:24 +02:00
if ( isset ( $response -> options ) && $response -> options ) {
2019-11-15 23:26:29 +01:00
$wpcom_options_response = $this -> render_option_keys ( self :: $jetpack_response_option_additions );
2022-12-15 17:41:53 +01:00
// Remove heic from jetpack (and atomic) sites so that the iOS app know to convert the file format into a JPEG.
// heic fromat is currently not supported by for uploading.
// See https://jetpackp2.wordpress.com/2020/08/19/image-uploads-in-the-wp-ios-app-broken
if ( $this -> site -> is_jetpack () && isset ( $response -> options [ 'allowed_file_types' ] ) ) {
$remove_file_types = array (
'heic' ,
);
$response -> options [ 'allowed_file_types' ] = array_values ( array_diff ( $response -> options [ 'allowed_file_types' ], $remove_file_types ) );
}
2019-11-15 23:26:29 +01:00
foreach ( $wpcom_options_response as $key => $value ) {
$response -> options [ $key ] = $value ;
}
}
restore_current_blog ();
2022-04-02 10:26:41 +02:00
return $response ; // possibly no need since it's modified in place.
2019-11-15 23:26:29 +01:00
}
}
2022-04-02 10:26:41 +02:00
new WPCOM_JSON_API_List_Post_Formats_Endpoint (
array (
'description' => 'Get a list of post formats supported by a site.' ,
'group' => '__do_not_document' ,
'stat' => 'sites:X:post-formats' ,
2019-11-15 23:26:29 +01:00
2022-04-02 10:26:41 +02:00
'method' => 'GET' ,
'path' => '/sites/%s/post-formats' ,
'path_labels' => array (
'$site' => '(int|string) Site ID or domain' ,
),
2019-11-15 23:26:29 +01:00
2022-04-02 10:26:41 +02:00
'query_parameters' => array (
'context' => false ,
),
2019-11-15 23:26:29 +01:00
2022-04-02 10:26:41 +02:00
'allow_fallback_to_jetpack_blog_token' => true ,
2020-11-18 09:10:44 +01:00
2022-04-02 10:26:41 +02:00
'response_format' => array (
'formats' => '(object) An object of supported post formats, each key a supported format slug mapped to its display string.' ,
),
2019-11-15 23:26:29 +01:00
)
2022-04-02 10:26:41 +02:00
);
2019-11-15 23:26:29 +01:00
2022-04-02 10:26:41 +02:00
/**
2025-08-27 08:44:30 +02:00
* List Post Formats endpoint class .
*
* @ phan - constructor - used - for - side - effects
2022-04-02 10:26:41 +02:00
*/
class WPCOM_JSON_API_List_Post_Formats_Endpoint extends WPCOM_JSON_API_Endpoint { // phpcs:ignore
/**
*
* API callback .
*
* / sites /% s / post - formats -> $blog_id
*
* @ param string $path - the path .
* @ param int $blog_id - the blog ID .
2025-12-12 13:13:07 +01:00
*
* @ return array | \WP_Error Array with 'formats' on success , or WP_Error on failure .
2022-04-02 10:26:41 +02:00
*/
public function callback ( $path = '' , $blog_id = 0 ) {
2019-11-15 23:26:29 +01:00
$blog_id = $this -> api -> switch_to_blog_and_validate_user ( $this -> api -> get_blog_id ( $blog_id ) );
if ( is_wp_error ( $blog_id ) ) {
return $blog_id ;
}
if ( defined ( 'IS_WPCOM' ) && IS_WPCOM ) {
$this -> load_theme_functions ();
}
// Get a list of supported post formats.
$all_formats = get_post_format_strings ();
$supported = get_theme_support ( 'post-formats' );
2022-12-15 17:41:53 +01:00
$response = array (
'formats' => array (),
);
2022-04-02 10:26:41 +02:00
$supported_formats = $response [ 'formats' ];
2019-11-15 23:26:29 +01:00
if ( isset ( $supported [ 0 ] ) ) {
foreach ( $supported [ 0 ] as $format ) {
$supported_formats [ $format ] = $all_formats [ $format ];
}
}
$response [ 'formats' ] = ( object ) $supported_formats ;
return $response ;
}
}
2022-04-02 10:26:41 +02:00
new WPCOM_JSON_API_List_Page_Templates_Endpoint (
array (
'description' => 'Get a list of page templates supported by a site.' ,
'group' => 'sites' ,
'stat' => 'sites:X:post-templates' ,
'method' => 'GET' ,
'path' => '/sites/%s/page-templates' ,
'path_labels' => array (
'$site' => '(int|string) Site ID or domain' ,
),
'query_parameters' => array (
'context' => false ,
),
'response_format' => array (
'templates' => '(array) A list of supported page templates. Contains label and file.' ,
),
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/33534099/page-templates' ,
)
);
/**
* List page templates endpoint class .
2025-08-27 08:44:30 +02:00
*
* @ phan - constructor - used - for - side - effects
2022-04-02 10:26:41 +02:00
*/
class WPCOM_JSON_API_List_Page_Templates_Endpoint extends WPCOM_JSON_API_Endpoint { // phpcs:ignore
/**
*
* API callback .
* / sites /% s / page - templates -> $blog_id
*
* @ param string $path - the path .
* @ param int $blog_id - the blog ID .
2025-12-12 13:13:07 +01:00
*
* @ return array | \WP_Error Array with 'templates' on success , or WP_Error on failure .
2022-04-02 10:26:41 +02:00
*/
public function callback ( $path = '' , $blog_id = 0 ) {
2019-11-15 23:26:29 +01:00
$blog_id = $this -> api -> switch_to_blog_and_validate_user ( $this -> api -> get_blog_id ( $blog_id ) );
if ( is_wp_error ( $blog_id ) ) {
return $blog_id ;
}
if ( defined ( 'IS_WPCOM' ) && IS_WPCOM ) {
$this -> load_theme_functions ();
}
2022-04-02 10:26:41 +02:00
$response = array ();
2019-11-15 23:26:29 +01:00
$page_templates = array ();
$templates = get_page_templates ();
ksort ( $templates );
foreach ( array_keys ( $templates ) as $label ) {
$page_templates [] = array (
'label' => $label ,
2022-04-02 10:26:41 +02:00
'file' => $templates [ $label ],
2019-11-15 23:26:29 +01:00
);
}
$response [ 'templates' ] = $page_templates ;
return $response ;
}
}