PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 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 All 507 releases
← All changes | _inc/lib/class.core-rest-api-endpoints.php +640 -859 12.4.2 → 16.3-beta View file →
@@ -8,9 +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\Current_Plan as Jetpack_Plan;
12 +use Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT;
13 +use Automattic\Jetpack\Connection\SSO;
13 14 use Automattic\Jetpack\Jetpack_CRM_Data;
14 15 use Automattic\Jetpack\Plugins_Installer;
15 16 use Automattic\Jetpack\Stats\Options as Stats_Options;
16 17 use Automattic\Jetpack\Status\Host;
@@ -17,13 +18,11 @@
17 18 use Automattic\Jetpack\Status\Visitor;
18 19 use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection_Shared_Functions;
19 20 use Automattic\Jetpack\Waf\Waf_Compatibility;
20 21
21 -/**
22 - * Disable direct access.
23 - */
22 +// Disable direct access.
24 23 if ( ! defined( 'ABSPATH' ) ) {
25 - exit;
24 + exit( 0 );
26 25 }
27 26
28 27 // Load WP_Error for error messages.
29 28 require_once ABSPATH . '/wp-includes/class-wp-error.php';
@@ -33,8 +32,10 @@
33 32 // Load API endpoints that are synced with WP.com
34 33 // Each of these is a class that will register its own routes on 'rest_api_init'.
35 34 require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/load-wpcom-endpoints.php';
36 35
36 +require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
37 +
37 38 /**
38 39 * Class Jetpack_Core_Json_Api_Endpoints
39 40 *
40 41 * @since 4.3.0
@@ -71,23 +72,10 @@
71 72 $module_toggle_endpoint = new Jetpack_Core_API_Module_Toggle_Endpoint( new Jetpack_IXR_Client() );
72 73 $site_endpoint = new Jetpack_Core_API_Site_Endpoint();
73 74 $widget_endpoint = new Jetpack_Core_API_Widget_Endpoint();
74 75
75 - /**
76 - * TODO: Move me somewhere that makes more sense.
77 - * Also give me permissions that aren't awful.
78 - */
79 - register_rest_route(
80 - 'jetpack/v4',
81 - 'jetpack-ai-jwt',
82 - array(
83 - 'methods' => WP_REST_Server::EDITABLE,
84 - 'callback' => __CLASS__ . '::get_openai_jwt',
85 - 'permission_callback' => function () {
86 - return ( new Connection_Manager( 'jetpack' ) )->is_user_connected() && current_user_can( 'edit_posts' );
87 - },
88 - )
89 - );
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();
90 78
91 79 register_rest_route(
92 80 'jetpack/v4',
93 81 'plans',
@@ -117,32 +105,10 @@
117 105 'permission_callback' => __CLASS__ . '::disconnect_site_permission_callback',
118 106 )
119 107 );
120 108
121 - // Test current connection status of Jetpack.
122 109 register_rest_route(
123 110 'jetpack/v4',
124 - '/connection/test',
125 - array(
126 - 'methods' => WP_REST_Server::READABLE,
127 - 'callback' => __CLASS__ . '::jetpack_connection_test',
128 - 'permission_callback' => __CLASS__ . '::manage_modules_permission_check',
129 - )
130 - );
131 -
132 - // Endpoint specific for privileged servers to request detailed debug information.
133 - register_rest_route(
134 - 'jetpack/v4',
135 - '/connection/test-wpcom/',
136 - array(
137 - 'methods' => WP_REST_Server::READABLE,
138 - 'callback' => __CLASS__ . '::jetpack_connection_test_for_external',
139 - 'permission_callback' => __CLASS__ . '::view_jetpack_connection_test_check',
140 - )
141 - );
142 -
143 - register_rest_route(
144 - 'jetpack/v4',
145 111 '/rewind',
146 112 array(
147 113 'methods' => WP_REST_Server::READABLE,
148 114 'callback' => __CLASS__ . '::get_rewind_data',
@@ -195,33 +161,11 @@
195 161 ),
196 162 )
197 163 );
198 164
199 - // Disconnect/unlink user from WordPress.com servers.
165 + // Get current site features.
200 166 register_rest_route(
201 167 'jetpack/v4',
202 - '/connection/user',
203 - array(
204 - 'methods' => WP_REST_Server::EDITABLE,
205 - 'callback' => __CLASS__ . '::unlink_user',
206 - 'permission_callback' => __CLASS__ . '::unlink_user_permission_callback',
207 - )
208 - );
209 -
210 - // Get current site data.
211 - register_rest_route(
212 - 'jetpack/v4',
213 - '/site',
214 - array(
215 - 'methods' => WP_REST_Server::READABLE,
216 - 'callback' => __CLASS__ . '::get_site_data',
217 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
218 - )
219 - );
220 -
221 - // Get current site data.
222 - register_rest_route(
223 - 'jetpack/v4',
224 168 '/site/features',
225 169 array(
226 170 'methods' => WP_REST_Server::READABLE,
227 171 'callback' => array( $site_endpoint, 'get_features' ),
@@ -605,103 +549,8 @@
605 549 ),
606 550 )
607 551 );
608 552
609 - register_rest_route(
610 - 'jetpack/v4',
611 - '/recommendations/data',
612 - array(
613 - array(
614 - 'methods' => WP_REST_Server::READABLE,
615 - 'callback' => __CLASS__ . '::get_recommendations_data',
616 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
617 - ),
618 - array(
619 - 'methods' => WP_REST_Server::EDITABLE,
620 - 'callback' => __CLASS__ . '::update_recommendations_data',
621 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
622 - 'args' => array(
623 - 'data' => array(
624 - 'required' => true,
625 - 'type' => 'object',
626 - 'validate_callback' => __CLASS__ . '::validate_recommendations_data',
627 - ),
628 - ),
629 - ),
630 - )
631 - );
632 -
633 - register_rest_route(
634 - 'jetpack/v4',
635 - '/recommendations/step',
636 - array(
637 - array(
638 - 'methods' => WP_REST_Server::READABLE,
639 - 'callback' => __CLASS__ . '::get_recommendations_step',
640 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
641 - ),
642 - array(
643 - 'methods' => WP_REST_Server::EDITABLE,
644 - 'callback' => __CLASS__ . '::update_recommendations_step',
645 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
646 - 'args' => array(
647 - 'step' => array(
648 - 'required' => true,
649 - 'type' => 'string',
650 - 'validate_callback' => __CLASS__ . '::validate_string',
651 - ),
652 - ),
653 - ),
654 - )
655 - );
656 -
657 - register_rest_route(
658 - 'jetpack/v4',
659 - '/recommendations/product-suggestions',
660 - array(
661 - array(
662 - 'methods' => WP_REST_Server::READABLE,
663 - 'callback' => __CLASS__ . '::get_recommendations_product_suggestions',
664 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
665 - ),
666 - )
667 - );
668 -
669 - register_rest_route(
670 - 'jetpack/v4',
671 - '/recommendations/upsell',
672 - array(
673 - array(
674 - 'methods' => WP_REST_Server::READABLE,
675 - 'callback' => __CLASS__ . '::get_recommendations_upsell',
676 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
677 - ),
678 - )
679 - );
680 -
681 - register_rest_route(
682 - 'jetpack/v4',
683 - '/recommendations/conditional',
684 - array(
685 - array(
686 - 'methods' => WP_REST_Server::READABLE,
687 - 'callback' => __CLASS__ . '::get_conditional_recommendations',
688 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
689 - ),
690 - )
691 - );
692 -
693 - // Get site discount.
694 - register_rest_route(
695 - 'jetpack/v4',
696 - '/site/discount',
697 - array(
698 - 'methods' => WP_REST_Server::READABLE,
699 - 'callback' => __CLASS__ . '::get_site_discount',
700 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
701 - )
702 - );
703 -
704 553 /*
705 554 * Manage the Jetpack CRM plugin's integration with Jetpack contact forms.
706 555 */
707 556 register_rest_route(
@@ -756,225 +605,107 @@
756 605 'permission_callback' => __CLASS__ . '::manage_modules_permission_check',
757 606 )
758 607 );
759 608
760 - // Get Jetpack introduction offers
609 + // Save subscriber token and redirect
761 610 register_rest_route(
762 611 'jetpack/v4',
763 - '/intro-offers',
612 + '/subscribers/auth',
764 613 array(
765 614 'methods' => WP_REST_Server::READABLE,
766 - 'callback' => __CLASS__ . '::get_intro_offers',
767 - '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 + ),
768 627 )
769 628 );
770 - }
771 629
772 - /**
773 - * Ask WPCOM for a JWT token to use for OpenAI conversations.
774 - * TODO: Clean me up. This is ugly hack code.
775 - */
776 - public static function get_openai_jwt() {
777 - $blog_id = \Jetpack_Options::get_option( 'id' );
778 -
779 - $response = \Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user(
780 - "/sites/$blog_id/jetpack-openai-query/jwt",
781 - '2',
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',
782 638 array(
783 - 'method' => 'POST',
784 - 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ),
785 - ),
786 - wp_json_encode( array() ),
787 - 'wpcom'
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 + )
788 643 );
789 644
790 - if ( is_wp_error( $response ) ) {
791 - return $response;
792 - }
793 -
794 - $json = json_decode( wp_remote_retrieve_body( $response ) );
795 -
796 - if ( ! isset( $json->token ) ) {
797 - return new WP_Error( 'no-token', 'No token returned from WPCOM' );
798 - }
799 -
800 - return array(
801 - 'token' => $json->token,
802 - 'blog_id' => $blog_id,
803 - );
804 - }
805 -
806 - /**
807 - * Get the data for the recommendations
808 - *
809 - * @return array Recommendations data
810 - */
811 - public static function get_recommendations_data() {
812 - return Jetpack_Recommendations::get_recommendations_data();
813 - }
814 -
815 - /**
816 - * Update the data for the recommendations
817 - *
818 - * @param WP_REST_Request $request The request.
819 - *
820 - * @return bool true
821 - */
822 - public static function update_recommendations_data( $request ) {
823 - $data = $request['data'];
824 - Jetpack_Recommendations::update_recommendations_data( $data );
825 -
826 - return true;
827 - }
828 -
829 - /**
830 - * Get the data for the recommendations
831 - *
832 - * @return array Recommendations data
833 - */
834 - public static function get_recommendations_step() {
835 - return Jetpack_Recommendations::get_recommendations_step();
836 - }
837 -
838 - /**
839 - * Update the step for the recommendations
840 - *
841 - * @param WP_REST_Request $request The request.
842 - *
843 - * @return bool true
844 - */
845 - public static function update_recommendations_step( $request ) {
846 - $step = $request['step'];
847 - Jetpack_Recommendations::update_recommendations_step( $step );
848 -
849 - return true;
850 - }
851 -
852 - /**
853 - * Get product suggestions for the recommendations
854 - *
855 - * @return string|WP_Error The response from the wpcom product suggestions endpoint as a JSON object.
856 - */
857 - public static function get_recommendations_product_suggestions() {
858 - $blog_id = Jetpack_Options::get_option( 'id' );
859 - if ( ! $blog_id ) {
860 - return new WP_Error( 'site_not_registered', esc_html__( 'Site not registered.', 'jetpack' ) );
861 - }
862 -
863 - $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() );
864 - if ( ! $user_connected ) {
865 - return wp_json_encode( array() );
866 - }
867 -
868 - $request_path = sprintf( '/sites/%s/jetpack-recommendations/product-suggestions?locale=' . get_user_locale(), $blog_id );
869 - $wpcom_request = Client::wpcom_json_api_request_as_user(
870 - $request_path,
871 - '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',
872 653 array(
873 - 'method' => 'GET',
874 - 'headers' => array(
875 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
876 - ),
654 + 'methods' => WP_REST_Server::READABLE,
655 + 'callback' => array( static::class, 'get_features_enabled' ),
656 + 'permission_callback' => array( static::class, 'get_features_permission_check' ),
877 657 )
878 658 );
879 -
880 - $response_code = wp_remote_retrieve_response_code( $wpcom_request );
881 - if ( 200 === $response_code ) {
882 - return json_decode( wp_remote_retrieve_body( $wpcom_request ) );
883 - } else {
884 - return new WP_Error(
885 - 'failed_to_fetch_data',
886 - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
887 - array( 'status' => $response_code )
888 - );
889 - }
890 659 }
891 660
892 661 /**
893 - * Get the upsell for the recommendations
662 + * Ask WPCOM for a JWT token to use for OpenAI conversations.
894 663 *
895 - * @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.
896 668 */
897 - public static function get_recommendations_upsell() {
898 - $blog_id = Jetpack_Options::get_option( 'id' );
899 - if ( ! $blog_id ) {
900 - return new WP_Error( 'site_not_registered', esc_html__( 'Site not registered.', 'jetpack' ) );
901 - }
669 + public static function get_openai_jwt() {
670 + _deprecated_function( __METHOD__, 'jetpack-16.2', '\Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT::get_jwt' );
902 671
903 - $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() );
904 - if ( ! $user_connected ) {
905 - $response = array(
906 - 'hide_upsell' => true,
907 - );
672 + $response = ( new REST_Jetpack_AI_JWT() )->get_jwt();
908 673
674 + if ( is_wp_error( $response ) ) {
909 675 return $response;
910 676 }
911 677
912 - $request_path = sprintf( '/sites/%s/jetpack-recommendations/upsell?locale=' . get_user_locale(), $blog_id );
913 - $wpcom_request = Client::wpcom_json_api_request_as_user(
914 - $request_path,
915 - '2',
916 - array(
917 - 'method' => 'GET',
918 - 'headers' => array(
919 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
920 - ),
921 - )
922 - );
923 -
924 - $response_code = wp_remote_retrieve_response_code( $wpcom_request );
925 - if ( 200 === $response_code ) {
926 - return json_decode( wp_remote_retrieve_body( $wpcom_request ) );
927 - } else {
928 - return new WP_Error(
929 - 'failed_to_fetch_data',
930 - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
931 - array( 'status' => $response_code )
932 - );
933 - }
678 + // Pre-deprecation callers expect the raw array, not a WP_REST_Response.
679 + return $response->get_data();
934 680 }
935 681
936 682 /**
937 - * Get conditional recommendations data.
683 + * Set subscriber cookie and redirect
938 684 *
939 - * @return array Conditional recommendations data.
940 - */
941 - public static function get_conditional_recommendations() {
942 - return Jetpack_Recommendations::get_conditional_recommendations();
943 - }
944 -
945 - /**
946 - * Validate the recommendations data
685 + * @param \WP_Rest_Request $request The URL to redirect to.
947 686 *
948 - * @param array $value Value to check received by request.
949 - * @param WP_REST_Request $request The request sent to the WP REST API.
950 - * @param string $param Name of the parameter passed to endpoint holding $value.
951 - *
952 - * @return bool|WP_Error
687 + * @return WP_Error|WP_REST_Response
953 688 */
954 - public static function validate_recommendations_data( $value, $request, $param ) {
955 - if ( ! is_array( $value ) ) {
956 - /* translators: Name of a parameter that must be an object */
957 - 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 ) );
958 699 }
959 700
960 - foreach ( $value as $answer ) {
961 - if ( is_array( $answer ) ) {
962 - $validate = self::validate_array_of_strings( $answer, $request, $param );
963 - } elseif ( is_string( $answer ) ) {
964 - $validate = self::validate_string( $answer, $request, $param );
965 - } elseif ( $answer === null ) {
966 - $validate = true;
967 - } else {
968 - $validate = self::validate_boolean( $answer, $request, $param );
969 - }
970 -
971 - if ( is_wp_error( $validate ) ) {
972 - return $validate;
973 - }
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 ) );
974 705 }
975 706
976 - return true;
707 + return new WP_REST_Response( null, 302, array( 'location' => $redirect_url ) );
977 708 }
978 709
979 710 /**
980 711 * Return a purchase token used for site-connected (non user-authenticated) checkout.
@@ -1104,9 +835,9 @@
1104 835 * @since 6.6.0
1105 836 *
1106 837 * @param WP_REST_Request $request The request sent to the WP REST API.
1107 838 *
1108 - * @return array|wp-error
839 + * @return array|WP_Error
1109 840 */
1110 841 public static function is_site_verified_and_token( $request ) {
1111 842 /**
1112 843 * Return an error if the site uses a Maintenance / Coming Soon plugin
@@ -1132,8 +863,9 @@
1132 863 || Jetpack::is_plugin_active( 'mojo-under-construction/mojo-contruction.php' ) && 1 == $under_construction_activation_status // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1133 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
1134 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
1135 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 + ||
1136 868 /**
1137 869 * Allow plugins to mark a site as "under construction".
1138 870 *
1139 871 * @since 6.7.0
@@ -1139,9 +871,9 @@
1139 871 * @since 6.7.0
1140 872 *
1141 873 * @param false bool Is the site under construction? Default to false.
1142 874 */
1143 - || true === apply_filters( 'jetpack_is_under_construction_plugin', false )
875 + true === apply_filters( 'jetpack_is_under_construction_plugin', false )
1144 876 ) {
1145 877 return new WP_Error( 'forbidden', __( 'Site is under construction and cannot be verified', 'jetpack' ) );
1146 878 }
1147 879
@@ -1213,9 +945,9 @@
1213 945 * @since 4.3.0
1214 946 *
1215 947 * @param WP_REST_Request $request The request sent to the WP REST API.
1216 948 *
1217 - * @return array|wp-error
949 + * @return array|WP_Error
1218 950 */
1219 951 public static function dismiss_notice( $request ) {
1220 952 $notice = $request['notice'];
1221 953
@@ -1280,24 +1012,20 @@
1280 1012
1281 1013 /**
1282 1014 * Verify that a user can use the /connection/user endpoint. Has to be a registered user and be currently linked.
1283 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 + *
1284 1021 * @since 4.3.0
1285 1022 *
1286 - * @uses Automattic\Jetpack\Connection\Manager::is_user_connected();)
1287 - *
1288 1023 * @return bool|WP_Error True if user is able to unlink.
1289 1024 */
1290 1025 public static function unlink_user_permission_callback() {
1291 - if ( current_user_can( 'jetpack_connect_user' ) && ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() ) ) {
1292 - return true;
1293 - }
1294 -
1295 - return new WP_Error(
1296 - 'invalid_user_permission_unlink_user',
1297 - REST_Connector::get_user_permissions_error_msg(),
1298 - array( 'status' => rest_authorization_required_code() )
1299 - );
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();
1300 1028 }
1301 1029
1302 1030 /**
1303 1031 * Verify that user can manage Jetpack modules.
@@ -1432,139 +1160,8 @@
1432 1160 );
1433 1161 }
1434 1162
1435 1163 /**
1436 - * Test connection status for this Jetpack site.
1437 - *
1438 - * @since 6.8.0
1439 - *
1440 - * @return array|WP_Error WP_Error returned if connection test does not succeed.
1441 - */
1442 - public static function jetpack_connection_test() {
1443 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1444 - $cxntests = new Jetpack_Cxn_Tests();
1445 -
1446 - if ( $cxntests->pass() ) {
1447 - return rest_ensure_response(
1448 - array(
1449 - 'code' => 'success',
1450 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1451 - )
1452 - );
1453 - } else {
1454 - return $cxntests->output_fails_as_wp_error();
1455 - }
1456 - }
1457 -
1458 - /**
1459 - * Test connection permission check method.
1460 - *
1461 - * @since 7.1.0
1462 - *
1463 - * @return bool
1464 - */
1465 - public static function view_jetpack_connection_test_check() {
1466 - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- This is verifying the trusted caller via a shared private key and timestamp.
1467 - if ( ! isset( $_GET['signature'] ) || ! isset( $_GET['timestamp'] ) || ! isset( $_GET['url'] ) ) {
1468 - return false;
1469 - }
1470 - $signature = base64_decode( wp_unslash( $_GET['signature'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1471 -
1472 - $signature_data = wp_json_encode(
1473 - array(
1474 - 'rest_route' => isset( $_GET['rest_route'] ) ? filter_var( wp_unslash( $_GET['rest_route'] ) ) : null,
1475 - 'timestamp' => (int) $_GET['timestamp'],
1476 - 'url' => esc_url_raw( wp_unslash( $_GET['url'] ) ),
1477 - )
1478 - );
1479 -
1480 - if (
1481 - ! function_exists( 'openssl_verify' )
1482 - || 1 !== openssl_verify(
1483 - $signature_data,
1484 - $signature,
1485 - JETPACK__DEBUGGER_PUBLIC_KEY
1486 - )
1487 - ) {
1488 - return false;
1489 - }
1490 -
1491 - // signature timestamp must be within 5min of current time.
1492 - if ( abs( time() - (int) $_GET['timestamp'] ) > 300 ) {
1493 - return false;
1494 - }
1495 -
1496 - // phpcs:enable WordPress.Security.NonceVerification.Recommended
1497 -
1498 - return true;
1499 - }
1500 -
1501 - /**
1502 - * Test connection status for this Jetpack site, encrypt the results for decryption by a third-party.
1503 - *
1504 - * @since 7.1.0
1505 - *
1506 - * @return array|mixed|object|WP_Error
1507 - */
1508 - public static function jetpack_connection_test_for_external() {
1509 - // 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.
1510 - add_filter( 'jetpack_debugger_run_self_test', '__return_false' );
1511 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1512 - $cxntests = new Jetpack_Cxn_Tests();
1513 -
1514 - if ( $cxntests->pass() ) {
1515 - $result = array(
1516 - 'code' => 'success',
1517 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1518 - );
1519 - } else {
1520 - $error = $cxntests->output_fails_as_wp_error(); // Using this so the output is similar both ways.
1521 - $errors = array();
1522 -
1523 - // Borrowed from WP_REST_Server::error_to_response().
1524 - foreach ( (array) $error->errors as $code => $messages ) {
1525 - foreach ( (array) $messages as $message ) {
1526 - $errors[] = array(
1527 - 'code' => $code,
1528 - 'message' => $message,
1529 - 'data' => $error->get_error_data( $code ),
1530 - );
1531 - }
1532 - }
1533 -
1534 - $result = ( ! empty( $errors ) ) ? $errors[0] : null;
1535 - if ( count( $errors ) > 1 ) {
1536 - // Remove the primary error.
1537 - array_shift( $errors );
1538 - $result['additional_errors'] = $errors;
1539 - }
1540 - }
1541 -
1542 - $result = wp_json_encode( $result );
1543 -
1544 - $encrypted = $cxntests->encrypt_string_for_wpcom( $result );
1545 -
1546 - if ( ! $encrypted || ! is_array( $encrypted ) ) {
1547 - return rest_ensure_response(
1548 - array(
1549 - 'code' => 'action_required',
1550 - 'message' => 'Please request results from the in-plugin debugger',
1551 - )
1552 - );
1553 - }
1554 -
1555 - return rest_ensure_response(
1556 - array(
1557 - 'code' => 'response',
1558 - 'debug' => array(
1559 - 'data' => $encrypted['data'],
1560 - 'key' => $encrypted['key'],
1561 - ),
1562 - )
1563 - );
1564 - }
1565 -
1566 - /**
1567 1164 * Fetch information about the Rewind status of the site.
1568 1165 */
1569 1166 public static function rewind_data() {
1570 1167 $site_id = Jetpack_Options::get_option( 'id' );
@@ -1607,9 +1204,9 @@
1607 1204 return rest_ensure_response(
1608 1205 array(
1609 1206 'code' => 'success',
1610 1207 'message' => esc_html__( 'Backup & Scan data correctly received.', 'jetpack' ),
1611 - 'data' => wp_json_encode( $rewind_data ),
1208 + 'data' => wp_json_encode( $rewind_data, JSON_UNESCAPED_SLASHES ),
1612 1209 )
1613 1210 );
1614 1211 }
1615 1212
@@ -1690,9 +1287,9 @@
1690 1287 return rest_ensure_response(
1691 1288 array(
1692 1289 'code' => 'success',
1693 1290 'message' => esc_html__( 'Scan state correctly received.', 'jetpack' ),
1694 - 'data' => wp_json_encode( $scan_state ),
1291 + 'data' => wp_json_encode( $scan_state, JSON_UNESCAPED_SLASHES ),
1695 1292 )
1696 1293 );
1697 1294 }
1698 1295
@@ -1739,41 +1336,8 @@
1739 1336 return new WP_Error( 'disconnect_failed', esc_html__( 'Was not able to disconnect the site. Please try again.', 'jetpack' ), array( 'status' => 400 ) );
1740 1337 }
1741 1338
1742 1339 /**
1743 - * Registers the Jetpack site
1744 - *
1745 - * @deprecated since Jetpack 9.7.0
1746 - * @see Automattic\Jetpack\Connection\REST_Connector::connection_register()
1747 - *
1748 - * @param WP_REST_Request $request The request sent to the WP REST API.
1749 - *
1750 - * @return bool|WP_Error True if Jetpack successfully registered
1751 - */
1752 - public static function register_site( $request ) {
1753 - _deprecated_function( __METHOD__, 'jetpack-9.7.0', '\Automattic\Jetpack\Connection\REST_Connector::connection_register' );
1754 -
1755 - if ( ! wp_verify_nonce( $request->get_param( 'registration_nonce' ), 'jetpack-registration-nonce' ) ) {
1756 - return new WP_Error( 'invalid_nonce', __( 'Unable to verify your request.', 'jetpack' ), array( 'status' => 403 ) );
1757 - }
1758 -
1759 - if ( isset( $request['from'] ) ) {
1760 - Jetpack::connection()->add_register_request_param( 'from', (string) $request['from'] );
1761 - }
1762 - $response = Jetpack::connection()->try_registration();
1763 -
1764 - if ( is_wp_error( $response ) ) {
1765 - return $response;
1766 - }
1767 -
1768 - return rest_ensure_response(
1769 - array(
1770 - 'authorizeUrl' => Jetpack::build_authorize_url( false ),
1771 - )
1772 - );
1773 - }
1774 -
1775 - /**
1776 1340 * Gets a new connect raw URL with fresh nonce.
1777 1341 *
1778 1342 * @uses Jetpack::disconnect();
1779 1343 * @since 4.3.0
@@ -1782,10 +1346,10 @@
1782 1346 *
1783 1347 * @return string|WP_Error A raw URL if the connection URL could be built; error message otherwise.
1784 1348 */
1785 1349 public static function build_connect_url( $request = array() ) {
1786 - $from = isset( $request['from'] ) ? $request['from'] : false;
1787 - $redirect = isset( $request['redirect'] ) ? $request['redirect'] : false;
1350 + $from = $request['from'] ?? false;
1351 + $redirect = $request['redirect'] ?? false;
1788 1352
1789 1353 $url = Jetpack::init()->build_connect_url( true, $redirect, $from );
1790 1354 if ( $url ) {
1791 1355 return rest_ensure_response( $url );
@@ -1808,9 +1372,9 @@
1808 1372 */
1809 1373 public static function get_user_connection_data() {
1810 1374 _deprecated_function( __METHOD__, 'jetpack-10.0.0', '\Automattic\Jetpack\Connection\REST_Connector::get_user_connection_data' );
1811 1375
1812 - 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';
1813 1377
1814 1378 $connection_owner = ( new Connection_Manager() )->get_connection_owner();
1815 1379 $owner_display_name = false === $connection_owner ? null : $connection_owner->data->display_name;
1816 1380
@@ -1823,30 +1387,21 @@
1823 1387
1824 1388 /**
1825 1389 * Unlinks current user from the WordPress.com Servers.
1826 1390 *
1827 - * @since 4.3.0
1391 + * @param WP_REST_Request $request The request sent to the WP REST API.
1828 1392 * @uses Automattic\Jetpack\Connection\Manager->disconnect_user
1829 1393 *
1830 - * @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()
1831 1396 *
1397 + * @since 4.3.0
1398 + *
1832 1399 * @return bool|WP_Error True if user successfully unlinked.
1833 1400 */
1834 1401 public static function unlink_user( $request ) {
1835 -
1836 - if ( ! isset( $request['linked'] ) || false !== $request['linked'] ) {
1837 - return new WP_Error( 'invalid_param', esc_html__( 'Invalid Parameter', 'jetpack' ), array( 'status' => 404 ) );
1838 - }
1839 -
1840 - if ( ( new Connection_Manager( 'jetpack' ) )->disconnect_user() ) {
1841 - return rest_ensure_response(
1842 - array(
1843 - 'code' => 'success',
1844 - )
1845 - );
1846 - }
1847 -
1848 - 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 );
1849 1404 }
1850 1405
1851 1406 /**
1852 1407 * Gets current user's tracking settings.
@@ -1905,9 +1460,9 @@
1905 1460 'Content-Type' => 'application/json',
1906 1461 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
1907 1462 ),
1908 1463 ),
1909 - wp_json_encode( $request->get_params() )
1464 + wp_json_encode( $request->get_params(), JSON_UNESCAPED_SLASHES )
1910 1465 );
1911 1466 if ( ! is_wp_error( $response ) ) {
1912 1467 $response = json_decode( wp_remote_retrieve_body( $response ), true );
1913 1468 }
@@ -1919,93 +1474,30 @@
1919 1474 /**
1920 1475 * Fetch site data from .com including the site's current plan and the site's products.
1921 1476 *
1922 1477 * @since 5.5.0
1478 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\Manager::get_connected_site_data().
1923 1479 *
1924 1480 * @return stdClass|WP_Error
1925 1481 */
1926 1482 public static function site_data() {
1927 - $site_id = Jetpack_Options::get_option( 'id' );
1483 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\Manager::get_connected_site_data' );
1928 1484
1929 - if ( ! $site_id ) {
1930 - return new WP_Error( 'site_id_missing', '', array( 'api_error_code' => __( 'site_id_missing', 'jetpack' ) ) );
1931 - }
1485 + return ( new Connection_Manager() )->get_connected_site_data();
1486 + }
1932 1487
1933 - $args = array( 'headers' => array() );
1934 -
1935 - // Allow use a store sandbox. Internal ref: PCYsg-IA-p2.
1936 - if ( isset( $_COOKIE ) && isset( $_COOKIE['store_sandbox'] ) ) {
1937 - $secret = filter_var( wp_unslash( $_COOKIE['store_sandbox'] ) );
1938 - $args['headers']['Cookie'] = "store_sandbox=$secret;";
1939 - }
1940 -
1941 - $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ) . '?force=wpcom', '1.1', $args );
1942 - $body = wp_remote_retrieve_body( $response );
1943 - $data = $body ? json_decode( $body ) : null;
1944 -
1945 - if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
1946 - $error_info = array(
1947 - 'api_error_code' => null,
1948 - 'api_http_code' => wp_remote_retrieve_response_code( $response ),
1949 - );
1950 -
1951 - if ( is_wp_error( $response ) ) {
1952 - $error_info['api_error_code'] = $response->get_error_code() ? wp_strip_all_tags( $response->get_error_code() ) : null;
1953 - } elseif ( $data && ! empty( $data->error ) ) {
1954 - $error_info['api_error_code'] = $data->error;
1955 - }
1956 -
1957 - return new WP_Error( 'site_data_fetch_failed', '', $error_info );
1958 - }
1959 -
1960 - Jetpack_Plan::update_from_sites_response( $response );
1961 -
1962 - return $data;
1963 - }
1964 1488 /**
1965 1489 * Get site data, including for example, the site's current plan.
1966 1490 *
1491 + * @since 4.3.0
1492 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\REST_Connector::site_data_response().
1493 + *
1967 1494 * @return WP_Error|WP_HTTP_Response|WP_REST_Response
1968 - * @since 4.3.0
1969 1495 */
1970 1496 public static function get_site_data() {
1971 - $site_data = self::site_data();
1497 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\REST_Connector::site_data_response' );
1972 1498
1973 - if ( ! is_wp_error( $site_data ) ) {
1974 -
1975 - /**
1976 - * Fires when the site data was successfully returned from the /sites/%d wpcom endpoint.
1977 - *
1978 - * @since 8.7.0
1979 - */
1980 - do_action( 'jetpack_get_site_data_success' );
1981 - return rest_ensure_response(
1982 - array(
1983 - 'code' => 'success',
1984 - 'message' => esc_html__( 'Site data correctly received.', 'jetpack' ),
1985 - 'data' => wp_json_encode( $site_data ),
1986 - )
1987 - );
1988 - }
1989 -
1990 - $error_data = $site_data->get_error_data();
1991 -
1992 - if ( empty( $error_data['api_error_code'] ) ) {
1993 - $error_message = esc_html__( 'Failed fetching site data from WordPress.com. If the problem persists, try reconnecting Jetpack.', 'jetpack' );
1994 - } else {
1995 - /* translators: %s is an error code (e.g. `token_mismatch`) */
1996 - $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'] );
1997 - }
1998 -
1999 - return new WP_Error(
2000 - $site_data->get_error_code(),
2001 - $error_message,
2002 - array(
2003 - 'status' => 400,
2004 - 'api_error_code' => empty( $error_data['api_error_code'] ) ? null : $error_data['api_error_code'],
2005 - 'api_http_code' => empty( $error_data['api_http_code'] ) ? null : $error_data['api_http_code'],
2006 - )
2007 - );
1499 + return REST_Connector::site_data_response();
2008 1500 }
2009 1501
2010 1502 /**
2011 1503 * Fetch AL data for this site and return it.
@@ -2065,64 +1557,8 @@
2065 1557 );
2066 1558 }
2067 1559
2068 1560 /**
2069 - * Fetch the discount for this site and return it.
2070 - *
2071 - * @since 10.8
2072 - *
2073 - * @return array|WP_Error
2074 - */
2075 - public static function get_site_discount() {
2076 - $site_id = Jetpack_Options::get_option( 'id' );
2077 -
2078 - if ( ! $site_id ) {
2079 - return new WP_Error(
2080 - 'site_id_missing',
2081 - esc_html__( 'Site ID is missing.', 'jetpack' ),
2082 - array( 'status' => 400 )
2083 - );
2084 - }
2085 -
2086 - $response = Client::wpcom_json_api_request_as_user(
2087 - "/sites/$site_id/discount",
2088 - '2',
2089 - array(
2090 - 'method' => 'GET',
2091 - 'headers' => array(
2092 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
2093 - ),
2094 - )
2095 - );
2096 -
2097 - $response_code = wp_remote_retrieve_response_code( $response );
2098 - $data = json_decode( wp_remote_retrieve_body( $response ) );
2099 -
2100 - if ( 200 !== $response_code ) {
2101 - return new WP_Error(
2102 - 'discount_fetch_failed',
2103 - is_object( $data ) && property_exists( $data, 'error' ) ? $data->error : esc_html__( 'Could not retrieve site discount.', 'jetpack' ),
2104 - array( 'status' => $response_code )
2105 - );
2106 - }
2107 -
2108 - if ( ! isset( $data ) ) {
2109 - return new WP_Error(
2110 - 'discount_parse_error',
2111 - esc_html__( 'Could not parse discount', 'jetpack' ),
2112 - array( 'status' => 204 ) // no content.
2113 - );
2114 - }
2115 -
2116 - return rest_ensure_response(
2117 - array(
2118 - 'code' => 'success',
2119 - 'data' => $data,
2120 - )
2121 - );
2122 - }
2123 -
2124 - /**
2125 1561 * Reset Jetpack options
2126 1562 *
2127 1563 * @since 4.3.0
2128 1564 *
@@ -2220,9 +1656,9 @@
2220 1656 public static function get_updateable_data_list( $selector = '' ) {
2221 1657
2222 1658 $options = array(
2223 1659 // Blocks.
2224 - 'jetpack_blocks_disabled' => array(
1660 + 'jetpack_blocks_disabled' => array(
2225 1661 'description' => esc_html__( 'Jetpack Blocks disabled.', 'jetpack' ),
2226 1662 'type' => 'boolean',
2227 1663 'default' => false,
2228 1664 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2229,9 +1665,9 @@
2229 1665 'jp_group' => 'settings',
2230 1666 ),
2231 1667
2232 1668 // Carousel
2233 - 'carousel_background_color' => array(
1669 + 'carousel_background_color' => array(
2234 1670 'description' => esc_html__( 'Color scheme.', 'jetpack' ),
2235 1671 'type' => 'string',
2236 1672 'default' => 'black',
2237 1673 'enum' => array(
@@ -2244,9 +1680,9 @@
2244 1680 ),
2245 1681 'validate_callback' => __CLASS__ . '::validate_list_item',
2246 1682 'jp_group' => 'carousel',
2247 1683 ),
2248 - 'carousel_display_exif' => array(
1684 + 'carousel_display_exif' => array(
2249 1685 'description' => wp_kses(
2250 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' ) ),
2251 1687 array(
2252 1688 'a' => array(
@@ -2259,9 +1695,9 @@
2259 1695 'default' => 0,
2260 1696 'validate_callback' => __CLASS__ . '::validate_boolean',
2261 1697 'jp_group' => 'carousel',
2262 1698 ),
2263 - 'carousel_display_comments' => array(
1699 + 'carousel_display_comments' => array(
2264 1700 'description' => esc_html__( 'Show comments area in carousel', 'jetpack' ),
2265 1701 'type' => 'boolean',
2266 1702 'default' => 1,
2267 1703 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2268,9 +1704,9 @@
2268 1704 'jp_group' => 'carousel',
2269 1705 ),
2270 1706
2271 1707 // Comments.
2272 - 'highlander_comment_form_prompt' => array(
1708 + 'highlander_comment_form_prompt' => array(
2273 1709 'description' => esc_html__( 'Greeting Text', 'jetpack' ),
2274 1710 'type' => 'string',
2275 1711 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2276 1712 'sanitize_callback' => 'sanitize_text_field',
@@ -2275,9 +1711,9 @@
2275 1711 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2276 1712 'sanitize_callback' => 'sanitize_text_field',
2277 1713 'jp_group' => 'comments',
2278 1714 ),
2279 - 'jetpack_comment_form_color_scheme' => array(
1715 + 'jetpack_comment_form_color_scheme' => array(
2280 1716 'description' => esc_html__( 'Color scheme', 'jetpack' ),
2281 1717 'type' => 'string',
2282 1718 'default' => 'light',
2283 1719 'enum' => array(
@@ -2292,41 +1728,47 @@
2292 1728 ),
2293 1729 'validate_callback' => __CLASS__ . '::validate_list_item',
2294 1730 'jp_group' => 'comments',
2295 1731 ),
1732 + 'enable_blocks_comments' => array(
1733 + 'description' => esc_html__( 'Enable blocks in comments', 'jetpack' ),
1734 + 'type' => 'boolean',
1735 + 'default' => 1,
1736 + 'validate_callback' => __CLASS__ . '::validate_boolean',
1737 + 'jp_group' => 'comments',
1738 + ),
2296 1739
2297 1740 // Custom Content Types.
2298 - 'jetpack_portfolio' => array(
1741 + 'jetpack_portfolio' => array(
2299 1742 'description' => esc_html__( 'Enable or disable Jetpack portfolio post type.', 'jetpack' ),
2300 1743 'type' => 'boolean',
2301 1744 'default' => 0,
2302 1745 'validate_callback' => __CLASS__ . '::validate_boolean',
2303 - 'jp_group' => 'custom-content-types',
1746 + 'jp_group' => 'settings',
2304 1747 ),
2305 - 'jetpack_portfolio_posts_per_page' => array(
1748 + 'jetpack_portfolio_posts_per_page' => array(
2306 1749 'description' => esc_html__( 'Number of entries to show at most in Portfolio pages.', 'jetpack' ),
2307 1750 'type' => 'integer',
2308 1751 'default' => 10,
2309 1752 'validate_callback' => __CLASS__ . '::validate_posint',
2310 - 'jp_group' => 'custom-content-types',
1753 + 'jp_group' => 'settings',
2311 1754 ),
2312 - 'jetpack_testimonial' => array(
1755 + 'jetpack_testimonial' => array(
2313 1756 'description' => esc_html__( 'Enable or disable Jetpack testimonial post type.', 'jetpack' ),
2314 1757 'type' => 'boolean',
2315 1758 'default' => 0,
2316 1759 'validate_callback' => __CLASS__ . '::validate_boolean',
2317 - 'jp_group' => 'custom-content-types',
1760 + 'jp_group' => 'settings',
2318 1761 ),
2319 - 'jetpack_testimonial_posts_per_page' => array(
1762 + 'jetpack_testimonial_posts_per_page' => array(
2320 1763 'description' => esc_html__( 'Number of entries to show at most in Testimonial pages.', 'jetpack' ),
2321 1764 'type' => 'integer',
2322 1765 'default' => 10,
2323 1766 'validate_callback' => __CLASS__ . '::validate_posint',
2324 - 'jp_group' => 'custom-content-types',
1767 + 'jp_group' => 'settings',
2325 1768 ),
2326 -
2327 1769 // WAF.
2328 - 'jetpack_waf_automatic_rules' => array(
1770 + 'jetpack_waf_automatic_rules' => array(
2329 1771 'description' => esc_html__( 'Enable automatic rules - Protect your site against untrusted traffic sources with automatic security rules.', 'jetpack' ),
2330 1772 'type' => 'boolean',
2331 1773 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2332 1774 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2331,16 +1773,16 @@
2331 1773 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2332 1774 'validate_callback' => __CLASS__ . '::validate_boolean',
2333 1775 'jp_group' => 'waf',
2334 1776 ),
2335 - 'jetpack_waf_ip_list' => array(
2336 - 'description' => esc_html__( 'Allow / Block list - Block or allow a specific request IP.', 'jetpack' ),
1777 + 'jetpack_waf_ip_block_list_enabled' => array(
1778 + 'description' => esc_html__( 'Block list - Block a specific request IP.', 'jetpack' ),
2337 1779 'type' => 'boolean',
2338 1780 'default' => 0,
2339 1781 'validate_callback' => __CLASS__ . '::validate_boolean',
2340 1782 'jp_group' => 'waf',
2341 1783 ),
2342 - 'jetpack_waf_ip_block_list' => array(
1784 + 'jetpack_waf_ip_block_list' => array(
2343 1785 'description' => esc_html__( 'Blocked IP addresses', 'jetpack' ),
2344 1786 'type' => 'string',
2345 1787 'default' => '',
2346 1788 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2346,9 +1788,16 @@
2346 1788 'validate_callback' => __CLASS__ . '::validate_string',
2347 1789 'sanitize_callback' => 'esc_textarea',
2348 1790 'jp_group' => 'waf',
2349 1791 ),
2350 - 'jetpack_waf_ip_allow_list' => array(
1792 + 'jetpack_waf_ip_allow_list_enabled' => array(
1793 + 'description' => esc_html__( 'Allow list - Allow a specific request IP.', 'jetpack' ),
1794 + 'type' => 'boolean',
1795 + 'default' => 0,
1796 + 'validate_callback' => __CLASS__ . '::validate_boolean',
1797 + 'jp_group' => 'settings',
1798 + ),
1799 + 'jetpack_waf_ip_allow_list' => array(
2351 1800 'description' => esc_html__( 'Always allowed IP addresses', 'jetpack' ),
2352 1801 'type' => 'string',
2353 1802 'default' => '',
2354 1803 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2354,17 +1803,24 @@
2354 1803 'validate_callback' => __CLASS__ . '::validate_string',
2355 1804 'sanitize_callback' => 'esc_textarea',
2356 1805 'jp_group' => 'settings',
2357 1806 ),
2358 - 'jetpack_waf_share_data' => array(
2359 - 'description' => esc_html__( 'Share data with Jetpack.', 'jetpack' ),
1807 + 'jetpack_waf_share_data' => array(
1808 + 'description' => esc_html__( 'Share basic data with Jetpack.', 'jetpack' ),
2360 1809 'type' => 'boolean',
2361 1810 'default' => 0,
2362 1811 'validate_callback' => __CLASS__ . '::validate_boolean',
2363 1812 'jp_group' => 'waf',
2364 1813 ),
1814 + 'jetpack_waf_share_debug_data' => array(
1815 + 'description' => esc_html__( 'Share detailed data with Jetpack.', 'jetpack' ),
1816 + 'type' => 'boolean',
1817 + 'default' => 0,
1818 + 'validate_callback' => __CLASS__ . '::validate_boolean',
1819 + 'jp_group' => 'waf',
1820 + ),
2365 1821 // Galleries.
2366 - 'tiled_galleries' => array(
1822 + 'tiled_galleries' => array(
2367 1823 'description' => esc_html__( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ),
2368 1824 'type' => 'boolean',
2369 1825 'default' => 0,
2370 1826 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2370,9 +1826,9 @@
2370 1826 'validate_callback' => __CLASS__ . '::validate_boolean',
2371 1827 'jp_group' => 'tiled-gallery',
2372 1828 ),
2373 1829
2374 - 'gravatar_disable_hovercards' => array(
1830 + 'gravatar_disable_hovercards' => array(
2375 1831 'description' => esc_html__( "View people's profiles when you mouse over their Gravatars", 'jetpack' ),
2376 1832 'type' => 'string',
2377 1833 'default' => 'enabled',
2378 1834 // Not visible. This is used as the checkbox value.
@@ -2388,9 +1844,9 @@
2388 1844 'jp_group' => 'gravatar-hovercards',
2389 1845 ),
2390 1846
2391 1847 // Infinite Scroll.
2392 - 'infinite_scroll' => array(
1848 + 'infinite_scroll' => array(
2393 1849 'description' => esc_html__( 'To infinity and beyond', 'jetpack' ),
2394 1850 'type' => 'boolean',
2395 1851 'default' => 1,
2396 1852 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2395,9 +1851,9 @@
2395 1851 'default' => 1,
2396 1852 'validate_callback' => __CLASS__ . '::validate_boolean',
2397 1853 'jp_group' => 'infinite-scroll',
2398 1854 ),
2399 - 'infinite_scroll_google_analytics' => array(
1855 + 'infinite_scroll_google_analytics' => array(
2400 1856 'description' => esc_html__( 'Use Google Analytics with Infinite Scroll', 'jetpack' ),
2401 1857 'type' => 'boolean',
2402 1858 'default' => 0,
2403 1859 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2404,9 +1860,9 @@
2404 1860 'jp_group' => 'infinite-scroll',
2405 1861 ),
2406 1862
2407 1863 // Likes.
2408 - 'wpl_default' => array(
1864 + 'wpl_default' => array(
2409 1865 'description' => esc_html__( 'WordPress.com Likes are', 'jetpack' ),
2410 1866 'type' => 'string',
2411 1867 'default' => 'on',
2412 1868 'enum' => array(
@@ -2419,9 +1875,9 @@
2419 1875 ),
2420 1876 'validate_callback' => __CLASS__ . '::validate_list_item',
2421 1877 'jp_group' => 'likes',
2422 1878 ),
2423 - 'social_notifications_like' => array(
1879 + 'social_notifications_like' => array(
2424 1880 'description' => esc_html__( 'Send email notification when someone likes a post', 'jetpack' ),
2425 1881 'type' => 'boolean',
2426 1882 'default' => 1,
2427 1883 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2428,9 +1884,9 @@
2428 1884 'jp_group' => 'likes',
2429 1885 ),
2430 1886
2431 1887 // Markdown.
2432 - 'wpcom_publish_comments_with_markdown' => array(
1888 + 'wpcom_publish_comments_with_markdown' => array(
2433 1889 'description' => esc_html__( 'Use Markdown for comments.', 'jetpack' ),
2434 1890 'type' => 'boolean',
2435 1891 'default' => 0,
2436 1892 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2435,9 +1891,9 @@
2435 1891 'default' => 0,
2436 1892 'validate_callback' => __CLASS__ . '::validate_boolean',
2437 1893 'jp_group' => 'markdown',
2438 1894 ),
2439 - 'wpcom_publish_posts_with_markdown' => array(
1895 + 'wpcom_publish_posts_with_markdown' => array(
2440 1896 'description' => esc_html__( 'Use Markdown for posts.', 'jetpack' ),
2441 1897 'type' => 'boolean',
2442 1898 'default' => 0,
2443 1899 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2444,9 +1900,9 @@
2444 1900 'jp_group' => 'markdown',
2445 1901 ),
2446 1902
2447 1903 // Monitor.
2448 - 'monitor_receive_notifications' => array(
1904 + 'monitor_receive_notifications' => array(
2449 1905 'description' => esc_html__( 'Receive Monitor Email Notifications.', 'jetpack' ),
2450 1906 'type' => 'boolean',
2451 1907 'default' => 0,
2452 1908 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2453,9 +1909,9 @@
2453 1909 'jp_group' => 'monitor',
2454 1910 ),
2455 1911
2456 1912 // Post by Email.
2457 - 'post_by_email_address' => array(
1913 + 'post_by_email_address' => array(
2458 1914 'description' => esc_html__( 'Email Address', 'jetpack' ),
2459 1915 'type' => 'string',
2460 1916 'default' => 'noop',
2461 1917 'enum' => array(
@@ -2474,9 +1930,9 @@
2474 1930 'jp_group' => 'post-by-email',
2475 1931 ),
2476 1932
2477 1933 // Protect.
2478 - 'jetpack_protect_key' => array(
1934 + 'jetpack_protect_key' => array(
2479 1935 'description' => esc_html__( 'Protect API key', 'jetpack' ),
2480 1936 'type' => 'string',
2481 1937 'default' => '',
2482 1938 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2481,9 +1937,9 @@
2481 1937 'default' => '',
2482 1938 'validate_callback' => __CLASS__ . '::validate_alphanum',
2483 1939 'jp_group' => 'protect',
2484 1940 ),
2485 - 'jetpack_protect_global_whitelist' => array(
1941 + 'jetpack_protect_global_whitelist' => array(
2486 1942 'description' => esc_html__( 'Protect global IP allow list', 'jetpack' ),
2487 1943 'type' => 'string',
2488 1944 'default' => '',
2489 1945 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2491,19 +1947,19 @@
2491 1947 'jp_group' => 'protect',
2492 1948 ),
2493 1949
2494 1950 // Sharing.
2495 - 'sharing_services' => array(
1951 + 'sharing_services' => array(
2496 1952 'description' => esc_html__( 'Enabled Services and those hidden behind a button', 'jetpack' ),
2497 1953 'type' => 'object',
2498 1954 'default' => array(
2499 - 'visible' => array( 'twitter', 'facebook' ),
1955 + 'visible' => array( 'facebook', 'x' ),
2500 1956 'hidden' => array(),
2501 1957 ),
2502 1958 'validate_callback' => __CLASS__ . '::validate_services',
2503 1959 'jp_group' => 'sharedaddy',
2504 1960 ),
2505 - 'button_style' => array(
1961 + 'button_style' => array(
2506 1962 'description' => esc_html__( 'Button Style', 'jetpack' ),
2507 1963 'type' => 'string',
2508 1964 'default' => 'icon',
2509 1965 'enum' => array(
@@ -2520,9 +1976,9 @@
2520 1976 ),
2521 1977 'validate_callback' => __CLASS__ . '::validate_list_item',
2522 1978 'jp_group' => 'sharedaddy',
2523 1979 ),
2524 - 'sharing_label' => array(
1980 + 'sharing_label' => array(
2525 1981 'description' => esc_html__( 'Sharing Label', 'jetpack' ),
2526 1982 'type' => 'string',
2527 1983 'default' => '',
2528 1984 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2528,9 +1984,9 @@
2528 1984 'validate_callback' => __CLASS__ . '::validate_string',
2529 1985 'sanitize_callback' => 'esc_html',
2530 1986 'jp_group' => 'sharedaddy',
2531 1987 ),
2532 - 'show' => array(
1988 + 'show' => array(
2533 1989 'description' => esc_html__( 'Views where buttons are shown', 'jetpack' ),
2534 1990 'type' => 'array',
2535 1991 'items' => array(
2536 1992 'type' => 'string',
@@ -2538,9 +1994,9 @@
2538 1994 'default' => array( 'post' ),
2539 1995 'validate_callback' => __CLASS__ . '::validate_sharing_show',
2540 1996 'jp_group' => 'sharedaddy',
2541 1997 ),
2542 - 'jetpack-twitter-cards-site-tag' => array(
1998 + 'jetpack-twitter-cards-site-tag' => array(
2543 1999 'description' => esc_html__( "The Twitter username of the owner of this site's domain.", 'jetpack' ),
2544 2000 'type' => 'string',
2545 2001 'default' => '',
2546 2002 'validate_callback' => __CLASS__ . '::validate_twitter_username',
@@ -2546,9 +2002,9 @@
2546 2002 'validate_callback' => __CLASS__ . '::validate_twitter_username',
2547 2003 'sanitize_callback' => 'esc_html',
2548 2004 'jp_group' => 'sharedaddy',
2549 2005 ),
2550 - 'sharedaddy_disable_resources' => array(
2006 + 'sharedaddy_disable_resources' => array(
2551 2007 'description' => esc_html__( 'Disable CSS and JS', 'jetpack' ),
2552 2008 'type' => 'boolean',
2553 2009 'default' => 0,
2554 2010 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2553,9 +2009,9 @@
2553 2009 'default' => 0,
2554 2010 'validate_callback' => __CLASS__ . '::validate_boolean',
2555 2011 'jp_group' => 'sharedaddy',
2556 2012 ),
2557 - 'custom' => array(
2013 + 'custom' => array(
2558 2014 'description' => esc_html__( 'Custom sharing services added by user.', 'jetpack' ),
2559 2015 'type' => 'object',
2560 2016 'default' => array(
2561 2017 'sharing_name' => '',
@@ -2564,10 +2020,10 @@
2564 2020 ),
2565 2021 'validate_callback' => __CLASS__ . '::validate_custom_service',
2566 2022 'jp_group' => 'sharedaddy',
2567 2023 ),
2568 - // Not an option, but an action that can be perfomed on the list of custom services passing the service ID.
2569 - 'sharing_delete_service' => array(
2024 + // Not an option, but an action that can be performed on the list of custom services passing the service ID.
2025 + 'sharing_delete_service' => array(
2570 2026 'description' => esc_html__( 'Delete custom sharing service.', 'jetpack' ),
2571 2027 'type' => 'string',
2572 2028 'default' => '',
2573 2029 'validate_callback' => __CLASS__ . '::validate_custom_service_id',
@@ -2574,25 +2030,25 @@
2574 2030 'jp_group' => 'sharedaddy',
2575 2031 ),
2576 2032
2577 2033 // SSO.
2578 - 'jetpack_sso_require_two_step' => array(
2034 + 'jetpack_sso_require_two_step' => array(
2579 2035 'description' => esc_html__( 'Require Two-Step Authentication', 'jetpack' ),
2580 2036 'type' => 'boolean',
2581 - 'default' => 0,
2037 + 'default' => SSO\Helpers::is_require_two_step_checkbox_disabled(),
2582 2038 'validate_callback' => __CLASS__ . '::validate_boolean',
2583 2039 'jp_group' => 'sso',
2584 2040 ),
2585 - 'jetpack_sso_match_by_email' => array(
2041 + 'jetpack_sso_match_by_email' => array(
2586 2042 'description' => esc_html__( 'Match by Email', 'jetpack' ),
2587 2043 'type' => 'boolean',
2588 - 'default' => 0,
2044 + 'default' => 1,
2589 2045 'validate_callback' => __CLASS__ . '::validate_boolean',
2590 2046 'jp_group' => 'sso',
2591 2047 ),
2592 2048
2593 2049 // Subscriptions.
2594 - 'stb_enabled' => array(
2050 + 'stb_enabled' => array(
2595 2051 'description' => esc_html__( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ),
2596 2052 'type' => 'boolean',
2597 2053 'default' => 1,
2598 2054 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2597,9 +2053,9 @@
2597 2053 'default' => 1,
2598 2054 'validate_callback' => __CLASS__ . '::validate_boolean',
2599 2055 'jp_group' => 'subscriptions',
2600 2056 ),
2601 - 'stc_enabled' => array(
2057 + 'stc_enabled' => array(
2602 2058 'description' => esc_html__( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ),
2603 2059 'type' => 'boolean',
2604 2060 'default' => 1,
2605 2061 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2604,9 +2060,79 @@
2604 2060 'default' => 1,
2605 2061 'validate_callback' => __CLASS__ . '::validate_boolean',
2606 2062 'jp_group' => 'subscriptions',
2607 2063 ),
2608 - 'sm_enabled' => array(
2064 + 'wpcom_newsletter_categories' => array(
2065 + 'description' => esc_html__( 'Array of post category ids that are marked as newsletter categories', 'jetpack' ),
2066 + 'type' => 'array',
2067 + 'default' => array(),
2068 + 'validate_callback' => __CLASS__ . '::validate_array',
2069 + 'jp_group' => 'subscriptions',
2070 + ),
2071 + 'wpcom_newsletter_categories_enabled' => array(
2072 + 'description' => esc_html__( 'Whether the newsletter categories are enabled or not', 'jetpack' ),
2073 + 'type' => 'boolean',
2074 + 'default' => 0,
2075 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2076 + 'jp_group' => 'subscriptions',
2077 + ),
2078 + 'wpcom_newsletter_send_default' => array(
2079 + 'description' => esc_html__( 'Whether to send newsletter emails by default when publishing a post', 'jetpack' ),
2080 + 'type' => 'boolean',
2081 + 'default' => 1,
2082 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2083 + 'jp_group' => 'subscriptions',
2084 + ),
2085 + 'wpcom_featured_image_in_email' => array(
2086 + 'description' => esc_html__( 'Whether to include the featured image in the email or not', 'jetpack' ),
2087 + 'type' => 'boolean',
2088 + 'default' => 0,
2089 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2090 + 'jp_group' => 'subscriptions',
2091 + ),
2092 + 'jetpack_gravatar_in_email' => array(
2093 + 'description' => esc_html__( 'Whether to show author avatar in the email byline', 'jetpack' ),
2094 + 'type' => 'boolean',
2095 + 'default' => 1,
2096 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2097 + 'jp_group' => 'subscriptions',
2098 + ),
2099 + 'jetpack_author_in_email' => array(
2100 + 'description' => esc_html__( 'Whether to show author display name in the email byline', 'jetpack' ),
2101 + 'type' => 'boolean',
2102 + 'default' => 1,
2103 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2104 + 'jp_group' => 'subscriptions',
2105 + ),
2106 + 'jetpack_post_date_in_email' => array(
2107 + 'description' => esc_html__( 'Whether to show date in the email byline', 'jetpack' ),
2108 + 'type' => 'boolean',
2109 + 'default' => 1,
2110 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2111 + 'jp_group' => 'subscriptions',
2112 + ),
2113 + 'wpcom_subscription_emails_use_excerpt' => array(
2114 + 'description' => esc_html__( 'Whether to use the excerpt in the email or not', 'jetpack' ),
2115 + 'type' => 'boolean',
2116 + 'default' => 0,
2117 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2118 + 'jp_group' => 'subscriptions',
2119 + ),
2120 + 'jetpack_subscriptions_reply_to' => array(
2121 + 'description' => esc_html__( 'Reply to email behaviour for newsletters emails', 'jetpack' ),
2122 + 'type' => 'string',
2123 + 'default' => Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to,
2124 + 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to',
2125 + 'jp_group' => 'subscriptions',
2126 + ),
2127 + 'jetpack_subscriptions_from_name' => array(
2128 + 'description' => esc_html__( 'From name for newsletters emails', 'jetpack' ),
2129 + 'type' => 'string',
2130 + 'default' => '',
2131 + 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to_name',
2132 + 'jp_group' => 'subscriptions',
2133 + ),
2134 + 'sm_enabled' => array(
2609 2135 'description' => esc_html__( 'Show popup Subscribe modal to readers.', 'jetpack' ),
2610 2136 'type' => 'boolean',
2611 2137 'default' => 0,
2612 2138 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2611,18 +2137,67 @@
2611 2137 'default' => 0,
2612 2138 'validate_callback' => __CLASS__ . '::validate_boolean',
2613 2139 'jp_group' => 'subscriptions',
2614 2140 ),
2615 - 'social_notifications_subscribe' => array(
2616 - 'description' => esc_html__( 'Send email notification when someone follows my blog', 'jetpack' ),
2141 + 'jetpack_subscribe_overlay_enabled' => array(
2142 + 'description' => esc_html__( 'Show subscribe overlay on homepage.', 'jetpack' ),
2617 2143 'type' => 'boolean',
2618 2144 'default' => 0,
2619 2145 'validate_callback' => __CLASS__ . '::validate_boolean',
2620 2146 'jp_group' => 'subscriptions',
2621 2147 ),
2148 + 'jetpack_subscribe_floating_button_enabled' => array(
2149 + 'description' => esc_html__( 'Show a floating subscribe button.', 'jetpack' ),
2150 + 'type' => 'boolean',
2151 + 'default' => 0,
2152 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2153 + 'jp_group' => 'subscriptions',
2154 + ),
2155 + 'jetpack_subscriptions_subscribe_post_end_enabled' => array(
2156 + 'description' => esc_html__( 'Add Subscribe block at the end of each post.', 'jetpack' ),
2157 + 'type' => 'boolean',
2158 + 'default' => 0,
2159 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2160 + 'jp_group' => 'subscriptions',
2161 + ),
2162 + 'jetpack_subscriptions_login_navigation_enabled' => array(
2163 + 'description' => esc_html__( 'Add Subscriber Login block to the navigation.', 'jetpack' ),
2164 + 'type' => 'boolean',
2165 + 'default' => 0,
2166 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2167 + 'jp_group' => 'subscriptions',
2168 + ),
2169 + 'jetpack_subscriptions_subscribe_navigation_enabled' => array(
2170 + 'description' => esc_html__( 'Add Subscribe block to the navigation.', 'jetpack' ),
2171 + 'type' => 'boolean',
2172 + 'default' => 0,
2173 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2174 + 'jp_group' => 'subscriptions',
2175 + ),
2176 + 'social_notifications_subscribe' => array(
2177 + 'description' => esc_html__( 'Send email notification when someone subscribes to my blog', 'jetpack' ),
2178 + 'type' => 'boolean',
2179 + 'default' => 0,
2180 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2181 + 'jp_group' => 'subscriptions',
2182 + ),
2183 + 'subscription_options' => array(
2184 + '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' ),
2185 + 'type' => 'object',
2186 + 'default' => array(
2187 + 'invitation' => '',
2188 + 'welcome' => '',
2189 + 'comment_follow' => '',
2190 + 'subscribe_modal_heading' => '',
2191 + 'free_tier_description' => '',
2192 + 'hide_free_tier' => false,
2193 + ),
2194 + 'validate_callback' => __CLASS__ . '::validate_subscription_options',
2195 + 'jp_group' => 'subscriptions',
2196 + ),
2622 2197
2623 2198 // Related Posts.
2624 - 'show_headline' => array(
2199 + 'show_headline' => array(
2625 2200 'description' => esc_html__( 'Highlight related content with a heading', 'jetpack' ),
2626 2201 'type' => 'boolean',
2627 2202 'default' => 1,
2628 2203 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2627,9 +2202,9 @@
2627 2202 'default' => 1,
2628 2203 'validate_callback' => __CLASS__ . '::validate_boolean',
2629 2204 'jp_group' => 'related-posts',
2630 2205 ),
2631 - 'show_thumbnails' => array(
2206 + 'show_thumbnails' => array(
2632 2207 'description' => esc_html__( 'Show a thumbnail image where available', 'jetpack' ),
2633 2208 'type' => 'boolean',
2634 2209 'default' => 0,
2635 2210 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2636,9 +2211,9 @@
2636 2211 'jp_group' => 'related-posts',
2637 2212 ),
2638 2213
2639 2214 // Search.
2640 - 'instant_search_enabled' => array(
2215 + 'instant_search_enabled' => array(
2641 2216 'description' => esc_html__( 'Enable Instant Search', 'jetpack' ),
2642 2217 'type' => 'boolean',
2643 2218 'default' => 0,
2644 2219 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2644,9 +2219,9 @@
2644 2219 'validate_callback' => __CLASS__ . '::validate_boolean',
2645 2220 'jp_group' => 'search',
2646 2221 ),
2647 2222
2648 - 'has_jetpack_search_product' => array(
2223 + 'has_jetpack_search_product' => array(
2649 2224 'description' => esc_html__( 'Has an active Jetpack Search product purchase', 'jetpack' ),
2650 2225 'type' => 'boolean',
2651 2226 'default' => 0,
2652 2227 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2652,9 +2227,9 @@
2652 2227 'validate_callback' => __CLASS__ . '::validate_boolean',
2653 2228 'jp_group' => 'settings',
2654 2229 ),
2655 2230
2656 - 'search_auto_config' => array(
2231 + 'search_auto_config' => array(
2657 2232 'description' => esc_html__( 'Trigger an auto config of instant search', 'jetpack' ),
2658 2233 'type' => 'boolean',
2659 2234 'default' => 0,
2660 2235 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2661,9 +2236,9 @@
2661 2236 'jp_group' => 'search',
2662 2237 ),
2663 2238
2664 2239 // Verification Tools.
2665 - 'google' => array(
2240 + 'google' => array(
2666 2241 'description' => esc_html__( 'Google Search Console', 'jetpack' ),
2667 2242 'type' => 'string',
2668 2243 'default' => '',
2669 2244 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2668,9 +2243,9 @@
2668 2243 'default' => '',
2669 2244 'validate_callback' => __CLASS__ . '::validate_verification_service',
2670 2245 'jp_group' => 'verification-tools',
2671 2246 ),
2672 - 'bing' => array(
2247 + 'bing' => array(
2673 2248 'description' => esc_html__( 'Bing Webmaster Center', 'jetpack' ),
2674 2249 'type' => 'string',
2675 2250 'default' => '',
2676 2251 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2675,9 +2250,9 @@
2675 2250 'default' => '',
2676 2251 'validate_callback' => __CLASS__ . '::validate_verification_service',
2677 2252 'jp_group' => 'verification-tools',
2678 2253 ),
2679 - 'pinterest' => array(
2254 + 'pinterest' => array(
2680 2255 'description' => esc_html__( 'Pinterest Site Verification', 'jetpack' ),
2681 2256 'type' => 'string',
2682 2257 'default' => '',
2683 2258 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2682,9 +2257,9 @@
2682 2257 'default' => '',
2683 2258 'validate_callback' => __CLASS__ . '::validate_verification_service',
2684 2259 'jp_group' => 'verification-tools',
2685 2260 ),
2686 - 'yandex' => array(
2261 + 'yandex' => array(
2687 2262 'description' => esc_html__( 'Yandex Site Verification', 'jetpack' ),
2688 2263 'type' => 'string',
2689 2264 'default' => '',
2690 2265 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2689,9 +2264,9 @@
2689 2264 'default' => '',
2690 2265 'validate_callback' => __CLASS__ . '::validate_verification_service',
2691 2266 'jp_group' => 'verification-tools',
2692 2267 ),
2693 - 'facebook' => array(
2268 + 'facebook' => array(
2694 2269 'description' => esc_html__( 'Facebook Domain Verification', 'jetpack' ),
2695 2270 'type' => 'string',
2696 2271 'default' => '',
2697 2272 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2698,9 +2273,9 @@
2698 2273 'jp_group' => 'verification-tools',
2699 2274 ),
2700 2275
2701 2276 // WordAds.
2702 - 'enable_header_ad' => array(
2277 + 'enable_header_ad' => array(
2703 2278 'description' => esc_html__( 'Display an ad unit at the top of each page.', 'jetpack' ),
2704 2279 'type' => 'boolean',
2705 2280 'default' => 1,
2706 2281 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2705,9 +2280,9 @@
2705 2280 'default' => 1,
2706 2281 'validate_callback' => __CLASS__ . '::validate_boolean',
2707 2282 'jp_group' => 'wordads',
2708 2283 ),
2709 - 'wordads_approved' => array(
2284 + 'wordads_approved' => array(
2710 2285 'description' => esc_html__( 'Is site approved for WordAds?', 'jetpack' ),
2711 2286 'type' => 'boolean',
2712 2287 'default' => 0,
2713 2288 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2712,9 +2287,9 @@
2712 2287 'default' => 0,
2713 2288 'validate_callback' => __CLASS__ . '::validate_boolean',
2714 2289 'jp_group' => 'wordads',
2715 2290 ),
2716 - 'wordads_second_belowpost' => array(
2291 + 'wordads_second_belowpost' => array(
2717 2292 'description' => esc_html__( 'Display second ad below post?', 'jetpack' ),
2718 2293 'type' => 'boolean',
2719 2294 'default' => 1,
2720 2295 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2719,9 +2294,16 @@
2719 2294 'default' => 1,
2720 2295 'validate_callback' => __CLASS__ . '::validate_boolean',
2721 2296 'jp_group' => 'wordads',
2722 2297 ),
2723 - 'wordads_display_front_page' => array(
2298 + 'wordads_inline_enabled' => array(
2299 + 'description' => esc_html__( 'Display inline ad within post content?', 'jetpack' ),
2300 + 'type' => 'boolean',
2301 + 'default' => 1,
2302 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2303 + 'jp_group' => 'wordads',
2304 + ),
2305 + 'wordads_display_front_page' => array(
2724 2306 'description' => esc_html__( 'Display ads on the front page?', 'jetpack' ),
2725 2307 'type' => 'boolean',
2726 2308 'default' => 1,
2727 2309 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2726,9 +2308,9 @@
2726 2308 'default' => 1,
2727 2309 'validate_callback' => __CLASS__ . '::validate_boolean',
2728 2310 'jp_group' => 'wordads',
2729 2311 ),
2730 - 'wordads_display_post' => array(
2312 + 'wordads_display_post' => array(
2731 2313 'description' => esc_html__( 'Display ads on posts?', 'jetpack' ),
2732 2314 'type' => 'boolean',
2733 2315 'default' => 1,
2734 2316 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2733,9 +2315,9 @@
2733 2315 'default' => 1,
2734 2316 'validate_callback' => __CLASS__ . '::validate_boolean',
2735 2317 'jp_group' => 'wordads',
2736 2318 ),
2737 - 'wordads_display_page' => array(
2319 + 'wordads_display_page' => array(
2738 2320 'description' => esc_html__( 'Display ads on pages?', 'jetpack' ),
2739 2321 'type' => 'boolean',
2740 2322 'default' => 1,
2741 2323 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2740,9 +2322,9 @@
2740 2322 'default' => 1,
2741 2323 'validate_callback' => __CLASS__ . '::validate_boolean',
2742 2324 'jp_group' => 'wordads',
2743 2325 ),
2744 - 'wordads_display_archive' => array(
2326 + 'wordads_display_archive' => array(
2745 2327 'description' => esc_html__( 'Display ads on archive pages?', 'jetpack' ),
2746 2328 'type' => 'boolean',
2747 2329 'default' => 1,
2748 2330 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2747,9 +2329,9 @@
2747 2329 'default' => 1,
2748 2330 'validate_callback' => __CLASS__ . '::validate_boolean',
2749 2331 'jp_group' => 'wordads',
2750 2332 ),
2751 - 'wordads_custom_adstxt_enabled' => array(
2333 + 'wordads_custom_adstxt_enabled' => array(
2752 2334 'description' => esc_html__( 'Custom ads.txt', 'jetpack' ),
2753 2335 'type' => 'boolean',
2754 2336 'default' => 0,
2755 2337 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2754,9 +2336,9 @@
2754 2336 'default' => 0,
2755 2337 'validate_callback' => __CLASS__ . '::validate_boolean',
2756 2338 'jp_group' => 'wordads',
2757 2339 ),
2758 - 'wordads_custom_adstxt' => array(
2340 + 'wordads_custom_adstxt' => array(
2759 2341 'description' => esc_html__( 'Custom ads.txt entries', 'jetpack' ),
2760 2342 'type' => 'string',
2761 2343 'default' => '',
2762 2344 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2762,9 +2344,9 @@
2762 2344 'validate_callback' => __CLASS__ . '::validate_string',
2763 2345 'sanitize_callback' => 'sanitize_textarea_field',
2764 2346 'jp_group' => 'wordads',
2765 2347 ),
2766 - 'wordads_ccpa_enabled' => array(
2348 + 'wordads_ccpa_enabled' => array(
2767 2349 'description' => esc_html__( 'Enable support for California Consumer Privacy Act', 'jetpack' ),
2768 2350 'type' => 'boolean',
2769 2351 'default' => 0,
2770 2352 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2769,9 +2351,9 @@
2769 2351 'default' => 0,
2770 2352 'validate_callback' => __CLASS__ . '::validate_boolean',
2771 2353 'jp_group' => 'wordads',
2772 2354 ),
2773 - 'wordads_ccpa_privacy_policy_url' => array(
2355 + 'wordads_ccpa_privacy_policy_url' => array(
2774 2356 'description' => esc_html__( 'Privacy Policy URL', 'jetpack' ),
2775 2357 'type' => 'string',
2776 2358 'default' => '',
2777 2359 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2777,11 +2359,18 @@
2777 2359 'validate_callback' => __CLASS__ . '::validate_string',
2778 2360 'sanitize_callback' => 'sanitize_text_field',
2779 2361 'jp_group' => 'wordads',
2780 2362 ),
2363 + 'wordads_cmp_enabled' => array(
2364 + 'description' => esc_html__( 'Enable GDPR Consent Management Banner for WordAds', 'jetpack' ),
2365 + 'type' => 'boolean',
2366 + 'default' => 0,
2367 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2368 + 'jp_group' => 'wordads',
2369 + ),
2781 2370
2782 2371 // Google Analytics.
2783 - 'google_analytics_tracking_id' => array(
2372 + 'google_analytics_tracking_id' => array(
2784 2373 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2785 2374 'type' => 'string',
2786 2375 'default' => '',
2787 2376 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2786,11 +2375,16 @@
2786 2375 'default' => '',
2787 2376 'validate_callback' => __CLASS__ . '::validate_alphanum',
2788 2377 'jp_group' => 'google-analytics',
2789 2378 ),
2379 + 'jetpack_wga' => array(
2380 + 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2381 + 'type' => 'object',
2382 + 'jp_group' => 'settings',
2383 + ),
2790 2384
2791 2385 // Stats.
2792 - 'admin_bar' => array(
2386 + 'admin_bar' => array(
2793 2387 'description' => esc_html__( 'Include a small chart in your admin bar with a 48-hour traffic snapshot.', 'jetpack' ),
2794 2388 'type' => 'boolean',
2795 2389 'default' => 1,
2796 2390 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2795,9 +2389,9 @@
2795 2389 'default' => 1,
2796 2390 'validate_callback' => __CLASS__ . '::validate_boolean',
2797 2391 'jp_group' => 'stats',
2798 2392 ),
2799 - 'enable_odyssey_stats' => array(
2393 + 'enable_odyssey_stats' => array(
2800 2394 'description' => esc_html__( 'Preview the new Jetpack Stats experience (Experimental).', 'jetpack' ),
2801 2395 'type' => 'boolean',
2802 2396 'default' => 1,
2803 2397 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2802,9 +2396,9 @@
2802 2396 'default' => 1,
2803 2397 'validate_callback' => __CLASS__ . '::validate_boolean',
2804 2398 'jp_group' => 'stats',
2805 2399 ),
2806 - 'roles' => array(
2400 + 'roles' => array(
2807 2401 'description' => esc_html__( 'Select the roles that will be able to view stats reports.', 'jetpack' ),
2808 2402 'type' => 'array',
2809 2403 'items' => array(
2810 2404 'type' => 'string',
@@ -2813,9 +2407,9 @@
2813 2407 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2814 2408 'sanitize_callback' => __CLASS__ . '::sanitize_stats_allowed_roles',
2815 2409 'jp_group' => 'stats',
2816 2410 ),
2817 - 'count_roles' => array(
2411 + 'count_roles' => array(
2818 2412 'description' => esc_html__( 'Count the page views of registered users who are logged in.', 'jetpack' ),
2819 2413 'type' => 'array',
2820 2414 'items' => array(
2821 2415 'type' => 'string',
@@ -2823,9 +2417,9 @@
2823 2417 'default' => array( 'administrator' ),
2824 2418 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2825 2419 'jp_group' => 'stats',
2826 2420 ),
2827 - 'blog_id' => array(
2421 + 'blog_id' => array(
2828 2422 'description' => esc_html__( 'Blog ID.', 'jetpack' ),
2829 2423 'type' => 'boolean',
2830 2424 'default' => 0,
2831 2425 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2830,9 +2424,9 @@
2830 2424 'default' => 0,
2831 2425 'validate_callback' => __CLASS__ . '::validate_boolean',
2832 2426 'jp_group' => 'stats',
2833 2427 ),
2834 - 'do_not_track' => array(
2428 + 'do_not_track' => array(
2835 2429 'description' => esc_html__( 'Do not track.', 'jetpack' ),
2836 2430 'type' => 'boolean',
2837 2431 'default' => 1,
2838 2432 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2837,9 +2431,9 @@
2837 2431 'default' => 1,
2838 2432 'validate_callback' => __CLASS__ . '::validate_boolean',
2839 2433 'jp_group' => 'stats',
2840 2434 ),
2841 - 'version' => array(
2435 + 'version' => array(
2842 2436 'description' => esc_html__( 'Version.', 'jetpack' ),
2843 2437 'type' => 'integer',
2844 2438 'default' => 9,
2845 2439 'validate_callback' => __CLASS__ . '::validate_posint',
@@ -2844,9 +2438,9 @@
2844 2438 'default' => 9,
2845 2439 'validate_callback' => __CLASS__ . '::validate_posint',
2846 2440 'jp_group' => 'stats',
2847 2441 ),
2848 - 'collapse_nudges' => array(
2442 + 'collapse_nudges' => array(
2849 2443 'description' => esc_html__( 'Collapse upgrade nudges', 'jetpack' ),
2850 2444 'type' => 'boolean',
2851 2445 'default' => 0,
2852 2446 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2853,9 +2447,9 @@
2853 2447 'jp_group' => 'stats',
2854 2448 ),
2855 2449
2856 2450 // Whether to share stats views with WordPress.com Reader.
2857 - 'wpcom_reader_views_enabled' => array(
2451 + 'wpcom_reader_views_enabled' => array(
2858 2452 'description' => esc_html__( 'Show post views in the WordPress.com Reader.', 'jetpack' ),
2859 2453 'type' => 'boolean',
2860 2454 'default' => 1,
2861 2455 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2862,9 +2456,9 @@
2862 2456 'jp_group' => 'settings',
2863 2457 ),
2864 2458
2865 2459 // Akismet - Not a module, but a plugin. The options can be passed and handled differently.
2866 - 'akismet_show_user_comments_approved' => array(
2460 + 'akismet_show_user_comments_approved' => array(
2867 2461 'description' => '',
2868 2462 'type' => 'boolean',
2869 2463 'default' => 0,
2870 2464 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2870,9 +2464,9 @@
2870 2464 'validate_callback' => __CLASS__ . '::validate_boolean',
2871 2465 'jp_group' => 'settings',
2872 2466 ),
2873 2467
2874 - 'wordpress_api_key' => array(
2468 + 'wordpress_api_key' => array(
2875 2469 'description' => '',
2876 2470 'type' => 'string',
2877 2471 'default' => '',
2878 2472 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2879,9 +2473,9 @@
2879 2473 'jp_group' => 'settings',
2880 2474 ),
2881 2475
2882 2476 // Empty stats card dismiss.
2883 - 'dismiss_empty_stats_card' => array(
2477 + 'dismiss_empty_stats_card' => array(
2884 2478 'description' => '',
2885 2479 'type' => 'boolean',
2886 2480 'default' => 0,
2887 2481 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2888,9 +2482,9 @@
2888 2482 'jp_group' => 'settings',
2889 2483 ),
2890 2484
2891 2485 // Backup Getting Started card on dashboard.
2892 - 'dismiss_dash_backup_getting_started' => array(
2486 + 'dismiss_dash_backup_getting_started' => array(
2893 2487 'description' => '',
2894 2488 'type' => 'boolean',
2895 2489 'default' => 0,
2896 2490 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2897,9 +2491,9 @@
2897 2491 'jp_group' => 'settings',
2898 2492 ),
2899 2493
2900 2494 // Agencies Learn More card on dashboard.
2901 - 'dismiss_dash_agencies_learn_more' => array(
2495 + 'dismiss_dash_agencies_learn_more' => array(
2902 2496 'description' => '',
2903 2497 'type' => 'boolean',
2904 2498 'default' => 0,
2905 2499 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2905,9 +2499,9 @@
2905 2499 'validate_callback' => __CLASS__ . '::validate_boolean',
2906 2500 'jp_group' => 'settings',
2907 2501 ),
2908 2502
2909 - 'lang_id' => array(
2503 + 'lang_id' => array(
2910 2504 'description' => esc_html__( 'Primary language for the site.', 'jetpack' ),
2911 2505 'type' => 'string',
2912 2506 'default' => 'en_US',
2913 2507 'jp_group' => 'settings',
@@ -2912,32 +2506,10 @@
2912 2506 'default' => 'en_US',
2913 2507 'jp_group' => 'settings',
2914 2508 ),
2915 2509
2916 - 'onboarding' => array(
2917 - 'description' => '',
2918 - 'type' => 'object',
2919 - 'default' => array(
2920 - 'siteTitle' => '',
2921 - 'siteDescription' => '',
2922 - 'siteType' => 'personal',
2923 - 'homepageFormat' => 'posts',
2924 - 'addContactForm' => 0,
2925 - 'businessAddress' => array(
2926 - 'name' => '',
2927 - 'street' => '',
2928 - 'city' => '',
2929 - 'state' => '',
2930 - 'zip' => '',
2931 - ),
2932 - 'installWooCommerce' => false,
2933 - ),
2934 - 'validate_callback' => __CLASS__ . '::validate_onboarding',
2935 - 'jp_group' => 'settings',
2936 - ),
2937 -
2938 2510 // SEO Tools.
2939 - 'advanced_seo_front_page_description' => array(
2511 + 'advanced_seo_front_page_description' => array(
2940 2512 'description' => esc_html__( 'Front page meta description.', 'jetpack' ),
2941 2513 'type' => 'string',
2942 2514 'default' => '',
2943 2515 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
@@ -2943,9 +2515,9 @@
2943 2515 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
2944 2516 'jp_group' => 'seo-tools',
2945 2517 ),
2946 2518
2947 - 'advanced_seo_title_formats' => array(
2519 + 'advanced_seo_title_formats' => array(
2948 2520 'description' => esc_html__( 'SEO page title structures.', 'jetpack' ),
2949 2521 'type' => 'object',
2950 2522 'default' => array(
2951 2523 'archives' => array(),
@@ -2958,10 +2530,34 @@
2958 2530 'validate_callback' => 'Jetpack_SEO_Titles::are_valid_title_formats',
2959 2531 'sanitize_callback' => 'Jetpack_SEO_Titles::sanitize_title_formats',
2960 2532 ),
2961 2533
2534 + // AI tab (Jetpack > SEO). Plain option the SEO package reads to serve
2535 + // /llms.txt. The front-end behavior is gated inside the package; this
2536 + // only round-trips the persisted state alongside the other seo-tools
2537 + // settings.
2538 + 'jetpack_seo_llms_txt_enabled' => array(
2539 + 'description' => esc_html__( 'Generate an llms.txt file to guide AI assistants around your content.', 'jetpack' ),
2540 + 'type' => 'boolean',
2541 + 'default' => 0,
2542 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2543 + 'jp_group' => 'seo-tools',
2544 + ),
2545 +
2546 + // AI tab (Jetpack > SEO). Sparse per-crawler override map the SEO
2547 + // package reads to emit robots.txt directives for blocked AI crawlers.
2548 + // Stored as `slug => bool` (true = blocked); catalog validation and
2549 + // default-pruning happen in `Ai_Crawlers::get_overrides()`.
2550 + 'jetpack_seo_ai_crawler_overrides' => array(
2551 + 'description' => esc_html__( 'AI crawler allow/block overrides.', 'jetpack' ),
2552 + 'type' => 'object',
2553 + 'default' => array(),
2554 + 'jp_group' => 'seo-tools',
2555 + 'sanitize_callback' => __CLASS__ . '::sanitize_ai_crawler_overrides',
2556 + ),
2557 +
2962 2558 // VideoPress.
2963 - 'videopress_private_enabled_for_site' => array(
2559 + 'videopress_private_enabled_for_site' => array(
2964 2560 'description' => esc_html__( 'Video Privacy: Restrict views to members of this site', 'jetpack' ),
2965 2561 'type' => 'boolean',
2966 2562 'default' => 0,
2967 2563 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2966,10 +2562,30 @@
2966 2562 'default' => 0,
2967 2563 'validate_callback' => __CLASS__ . '::validate_boolean',
2968 2564 'jp_group' => 'videopress',
2969 2565 ),
2566 + 'videopress_share_menu_disabled' => array(
2567 + 'description' => esc_html__( 'Hide the share menu on every video, overriding each video’s own setting', 'jetpack' ),
2568 + 'type' => 'boolean',
2569 + 'default' => 0,
2570 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2571 + 'jp_group' => 'videopress',
2572 + ),
2970 2573 );
2971 2574
2575 + // SEO Tools - SEO Enhancer.
2576 + // TODO: move this to the main options array? The filter was there while developing the feature.
2577 + // It might come in handy to hold its availability behind the filter since it still depends on AI to be available.
2578 + if ( apply_filters( 'ai_seo_enhancer_enabled', true ) ) {
2579 + $options['ai_seo_enhancer_enabled'] = array(
2580 + 'description' => esc_html__( 'Automatically generate SEO title, SEO description, and image alt text for new posts.', 'jetpack' ),
2581 + 'type' => 'boolean',
2582 + 'default' => 0,
2583 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2584 + 'jp_group' => 'seo-tools',
2585 + );
2586 + }
2587 +
2972 2588 // Add modules to list so they can be toggled.
2973 2589 $modules = Jetpack::get_available_modules();
2974 2590 if ( is_array( $modules ) && ! empty( $modules ) ) {
2975 2591 $module_args = array(
@@ -3015,8 +2631,10 @@
3015 2631 * Validates that the parameters are proper values that can be set during Jetpack onboarding.
3016 2632 *
3017 2633 * @since 5.4.0
3018 2634 *
2635 + * @deprecated since 13.9
2636 + *
3019 2637 * @param array $onboarding_data Values to check.
3020 2638 * @param WP_REST_Request $request The request sent to the WP REST API.
3021 2639 * @param string $param Name of the parameter passed to endpoint holding $value.
3022 2640 *
@@ -3021,24 +2639,10 @@
3021 2639 * @param string $param Name of the parameter passed to endpoint holding $value.
3022 2640 *
3023 2641 * @return bool|WP_Error
3024 2642 */
3025 - public static function validate_onboarding( $onboarding_data, $request, $param ) {
3026 - if ( ! is_array( $onboarding_data ) ) {
3027 - return new WP_Error( 'invalid_param', esc_html__( 'Not valid onboarding data.', 'jetpack' ) );
3028 - }
3029 - foreach ( $onboarding_data as $value ) {
3030 - if ( is_string( $value ) ) {
3031 - $onboarding_choice = self::validate_string( $value, $request, $param );
3032 - } elseif ( is_array( $value ) ) {
3033 - $onboarding_choice = self::validate_onboarding( $value, $request, $param );
3034 - } else {
3035 - $onboarding_choice = self::validate_boolean( $value, $request, $param );
3036 - }
3037 - if ( is_wp_error( $onboarding_choice ) ) {
3038 - return $onboarding_choice;
3039 - }
3040 - }
2643 + public static function validate_onboarding( $onboarding_data, $request, $param ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
2644 + _deprecated_function( __METHOD__, '13.9' );
3041 2645 return true;
3042 2646 }
3043 2647
3044 2648 /**
@@ -3234,14 +2838,14 @@
3234 2838 *
3235 2839 * @return bool|WP_Error
3236 2840 */
3237 2841 public static function validate_verification_service( $value, $request, $param ) {
3238 - if ( ! empty( $value ) && ! ( is_string( $value ) && ( preg_match( '/^[a-z0-9_-]+$/i', $value ) || jetpack_verification_get_code( $value ) !== false ) ) ) {
2842 + if ( ! empty( $value ) && ( ! is_string( $value ) || false === jetpack_verification_validate_code( $value ) ) ) {
3239 2843 return new WP_Error(
3240 2844 'invalid_param',
3241 2845 sprintf(
3242 2846 /* Translators: Placeholder is a verification string used to verify a service like Google Webmaster Console. */
3243 - esc_html__( '%s must be an alphanumeric string or a verification tag.', 'jetpack' ),
2847 + esc_html__( '%s must be a valid verification code or verification tag.', 'jetpack' ),
3244 2848 $param
3245 2849 )
3246 2850 );
3247 2851 }
@@ -3252,9 +2856,9 @@
3252 2856 * Validates that the parameter is among the roles allowed for Stats.
3253 2857 *
3254 2858 * @since 4.3.0
3255 2859 *
3256 - * @param string|bool $value Value to check.
2860 + * @param mixed $value Value to check.
3257 2861 * @param WP_REST_Request $request The request sent to the WP REST API.
3258 2862 * @param string $param Name of the parameter passed to endpoint holding $value.
3259 2863 *
3260 2864 * @return bool|WP_Error
@@ -3259,16 +2863,37 @@
3259 2863 *
3260 2864 * @return bool|WP_Error
3261 2865 */
3262 2866 public static function validate_stats_roles( $value, $request, $param ) {
3263 - if ( ! empty( $value ) && ! array_intersect( self::$stats_roles, $value ) ) {
2867 + // An empty value clears the setting; sanitize_stats_allowed_roles() falls back to 'administrator'.
2868 + if ( empty( $value ) ) {
2869 + return true;
2870 + }
2871 +
2872 + // Enforce the schema's list-of-strings contract before array_intersect() below sees the value.
2873 + if ( ! is_array( $value ) || count( array_filter( $value, 'is_string' ) ) !== count( $value ) ) {
3264 2874 return new WP_Error(
3265 2875 'invalid_param',
3266 2876 sprintf(
2877 + /* Translators: Placeholder is a parameter name. */
2878 + esc_html__( '%s must be an array of user roles.', 'jetpack' ),
2879 + $param
2880 + )
2881 + );
2882 + }
2883 +
2884 + if ( ! function_exists( 'get_editable_roles' ) ) {
2885 + require_once ABSPATH . 'wp-admin/includes/user.php';
2886 + }
2887 + $editable_roles = array_keys( get_editable_roles() );
2888 + if ( ! array_intersect( $editable_roles, $value ) ) {
2889 + return new WP_Error(
2890 + 'invalid_param',
2891 + sprintf(
3267 2892 /* 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. */
3268 2893 esc_html__( '%1$s must be %2$s.', 'jetpack' ),
3269 2894 $param,
3270 - implode( ', ', self::$stats_roles )
2895 + implode( ', ', $editable_roles )
3271 2896 )
3272 2897 );
3273 2898 }
3274 2899 return true;
@@ -3311,8 +2936,59 @@
3311 2936 return true;
3312 2937 }
3313 2938
3314 2939 /**
2940 + * Validates that the parameter is among the valid reply-to types for subscriptions.
2941 + *
2942 + * @since 4.3.0
2943 + *
2944 + * @param string|bool $value Value to check.
2945 + * @param WP_REST_Request $request The request sent to the WP REST API.
2946 + * @param string $param Name of the parameter passed to endpoint holding $value.
2947 + *
2948 + * @return bool|WP_Error
2949 + */
2950 + public static function validate_subscriptions_reply_to( $value, $request, $param ) {
2951 + require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
2952 + if ( ! empty( $value ) && ! Automattic\Jetpack\Modules\Subscriptions\Settings::is_valid_reply_to( $value ) ) {
2953 + return new WP_Error(
2954 + 'invalid_param',
2955 + sprintf(
2956 + /* Translators: Placeholder is a parameter name. */
2957 + esc_html__( '%s must be a valid type.', 'jetpack' ),
2958 + $param
2959 + )
2960 + );
2961 + }
2962 + return true;
2963 + }
2964 +
2965 + /**
2966 + * Validates that the parameter is among the valid reply-to types for subscriptions.
2967 + *
2968 + * @since 4.3.0
2969 + *
2970 + * @param string|bool $value Value to check.
2971 + * @param WP_REST_Request $request The request sent to the WP REST API.
2972 + * @param string $param Name of the parameter passed to endpoint holding $value.
2973 + *
2974 + * @return bool|WP_Error
2975 + */
2976 + public static function validate_subscriptions_reply_to_name( $value, $request, $param ) {
2977 + if ( ! empty( $value ) && ! is_string( $value ) ) {
2978 + return new WP_Error(
2979 + 'invalid_param',
2980 + sprintf(
2981 + /* Translators: Placeholder is a parameter name. */
2982 + esc_html__( '%s must be a valid type.', 'jetpack' ),
2983 + $param
2984 + )
2985 + );
2986 + }
2987 + return true;
2988 + }
2989 +
2990 + /**
3315 2991 * Validates that the parameter is among the views where the Sharing can be displayed.
3316 2992 *
3317 2993 * @since 4.3.0
3318 2994 *
@@ -3527,16 +3203,72 @@
3527 3203 return true;
3528 3204 }
3529 3205
3530 3206 /**
3207 + * Validates the subscription_options parameter.
3208 + *
3209 + * @param array $values Value to check.
3210 + *
3211 + * @return bool|WP_Error
3212 + */
3213 + public static function validate_subscription_options( $values ) {
3214 + // A REST "object" decodes to a PHP associative array. Reject any other
3215 + // type (object, string, int, null, ...) up front so the array_keys()
3216 + // loop below never runs against a non-array and triggers a PHP warning.
3217 + if ( ! is_array( $values ) ) {
3218 + return new WP_Error(
3219 + 'invalid_param',
3220 + /* Translators: subscription_options is a variable name, and shouldn't be translated. */
3221 + esc_html__( 'subscription_options must be an object.', 'jetpack' )
3222 + );
3223 + }
3224 + foreach ( array_keys( $values ) as $key ) {
3225 + if ( ! in_array( $key, array( 'welcome', 'invitation', 'comment_follow', 'subscribe_modal_heading', 'free_tier_description', 'hide_free_tier' ), true ) ) {
3226 + return new WP_Error(
3227 + 'invalid_param',
3228 + sprintf(
3229 + /* Translators: Placeholder is the invalid param being sent. */
3230 + esc_html__( '%s is not one of the allowed members of subscription_options.', 'jetpack' ),
3231 + $key
3232 + )
3233 + );
3234 + }
3235 + }
3236 + return true;
3237 + }
3238 +
3239 + /**
3240 + * Validates that the parameter is an array.
3241 + *
3242 + * @param array $values Value to check.
3243 + * @param WP_REST_Request $request The request sent to the WP REST API.
3244 + * @param string $param Name of the parameter passed to the endpoint holding $value.
3245 + *
3246 + * @return bool|WP_Error
3247 + */
3248 + public static function validate_array( $values, $request, $param ) {
3249 + if ( ! is_array( $values ) ) {
3250 + return new WP_Error(
3251 + 'invalid_param',
3252 + sprintf(
3253 + /* Translators: Placeholder is a parameter name. */
3254 + esc_html__( '%s must be an object.', 'jetpack' ),
3255 + $param
3256 + )
3257 + );
3258 + }
3259 + return true;
3260 + }
3261 +
3262 + /**
3531 3263 * If for some reason the roles allowed to see Stats are empty (for example, user tampering with checkboxes),
3532 3264 * return an array with only 'administrator' as the allowed role and save it for 'roles' option.
3533 3265 *
3534 3266 * @since 4.3.0
3535 3267 *
3536 - * @param string|bool $value Value to check.
3268 + * @param mixed $value Value to check.
3537 3269 *
3538 - * @return bool|array
3270 + * @return mixed The value as submitted, or an array holding only 'administrator' when it is empty.
3539 3271 */
3540 3272 public static function sanitize_stats_allowed_roles( $value ) {
3541 3273 if ( empty( $value ) ) {
3542 3274 return array( 'administrator' );
@@ -3544,8 +3276,31 @@
3544 3276 return $value;
3545 3277 }
3546 3278
3547 3279 /**
3280 + * Sanitize the AI crawler override map.
3281 + *
3282 + * Keeps the value package-agnostic: each key is normalized with sanitize_key()
3283 + * and each value cast to bool. Catalog validation and default-pruning happen in
3284 + * `Automattic\Jetpack\SEO\Ai_Crawlers::get_overrides()`.
3285 + *
3286 + * @param mixed $value The submitted override map.
3287 + *
3288 + * @return array<string, bool> Sanitized `slug => bool` map.
3289 + */
3290 + public static function sanitize_ai_crawler_overrides( $value ) {
3291 + if ( ! is_array( $value ) ) {
3292 + return array();
3293 + }
3294 +
3295 + $sanitized = array();
3296 + foreach ( $value as $k => $v ) {
3297 + $sanitized[ sanitize_key( $k ) ] = (bool) $v;
3298 + }
3299 + return $sanitized;
3300 + }
3301 +
3302 + /**
3548 3303 * Get the currently accessed route and return the module slug in it.
3549 3304 *
3550 3305 * @since 4.3.0
3551 3306 *
@@ -3554,9 +3309,9 @@
3554 3309 * @return array|string
3555 3310 */
3556 3311 public static function get_module_requested( $route = '/module/(?P<slug>[a-z\-]+)' ) {
3557 3312
3558 - if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
3313 + if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) || ! is_string( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
3559 3314 return '';
3560 3315 }
3561 3316
3562 3317 preg_match( "#$route#", $GLOBALS['wp']->query_vars['rest_route'], $module );
@@ -3607,8 +3362,40 @@
3607 3362 return $modules;
3608 3363 }
3609 3364
3610 3365 /**
3366 + * Remove options the current user cannot read.
3367 + *
3368 + * Covers every `jetpack_waf_*` option, plus the two Protect options that expose the
3369 + * same data under a different name: `jetpack_protect_global_whitelist` is populated
3370 + * from `jetpack_waf_ip_allow_list`, and `jetpack_protect_key` is a shared secret.
3371 + *
3372 + * @since 16.2
3373 + *
3374 + * @param array $options Option definitions keyed by option name.
3375 + * @return array
3376 + */
3377 + public static function filter_options_for_response( $options ) {
3378 + if ( current_user_can( 'manage_options' ) ) {
3379 + return $options;
3380 + }
3381 +
3382 + $restricted = array(
3383 + 'jetpack_protect_key',
3384 + 'jetpack_protect_global_whitelist',
3385 + );
3386 +
3387 + return array_filter(
3388 + $options,
3389 + static function ( $option_name ) use ( $restricted ) {
3390 + return 0 !== strpos( $option_name, 'jetpack_waf_' )
3391 + && ! in_array( $option_name, $restricted, true );
3392 + },
3393 + ARRAY_FILTER_USE_KEY
3394 + );
3395 + }
3396 +
3397 + /**
3611 3398 * Remove 'validate_callback' item from options available for module.
3612 3399 * Fetch current option value and add to array of module options.
3613 3400 * Prepare values of module options that need special handling, like those saved in wpcom.
3614 3401 *
@@ -3671,9 +3458,9 @@
3671 3458 $options = self::split_options( $options, $sharer->get_global_options() );
3672 3459 $options['sharing_services']['current_value'] = $sharer->get_blog_services();
3673 3460 $other_sharedaddy_options = array( 'jetpack-twitter-cards-site-tag', 'sharedaddy_disable_resources', 'sharing_delete_service' );
3674 3461 foreach ( $other_sharedaddy_options as $key ) {
3675 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3462 + $default_value = $options[ $key ]['default'] ?? '';
3676 3463 $current_value = get_option( $key, $default_value );
3677 3464 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3678 3465 }
3679 3466 break;
@@ -3684,9 +3471,9 @@
3684 3471 break;
3685 3472 default:
3686 3473 // These option are just stored as plain WordPress options.
3687 3474 foreach ( $options as $key => $value ) {
3688 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3475 + $default_value = $options[ $key ]['default'] ?? '';
3689 3476 $current_value = get_option( $key, $default_value );
3690 3477 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3691 3478 }
3692 3479 }
@@ -3696,14 +3483,17 @@
3696 3483 // We don't need validate_callback in the response.
3697 3484 if ( isset( $options[ $key ]['validate_callback'] ) ) {
3698 3485 unset( $options[ $key ]['validate_callback'] );
3699 3486 }
3700 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3487 + $default_value = $options[ $key ]['default'] ?? '';
3701 3488 if ( ! array_key_exists( 'current_value', $options[ $key ] ) ) {
3702 3489 $options[ $key ]['current_value'] = self::cast_value( $default_value, $options[ $key ] );
3703 3490 }
3704 3491 }
3705 - return $options;
3492 +
3493 + // Filter last: the switch above assigns current_value by key without isset(),
3494 + // so filtering earlier would let those assignments re-add a removed option.
3495 + return self::filter_options_for_response( $options );
3706 3496 }
3707 3497
3708 3498 /**
3709 3499 * Splits module options saved as arrays like relatedposts or verification_services_codes into separate options to be returned in the response.
@@ -4208,61 +3998,52 @@
4208 3998 return rest_ensure_response( array( 'success' => $updated_option ) );
4209 3999 }
4210 4000
4211 4001 /**
4212 - * Fetch introdution offers.
4002 + * Return the list of available features.
4213 4003 *
4214 - * @since 10.9
4215 - *
4216 - * @return array|WP_Error
4004 + * @return array
4217 4005 */
4218 - public static function get_intro_offers() {
4219 - $site_id = Jetpack_Options::get_option( 'id' );
4220 -
4221 - if ( ! $site_id ) {
4222 - return new WP_Error(
4223 - 'site_id_missing',
4224 - esc_html__( 'Site ID is missing.', 'jetpack' ),
4225 - array( 'status' => 400 )
4226 - );
4006 + public static function get_features_available() {
4007 + $raw_modules = Jetpack::get_available_modules();
4008 + $modules = array();
4009 + foreach ( $raw_modules as $module ) {
4010 + $modules[] = Jetpack::get_module_slug( $module );
4227 4011 }
4228 4012
4229 - $response = Client::wpcom_json_api_request_as_user(
4230 - '/introductory-offers',
4231 - '2',
4232 - array(
4233 - 'method' => 'GET',
4234 - 'headers' => array(
4235 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
4236 - ),
4237 - )
4238 - );
4013 + return $modules;
4014 + }
4239 4015
4240 - $response_code = wp_remote_retrieve_response_code( $response );
4241 -
4242 - if ( 200 !== $response_code ) {
4243 - return new WP_Error(
4244 - 'intro_offers_fetch_failed',
4245 - esc_html__( 'Could not retrieve intro offers.', 'jetpack' ),
4246 - array( 'status' => $response_code )
4247 - );
4016 + /**
4017 + * Returns what features are enabled. Uses the slug of the modules files.
4018 + *
4019 + * @return array
4020 + */
4021 + public static function get_features_enabled() {
4022 + $raw_modules = Jetpack::get_active_modules();
4023 + $modules = array();
4024 + foreach ( $raw_modules as $module ) {
4025 + $modules[] = Jetpack::get_module_slug( $module );
4248 4026 }
4249 4027
4250 - $data = json_decode( wp_remote_retrieve_body( $response ) );
4028 + return $modules;
4029 + }
4251 4030
4252 - if ( ! isset( $data ) ) {
4253 - return new WP_Error(
4254 - 'intro_offers_error',
4255 - esc_html__( 'Could not parse intro offers.', 'jetpack' ),
4256 - array( 'status' => 204 ) // no content.
4031 + /**
4032 + * Verify that the API client is allowed to replace user token.
4033 + *
4034 + * @since 1.29.0
4035 + *
4036 + * @return bool|WP_Error
4037 + */
4038 + public static function get_features_permission_check() {
4039 + if ( ! Rest_Authentication::is_signed_with_blog_token() ) {
4040 + $message = esc_html__(
4041 + 'You do not have the correct user permissions to perform this action. Please contact your site admin if you think this is a mistake.',
4042 + 'jetpack'
4257 4043 );
4044 + return new WP_Error( 'invalid_permission_fetch_features', $message, array( 'status' => rest_authorization_required_code() ) );
4258 4045 }
4259 4046
4260 - return rest_ensure_response(
4261 - array(
4262 - 'code' => 'success',
4263 - 'data' => $data,
4264 - )
4265 - );
4047 + return true;
4266 4048 }
4267 -
4268 4049 } // class end