PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 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 All 506 releases
← All changes | _inc/lib/class.core-rest-api-endpoints.php +645 -811 12.0.3 → 16.3-a.5 View file →
@@ -8,8 +8,10 @@
8 8 use Automattic\Jetpack\Connection\Client;
9 9 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
10 10 use Automattic\Jetpack\Connection\Rest_Authentication;
11 11 use Automattic\Jetpack\Connection\REST_Connector;
12 +use Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT;
13 +use Automattic\Jetpack\Connection\SSO;
12 14 use Automattic\Jetpack\Jetpack_CRM_Data;
13 15 use Automattic\Jetpack\Plugins_Installer;
14 16 use Automattic\Jetpack\Stats\Options as Stats_Options;
15 17 use Automattic\Jetpack\Status\Host;
@@ -16,13 +18,11 @@
16 18 use Automattic\Jetpack\Status\Visitor;
17 19 use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection_Shared_Functions;
18 20 use Automattic\Jetpack\Waf\Waf_Compatibility;
19 21
20 -/**
21 - * Disable direct access.
22 - */
22 +// Disable direct access.
23 23 if ( ! defined( 'ABSPATH' ) ) {
24 - exit;
24 + exit( 0 );
25 25 }
26 26
27 27 // Load WP_Error for error messages.
28 28 require_once ABSPATH . '/wp-includes/class-wp-error.php';
@@ -32,8 +32,10 @@
32 32 // Load API endpoints that are synced with WP.com
33 33 // Each of these is a class that will register its own routes on 'rest_api_init'.
34 34 require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/load-wpcom-endpoints.php';
35 35
36 +require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
37 +
36 38 /**
37 39 * Class Jetpack_Core_Json_Api_Endpoints
38 40 *
39 41 * @since 4.3.0
@@ -70,8 +72,11 @@
70 72 $module_toggle_endpoint = new Jetpack_Core_API_Module_Toggle_Endpoint( new Jetpack_IXR_Client() );
71 73 $site_endpoint = new Jetpack_Core_API_Site_Endpoint();
72 74 $widget_endpoint = new Jetpack_Core_API_Widget_Endpoint();
73 75
76 + // My Jetpack and Agents Manager register the same controller; its guard keeps the route registered once.
77 + ( new REST_Jetpack_AI_JWT() )->register_rest_route();
78 +
74 79 register_rest_route(
75 80 'jetpack/v4',
76 81 'plans',
77 82 array(
@@ -100,32 +105,10 @@
100 105 'permission_callback' => __CLASS__ . '::disconnect_site_permission_callback',
101 106 )
102 107 );
103 108
104 - // Test current connection status of Jetpack.
105 109 register_rest_route(
106 110 'jetpack/v4',
107 - '/connection/test',
108 - array(
109 - 'methods' => WP_REST_Server::READABLE,
110 - 'callback' => __CLASS__ . '::jetpack_connection_test',
111 - 'permission_callback' => __CLASS__ . '::manage_modules_permission_check',
112 - )
113 - );
114 -
115 - // Endpoint specific for privileged servers to request detailed debug information.
116 - register_rest_route(
117 - 'jetpack/v4',
118 - '/connection/test-wpcom/',
119 - array(
120 - 'methods' => WP_REST_Server::READABLE,
121 - 'callback' => __CLASS__ . '::jetpack_connection_test_for_external',
122 - 'permission_callback' => __CLASS__ . '::view_jetpack_connection_test_check',
123 - )
124 - );
125 -
126 - register_rest_route(
127 - 'jetpack/v4',
128 111 '/rewind',
129 112 array(
130 113 'methods' => WP_REST_Server::READABLE,
131 114 'callback' => __CLASS__ . '::get_rewind_data',
@@ -178,33 +161,11 @@
178 161 ),
179 162 )
180 163 );
181 164
182 - // Disconnect/unlink user from WordPress.com servers.
165 + // Get current site features.
183 166 register_rest_route(
184 167 'jetpack/v4',
185 - '/connection/user',
186 - array(
187 - 'methods' => WP_REST_Server::EDITABLE,
188 - 'callback' => __CLASS__ . '::unlink_user',
189 - 'permission_callback' => __CLASS__ . '::unlink_user_permission_callback',
190 - )
191 - );
192 -
193 - // Get current site data.
194 - register_rest_route(
195 - 'jetpack/v4',
196 - '/site',
197 - array(
198 - 'methods' => WP_REST_Server::READABLE,
199 - 'callback' => __CLASS__ . '::get_site_data',
200 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
201 - )
202 - );
203 -
204 - // Get current site data.
205 - register_rest_route(
206 - 'jetpack/v4',
207 168 '/site/features',
208 169 array(
209 170 'methods' => WP_REST_Server::READABLE,
210 171 'callback' => array( $site_endpoint, 'get_features' ),
@@ -588,103 +549,8 @@
588 549 ),
589 550 )
590 551 );
591 552
592 - register_rest_route(
593 - 'jetpack/v4',
594 - '/recommendations/data',
595 - array(
596 - array(
597 - 'methods' => WP_REST_Server::READABLE,
598 - 'callback' => __CLASS__ . '::get_recommendations_data',
599 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
600 - ),
601 - array(
602 - 'methods' => WP_REST_Server::EDITABLE,
603 - 'callback' => __CLASS__ . '::update_recommendations_data',
604 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
605 - 'args' => array(
606 - 'data' => array(
607 - 'required' => true,
608 - 'type' => 'object',
609 - 'validate_callback' => __CLASS__ . '::validate_recommendations_data',
610 - ),
611 - ),
612 - ),
613 - )
614 - );
615 -
616 - register_rest_route(
617 - 'jetpack/v4',
618 - '/recommendations/step',
619 - array(
620 - array(
621 - 'methods' => WP_REST_Server::READABLE,
622 - 'callback' => __CLASS__ . '::get_recommendations_step',
623 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
624 - ),
625 - array(
626 - 'methods' => WP_REST_Server::EDITABLE,
627 - 'callback' => __CLASS__ . '::update_recommendations_step',
628 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
629 - 'args' => array(
630 - 'step' => array(
631 - 'required' => true,
632 - 'type' => 'string',
633 - 'validate_callback' => __CLASS__ . '::validate_string',
634 - ),
635 - ),
636 - ),
637 - )
638 - );
639 -
640 - register_rest_route(
641 - 'jetpack/v4',
642 - '/recommendations/product-suggestions',
643 - array(
644 - array(
645 - 'methods' => WP_REST_Server::READABLE,
646 - 'callback' => __CLASS__ . '::get_recommendations_product_suggestions',
647 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
648 - ),
649 - )
650 - );
651 -
652 - register_rest_route(
653 - 'jetpack/v4',
654 - '/recommendations/upsell',
655 - array(
656 - array(
657 - 'methods' => WP_REST_Server::READABLE,
658 - 'callback' => __CLASS__ . '::get_recommendations_upsell',
659 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
660 - ),
661 - )
662 - );
663 -
664 - register_rest_route(
665 - 'jetpack/v4',
666 - '/recommendations/conditional',
667 - array(
668 - array(
669 - 'methods' => WP_REST_Server::READABLE,
670 - 'callback' => __CLASS__ . '::get_conditional_recommendations',
671 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
672 - ),
673 - )
674 - );
675 -
676 - // Get site discount.
677 - register_rest_route(
678 - 'jetpack/v4',
679 - '/site/discount',
680 - array(
681 - 'methods' => WP_REST_Server::READABLE,
682 - 'callback' => __CLASS__ . '::get_site_discount',
683 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
684 - )
685 - );
686 -
687 553 /*
688 554 * Manage the Jetpack CRM plugin's integration with Jetpack contact forms.
689 555 */
690 556 register_rest_route(
@@ -739,191 +605,107 @@
739 605 'permission_callback' => __CLASS__ . '::manage_modules_permission_check',
740 606 )
741 607 );
742 608
743 - // Get Jetpack introduction offers
609 + // Save subscriber token and redirect
744 610 register_rest_route(
745 611 'jetpack/v4',
746 - '/intro-offers',
612 + '/subscribers/auth',
747 613 array(
748 614 'methods' => WP_REST_Server::READABLE,
749 - 'callback' => __CLASS__ . '::get_intro_offers',
750 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
615 + 'callback' => __CLASS__ . '::set_subscriber_cookie_and_redirect',
616 + 'permission_callback' => '__return_true',
617 + 'args' => array(
618 + 'redirect_url' => array(
619 + 'required' => true,
620 + 'description' => __( 'The URL to redirect to.', 'jetpack' ),
621 + 'validate_callback' => 'wp_http_validate_url',
622 + 'sanitize_callback' => 'sanitize_url',
623 + 'type' => 'string',
624 + 'format' => 'uri',
625 + ),
626 + ),
751 627 )
752 628 );
753 - }
754 629
755 - /**
756 - * Get the data for the recommendations
757 - *
758 - * @return array Recommendations data
759 - */
760 - public static function get_recommendations_data() {
761 - return Jetpack_Recommendations::get_recommendations_data();
762 - }
630 + /**
631 + * Get the list of available Jetpack features.
632 + *
633 + * @since 13.9
634 + */
635 + register_rest_route(
636 + 'jetpack/v4',
637 + '/features/available',
638 + array(
639 + 'methods' => WP_REST_Server::READABLE,
640 + 'callback' => array( static::class, 'get_features_available' ),
641 + 'permission_callback' => array( static::class, 'get_features_permission_check' ),
642 + )
643 + );
763 644
764 - /**
765 - * Update the data for the recommendations
766 - *
767 - * @param WP_REST_Request $request The request.
768 - *
769 - * @return bool true
770 - */
771 - public static function update_recommendations_data( $request ) {
772 - $data = $request['data'];
773 - Jetpack_Recommendations::update_recommendations_data( $data );
774 -
775 - return true;
776 - }
777 -
778 - /**
779 - * Get the data for the recommendations
780 - *
781 - * @return array Recommendations data
782 - */
783 - public static function get_recommendations_step() {
784 - return Jetpack_Recommendations::get_recommendations_step();
785 - }
786 -
787 - /**
788 - * Update the step for the recommendations
789 - *
790 - * @param WP_REST_Request $request The request.
791 - *
792 - * @return bool true
793 - */
794 - public static function update_recommendations_step( $request ) {
795 - $step = $request['step'];
796 - Jetpack_Recommendations::update_recommendations_step( $step );
797 -
798 - return true;
799 - }
800 -
801 - /**
802 - * Get product suggestions for the recommendations
803 - *
804 - * @return string|WP_Error The response from the wpcom product suggestions endpoint as a JSON object.
805 - */
806 - public static function get_recommendations_product_suggestions() {
807 - $blog_id = Jetpack_Options::get_option( 'id' );
808 - if ( ! $blog_id ) {
809 - return new WP_Error( 'site_not_registered', esc_html__( 'Site not registered.', 'jetpack' ) );
810 - }
811 -
812 - $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() );
813 - if ( ! $user_connected ) {
814 - return wp_json_encode( array() );
815 - }
816 -
817 - $request_path = sprintf( '/sites/%s/jetpack-recommendations/product-suggestions?locale=' . get_user_locale(), $blog_id );
818 - $wpcom_request = Client::wpcom_json_api_request_as_user(
819 - $request_path,
820 - '2',
645 + /**
646 + * Get the list of enabled Jetpack features.
647 + *
648 + * @since 13.9
649 + */
650 + register_rest_route(
651 + 'jetpack/v4',
652 + '/features/enabled',
821 653 array(
822 - 'method' => 'GET',
823 - 'headers' => array(
824 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
825 - ),
654 + 'methods' => WP_REST_Server::READABLE,
655 + 'callback' => array( static::class, 'get_features_enabled' ),
656 + 'permission_callback' => array( static::class, 'get_features_permission_check' ),
826 657 )
827 658 );
828 -
829 - $response_code = wp_remote_retrieve_response_code( $wpcom_request );
830 - if ( 200 === $response_code ) {
831 - return json_decode( wp_remote_retrieve_body( $wpcom_request ) );
832 - } else {
833 - return new WP_Error(
834 - 'failed_to_fetch_data',
835 - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
836 - array( 'status' => $response_code )
837 - );
838 - }
839 659 }
840 660
841 661 /**
842 - * Get the upsell for the recommendations
662 + * Ask WPCOM for a JWT token to use for OpenAI conversations.
843 663 *
844 - * @return string The response from the wpcom upsell endpoint as a JSON object
664 + * @deprecated since 16.2
665 + * @see Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT::get_jwt()
666 + *
667 + * @return array|WP_Error The token and blog ID, or the error from WPCOM.
845 668 */
846 - public static function get_recommendations_upsell() {
847 - $blog_id = Jetpack_Options::get_option( 'id' );
848 - if ( ! $blog_id ) {
849 - return new WP_Error( 'site_not_registered', esc_html__( 'Site not registered.', 'jetpack' ) );
850 - }
669 + public static function get_openai_jwt() {
670 + _deprecated_function( __METHOD__, 'jetpack-16.2', '\Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT::get_jwt' );
851 671
852 - $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() );
853 - if ( ! $user_connected ) {
854 - $response = array(
855 - 'hide_upsell' => true,
856 - );
672 + $response = ( new REST_Jetpack_AI_JWT() )->get_jwt();
857 673
674 + if ( is_wp_error( $response ) ) {
858 675 return $response;
859 676 }
860 677
861 - $request_path = sprintf( '/sites/%s/jetpack-recommendations/upsell?locale=' . get_user_locale(), $blog_id );
862 - $wpcom_request = Client::wpcom_json_api_request_as_user(
863 - $request_path,
864 - '2',
865 - array(
866 - 'method' => 'GET',
867 - 'headers' => array(
868 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
869 - ),
870 - )
871 - );
872 -
873 - $response_code = wp_remote_retrieve_response_code( $wpcom_request );
874 - if ( 200 === $response_code ) {
875 - return json_decode( wp_remote_retrieve_body( $wpcom_request ) );
876 - } else {
877 - return new WP_Error(
878 - 'failed_to_fetch_data',
879 - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
880 - array( 'status' => $response_code )
881 - );
882 - }
678 + // Pre-deprecation callers expect the raw array, not a WP_REST_Response.
679 + return $response->get_data();
883 680 }
884 681
885 682 /**
886 - * Get conditional recommendations data.
683 + * Set subscriber cookie and redirect
887 684 *
888 - * @return array Conditional recommendations data.
889 - */
890 - public static function get_conditional_recommendations() {
891 - return Jetpack_Recommendations::get_conditional_recommendations();
892 - }
893 -
894 - /**
895 - * Validate the recommendations data
685 + * @param \WP_Rest_Request $request The URL to redirect to.
896 686 *
897 - * @param array $value Value to check received by request.
898 - * @param WP_REST_Request $request The request sent to the WP REST API.
899 - * @param string $param Name of the parameter passed to endpoint holding $value.
900 - *
901 - * @return bool|WP_Error
687 + * @return WP_Error|WP_REST_Response
902 688 */
903 - public static function validate_recommendations_data( $value, $request, $param ) {
904 - if ( ! is_array( $value ) ) {
905 - /* translators: Name of a parameter that must be an object */
906 - return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an object.', 'jetpack' ), $param ) );
689 + public static function set_subscriber_cookie_and_redirect( $request ) {
690 + require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
691 + $subscription_service = \Automattic\Jetpack\Extensions\Premium_Content\subscription_service();
692 + // Note: get_and_set_token_from_request() sets the subscriber cookie as a side effect.
693 + // The cookie is set regardless of the redirect target below; only the redirect is gated.
694 + $token = $subscription_service->get_and_set_token_from_request();
695 + $payload = $subscription_service->decode_token( $token );
696 + $is_valid_token = ! empty( $payload );
697 + if ( ! $is_valid_token ) {
698 + return new WP_Error( 'invalid-token', 'Invalid Token', array( 'status' => 403 ) );
907 699 }
908 700
909 - foreach ( $value as $answer ) {
910 - if ( is_array( $answer ) ) {
911 - $validate = self::validate_array_of_strings( $answer, $request, $param );
912 - } elseif ( is_string( $answer ) ) {
913 - $validate = self::validate_string( $answer, $request, $param );
914 - } elseif ( $answer === null ) {
915 - $validate = true;
916 - } else {
917 - $validate = self::validate_boolean( $answer, $request, $param );
918 - }
919 -
920 - if ( is_wp_error( $validate ) ) {
921 - return $validate;
922 - }
701 + // Only redirect to the current site, not to an arbitrary host.
702 + $redirect_url = wp_validate_redirect( $request['redirect_url'], '' );
703 + if ( ! $redirect_url ) {
704 + return new WP_Error( 'invalid-redirect', 'Invalid Redirect URL', array( 'status' => 400 ) );
923 705 }
924 706
925 - return true;
707 + return new WP_REST_Response( null, 302, array( 'location' => $redirect_url ) );
926 708 }
927 709
928 710 /**
929 711 * Return a purchase token used for site-connected (non user-authenticated) checkout.
@@ -1053,9 +835,9 @@
1053 835 * @since 6.6.0
1054 836 *
1055 837 * @param WP_REST_Request $request The request sent to the WP REST API.
1056 838 *
1057 - * @return array|wp-error
839 + * @return array|WP_Error
1058 840 */
1059 841 public static function is_site_verified_and_token( $request ) {
1060 842 /**
1061 843 * Return an error if the site uses a Maintenance / Coming Soon plugin
@@ -1081,8 +863,9 @@
1081 863 || Jetpack::is_plugin_active( 'mojo-under-construction/mojo-contruction.php' ) && 1 == $under_construction_activation_status // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1082 864 || ( Jetpack::is_plugin_active( 'under-construction-page/under-construction.php' ) && isset( $ucp_options['status'] ) && 1 == $ucp_options['status'] ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1083 865 || ( Jetpack::is_plugin_active( 'ultimate-under-construction/ultimate-under-construction.php' ) && isset( $uuc_settings['enable'] ) && 1 == $uuc_settings['enable'] ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1084 866 || ( Jetpack::is_plugin_active( 'coming-soon/coming-soon.php' ) && isset( $csp4['status'] ) && ( 1 == $csp4['status'] || 2 == $csp4['status'] ) ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
867 + ||
1085 868 /**
1086 869 * Allow plugins to mark a site as "under construction".
1087 870 *
1088 871 * @since 6.7.0
@@ -1088,9 +871,9 @@
1088 871 * @since 6.7.0
1089 872 *
1090 873 * @param false bool Is the site under construction? Default to false.
1091 874 */
1092 - || true === apply_filters( 'jetpack_is_under_construction_plugin', false )
875 + true === apply_filters( 'jetpack_is_under_construction_plugin', false )
1093 876 ) {
1094 877 return new WP_Error( 'forbidden', __( 'Site is under construction and cannot be verified', 'jetpack' ) );
1095 878 }
1096 879
@@ -1162,9 +945,9 @@
1162 945 * @since 4.3.0
1163 946 *
1164 947 * @param WP_REST_Request $request The request sent to the WP REST API.
1165 948 *
1166 - * @return array|wp-error
949 + * @return array|WP_Error
1167 950 */
1168 951 public static function dismiss_notice( $request ) {
1169 952 $notice = $request['notice'];
1170 953
@@ -1229,24 +1012,20 @@
1229 1012
1230 1013 /**
1231 1014 * Verify that a user can use the /connection/user endpoint. Has to be a registered user and be currently linked.
1232 1015 *
1016 + * @uses Automattic\Jetpack\Connection\Manager::is_user_connected();)
1017 + *
1018 + * @deprecated since Jetpack 14.4.0
1019 + * @see Automattic\Jetpack\Connection\REST_Connector::unlink_user_permission_callback()
1020 + *
1233 1021 * @since 4.3.0
1234 1022 *
1235 - * @uses Automattic\Jetpack\Connection\Manager::is_user_connected();)
1236 - *
1237 1023 * @return bool|WP_Error True if user is able to unlink.
1238 1024 */
1239 1025 public static function unlink_user_permission_callback() {
1240 - if ( current_user_can( 'jetpack_connect_user' ) && ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() ) ) {
1241 - return true;
1242 - }
1243 -
1244 - return new WP_Error(
1245 - 'invalid_user_permission_unlink_user',
1246 - REST_Connector::get_user_permissions_error_msg(),
1247 - array( 'status' => rest_authorization_required_code() )
1248 - );
1026 + _deprecated_function( __METHOD__, 'jetpack-14.4.0', 'Automattic\Jetpack\Connection\REST_Connector::unlink_user_permission_callback()' );
1027 + return REST_Connector::unlink_user_permission_callback();
1249 1028 }
1250 1029
1251 1030 /**
1252 1031 * Verify that user can manage Jetpack modules.
@@ -1381,139 +1160,8 @@
1381 1160 );
1382 1161 }
1383 1162
1384 1163 /**
1385 - * Test connection status for this Jetpack site.
1386 - *
1387 - * @since 6.8.0
1388 - *
1389 - * @return array|WP_Error WP_Error returned if connection test does not succeed.
1390 - */
1391 - public static function jetpack_connection_test() {
1392 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1393 - $cxntests = new Jetpack_Cxn_Tests();
1394 -
1395 - if ( $cxntests->pass() ) {
1396 - return rest_ensure_response(
1397 - array(
1398 - 'code' => 'success',
1399 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1400 - )
1401 - );
1402 - } else {
1403 - return $cxntests->output_fails_as_wp_error();
1404 - }
1405 - }
1406 -
1407 - /**
1408 - * Test connection permission check method.
1409 - *
1410 - * @since 7.1.0
1411 - *
1412 - * @return bool
1413 - */
1414 - public static function view_jetpack_connection_test_check() {
1415 - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- This is verifying the trusted caller via a shared private key and timestamp.
1416 - if ( ! isset( $_GET['signature'], $_GET['timestamp'], $_GET['url'] ) ) {
1417 - return false;
1418 - }
1419 - $signature = base64_decode( wp_unslash( $_GET['signature'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1420 -
1421 - $signature_data = wp_json_encode(
1422 - array(
1423 - 'rest_route' => isset( $_GET['rest_route'] ) ? filter_var( wp_unslash( $_GET['rest_route'] ) ) : null,
1424 - 'timestamp' => (int) $_GET['timestamp'],
1425 - 'url' => esc_url_raw( wp_unslash( $_GET['url'] ) ),
1426 - )
1427 - );
1428 -
1429 - if (
1430 - ! function_exists( 'openssl_verify' )
1431 - || 1 !== openssl_verify(
1432 - $signature_data,
1433 - $signature,
1434 - JETPACK__DEBUGGER_PUBLIC_KEY
1435 - )
1436 - ) {
1437 - return false;
1438 - }
1439 -
1440 - // signature timestamp must be within 5min of current time.
1441 - if ( abs( time() - (int) $_GET['timestamp'] ) > 300 ) {
1442 - return false;
1443 - }
1444 -
1445 - // phpcs:enable WordPress.Security.NonceVerification.Recommended
1446 -
1447 - return true;
1448 - }
1449 -
1450 - /**
1451 - * Test connection status for this Jetpack site, encrypt the results for decryption by a third-party.
1452 - *
1453 - * @since 7.1.0
1454 - *
1455 - * @return array|mixed|object|WP_Error
1456 - */
1457 - public static function jetpack_connection_test_for_external() {
1458 - // Since we are running this test for inclusion in the WP.com testing suite, let's not try to run them as part of these results.
1459 - add_filter( 'jetpack_debugger_run_self_test', '__return_false' );
1460 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1461 - $cxntests = new Jetpack_Cxn_Tests();
1462 -
1463 - if ( $cxntests->pass() ) {
1464 - $result = array(
1465 - 'code' => 'success',
1466 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1467 - );
1468 - } else {
1469 - $error = $cxntests->output_fails_as_wp_error(); // Using this so the output is similar both ways.
1470 - $errors = array();
1471 -
1472 - // Borrowed from WP_REST_Server::error_to_response().
1473 - foreach ( (array) $error->errors as $code => $messages ) {
1474 - foreach ( (array) $messages as $message ) {
1475 - $errors[] = array(
1476 - 'code' => $code,
1477 - 'message' => $message,
1478 - 'data' => $error->get_error_data( $code ),
1479 - );
1480 - }
1481 - }
1482 -
1483 - $result = ( ! empty( $errors ) ) ? $errors[0] : null;
1484 - if ( count( $errors ) > 1 ) {
1485 - // Remove the primary error.
1486 - array_shift( $errors );
1487 - $result['additional_errors'] = $errors;
1488 - }
1489 - }
1490 -
1491 - $result = wp_json_encode( $result );
1492 -
1493 - $encrypted = $cxntests->encrypt_string_for_wpcom( $result );
1494 -
1495 - if ( ! $encrypted || ! is_array( $encrypted ) ) {
1496 - return rest_ensure_response(
1497 - array(
1498 - 'code' => 'action_required',
1499 - 'message' => 'Please request results from the in-plugin debugger',
1500 - )
1501 - );
1502 - }
1503 -
1504 - return rest_ensure_response(
1505 - array(
1506 - 'code' => 'response',
1507 - 'debug' => array(
1508 - 'data' => $encrypted['data'],
1509 - 'key' => $encrypted['key'],
1510 - ),
1511 - )
1512 - );
1513 - }
1514 -
1515 - /**
1516 1164 * Fetch information about the Rewind status of the site.
1517 1165 */
1518 1166 public static function rewind_data() {
1519 1167 $site_id = Jetpack_Options::get_option( 'id' );
@@ -1556,9 +1204,9 @@
1556 1204 return rest_ensure_response(
1557 1205 array(
1558 1206 'code' => 'success',
1559 1207 'message' => esc_html__( 'Backup & Scan data correctly received.', 'jetpack' ),
1560 - 'data' => wp_json_encode( $rewind_data ),
1208 + 'data' => wp_json_encode( $rewind_data, JSON_UNESCAPED_SLASHES ),
1561 1209 )
1562 1210 );
1563 1211 }
1564 1212
@@ -1639,9 +1287,9 @@
1639 1287 return rest_ensure_response(
1640 1288 array(
1641 1289 'code' => 'success',
1642 1290 'message' => esc_html__( 'Scan state correctly received.', 'jetpack' ),
1643 - 'data' => wp_json_encode( $scan_state ),
1291 + 'data' => wp_json_encode( $scan_state, JSON_UNESCAPED_SLASHES ),
1644 1292 )
1645 1293 );
1646 1294 }
1647 1295
@@ -1688,41 +1336,8 @@
1688 1336 return new WP_Error( 'disconnect_failed', esc_html__( 'Was not able to disconnect the site. Please try again.', 'jetpack' ), array( 'status' => 400 ) );
1689 1337 }
1690 1338
1691 1339 /**
1692 - * Registers the Jetpack site
1693 - *
1694 - * @deprecated since Jetpack 9.7.0
1695 - * @see Automattic\Jetpack\Connection\REST_Connector::connection_register()
1696 - *
1697 - * @param WP_REST_Request $request The request sent to the WP REST API.
1698 - *
1699 - * @return bool|WP_Error True if Jetpack successfully registered
1700 - */
1701 - public static function register_site( $request ) {
1702 - _deprecated_function( __METHOD__, 'jetpack-9.7.0', '\Automattic\Jetpack\Connection\REST_Connector::connection_register' );
1703 -
1704 - if ( ! wp_verify_nonce( $request->get_param( 'registration_nonce' ), 'jetpack-registration-nonce' ) ) {
1705 - return new WP_Error( 'invalid_nonce', __( 'Unable to verify your request.', 'jetpack' ), array( 'status' => 403 ) );
1706 - }
1707 -
1708 - if ( isset( $request['from'] ) ) {
1709 - Jetpack::connection()->add_register_request_param( 'from', (string) $request['from'] );
1710 - }
1711 - $response = Jetpack::connection()->try_registration();
1712 -
1713 - if ( is_wp_error( $response ) ) {
1714 - return $response;
1715 - }
1716 -
1717 - return rest_ensure_response(
1718 - array(
1719 - 'authorizeUrl' => Jetpack::build_authorize_url( false ),
1720 - )
1721 - );
1722 - }
1723 -
1724 - /**
1725 1340 * Gets a new connect raw URL with fresh nonce.
1726 1341 *
1727 1342 * @uses Jetpack::disconnect();
1728 1343 * @since 4.3.0
@@ -1731,10 +1346,10 @@
1731 1346 *
1732 1347 * @return string|WP_Error A raw URL if the connection URL could be built; error message otherwise.
1733 1348 */
1734 1349 public static function build_connect_url( $request = array() ) {
1735 - $from = isset( $request['from'] ) ? $request['from'] : false;
1736 - $redirect = isset( $request['redirect'] ) ? $request['redirect'] : false;
1350 + $from = $request['from'] ?? false;
1351 + $redirect = $request['redirect'] ?? false;
1737 1352
1738 1353 $url = Jetpack::init()->build_connect_url( true, $redirect, $from );
1739 1354 if ( $url ) {
1740 1355 return rest_ensure_response( $url );
@@ -1757,9 +1372,9 @@
1757 1372 */
1758 1373 public static function get_user_connection_data() {
1759 1374 _deprecated_function( __METHOD__, 'jetpack-10.0.0', '\Automattic\Jetpack\Connection\REST_Connector::get_user_connection_data' );
1760 1375
1761 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class.jetpack-react-page.php';
1376 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-redux-state-helper.php';
1762 1377
1763 1378 $connection_owner = ( new Connection_Manager() )->get_connection_owner();
1764 1379 $owner_display_name = false === $connection_owner ? null : $connection_owner->data->display_name;
1765 1380
@@ -1772,30 +1387,21 @@
1772 1387
1773 1388 /**
1774 1389 * Unlinks current user from the WordPress.com Servers.
1775 1390 *
1776 - * @since 4.3.0
1391 + * @param WP_REST_Request $request The request sent to the WP REST API.
1777 1392 * @uses Automattic\Jetpack\Connection\Manager->disconnect_user
1778 1393 *
1779 - * @param WP_REST_Request $request The request sent to the WP REST API.
1394 + * @deprecated since Jetpack 14.4.0
1395 + * @see Automattic\Jetpack\Connection\REST_Connector::unlink_user()
1780 1396 *
1397 + * @since 4.3.0
1398 + *
1781 1399 * @return bool|WP_Error True if user successfully unlinked.
1782 1400 */
1783 1401 public static function unlink_user( $request ) {
1784 -
1785 - if ( ! isset( $request['linked'] ) || false !== $request['linked'] ) {
1786 - return new WP_Error( 'invalid_param', esc_html__( 'Invalid Parameter', 'jetpack' ), array( 'status' => 404 ) );
1787 - }
1788 -
1789 - if ( ( new Connection_Manager( 'jetpack' ) )->disconnect_user() ) {
1790 - return rest_ensure_response(
1791 - array(
1792 - 'code' => 'success',
1793 - )
1794 - );
1795 - }
1796 -
1797 - return new WP_Error( 'unlink_user_failed', esc_html__( 'Was not able to unlink the user. Please try again.', 'jetpack' ), array( 'status' => 400 ) );
1402 + _deprecated_function( __METHOD__, 'jetpack-14.4.0', 'Automattic\Jetpack\Connection\REST_Connector::unlink_user()' );
1403 + return REST_Connector::unlink_user( $request );
1798 1404 }
1799 1405
1800 1406 /**
1801 1407 * Gets current user's tracking settings.
@@ -1854,9 +1460,9 @@
1854 1460 'Content-Type' => 'application/json',
1855 1461 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
1856 1462 ),
1857 1463 ),
1858 - wp_json_encode( $request->get_params() )
1464 + wp_json_encode( $request->get_params(), JSON_UNESCAPED_SLASHES )
1859 1465 );
1860 1466 if ( ! is_wp_error( $response ) ) {
1861 1467 $response = json_decode( wp_remote_retrieve_body( $response ), true );
1862 1468 }
@@ -1868,93 +1474,30 @@
1868 1474 /**
1869 1475 * Fetch site data from .com including the site's current plan and the site's products.
1870 1476 *
1871 1477 * @since 5.5.0
1478 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\Manager::get_connected_site_data().
1872 1479 *
1873 1480 * @return stdClass|WP_Error
1874 1481 */
1875 1482 public static function site_data() {
1876 - $site_id = Jetpack_Options::get_option( 'id' );
1483 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\Manager::get_connected_site_data' );
1877 1484
1878 - if ( ! $site_id ) {
1879 - return new WP_Error( 'site_id_missing', '', array( 'api_error_code' => __( 'site_id_missing', 'jetpack' ) ) );
1880 - }
1485 + return ( new Connection_Manager() )->get_connected_site_data();
1486 + }
1881 1487
1882 - $args = array( 'headers' => array() );
1883 -
1884 - // Allow use a store sandbox. Internal ref: PCYsg-IA-p2.
1885 - if ( isset( $_COOKIE ) && isset( $_COOKIE['store_sandbox'] ) ) {
1886 - $secret = filter_var( wp_unslash( $_COOKIE['store_sandbox'] ) );
1887 - $args['headers']['Cookie'] = "store_sandbox=$secret;";
1888 - }
1889 -
1890 - $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ) . '?force=wpcom', '1.1', $args );
1891 - $body = wp_remote_retrieve_body( $response );
1892 - $data = $body ? json_decode( $body ) : null;
1893 -
1894 - if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
1895 - $error_info = array(
1896 - 'api_error_code' => null,
1897 - 'api_http_code' => wp_remote_retrieve_response_code( $response ),
1898 - );
1899 -
1900 - if ( is_wp_error( $response ) ) {
1901 - $error_info['api_error_code'] = $response->get_error_code() ? wp_strip_all_tags( $response->get_error_code() ) : null;
1902 - } elseif ( $data && ! empty( $data->error ) ) {
1903 - $error_info['api_error_code'] = $data->error;
1904 - }
1905 -
1906 - return new WP_Error( 'site_data_fetch_failed', '', $error_info );
1907 - }
1908 -
1909 - Jetpack_Plan::update_from_sites_response( $response );
1910 -
1911 - return $data;
1912 - }
1913 1488 /**
1914 1489 * Get site data, including for example, the site's current plan.
1915 1490 *
1491 + * @since 4.3.0
1492 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\REST_Connector::site_data_response().
1493 + *
1916 1494 * @return WP_Error|WP_HTTP_Response|WP_REST_Response
1917 - * @since 4.3.0
1918 1495 */
1919 1496 public static function get_site_data() {
1920 - $site_data = self::site_data();
1497 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\REST_Connector::site_data_response' );
1921 1498
1922 - if ( ! is_wp_error( $site_data ) ) {
1923 -
1924 - /**
1925 - * Fires when the site data was successfully returned from the /sites/%d wpcom endpoint.
1926 - *
1927 - * @since 8.7.0
1928 - */
1929 - do_action( 'jetpack_get_site_data_success' );
1930 - return rest_ensure_response(
1931 - array(
1932 - 'code' => 'success',
1933 - 'message' => esc_html__( 'Site data correctly received.', 'jetpack' ),
1934 - 'data' => wp_json_encode( $site_data ),
1935 - )
1936 - );
1937 - }
1938 -
1939 - $error_data = $site_data->get_error_data();
1940 -
1941 - if ( empty( $error_data['api_error_code'] ) ) {
1942 - $error_message = esc_html__( 'Failed fetching site data from WordPress.com. If the problem persists, try reconnecting Jetpack.', 'jetpack' );
1943 - } else {
1944 - /* translators: %s is an error code (e.g. `token_mismatch`) */
1945 - $error_message = sprintf( esc_html__( 'Failed fetching site data from WordPress.com (%s). If the problem persists, try reconnecting Jetpack.', 'jetpack' ), $error_data['api_error_code'] );
1946 - }
1947 -
1948 - return new WP_Error(
1949 - $site_data->get_error_code(),
1950 - $error_message,
1951 - array(
1952 - 'status' => 400,
1953 - 'api_error_code' => empty( $error_data['api_error_code'] ) ? null : $error_data['api_error_code'],
1954 - 'api_http_code' => empty( $error_data['api_http_code'] ) ? null : $error_data['api_http_code'],
1955 - )
1956 - );
1499 + return REST_Connector::site_data_response();
1957 1500 }
1958 1501
1959 1502 /**
1960 1503 * Fetch AL data for this site and return it.
@@ -2014,64 +1557,8 @@
2014 1557 );
2015 1558 }
2016 1559
2017 1560 /**
2018 - * Fetch the discount for this site and return it.
2019 - *
2020 - * @since 10.8
2021 - *
2022 - * @return array|WP_Error
2023 - */
2024 - public static function get_site_discount() {
2025 - $site_id = Jetpack_Options::get_option( 'id' );
2026 -
2027 - if ( ! $site_id ) {
2028 - return new WP_Error(
2029 - 'site_id_missing',
2030 - esc_html__( 'Site ID is missing.', 'jetpack' ),
2031 - array( 'status' => 400 )
2032 - );
2033 - }
2034 -
2035 - $response = Client::wpcom_json_api_request_as_user(
2036 - "/sites/$site_id/discount",
2037 - '2',
2038 - array(
2039 - 'method' => 'GET',
2040 - 'headers' => array(
2041 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
2042 - ),
2043 - )
2044 - );
2045 -
2046 - $response_code = wp_remote_retrieve_response_code( $response );
2047 - $data = json_decode( wp_remote_retrieve_body( $response ) );
2048 -
2049 - if ( 200 !== $response_code ) {
2050 - return new WP_Error(
2051 - 'discount_fetch_failed',
2052 - is_object( $data ) && property_exists( $data, 'error' ) ? $data->error : esc_html__( 'Could not retrieve site discount.', 'jetpack' ),
2053 - array( 'status' => $response_code )
2054 - );
2055 - }
2056 -
2057 - if ( ! isset( $data ) ) {
2058 - return new WP_Error(
2059 - 'discount_parse_error',
2060 - esc_html__( 'Could not parse discount', 'jetpack' ),
2061 - array( 'status' => 204 ) // no content.
2062 - );
2063 - }
2064 -
2065 - return rest_ensure_response(
2066 - array(
2067 - 'code' => 'success',
2068 - 'data' => $data,
2069 - )
2070 - );
2071 - }
2072 -
2073 - /**
2074 1561 * Reset Jetpack options
2075 1562 *
2076 1563 * @since 4.3.0
2077 1564 *
@@ -2169,9 +1656,9 @@
2169 1656 public static function get_updateable_data_list( $selector = '' ) {
2170 1657
2171 1658 $options = array(
2172 1659 // Blocks.
2173 - 'jetpack_blocks_disabled' => array(
1660 + 'jetpack_blocks_disabled' => array(
2174 1661 'description' => esc_html__( 'Jetpack Blocks disabled.', 'jetpack' ),
2175 1662 'type' => 'boolean',
2176 1663 'default' => false,
2177 1664 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2178,9 +1665,9 @@
2178 1665 'jp_group' => 'settings',
2179 1666 ),
2180 1667
2181 1668 // Carousel
2182 - 'carousel_background_color' => array(
1669 + 'carousel_background_color' => array(
2183 1670 'description' => esc_html__( 'Color scheme.', 'jetpack' ),
2184 1671 'type' => 'string',
2185 1672 'default' => 'black',
2186 1673 'enum' => array(
@@ -2193,9 +1680,9 @@
2193 1680 ),
2194 1681 'validate_callback' => __CLASS__ . '::validate_list_item',
2195 1682 'jp_group' => 'carousel',
2196 1683 ),
2197 - 'carousel_display_exif' => array(
1684 + 'carousel_display_exif' => array(
2198 1685 'description' => wp_kses(
2199 1686 sprintf( __( 'Show photo metadata (<a href="https://en.wikipedia.org/wiki/Exchangeable_image_file_format" target="_blank">Exif</a>) in carousel, when available.', 'jetpack' ) ),
2200 1687 array(
2201 1688 'a' => array(
@@ -2208,9 +1695,9 @@
2208 1695 'default' => 0,
2209 1696 'validate_callback' => __CLASS__ . '::validate_boolean',
2210 1697 'jp_group' => 'carousel',
2211 1698 ),
2212 - 'carousel_display_comments' => array(
1699 + 'carousel_display_comments' => array(
2213 1700 'description' => esc_html__( 'Show comments area in carousel', 'jetpack' ),
2214 1701 'type' => 'boolean',
2215 1702 'default' => 1,
2216 1703 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2217,9 +1704,9 @@
2217 1704 'jp_group' => 'carousel',
2218 1705 ),
2219 1706
2220 1707 // Comments.
2221 - 'highlander_comment_form_prompt' => array(
1708 + 'highlander_comment_form_prompt' => array(
2222 1709 'description' => esc_html__( 'Greeting Text', 'jetpack' ),
2223 1710 'type' => 'string',
2224 1711 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2225 1712 'sanitize_callback' => 'sanitize_text_field',
@@ -2224,9 +1711,9 @@
2224 1711 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2225 1712 'sanitize_callback' => 'sanitize_text_field',
2226 1713 'jp_group' => 'comments',
2227 1714 ),
2228 - 'jetpack_comment_form_color_scheme' => array(
1715 + 'jetpack_comment_form_color_scheme' => array(
2229 1716 'description' => esc_html__( 'Color scheme', 'jetpack' ),
2230 1717 'type' => 'string',
2231 1718 'default' => 'light',
2232 1719 'enum' => array(
@@ -2243,39 +1730,38 @@
2243 1730 'jp_group' => 'comments',
2244 1731 ),
2245 1732
2246 1733 // Custom Content Types.
2247 - 'jetpack_portfolio' => array(
1734 + 'jetpack_portfolio' => array(
2248 1735 'description' => esc_html__( 'Enable or disable Jetpack portfolio post type.', 'jetpack' ),
2249 1736 'type' => 'boolean',
2250 1737 'default' => 0,
2251 1738 'validate_callback' => __CLASS__ . '::validate_boolean',
2252 - 'jp_group' => 'custom-content-types',
1739 + 'jp_group' => 'settings',
2253 1740 ),
2254 - 'jetpack_portfolio_posts_per_page' => array(
1741 + 'jetpack_portfolio_posts_per_page' => array(
2255 1742 'description' => esc_html__( 'Number of entries to show at most in Portfolio pages.', 'jetpack' ),
2256 1743 'type' => 'integer',
2257 1744 'default' => 10,
2258 1745 'validate_callback' => __CLASS__ . '::validate_posint',
2259 - 'jp_group' => 'custom-content-types',
1746 + 'jp_group' => 'settings',
2260 1747 ),
2261 - 'jetpack_testimonial' => array(
1748 + 'jetpack_testimonial' => array(
2262 1749 'description' => esc_html__( 'Enable or disable Jetpack testimonial post type.', 'jetpack' ),
2263 1750 'type' => 'boolean',
2264 1751 'default' => 0,
2265 1752 'validate_callback' => __CLASS__ . '::validate_boolean',
2266 - 'jp_group' => 'custom-content-types',
1753 + 'jp_group' => 'settings',
2267 1754 ),
2268 - 'jetpack_testimonial_posts_per_page' => array(
1755 + 'jetpack_testimonial_posts_per_page' => array(
2269 1756 'description' => esc_html__( 'Number of entries to show at most in Testimonial pages.', 'jetpack' ),
2270 1757 'type' => 'integer',
2271 1758 'default' => 10,
2272 1759 'validate_callback' => __CLASS__ . '::validate_posint',
2273 - 'jp_group' => 'custom-content-types',
1760 + 'jp_group' => 'settings',
2274 1761 ),
2275 -
2276 1762 // WAF.
2277 - 'jetpack_waf_automatic_rules' => array(
1763 + 'jetpack_waf_automatic_rules' => array(
2278 1764 'description' => esc_html__( 'Enable automatic rules - Protect your site against untrusted traffic sources with automatic security rules.', 'jetpack' ),
2279 1765 'type' => 'boolean',
2280 1766 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2281 1767 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2280,16 +1766,16 @@
2280 1766 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2281 1767 'validate_callback' => __CLASS__ . '::validate_boolean',
2282 1768 'jp_group' => 'waf',
2283 1769 ),
2284 - 'jetpack_waf_ip_list' => array(
2285 - 'description' => esc_html__( 'Allow / Block list - Block or allow a specific request IP.', 'jetpack' ),
1770 + 'jetpack_waf_ip_block_list_enabled' => array(
1771 + 'description' => esc_html__( 'Block list - Block a specific request IP.', 'jetpack' ),
2286 1772 'type' => 'boolean',
2287 1773 'default' => 0,
2288 1774 'validate_callback' => __CLASS__ . '::validate_boolean',
2289 1775 'jp_group' => 'waf',
2290 1776 ),
2291 - 'jetpack_waf_ip_block_list' => array(
1777 + 'jetpack_waf_ip_block_list' => array(
2292 1778 'description' => esc_html__( 'Blocked IP addresses', 'jetpack' ),
2293 1779 'type' => 'string',
2294 1780 'default' => '',
2295 1781 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2295,18 +1781,32 @@
2295 1781 'validate_callback' => __CLASS__ . '::validate_string',
2296 1782 'sanitize_callback' => 'esc_textarea',
2297 1783 'jp_group' => 'waf',
2298 1784 ),
2299 - 'jetpack_waf_ip_allow_list' => array(
1785 + 'jetpack_waf_ip_allow_list_enabled' => array(
1786 + 'description' => esc_html__( 'Allow list - Allow a specific request IP.', 'jetpack' ),
1787 + 'type' => 'boolean',
1788 + 'default' => 0,
1789 + 'validate_callback' => __CLASS__ . '::validate_boolean',
1790 + 'jp_group' => 'settings',
1791 + ),
1792 + 'jetpack_waf_ip_allow_list' => array(
2300 1793 'description' => esc_html__( 'Always allowed IP addresses', 'jetpack' ),
2301 1794 'type' => 'string',
2302 1795 'default' => '',
2303 1796 'validate_callback' => __CLASS__ . '::validate_string',
2304 1797 'sanitize_callback' => 'esc_textarea',
1798 + 'jp_group' => 'settings',
1799 + ),
1800 + 'jetpack_waf_share_data' => array(
1801 + 'description' => esc_html__( 'Share basic data with Jetpack.', 'jetpack' ),
1802 + 'type' => 'boolean',
1803 + 'default' => 0,
1804 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2305 1805 'jp_group' => 'waf',
2306 1806 ),
2307 - 'jetpack_waf_share_data' => array(
2308 - 'description' => esc_html__( 'Share data with Jetpack.', 'jetpack' ),
1807 + 'jetpack_waf_share_debug_data' => array(
1808 + 'description' => esc_html__( 'Share detailed data with Jetpack.', 'jetpack' ),
2309 1809 'type' => 'boolean',
2310 1810 'default' => 0,
2311 1811 'validate_callback' => __CLASS__ . '::validate_boolean',
2312 1812 'jp_group' => 'waf',
@@ -2311,9 +1811,9 @@
2311 1811 'validate_callback' => __CLASS__ . '::validate_boolean',
2312 1812 'jp_group' => 'waf',
2313 1813 ),
2314 1814 // Galleries.
2315 - 'tiled_galleries' => array(
1815 + 'tiled_galleries' => array(
2316 1816 'description' => esc_html__( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ),
2317 1817 'type' => 'boolean',
2318 1818 'default' => 0,
2319 1819 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2319,9 +1819,9 @@
2319 1819 'validate_callback' => __CLASS__ . '::validate_boolean',
2320 1820 'jp_group' => 'tiled-gallery',
2321 1821 ),
2322 1822
2323 - 'gravatar_disable_hovercards' => array(
1823 + 'gravatar_disable_hovercards' => array(
2324 1824 'description' => esc_html__( "View people's profiles when you mouse over their Gravatars", 'jetpack' ),
2325 1825 'type' => 'string',
2326 1826 'default' => 'enabled',
2327 1827 // Not visible. This is used as the checkbox value.
@@ -2337,9 +1837,9 @@
2337 1837 'jp_group' => 'gravatar-hovercards',
2338 1838 ),
2339 1839
2340 1840 // Infinite Scroll.
2341 - 'infinite_scroll' => array(
1841 + 'infinite_scroll' => array(
2342 1842 'description' => esc_html__( 'To infinity and beyond', 'jetpack' ),
2343 1843 'type' => 'boolean',
2344 1844 'default' => 1,
2345 1845 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2344,9 +1844,9 @@
2344 1844 'default' => 1,
2345 1845 'validate_callback' => __CLASS__ . '::validate_boolean',
2346 1846 'jp_group' => 'infinite-scroll',
2347 1847 ),
2348 - 'infinite_scroll_google_analytics' => array(
1848 + 'infinite_scroll_google_analytics' => array(
2349 1849 'description' => esc_html__( 'Use Google Analytics with Infinite Scroll', 'jetpack' ),
2350 1850 'type' => 'boolean',
2351 1851 'default' => 0,
2352 1852 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2353,9 +1853,9 @@
2353 1853 'jp_group' => 'infinite-scroll',
2354 1854 ),
2355 1855
2356 1856 // Likes.
2357 - 'wpl_default' => array(
1857 + 'wpl_default' => array(
2358 1858 'description' => esc_html__( 'WordPress.com Likes are', 'jetpack' ),
2359 1859 'type' => 'string',
2360 1860 'default' => 'on',
2361 1861 'enum' => array(
@@ -2368,9 +1868,9 @@
2368 1868 ),
2369 1869 'validate_callback' => __CLASS__ . '::validate_list_item',
2370 1870 'jp_group' => 'likes',
2371 1871 ),
2372 - 'social_notifications_like' => array(
1872 + 'social_notifications_like' => array(
2373 1873 'description' => esc_html__( 'Send email notification when someone likes a post', 'jetpack' ),
2374 1874 'type' => 'boolean',
2375 1875 'default' => 1,
2376 1876 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2377,9 +1877,9 @@
2377 1877 'jp_group' => 'likes',
2378 1878 ),
2379 1879
2380 1880 // Markdown.
2381 - 'wpcom_publish_comments_with_markdown' => array(
1881 + 'wpcom_publish_comments_with_markdown' => array(
2382 1882 'description' => esc_html__( 'Use Markdown for comments.', 'jetpack' ),
2383 1883 'type' => 'boolean',
2384 1884 'default' => 0,
2385 1885 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2384,9 +1884,9 @@
2384 1884 'default' => 0,
2385 1885 'validate_callback' => __CLASS__ . '::validate_boolean',
2386 1886 'jp_group' => 'markdown',
2387 1887 ),
2388 - 'wpcom_publish_posts_with_markdown' => array(
1888 + 'wpcom_publish_posts_with_markdown' => array(
2389 1889 'description' => esc_html__( 'Use Markdown for posts.', 'jetpack' ),
2390 1890 'type' => 'boolean',
2391 1891 'default' => 0,
2392 1892 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2393,9 +1893,9 @@
2393 1893 'jp_group' => 'markdown',
2394 1894 ),
2395 1895
2396 1896 // Monitor.
2397 - 'monitor_receive_notifications' => array(
1897 + 'monitor_receive_notifications' => array(
2398 1898 'description' => esc_html__( 'Receive Monitor Email Notifications.', 'jetpack' ),
2399 1899 'type' => 'boolean',
2400 1900 'default' => 0,
2401 1901 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2402,9 +1902,9 @@
2402 1902 'jp_group' => 'monitor',
2403 1903 ),
2404 1904
2405 1905 // Post by Email.
2406 - 'post_by_email_address' => array(
1906 + 'post_by_email_address' => array(
2407 1907 'description' => esc_html__( 'Email Address', 'jetpack' ),
2408 1908 'type' => 'string',
2409 1909 'default' => 'noop',
2410 1910 'enum' => array(
@@ -2423,9 +1923,9 @@
2423 1923 'jp_group' => 'post-by-email',
2424 1924 ),
2425 1925
2426 1926 // Protect.
2427 - 'jetpack_protect_key' => array(
1927 + 'jetpack_protect_key' => array(
2428 1928 'description' => esc_html__( 'Protect API key', 'jetpack' ),
2429 1929 'type' => 'string',
2430 1930 'default' => '',
2431 1931 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2430,9 +1930,9 @@
2430 1930 'default' => '',
2431 1931 'validate_callback' => __CLASS__ . '::validate_alphanum',
2432 1932 'jp_group' => 'protect',
2433 1933 ),
2434 - 'jetpack_protect_global_whitelist' => array(
1934 + 'jetpack_protect_global_whitelist' => array(
2435 1935 'description' => esc_html__( 'Protect global IP allow list', 'jetpack' ),
2436 1936 'type' => 'string',
2437 1937 'default' => '',
2438 1938 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2440,19 +1940,19 @@
2440 1940 'jp_group' => 'protect',
2441 1941 ),
2442 1942
2443 1943 // Sharing.
2444 - 'sharing_services' => array(
1944 + 'sharing_services' => array(
2445 1945 'description' => esc_html__( 'Enabled Services and those hidden behind a button', 'jetpack' ),
2446 1946 'type' => 'object',
2447 1947 'default' => array(
2448 - 'visible' => array( 'twitter', 'facebook' ),
1948 + 'visible' => array( 'facebook', 'x' ),
2449 1949 'hidden' => array(),
2450 1950 ),
2451 1951 'validate_callback' => __CLASS__ . '::validate_services',
2452 1952 'jp_group' => 'sharedaddy',
2453 1953 ),
2454 - 'button_style' => array(
1954 + 'button_style' => array(
2455 1955 'description' => esc_html__( 'Button Style', 'jetpack' ),
2456 1956 'type' => 'string',
2457 1957 'default' => 'icon',
2458 1958 'enum' => array(
@@ -2469,9 +1969,9 @@
2469 1969 ),
2470 1970 'validate_callback' => __CLASS__ . '::validate_list_item',
2471 1971 'jp_group' => 'sharedaddy',
2472 1972 ),
2473 - 'sharing_label' => array(
1973 + 'sharing_label' => array(
2474 1974 'description' => esc_html__( 'Sharing Label', 'jetpack' ),
2475 1975 'type' => 'string',
2476 1976 'default' => '',
2477 1977 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2477,9 +1977,9 @@
2477 1977 'validate_callback' => __CLASS__ . '::validate_string',
2478 1978 'sanitize_callback' => 'esc_html',
2479 1979 'jp_group' => 'sharedaddy',
2480 1980 ),
2481 - 'show' => array(
1981 + 'show' => array(
2482 1982 'description' => esc_html__( 'Views where buttons are shown', 'jetpack' ),
2483 1983 'type' => 'array',
2484 1984 'items' => array(
2485 1985 'type' => 'string',
@@ -2487,9 +1987,9 @@
2487 1987 'default' => array( 'post' ),
2488 1988 'validate_callback' => __CLASS__ . '::validate_sharing_show',
2489 1989 'jp_group' => 'sharedaddy',
2490 1990 ),
2491 - 'jetpack-twitter-cards-site-tag' => array(
1991 + 'jetpack-twitter-cards-site-tag' => array(
2492 1992 'description' => esc_html__( "The Twitter username of the owner of this site's domain.", 'jetpack' ),
2493 1993 'type' => 'string',
2494 1994 'default' => '',
2495 1995 'validate_callback' => __CLASS__ . '::validate_twitter_username',
@@ -2495,9 +1995,9 @@
2495 1995 'validate_callback' => __CLASS__ . '::validate_twitter_username',
2496 1996 'sanitize_callback' => 'esc_html',
2497 1997 'jp_group' => 'sharedaddy',
2498 1998 ),
2499 - 'sharedaddy_disable_resources' => array(
1999 + 'sharedaddy_disable_resources' => array(
2500 2000 'description' => esc_html__( 'Disable CSS and JS', 'jetpack' ),
2501 2001 'type' => 'boolean',
2502 2002 'default' => 0,
2503 2003 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2502,9 +2002,9 @@
2502 2002 'default' => 0,
2503 2003 'validate_callback' => __CLASS__ . '::validate_boolean',
2504 2004 'jp_group' => 'sharedaddy',
2505 2005 ),
2506 - 'custom' => array(
2006 + 'custom' => array(
2507 2007 'description' => esc_html__( 'Custom sharing services added by user.', 'jetpack' ),
2508 2008 'type' => 'object',
2509 2009 'default' => array(
2510 2010 'sharing_name' => '',
@@ -2513,10 +2013,10 @@
2513 2013 ),
2514 2014 'validate_callback' => __CLASS__ . '::validate_custom_service',
2515 2015 'jp_group' => 'sharedaddy',
2516 2016 ),
2517 - // Not an option, but an action that can be perfomed on the list of custom services passing the service ID.
2518 - 'sharing_delete_service' => array(
2017 + // Not an option, but an action that can be performed on the list of custom services passing the service ID.
2018 + 'sharing_delete_service' => array(
2519 2019 'description' => esc_html__( 'Delete custom sharing service.', 'jetpack' ),
2520 2020 'type' => 'string',
2521 2021 'default' => '',
2522 2022 'validate_callback' => __CLASS__ . '::validate_custom_service_id',
@@ -2523,25 +2023,25 @@
2523 2023 'jp_group' => 'sharedaddy',
2524 2024 ),
2525 2025
2526 2026 // SSO.
2527 - 'jetpack_sso_require_two_step' => array(
2027 + 'jetpack_sso_require_two_step' => array(
2528 2028 'description' => esc_html__( 'Require Two-Step Authentication', 'jetpack' ),
2529 2029 'type' => 'boolean',
2530 - 'default' => 0,
2030 + 'default' => SSO\Helpers::is_require_two_step_checkbox_disabled(),
2531 2031 'validate_callback' => __CLASS__ . '::validate_boolean',
2532 2032 'jp_group' => 'sso',
2533 2033 ),
2534 - 'jetpack_sso_match_by_email' => array(
2034 + 'jetpack_sso_match_by_email' => array(
2535 2035 'description' => esc_html__( 'Match by Email', 'jetpack' ),
2536 2036 'type' => 'boolean',
2537 - 'default' => 0,
2037 + 'default' => 1,
2538 2038 'validate_callback' => __CLASS__ . '::validate_boolean',
2539 2039 'jp_group' => 'sso',
2540 2040 ),
2541 2041
2542 2042 // Subscriptions.
2543 - 'stb_enabled' => array(
2043 + 'stb_enabled' => array(
2544 2044 'description' => esc_html__( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ),
2545 2045 'type' => 'boolean',
2546 2046 'default' => 1,
2547 2047 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2546,9 +2046,9 @@
2546 2046 'default' => 1,
2547 2047 'validate_callback' => __CLASS__ . '::validate_boolean',
2548 2048 'jp_group' => 'subscriptions',
2549 2049 ),
2550 - 'stc_enabled' => array(
2050 + 'stc_enabled' => array(
2551 2051 'description' => esc_html__( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ),
2552 2052 'type' => 'boolean',
2553 2053 'default' => 1,
2554 2054 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2553,18 +2053,144 @@
2553 2053 'default' => 1,
2554 2054 'validate_callback' => __CLASS__ . '::validate_boolean',
2555 2055 'jp_group' => 'subscriptions',
2556 2056 ),
2557 - 'social_notifications_subscribe' => array(
2558 - 'description' => esc_html__( 'Send email notification when someone follows my blog', 'jetpack' ),
2057 + 'wpcom_newsletter_categories' => array(
2058 + 'description' => esc_html__( 'Array of post category ids that are marked as newsletter categories', 'jetpack' ),
2059 + 'type' => 'array',
2060 + 'default' => array(),
2061 + 'validate_callback' => __CLASS__ . '::validate_array',
2062 + 'jp_group' => 'subscriptions',
2063 + ),
2064 + 'wpcom_newsletter_categories_enabled' => array(
2065 + 'description' => esc_html__( 'Whether the newsletter categories are enabled or not', 'jetpack' ),
2559 2066 'type' => 'boolean',
2560 2067 'default' => 0,
2561 2068 'validate_callback' => __CLASS__ . '::validate_boolean',
2562 2069 'jp_group' => 'subscriptions',
2563 2070 ),
2071 + 'wpcom_newsletter_send_default' => array(
2072 + 'description' => esc_html__( 'Whether to send newsletter emails by default when publishing a post', 'jetpack' ),
2073 + 'type' => 'boolean',
2074 + 'default' => 1,
2075 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2076 + 'jp_group' => 'subscriptions',
2077 + ),
2078 + 'wpcom_featured_image_in_email' => array(
2079 + 'description' => esc_html__( 'Whether to include the featured image in the email or not', 'jetpack' ),
2080 + 'type' => 'boolean',
2081 + 'default' => 0,
2082 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2083 + 'jp_group' => 'subscriptions',
2084 + ),
2085 + 'jetpack_gravatar_in_email' => array(
2086 + 'description' => esc_html__( 'Whether to show author avatar in the email byline', 'jetpack' ),
2087 + 'type' => 'boolean',
2088 + 'default' => 1,
2089 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2090 + 'jp_group' => 'subscriptions',
2091 + ),
2092 + 'jetpack_author_in_email' => array(
2093 + 'description' => esc_html__( 'Whether to show author display name in the email byline', 'jetpack' ),
2094 + 'type' => 'boolean',
2095 + 'default' => 1,
2096 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2097 + 'jp_group' => 'subscriptions',
2098 + ),
2099 + 'jetpack_post_date_in_email' => array(
2100 + 'description' => esc_html__( 'Whether to show date in the email byline', 'jetpack' ),
2101 + 'type' => 'boolean',
2102 + 'default' => 1,
2103 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2104 + 'jp_group' => 'subscriptions',
2105 + ),
2106 + 'wpcom_subscription_emails_use_excerpt' => array(
2107 + 'description' => esc_html__( 'Whether to use the excerpt in the email or not', 'jetpack' ),
2108 + 'type' => 'boolean',
2109 + 'default' => 0,
2110 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2111 + 'jp_group' => 'subscriptions',
2112 + ),
2113 + 'jetpack_subscriptions_reply_to' => array(
2114 + 'description' => esc_html__( 'Reply to email behaviour for newsletters emails', 'jetpack' ),
2115 + 'type' => 'string',
2116 + 'default' => Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to,
2117 + 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to',
2118 + 'jp_group' => 'subscriptions',
2119 + ),
2120 + 'jetpack_subscriptions_from_name' => array(
2121 + 'description' => esc_html__( 'From name for newsletters emails', 'jetpack' ),
2122 + 'type' => 'string',
2123 + 'default' => '',
2124 + 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to_name',
2125 + 'jp_group' => 'subscriptions',
2126 + ),
2127 + 'sm_enabled' => array(
2128 + 'description' => esc_html__( 'Show popup Subscribe modal to readers.', 'jetpack' ),
2129 + 'type' => 'boolean',
2130 + 'default' => 0,
2131 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2132 + 'jp_group' => 'subscriptions',
2133 + ),
2134 + 'jetpack_subscribe_overlay_enabled' => array(
2135 + 'description' => esc_html__( 'Show subscribe overlay on homepage.', 'jetpack' ),
2136 + 'type' => 'boolean',
2137 + 'default' => 0,
2138 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2139 + 'jp_group' => 'subscriptions',
2140 + ),
2141 + 'jetpack_subscribe_floating_button_enabled' => array(
2142 + 'description' => esc_html__( 'Show a floating subscribe button.', 'jetpack' ),
2143 + 'type' => 'boolean',
2144 + 'default' => 0,
2145 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2146 + 'jp_group' => 'subscriptions',
2147 + ),
2148 + 'jetpack_subscriptions_subscribe_post_end_enabled' => array(
2149 + 'description' => esc_html__( 'Add Subscribe block at the end of each post.', 'jetpack' ),
2150 + 'type' => 'boolean',
2151 + 'default' => 0,
2152 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2153 + 'jp_group' => 'subscriptions',
2154 + ),
2155 + 'jetpack_subscriptions_login_navigation_enabled' => array(
2156 + 'description' => esc_html__( 'Add Subscriber Login block to the navigation.', 'jetpack' ),
2157 + 'type' => 'boolean',
2158 + 'default' => 0,
2159 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2160 + 'jp_group' => 'subscriptions',
2161 + ),
2162 + 'jetpack_subscriptions_subscribe_navigation_enabled' => array(
2163 + 'description' => esc_html__( 'Add Subscribe block to the navigation.', 'jetpack' ),
2164 + 'type' => 'boolean',
2165 + 'default' => 0,
2166 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2167 + 'jp_group' => 'subscriptions',
2168 + ),
2169 + 'social_notifications_subscribe' => array(
2170 + 'description' => esc_html__( 'Send email notification when someone subscribes to my blog', 'jetpack' ),
2171 + 'type' => 'boolean',
2172 + 'default' => 0,
2173 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2174 + 'jp_group' => 'subscriptions',
2175 + ),
2176 + 'subscription_options' => array(
2177 + 'description' => esc_html__( 'Options used in subscription email templates and the Subscribe block: \'invitation\', \'welcome\', \'comment_follow\', \'subscribe_modal_heading\', \'free_tier_description\' and \'hide_free_tier\'.', 'jetpack' ),
2178 + 'type' => 'object',
2179 + 'default' => array(
2180 + 'invitation' => '',
2181 + 'welcome' => '',
2182 + 'comment_follow' => '',
2183 + 'subscribe_modal_heading' => '',
2184 + 'free_tier_description' => '',
2185 + 'hide_free_tier' => false,
2186 + ),
2187 + 'validate_callback' => __CLASS__ . '::validate_subscription_options',
2188 + 'jp_group' => 'subscriptions',
2189 + ),
2564 2190
2565 2191 // Related Posts.
2566 - 'show_headline' => array(
2192 + 'show_headline' => array(
2567 2193 'description' => esc_html__( 'Highlight related content with a heading', 'jetpack' ),
2568 2194 'type' => 'boolean',
2569 2195 'default' => 1,
2570 2196 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2569,9 +2195,9 @@
2569 2195 'default' => 1,
2570 2196 'validate_callback' => __CLASS__ . '::validate_boolean',
2571 2197 'jp_group' => 'related-posts',
2572 2198 ),
2573 - 'show_thumbnails' => array(
2199 + 'show_thumbnails' => array(
2574 2200 'description' => esc_html__( 'Show a thumbnail image where available', 'jetpack' ),
2575 2201 'type' => 'boolean',
2576 2202 'default' => 0,
2577 2203 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2578,9 +2204,9 @@
2578 2204 'jp_group' => 'related-posts',
2579 2205 ),
2580 2206
2581 2207 // Search.
2582 - 'instant_search_enabled' => array(
2208 + 'instant_search_enabled' => array(
2583 2209 'description' => esc_html__( 'Enable Instant Search', 'jetpack' ),
2584 2210 'type' => 'boolean',
2585 2211 'default' => 0,
2586 2212 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2586,9 +2212,9 @@
2586 2212 'validate_callback' => __CLASS__ . '::validate_boolean',
2587 2213 'jp_group' => 'search',
2588 2214 ),
2589 2215
2590 - 'has_jetpack_search_product' => array(
2216 + 'has_jetpack_search_product' => array(
2591 2217 'description' => esc_html__( 'Has an active Jetpack Search product purchase', 'jetpack' ),
2592 2218 'type' => 'boolean',
2593 2219 'default' => 0,
2594 2220 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2594,9 +2220,9 @@
2594 2220 'validate_callback' => __CLASS__ . '::validate_boolean',
2595 2221 'jp_group' => 'settings',
2596 2222 ),
2597 2223
2598 - 'search_auto_config' => array(
2224 + 'search_auto_config' => array(
2599 2225 'description' => esc_html__( 'Trigger an auto config of instant search', 'jetpack' ),
2600 2226 'type' => 'boolean',
2601 2227 'default' => 0,
2602 2228 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2603,9 +2229,9 @@
2603 2229 'jp_group' => 'search',
2604 2230 ),
2605 2231
2606 2232 // Verification Tools.
2607 - 'google' => array(
2233 + 'google' => array(
2608 2234 'description' => esc_html__( 'Google Search Console', 'jetpack' ),
2609 2235 'type' => 'string',
2610 2236 'default' => '',
2611 2237 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2610,9 +2236,9 @@
2610 2236 'default' => '',
2611 2237 'validate_callback' => __CLASS__ . '::validate_verification_service',
2612 2238 'jp_group' => 'verification-tools',
2613 2239 ),
2614 - 'bing' => array(
2240 + 'bing' => array(
2615 2241 'description' => esc_html__( 'Bing Webmaster Center', 'jetpack' ),
2616 2242 'type' => 'string',
2617 2243 'default' => '',
2618 2244 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2617,9 +2243,9 @@
2617 2243 'default' => '',
2618 2244 'validate_callback' => __CLASS__ . '::validate_verification_service',
2619 2245 'jp_group' => 'verification-tools',
2620 2246 ),
2621 - 'pinterest' => array(
2247 + 'pinterest' => array(
2622 2248 'description' => esc_html__( 'Pinterest Site Verification', 'jetpack' ),
2623 2249 'type' => 'string',
2624 2250 'default' => '',
2625 2251 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2624,9 +2250,9 @@
2624 2250 'default' => '',
2625 2251 'validate_callback' => __CLASS__ . '::validate_verification_service',
2626 2252 'jp_group' => 'verification-tools',
2627 2253 ),
2628 - 'yandex' => array(
2254 + 'yandex' => array(
2629 2255 'description' => esc_html__( 'Yandex Site Verification', 'jetpack' ),
2630 2256 'type' => 'string',
2631 2257 'default' => '',
2632 2258 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2631,9 +2257,9 @@
2631 2257 'default' => '',
2632 2258 'validate_callback' => __CLASS__ . '::validate_verification_service',
2633 2259 'jp_group' => 'verification-tools',
2634 2260 ),
2635 - 'facebook' => array(
2261 + 'facebook' => array(
2636 2262 'description' => esc_html__( 'Facebook Domain Verification', 'jetpack' ),
2637 2263 'type' => 'string',
2638 2264 'default' => '',
2639 2265 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2640,9 +2266,9 @@
2640 2266 'jp_group' => 'verification-tools',
2641 2267 ),
2642 2268
2643 2269 // WordAds.
2644 - 'enable_header_ad' => array(
2270 + 'enable_header_ad' => array(
2645 2271 'description' => esc_html__( 'Display an ad unit at the top of each page.', 'jetpack' ),
2646 2272 'type' => 'boolean',
2647 2273 'default' => 1,
2648 2274 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2647,9 +2273,9 @@
2647 2273 'default' => 1,
2648 2274 'validate_callback' => __CLASS__ . '::validate_boolean',
2649 2275 'jp_group' => 'wordads',
2650 2276 ),
2651 - 'wordads_approved' => array(
2277 + 'wordads_approved' => array(
2652 2278 'description' => esc_html__( 'Is site approved for WordAds?', 'jetpack' ),
2653 2279 'type' => 'boolean',
2654 2280 'default' => 0,
2655 2281 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2654,9 +2280,9 @@
2654 2280 'default' => 0,
2655 2281 'validate_callback' => __CLASS__ . '::validate_boolean',
2656 2282 'jp_group' => 'wordads',
2657 2283 ),
2658 - 'wordads_second_belowpost' => array(
2284 + 'wordads_second_belowpost' => array(
2659 2285 'description' => esc_html__( 'Display second ad below post?', 'jetpack' ),
2660 2286 'type' => 'boolean',
2661 2287 'default' => 1,
2662 2288 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2661,9 +2287,16 @@
2661 2287 'default' => 1,
2662 2288 'validate_callback' => __CLASS__ . '::validate_boolean',
2663 2289 'jp_group' => 'wordads',
2664 2290 ),
2665 - 'wordads_display_front_page' => array(
2291 + 'wordads_inline_enabled' => array(
2292 + 'description' => esc_html__( 'Display inline ad within post content?', 'jetpack' ),
2293 + 'type' => 'boolean',
2294 + 'default' => 1,
2295 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2296 + 'jp_group' => 'wordads',
2297 + ),
2298 + 'wordads_display_front_page' => array(
2666 2299 'description' => esc_html__( 'Display ads on the front page?', 'jetpack' ),
2667 2300 'type' => 'boolean',
2668 2301 'default' => 1,
2669 2302 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2668,9 +2301,9 @@
2668 2301 'default' => 1,
2669 2302 'validate_callback' => __CLASS__ . '::validate_boolean',
2670 2303 'jp_group' => 'wordads',
2671 2304 ),
2672 - 'wordads_display_post' => array(
2305 + 'wordads_display_post' => array(
2673 2306 'description' => esc_html__( 'Display ads on posts?', 'jetpack' ),
2674 2307 'type' => 'boolean',
2675 2308 'default' => 1,
2676 2309 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2675,9 +2308,9 @@
2675 2308 'default' => 1,
2676 2309 'validate_callback' => __CLASS__ . '::validate_boolean',
2677 2310 'jp_group' => 'wordads',
2678 2311 ),
2679 - 'wordads_display_page' => array(
2312 + 'wordads_display_page' => array(
2680 2313 'description' => esc_html__( 'Display ads on pages?', 'jetpack' ),
2681 2314 'type' => 'boolean',
2682 2315 'default' => 1,
2683 2316 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2682,9 +2315,9 @@
2682 2315 'default' => 1,
2683 2316 'validate_callback' => __CLASS__ . '::validate_boolean',
2684 2317 'jp_group' => 'wordads',
2685 2318 ),
2686 - 'wordads_display_archive' => array(
2319 + 'wordads_display_archive' => array(
2687 2320 'description' => esc_html__( 'Display ads on archive pages?', 'jetpack' ),
2688 2321 'type' => 'boolean',
2689 2322 'default' => 1,
2690 2323 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2689,9 +2322,9 @@
2689 2322 'default' => 1,
2690 2323 'validate_callback' => __CLASS__ . '::validate_boolean',
2691 2324 'jp_group' => 'wordads',
2692 2325 ),
2693 - 'wordads_custom_adstxt_enabled' => array(
2326 + 'wordads_custom_adstxt_enabled' => array(
2694 2327 'description' => esc_html__( 'Custom ads.txt', 'jetpack' ),
2695 2328 'type' => 'boolean',
2696 2329 'default' => 0,
2697 2330 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2696,9 +2329,9 @@
2696 2329 'default' => 0,
2697 2330 'validate_callback' => __CLASS__ . '::validate_boolean',
2698 2331 'jp_group' => 'wordads',
2699 2332 ),
2700 - 'wordads_custom_adstxt' => array(
2333 + 'wordads_custom_adstxt' => array(
2701 2334 'description' => esc_html__( 'Custom ads.txt entries', 'jetpack' ),
2702 2335 'type' => 'string',
2703 2336 'default' => '',
2704 2337 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2704,9 +2337,9 @@
2704 2337 'validate_callback' => __CLASS__ . '::validate_string',
2705 2338 'sanitize_callback' => 'sanitize_textarea_field',
2706 2339 'jp_group' => 'wordads',
2707 2340 ),
2708 - 'wordads_ccpa_enabled' => array(
2341 + 'wordads_ccpa_enabled' => array(
2709 2342 'description' => esc_html__( 'Enable support for California Consumer Privacy Act', 'jetpack' ),
2710 2343 'type' => 'boolean',
2711 2344 'default' => 0,
2712 2345 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2711,9 +2344,9 @@
2711 2344 'default' => 0,
2712 2345 'validate_callback' => __CLASS__ . '::validate_boolean',
2713 2346 'jp_group' => 'wordads',
2714 2347 ),
2715 - 'wordads_ccpa_privacy_policy_url' => array(
2348 + 'wordads_ccpa_privacy_policy_url' => array(
2716 2349 'description' => esc_html__( 'Privacy Policy URL', 'jetpack' ),
2717 2350 'type' => 'string',
2718 2351 'default' => '',
2719 2352 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2719,11 +2352,18 @@
2719 2352 'validate_callback' => __CLASS__ . '::validate_string',
2720 2353 'sanitize_callback' => 'sanitize_text_field',
2721 2354 'jp_group' => 'wordads',
2722 2355 ),
2356 + 'wordads_cmp_enabled' => array(
2357 + 'description' => esc_html__( 'Enable GDPR Consent Management Banner for WordAds', 'jetpack' ),
2358 + 'type' => 'boolean',
2359 + 'default' => 0,
2360 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2361 + 'jp_group' => 'wordads',
2362 + ),
2723 2363
2724 2364 // Google Analytics.
2725 - 'google_analytics_tracking_id' => array(
2365 + 'google_analytics_tracking_id' => array(
2726 2366 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2727 2367 'type' => 'string',
2728 2368 'default' => '',
2729 2369 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2728,11 +2368,16 @@
2728 2368 'default' => '',
2729 2369 'validate_callback' => __CLASS__ . '::validate_alphanum',
2730 2370 'jp_group' => 'google-analytics',
2731 2371 ),
2372 + 'jetpack_wga' => array(
2373 + 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2374 + 'type' => 'object',
2375 + 'jp_group' => 'settings',
2376 + ),
2732 2377
2733 2378 // Stats.
2734 - 'admin_bar' => array(
2379 + 'admin_bar' => array(
2735 2380 'description' => esc_html__( 'Include a small chart in your admin bar with a 48-hour traffic snapshot.', 'jetpack' ),
2736 2381 'type' => 'boolean',
2737 2382 'default' => 1,
2738 2383 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2737,9 +2382,9 @@
2737 2382 'default' => 1,
2738 2383 'validate_callback' => __CLASS__ . '::validate_boolean',
2739 2384 'jp_group' => 'stats',
2740 2385 ),
2741 - 'enable_odyssey_stats' => array(
2386 + 'enable_odyssey_stats' => array(
2742 2387 'description' => esc_html__( 'Preview the new Jetpack Stats experience (Experimental).', 'jetpack' ),
2743 2388 'type' => 'boolean',
2744 2389 'default' => 1,
2745 2390 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2744,9 +2389,9 @@
2744 2389 'default' => 1,
2745 2390 'validate_callback' => __CLASS__ . '::validate_boolean',
2746 2391 'jp_group' => 'stats',
2747 2392 ),
2748 - 'roles' => array(
2393 + 'roles' => array(
2749 2394 'description' => esc_html__( 'Select the roles that will be able to view stats reports.', 'jetpack' ),
2750 2395 'type' => 'array',
2751 2396 'items' => array(
2752 2397 'type' => 'string',
@@ -2755,9 +2400,9 @@
2755 2400 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2756 2401 'sanitize_callback' => __CLASS__ . '::sanitize_stats_allowed_roles',
2757 2402 'jp_group' => 'stats',
2758 2403 ),
2759 - 'count_roles' => array(
2404 + 'count_roles' => array(
2760 2405 'description' => esc_html__( 'Count the page views of registered users who are logged in.', 'jetpack' ),
2761 2406 'type' => 'array',
2762 2407 'items' => array(
2763 2408 'type' => 'string',
@@ -2765,9 +2410,9 @@
2765 2410 'default' => array( 'administrator' ),
2766 2411 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2767 2412 'jp_group' => 'stats',
2768 2413 ),
2769 - 'blog_id' => array(
2414 + 'blog_id' => array(
2770 2415 'description' => esc_html__( 'Blog ID.', 'jetpack' ),
2771 2416 'type' => 'boolean',
2772 2417 'default' => 0,
2773 2418 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2772,9 +2417,9 @@
2772 2417 'default' => 0,
2773 2418 'validate_callback' => __CLASS__ . '::validate_boolean',
2774 2419 'jp_group' => 'stats',
2775 2420 ),
2776 - 'do_not_track' => array(
2421 + 'do_not_track' => array(
2777 2422 'description' => esc_html__( 'Do not track.', 'jetpack' ),
2778 2423 'type' => 'boolean',
2779 2424 'default' => 1,
2780 2425 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2779,9 +2424,9 @@
2779 2424 'default' => 1,
2780 2425 'validate_callback' => __CLASS__ . '::validate_boolean',
2781 2426 'jp_group' => 'stats',
2782 2427 ),
2783 - 'version' => array(
2428 + 'version' => array(
2784 2429 'description' => esc_html__( 'Version.', 'jetpack' ),
2785 2430 'type' => 'integer',
2786 2431 'default' => 9,
2787 2432 'validate_callback' => __CLASS__ . '::validate_posint',
@@ -2786,9 +2431,9 @@
2786 2431 'default' => 9,
2787 2432 'validate_callback' => __CLASS__ . '::validate_posint',
2788 2433 'jp_group' => 'stats',
2789 2434 ),
2790 - 'collapse_nudges' => array(
2435 + 'collapse_nudges' => array(
2791 2436 'description' => esc_html__( 'Collapse upgrade nudges', 'jetpack' ),
2792 2437 'type' => 'boolean',
2793 2438 'default' => 0,
2794 2439 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2794,10 +2439,19 @@
2794 2439 'validate_callback' => __CLASS__ . '::validate_boolean',
2795 2440 'jp_group' => 'stats',
2796 2441 ),
2797 2442
2443 + // Whether to share stats views with WordPress.com Reader.
2444 + 'wpcom_reader_views_enabled' => array(
2445 + 'description' => esc_html__( 'Show post views in the WordPress.com Reader.', 'jetpack' ),
2446 + 'type' => 'boolean',
2447 + 'default' => 1,
2448 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2449 + 'jp_group' => 'settings',
2450 + ),
2451 +
2798 2452 // Akismet - Not a module, but a plugin. The options can be passed and handled differently.
2799 - 'akismet_show_user_comments_approved' => array(
2453 + 'akismet_show_user_comments_approved' => array(
2800 2454 'description' => '',
2801 2455 'type' => 'boolean',
2802 2456 'default' => 0,
2803 2457 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2803,9 +2457,9 @@
2803 2457 'validate_callback' => __CLASS__ . '::validate_boolean',
2804 2458 'jp_group' => 'settings',
2805 2459 ),
2806 2460
2807 - 'wordpress_api_key' => array(
2461 + 'wordpress_api_key' => array(
2808 2462 'description' => '',
2809 2463 'type' => 'string',
2810 2464 'default' => '',
2811 2465 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2812,9 +2466,9 @@
2812 2466 'jp_group' => 'settings',
2813 2467 ),
2814 2468
2815 2469 // Empty stats card dismiss.
2816 - 'dismiss_empty_stats_card' => array(
2470 + 'dismiss_empty_stats_card' => array(
2817 2471 'description' => '',
2818 2472 'type' => 'boolean',
2819 2473 'default' => 0,
2820 2474 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2821,9 +2475,9 @@
2821 2475 'jp_group' => 'settings',
2822 2476 ),
2823 2477
2824 2478 // Backup Getting Started card on dashboard.
2825 - 'dismiss_dash_backup_getting_started' => array(
2479 + 'dismiss_dash_backup_getting_started' => array(
2826 2480 'description' => '',
2827 2481 'type' => 'boolean',
2828 2482 'default' => 0,
2829 2483 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2830,9 +2484,9 @@
2830 2484 'jp_group' => 'settings',
2831 2485 ),
2832 2486
2833 2487 // Agencies Learn More card on dashboard.
2834 - 'dismiss_dash_agencies_learn_more' => array(
2488 + 'dismiss_dash_agencies_learn_more' => array(
2835 2489 'description' => '',
2836 2490 'type' => 'boolean',
2837 2491 'default' => 0,
2838 2492 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2838,9 +2492,9 @@
2838 2492 'validate_callback' => __CLASS__ . '::validate_boolean',
2839 2493 'jp_group' => 'settings',
2840 2494 ),
2841 2495
2842 - 'lang_id' => array(
2496 + 'lang_id' => array(
2843 2497 'description' => esc_html__( 'Primary language for the site.', 'jetpack' ),
2844 2498 'type' => 'string',
2845 2499 'default' => 'en_US',
2846 2500 'jp_group' => 'settings',
@@ -2845,32 +2499,10 @@
2845 2499 'default' => 'en_US',
2846 2500 'jp_group' => 'settings',
2847 2501 ),
2848 2502
2849 - 'onboarding' => array(
2850 - 'description' => '',
2851 - 'type' => 'object',
2852 - 'default' => array(
2853 - 'siteTitle' => '',
2854 - 'siteDescription' => '',
2855 - 'siteType' => 'personal',
2856 - 'homepageFormat' => 'posts',
2857 - 'addContactForm' => 0,
2858 - 'businessAddress' => array(
2859 - 'name' => '',
2860 - 'street' => '',
2861 - 'city' => '',
2862 - 'state' => '',
2863 - 'zip' => '',
2864 - ),
2865 - 'installWooCommerce' => false,
2866 - ),
2867 - 'validate_callback' => __CLASS__ . '::validate_onboarding',
2868 - 'jp_group' => 'settings',
2869 - ),
2870 -
2871 2503 // SEO Tools.
2872 - 'advanced_seo_front_page_description' => array(
2504 + 'advanced_seo_front_page_description' => array(
2873 2505 'description' => esc_html__( 'Front page meta description.', 'jetpack' ),
2874 2506 'type' => 'string',
2875 2507 'default' => '',
2876 2508 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
@@ -2876,9 +2508,9 @@
2876 2508 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
2877 2509 'jp_group' => 'seo-tools',
2878 2510 ),
2879 2511
2880 - 'advanced_seo_title_formats' => array(
2512 + 'advanced_seo_title_formats' => array(
2881 2513 'description' => esc_html__( 'SEO page title structures.', 'jetpack' ),
2882 2514 'type' => 'object',
2883 2515 'default' => array(
2884 2516 'archives' => array(),
@@ -2891,10 +2523,34 @@
2891 2523 'validate_callback' => 'Jetpack_SEO_Titles::are_valid_title_formats',
2892 2524 'sanitize_callback' => 'Jetpack_SEO_Titles::sanitize_title_formats',
2893 2525 ),
2894 2526
2527 + // AI tab (Jetpack > SEO). Plain option the SEO package reads to serve
2528 + // /llms.txt. The front-end behavior is gated inside the package; this
2529 + // only round-trips the persisted state alongside the other seo-tools
2530 + // settings.
2531 + 'jetpack_seo_llms_txt_enabled' => array(
2532 + 'description' => esc_html__( 'Generate an llms.txt file to guide AI assistants around your content.', 'jetpack' ),
2533 + 'type' => 'boolean',
2534 + 'default' => 0,
2535 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2536 + 'jp_group' => 'seo-tools',
2537 + ),
2538 +
2539 + // AI tab (Jetpack > SEO). Sparse per-crawler override map the SEO
2540 + // package reads to emit robots.txt directives for blocked AI crawlers.
2541 + // Stored as `slug => bool` (true = blocked); catalog validation and
2542 + // default-pruning happen in `Ai_Crawlers::get_overrides()`.
2543 + 'jetpack_seo_ai_crawler_overrides' => array(
2544 + 'description' => esc_html__( 'AI crawler allow/block overrides.', 'jetpack' ),
2545 + 'type' => 'object',
2546 + 'default' => array(),
2547 + 'jp_group' => 'seo-tools',
2548 + 'sanitize_callback' => __CLASS__ . '::sanitize_ai_crawler_overrides',
2549 + ),
2550 +
2895 2551 // VideoPress.
2896 - 'videopress_private_enabled_for_site' => array(
2552 + 'videopress_private_enabled_for_site' => array(
2897 2553 'description' => esc_html__( 'Video Privacy: Restrict views to members of this site', 'jetpack' ),
2898 2554 'type' => 'boolean',
2899 2555 'default' => 0,
2900 2556 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2901,8 +2557,21 @@
2901 2557 'jp_group' => 'videopress',
2902 2558 ),
2903 2559 );
2904 2560
2561 + // SEO Tools - SEO Enhancer.
2562 + // TODO: move this to the main options array? The filter was there while developing the feature.
2563 + // It might come in handy to hold its availability behind the filter since it still depends on AI to be available.
2564 + if ( apply_filters( 'ai_seo_enhancer_enabled', true ) ) {
2565 + $options['ai_seo_enhancer_enabled'] = array(
2566 + 'description' => esc_html__( 'Automatically generate SEO title, SEO description, and image alt text for new posts.', 'jetpack' ),
2567 + 'type' => 'boolean',
2568 + 'default' => 0,
2569 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2570 + 'jp_group' => 'seo-tools',
2571 + );
2572 + }
2573 +
2905 2574 // Add modules to list so they can be toggled.
2906 2575 $modules = Jetpack::get_available_modules();
2907 2576 if ( is_array( $modules ) && ! empty( $modules ) ) {
2908 2577 $module_args = array(
@@ -2948,8 +2617,10 @@
2948 2617 * Validates that the parameters are proper values that can be set during Jetpack onboarding.
2949 2618 *
2950 2619 * @since 5.4.0
2951 2620 *
2621 + * @deprecated since 13.9
2622 + *
2952 2623 * @param array $onboarding_data Values to check.
2953 2624 * @param WP_REST_Request $request The request sent to the WP REST API.
2954 2625 * @param string $param Name of the parameter passed to endpoint holding $value.
2955 2626 *
@@ -2954,24 +2625,10 @@
2954 2625 * @param string $param Name of the parameter passed to endpoint holding $value.
2955 2626 *
2956 2627 * @return bool|WP_Error
2957 2628 */
2958 - public static function validate_onboarding( $onboarding_data, $request, $param ) {
2959 - if ( ! is_array( $onboarding_data ) ) {
2960 - return new WP_Error( 'invalid_param', esc_html__( 'Not valid onboarding data.', 'jetpack' ) );
2961 - }
2962 - foreach ( $onboarding_data as $value ) {
2963 - if ( is_string( $value ) ) {
2964 - $onboarding_choice = self::validate_string( $value, $request, $param );
2965 - } elseif ( is_array( $value ) ) {
2966 - $onboarding_choice = self::validate_onboarding( $value, $request, $param );
2967 - } else {
2968 - $onboarding_choice = self::validate_boolean( $value, $request, $param );
2969 - }
2970 - if ( is_wp_error( $onboarding_choice ) ) {
2971 - return $onboarding_choice;
2972 - }
2973 - }
2629 + public static function validate_onboarding( $onboarding_data, $request, $param ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
2630 + _deprecated_function( __METHOD__, '13.9' );
2974 2631 return true;
2975 2632 }
2976 2633
2977 2634 /**
@@ -3167,14 +2824,14 @@
3167 2824 *
3168 2825 * @return bool|WP_Error
3169 2826 */
3170 2827 public static function validate_verification_service( $value, $request, $param ) {
3171 - if ( ! empty( $value ) && ! ( is_string( $value ) && ( preg_match( '/^[a-z0-9_-]+$/i', $value ) || jetpack_verification_get_code( $value ) !== false ) ) ) {
2828 + if ( ! empty( $value ) && ( ! is_string( $value ) || false === jetpack_verification_validate_code( $value ) ) ) {
3172 2829 return new WP_Error(
3173 2830 'invalid_param',
3174 2831 sprintf(
3175 2832 /* Translators: Placeholder is a verification string used to verify a service like Google Webmaster Console. */
3176 - esc_html__( '%s must be an alphanumeric string or a verification tag.', 'jetpack' ),
2833 + esc_html__( '%s must be a valid verification code or verification tag.', 'jetpack' ),
3177 2834 $param
3178 2835 )
3179 2836 );
3180 2837 }
@@ -3185,9 +2842,9 @@
3185 2842 * Validates that the parameter is among the roles allowed for Stats.
3186 2843 *
3187 2844 * @since 4.3.0
3188 2845 *
3189 - * @param string|bool $value Value to check.
2846 + * @param mixed $value Value to check.
3190 2847 * @param WP_REST_Request $request The request sent to the WP REST API.
3191 2848 * @param string $param Name of the parameter passed to endpoint holding $value.
3192 2849 *
3193 2850 * @return bool|WP_Error
@@ -3192,16 +2849,37 @@
3192 2849 *
3193 2850 * @return bool|WP_Error
3194 2851 */
3195 2852 public static function validate_stats_roles( $value, $request, $param ) {
3196 - if ( ! empty( $value ) && ! array_intersect( self::$stats_roles, $value ) ) {
2853 + // An empty value clears the setting; sanitize_stats_allowed_roles() falls back to 'administrator'.
2854 + if ( empty( $value ) ) {
2855 + return true;
2856 + }
2857 +
2858 + // Enforce the schema's list-of-strings contract before array_intersect() below sees the value.
2859 + if ( ! is_array( $value ) || count( array_filter( $value, 'is_string' ) ) !== count( $value ) ) {
3197 2860 return new WP_Error(
3198 2861 'invalid_param',
3199 2862 sprintf(
2863 + /* Translators: Placeholder is a parameter name. */
2864 + esc_html__( '%s must be an array of user roles.', 'jetpack' ),
2865 + $param
2866 + )
2867 + );
2868 + }
2869 +
2870 + if ( ! function_exists( 'get_editable_roles' ) ) {
2871 + require_once ABSPATH . 'wp-admin/includes/user.php';
2872 + }
2873 + $editable_roles = array_keys( get_editable_roles() );
2874 + if ( ! array_intersect( $editable_roles, $value ) ) {
2875 + return new WP_Error(
2876 + 'invalid_param',
2877 + sprintf(
3200 2878 /* Translators: first variable is the name of a parameter passed to endpoint holding the role that will be checked, the second is a list of roles allowed to see stats. The parameter is checked against this list. */
3201 2879 esc_html__( '%1$s must be %2$s.', 'jetpack' ),
3202 2880 $param,
3203 - join( ', ', self::$stats_roles )
2881 + implode( ', ', $editable_roles )
3204 2882 )
3205 2883 );
3206 2884 }
3207 2885 return true;
@@ -3236,9 +2914,9 @@
3236 2914 sprintf(
3237 2915 /* Translators: first variable is the name of a parameter passed to endpoint holding the post type where Sharing will be displayed, the second is a list of post types where Sharing can be displayed */
3238 2916 esc_html__( '%1$s must be %2$s.', 'jetpack' ),
3239 2917 $param,
3240 - join( ', ', $views )
2918 + implode( ', ', $views )
3241 2919 )
3242 2920 );
3243 2921 }
3244 2922 return true;
@@ -3244,8 +2922,59 @@
3244 2922 return true;
3245 2923 }
3246 2924
3247 2925 /**
2926 + * Validates that the parameter is among the valid reply-to types for subscriptions.
2927 + *
2928 + * @since 4.3.0
2929 + *
2930 + * @param string|bool $value Value to check.
2931 + * @param WP_REST_Request $request The request sent to the WP REST API.
2932 + * @param string $param Name of the parameter passed to endpoint holding $value.
2933 + *
2934 + * @return bool|WP_Error
2935 + */
2936 + public static function validate_subscriptions_reply_to( $value, $request, $param ) {
2937 + require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
2938 + if ( ! empty( $value ) && ! Automattic\Jetpack\Modules\Subscriptions\Settings::is_valid_reply_to( $value ) ) {
2939 + return new WP_Error(
2940 + 'invalid_param',
2941 + sprintf(
2942 + /* Translators: Placeholder is a parameter name. */
2943 + esc_html__( '%s must be a valid type.', 'jetpack' ),
2944 + $param
2945 + )
2946 + );
2947 + }
2948 + return true;
2949 + }
2950 +
2951 + /**
2952 + * Validates that the parameter is among the valid reply-to types for subscriptions.
2953 + *
2954 + * @since 4.3.0
2955 + *
2956 + * @param string|bool $value Value to check.
2957 + * @param WP_REST_Request $request The request sent to the WP REST API.
2958 + * @param string $param Name of the parameter passed to endpoint holding $value.
2959 + *
2960 + * @return bool|WP_Error
2961 + */
2962 + public static function validate_subscriptions_reply_to_name( $value, $request, $param ) {
2963 + if ( ! empty( $value ) && ! is_string( $value ) ) {
2964 + return new WP_Error(
2965 + 'invalid_param',
2966 + sprintf(
2967 + /* Translators: Placeholder is a parameter name. */
2968 + esc_html__( '%s must be a valid type.', 'jetpack' ),
2969 + $param
2970 + )
2971 + );
2972 + }
2973 + return true;
2974 + }
2975 +
2976 + /**
3248 2977 * Validates that the parameter is among the views where the Sharing can be displayed.
3249 2978 *
3250 2979 * @since 4.3.0
3251 2980 *
@@ -3292,9 +3021,9 @@
3292 3021 sprintf(
3293 3022 /* Translators: placeholder 1 is a parameter holding the services passed to endpoint, placeholder 2 is a list of all Jetpack Sharing services */
3294 3023 esc_html__( '%1$s visible and hidden items must be a list of %2$s.', 'jetpack' ),
3295 3024 $param,
3296 - join( ', ', $services )
3025 + implode( ', ', $services )
3297 3026 )
3298 3027 );
3299 3028 }
3300 3029 return true;
@@ -3460,16 +3189,72 @@
3460 3189 return true;
3461 3190 }
3462 3191
3463 3192 /**
3193 + * Validates the subscription_options parameter.
3194 + *
3195 + * @param array $values Value to check.
3196 + *
3197 + * @return bool|WP_Error
3198 + */
3199 + public static function validate_subscription_options( $values ) {
3200 + // A REST "object" decodes to a PHP associative array. Reject any other
3201 + // type (object, string, int, null, ...) up front so the array_keys()
3202 + // loop below never runs against a non-array and triggers a PHP warning.
3203 + if ( ! is_array( $values ) ) {
3204 + return new WP_Error(
3205 + 'invalid_param',
3206 + /* Translators: subscription_options is a variable name, and shouldn't be translated. */
3207 + esc_html__( 'subscription_options must be an object.', 'jetpack' )
3208 + );
3209 + }
3210 + foreach ( array_keys( $values ) as $key ) {
3211 + if ( ! in_array( $key, array( 'welcome', 'invitation', 'comment_follow', 'subscribe_modal_heading', 'free_tier_description', 'hide_free_tier' ), true ) ) {
3212 + return new WP_Error(
3213 + 'invalid_param',
3214 + sprintf(
3215 + /* Translators: Placeholder is the invalid param being sent. */
3216 + esc_html__( '%s is not one of the allowed members of subscription_options.', 'jetpack' ),
3217 + $key
3218 + )
3219 + );
3220 + }
3221 + }
3222 + return true;
3223 + }
3224 +
3225 + /**
3226 + * Validates that the parameter is an array.
3227 + *
3228 + * @param array $values Value to check.
3229 + * @param WP_REST_Request $request The request sent to the WP REST API.
3230 + * @param string $param Name of the parameter passed to the endpoint holding $value.
3231 + *
3232 + * @return bool|WP_Error
3233 + */
3234 + public static function validate_array( $values, $request, $param ) {
3235 + if ( ! is_array( $values ) ) {
3236 + return new WP_Error(
3237 + 'invalid_param',
3238 + sprintf(
3239 + /* Translators: Placeholder is a parameter name. */
3240 + esc_html__( '%s must be an object.', 'jetpack' ),
3241 + $param
3242 + )
3243 + );
3244 + }
3245 + return true;
3246 + }
3247 +
3248 + /**
3464 3249 * If for some reason the roles allowed to see Stats are empty (for example, user tampering with checkboxes),
3465 3250 * return an array with only 'administrator' as the allowed role and save it for 'roles' option.
3466 3251 *
3467 3252 * @since 4.3.0
3468 3253 *
3469 - * @param string|bool $value Value to check.
3254 + * @param mixed $value Value to check.
3470 3255 *
3471 - * @return bool|array
3256 + * @return mixed The value as submitted, or an array holding only 'administrator' when it is empty.
3472 3257 */
3473 3258 public static function sanitize_stats_allowed_roles( $value ) {
3474 3259 if ( empty( $value ) ) {
3475 3260 return array( 'administrator' );
@@ -3477,8 +3262,31 @@
3477 3262 return $value;
3478 3263 }
3479 3264
3480 3265 /**
3266 + * Sanitize the AI crawler override map.
3267 + *
3268 + * Keeps the value package-agnostic: each key is normalized with sanitize_key()
3269 + * and each value cast to bool. Catalog validation and default-pruning happen in
3270 + * `Automattic\Jetpack\SEO\Ai_Crawlers::get_overrides()`.
3271 + *
3272 + * @param mixed $value The submitted override map.
3273 + *
3274 + * @return array<string, bool> Sanitized `slug => bool` map.
3275 + */
3276 + public static function sanitize_ai_crawler_overrides( $value ) {
3277 + if ( ! is_array( $value ) ) {
3278 + return array();
3279 + }
3280 +
3281 + $sanitized = array();
3282 + foreach ( $value as $k => $v ) {
3283 + $sanitized[ sanitize_key( $k ) ] = (bool) $v;
3284 + }
3285 + return $sanitized;
3286 + }
3287 +
3288 + /**
3481 3289 * Get the currently accessed route and return the module slug in it.
3482 3290 *
3483 3291 * @since 4.3.0
3484 3292 *
@@ -3487,9 +3295,9 @@
3487 3295 * @return array|string
3488 3296 */
3489 3297 public static function get_module_requested( $route = '/module/(?P<slug>[a-z\-]+)' ) {
3490 3298
3491 - if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
3299 + if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) || ! is_string( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
3492 3300 return '';
3493 3301 }
3494 3302
3495 3303 preg_match( "#$route#", $GLOBALS['wp']->query_vars['rest_route'], $module );
@@ -3540,8 +3348,40 @@
3540 3348 return $modules;
3541 3349 }
3542 3350
3543 3351 /**
3352 + * Remove options the current user cannot read.
3353 + *
3354 + * Covers every `jetpack_waf_*` option, plus the two Protect options that expose the
3355 + * same data under a different name: `jetpack_protect_global_whitelist` is populated
3356 + * from `jetpack_waf_ip_allow_list`, and `jetpack_protect_key` is a shared secret.
3357 + *
3358 + * @since 16.2
3359 + *
3360 + * @param array $options Option definitions keyed by option name.
3361 + * @return array
3362 + */
3363 + public static function filter_options_for_response( $options ) {
3364 + if ( current_user_can( 'manage_options' ) ) {
3365 + return $options;
3366 + }
3367 +
3368 + $restricted = array(
3369 + 'jetpack_protect_key',
3370 + 'jetpack_protect_global_whitelist',
3371 + );
3372 +
3373 + return array_filter(
3374 + $options,
3375 + static function ( $option_name ) use ( $restricted ) {
3376 + return 0 !== strpos( $option_name, 'jetpack_waf_' )
3377 + && ! in_array( $option_name, $restricted, true );
3378 + },
3379 + ARRAY_FILTER_USE_KEY
3380 + );
3381 + }
3382 +
3383 + /**
3544 3384 * Remove 'validate_callback' item from options available for module.
3545 3385 * Fetch current option value and add to array of module options.
3546 3386 * Prepare values of module options that need special handling, like those saved in wpcom.
3547 3387 *
@@ -3604,9 +3444,9 @@
3604 3444 $options = self::split_options( $options, $sharer->get_global_options() );
3605 3445 $options['sharing_services']['current_value'] = $sharer->get_blog_services();
3606 3446 $other_sharedaddy_options = array( 'jetpack-twitter-cards-site-tag', 'sharedaddy_disable_resources', 'sharing_delete_service' );
3607 3447 foreach ( $other_sharedaddy_options as $key ) {
3608 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3448 + $default_value = $options[ $key ]['default'] ?? '';
3609 3449 $current_value = get_option( $key, $default_value );
3610 3450 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3611 3451 }
3612 3452 break;
@@ -3617,9 +3457,9 @@
3617 3457 break;
3618 3458 default:
3619 3459 // These option are just stored as plain WordPress options.
3620 3460 foreach ( $options as $key => $value ) {
3621 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3461 + $default_value = $options[ $key ]['default'] ?? '';
3622 3462 $current_value = get_option( $key, $default_value );
3623 3463 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3624 3464 }
3625 3465 }
@@ -3629,14 +3469,17 @@
3629 3469 // We don't need validate_callback in the response.
3630 3470 if ( isset( $options[ $key ]['validate_callback'] ) ) {
3631 3471 unset( $options[ $key ]['validate_callback'] );
3632 3472 }
3633 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3473 + $default_value = $options[ $key ]['default'] ?? '';
3634 3474 if ( ! array_key_exists( 'current_value', $options[ $key ] ) ) {
3635 3475 $options[ $key ]['current_value'] = self::cast_value( $default_value, $options[ $key ] );
3636 3476 }
3637 3477 }
3638 - return $options;
3478 +
3479 + // Filter last: the switch above assigns current_value by key without isset(),
3480 + // so filtering earlier would let those assignments re-add a removed option.
3481 + return self::filter_options_for_response( $options );
3639 3482 }
3640 3483
3641 3484 /**
3642 3485 * Splits module options saved as arrays like relatedposts or verification_services_codes into separate options to be returned in the response.
@@ -4141,61 +3984,52 @@
4141 3984 return rest_ensure_response( array( 'success' => $updated_option ) );
4142 3985 }
4143 3986
4144 3987 /**
4145 - * Fetch introdution offers.
3988 + * Return the list of available features.
4146 3989 *
4147 - * @since 10.9
4148 - *
4149 - * @return array|WP_Error
3990 + * @return array
4150 3991 */
4151 - public static function get_intro_offers() {
4152 - $site_id = Jetpack_Options::get_option( 'id' );
4153 -
4154 - if ( ! $site_id ) {
4155 - return new WP_Error(
4156 - 'site_id_missing',
4157 - esc_html__( 'Site ID is missing.', 'jetpack' ),
4158 - array( 'status' => 400 )
4159 - );
3992 + public static function get_features_available() {
3993 + $raw_modules = Jetpack::get_available_modules();
3994 + $modules = array();
3995 + foreach ( $raw_modules as $module ) {
3996 + $modules[] = Jetpack::get_module_slug( $module );
4160 3997 }
4161 3998
4162 - $response = Client::wpcom_json_api_request_as_user(
4163 - '/introductory-offers',
4164 - '2',
4165 - array(
4166 - 'method' => 'GET',
4167 - 'headers' => array(
4168 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
4169 - ),
4170 - )
4171 - );
3999 + return $modules;
4000 + }
4172 4001
4173 - $response_code = wp_remote_retrieve_response_code( $response );
4174 -
4175 - if ( 200 !== $response_code ) {
4176 - return new WP_Error(
4177 - 'intro_offers_fetch_failed',
4178 - esc_html__( 'Could not retrieve intro offers.', 'jetpack' ),
4179 - array( 'status' => $response_code )
4180 - );
4002 + /**
4003 + * Returns what features are enabled. Uses the slug of the modules files.
4004 + *
4005 + * @return array
4006 + */
4007 + public static function get_features_enabled() {
4008 + $raw_modules = Jetpack::get_active_modules();
4009 + $modules = array();
4010 + foreach ( $raw_modules as $module ) {
4011 + $modules[] = Jetpack::get_module_slug( $module );
4181 4012 }
4182 4013
4183 - $data = json_decode( wp_remote_retrieve_body( $response ) );
4014 + return $modules;
4015 + }
4184 4016
4185 - if ( ! isset( $data ) ) {
4186 - return new WP_Error(
4187 - 'intro_offers_error',
4188 - esc_html__( 'Could not parse intro offers.', 'jetpack' ),
4189 - array( 'status' => 204 ) // no content.
4017 + /**
4018 + * Verify that the API client is allowed to replace user token.
4019 + *
4020 + * @since 1.29.0
4021 + *
4022 + * @return bool|WP_Error
4023 + */
4024 + public static function get_features_permission_check() {
4025 + if ( ! Rest_Authentication::is_signed_with_blog_token() ) {
4026 + $message = esc_html__(
4027 + 'You do not have the correct user permissions to perform this action. Please contact your site admin if you think this is a mistake.',
4028 + 'jetpack'
4190 4029 );
4030 + return new WP_Error( 'invalid_permission_fetch_features', $message, array( 'status' => rest_authorization_required_code() ) );
4191 4031 }
4192 4032
4193 - return rest_ensure_response(
4194 - array(
4195 - 'code' => 'success',
4196 - 'data' => $data,
4197 - )
4198 - );
4033 + return true;
4199 4034 }
4200 -
4201 4035 } // class end