PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | json-endpoints/class.wpcom-json-api-site-settings-endpoint.php +454 -217 13.5.216.3-a.1 View file →
@@ -6,8 +6,12 @@
6 6 */
7 7
8 8 use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection_Shared_Functions;
9 9
10 +if ( ! defined( 'ABSPATH' ) ) {
11 + exit( 0 );
12 +}
13 +
10 14 new WPCOM_JSON_API_Site_Settings_Endpoint(
11 15 array(
12 16 'description' => 'Get detailed settings information about a site.',
13 17 'group' => '__do_not_document',
@@ -44,89 +48,99 @@
44 48 '$site' => '(int|string) Site ID or domain',
45 49 ),
46 50
47 51 'request_format' => array(
48 - 'migration_source_site_domain' => '(string) The source site URL, from the migration flow',
49 - 'in_site_migration_flow' => '(string) The migration flow the site is in',
50 - 'blogname' => '(string) Blog name',
51 - 'blogdescription' => '(string) Blog description',
52 - 'default_pingback_flag' => '(bool) Notify blogs linked from article?',
53 - 'default_ping_status' => '(bool) Allow link notifications from other blogs?',
54 - 'default_comment_status' => '(bool) Allow comments on new articles?',
55 - 'blog_public' => '(string) Site visibility; -1: private, 0: discourage search engines, 1: allow search engines',
56 - 'wpcom_data_sharing_opt_out' => '(bool) Did the site opt out of sharing public content with third parties and research partners?',
57 - 'jetpack_sync_non_public_post_stati' => '(bool) allow sync of post and pages with non-public posts stati',
58 - 'jetpack_relatedposts_enabled' => '(bool) Enable related posts?',
59 - 'jetpack_relatedposts_show_context' => '(bool) Show post\'s tags and category in related posts?',
60 - 'jetpack_relatedposts_show_date' => '(bool) Show date in related posts?',
61 - 'jetpack_relatedposts_show_headline' => '(bool) Show headline in related posts?',
62 - 'jetpack_relatedposts_show_thumbnails' => '(bool) Show thumbnails in related posts?',
63 - 'jetpack_protect_whitelist' => '(array) List of IP addresses to always allow',
64 - 'instant_search_enabled' => '(bool) Enable the new Jetpack Instant Search interface',
65 - 'jetpack_search_enabled' => '(bool) Enable Jetpack Search',
66 - 'jetpack_search_supported' => '(bool) Jetpack Search is supported',
67 - 'infinite_scroll' => '(bool) Support infinite scroll of posts?',
68 - 'default_category' => '(int) Default post category',
69 - 'default_post_format' => '(string) Default post format',
70 - 'require_name_email' => '(bool) Require comment authors to fill out name and email?',
71 - 'comment_registration' => '(bool) Require users to be registered and logged in to comment?',
72 - 'close_comments_for_old_posts' => '(bool) Automatically close comments on old posts?',
73 - 'close_comments_days_old' => '(int) Age at which to close comments',
74 - 'thread_comments' => '(bool) Enable threaded comments?',
75 - 'thread_comments_depth' => '(int) Depth to thread comments',
76 - 'page_comments' => '(bool) Break comments into pages?',
77 - 'comments_per_page' => '(int) Number of comments to display per page',
78 - 'default_comments_page' => '(string) newest|oldest Which page of comments to display first',
79 - 'comment_order' => '(string) asc|desc Order to display comments within page',
80 - 'comments_notify' => '(bool) Email me when someone comments?',
81 - 'moderation_notify' => '(bool) Email me when a comment is helf for moderation?',
82 - 'social_notifications_like' => '(bool) Email me when someone likes my post?',
83 - 'social_notifications_reblog' => '(bool) Email me when someone reblogs my post?',
84 - 'social_notifications_subscribe' => '(bool) Email me when someone subscribes to my blog?',
85 - 'comment_moderation' => '(bool) Moderate comments for manual approval?',
86 - 'comment_previously_approved' => '(bool) Moderate comments unless author has a previously-approved comment?',
87 - 'comment_max_links' => '(int) Moderate comments that contain X or more links',
88 - 'moderation_keys' => '(string) Words or phrases that trigger comment moderation, one per line',
89 - 'disallowed_keys' => '(string) Words or phrases that mark comment spam, one per line',
90 - 'lang_id' => '(int) ID for language blog is written in',
91 - 'wga' => '(array) Google Analytics Settings',
92 - 'disabled_likes' => '(bool) Are likes globally disabled (they can still be turned on per post)?',
93 - 'disabled_reblogs' => '(bool) Are reblogs disabled on posts?',
94 - 'jetpack_comment_likes_enabled' => '(bool) Are comment likes enabled for all comments?',
95 - 'sharing_button_style' => '(string) Style to use for sharing buttons (icon-text, icon, text, or official)',
96 - 'sharing_label' => '(string) Label to use for sharing buttons, e.g. "Share this:"',
97 - 'sharing_show' => '(string|array:string) Post type or array of types where sharing buttons are to be displayed',
98 - 'sharing_open_links' => '(string) Link target for sharing buttons (same or new)',
99 - 'twitter_via' => '(string) Twitter username to include in tweets when people share using the Twitter button',
100 - 'jetpack-twitter-cards-site-tag' => '(string) The Twitter username of the owner of the site\'s domain.',
101 - 'eventbrite_api_token' => '(int) The Keyring token ID for an Eventbrite token to associate with the site',
102 - 'timezone_string' => '(string) PHP-compatible timezone string like \'UTC-5\'',
103 - 'gmt_offset' => '(int) Site offset from UTC in hours',
104 - 'date_format' => '(string) PHP Date-compatible date format',
105 - 'time_format' => '(string) PHP Date-compatible time format',
106 - 'start_of_week' => '(int) Starting day of week (0 = Sunday, 6 = Saturday)',
107 - 'jetpack_testimonial' => '(bool) Whether testimonial custom post type is enabled for the site',
108 - 'jetpack_testimonial_posts_per_page' => '(int) Number of testimonials to show per page',
109 - 'jetpack_portfolio' => '(bool) Whether portfolio custom post type is enabled for the site',
110 - 'jetpack_portfolio_posts_per_page' => '(int) Number of portfolio projects to show per page',
111 - Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION => '(string) The seo meta description for the site.',
112 - Jetpack_SEO_Titles::TITLE_FORMATS_OPTION => '(array) SEO meta title formats. Allowed keys: front_page, posts, pages, groups, archives',
113 - 'verification_services_codes' => '(array) Website verification codes. Allowed keys: google, pinterest, bing, yandex, facebook',
114 - 'markdown_supported' => '(bool) Whether markdown is supported for this site',
115 - 'wpcom_publish_posts_with_markdown' => '(bool) Whether markdown is enabled for posts',
116 - 'wpcom_publish_comments_with_markdown' => '(bool) Whether markdown is enabled for comments',
117 - 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear',
118 - 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache',
119 - 'posts_per_page' => '(int) Number of posts to show on blog pages',
120 - 'posts_per_rss' => '(int) Number of posts to show in the RSS feed',
121 - 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts',
122 - 'launchpad_screen' => '(string) Whether or not launchpad is presented and what size it will be',
123 - 'sm_enabled' => '(bool) Whether the newsletter subscribe modal is enabled',
124 - 'jetpack_subscribe_overlay_enabled' => '(bool) Whether the newsletter subscribe overlay is enabled',
52 + 'migration_source_site_domain' => '(string) The source site URL, from the migration flow',
53 + 'in_site_migration_flow' => '(string) The migration flow the site is in',
54 + 'blogname' => '(string) Blog name',
55 + 'blogdescription' => '(string) Blog description',
56 + 'default_pingback_flag' => '(bool) Notify blogs linked from article?',
57 + 'default_ping_status' => '(bool) Allow link notifications from other blogs?',
58 + 'default_comment_status' => '(bool) Allow comments on new articles?',
59 + 'blog_public' => '(string) Site visibility; -1: private, 0: discourage search engines, 1: allow search engines',
60 + 'wpcom_data_sharing_opt_out' => '(bool) Did the site opt out of sharing public content with third parties and research partners?',
61 + 'jetpack_sync_non_public_post_stati' => '(bool) allow sync of post and pages with non-public posts stati',
62 + 'jetpack_relatedposts_enabled' => '(bool) Enable related posts?',
63 + 'jetpack_relatedposts_show_context' => '(bool) Show post\'s tags and category in related posts?',
64 + 'jetpack_relatedposts_show_date' => '(bool) Show date in related posts?',
65 + 'jetpack_relatedposts_show_headline' => '(bool) Show headline in related posts?',
66 + 'jetpack_relatedposts_show_thumbnails' => '(bool) Show thumbnails in related posts?',
67 + 'jetpack_protect_whitelist' => '(array) List of IP addresses to always allow',
68 + 'instant_search_enabled' => '(bool) Enable the new Jetpack Instant Search interface',
69 + 'jetpack_search_enabled' => '(bool) Enable Jetpack Search',
70 + 'jetpack_search_supported' => '(bool) Jetpack Search is supported',
71 + 'infinite_scroll' => '(bool) Support infinite scroll of posts?',
72 + 'default_category' => '(int) Default post category',
73 + 'default_post_format' => '(string) Default post format',
74 + 'require_name_email' => '(bool) Require comment authors to fill out name and email?',
75 + 'comment_registration' => '(bool) Require users to be registered and logged in to comment?',
76 + 'close_comments_for_old_posts' => '(bool) Automatically close comments on old posts?',
77 + 'close_comments_days_old' => '(int) Age at which to close comments',
78 + 'thread_comments' => '(bool) Enable threaded comments?',
79 + 'thread_comments_depth' => '(int) Depth to thread comments',
80 + 'page_comments' => '(bool) Break comments into pages?',
81 + 'comments_per_page' => '(int) Number of comments to display per page',
82 + 'default_comments_page' => '(string) newest|oldest Which page of comments to display first',
83 + 'comment_order' => '(string) asc|desc Order to display comments within page',
84 + 'comments_notify' => '(bool) Email me when someone comments?',
85 + 'moderation_notify' => '(bool) Email me when a comment is helf for moderation?',
86 + 'social_notifications_like' => '(bool) Email me when someone likes my post?',
87 + 'social_notifications_reblog' => '(bool) Email me when someone reblogs my post?',
88 + 'social_notifications_subscribe' => '(bool) Email me when someone subscribes to my blog?',
89 + 'comment_moderation' => '(bool) Moderate comments for manual approval?',
90 + 'comment_previously_approved' => '(bool) Moderate comments unless author has a previously-approved comment?',
91 + 'comment_max_links' => '(int) Moderate comments that contain X or more links',
92 + 'moderation_keys' => '(string) Words or phrases that trigger comment moderation, one per line',
93 + 'disallowed_keys' => '(string) Words or phrases that mark comment spam, one per line',
94 + 'lang_id' => '(int) ID for language blog is written in',
95 + 'wga' => '(array) Google Analytics Settings',
96 + 'disabled_likes' => '(bool) Are likes globally disabled (they can still be turned on per post)?',
97 + 'disabled_reblogs' => '(bool) Are reblogs disabled on posts?',
98 + 'jetpack_comment_likes_enabled' => '(bool) Are comment likes enabled for all comments?',
99 + 'sharing_button_style' => '(string) Style to use for sharing buttons (icon-text, icon, text, or official)',
100 + 'sharing_label' => '(string) Label to use for sharing buttons, e.g. "Share this:"',
101 + 'sharing_show' => '(string|array:string) Post type or array of types where sharing buttons are to be displayed',
102 + 'sharing_open_links' => '(string) Link target for sharing buttons (same or new)',
103 + 'twitter_via' => '(string) Twitter username to include in tweets when people share using the Twitter button',
104 + 'jetpack-twitter-cards-site-tag' => '(string) The Twitter username of the owner of the site\'s domain.',
105 + 'eventbrite_api_token' => '(int) The Keyring token ID for an Eventbrite token to associate with the site',
106 + 'timezone_string' => '(string) PHP-compatible timezone string like \'UTC-5\'',
107 + 'gmt_offset' => '(int) Site offset from UTC in hours',
108 + 'date_format' => '(string) PHP Date-compatible date format',
109 + 'time_format' => '(string) PHP Date-compatible time format',
110 + 'start_of_week' => '(int) Starting day of week (0 = Sunday, 6 = Saturday)',
111 + 'jetpack_testimonial' => '(bool) Whether testimonial custom post type is enabled for the site',
112 + 'jetpack_testimonial_posts_per_page' => '(int) Number of testimonials to show per page',
113 + 'jetpack_portfolio' => '(bool) Whether portfolio custom post type is enabled for the site',
114 + 'jetpack_portfolio_posts_per_page' => '(int) Number of portfolio projects to show per page',
115 + Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION => '(string) The seo meta description for the site.',
116 + Jetpack_SEO_Titles::TITLE_FORMATS_OPTION => '(array) SEO meta title formats. Allowed keys: front_page, posts, pages, groups, archives',
117 + 'verification_services_codes' => '(array) Website verification codes. Allowed keys: google, pinterest, bing, yandex, facebook',
118 + 'markdown_supported' => '(bool) Whether markdown is supported for this site',
119 + 'wpcom_publish_posts_with_markdown' => '(bool) Whether markdown is enabled for posts',
120 + 'wpcom_publish_comments_with_markdown' => '(bool) Whether markdown is enabled for comments',
121 + 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear',
122 + 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache',
123 + 'posts_per_page' => '(int) Number of posts to show on blog pages',
124 + 'posts_per_rss' => '(int) Number of posts to show in the RSS feed',
125 + 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts',
126 + 'launchpad_screen' => '(string) Whether or not launchpad is presented and what size it will be',
127 + 'sm_enabled' => '(bool) Whether the newsletter subscribe modal is enabled',
128 + 'jetpack_subscribe_overlay_enabled' => '(bool) Whether the newsletter subscribe overlay is enabled',
129 + 'jetpack_subscribe_floating_button_enabled' => '(bool) Whether the newsletter floating subscribe button is enabled',
125 130 'jetpack_subscriptions_subscribe_post_end_enabled' => '(bool) Whether the Subscribe block at the end of each post placement is enabled',
126 131 'jetpack_subscriptions_login_navigation_enabled' => '(bool) Whether the Subscriber Login block navigation placement is enabled',
127 132 'jetpack_subscriptions_subscribe_navigation_enabled' => '(Bool) Whether the Subscribe block navigation placement is enabled',
128 - 'wpcom_ai_site_prompt' => '(string) User input in the AI site prompt',
133 + 'wpcom_ai_site_prompt' => '(string) User input in the AI site prompt',
134 + 'jetpack_waf_automatic_rules' => '(bool) Whether the WAF should enforce automatic firewall rules',
135 + 'jetpack_waf_ip_allow_list' => '(string) List of IP addresses to always allow',
136 + 'jetpack_waf_ip_allow_list_enabled' => '(bool) Whether the IP allow list is enabled',
137 + 'jetpack_waf_ip_block_list' => '(string) List of IP addresses the WAF should always block',
138 + 'jetpack_waf_ip_block_list_enabled' => '(bool) Whether the IP block list is enabled',
139 + 'jetpack_waf_share_data' => '(bool) Whether the WAF should share basic data with Jetpack',
140 + 'jetpack_waf_share_debug_data' => '(bool) Whether the WAF should share debug data with Jetpack',
141 + 'jetpack_waf_automatic_rules_last_updated_timestamp' => '(int) Timestamp of the last time the automatic rules were updated',
142 + 'mcp_abilities' => '(array) List of MCP Abilities',
129 143 ),
130 144
131 145 'response_format' => array(
132 146 'updated' => '(array)',
@@ -137,8 +151,10 @@
137 151 );
138 152
139 153 /**
140 154 * Manage Site settings endpoint.
155 + *
156 + * @phan-constructor-used-for-side-effects
141 157 */
142 158 class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint {
143 159
144 160 /**
@@ -318,12 +334,14 @@
318 334 case 'ID':
319 335 $response[ $key ] = $blog_id;
320 336 break;
321 337 case 'name':
322 - $response[ $key ] = (string) htmlspecialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
338 + $name = get_bloginfo( 'name' );
339 + $response[ $key ] = is_string( $name ) ? htmlspecialchars_decode( $name, ENT_QUOTES ) : '';
323 340 break;
324 341 case 'description':
325 - $response[ $key ] = (string) htmlspecialchars_decode( get_bloginfo( 'description' ), ENT_QUOTES );
342 + $description = get_bloginfo( 'description' );
343 + $response[ $key ] = is_string( $description ) ? htmlspecialchars_decode( $description, ENT_QUOTES ) : '';
326 344 break;
327 345 case 'URL':
328 346 $response[ $key ] = (string) home_url();
329 347 break;
@@ -362,18 +380,19 @@
362 380 get_categories( array( 'hide_empty' => false ) )
363 381 )
364 382 );
365 383
366 - $newsletter_categories = maybe_unserialize( get_option( 'wpcom_newsletter_categories', array() ) );
367 - $newsletter_category_ids = array_map(
368 - function ( $newsletter_category ) {
369 - return $newsletter_category['term_id'];
370 - },
371 - $newsletter_categories
372 - );
384 + // Make sure we are returning a consistent type
385 + if ( ! class_exists( 'Jetpack_Newsletter_Category_Helper' ) ) {
386 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-newsletter-category-helper.php';
387 + }
388 + $newsletter_category_ids = Jetpack_Newsletter_Category_Helper::get_category_ids();
373 389
374 390 $api_cache = $site->is_jetpack() ? (bool) get_option( 'jetpack_api_cache_enabled' ) : true;
375 391
392 + // Get Sites MCP settings
393 + $mcp_abilities = $this->get_site_mcp_abilities();
394 +
376 395 $response[ $key ] = array(
377 396 // also exists as "options".
378 397 'admin_url' => get_admin_url(),
379 398 'default_ping_status' => 'closed' !== get_option( 'default_ping_status' ),
@@ -389,9 +408,9 @@
389 408 'jetpack_relatedposts_show_context' => ! empty( $jetpack_relatedposts_options['show_context'] ),
390 409 'jetpack_relatedposts_show_date' => ! empty( $jetpack_relatedposts_options['show_date'] ),
391 410 'jetpack_relatedposts_show_headline' => ! empty( $jetpack_relatedposts_options['show_headline'] ),
392 411 'jetpack_relatedposts_show_thumbnails' => ! empty( $jetpack_relatedposts_options['show_thumbnails'] ),
393 - 'jetpack_search_enabled' => (bool) $jetpack_search_active,
412 + 'jetpack_search_enabled' => $jetpack_search_active,
394 413 'jetpack_search_supported' => (bool) $jetpack_search_supported,
395 414 'default_category' => (int) get_option( 'default_category' ),
396 415 'post_categories' => (array) $post_categories,
397 416 'default_post_format' => get_option( 'default_post_format' ),
@@ -421,9 +440,8 @@
421 440 'lang_id' => defined( 'IS_WPCOM' ) && IS_WPCOM
422 441 ? get_lang_id_by_code( wpcom_l10n_get_blog_locale_variant( $blog_id, true ) )
423 442 : get_option( 'lang_id' ),
424 443 'site_vertical_id' => (string) get_option( 'site_vertical_id' ),
425 - 'wga' => $this->get_google_analytics(),
426 444 'jetpack_cloudflare_analytics' => get_option( 'jetpack_cloudflare_analytics' ),
427 445 'disabled_likes' => (bool) get_option( 'disabled_likes' ),
428 446 'disabled_reblogs' => (bool) get_option( 'disabled_reblogs' ),
429 447 'jetpack_comment_likes_enabled' => (bool) get_option( 'jetpack_comment_likes_enabled', false ),
@@ -448,30 +466,47 @@
448 466 'markdown_supported' => true,
449 467 'site_icon' => $this->get_cast_option_value_or_null( 'site_icon', 'intval' ),
450 468 Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION => get_option( Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION, '' ),
451 469 Jetpack_SEO_Titles::TITLE_FORMATS_OPTION => get_option( Jetpack_SEO_Titles::TITLE_FORMATS_OPTION, array() ),
470 + 'verification_services_codes' => get_option( 'verification_services_codes', null ),
452 471 'api_cache' => $api_cache,
453 472 'posts_per_page' => (int) get_option( 'posts_per_page' ),
454 473 'posts_per_rss' => (int) get_option( 'posts_per_rss' ),
455 474 'rss_use_excerpt' => (bool) get_option( 'rss_use_excerpt' ),
456 475 'launchpad_screen' => (string) get_option( 'launchpad_screen' ),
457 - 'wpcom_featured_image_in_email' => (bool) get_option( 'wpcom_featured_image_in_email' ),
476 + 'wpcom_newsletter_send_default' => (bool) get_option( 'wpcom_newsletter_send_default', true ),
477 + 'wpcom_featured_image_in_email' => ( function () use ( $site ) {
478 + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
479 + $registered_date = method_exists( $site, 'get_registered_date' ) ? $site->get_registered_date() : '';
480 + // Compare to May 2, 2025 (ISO 8601 format)
481 + if ( $registered_date && $registered_date !== '0000-00-00T00:00:00+00:00' && strtotime( $registered_date ) >= strtotime( '2025-05-02T00:00:00+00:00' ) ) {
482 + return (bool) get_option( 'wpcom_featured_image_in_email', true );
483 + }
484 + }
485 + // For all other sites, use the saved value or default to false for legacy behavior.
486 + return (bool) get_option( 'wpcom_featured_image_in_email', false );
487 + } )(),
488 + 'jetpack_gravatar_in_email' => (bool) get_option( 'jetpack_gravatar_in_email', true ),
489 + 'jetpack_author_in_email' => (bool) get_option( 'jetpack_author_in_email', true ),
490 + 'jetpack_post_date_in_email' => (bool) get_option( 'jetpack_post_date_in_email', true ),
458 491 'wpcom_newsletter_categories' => $newsletter_category_ids,
459 492 'wpcom_newsletter_categories_enabled' => (bool) get_option( 'wpcom_newsletter_categories_enabled' ),
460 493 'sm_enabled' => (bool) get_option( 'sm_enabled' ),
461 494 'jetpack_subscribe_overlay_enabled' => (bool) get_option( 'jetpack_subscribe_overlay_enabled' ),
495 + 'jetpack_subscribe_floating_button_enabled' => (bool) get_option( 'jetpack_subscribe_floating_button_enabled' ),
462 496 'jetpack_subscriptions_subscribe_post_end_enabled' => (bool) get_option( 'jetpack_subscriptions_subscribe_post_end_enabled' ),
463 497 'jetpack_subscriptions_login_navigation_enabled' => (bool) get_option( 'jetpack_subscriptions_login_navigation_enabled' ),
464 498 'jetpack_subscriptions_subscribe_navigation_enabled' => (bool) get_option( 'jetpack_subscriptions_subscribe_navigation_enabled' ),
465 499 'wpcom_gifting_subscription' => (bool) get_option( 'wpcom_gifting_subscription', $this->get_wpcom_gifting_subscription_default() ),
466 500 'wpcom_reader_views_enabled' => (bool) get_option( 'wpcom_reader_views_enabled', true ),
467 - 'wpcom_subscription_emails_use_excerpt' => $this->get_wpcom_subscription_emails_use_excerpt_option(),
501 + 'wpcom_subscription_emails_use_excerpt' => (bool) get_option( 'wpcom_subscription_emails_use_excerpt' ),
468 502 'jetpack_subscriptions_reply_to' => (string) $this->get_subscriptions_reply_to_option(),
469 503 'jetpack_subscriptions_from_name' => (string) get_option( 'jetpack_subscriptions_from_name' ),
470 504 'show_on_front' => (string) get_option( 'show_on_front' ),
471 505 'page_on_front' => (string) get_option( 'page_on_front' ),
472 506 'page_for_posts' => (string) get_option( 'page_for_posts' ),
473 - 'subscription_options' => (array) get_option( 'subscription_options' ),
507 + 'subscription_options' => $this->get_subscription_options_in_user_locale(),
508 + 'supports_free_tier_customization' => true,
474 509 'jetpack_verbum_subscription_modal' => (bool) get_option( 'jetpack_verbum_subscription_modal', true ),
475 510 'enable_verbum_commenting' => (bool) get_option( 'enable_verbum_commenting', true ),
476 511 'enable_blocks_comments' => (bool) get_option( 'enable_blocks_comments', true ),
477 512 'highlander_comment_form_prompt' => $this->get_highlander_comment_form_prompt_option(),
@@ -477,10 +512,33 @@
477 512 'highlander_comment_form_prompt' => $this->get_highlander_comment_form_prompt_option(),
478 513 'jetpack_comment_form_color_scheme' => (string) get_option( 'jetpack_comment_form_color_scheme' ),
479 514 'in_site_migration_flow' => (string) get_option( 'in_site_migration_flow', '' ),
480 515 'migration_source_site_domain' => (string) get_option( 'migration_source_site_domain' ),
516 + 'jetpack_waf_automatic_rules' => (bool) get_option( 'jetpack_waf_automatic_rules' ),
517 + 'jetpack_waf_ip_allow_list' => (string) get_option( 'jetpack_waf_ip_allow_list' ),
518 + 'jetpack_waf_ip_allow_list_enabled' => (bool) get_option( 'jetpack_waf_ip_allow_list_enabled' ),
519 + 'jetpack_waf_ip_block_list' => (string) get_option( 'jetpack_waf_ip_block_list' ),
520 + 'jetpack_waf_ip_block_list_enabled' => (bool) get_option( 'jetpack_waf_ip_block_list_enabled' ),
521 + 'jetpack_waf_share_data' => (bool) get_option( 'jetpack_waf_share_data' ),
522 + 'jetpack_waf_share_debug_data' => (bool) get_option( 'jetpack_waf_share_debug_data' ),
523 + 'jetpack_waf_automatic_rules_last_updated_timestamp' => (int) get_option( 'jetpack_waf_automatic_rules_last_updated_timestamp' ),
524 + 'is_fully_managed_agency_site' => (bool) get_option( 'is_fully_managed_agency_site' ),
525 + 'wpcom_hide_action_bar' => (bool) get_option( 'wpcom_hide_action_bar' ),
526 + 'mcp_abilities' => $mcp_abilities,
481 527 );
482 528
529 + require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
530 + if ( class_exists( 'Jetpack_Memberships' ) ) {
531 + $response[ $key ]['newsletter_has_active_plan'] = count( Jetpack_Memberships::get_all_newsletter_plan_ids( false ) ) > 0;
532 + // Read-only/derived: the free tier's markdown description rendered to
533 + // safe HTML, colocated with subscription_options so it's
534 + // read-after-write consistent. Not part of the writable
535 + // subscription_options bag (which would round-trip and persist it).
536 + $response[ $key ]['free_tier_description_rendered'] = Jetpack_Memberships::render_tier_description_html(
537 + ( (array) get_option( 'subscription_options' ) )['free_tier_description'] ?? ''
538 + );
539 + }
540 +
483 541 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
484 542 $response[ $key ]['wpcom_publish_posts_with_markdown'] = (bool) WPCom_Markdown::get_instance()->is_posting_enabled();
485 543 $response[ $key ]['wpcom_publish_comments_with_markdown'] = (bool) WPCom_Markdown::get_instance()->is_commenting_enabled();
486 544
@@ -511,12 +569,14 @@
511 569 *
512 570 * @module json-api
513 571 *
514 572 * @since 3.9.3
573 + * @since 13.6 Added the API object parameter.
515 574 *
516 575 * @param mixed $response_item A single site setting.
576 + * @param WPCOM_JSON_API_Site_Settings_Endpoint $this The API object.
517 577 */
518 - $response[ $key ] = apply_filters( 'site_settings_endpoint_get', $response[ $key ] );
578 + $response[ $key ] = apply_filters( 'site_settings_endpoint_get', $response[ $key ], $this );
519 579
520 580 if ( class_exists( 'Sharing_Service' ) ) {
521 581 $ss = new Sharing_Service();
522 582 $sharing = $ss->get_global_options();
@@ -573,8 +633,158 @@
573 633 return false;
574 634 }
575 635
576 636 /**
637 + * Reads `subscription_options` with the current user's locale active, to
638 + * ensure that the defaults would be translated when displaying to the user
639 + * or comparing the options before saving.
640 + *
641 + * @return array The `subscription_options` value, defaults included.
642 + */
643 + private function get_subscription_options_in_user_locale() {
644 + $switched_locale = false;
645 +
646 + if ( function_exists( 'wpcom_switch_to_user_locale' ) ) {
647 + // Compare the locales before/after switch to decide if we should switch back
648 + $locale_before = determine_locale();
649 + // @phan-suppress-next-line PhanUndeclaredFunction -- Checked above. See also https://github.com/phan/phan/issues/1204.
650 + wpcom_switch_to_user_locale();
651 + $switched_locale = determine_locale() !== $locale_before;
652 + }
653 +
654 + // Resolve the defaults the same way get_option() does for a missing row (via the
655 + // `default_option_*` filter with $passed_default = false), then let any stored
656 + // sub-keys take precedence. Passing an array default keeps get_option() from
657 + // re-populating the defaults, so a partial row stays partial before the merge.
658 + $default_subscription_options = (array) apply_filters( 'default_option_subscription_options', array(), 'subscription_options', false );
659 + $stored_subscription_options = (array) get_option( 'subscription_options', array() );
660 + $subscription_options = array_merge( $default_subscription_options, $stored_subscription_options );
661 +
662 + if ( $switched_locale ) {
663 + restore_previous_locale();
664 + }
665 +
666 + return $subscription_options;
667 + }
668 +
669 + /**
670 + * Get list of all site level MCP abilities.
671 + *
672 + * @return array
673 + */
674 + private function get_all_site_mcp_abilities(): array {
675 + $all_abilities = array();
676 + $ability_registry_file = WP_CONTENT_DIR . '/mu-plugins/wpcom-mcp/includes/AbilitiesRegistry/Registry/AbilityRegistry.php';
677 + if ( file_exists( $ability_registry_file ) ) {
678 + require_once $ability_registry_file;
679 + // @phan-suppress-next-line PhanUndeclaredClassMethod
680 + $abilities_resources = Automattic\WpcomMcp\AbilitiesRegistry\Registry\AbilityRegistry::get_resources_for_server( 'site-level' );
681 + // @phan-suppress-next-line PhanUndeclaredClassMethod
682 + $abilities_tools = Automattic\WpcomMcp\AbilitiesRegistry\Registry\AbilityRegistry::get_tools_for_server( 'site-level' );
683 + // @phan-suppress-next-line PhanUndeclaredClassMethod
684 + $abilities_prompts = Automattic\WpcomMcp\AbilitiesRegistry\Registry\AbilityRegistry::get_prompts_for_server( 'site-level' );
685 + $all_abilities = array_merge( $abilities_resources, $abilities_tools, $abilities_prompts );
686 + }
687 + return apply_filters( 'jetpack_site_mcp_abilities', $all_abilities );
688 + }
689 +
690 + /**
691 + * Get ability meta from config.
692 + *
693 + * @param string $ability_name Ability name, i.e. wpcom-mcp/posts-search.
694 + *
695 + * @return array
696 + */
697 + private function get_mcp_abilities_metadata( string $ability_name ): array {
698 + $ability_meta = array();
699 + $ability_registry_file = WP_CONTENT_DIR . '/mu-plugins/wpcom-mcp/includes/AbilitiesRegistry/Registry/AbilityRegistry.php';
700 + if ( file_exists( $ability_registry_file ) ) {
701 + require_once $ability_registry_file;
702 + // @phan-suppress-next-line PhanUndeclaredClassMethod
703 + $ability_meta = Automattic\WpcomMcp\AbilitiesRegistry\Registry\AbilityRegistry::get_metadata( $ability_name );
704 + }
705 + return apply_filters( 'jetpack_site_mcp_ability_meta', $ability_meta, $ability_name );
706 + }
707 +
708 + /**
709 + * Get MCP abilities for the current site.
710 + *
711 + * @return array
712 + */
713 + public function get_site_mcp_abilities(): array {
714 + $current_mcp_abilities = get_option( 'mcp_abilities', array() );
715 + if ( ! is_array( $current_mcp_abilities ) ) {
716 + $current_mcp_abilities = array();
717 + }
718 +
719 + $all_abilities = $this->get_all_site_mcp_abilities();
720 + if ( empty( $all_abilities ) ) {
721 + return array();
722 + }
723 +
724 + $computed_abilities = array();
725 + foreach ( $all_abilities as $ability_name ) {
726 + // Get base metadata first
727 + $ability_meta = $this->get_mcp_abilities_metadata( $ability_name );
728 + if ( ! empty( $ability_meta ) ) {
729 + // Use stored value or fall back to metadata default
730 + $enabled = $current_mcp_abilities[ $ability_name ] ?? $ability_meta['enabled'] ?? false;
731 +
732 + $computed_abilities[ $ability_name ] = array(
733 + 'name' => $ability_name,
734 + 'title' => $ability_meta['title'] ?? '',
735 + 'description' => $ability_meta['description'] ?? '',
736 + 'category' => $ability_meta['category'] ?? '',
737 + 'type' => $ability_meta['type'] ?? '',
738 + 'enabled' => (bool) $enabled,
739 + );
740 + }
741 + }
742 + return $computed_abilities;
743 + }
744 +
745 + /**
746 + * Sets the MCP abilities for the current site.
747 + *
748 + * @param mixed $value MCP abilities array.
749 + *
750 + * @return true|WP_Error
751 + */
752 + public function set_site_mcp_abilities( $value ) {
753 + // Validate input format
754 + if ( ! is_array( $value ) ) {
755 + return new WP_Error( 'invalid_format', __( 'Site MCP abilities must be an array', 'jetpack' ) );
756 + }
757 +
758 + $all_abilities = $this->get_all_site_mcp_abilities();
759 +
760 + // Filter ability names that don't exist
761 + $value = array_filter(
762 + $value,
763 + function ( $ability_name ) use ( $all_abilities ) {
764 + return in_array( $ability_name, $all_abilities, true );
765 + },
766 + ARRAY_FILTER_USE_KEY
767 + );
768 +
769 + // Validate each ability exists and value is boolean-like
770 + foreach ( $value as $ability_name => $enabled ) {
771 + if ( ! is_string( $ability_name ) || ( ! WPCOM_JSON_API::is_truthy( $enabled ) && ! WPCOM_JSON_API::is_falsy( $enabled ) ) ) {
772 + $error_message = sprintf(
773 + // Translators: %s is an MCP ability name
774 + __( 'Invalid ability: %s', 'jetpack' ),
775 + $ability_name
776 + );
777 + return new WP_Error( 'invalid_ability', $error_message );
778 + }
779 + }
780 +
781 + update_option( 'mcp_abilities', $value );
782 +
783 + return true;
784 + }
785 +
786 + /**
577 787 * Get locale.
578 788 *
579 789 * @param string $key Language.
580 790 */
@@ -590,31 +800,11 @@
590 800 return false;
591 801 }
592 802
593 803 /**
594 - * Get GA tracking code.
595 - */
596 - protected function get_google_analytics() {
597 - $option_name = $this->get_google_analytics_option_name();
598 -
599 - return get_option( $option_name );
600 - }
601 -
602 - /**
603 - * Get GA tracking code option name.
604 - */
605 - protected function get_google_analytics_option_name() {
606 - /** This filter is documented in class.json-api-endpoints.php */
607 - $is_jetpack = true === apply_filters( 'is_jetpack_site', false, get_current_blog_id() );
608 - $option_name = $is_jetpack ? 'jetpack_wga' : 'wga';
609 -
610 - return $option_name;
611 - }
612 -
613 - /**
614 804 * Updates site settings for authorized users
615 805 *
616 - * @return array
806 + * @return array|WP_Error
617 807 */
618 808 public function update_settings() {
619 809 /*
620 810 * $this->input() retrieves posted arguments whitelisted and casted to the $request_format
@@ -642,8 +832,12 @@
642 832 $jetpack_relatedposts_options = array();
643 833 $sharing_options = array();
644 834 $updated = array();
645 835
836 + if ( ! class_exists( 'Jetpack_Newsletter_Category_Helper' ) ) {
837 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-newsletter-category-helper.php';
838 + }
839 +
646 840 foreach ( $input as $key => $value ) {
647 841
648 842 if ( ! is_array( $value ) ) {
649 843 $value = trim( $value );
@@ -685,8 +879,9 @@
685 879 case 'jetpack_search_enabled':
686 880 if ( $value ) {
687 881 Jetpack::activate_module( $blog_id, 'search' );
688 882 } else {
883 + // @phan-suppress-next-line PhanParamTooMany -- Phan doesn't know about the WP.com variant of the Jetpack class.
689 884 Jetpack::deactivate_module( $blog_id, 'search' );
690 885 }
691 886 $updated[ $key ] = (bool) $value;
692 887 break;
@@ -701,8 +896,9 @@
701 896 if ( 'jetpack_relatedposts_enabled' === $key ) {
702 897 if ( $value ) {
703 898 Jetpack::activate_module( $blog_id, 'related-posts' );
704 899 } else {
900 + // @phan-suppress-next-line PhanParamTooMany -- Phan doesn't know about the WP.com variant of the Jetpack class.
705 901 Jetpack::deactivate_module( $blog_id, 'related-posts' );
706 902 }
707 903 }
708 904 $just_the_key = substr( $key, 21 );
@@ -717,45 +913,9 @@
717 913 if ( update_option( $key, $coerce_value ) ) {
718 914 $updated[ $key ] = $value;
719 915 }
720 916 break;
721 - case 'wga':
722 - case 'jetpack_wga':
723 - if ( ! isset( $value['code'] ) || ! preg_match( '/^$|^(UA-\d+-\d+)|(G-[A-Z0-9]+)$/i', $value['code'] ) ) {
724 - return new WP_Error( 'invalid_code', 'Invalid UA ID' );
725 - }
726 917
727 - $option_name = $this->get_google_analytics_option_name();
728 -
729 - $wga = get_option( $option_name, array() );
730 - $wga['code'] = $value['code']; // maintain compatibility with wp-google-analytics.
731 -
732 - /**
733 - * Allow newer versions of this endpoint to filter in additional fields for Google Analytics
734 - *
735 - * @since 5.4.0
736 - *
737 - * @param array $wga Associative array of existing Google Analytics settings.
738 - * @param array $value Associative array of new Google Analytics settings passed to the endpoint.
739 - */
740 - $wga = apply_filters( 'site_settings_update_wga', $wga, $value );
741 -
742 - if ( update_option( $option_name, $wga ) ) {
743 - $updated[ $key ] = $value;
744 - }
745 -
746 - $enabled_or_disabled = $wga['code'] ? 'enabled' : 'disabled';
747 -
748 - /** This action is documented in modules/widgets/social-media-icons.php */
749 - do_action( 'jetpack_bump_stats_extras', 'google-analytics', $enabled_or_disabled );
750 -
751 - $is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM;
752 - if ( $is_wpcom ) {
753 - $business_plugins = WPCOM_Business_Plugins::instance();
754 - $business_plugins->activate_plugin( 'wp-google-analytics' );
755 - }
756 - break;
757 -
758 918 case 'cloudflare_analytics':
759 919 if ( ! isset( $value['code'] ) || ! preg_match( '/^$|^[a-fA-F0-9]+$/i', $value['code'] ) ) {
760 920 return new WP_Error( 'invalid_code', __( 'Invalid Cloudflare Analytics ID', 'jetpack' ) );
761 921 }
@@ -847,9 +1007,9 @@
847 1007 if ( ! is_array( $value ) ) {
848 1008 break;
849 1009 }
850 1010
851 - $allowed_keys = array( 'invitation', 'comment_follow', 'welcome' );
1011 + $allowed_keys = array( 'invitation', 'comment_follow', 'welcome', 'subscribe_modal_heading', 'free_tier_description', 'hide_free_tier' );
852 1012 $filtered_value = array_filter(
853 1013 $value,
854 1014 function ( $key ) use ( $allowed_keys ) {
855 1015 return in_array( $key, $allowed_keys, true );
@@ -860,8 +1020,16 @@
860 1020 if ( empty( $filtered_value ) ) {
861 1021 break;
862 1022 }
863 1023
1024 + // `hide_free_tier` is a boolean flag, so pull it out before the HTML
1025 + // sanitization below (which expects strings). Parse it with is_truthy()
1026 + // so stringy booleans (e.g. "false", "0") are interpreted correctly
1027 + // rather than being treated as truthy by a plain `! empty()`.
1028 + $has_hide_free_tier = array_key_exists( 'hide_free_tier', $filtered_value );
1029 + $hide_free_tier = $has_hide_free_tier && WPCOM_JSON_API::is_truthy( $filtered_value['hide_free_tier'] );
1030 + unset( $filtered_value['hide_free_tier'] );
1031 +
864 1032 array_walk_recursive(
865 1033 $filtered_value,
866 1034 function ( &$value ) {
867 1035 $value = wp_kses(
@@ -874,13 +1042,89 @@
874 1042 );
875 1043 }
876 1044 );
877 1045
878 - $old_subscription_options = get_option( 'subscription_options' );
879 - $new_subscription_options = array_merge( $old_subscription_options, $filtered_value );
1046 + // Normalize whitespace-only `subscribe_modal_heading` input to empty so
1047 + // the modal template's `empty()` fallback fires. PHP's `empty()` treats
1048 + // `" "` as non-empty, which would otherwise render a blank heading.
1049 + if ( isset( $filtered_value['subscribe_modal_heading'] ) ) {
1050 + $filtered_value['subscribe_modal_heading'] = trim( $filtered_value['subscribe_modal_heading'] );
1051 + }
880 1052
1053 + // The free tier description is stored as plain markdown source, so strip
1054 + // all HTML and cap its length to match the paid-tier description field.
1055 + // WordPress core guarantees mb_substr() (polyfilled in wp-includes/compat.php
1056 + // when the mbstring extension is unavailable), so it's safe to use directly.
1057 + // A JSON payload could supply a non-scalar (array/object) for this field,
1058 + // which would fatal in wp_kses()/mb_substr() on PHP 8+, so drop invalid values.
1059 + if ( isset( $filtered_value['free_tier_description'] ) ) {
1060 + if ( is_scalar( $filtered_value['free_tier_description'] ) ) {
1061 + $filtered_value['free_tier_description'] = mb_substr( wp_kses( (string) $filtered_value['free_tier_description'], array() ), 0, 500 );
1062 + } else {
1063 + unset( $filtered_value['free_tier_description'] );
1064 + }
1065 + }
1066 +
1067 + if ( $has_hide_free_tier ) {
1068 + $filtered_value['hide_free_tier'] = $hide_free_tier;
1069 + }
1070 +
1071 + // Clients that render the settings form tend to post the whole
1072 + // `subscription_options` bag back, including sub-keys the user never
1073 + // touched. This could result in a translated value inadvertently
1074 + // saved in the database.
1075 + // Get the value from db or the default options populated by filter.
1076 + $current_subscription_options = $this->get_subscription_options_in_user_locale();
1077 + $changed_subscription_options = array();
1078 +
1079 + foreach ( $filtered_value as $subscription_option_key => $subscription_option_value ) {
1080 + $current_subscription_option = $current_subscription_options[ $subscription_option_key ] ?? null;
1081 +
1082 + // The incoming value has already been through wp_kses() above, and
1083 + // wp_kses() is not guaranteed to be byte-preserving — it rewrites
1084 + // attribute quoting, and differently across WordPress versions. Put the
1085 + // current value through the same pass so the comparison reflects a real
1086 + // edit rather than a sanitizer rewrite; without this, a default carrying
1087 + // markup (`invitation`) never compares equal and is persisted on every
1088 + // save. Safe to apply to an already-sanitized value: the pass is
1089 + // idempotent.
1090 + if ( is_string( $current_subscription_option ) ) {
1091 + $current_subscription_option = wp_kses(
1092 + $current_subscription_option,
1093 + array(
1094 + 'a' => array(
1095 + 'href' => array(),
1096 + ),
1097 + )
1098 + );
1099 + }
1100 +
1101 + // A sub-key the site has never stored reads as unset everywhere this
1102 + // option is consumed, so an empty incoming value for it is not a change.
1103 + if (
1104 + null === $current_subscription_option
1105 + && ( '' === $subscription_option_value || false === $subscription_option_value )
1106 + ) {
1107 + continue;
1108 + }
1109 +
1110 + if ( $current_subscription_option === $subscription_option_value ) {
1111 + continue;
1112 + }
1113 +
1114 + $changed_subscription_options[ $subscription_option_key ] = $subscription_option_value;
1115 + }
1116 +
1117 + if ( empty( $changed_subscription_options ) ) {
1118 + break;
1119 + }
1120 +
1121 + // Get the value from the database or an empty array.
1122 + $old_subscription_options = get_option( 'subscription_options', array() );
1123 + $new_subscription_options = array_merge( $old_subscription_options, $changed_subscription_options );
1124 +
881 1125 if ( update_option( $key, $new_subscription_options ) ) {
882 - $updated[ $key ] = $filtered_value;
1126 + $updated[ $key ] = $changed_subscription_options;
883 1127 }
884 1128 break;
885 1129
886 1130 case 'woocommerce_onboarding_profile':
@@ -1023,9 +1267,11 @@
1023 1267 }
1024 1268 break;
1025 1269
1026 1270 case 'rss_use_excerpt':
1027 - update_option( 'rss_use_excerpt', (int) (bool) $value );
1271 + $sanitized_value = (int) (bool) $value;
1272 + update_option( $key, $sanitized_value );
1273 + $updated[ $key ] = $sanitized_value;
1028 1274 break;
1029 1275
1030 1276 case 'wpcom_subscription_emails_use_excerpt':
1031 1277 update_option( 'wpcom_subscription_emails_use_excerpt', (bool) $value );
@@ -1034,18 +1280,21 @@
1034 1280
1035 1281 case 'jetpack_subscriptions_reply_to':
1036 1282 require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
1037 1283 $to_set_value = Automattic\Jetpack\Modules\Subscriptions\Settings::is_valid_reply_to( $value )
1038 - ? $value
1039 - : Automattic\Jetpack\Modules\Subscriptions\Settings::get_default_reply_to();
1284 + ? (string) $value
1285 + : Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to;
1040 1286
1041 - update_option( 'jetpack_subscriptions_reply_to', (string) $to_set_value );
1042 - $updated[ $key ] = (bool) $value;
1287 + if ( update_option( $key, $to_set_value ) ) {
1288 + $updated[ $key ] = $to_set_value;
1289 + }
1043 1290 break;
1291 +
1044 1292 case 'jetpack_subscriptions_from_name':
1045 - $to_set_value = sanitize_text_field( $value );
1046 - update_option( 'jetpack_subscriptions_from_name', (string) $to_set_value );
1047 - $updated[ $key ] = (bool) $value;
1293 + $sanitized_value = sanitize_text_field( $value );
1294 + if ( update_option( $key, $sanitized_value ) ) {
1295 + $updated[ $key ] = $sanitized_value;
1296 + }
1048 1297 break;
1049 1298
1050 1299 case 'instant_search_enabled':
1051 1300 update_option( 'instant_search_enabled', (bool) $value );
@@ -1063,49 +1312,24 @@
1063 1312 update_option( 'lang_id', (int) $value );
1064 1313 $updated[ $key ] = (int) $value;
1065 1314 break;
1066 1315
1316 + case 'wpcom_newsletter_send_default':
1317 + update_option( 'wpcom_newsletter_send_default', (int) (bool) $value );
1318 + $updated[ $key ] = (int) (bool) $value;
1319 + break;
1320 +
1067 1321 case 'wpcom_featured_image_in_email':
1068 1322 update_option( 'wpcom_featured_image_in_email', (int) (bool) $value );
1069 1323 $updated[ $key ] = (int) (bool) $value;
1070 1324 break;
1071 1325
1072 - case 'wpcom_newsletter_categories':
1073 - $sanitized_category_ids = (array) $value;
1326 + case Jetpack_Newsletter_Category_Helper::NEWSLETTER_CATEGORIES_OPTION:
1327 + $update_newsletter_categories = Jetpack_Newsletter_Category_Helper::save_category_ids( (array) $value );
1328 + if ( $update_newsletter_categories ) {
1329 + $updated[ $key ] = $update_newsletter_categories;
1330 + }
1074 1331
1075 - array_walk_recursive(
1076 - $sanitized_category_ids,
1077 - function ( &$value ) {
1078 - if ( is_int( $value ) && $value > 0 ) {
1079 - return;
1080 - }
1081 -
1082 - $value = (int) $value;
1083 - if ( $value <= 0 ) {
1084 - $value = null;
1085 - }
1086 - }
1087 - );
1088 -
1089 - $sanitized_category_ids = array_unique(
1090 - array_filter(
1091 - $sanitized_category_ids,
1092 - function ( $category_id ) {
1093 - return $category_id !== null;
1094 - }
1095 - )
1096 - );
1097 -
1098 - $new_value = array_map(
1099 - function ( $category_id ) {
1100 - return array( 'term_id' => $category_id );
1101 - },
1102 - $sanitized_category_ids
1103 - );
1104 -
1105 - if ( update_option( $key, $new_value ) ) {
1106 - $updated[ $key ] = $new_value;
1107 - }
1108 1332 break;
1109 1333
1110 1334 case 'wpcom_newsletter_categories_enabled':
1111 1335 update_option( 'wpcom_newsletter_categories_enabled', (int) (bool) $value );
@@ -1121,8 +1345,13 @@
1121 1345 update_option( 'jetpack_subscribe_overlay_enabled', (int) (bool) $value );
1122 1346 $updated[ $key ] = (int) (bool) $value;
1123 1347 break;
1124 1348
1349 + case 'jetpack_subscribe_floating_button_enabled':
1350 + update_option( 'jetpack_subscribe_floating_button_enabled', (int) (bool) $value );
1351 + $updated[ $key ] = (int) (bool) $value;
1352 + break;
1353 +
1125 1354 case 'jetpack_subscriptions_subscribe_post_end_enabled':
1126 1355 update_option( 'jetpack_subscriptions_subscribe_post_end_enabled', (int) (bool) $value );
1127 1356 $updated[ $key ] = (int) (bool) $value;
1128 1357 break;
@@ -1204,8 +1433,24 @@
1204 1433 update_option( 'migration_source_site_domain', $value );
1205 1434 $updated[ $key ] = $value;
1206 1435 break;
1207 1436
1437 + case 'is_fully_managed_agency_site':
1438 + case 'wpcom_hide_action_bar':
1439 + $coerce_value = (int) (bool) $value;
1440 + if ( update_option( $key, $coerce_value ) ) {
1441 + $updated[ $key ] = (bool) $coerce_value;
1442 + }
1443 + break;
1444 +
1445 + case 'mcp_abilities':
1446 + $result = $this->set_site_mcp_abilities( $value );
1447 + if ( is_wp_error( $result ) ) {
1448 + return $result;
1449 + }
1450 + $updated[ $key ] = $this->get_site_mcp_abilities();
1451 + break;
1452 +
1208 1453 default:
1209 1454 // allow future versions of this endpoint to support additional settings keys.
1210 1455 if ( has_filter( 'site_settings_endpoint_update_' . $key ) ) {
1211 1456 /**
@@ -1213,13 +1458,22 @@
1213 1458 *
1214 1459 * @module json-api
1215 1460 *
1216 1461 * @since 3.9.3
1462 + * @since 13.6 Added the API object parameter.
1217 1463 *
1218 1464 * @param mixed $response_item A single site setting value.
1465 + * @param WPCOM_JSON_API_Site_Settings_Endpoint The API object parameter.
1219 1466 */
1220 - $value = apply_filters( 'site_settings_endpoint_update_' . $key, $value );
1221 - $updated[ $key ] = $value;
1467 + $value = apply_filters( 'site_settings_endpoint_update_' . $key, $value, $this );
1468 +
1469 + if ( is_wp_error( $value ) ) {
1470 + return $value;
1471 + }
1472 +
1473 + if ( $value ) {
1474 + $updated[ $key ] = $value;
1475 + }
1222 1476 break;
1223 1477 }
1224 1478 // no worries, we've already whitelisted and casted arguments above.
1225 1479 if ( update_option( $key, $value ) ) {
@@ -1289,25 +1543,8 @@
1289 1543 );
1290 1544 }
1291 1545
1292 1546 /**
1293 - * Get the value of the wpcom_subscription_emails_use_excerpt option.
1294 - * When the option is not set, it will return the value of the rss_use_excerpt option.
1295 - *
1296 - * @return bool
1297 - */
1298 - protected function get_wpcom_subscription_emails_use_excerpt_option() {
1299 - $wpcom_subscription_emails_use_excerpt = get_option( 'wpcom_subscription_emails_use_excerpt', null );
1300 -
1301 - if ( $wpcom_subscription_emails_use_excerpt === null ) {
1302 - $rss_use_excerpt = get_option( 'rss_use_excerpt', null );
1303 - $wpcom_subscription_emails_use_excerpt = $rss_use_excerpt === null ? false : $rss_use_excerpt;
1304 - }
1305 -
1306 - return (bool) $wpcom_subscription_emails_use_excerpt;
1307 - }
1308 -
1309 - /**
1310 1547 * Get the string value of the jetpack_subscriptions_reply_to option.
1311 1548 * When the option is not set, it will retun 'no-reply'.
1312 1549 *
1313 1550 * @return string
@@ -1315,9 +1552,9 @@
1315 1552 protected function get_subscriptions_reply_to_option() {
1316 1553 $reply_to = get_option( 'jetpack_subscriptions_reply_to', null );
1317 1554 if ( $reply_to === null ) {
1318 1555 require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
1319 - return Automattic\Jetpack\Modules\Subscriptions\Settings::get_default_reply_to();
1556 + return Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to;
1320 1557 }
1321 1558 return $reply_to;
1322 1559 }
1323 1560