From e933bdbca42cb9753abbff6904e2e5c763850284 Mon Sep 17 00:00:00 2001 From: Jeremy Massel <1123407+jkmassel@users.noreply.github.com> Date: Mon, 15 Sep 2025 14:49:27 -0600 Subject: [PATCH] Fix Endpoint Boolean Arg Types When the Jetpack endpoint types are listed, some are encoded like: ``` {"description":"Enable automatic rules - Protect your site against untrusted traffic sources with automatic security rules.","type":"boolean","default":false,"required":false} ``` while others are encoded like: ``` {"description":"Allow list - Allow a specific request IP.","type":"boolean","default":0,"required":false} ``` Typed JSON parsers will encode `default: 0` as an integer, not a boolean so the type matters here. This patch properly types these endpoint arguments. --- .../lib/class.core-rest-api-endpoints.php | 122 +++++++++--------- .../changelog/fix-endpoint-boolean-arg-types | 4 + 2 files changed, 65 insertions(+), 61 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/fix-endpoint-boolean-arg-types diff --git a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php index 9088ca8eee27b..a56f6e39a7002 100644 --- a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php +++ b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php @@ -2268,14 +2268,14 @@ public static function get_updateable_data_list( $selector = '' ) { ) ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'carousel', ), 'carousel_display_comments' => array( 'description' => esc_html__( 'Show comments area in carousel', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'carousel', ), @@ -2310,7 +2310,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'jetpack_portfolio' => array( 'description' => esc_html__( 'Enable or disable Jetpack portfolio post type.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -2324,7 +2324,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'jetpack_testimonial' => array( 'description' => esc_html__( 'Enable or disable Jetpack testimonial post type.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -2346,7 +2346,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'jetpack_waf_ip_block_list_enabled' => array( 'description' => esc_html__( 'Block list - Block a specific request IP.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'waf', ), @@ -2361,7 +2361,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'jetpack_waf_ip_allow_list_enabled' => array( 'description' => esc_html__( 'Allow list - Allow a specific request IP.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -2376,14 +2376,14 @@ public static function get_updateable_data_list( $selector = '' ) { 'jetpack_waf_share_data' => array( 'description' => esc_html__( 'Share basic data with Jetpack.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'waf', ), 'jetpack_waf_share_debug_data' => array( 'description' => esc_html__( 'Share detailed data with Jetpack.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'waf', ), @@ -2391,7 +2391,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'tiled_galleries' => array( 'description' => esc_html__( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'tiled-gallery', ), @@ -2417,14 +2417,14 @@ public static function get_updateable_data_list( $selector = '' ) { 'infinite_scroll' => array( 'description' => esc_html__( 'To infinity and beyond', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'infinite-scroll', ), 'infinite_scroll_google_analytics' => array( 'description' => esc_html__( 'Use Google Analytics with Infinite Scroll', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'infinite-scroll', ), @@ -2448,7 +2448,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'social_notifications_like' => array( 'description' => esc_html__( 'Send email notification when someone likes a post', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'likes', ), @@ -2457,14 +2457,14 @@ public static function get_updateable_data_list( $selector = '' ) { 'wpcom_publish_comments_with_markdown' => array( 'description' => esc_html__( 'Use Markdown for comments.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'markdown', ), 'wpcom_publish_posts_with_markdown' => array( 'description' => esc_html__( 'Use Markdown for posts.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'markdown', ), @@ -2473,7 +2473,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'monitor_receive_notifications' => array( 'description' => esc_html__( 'Receive Monitor Email Notifications.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'monitor', ), @@ -2575,7 +2575,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'sharedaddy_disable_resources' => array( 'description' => esc_html__( 'Disable CSS and JS', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'sharedaddy', ), @@ -2610,7 +2610,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'jetpack_sso_match_by_email' => array( 'description' => esc_html__( 'Match by Email', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'sso', ), @@ -2619,14 +2619,14 @@ public static function get_updateable_data_list( $selector = '' ) { 'stb_enabled' => array( 'description' => esc_html__( "Show a 'follow blog' option in the comment form", 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'stc_enabled' => array( 'description' => esc_html__( "Show a 'follow comments' option in the comment form", 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), @@ -2640,42 +2640,42 @@ public static function get_updateable_data_list( $selector = '' ) { 'wpcom_newsletter_categories_enabled' => array( 'description' => esc_html__( 'Whether the newsletter categories are enabled or not', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'wpcom_featured_image_in_email' => array( 'description' => esc_html__( 'Whether to include the featured image in the email or not', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_gravatar_in_email' => array( 'description' => esc_html__( 'Whether to show author avatar in the email byline', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_author_in_email' => array( 'description' => esc_html__( 'Whether to show author display name in the email byline', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_post_date_in_email' => array( 'description' => esc_html__( 'Whether to show date in the email byline', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'wpcom_subscription_emails_use_excerpt' => array( 'description' => esc_html__( 'Whether to use the excerpt in the email or not', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), @@ -2696,49 +2696,49 @@ public static function get_updateable_data_list( $selector = '' ) { 'sm_enabled' => array( 'description' => esc_html__( 'Show popup Subscribe modal to readers.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_subscribe_overlay_enabled' => array( 'description' => esc_html__( 'Show subscribe overlay on homepage.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_subscribe_floating_button_enabled' => array( 'description' => esc_html__( 'Show a floating subscribe button.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_subscriptions_subscribe_post_end_enabled' => array( 'description' => esc_html__( 'Add Subscribe block at the end of each post.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_subscriptions_login_navigation_enabled' => array( 'description' => esc_html__( 'Add Subscriber Login block to the navigation.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'jetpack_subscriptions_subscribe_navigation_enabled' => array( 'description' => esc_html__( 'Add Subscribe block to the navigation.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), 'social_notifications_subscribe' => array( 'description' => esc_html__( 'Send email notification when someone subscribes to my blog', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'subscriptions', ), @@ -2758,14 +2758,14 @@ public static function get_updateable_data_list( $selector = '' ) { 'show_headline' => array( 'description' => esc_html__( 'Highlight related content with a heading', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'related-posts', ), 'show_thumbnails' => array( 'description' => esc_html__( 'Show a thumbnail image where available', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'related-posts', ), @@ -2774,7 +2774,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'instant_search_enabled' => array( 'description' => esc_html__( 'Enable Instant Search', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'search', ), @@ -2782,7 +2782,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'has_jetpack_search_product' => array( 'description' => esc_html__( 'Has an active Jetpack Search product purchase', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -2790,7 +2790,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'search_auto_config' => array( 'description' => esc_html__( 'Trigger an auto config of instant search', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'search', ), @@ -2836,63 +2836,63 @@ public static function get_updateable_data_list( $selector = '' ) { 'enable_header_ad' => array( 'description' => esc_html__( 'Display an ad unit at the top of each page.', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_approved' => array( 'description' => esc_html__( 'Is site approved for WordAds?', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_second_belowpost' => array( 'description' => esc_html__( 'Display second ad below post?', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_inline_enabled' => array( 'description' => esc_html__( 'Display inline ad within post content?', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_display_front_page' => array( 'description' => esc_html__( 'Display ads on the front page?', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_display_post' => array( 'description' => esc_html__( 'Display ads on posts?', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_display_page' => array( 'description' => esc_html__( 'Display ads on pages?', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_display_archive' => array( 'description' => esc_html__( 'Display ads on archive pages?', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), 'wordads_custom_adstxt_enabled' => array( 'description' => esc_html__( 'Custom ads.txt', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), @@ -2907,7 +2907,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'wordads_ccpa_enabled' => array( 'description' => esc_html__( 'Enable support for California Consumer Privacy Act', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), @@ -2922,7 +2922,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'wordads_cmp_enabled' => array( 'description' => esc_html__( 'Enable GDPR Consent Management Banner for WordAds', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'wordads', ), @@ -2945,14 +2945,14 @@ public static function get_updateable_data_list( $selector = '' ) { 'admin_bar' => array( 'description' => esc_html__( 'Include a small chart in your admin bar with a 48-hour traffic snapshot.', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'stats', ), 'enable_odyssey_stats' => array( 'description' => esc_html__( 'Preview the new Jetpack Stats experience (Experimental).', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'stats', ), @@ -2980,14 +2980,14 @@ public static function get_updateable_data_list( $selector = '' ) { 'blog_id' => array( 'description' => esc_html__( 'Blog ID.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'stats', ), 'do_not_track' => array( 'description' => esc_html__( 'Do not track.', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'stats', ), @@ -3001,7 +3001,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'collapse_nudges' => array( 'description' => esc_html__( 'Collapse upgrade nudges', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'stats', ), @@ -3010,7 +3010,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'wpcom_reader_views_enabled' => array( 'description' => esc_html__( 'Show post views in the WordPress.com Reader.', 'jetpack' ), 'type' => 'boolean', - 'default' => 1, + 'default' => true, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -3019,7 +3019,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'akismet_show_user_comments_approved' => array( 'description' => '', 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -3036,7 +3036,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'dismiss_empty_stats_card' => array( 'description' => '', 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -3045,7 +3045,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'dismiss_dash_backup_getting_started' => array( 'description' => '', 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -3054,7 +3054,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'dismiss_dash_agencies_learn_more' => array( 'description' => '', 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'settings', ), @@ -3094,7 +3094,7 @@ public static function get_updateable_data_list( $selector = '' ) { 'videopress_private_enabled_for_site' => array( 'description' => esc_html__( 'Video Privacy: Restrict views to members of this site', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'videopress', ), @@ -3107,7 +3107,7 @@ public static function get_updateable_data_list( $selector = '' ) { $options['ai_seo_enhancer_enabled'] = array( 'description' => esc_html__( 'Automatically generate SEO title, SEO description, and image alt text for new posts.', 'jetpack' ), 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'seo-tools', ); @@ -3119,7 +3119,7 @@ public static function get_updateable_data_list( $selector = '' ) { $module_args = array( 'description' => '', 'type' => 'boolean', - 'default' => 0, + 'default' => false, 'validate_callback' => __CLASS__ . '::validate_boolean', 'jp_group' => 'modules', ); diff --git a/projects/plugins/jetpack/changelog/fix-endpoint-boolean-arg-types b/projects/plugins/jetpack/changelog/fix-endpoint-boolean-arg-types new file mode 100644 index 0000000000000..aa5dc92e504a8 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-endpoint-boolean-arg-types @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +REST API: Ensure endpoint argument registration uses valid types for booleans.