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