← All changes
|
json-endpoints/class.wpcom-json-api-get-site-endpoint.php
+224
-44
12.7.3
→
16.3-a.1
View file →
| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | new WPCOM_JSON_API_GET_Site_Endpoint( |
| 4 | 8 | array( |
| 5 | 9 | 'description' => 'Get information about a site.', |
| 6 | 10 | 'group' => 'sites', |
| @@ -12,8 +16,10 @@ | ||
| 12 | 16 | 'path' => '/sites/%s', |
| 13 | 17 | 'path_labels' => array( |
| 14 | 18 | '$site' => '(int|string) Site ID or domain', |
| 15 | 19 | ), |
| 20 | + 'rest_route' => '/site', | |
| 21 | + 'rest_min_jp_version' => '15.9', | |
| 16 | 22 | 'allow_jetpack_site_auth' => true, |
| 17 | 23 | |
| 18 | 24 | 'allow_fallback_to_jetpack_blog_token' => true, |
| 19 | 25 | |
| @@ -29,8 +35,10 @@ | ||
| 29 | 35 | ); |
| 30 | 36 | |
| 31 | 37 | /** |
| 32 | 38 | * GET Site endpoint class. |
| 39 | + * | |
| 40 | + * @phan-constructor-used-for-side-effects | |
| 33 | 41 | */ |
| 34 | 42 | class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { |
| 35 | 43 | |
| 36 | 44 | /** |
| @@ -39,8 +47,9 @@ | ||
| 39 | 47 | * @var array $site_format |
| 40 | 48 | */ |
| 41 | 49 | public static $site_format = array( |
| 42 | 50 | 'ID' => '(int) Site ID', |
| 51 | + 'slug' => '(string) Slug of site', | |
| 43 | 52 | 'name' => '(string) Title of site', |
| 44 | 53 | 'description' => '(string) Tagline or description of site', |
| 45 | 54 | 'URL' => '(string) Full URL to the site', |
| 46 | 55 | 'user_can_manage' => '(bool) The current user can manage this site', // deprecated. |
| @@ -78,11 +87,24 @@ | ||
| 78 | 87 | 'is_wpcom_atomic' => '(bool) If the site is a WP.com Atomic one.', |
| 79 | 88 | 'is_wpcom_staging_site' => '(bool) If the site is a WP.com staging site.', |
| 80 | 89 | 'user_interactions' => '(array) An array of user interactions with a site.', |
| 81 | 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.', | |
| 82 | 92 | 'was_migration_trial' => '(bool) If the site ever used a migration trial.', |
| 83 | 93 | 'was_hosting_trial' => '(bool) If the site ever used a hosting trial.', |
| 84 | 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 | + 'atomic_email_block' => '(object) State of the block on the site\'s outgoing email, with `status` (`blocked` while a block is active, `at_risk` once it has expired), `reason` and `expires_on` keys, or null when the site has no block history. WordPress.com platform only.', | |
| 105 | + 'hosting_provider_guess' => '(string) Guess of the hosting provider. WordPress.com platform only; only returned when explicitly requested via the fields parameter.', | |
| 106 | + '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.', | |
| 85 | 107 | ); |
| 86 | 108 | |
| 87 | 109 | /** |
| 88 | 110 | * No member fields. |
| @@ -114,8 +136,15 @@ | ||
| 114 | 136 | 'is_fse_eligible', |
| 115 | 137 | 'is_core_site_editor_enabled', |
| 116 | 138 | 'is_wpcom_atomic', |
| 117 | 139 | 'is_wpcom_staging_site', |
| 140 | + 'is_deleted', | |
| 141 | + 'is_wpcom_flex', | |
| 142 | + 'is_a4a_client', | |
| 143 | + 'is_a4a_dev_site', | |
| 144 | + 'is_garden', | |
| 145 | + 'big_sky_enabled', | |
| 146 | + 'garden_name', | |
| 118 | 147 | ); |
| 119 | 148 | |
| 120 | 149 | /** |
| 121 | 150 | * Site options. |
| @@ -134,8 +163,9 @@ | ||
| 134 | 163 | 'is_redirect', |
| 135 | 164 | 'unmapped_url', |
| 136 | 165 | 'featured_images_enabled', |
| 137 | 166 | 'theme_slug', |
| 167 | + 'theme_errors', | |
| 138 | 168 | 'header_image', |
| 139 | 169 | 'background_color', |
| 140 | 170 | 'image_default_link_type', |
| 141 | 171 | 'image_thumbnail_width', |
| @@ -195,37 +225,39 @@ | ||
| 195 | 225 | 'was_created_with_blank_canvas_design', |
| 196 | 226 | 'videopress_storage_used', |
| 197 | 227 | 'is_difm_lite_in_progress', |
| 198 | 228 | 'difm_lite_site_options', |
| 229 | + 'is_gating_business_q1', | |
| 199 | 230 | 'site_intent', |
| 231 | + 'site_partner_bundle', | |
| 232 | + 'onboarding_segment', | |
| 200 | 233 | 'site_vertical_id', |
| 201 | 234 | 'blogging_prompts_settings', |
| 202 | 235 | 'launchpad_screen', |
| 203 | 236 | 'launchpad_checklist_tasks_statuses', |
| 237 | + 'migration_source_site_domain', | |
| 204 | 238 | 'wpcom_production_blog_id', |
| 205 | 239 | 'wpcom_staging_blog_ids', |
| 206 | 240 | 'can_blaze', |
| 207 | 241 | 'wpcom_site_setup', |
| 208 | 242 | 'is_commercial', |
| 243 | + 'is_commercial_reasons', | |
| 244 | + 'wpcom_admin_interface', | |
| 245 | + 'wpcom_classic_early_release', | |
| 246 | + 'jetpack_recovery_mode_status', | |
| 247 | + 'apm_enabled', | |
| 248 | + 'wpcom_ai_launchpad_enabled', | |
| 249 | + 'wpcom_ai_launchpad_dismissed', | |
| 250 | + 'wpcom_ai_launchpad_completed', | |
| 209 | 251 | ); |
| 210 | 252 | |
| 211 | 253 | /** |
| 212 | - * List of DIFM Lite options to be displayed | |
| 213 | - * | |
| 214 | - * @var array $displayed_difm_lite_site_options | |
| 215 | - */ | |
| 216 | - protected static $displayed_difm_lite_site_options = array( | |
| 217 | - 'site_category', | |
| 218 | - 'is_website_content_submitted', | |
| 219 | - 'selected_page_titles', | |
| 220 | - ); | |
| 221 | - | |
| 222 | - /** | |
| 223 | 254 | * Jetpack response fields. |
| 224 | 255 | * |
| 225 | 256 | * @var array $jetpack_response_field_additions |
| 226 | 257 | */ |
| 227 | 258 | protected static $jetpack_response_field_additions = array( |
| 259 | + 'slug', | |
| 228 | 260 | 'subscribers_count', |
| 229 | 261 | 'site_migration', |
| 230 | 262 | 'site_owner', |
| 231 | 263 | 'is_wpcom_staging_site', |
| @@ -231,8 +263,17 @@ | ||
| 231 | 263 | 'is_wpcom_staging_site', |
| 232 | 264 | 'was_ecommerce_trial', |
| 233 | 265 | 'was_migration_trial', |
| 234 | 266 | 'was_hosting_trial', |
| 267 | + 'was_upgraded_from_trial', | |
| 268 | + 'is_a4a_dev_site', | |
| 269 | + 'is_garden', | |
| 270 | + 'garden_name', | |
| 271 | + 'garden_partner', | |
| 272 | + 'garden_is_provisioned', | |
| 273 | + 'is_wpcom_flex', | |
| 274 | + 'big_sky_enabled', | |
| 275 | + 'atomic_email_block', | |
| 235 | 276 | ); |
| 236 | 277 | |
| 237 | 278 | /** |
| 238 | 279 | * Jetpack response field member additions. |
| @@ -248,9 +289,9 @@ | ||
| 248 | 289 | |
| 249 | 290 | /** |
| 250 | 291 | * Jetpack response option additions. |
| 251 | 292 | * |
| 252 | - * @var array $jetpack_response_field_member_additions | |
| 293 | + * @var array $jetpack_response_option_additions | |
| 253 | 294 | */ |
| 254 | 295 | protected static $jetpack_response_option_additions = array( |
| 255 | 296 | 'publicize_permanently_disabled', |
| 256 | 297 | 'ak_vp_bundle_enabled', |
| @@ -274,8 +315,13 @@ | ||
| 274 | 315 | 'blogging_prompts_settings', |
| 275 | 316 | 'wpcom_production_blog_id', |
| 276 | 317 | 'wpcom_staging_blog_ids', |
| 277 | 318 | 'is_commercial', |
| 319 | + 'is_commercial_reasons', | |
| 320 | + 'wpcom_admin_interface', | |
| 321 | + 'wpcom_classic_early_release', | |
| 322 | + 'jetpack_recovery_mode_status', | |
| 323 | + 'apm_enabled', | |
| 278 | 324 | ); |
| 279 | 325 | |
| 280 | 326 | /** |
| 281 | 327 | * Current enabled trials. |
| @@ -288,11 +334,11 @@ | ||
| 288 | 334 | 'was_hosting_trial' => 'hosting', |
| 289 | 335 | ); |
| 290 | 336 | |
| 291 | 337 | /** |
| 292 | - * Site | |
| 338 | + * Site. | |
| 293 | 339 | * |
| 294 | - * @var $site. | |
| 340 | + * @var SAL_Site $site. | |
| 295 | 341 | */ |
| 296 | 342 | private $site; |
| 297 | 343 | |
| 298 | 344 | /** |
| @@ -315,10 +361,12 @@ | ||
| 315 | 361 | * |
| 316 | 362 | * /sites/mine |
| 317 | 363 | * /sites/%s -> $blog_id\ |
| 318 | 364 | * |
| 319 | - * @param string $path - the path. | |
| 320 | - * @param int $blog_id - the blog ID. | |
| 365 | + * @param string $path - the path. | |
| 366 | + * @param int|string $blog_id - the blog ID or the string 'mine'. | |
| 367 | + * | |
| 368 | + * @return array|\WP_Error Site response array on success, or WP_Error on failure. | |
| 321 | 369 | */ |
| 322 | 370 | public function callback( $path = '', $blog_id = 0 ) { |
| 323 | 371 | if ( 'mine' === $blog_id ) { |
| 324 | 372 | $api = WPCOM_JSON_API::init(); |
| @@ -454,8 +502,11 @@ | ||
| 454 | 502 | switch ( $key ) { |
| 455 | 503 | case 'ID': |
| 456 | 504 | $response[ $key ] = $this->site->blog_id; |
| 457 | 505 | break; |
| 506 | + case 'slug': | |
| 507 | + $response[ $key ] = $this->site->get_slug(); | |
| 508 | + break; | |
| 458 | 509 | case 'name': |
| 459 | 510 | $response[ $key ] = $this->site->get_name(); |
| 460 | 511 | break; |
| 461 | 512 | case 'description': |
| @@ -561,13 +612,9 @@ | ||
| 561 | 612 | case 'products': |
| 562 | 613 | $response[ $key ] = $this->site->get_products(); |
| 563 | 614 | break; |
| 564 | 615 | case 'zendesk_site_meta': |
| 565 | - // D59613-code only added this function to the wpcom SAL subclasses. Absent any better idea, | |
| 566 | - // we'll just omit the key entirely in Jetpack. | |
| 567 | - if ( is_callable( array( $this->site, 'get_zendesk_site_meta' ) ) ) { | |
| 568 | - $response[ $key ] = $this->site->get_zendesk_site_meta(); | |
| 569 | - } | |
| 616 | + $response[ $key ] = $this->site->get_zendesk_site_meta(); | |
| 570 | 617 | break; |
| 571 | 618 | case 'quota': |
| 572 | 619 | $response[ $key ] = $this->site->get_quota(); |
| 573 | 620 | break; |
| @@ -603,8 +650,57 @@ | ||
| 603 | 650 | break; |
| 604 | 651 | case 'was_hosting_trial': |
| 605 | 652 | $response[ $key ] = $this->site->was_trial( self::$jetpack_enabled_trials['was_hosting_trial'] ); |
| 606 | 653 | break; |
| 654 | + case 'was_upgraded_from_trial': | |
| 655 | + $response[ $key ] = $this->site->was_upgraded_from_trial(); | |
| 656 | + break; | |
| 657 | + case 'is_deleted': | |
| 658 | + $response[ $key ] = $this->site->is_deleted(); | |
| 659 | + break; | |
| 660 | + case 'is_a4a_client': | |
| 661 | + $response[ $key ] = $this->site->is_a4a_client(); | |
| 662 | + break; | |
| 663 | + case 'is_a4a_dev_site': | |
| 664 | + $response[ $key ] = $this->site->is_a4a_dev_site(); | |
| 665 | + break; | |
| 666 | + case 'is_garden': | |
| 667 | + $response[ $key ] = $this->site->is_garden(); | |
| 668 | + break; | |
| 669 | + case 'garden_name': | |
| 670 | + $response[ $key ] = $this->site->garden_name(); | |
| 671 | + break; | |
| 672 | + case 'garden_partner': | |
| 673 | + $response[ $key ] = $this->site->garden_partner(); | |
| 674 | + break; | |
| 675 | + case 'garden_is_provisioned': | |
| 676 | + $response[ $key ] = $this->site->garden_is_provisioned(); | |
| 677 | + break; | |
| 678 | + case 'is_wpcom_flex': | |
| 679 | + $response[ $key ] = $this->site->is_wpcom_flex(); | |
| 680 | + break; | |
| 681 | + case 'big_sky_enabled': | |
| 682 | + $response[ $key ] = $this->site->is_big_sky_enabled(); | |
| 683 | + break; | |
| 684 | + case 'atomic_email_block': | |
| 685 | + $response[ $key ] = $this->site->get_atomic_email_block(); | |
| 686 | + break; | |
| 687 | + case 'hosting_provider_guess': | |
| 688 | + // WordPress.com platform decoration, computed only when explicitly requested | |
| 689 | + // via `fields` so default `_all` responses are unchanged. | |
| 690 | + if ( $this->is_wpcom() | |
| 691 | + && function_exists( 'get_jetpack_hosting_provider' ) | |
| 692 | + && is_array( $this->fields_to_include ) ) { | |
| 693 | + $response[ $key ] = get_jetpack_hosting_provider( get_current_blog_id() ); | |
| 694 | + } | |
| 695 | + break; | |
| 696 | + case 'environment_type': | |
| 697 | + // WordPress.com platform decoration, computed only when explicitly requested | |
| 698 | + // via `fields` so default `_all` responses are unchanged. | |
| 699 | + if ( $this->is_wpcom() && is_array( $this->fields_to_include ) ) { | |
| 700 | + $response[ $key ] = $this->get_site_environment_type(); | |
| 701 | + } | |
| 702 | + break; | |
| 607 | 703 | } |
| 608 | 704 | |
| 609 | 705 | do_action( 'post_render_site_response_key', $key ); |
| 610 | 706 | } |
| @@ -654,8 +750,11 @@ | ||
| 654 | 750 | break; |
| 655 | 751 | case 'theme_slug': |
| 656 | 752 | $options[ $key ] = $site->get_theme_slug(); |
| 657 | 753 | break; |
| 754 | + case 'theme_errors': | |
| 755 | + $options[ $key ] = $site->get_theme_errors(); | |
| 756 | + break; | |
| 658 | 757 | case 'header_image': |
| 659 | 758 | $options[ $key ] = $site->get_header_image(); |
| 660 | 759 | break; |
| 661 | 760 | case 'background_color': |
| @@ -814,13 +913,9 @@ | ||
| 814 | 913 | case 'import_engine': |
| 815 | 914 | $options[ $key ] = $site->get_import_engine(); |
| 816 | 915 | break; |
| 817 | 916 | case 'is_pending_plan': |
| 818 | - // D40032-code only added this function to the wpcom SAL subclasses. Absent any better idea, | |
| 819 | - // we'll just omit the key entirely in Jetpack. | |
| 820 | - if ( is_callable( array( $site, 'is_pending_plan' ) ) ) { | |
| 821 | - $options[ $key ] = $site->is_pending_plan(); | |
| 822 | - } | |
| 917 | + $options[ $key ] = $site->is_pending_plan(); | |
| 823 | 918 | break; |
| 824 | 919 | |
| 825 | 920 | case 'is_wpforteams_site': |
| 826 | 921 | $options[ $key ] = $site->is_wpforteams_site(); |
| @@ -862,25 +957,28 @@ | ||
| 862 | 957 | case 'is_difm_lite_in_progress': |
| 863 | 958 | $options[ $key ] = $site->is_difm_lite_in_progress(); |
| 864 | 959 | break; |
| 865 | 960 | case 'difm_lite_site_options': |
| 866 | - $difm_lite_options = $site->get_difm_lite_site_options(); | |
| 867 | - $visible_options = self::$displayed_difm_lite_site_options; | |
| 868 | - $filtered_difm_lite_options = new stdClass(); | |
| 869 | - if ( $difm_lite_options ) { | |
| 870 | - $filtered_difm_lite_options = array_filter( | |
| 871 | - $difm_lite_options, | |
| 872 | - function ( $key ) use ( $visible_options ) { | |
| 873 | - return in_array( $key, $visible_options, true ); | |
| 874 | - }, | |
| 875 | - ARRAY_FILTER_USE_KEY | |
| 876 | - ); | |
| 961 | + $difm_lite_site_options = $site->get_difm_lite_site_options(); | |
| 962 | + if ( null !== $difm_lite_site_options ) { | |
| 963 | + $options[ $key ] = (object) $difm_lite_site_options; | |
| 877 | 964 | } |
| 878 | - $options[ $key ] = $filtered_difm_lite_options; | |
| 879 | 965 | break; |
| 966 | + case 'is_gating_business_q1': | |
| 967 | + $options[ $key ] = $site->is_gating_business_q1(); | |
| 968 | + break; | |
| 880 | 969 | case 'site_intent': |
| 881 | 970 | $options[ $key ] = $site->get_site_intent(); |
| 882 | 971 | break; |
| 972 | + case 'site_partner_bundle': | |
| 973 | + $options[ $key ] = $site->get_site_partner_bundle(); | |
| 974 | + break; | |
| 975 | + case 'site_goals': | |
| 976 | + $options[ $key ] = $site->get_site_goals(); | |
| 977 | + break; | |
| 978 | + case 'onboarding_segment': | |
| 979 | + $options[ $key ] = $site->get_onboarding_segment(); | |
| 980 | + break; | |
| 883 | 981 | case 'site_vertical_id': |
| 884 | 982 | $options[ $key ] = $site->get_site_vertical_id(); |
| 885 | 983 | break; |
| 886 | 984 | case 'blogging_prompts_settings': |
| @@ -893,8 +991,11 @@ | ||
| 893 | 991 | break; |
| 894 | 992 | case 'launchpad_checklist_tasks_statuses': |
| 895 | 993 | $options[ $key ] = $site->get_launchpad_checklist_tasks_statuses(); |
| 896 | 994 | break; |
| 995 | + case 'migration_source_site_domain': | |
| 996 | + $options[ $key ] = $site->get_migration_source_site_domain(); | |
| 997 | + break; | |
| 897 | 998 | case 'wpcom_production_blog_id': |
| 898 | 999 | $options[ $key ] = $site->get_wpcom_production_blog_id(); |
| 899 | 1000 | break; |
| 900 | 1001 | case 'wpcom_staging_blog_ids': |
| @@ -908,8 +1009,32 @@ | ||
| 908 | 1009 | break; |
| 909 | 1010 | case 'is_commercial': |
| 910 | 1011 | $options[ $key ] = $site->is_commercial(); |
| 911 | 1012 | break; |
| 1013 | + case 'is_commercial_reasons': | |
| 1014 | + $options[ $key ] = $site->get_is_commercial_reasons(); | |
| 1015 | + break; | |
| 1016 | + case 'wpcom_admin_interface': | |
| 1017 | + $options[ $key ] = $site->get_wpcom_admin_interface(); | |
| 1018 | + break; | |
| 1019 | + case 'wpcom_classic_early_release': | |
| 1020 | + $options[ $key ] = $site->get_wpcom_classic_early_release(); | |
| 1021 | + break; | |
| 1022 | + case 'jetpack_recovery_mode_status': | |
| 1023 | + $options[ $key ] = $site->get_jetpack_recovery_mode_status(); | |
| 1024 | + break; | |
| 1025 | + case 'apm_enabled': | |
| 1026 | + $options[ $key ] = $site->get_apm_enabled(); | |
| 1027 | + break; | |
| 1028 | + case 'wpcom_ai_launchpad_enabled': | |
| 1029 | + $options[ $key ] = $site->is_ai_launchpad_enabled(); | |
| 1030 | + break; | |
| 1031 | + case 'wpcom_ai_launchpad_dismissed': | |
| 1032 | + $options[ $key ] = $site->is_ai_launchpad_dismissed(); | |
| 1033 | + break; | |
| 1034 | + case 'wpcom_ai_launchpad_completed': | |
| 1035 | + $options[ $key ] = $site->is_ai_launchpad_completed(); | |
| 1036 | + break; | |
| 912 | 1037 | } |
| 913 | 1038 | } |
| 914 | 1039 | |
| 915 | 1040 | return $options; |
| @@ -941,14 +1066,20 @@ | ||
| 941 | 1066 | |
| 942 | 1067 | /** |
| 943 | 1068 | * Apply any WPCOM-only response components to a Jetpack site response. |
| 944 | 1069 | * |
| 945 | - * @param array $response - the response. | |
| 1070 | + * @param object $response - the response. | |
| 946 | 1071 | */ |
| 947 | 1072 | public function decorate_jetpack_response( &$response ) { |
| 1073 | + $this->filter_fields_and_options(); | |
| 948 | 1074 | $this->site = $this->get_platform()->get_site( $response->ID ); |
| 949 | 1075 | switch_to_blog( $this->site->get_id() ); |
| 950 | 1076 | |
| 1077 | + // Allow the SAL site to apply its own overrides to the proxied response. | |
| 1078 | + if ( method_exists( $this->site, 'decorate_jetpack_response' ) ) { | |
| 1079 | + $this->site->decorate_jetpack_response( $response ); // @phan-suppress-current-line PhanUndeclaredMethod -- checked via method_exists(). | |
| 1080 | + } | |
| 1081 | + | |
| 951 | 1082 | $wpcom_response = $this->render_response_keys( self::$jetpack_response_field_additions ); |
| 952 | 1083 | |
| 953 | 1084 | foreach ( $wpcom_response as $key => $value ) { |
| 954 | 1085 | $response->{ $key } = $value; |
| @@ -953,9 +1084,11 @@ | ||
| 953 | 1084 | foreach ( $wpcom_response as $key => $value ) { |
| 954 | 1085 | $response->{ $key } = $value; |
| 955 | 1086 | } |
| 956 | 1087 | |
| 957 | - if ( $this->has_user_access() || $this->has_blog_access( $this->api->token_details ) ) { | |
| 1088 | + $has_site_access = $this->has_user_access() || $this->has_blog_access( $this->api->token_details ); | |
| 1089 | + | |
| 1090 | + if ( $has_site_access ) { | |
| 958 | 1091 | $wpcom_member_response = $this->render_response_keys( self::$jetpack_response_field_member_additions ); |
| 959 | 1092 | |
| 960 | 1093 | foreach ( $wpcom_member_response as $key => $value ) { |
| 961 | 1094 | $response->{ $key } = $value; |
| @@ -974,22 +1107,28 @@ | ||
| 974 | 1107 | unset( $response->site_owner ); |
| 975 | 1108 | unset( $response->plan ); |
| 976 | 1109 | unset( $response->products ); |
| 977 | 1110 | unset( $response->zendesk_site_meta ); |
| 1111 | + unset( $response->atomic_email_block ); | |
| 978 | 1112 | } |
| 979 | 1113 | |
| 980 | 1114 | // render additional options. |
| 981 | - if ( $response->options ) { | |
| 1115 | + if ( isset( $response->options ) && $response->options ) { | |
| 982 | 1116 | $wpcom_options_response = $this->render_option_keys( self::$jetpack_response_option_additions ); |
| 983 | 1117 | |
| 984 | 1118 | // Remove heic from jetpack (and atomic) sites so that the iOS app know to convert the file format into a JPEG. |
| 985 | 1119 | // heic fromat is currently not supported by for uploading. |
| 986 | 1120 | // See https://jetpackp2.wordpress.com/2020/08/19/image-uploads-in-the-wp-ios-app-broken |
| 987 | - if ( $this->site->is_jetpack() && isset( $response->options['allowed_file_types'] ) ) { | |
| 1121 | + if ( | |
| 1122 | + $this->site->is_jetpack() | |
| 1123 | + && isset( $response->options['allowed_file_types'] ) | |
| 1124 | + && is_array( $response->options['allowed_file_types'] ) | |
| 1125 | + ) { | |
| 1126 | + $allowed_file_types = (array) $response->options['allowed_file_types']; | |
| 988 | 1127 | $remove_file_types = array( |
| 989 | 1128 | 'heic', |
| 990 | 1129 | ); |
| 991 | - $response->options['allowed_file_types'] = array_values( array_diff( $response->options['allowed_file_types'], $remove_file_types ) ); | |
| 1130 | + $response->options['allowed_file_types'] = array_values( array_diff( $allowed_file_types, $remove_file_types ) ); | |
| 992 | 1131 | } |
| 993 | 1132 | |
| 994 | 1133 | foreach ( $wpcom_options_response as $key => $value ) { |
| 995 | 1134 | $response->options[ $key ] = $value; |
| @@ -995,11 +1134,44 @@ | ||
| 995 | 1134 | $response->options[ $key ] = $value; |
| 996 | 1135 | } |
| 997 | 1136 | } |
| 998 | 1137 | |
| 1138 | + // WordPress.com platform fields are not part of proxied Jetpack responses; | |
| 1139 | + // add them only when explicitly requested. | |
| 1140 | + if ( $this->is_wpcom() && $has_site_access && is_array( $this->fields_to_include ) ) { | |
| 1141 | + if ( function_exists( 'get_jetpack_hosting_provider' ) && in_array( 'hosting_provider_guess', $this->fields_to_include, true ) ) { | |
| 1142 | + $response->hosting_provider_guess = get_jetpack_hosting_provider( get_current_blog_id() ); | |
| 1143 | + } | |
| 1144 | + if ( in_array( 'environment_type', $this->fields_to_include, true ) ) { | |
| 1145 | + $response->environment_type = $this->get_site_environment_type(); | |
| 1146 | + } | |
| 1147 | + } | |
| 1148 | + | |
| 999 | 1149 | restore_current_blog(); |
| 1000 | 1150 | return $response; // possibly no need since it's modified in place. |
| 1001 | 1151 | } |
| 1152 | + | |
| 1153 | + /** | |
| 1154 | + * Whether this request is running on the WordPress.com platform. | |
| 1155 | + * | |
| 1156 | + * @return bool | |
| 1157 | + */ | |
| 1158 | + protected function is_wpcom() { | |
| 1159 | + return ( new \Automattic\Jetpack\Status\Host() )->is_wpcom_platform(); | |
| 1160 | + } | |
| 1161 | + | |
| 1162 | + /** | |
| 1163 | + * Get the site's synced WP_ENVIRONMENT_TYPE. | |
| 1164 | + * | |
| 1165 | + * @return string|null | |
| 1166 | + */ | |
| 1167 | + protected function get_site_environment_type() { | |
| 1168 | + if ( function_exists( 'get_blog_option' ) ) { | |
| 1169 | + return get_blog_option( get_current_blog_id(), 'jetpack_callable_wp_get_environment_type', null ); | |
| 1170 | + } | |
| 1171 | + | |
| 1172 | + return get_option( 'jetpack_callable_wp_get_environment_type', null ); | |
| 1173 | + } | |
| 1002 | 1174 | } |
| 1003 | 1175 | |
| 1004 | 1176 | new WPCOM_JSON_API_List_Post_Formats_Endpoint( |
| 1005 | 1177 | array( |
| @@ -1025,9 +1197,11 @@ | ||
| 1025 | 1197 | ) |
| 1026 | 1198 | ); |
| 1027 | 1199 | |
| 1028 | 1200 | /** |
| 1029 | - * List Post Formates endpoint class. | |
| 1201 | + * List Post Formats endpoint class. | |
| 1202 | + * | |
| 1203 | + * @phan-constructor-used-for-side-effects | |
| 1030 | 1204 | */ |
| 1031 | 1205 | class WPCOM_JSON_API_List_Post_Formats_Endpoint extends WPCOM_JSON_API_Endpoint { // phpcs:ignore |
| 1032 | 1206 | /** |
| 1033 | 1207 | * |
| @@ -1036,8 +1210,10 @@ | ||
| 1036 | 1210 | * /sites/%s/post-formats -> $blog_id |
| 1037 | 1211 | * |
| 1038 | 1212 | * @param string $path - the path. |
| 1039 | 1213 | * @param int $blog_id - the blog ID. |
| 1214 | + * | |
| 1215 | + * @return array|\WP_Error Array with 'formats' on success, or WP_Error on failure. | |
| 1040 | 1216 | */ |
| 1041 | 1217 | public function callback( $path = '', $blog_id = 0 ) { |
| 1042 | 1218 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
| 1043 | 1219 | if ( is_wp_error( $blog_id ) ) { |
| @@ -1091,8 +1267,10 @@ | ||
| 1091 | 1267 | ); |
| 1092 | 1268 | |
| 1093 | 1269 | /** |
| 1094 | 1270 | * List page templates endpoint class. |
| 1271 | + * | |
| 1272 | + * @phan-constructor-used-for-side-effects | |
| 1095 | 1273 | */ |
| 1096 | 1274 | class WPCOM_JSON_API_List_Page_Templates_Endpoint extends WPCOM_JSON_API_Endpoint { // phpcs:ignore |
| 1097 | 1275 | /** |
| 1098 | 1276 | * |
| @@ -1100,8 +1278,10 @@ | ||
| 1100 | 1278 | * /sites/%s/page-templates -> $blog_id |
| 1101 | 1279 | * |
| 1102 | 1280 | * @param string $path - the path. |
| 1103 | 1281 | * @param int $blog_id - the blog ID. |
| 1282 | + * | |
| 1283 | + * @return array|\WP_Error Array with 'templates' on success, or WP_Error on failure. | |
| 1104 | 1284 | */ |
| 1105 | 1285 | public function callback( $path = '', $blog_id = 0 ) { |
| 1106 | 1286 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
| 1107 | 1287 | if ( is_wp_error( $blog_id ) ) { |