PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | _inc/lib/class.core-rest-api-endpoints.php +389 -858 13.8.3 → 16.3-a.5 View file →
@@ -8,10 +8,10 @@
8 8 use Automattic\Jetpack\Connection\Client;
9 9 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
10 10 use Automattic\Jetpack\Connection\Rest_Authentication;
11 11 use Automattic\Jetpack\Connection\REST_Connector;
12 +use Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT;
12 13 use Automattic\Jetpack\Connection\SSO;
13 -use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
14 14 use Automattic\Jetpack\Jetpack_CRM_Data;
15 15 use Automattic\Jetpack\Plugins_Installer;
16 16 use Automattic\Jetpack\Stats\Options as Stats_Options;
17 17 use Automattic\Jetpack\Status\Host;
@@ -20,9 +20,9 @@
20 20 use Automattic\Jetpack\Waf\Waf_Compatibility;
21 21
22 22 // Disable direct access.
23 23 if ( ! defined( 'ABSPATH' ) ) {
24 - exit;
24 + exit( 0 );
25 25 }
26 26
27 27 // Load WP_Error for error messages.
28 28 require_once ABSPATH . '/wp-includes/class-wp-error.php';
@@ -32,8 +32,10 @@
32 32 // Load API endpoints that are synced with WP.com
33 33 // Each of these is a class that will register its own routes on 'rest_api_init'.
34 34 require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/load-wpcom-endpoints.php';
35 35
36 +require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
37 +
36 38 /**
37 39 * Class Jetpack_Core_Json_Api_Endpoints
38 40 *
39 41 * @since 4.3.0
@@ -70,23 +72,10 @@
70 72 $module_toggle_endpoint = new Jetpack_Core_API_Module_Toggle_Endpoint( new Jetpack_IXR_Client() );
71 73 $site_endpoint = new Jetpack_Core_API_Site_Endpoint();
72 74 $widget_endpoint = new Jetpack_Core_API_Widget_Endpoint();
73 75
74 - /**
75 - * TODO: Move me somewhere that makes more sense.
76 - * Also give me permissions that aren't awful.
77 - */
78 - register_rest_route(
79 - 'jetpack/v4',
80 - 'jetpack-ai-jwt',
81 - array(
82 - 'methods' => WP_REST_Server::EDITABLE,
83 - 'callback' => __CLASS__ . '::get_openai_jwt',
84 - 'permission_callback' => function () {
85 - return ( new Connection_Manager( 'jetpack' ) )->is_user_connected() && current_user_can( 'edit_posts' );
86 - },
87 - )
88 - );
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();
89 78
90 79 register_rest_route(
91 80 'jetpack/v4',
92 81 'plans',
@@ -116,32 +105,10 @@
116 105 'permission_callback' => __CLASS__ . '::disconnect_site_permission_callback',
117 106 )
118 107 );
119 108
120 - // Test current connection status of Jetpack.
121 109 register_rest_route(
122 110 'jetpack/v4',
123 - '/connection/test',
124 - array(
125 - 'methods' => WP_REST_Server::READABLE,
126 - 'callback' => __CLASS__ . '::jetpack_connection_test',
127 - 'permission_callback' => __CLASS__ . '::manage_modules_permission_check',
128 - )
129 - );
130 -
131 - // Endpoint specific for privileged servers to request detailed debug information.
132 - register_rest_route(
133 - 'jetpack/v4',
134 - '/connection/test-wpcom/',
135 - array(
136 - 'methods' => WP_REST_Server::READABLE,
137 - 'callback' => __CLASS__ . '::jetpack_connection_test_for_external',
138 - 'permission_callback' => __CLASS__ . '::view_jetpack_connection_test_check',
139 - )
140 - );
141 -
142 - register_rest_route(
143 - 'jetpack/v4',
144 111 '/rewind',
145 112 array(
146 113 'methods' => WP_REST_Server::READABLE,
147 114 'callback' => __CLASS__ . '::get_rewind_data',
@@ -194,33 +161,11 @@
194 161 ),
195 162 )
196 163 );
197 164
198 - // Disconnect/unlink user from WordPress.com servers.
165 + // Get current site features.
199 166 register_rest_route(
200 167 'jetpack/v4',
201 - '/connection/user',
202 - array(
203 - 'methods' => WP_REST_Server::EDITABLE,
204 - 'callback' => __CLASS__ . '::unlink_user',
205 - 'permission_callback' => __CLASS__ . '::unlink_user_permission_callback',
206 - )
207 - );
208 -
209 - // Get current site data.
210 - register_rest_route(
211 - 'jetpack/v4',
212 - '/site',
213 - array(
214 - 'methods' => WP_REST_Server::READABLE,
215 - 'callback' => __CLASS__ . '::get_site_data',
216 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
217 - )
218 - );
219 -
220 - // Get current site data.
221 - register_rest_route(
222 - 'jetpack/v4',
223 168 '/site/features',
224 169 array(
225 170 'methods' => WP_REST_Server::READABLE,
226 171 'callback' => array( $site_endpoint, 'get_features' ),
@@ -604,103 +549,8 @@
604 549 ),
605 550 )
606 551 );
607 552
608 - register_rest_route(
609 - 'jetpack/v4',
610 - '/recommendations/data',
611 - array(
612 - array(
613 - 'methods' => WP_REST_Server::READABLE,
614 - 'callback' => __CLASS__ . '::get_recommendations_data',
615 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
616 - ),
617 - array(
618 - 'methods' => WP_REST_Server::EDITABLE,
619 - 'callback' => __CLASS__ . '::update_recommendations_data',
620 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
621 - 'args' => array(
622 - 'data' => array(
623 - 'required' => true,
624 - 'type' => 'object',
625 - 'validate_callback' => __CLASS__ . '::validate_recommendations_data',
626 - ),
627 - ),
628 - ),
629 - )
630 - );
631 -
632 - register_rest_route(
633 - 'jetpack/v4',
634 - '/recommendations/step',
635 - array(
636 - array(
637 - 'methods' => WP_REST_Server::READABLE,
638 - 'callback' => __CLASS__ . '::get_recommendations_step',
639 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
640 - ),
641 - array(
642 - 'methods' => WP_REST_Server::EDITABLE,
643 - 'callback' => __CLASS__ . '::update_recommendations_step',
644 - 'permission_callback' => __CLASS__ . '::update_settings_permission_check',
645 - 'args' => array(
646 - 'step' => array(
647 - 'required' => true,
648 - 'type' => 'string',
649 - 'validate_callback' => __CLASS__ . '::validate_string',
650 - ),
651 - ),
652 - ),
653 - )
654 - );
655 -
656 - register_rest_route(
657 - 'jetpack/v4',
658 - '/recommendations/product-suggestions',
659 - array(
660 - array(
661 - 'methods' => WP_REST_Server::READABLE,
662 - 'callback' => __CLASS__ . '::get_recommendations_product_suggestions',
663 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
664 - ),
665 - )
666 - );
667 -
668 - register_rest_route(
669 - 'jetpack/v4',
670 - '/recommendations/upsell',
671 - array(
672 - array(
673 - 'methods' => WP_REST_Server::READABLE,
674 - 'callback' => __CLASS__ . '::get_recommendations_upsell',
675 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
676 - ),
677 - )
678 - );
679 -
680 - register_rest_route(
681 - 'jetpack/v4',
682 - '/recommendations/conditional',
683 - array(
684 - array(
685 - 'methods' => WP_REST_Server::READABLE,
686 - 'callback' => __CLASS__ . '::get_conditional_recommendations',
687 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
688 - ),
689 - )
690 - );
691 -
692 - // Get site discount.
693 - register_rest_route(
694 - 'jetpack/v4',
695 - '/site/discount',
696 - array(
697 - 'methods' => WP_REST_Server::READABLE,
698 - 'callback' => __CLASS__ . '::get_site_discount',
699 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
700 - )
701 - );
702 -
703 553 /*
704 554 * Manage the Jetpack CRM plugin's integration with Jetpack contact forms.
705 555 */
706 556 register_rest_route(
@@ -755,19 +605,8 @@
755 605 'permission_callback' => __CLASS__ . '::manage_modules_permission_check',
756 606 )
757 607 );
758 608
759 - // Get Jetpack introduction offers
760 - register_rest_route(
761 - 'jetpack/v4',
762 - '/intro-offers',
763 - array(
764 - 'methods' => WP_REST_Server::READABLE,
765 - 'callback' => __CLASS__ . '::get_intro_offers',
766 - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check',
767 - )
768 - );
769 -
770 609 // Save subscriber token and redirect
771 610 register_rest_route(
772 611 'jetpack/v4',
773 612 '/subscribers/auth',
@@ -786,42 +625,59 @@
786 625 ),
787 626 ),
788 627 )
789 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 + );
790 659 }
791 660
792 661 /**
793 662 * Ask WPCOM for a JWT token to use for OpenAI conversations.
794 - * 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.
795 668 */
796 669 public static function get_openai_jwt() {
797 - $blog_id = \Jetpack_Options::get_option( 'id' );
670 + _deprecated_function( __METHOD__, 'jetpack-16.2', '\Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT::get_jwt' );
798 671
799 - $response = \Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user(
800 - "/sites/$blog_id/jetpack-openai-query/jwt",
801 - '2',
802 - array(
803 - 'method' => 'POST',
804 - 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ),
805 - ),
806 - wp_json_encode( array() ),
807 - 'wpcom'
808 - );
672 + $response = ( new REST_Jetpack_AI_JWT() )->get_jwt();
809 673
810 674 if ( is_wp_error( $response ) ) {
811 675 return $response;
812 676 }
813 677
814 - $json = json_decode( wp_remote_retrieve_body( $response ) );
815 -
816 - if ( ! isset( $json->token ) ) {
817 - return new WP_Error( 'no-token', 'No token returned from WPCOM' );
818 - }
819 -
820 - return array(
821 - 'token' => $json->token,
822 - 'blog_id' => $blog_id,
823 - );
678 + // Pre-deprecation callers expect the raw array, not a WP_REST_Response.
679 + return $response->get_data();
824 680 }
825 681
826 682 /**
827 683 * Set subscriber cookie and redirect
@@ -832,191 +688,27 @@
832 688 */
833 689 public static function set_subscriber_cookie_and_redirect( $request ) {
834 690 require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
835 691 $subscription_service = \Automattic\Jetpack\Extensions\Premium_Content\subscription_service();
836 - $token = $subscription_service->get_and_set_token_from_request();
837 - $payload = $subscription_service->decode_token( $token );
838 - $is_valid_token = ! empty( $payload );
839 - if ( $is_valid_token ) {
840 - 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 ) );
841 699 }
842 - return new WP_Error( 'invalid-token', 'Invalid Token' );
843 - }
844 700
845 - /**
846 - * Get the data for the recommendations
847 - *
848 - * @return array Recommendations data
849 - */
850 - public static function get_recommendations_data() {
851 - return Jetpack_Recommendations::get_recommendations_data();
852 - }
853 -
854 - /**
855 - * Update the data for the recommendations
856 - *
857 - * @param WP_REST_Request $request The request.
858 - *
859 - * @return bool true
860 - */
861 - public static function update_recommendations_data( $request ) {
862 - $data = $request['data'];
863 - Jetpack_Recommendations::update_recommendations_data( $data );
864 -
865 - return true;
866 - }
867 -
868 - /**
869 - * Get the data for the recommendations
870 - *
871 - * @return array Recommendations data
872 - */
873 - public static function get_recommendations_step() {
874 - return Jetpack_Recommendations::get_recommendations_step();
875 - }
876 -
877 - /**
878 - * Update the step for the recommendations
879 - *
880 - * @param WP_REST_Request $request The request.
881 - *
882 - * @return bool true
883 - */
884 - public static function update_recommendations_step( $request ) {
885 - $step = $request['step'];
886 - Jetpack_Recommendations::update_recommendations_step( $step );
887 -
888 - return true;
889 - }
890 -
891 - /**
892 - * Get product suggestions for the recommendations
893 - *
894 - * @return string|WP_Error The response from the wpcom product suggestions endpoint as a JSON object.
895 - */
896 - public static function get_recommendations_product_suggestions() {
897 - $blog_id = Jetpack_Options::get_option( 'id' );
898 - if ( ! $blog_id ) {
899 - 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 ) );
900 705 }
901 706
902 - $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() );
903 - if ( ! $user_connected ) {
904 - return wp_json_encode( array() );
905 - }
906 -
907 - $request_path = sprintf( '/sites/%s/jetpack-recommendations/product-suggestions?locale=' . get_user_locale(), $blog_id );
908 - $wpcom_request = Client::wpcom_json_api_request_as_user(
909 - $request_path,
910 - '2',
911 - array(
912 - 'method' => 'GET',
913 - 'headers' => array(
914 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
915 - ),
916 - )
917 - );
918 -
919 - $response_code = wp_remote_retrieve_response_code( $wpcom_request );
920 - if ( 200 === $response_code ) {
921 - return json_decode( wp_remote_retrieve_body( $wpcom_request ) );
922 - } else {
923 - return new WP_Error(
924 - 'failed_to_fetch_data',
925 - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
926 - array( 'status' => $response_code )
927 - );
928 - }
707 + return new WP_REST_Response( null, 302, array( 'location' => $redirect_url ) );
929 708 }
930 709
931 710 /**
932 - * Get the upsell for the recommendations
933 - *
934 - * @return string The response from the wpcom upsell endpoint as a JSON object
935 - */
936 - public static function get_recommendations_upsell() {
937 - $blog_id = Jetpack_Options::get_option( 'id' );
938 - if ( ! $blog_id ) {
939 - return new WP_Error( 'site_not_registered', esc_html__( 'Site not registered.', 'jetpack' ) );
940 - }
941 -
942 - $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() );
943 - if ( ! $user_connected ) {
944 - $response = array(
945 - 'hide_upsell' => true,
946 - );
947 -
948 - return $response;
949 - }
950 -
951 - $request_path = sprintf( '/sites/%s/jetpack-recommendations/upsell?locale=' . get_user_locale(), $blog_id );
952 - $wpcom_request = Client::wpcom_json_api_request_as_user(
953 - $request_path,
954 - '2',
955 - array(
956 - 'method' => 'GET',
957 - 'headers' => array(
958 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
959 - ),
960 - )
961 - );
962 -
963 - $response_code = wp_remote_retrieve_response_code( $wpcom_request );
964 - if ( 200 === $response_code ) {
965 - return json_decode( wp_remote_retrieve_body( $wpcom_request ) );
966 - } else {
967 - return new WP_Error(
968 - 'failed_to_fetch_data',
969 - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ),
970 - array( 'status' => $response_code )
971 - );
972 - }
973 - }
974 -
975 - /**
976 - * Get conditional recommendations data.
977 - *
978 - * @return array Conditional recommendations data.
979 - */
980 - public static function get_conditional_recommendations() {
981 - return Jetpack_Recommendations::get_conditional_recommendations();
982 - }
983 -
984 - /**
985 - * Validate the recommendations data
986 - *
987 - * @param array $value Value to check received by request.
988 - * @param WP_REST_Request $request The request sent to the WP REST API.
989 - * @param string $param Name of the parameter passed to endpoint holding $value.
990 - *
991 - * @return bool|WP_Error
992 - */
993 - public static function validate_recommendations_data( $value, $request, $param ) {
994 - if ( ! is_array( $value ) ) {
995 - /* translators: Name of a parameter that must be an object */
996 - return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an object.', 'jetpack' ), $param ) );
997 - }
998 -
999 - foreach ( $value as $answer ) {
1000 - if ( is_array( $answer ) ) {
1001 - $validate = self::validate_array_of_strings( $answer, $request, $param );
1002 - } elseif ( is_string( $answer ) ) {
1003 - $validate = self::validate_string( $answer, $request, $param );
1004 - } elseif ( $answer === null ) {
1005 - $validate = true;
1006 - } else {
1007 - $validate = self::validate_boolean( $answer, $request, $param );
1008 - }
1009 -
1010 - if ( is_wp_error( $validate ) ) {
1011 - return $validate;
1012 - }
1013 - }
1014 -
1015 - return true;
1016 - }
1017 -
1018 - /**
1019 711 * Return a purchase token used for site-connected (non user-authenticated) checkout.
1020 712 *
1021 713 * @return string|WP_Error The current purchase token or WP_Error with error details.
1022 714 */
@@ -1171,8 +863,9 @@
1171 863 || Jetpack::is_plugin_active( 'mojo-under-construction/mojo-contruction.php' ) && 1 == $under_construction_activation_status // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1172 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
1173 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
1174 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 + ||
1175 868 /**
1176 869 * Allow plugins to mark a site as "under construction".
1177 870 *
1178 871 * @since 6.7.0
@@ -1178,9 +871,9 @@
1178 871 * @since 6.7.0
1179 872 *
1180 873 * @param false bool Is the site under construction? Default to false.
1181 874 */
1182 - || true === apply_filters( 'jetpack_is_under_construction_plugin', false )
875 + true === apply_filters( 'jetpack_is_under_construction_plugin', false )
1183 876 ) {
1184 877 return new WP_Error( 'forbidden', __( 'Site is under construction and cannot be verified', 'jetpack' ) );
1185 878 }
1186 879
@@ -1319,24 +1012,20 @@
1319 1012
1320 1013 /**
1321 1014 * Verify that a user can use the /connection/user endpoint. Has to be a registered user and be currently linked.
1322 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 + *
1323 1021 * @since 4.3.0
1324 1022 *
1325 - * @uses Automattic\Jetpack\Connection\Manager::is_user_connected();)
1326 - *
1327 1023 * @return bool|WP_Error True if user is able to unlink.
1328 1024 */
1329 1025 public static function unlink_user_permission_callback() {
1330 - if ( current_user_can( 'jetpack_connect_user' ) && ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() ) ) {
1331 - return true;
1332 - }
1333 -
1334 - return new WP_Error(
1335 - 'invalid_user_permission_unlink_user',
1336 - REST_Connector::get_user_permissions_error_msg(),
1337 - array( 'status' => rest_authorization_required_code() )
1338 - );
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();
1339 1028 }
1340 1029
1341 1030 /**
1342 1031 * Verify that user can manage Jetpack modules.
@@ -1471,136 +1160,8 @@
1471 1160 );
1472 1161 }
1473 1162
1474 1163 /**
1475 - * Test connection status for this Jetpack site.
1476 - *
1477 - * @since 6.8.0
1478 - *
1479 - * @return array|WP_Error WP_Error returned if connection test does not succeed.
1480 - */
1481 - public static function jetpack_connection_test() {
1482 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1483 - $cxntests = new Jetpack_Cxn_Tests();
1484 -
1485 - if ( $cxntests->pass() ) {
1486 - return rest_ensure_response(
1487 - array(
1488 - 'code' => 'success',
1489 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1490 - )
1491 - );
1492 - } else {
1493 - return $cxntests->output_fails_as_wp_error();
1494 - }
1495 - }
1496 -
1497 - /**
1498 - * Test connection permission check method.
1499 - *
1500 - * @since 7.1.0
1501 - *
1502 - * @return bool
1503 - */
1504 - public static function view_jetpack_connection_test_check() {
1505 - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- This is verifying the trusted caller via a shared private key and timestamp.
1506 - if ( ! isset( $_GET['signature'] ) || ! isset( $_GET['timestamp'] ) || ! isset( $_GET['url'] ) ) {
1507 - return false;
1508 - }
1509 - $signature = base64_decode( wp_unslash( $_GET['signature'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1510 -
1511 - $signature_data = wp_json_encode(
1512 - array(
1513 - 'rest_route' => isset( $_GET['rest_route'] ) ? filter_var( wp_unslash( $_GET['rest_route'] ) ) : null,
1514 - 'timestamp' => (int) $_GET['timestamp'],
1515 - 'url' => esc_url_raw( wp_unslash( $_GET['url'] ) ),
1516 - )
1517 - );
1518 -
1519 - if (
1520 - ! function_exists( 'openssl_verify' )
1521 - || 1 !== openssl_verify(
1522 - $signature_data,
1523 - $signature,
1524 - JETPACK__DEBUGGER_PUBLIC_KEY
1525 - )
1526 - ) {
1527 - return false;
1528 - }
1529 -
1530 - // signature timestamp must be within 5min of current time.
1531 - if ( abs( time() - (int) $_GET['timestamp'] ) > 300 ) {
1532 - return false;
1533 - }
1534 -
1535 - // phpcs:enable WordPress.Security.NonceVerification.Recommended
1536 -
1537 - return true;
1538 - }
1539 -
1540 - /**
1541 - * Test connection status for this Jetpack site, encrypt the results for decryption by a third-party.
1542 - *
1543 - * @since 7.1.0
1544 - *
1545 - * @return array|mixed|object|WP_Error
1546 - */
1547 - public static function jetpack_connection_test_for_external() {
1548 - // 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.
1549 - add_filter( 'jetpack_debugger_run_self_test', '__return_false' );
1550 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1551 - $cxntests = new Jetpack_Cxn_Tests();
1552 -
1553 - if ( $cxntests->pass() ) {
1554 - $result = array(
1555 - 'code' => 'success',
1556 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1557 - );
1558 - } else {
1559 - $error = $cxntests->output_fails_as_wp_error(); // Using this so the output is similar both ways.
1560 - $errors = array();
1561 -
1562 - // Borrowed from WP_REST_Server::error_to_response().
1563 - foreach ( (array) $error->errors as $code => $messages ) {
1564 - foreach ( (array) $messages as $message ) {
1565 - $errors[] = array(
1566 - 'code' => $code,
1567 - 'message' => $message,
1568 - 'data' => $error->get_error_data( $code ),
1569 - );
1570 - }
1571 - }
1572 -
1573 - $result = ( ! empty( $errors ) ) ? $errors[0] : null;
1574 - if ( count( $errors ) > 1 ) {
1575 - // Remove the primary error.
1576 - array_shift( $errors );
1577 - $result['additional_errors'] = $errors;
1578 - }
1579 - }
1580 -
1581 - $result = wp_json_encode( $result );
1582 -
1583 - $encrypted = $cxntests->encrypt_string_for_wpcom( $result );
1584 -
1585 - if ( ! $encrypted || ! is_array( $encrypted ) ) {
1586 - return rest_ensure_response(
1587 - array(
1588 - 'code' => 'action_required',
1589 - 'message' => 'Please request results from the in-plugin debugger',
1590 - )
1591 - );
1592 - }
1593 -
1594 - return rest_ensure_response(
1595 - array(
1596 - 'code' => 'response',
1597 - 'debug' => $encrypted,
1598 - )
1599 - );
1600 - }
1601 -
1602 - /**
1603 1164 * Fetch information about the Rewind status of the site.
1604 1165 */
1605 1166 public static function rewind_data() {
1606 1167 $site_id = Jetpack_Options::get_option( 'id' );
@@ -1643,9 +1204,9 @@
1643 1204 return rest_ensure_response(
1644 1205 array(
1645 1206 'code' => 'success',
1646 1207 'message' => esc_html__( 'Backup & Scan data correctly received.', 'jetpack' ),
1647 - 'data' => wp_json_encode( $rewind_data ),
1208 + 'data' => wp_json_encode( $rewind_data, JSON_UNESCAPED_SLASHES ),
1648 1209 )
1649 1210 );
1650 1211 }
1651 1212
@@ -1726,9 +1287,9 @@
1726 1287 return rest_ensure_response(
1727 1288 array(
1728 1289 'code' => 'success',
1729 1290 'message' => esc_html__( 'Scan state correctly received.', 'jetpack' ),
1730 - 'data' => wp_json_encode( $scan_state ),
1291 + 'data' => wp_json_encode( $scan_state, JSON_UNESCAPED_SLASHES ),
1731 1292 )
1732 1293 );
1733 1294 }
1734 1295
@@ -1785,10 +1346,10 @@
1785 1346 *
1786 1347 * @return string|WP_Error A raw URL if the connection URL could be built; error message otherwise.
1787 1348 */
1788 1349 public static function build_connect_url( $request = array() ) {
1789 - $from = isset( $request['from'] ) ? $request['from'] : false;
1790 - $redirect = isset( $request['redirect'] ) ? $request['redirect'] : false;
1350 + $from = $request['from'] ?? false;
1351 + $redirect = $request['redirect'] ?? false;
1791 1352
1792 1353 $url = Jetpack::init()->build_connect_url( true, $redirect, $from );
1793 1354 if ( $url ) {
1794 1355 return rest_ensure_response( $url );
@@ -1811,9 +1372,9 @@
1811 1372 */
1812 1373 public static function get_user_connection_data() {
1813 1374 _deprecated_function( __METHOD__, 'jetpack-10.0.0', '\Automattic\Jetpack\Connection\REST_Connector::get_user_connection_data' );
1814 1375
1815 - 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';
1816 1377
1817 1378 $connection_owner = ( new Connection_Manager() )->get_connection_owner();
1818 1379 $owner_display_name = false === $connection_owner ? null : $connection_owner->data->display_name;
1819 1380
@@ -1826,30 +1387,21 @@
1826 1387
1827 1388 /**
1828 1389 * Unlinks current user from the WordPress.com Servers.
1829 1390 *
1830 - * @since 4.3.0
1391 + * @param WP_REST_Request $request The request sent to the WP REST API.
1831 1392 * @uses Automattic\Jetpack\Connection\Manager->disconnect_user
1832 1393 *
1833 - * @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()
1834 1396 *
1397 + * @since 4.3.0
1398 + *
1835 1399 * @return bool|WP_Error True if user successfully unlinked.
1836 1400 */
1837 1401 public static function unlink_user( $request ) {
1838 -
1839 - if ( ! isset( $request['linked'] ) || false !== $request['linked'] ) {
1840 - return new WP_Error( 'invalid_param', esc_html__( 'Invalid Parameter', 'jetpack' ), array( 'status' => 404 ) );
1841 - }
1842 -
1843 - if ( ( new Connection_Manager( 'jetpack' ) )->disconnect_user() ) {
1844 - return rest_ensure_response(
1845 - array(
1846 - 'code' => 'success',
1847 - )
1848 - );
1849 - }
1850 -
1851 - 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 );
1852 1404 }
1853 1405
1854 1406 /**
1855 1407 * Gets current user's tracking settings.
@@ -1908,9 +1460,9 @@
1908 1460 'Content-Type' => 'application/json',
1909 1461 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
1910 1462 ),
1911 1463 ),
1912 - wp_json_encode( $request->get_params() )
1464 + wp_json_encode( $request->get_params(), JSON_UNESCAPED_SLASHES )
1913 1465 );
1914 1466 if ( ! is_wp_error( $response ) ) {
1915 1467 $response = json_decode( wp_remote_retrieve_body( $response ), true );
1916 1468 }
@@ -1922,93 +1474,30 @@
1922 1474 /**
1923 1475 * Fetch site data from .com including the site's current plan and the site's products.
1924 1476 *
1925 1477 * @since 5.5.0
1478 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\Manager::get_connected_site_data().
1926 1479 *
1927 1480 * @return stdClass|WP_Error
1928 1481 */
1929 1482 public static function site_data() {
1930 - $site_id = Jetpack_Options::get_option( 'id' );
1483 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\Manager::get_connected_site_data' );
1931 1484
1932 - if ( ! $site_id ) {
1933 - return new WP_Error( 'site_id_missing', '', array( 'api_error_code' => __( 'site_id_missing', 'jetpack' ) ) );
1934 - }
1485 + return ( new Connection_Manager() )->get_connected_site_data();
1486 + }
1935 1487
1936 - $args = array( 'headers' => array() );
1937 -
1938 - // Allow use a store sandbox. Internal ref: PCYsg-IA-p2.
1939 - if ( isset( $_COOKIE ) && isset( $_COOKIE['store_sandbox'] ) ) {
1940 - $secret = filter_var( wp_unslash( $_COOKIE['store_sandbox'] ) );
1941 - $args['headers']['Cookie'] = "store_sandbox=$secret;";
1942 - }
1943 -
1944 - $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ) . '?force=wpcom', '1.1', $args );
1945 - $body = wp_remote_retrieve_body( $response );
1946 - $data = $body ? json_decode( $body ) : null;
1947 -
1948 - if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
1949 - $error_info = array(
1950 - 'api_error_code' => null,
1951 - 'api_http_code' => wp_remote_retrieve_response_code( $response ),
1952 - );
1953 -
1954 - if ( is_wp_error( $response ) ) {
1955 - $error_info['api_error_code'] = $response->get_error_code() ? wp_strip_all_tags( $response->get_error_code() ) : null;
1956 - } elseif ( $data && ! empty( $data->error ) ) {
1957 - $error_info['api_error_code'] = $data->error;
1958 - }
1959 -
1960 - return new WP_Error( 'site_data_fetch_failed', '', $error_info );
1961 - }
1962 -
1963 - Jetpack_Plan::update_from_sites_response( $response );
1964 -
1965 - return $data;
1966 - }
1967 1488 /**
1968 1489 * Get site data, including for example, the site's current plan.
1969 1490 *
1491 + * @since 4.3.0
1492 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\REST_Connector::site_data_response().
1493 + *
1970 1494 * @return WP_Error|WP_HTTP_Response|WP_REST_Response
1971 - * @since 4.3.0
1972 1495 */
1973 1496 public static function get_site_data() {
1974 - $site_data = self::site_data();
1497 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\REST_Connector::site_data_response' );
1975 1498
1976 - if ( ! is_wp_error( $site_data ) ) {
1977 -
1978 - /**
1979 - * Fires when the site data was successfully returned from the /sites/%d wpcom endpoint.
1980 - *
1981 - * @since 8.7.0
1982 - */
1983 - do_action( 'jetpack_get_site_data_success' );
1984 - return rest_ensure_response(
1985 - array(
1986 - 'code' => 'success',
1987 - 'message' => esc_html__( 'Site data correctly received.', 'jetpack' ),
1988 - 'data' => wp_json_encode( $site_data ),
1989 - )
1990 - );
1991 - }
1992 -
1993 - $error_data = $site_data->get_error_data();
1994 -
1995 - if ( empty( $error_data['api_error_code'] ) ) {
1996 - $error_message = esc_html__( 'Failed fetching site data from WordPress.com. If the problem persists, try reconnecting Jetpack.', 'jetpack' );
1997 - } else {
1998 - /* translators: %s is an error code (e.g. `token_mismatch`) */
1999 - $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'] );
2000 - }
2001 -
2002 - return new WP_Error(
2003 - $site_data->get_error_code(),
2004 - $error_message,
2005 - array(
2006 - 'status' => 400,
2007 - 'api_error_code' => empty( $error_data['api_error_code'] ) ? null : $error_data['api_error_code'],
2008 - 'api_http_code' => empty( $error_data['api_http_code'] ) ? null : $error_data['api_http_code'],
2009 - )
2010 - );
1499 + return REST_Connector::site_data_response();
2011 1500 }
2012 1501
2013 1502 /**
2014 1503 * Fetch AL data for this site and return it.
@@ -2068,64 +1557,8 @@
2068 1557 );
2069 1558 }
2070 1559
2071 1560 /**
2072 - * Fetch the discount for this site and return it.
2073 - *
2074 - * @since 10.8
2075 - *
2076 - * @return array|WP_Error
2077 - */
2078 - public static function get_site_discount() {
2079 - $site_id = Jetpack_Options::get_option( 'id' );
2080 -
2081 - if ( ! $site_id ) {
2082 - return new WP_Error(
2083 - 'site_id_missing',
2084 - esc_html__( 'Site ID is missing.', 'jetpack' ),
2085 - array( 'status' => 400 )
2086 - );
2087 - }
2088 -
2089 - $response = Client::wpcom_json_api_request_as_user(
2090 - "/sites/$site_id/discount",
2091 - '2',
2092 - array(
2093 - 'method' => 'GET',
2094 - 'headers' => array(
2095 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
2096 - ),
2097 - )
2098 - );
2099 -
2100 - $response_code = wp_remote_retrieve_response_code( $response );
2101 - $data = json_decode( wp_remote_retrieve_body( $response ) );
2102 -
2103 - if ( 200 !== $response_code ) {
2104 - return new WP_Error(
2105 - 'discount_fetch_failed',
2106 - is_object( $data ) && property_exists( $data, 'error' ) ? $data->error : esc_html__( 'Could not retrieve site discount.', 'jetpack' ),
2107 - array( 'status' => $response_code )
2108 - );
2109 - }
2110 -
2111 - if ( ! isset( $data ) ) {
2112 - return new WP_Error(
2113 - 'discount_parse_error',
2114 - esc_html__( 'Could not parse discount', 'jetpack' ),
2115 - array( 'status' => 204 ) // no content.
2116 - );
2117 - }
2118 -
2119 - return rest_ensure_response(
2120 - array(
2121 - 'code' => 'success',
2122 - 'data' => $data,
2123 - )
2124 - );
2125 - }
2126 -
2127 - /**
2128 1561 * Reset Jetpack options
2129 1562 *
2130 1563 * @since 4.3.0
2131 1564 *
@@ -2223,9 +1656,9 @@
2223 1656 public static function get_updateable_data_list( $selector = '' ) {
2224 1657
2225 1658 $options = array(
2226 1659 // Blocks.
2227 - 'jetpack_blocks_disabled' => array(
1660 + 'jetpack_blocks_disabled' => array(
2228 1661 'description' => esc_html__( 'Jetpack Blocks disabled.', 'jetpack' ),
2229 1662 'type' => 'boolean',
2230 1663 'default' => false,
2231 1664 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2232,9 +1665,9 @@
2232 1665 'jp_group' => 'settings',
2233 1666 ),
2234 1667
2235 1668 // Carousel
2236 - 'carousel_background_color' => array(
1669 + 'carousel_background_color' => array(
2237 1670 'description' => esc_html__( 'Color scheme.', 'jetpack' ),
2238 1671 'type' => 'string',
2239 1672 'default' => 'black',
2240 1673 'enum' => array(
@@ -2247,9 +1680,9 @@
2247 1680 ),
2248 1681 'validate_callback' => __CLASS__ . '::validate_list_item',
2249 1682 'jp_group' => 'carousel',
2250 1683 ),
2251 - 'carousel_display_exif' => array(
1684 + 'carousel_display_exif' => array(
2252 1685 'description' => wp_kses(
2253 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' ) ),
2254 1687 array(
2255 1688 'a' => array(
@@ -2262,9 +1695,9 @@
2262 1695 'default' => 0,
2263 1696 'validate_callback' => __CLASS__ . '::validate_boolean',
2264 1697 'jp_group' => 'carousel',
2265 1698 ),
2266 - 'carousel_display_comments' => array(
1699 + 'carousel_display_comments' => array(
2267 1700 'description' => esc_html__( 'Show comments area in carousel', 'jetpack' ),
2268 1701 'type' => 'boolean',
2269 1702 'default' => 1,
2270 1703 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2271,9 +1704,9 @@
2271 1704 'jp_group' => 'carousel',
2272 1705 ),
2273 1706
2274 1707 // Comments.
2275 - 'highlander_comment_form_prompt' => array(
1708 + 'highlander_comment_form_prompt' => array(
2276 1709 'description' => esc_html__( 'Greeting Text', 'jetpack' ),
2277 1710 'type' => 'string',
2278 1711 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2279 1712 'sanitize_callback' => 'sanitize_text_field',
@@ -2278,9 +1711,9 @@
2278 1711 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2279 1712 'sanitize_callback' => 'sanitize_text_field',
2280 1713 'jp_group' => 'comments',
2281 1714 ),
2282 - 'jetpack_comment_form_color_scheme' => array(
1715 + 'jetpack_comment_form_color_scheme' => array(
2283 1716 'description' => esc_html__( 'Color scheme', 'jetpack' ),
2284 1717 'type' => 'string',
2285 1718 'default' => 'light',
2286 1719 'enum' => array(
@@ -2297,39 +1730,38 @@
2297 1730 'jp_group' => 'comments',
2298 1731 ),
2299 1732
2300 1733 // Custom Content Types.
2301 - 'jetpack_portfolio' => array(
1734 + 'jetpack_portfolio' => array(
2302 1735 'description' => esc_html__( 'Enable or disable Jetpack portfolio post type.', 'jetpack' ),
2303 1736 'type' => 'boolean',
2304 1737 'default' => 0,
2305 1738 'validate_callback' => __CLASS__ . '::validate_boolean',
2306 - 'jp_group' => 'custom-content-types',
1739 + 'jp_group' => 'settings',
2307 1740 ),
2308 - 'jetpack_portfolio_posts_per_page' => array(
1741 + 'jetpack_portfolio_posts_per_page' => array(
2309 1742 'description' => esc_html__( 'Number of entries to show at most in Portfolio pages.', 'jetpack' ),
2310 1743 'type' => 'integer',
2311 1744 'default' => 10,
2312 1745 'validate_callback' => __CLASS__ . '::validate_posint',
2313 - 'jp_group' => 'custom-content-types',
1746 + 'jp_group' => 'settings',
2314 1747 ),
2315 - 'jetpack_testimonial' => array(
1748 + 'jetpack_testimonial' => array(
2316 1749 'description' => esc_html__( 'Enable or disable Jetpack testimonial post type.', 'jetpack' ),
2317 1750 'type' => 'boolean',
2318 1751 'default' => 0,
2319 1752 'validate_callback' => __CLASS__ . '::validate_boolean',
2320 - 'jp_group' => 'custom-content-types',
1753 + 'jp_group' => 'settings',
2321 1754 ),
2322 - 'jetpack_testimonial_posts_per_page' => array(
1755 + 'jetpack_testimonial_posts_per_page' => array(
2323 1756 'description' => esc_html__( 'Number of entries to show at most in Testimonial pages.', 'jetpack' ),
2324 1757 'type' => 'integer',
2325 1758 'default' => 10,
2326 1759 'validate_callback' => __CLASS__ . '::validate_posint',
2327 - 'jp_group' => 'custom-content-types',
1760 + 'jp_group' => 'settings',
2328 1761 ),
2329 -
2330 1762 // WAF.
2331 - 'jetpack_waf_automatic_rules' => array(
1763 + 'jetpack_waf_automatic_rules' => array(
2332 1764 'description' => esc_html__( 'Enable automatic rules - Protect your site against untrusted traffic sources with automatic security rules.', 'jetpack' ),
2333 1765 'type' => 'boolean',
2334 1766 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2335 1767 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2334,9 +1766,9 @@
2334 1766 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2335 1767 'validate_callback' => __CLASS__ . '::validate_boolean',
2336 1768 'jp_group' => 'waf',
2337 1769 ),
2338 - 'jetpack_waf_ip_block_list_enabled' => array(
1770 + 'jetpack_waf_ip_block_list_enabled' => array(
2339 1771 'description' => esc_html__( 'Block list - Block a specific request IP.', 'jetpack' ),
2340 1772 'type' => 'boolean',
2341 1773 'default' => 0,
2342 1774 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2341,9 +1773,9 @@
2341 1773 'default' => 0,
2342 1774 'validate_callback' => __CLASS__ . '::validate_boolean',
2343 1775 'jp_group' => 'waf',
2344 1776 ),
2345 - 'jetpack_waf_ip_block_list' => array(
1777 + 'jetpack_waf_ip_block_list' => array(
2346 1778 'description' => esc_html__( 'Blocked IP addresses', 'jetpack' ),
2347 1779 'type' => 'string',
2348 1780 'default' => '',
2349 1781 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2349,9 +1781,9 @@
2349 1781 'validate_callback' => __CLASS__ . '::validate_string',
2350 1782 'sanitize_callback' => 'esc_textarea',
2351 1783 'jp_group' => 'waf',
2352 1784 ),
2353 - 'jetpack_waf_ip_allow_list_enabled' => array(
1785 + 'jetpack_waf_ip_allow_list_enabled' => array(
2354 1786 'description' => esc_html__( 'Allow list - Allow a specific request IP.', 'jetpack' ),
2355 1787 'type' => 'boolean',
2356 1788 'default' => 0,
2357 1789 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2356,9 +1788,9 @@
2356 1788 'default' => 0,
2357 1789 'validate_callback' => __CLASS__ . '::validate_boolean',
2358 1790 'jp_group' => 'settings',
2359 1791 ),
2360 - 'jetpack_waf_ip_allow_list' => array(
1792 + 'jetpack_waf_ip_allow_list' => array(
2361 1793 'description' => esc_html__( 'Always allowed IP addresses', 'jetpack' ),
2362 1794 'type' => 'string',
2363 1795 'default' => '',
2364 1796 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2364,9 +1796,9 @@
2364 1796 'validate_callback' => __CLASS__ . '::validate_string',
2365 1797 'sanitize_callback' => 'esc_textarea',
2366 1798 'jp_group' => 'settings',
2367 1799 ),
2368 - 'jetpack_waf_share_data' => array(
1800 + 'jetpack_waf_share_data' => array(
2369 1801 'description' => esc_html__( 'Share basic data with Jetpack.', 'jetpack' ),
2370 1802 'type' => 'boolean',
2371 1803 'default' => 0,
2372 1804 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2371,9 +1803,9 @@
2371 1803 'default' => 0,
2372 1804 'validate_callback' => __CLASS__ . '::validate_boolean',
2373 1805 'jp_group' => 'waf',
2374 1806 ),
2375 - 'jetpack_waf_share_debug_data' => array(
1807 + 'jetpack_waf_share_debug_data' => array(
2376 1808 'description' => esc_html__( 'Share detailed data with Jetpack.', 'jetpack' ),
2377 1809 'type' => 'boolean',
2378 1810 'default' => 0,
2379 1811 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2379,9 +1811,9 @@
2379 1811 'validate_callback' => __CLASS__ . '::validate_boolean',
2380 1812 'jp_group' => 'waf',
2381 1813 ),
2382 1814 // Galleries.
2383 - 'tiled_galleries' => array(
1815 + 'tiled_galleries' => array(
2384 1816 'description' => esc_html__( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ),
2385 1817 'type' => 'boolean',
2386 1818 'default' => 0,
2387 1819 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2387,9 +1819,9 @@
2387 1819 'validate_callback' => __CLASS__ . '::validate_boolean',
2388 1820 'jp_group' => 'tiled-gallery',
2389 1821 ),
2390 1822
2391 - 'gravatar_disable_hovercards' => array(
1823 + 'gravatar_disable_hovercards' => array(
2392 1824 'description' => esc_html__( "View people's profiles when you mouse over their Gravatars", 'jetpack' ),
2393 1825 'type' => 'string',
2394 1826 'default' => 'enabled',
2395 1827 // Not visible. This is used as the checkbox value.
@@ -2405,9 +1837,9 @@
2405 1837 'jp_group' => 'gravatar-hovercards',
2406 1838 ),
2407 1839
2408 1840 // Infinite Scroll.
2409 - 'infinite_scroll' => array(
1841 + 'infinite_scroll' => array(
2410 1842 'description' => esc_html__( 'To infinity and beyond', 'jetpack' ),
2411 1843 'type' => 'boolean',
2412 1844 'default' => 1,
2413 1845 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2412,9 +1844,9 @@
2412 1844 'default' => 1,
2413 1845 'validate_callback' => __CLASS__ . '::validate_boolean',
2414 1846 'jp_group' => 'infinite-scroll',
2415 1847 ),
2416 - 'infinite_scroll_google_analytics' => array(
1848 + 'infinite_scroll_google_analytics' => array(
2417 1849 'description' => esc_html__( 'Use Google Analytics with Infinite Scroll', 'jetpack' ),
2418 1850 'type' => 'boolean',
2419 1851 'default' => 0,
2420 1852 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2421,9 +1853,9 @@
2421 1853 'jp_group' => 'infinite-scroll',
2422 1854 ),
2423 1855
2424 1856 // Likes.
2425 - 'wpl_default' => array(
1857 + 'wpl_default' => array(
2426 1858 'description' => esc_html__( 'WordPress.com Likes are', 'jetpack' ),
2427 1859 'type' => 'string',
2428 1860 'default' => 'on',
2429 1861 'enum' => array(
@@ -2436,9 +1868,9 @@
2436 1868 ),
2437 1869 'validate_callback' => __CLASS__ . '::validate_list_item',
2438 1870 'jp_group' => 'likes',
2439 1871 ),
2440 - 'social_notifications_like' => array(
1872 + 'social_notifications_like' => array(
2441 1873 'description' => esc_html__( 'Send email notification when someone likes a post', 'jetpack' ),
2442 1874 'type' => 'boolean',
2443 1875 'default' => 1,
2444 1876 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2445,9 +1877,9 @@
2445 1877 'jp_group' => 'likes',
2446 1878 ),
2447 1879
2448 1880 // Markdown.
2449 - 'wpcom_publish_comments_with_markdown' => array(
1881 + 'wpcom_publish_comments_with_markdown' => array(
2450 1882 'description' => esc_html__( 'Use Markdown for comments.', 'jetpack' ),
2451 1883 'type' => 'boolean',
2452 1884 'default' => 0,
2453 1885 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2452,9 +1884,9 @@
2452 1884 'default' => 0,
2453 1885 'validate_callback' => __CLASS__ . '::validate_boolean',
2454 1886 'jp_group' => 'markdown',
2455 1887 ),
2456 - 'wpcom_publish_posts_with_markdown' => array(
1888 + 'wpcom_publish_posts_with_markdown' => array(
2457 1889 'description' => esc_html__( 'Use Markdown for posts.', 'jetpack' ),
2458 1890 'type' => 'boolean',
2459 1891 'default' => 0,
2460 1892 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2461,9 +1893,9 @@
2461 1893 'jp_group' => 'markdown',
2462 1894 ),
2463 1895
2464 1896 // Monitor.
2465 - 'monitor_receive_notifications' => array(
1897 + 'monitor_receive_notifications' => array(
2466 1898 'description' => esc_html__( 'Receive Monitor Email Notifications.', 'jetpack' ),
2467 1899 'type' => 'boolean',
2468 1900 'default' => 0,
2469 1901 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2470,9 +1902,9 @@
2470 1902 'jp_group' => 'monitor',
2471 1903 ),
2472 1904
2473 1905 // Post by Email.
2474 - 'post_by_email_address' => array(
1906 + 'post_by_email_address' => array(
2475 1907 'description' => esc_html__( 'Email Address', 'jetpack' ),
2476 1908 'type' => 'string',
2477 1909 'default' => 'noop',
2478 1910 'enum' => array(
@@ -2491,9 +1923,9 @@
2491 1923 'jp_group' => 'post-by-email',
2492 1924 ),
2493 1925
2494 1926 // Protect.
2495 - 'jetpack_protect_key' => array(
1927 + 'jetpack_protect_key' => array(
2496 1928 'description' => esc_html__( 'Protect API key', 'jetpack' ),
2497 1929 'type' => 'string',
2498 1930 'default' => '',
2499 1931 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2498,9 +1930,9 @@
2498 1930 'default' => '',
2499 1931 'validate_callback' => __CLASS__ . '::validate_alphanum',
2500 1932 'jp_group' => 'protect',
2501 1933 ),
2502 - 'jetpack_protect_global_whitelist' => array(
1934 + 'jetpack_protect_global_whitelist' => array(
2503 1935 'description' => esc_html__( 'Protect global IP allow list', 'jetpack' ),
2504 1936 'type' => 'string',
2505 1937 'default' => '',
2506 1938 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2508,9 +1940,9 @@
2508 1940 'jp_group' => 'protect',
2509 1941 ),
2510 1942
2511 1943 // Sharing.
2512 - 'sharing_services' => array(
1944 + 'sharing_services' => array(
2513 1945 'description' => esc_html__( 'Enabled Services and those hidden behind a button', 'jetpack' ),
2514 1946 'type' => 'object',
2515 1947 'default' => array(
2516 1948 'visible' => array( 'facebook', 'x' ),
@@ -2518,9 +1950,9 @@
2518 1950 ),
2519 1951 'validate_callback' => __CLASS__ . '::validate_services',
2520 1952 'jp_group' => 'sharedaddy',
2521 1953 ),
2522 - 'button_style' => array(
1954 + 'button_style' => array(
2523 1955 'description' => esc_html__( 'Button Style', 'jetpack' ),
2524 1956 'type' => 'string',
2525 1957 'default' => 'icon',
2526 1958 'enum' => array(
@@ -2537,9 +1969,9 @@
2537 1969 ),
2538 1970 'validate_callback' => __CLASS__ . '::validate_list_item',
2539 1971 'jp_group' => 'sharedaddy',
2540 1972 ),
2541 - 'sharing_label' => array(
1973 + 'sharing_label' => array(
2542 1974 'description' => esc_html__( 'Sharing Label', 'jetpack' ),
2543 1975 'type' => 'string',
2544 1976 'default' => '',
2545 1977 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2545,9 +1977,9 @@
2545 1977 'validate_callback' => __CLASS__ . '::validate_string',
2546 1978 'sanitize_callback' => 'esc_html',
2547 1979 'jp_group' => 'sharedaddy',
2548 1980 ),
2549 - 'show' => array(
1981 + 'show' => array(
2550 1982 'description' => esc_html__( 'Views where buttons are shown', 'jetpack' ),
2551 1983 'type' => 'array',
2552 1984 'items' => array(
2553 1985 'type' => 'string',
@@ -2555,9 +1987,9 @@
2555 1987 'default' => array( 'post' ),
2556 1988 'validate_callback' => __CLASS__ . '::validate_sharing_show',
2557 1989 'jp_group' => 'sharedaddy',
2558 1990 ),
2559 - 'jetpack-twitter-cards-site-tag' => array(
1991 + 'jetpack-twitter-cards-site-tag' => array(
2560 1992 'description' => esc_html__( "The Twitter username of the owner of this site's domain.", 'jetpack' ),
2561 1993 'type' => 'string',
2562 1994 'default' => '',
2563 1995 'validate_callback' => __CLASS__ . '::validate_twitter_username',
@@ -2563,9 +1995,9 @@
2563 1995 'validate_callback' => __CLASS__ . '::validate_twitter_username',
2564 1996 'sanitize_callback' => 'esc_html',
2565 1997 'jp_group' => 'sharedaddy',
2566 1998 ),
2567 - 'sharedaddy_disable_resources' => array(
1999 + 'sharedaddy_disable_resources' => array(
2568 2000 'description' => esc_html__( 'Disable CSS and JS', 'jetpack' ),
2569 2001 'type' => 'boolean',
2570 2002 'default' => 0,
2571 2003 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2570,9 +2002,9 @@
2570 2002 'default' => 0,
2571 2003 'validate_callback' => __CLASS__ . '::validate_boolean',
2572 2004 'jp_group' => 'sharedaddy',
2573 2005 ),
2574 - 'custom' => array(
2006 + 'custom' => array(
2575 2007 'description' => esc_html__( 'Custom sharing services added by user.', 'jetpack' ),
2576 2008 'type' => 'object',
2577 2009 'default' => array(
2578 2010 'sharing_name' => '',
@@ -2582,9 +2014,9 @@
2582 2014 'validate_callback' => __CLASS__ . '::validate_custom_service',
2583 2015 'jp_group' => 'sharedaddy',
2584 2016 ),
2585 2017 // Not an option, but an action that can be performed on the list of custom services passing the service ID.
2586 - 'sharing_delete_service' => array(
2018 + 'sharing_delete_service' => array(
2587 2019 'description' => esc_html__( 'Delete custom sharing service.', 'jetpack' ),
2588 2020 'type' => 'string',
2589 2021 'default' => '',
2590 2022 'validate_callback' => __CLASS__ . '::validate_custom_service_id',
@@ -2591,9 +2023,9 @@
2591 2023 'jp_group' => 'sharedaddy',
2592 2024 ),
2593 2025
2594 2026 // SSO.
2595 - 'jetpack_sso_require_two_step' => array(
2027 + 'jetpack_sso_require_two_step' => array(
2596 2028 'description' => esc_html__( 'Require Two-Step Authentication', 'jetpack' ),
2597 2029 'type' => 'boolean',
2598 2030 'default' => SSO\Helpers::is_require_two_step_checkbox_disabled(),
2599 2031 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2598,9 +2030,9 @@
2598 2030 'default' => SSO\Helpers::is_require_two_step_checkbox_disabled(),
2599 2031 'validate_callback' => __CLASS__ . '::validate_boolean',
2600 2032 'jp_group' => 'sso',
2601 2033 ),
2602 - 'jetpack_sso_match_by_email' => array(
2034 + 'jetpack_sso_match_by_email' => array(
2603 2035 'description' => esc_html__( 'Match by Email', 'jetpack' ),
2604 2036 'type' => 'boolean',
2605 2037 'default' => 1,
2606 2038 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2607,9 +2039,9 @@
2607 2039 'jp_group' => 'sso',
2608 2040 ),
2609 2041
2610 2042 // Subscriptions.
2611 - 'stb_enabled' => array(
2043 + 'stb_enabled' => array(
2612 2044 'description' => esc_html__( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ),
2613 2045 'type' => 'boolean',
2614 2046 'default' => 1,
2615 2047 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2614,9 +2046,9 @@
2614 2046 'default' => 1,
2615 2047 'validate_callback' => __CLASS__ . '::validate_boolean',
2616 2048 'jp_group' => 'subscriptions',
2617 2049 ),
2618 - 'stc_enabled' => array(
2050 + 'stc_enabled' => array(
2619 2051 'description' => esc_html__( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ),
2620 2052 'type' => 'boolean',
2621 2053 'default' => 1,
2622 2054 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2621,9 +2053,9 @@
2621 2053 'default' => 1,
2622 2054 'validate_callback' => __CLASS__ . '::validate_boolean',
2623 2055 'jp_group' => 'subscriptions',
2624 2056 ),
2625 - 'wpcom_newsletter_categories' => array(
2057 + 'wpcom_newsletter_categories' => array(
2626 2058 'description' => esc_html__( 'Array of post category ids that are marked as newsletter categories', 'jetpack' ),
2627 2059 'type' => 'array',
2628 2060 'default' => array(),
2629 2061 'validate_callback' => __CLASS__ . '::validate_array',
@@ -2628,9 +2060,9 @@
2628 2060 'default' => array(),
2629 2061 'validate_callback' => __CLASS__ . '::validate_array',
2630 2062 'jp_group' => 'subscriptions',
2631 2063 ),
2632 - 'wpcom_newsletter_categories_enabled' => array(
2064 + 'wpcom_newsletter_categories_enabled' => array(
2633 2065 'description' => esc_html__( 'Whether the newsletter categories are enabled or not', 'jetpack' ),
2634 2066 'type' => 'boolean',
2635 2067 'default' => 0,
2636 2068 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2635,16 +2067,23 @@
2635 2067 'default' => 0,
2636 2068 'validate_callback' => __CLASS__ . '::validate_boolean',
2637 2069 'jp_group' => 'subscriptions',
2638 2070 ),
2639 - 'wpcom_featured_image_in_email' => array(
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(
2640 2079 'description' => esc_html__( 'Whether to include the featured image in the email or not', 'jetpack' ),
2641 2080 'type' => 'boolean',
2642 - 'default' => 1,
2081 + 'default' => 0,
2643 2082 'validate_callback' => __CLASS__ . '::validate_boolean',
2644 2083 'jp_group' => 'subscriptions',
2645 2084 ),
2646 - 'jetpack_gravatar_in_email' => array(
2085 + 'jetpack_gravatar_in_email' => array(
2647 2086 'description' => esc_html__( 'Whether to show author avatar in the email byline', 'jetpack' ),
2648 2087 'type' => 'boolean',
2649 2088 'default' => 1,
2650 2089 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2649,9 +2088,9 @@
2649 2088 'default' => 1,
2650 2089 'validate_callback' => __CLASS__ . '::validate_boolean',
2651 2090 'jp_group' => 'subscriptions',
2652 2091 ),
2653 - 'jetpack_author_in_email' => array(
2092 + 'jetpack_author_in_email' => array(
2654 2093 'description' => esc_html__( 'Whether to show author display name in the email byline', 'jetpack' ),
2655 2094 'type' => 'boolean',
2656 2095 'default' => 1,
2657 2096 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2656,9 +2095,9 @@
2656 2095 'default' => 1,
2657 2096 'validate_callback' => __CLASS__ . '::validate_boolean',
2658 2097 'jp_group' => 'subscriptions',
2659 2098 ),
2660 - 'jetpack_post_date_in_email' => array(
2099 + 'jetpack_post_date_in_email' => array(
2661 2100 'description' => esc_html__( 'Whether to show date in the email byline', 'jetpack' ),
2662 2101 'type' => 'boolean',
2663 2102 'default' => 1,
2664 2103 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2663,9 +2102,9 @@
2663 2102 'default' => 1,
2664 2103 'validate_callback' => __CLASS__ . '::validate_boolean',
2665 2104 'jp_group' => 'subscriptions',
2666 2105 ),
2667 - 'wpcom_subscription_emails_use_excerpt' => array(
2106 + 'wpcom_subscription_emails_use_excerpt' => array(
2668 2107 'description' => esc_html__( 'Whether to use the excerpt in the email or not', 'jetpack' ),
2669 2108 'type' => 'boolean',
2670 2109 'default' => 0,
2671 2110 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2670,16 +2109,16 @@
2670 2109 'default' => 0,
2671 2110 'validate_callback' => __CLASS__ . '::validate_boolean',
2672 2111 'jp_group' => 'subscriptions',
2673 2112 ),
2674 - 'jetpack_subscriptions_reply_to' => array(
2113 + 'jetpack_subscriptions_reply_to' => array(
2675 2114 'description' => esc_html__( 'Reply to email behaviour for newsletters emails', 'jetpack' ),
2676 2115 'type' => 'string',
2677 - 'default' => 'no-reply',
2116 + 'default' => Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to,
2678 2117 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to',
2679 2118 'jp_group' => 'subscriptions',
2680 2119 ),
2681 - 'jetpack_subscriptions_from_name' => array(
2120 + 'jetpack_subscriptions_from_name' => array(
2682 2121 'description' => esc_html__( 'From name for newsletters emails', 'jetpack' ),
2683 2122 'type' => 'string',
2684 2123 'default' => '',
2685 2124 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to_name',
@@ -2684,9 +2123,9 @@
2684 2123 'default' => '',
2685 2124 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to_name',
2686 2125 'jp_group' => 'subscriptions',
2687 2126 ),
2688 - 'sm_enabled' => array(
2127 + 'sm_enabled' => array(
2689 2128 'description' => esc_html__( 'Show popup Subscribe modal to readers.', 'jetpack' ),
2690 2129 'type' => 'boolean',
2691 2130 'default' => 0,
2692 2131 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2691,9 +2130,9 @@
2691 2130 'default' => 0,
2692 2131 'validate_callback' => __CLASS__ . '::validate_boolean',
2693 2132 'jp_group' => 'subscriptions',
2694 2133 ),
2695 - 'jetpack_subscribe_overlay_enabled' => array(
2134 + 'jetpack_subscribe_overlay_enabled' => array(
2696 2135 'description' => esc_html__( 'Show subscribe overlay on homepage.', 'jetpack' ),
2697 2136 'type' => 'boolean',
2698 2137 'default' => 0,
2699 2138 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2698,8 +2137,15 @@
2698 2137 'default' => 0,
2699 2138 'validate_callback' => __CLASS__ . '::validate_boolean',
2700 2139 'jp_group' => 'subscriptions',
2701 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 + ),
2702 2148 'jetpack_subscriptions_subscribe_post_end_enabled' => array(
2703 2149 'description' => esc_html__( 'Add Subscribe block at the end of each post.', 'jetpack' ),
2704 2150 'type' => 'boolean',
2705 2151 'default' => 0,
@@ -2719,9 +2165,9 @@
2719 2165 'default' => 0,
2720 2166 'validate_callback' => __CLASS__ . '::validate_boolean',
2721 2167 'jp_group' => 'subscriptions',
2722 2168 ),
2723 - 'social_notifications_subscribe' => array(
2169 + 'social_notifications_subscribe' => array(
2724 2170 'description' => esc_html__( 'Send email notification when someone subscribes to my blog', 'jetpack' ),
2725 2171 'type' => 'boolean',
2726 2172 'default' => 0,
2727 2173 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2726,15 +2172,18 @@
2726 2172 'default' => 0,
2727 2173 'validate_callback' => __CLASS__ . '::validate_boolean',
2728 2174 'jp_group' => 'subscriptions',
2729 2175 ),
2730 - 'subscription_options' => array(
2731 - 'description' => esc_html__( 'Three options used in subscription email templates: \'invitation\', \'welcome\' and \'comment_follow\'.', 'jetpack' ),
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' ),
2732 2178 'type' => 'object',
2733 2179 'default' => array(
2734 - 'invitation' => '',
2735 - 'welcome' => '',
2736 - 'comment_follow' => '',
2180 + 'invitation' => '',
2181 + 'welcome' => '',
2182 + 'comment_follow' => '',
2183 + 'subscribe_modal_heading' => '',
2184 + 'free_tier_description' => '',
2185 + 'hide_free_tier' => false,
2737 2186 ),
2738 2187 'validate_callback' => __CLASS__ . '::validate_subscription_options',
2739 2188 'jp_group' => 'subscriptions',
2740 2189 ),
@@ -2739,9 +2188,9 @@
2739 2188 'jp_group' => 'subscriptions',
2740 2189 ),
2741 2190
2742 2191 // Related Posts.
2743 - 'show_headline' => array(
2192 + 'show_headline' => array(
2744 2193 'description' => esc_html__( 'Highlight related content with a heading', 'jetpack' ),
2745 2194 'type' => 'boolean',
2746 2195 'default' => 1,
2747 2196 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2746,9 +2195,9 @@
2746 2195 'default' => 1,
2747 2196 'validate_callback' => __CLASS__ . '::validate_boolean',
2748 2197 'jp_group' => 'related-posts',
2749 2198 ),
2750 - 'show_thumbnails' => array(
2199 + 'show_thumbnails' => array(
2751 2200 'description' => esc_html__( 'Show a thumbnail image where available', 'jetpack' ),
2752 2201 'type' => 'boolean',
2753 2202 'default' => 0,
2754 2203 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2755,9 +2204,9 @@
2755 2204 'jp_group' => 'related-posts',
2756 2205 ),
2757 2206
2758 2207 // Search.
2759 - 'instant_search_enabled' => array(
2208 + 'instant_search_enabled' => array(
2760 2209 'description' => esc_html__( 'Enable Instant Search', 'jetpack' ),
2761 2210 'type' => 'boolean',
2762 2211 'default' => 0,
2763 2212 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2763,9 +2212,9 @@
2763 2212 'validate_callback' => __CLASS__ . '::validate_boolean',
2764 2213 'jp_group' => 'search',
2765 2214 ),
2766 2215
2767 - 'has_jetpack_search_product' => array(
2216 + 'has_jetpack_search_product' => array(
2768 2217 'description' => esc_html__( 'Has an active Jetpack Search product purchase', 'jetpack' ),
2769 2218 'type' => 'boolean',
2770 2219 'default' => 0,
2771 2220 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2771,9 +2220,9 @@
2771 2220 'validate_callback' => __CLASS__ . '::validate_boolean',
2772 2221 'jp_group' => 'settings',
2773 2222 ),
2774 2223
2775 - 'search_auto_config' => array(
2224 + 'search_auto_config' => array(
2776 2225 'description' => esc_html__( 'Trigger an auto config of instant search', 'jetpack' ),
2777 2226 'type' => 'boolean',
2778 2227 'default' => 0,
2779 2228 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2780,9 +2229,9 @@
2780 2229 'jp_group' => 'search',
2781 2230 ),
2782 2231
2783 2232 // Verification Tools.
2784 - 'google' => array(
2233 + 'google' => array(
2785 2234 'description' => esc_html__( 'Google Search Console', 'jetpack' ),
2786 2235 'type' => 'string',
2787 2236 'default' => '',
2788 2237 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2787,9 +2236,9 @@
2787 2236 'default' => '',
2788 2237 'validate_callback' => __CLASS__ . '::validate_verification_service',
2789 2238 'jp_group' => 'verification-tools',
2790 2239 ),
2791 - 'bing' => array(
2240 + 'bing' => array(
2792 2241 'description' => esc_html__( 'Bing Webmaster Center', 'jetpack' ),
2793 2242 'type' => 'string',
2794 2243 'default' => '',
2795 2244 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2794,9 +2243,9 @@
2794 2243 'default' => '',
2795 2244 'validate_callback' => __CLASS__ . '::validate_verification_service',
2796 2245 'jp_group' => 'verification-tools',
2797 2246 ),
2798 - 'pinterest' => array(
2247 + 'pinterest' => array(
2799 2248 'description' => esc_html__( 'Pinterest Site Verification', 'jetpack' ),
2800 2249 'type' => 'string',
2801 2250 'default' => '',
2802 2251 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2801,9 +2250,9 @@
2801 2250 'default' => '',
2802 2251 'validate_callback' => __CLASS__ . '::validate_verification_service',
2803 2252 'jp_group' => 'verification-tools',
2804 2253 ),
2805 - 'yandex' => array(
2254 + 'yandex' => array(
2806 2255 'description' => esc_html__( 'Yandex Site Verification', 'jetpack' ),
2807 2256 'type' => 'string',
2808 2257 'default' => '',
2809 2258 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2808,9 +2257,9 @@
2808 2257 'default' => '',
2809 2258 'validate_callback' => __CLASS__ . '::validate_verification_service',
2810 2259 'jp_group' => 'verification-tools',
2811 2260 ),
2812 - 'facebook' => array(
2261 + 'facebook' => array(
2813 2262 'description' => esc_html__( 'Facebook Domain Verification', 'jetpack' ),
2814 2263 'type' => 'string',
2815 2264 'default' => '',
2816 2265 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2817,9 +2266,9 @@
2817 2266 'jp_group' => 'verification-tools',
2818 2267 ),
2819 2268
2820 2269 // WordAds.
2821 - 'enable_header_ad' => array(
2270 + 'enable_header_ad' => array(
2822 2271 'description' => esc_html__( 'Display an ad unit at the top of each page.', 'jetpack' ),
2823 2272 'type' => 'boolean',
2824 2273 'default' => 1,
2825 2274 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2824,9 +2273,9 @@
2824 2273 'default' => 1,
2825 2274 'validate_callback' => __CLASS__ . '::validate_boolean',
2826 2275 'jp_group' => 'wordads',
2827 2276 ),
2828 - 'wordads_approved' => array(
2277 + 'wordads_approved' => array(
2829 2278 'description' => esc_html__( 'Is site approved for WordAds?', 'jetpack' ),
2830 2279 'type' => 'boolean',
2831 2280 'default' => 0,
2832 2281 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2831,9 +2280,9 @@
2831 2280 'default' => 0,
2832 2281 'validate_callback' => __CLASS__ . '::validate_boolean',
2833 2282 'jp_group' => 'wordads',
2834 2283 ),
2835 - 'wordads_second_belowpost' => array(
2284 + 'wordads_second_belowpost' => array(
2836 2285 'description' => esc_html__( 'Display second ad below post?', 'jetpack' ),
2837 2286 'type' => 'boolean',
2838 2287 'default' => 1,
2839 2288 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2838,9 +2287,9 @@
2838 2287 'default' => 1,
2839 2288 'validate_callback' => __CLASS__ . '::validate_boolean',
2840 2289 'jp_group' => 'wordads',
2841 2290 ),
2842 - 'wordads_inline_enabled' => array(
2291 + 'wordads_inline_enabled' => array(
2843 2292 'description' => esc_html__( 'Display inline ad within post content?', 'jetpack' ),
2844 2293 'type' => 'boolean',
2845 2294 'default' => 1,
2846 2295 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2845,9 +2294,9 @@
2845 2294 'default' => 1,
2846 2295 'validate_callback' => __CLASS__ . '::validate_boolean',
2847 2296 'jp_group' => 'wordads',
2848 2297 ),
2849 - 'wordads_display_front_page' => array(
2298 + 'wordads_display_front_page' => array(
2850 2299 'description' => esc_html__( 'Display ads on the front page?', 'jetpack' ),
2851 2300 'type' => 'boolean',
2852 2301 'default' => 1,
2853 2302 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2852,9 +2301,9 @@
2852 2301 'default' => 1,
2853 2302 'validate_callback' => __CLASS__ . '::validate_boolean',
2854 2303 'jp_group' => 'wordads',
2855 2304 ),
2856 - 'wordads_display_post' => array(
2305 + 'wordads_display_post' => array(
2857 2306 'description' => esc_html__( 'Display ads on posts?', 'jetpack' ),
2858 2307 'type' => 'boolean',
2859 2308 'default' => 1,
2860 2309 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2859,9 +2308,9 @@
2859 2308 'default' => 1,
2860 2309 'validate_callback' => __CLASS__ . '::validate_boolean',
2861 2310 'jp_group' => 'wordads',
2862 2311 ),
2863 - 'wordads_display_page' => array(
2312 + 'wordads_display_page' => array(
2864 2313 'description' => esc_html__( 'Display ads on pages?', 'jetpack' ),
2865 2314 'type' => 'boolean',
2866 2315 'default' => 1,
2867 2316 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2866,9 +2315,9 @@
2866 2315 'default' => 1,
2867 2316 'validate_callback' => __CLASS__ . '::validate_boolean',
2868 2317 'jp_group' => 'wordads',
2869 2318 ),
2870 - 'wordads_display_archive' => array(
2319 + 'wordads_display_archive' => array(
2871 2320 'description' => esc_html__( 'Display ads on archive pages?', 'jetpack' ),
2872 2321 'type' => 'boolean',
2873 2322 'default' => 1,
2874 2323 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2873,9 +2322,9 @@
2873 2322 'default' => 1,
2874 2323 'validate_callback' => __CLASS__ . '::validate_boolean',
2875 2324 'jp_group' => 'wordads',
2876 2325 ),
2877 - 'wordads_custom_adstxt_enabled' => array(
2326 + 'wordads_custom_adstxt_enabled' => array(
2878 2327 'description' => esc_html__( 'Custom ads.txt', 'jetpack' ),
2879 2328 'type' => 'boolean',
2880 2329 'default' => 0,
2881 2330 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2880,9 +2329,9 @@
2880 2329 'default' => 0,
2881 2330 'validate_callback' => __CLASS__ . '::validate_boolean',
2882 2331 'jp_group' => 'wordads',
2883 2332 ),
2884 - 'wordads_custom_adstxt' => array(
2333 + 'wordads_custom_adstxt' => array(
2885 2334 'description' => esc_html__( 'Custom ads.txt entries', 'jetpack' ),
2886 2335 'type' => 'string',
2887 2336 'default' => '',
2888 2337 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2888,9 +2337,9 @@
2888 2337 'validate_callback' => __CLASS__ . '::validate_string',
2889 2338 'sanitize_callback' => 'sanitize_textarea_field',
2890 2339 'jp_group' => 'wordads',
2891 2340 ),
2892 - 'wordads_ccpa_enabled' => array(
2341 + 'wordads_ccpa_enabled' => array(
2893 2342 'description' => esc_html__( 'Enable support for California Consumer Privacy Act', 'jetpack' ),
2894 2343 'type' => 'boolean',
2895 2344 'default' => 0,
2896 2345 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2895,9 +2344,9 @@
2895 2344 'default' => 0,
2896 2345 'validate_callback' => __CLASS__ . '::validate_boolean',
2897 2346 'jp_group' => 'wordads',
2898 2347 ),
2899 - 'wordads_ccpa_privacy_policy_url' => array(
2348 + 'wordads_ccpa_privacy_policy_url' => array(
2900 2349 'description' => esc_html__( 'Privacy Policy URL', 'jetpack' ),
2901 2350 'type' => 'string',
2902 2351 'default' => '',
2903 2352 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2903,9 +2352,9 @@
2903 2352 'validate_callback' => __CLASS__ . '::validate_string',
2904 2353 'sanitize_callback' => 'sanitize_text_field',
2905 2354 'jp_group' => 'wordads',
2906 2355 ),
2907 - 'wordads_cmp_enabled' => array(
2356 + 'wordads_cmp_enabled' => array(
2908 2357 'description' => esc_html__( 'Enable GDPR Consent Management Banner for WordAds', 'jetpack' ),
2909 2358 'type' => 'boolean',
2910 2359 'default' => 0,
2911 2360 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2912,9 +2361,9 @@
2912 2361 'jp_group' => 'wordads',
2913 2362 ),
2914 2363
2915 2364 // Google Analytics.
2916 - 'google_analytics_tracking_id' => array(
2365 + 'google_analytics_tracking_id' => array(
2917 2366 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2918 2367 'type' => 'string',
2919 2368 'default' => '',
2920 2369 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2919,11 +2368,16 @@
2919 2368 'default' => '',
2920 2369 'validate_callback' => __CLASS__ . '::validate_alphanum',
2921 2370 'jp_group' => 'google-analytics',
2922 2371 ),
2372 + 'jetpack_wga' => array(
2373 + 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2374 + 'type' => 'object',
2375 + 'jp_group' => 'settings',
2376 + ),
2923 2377
2924 2378 // Stats.
2925 - 'admin_bar' => array(
2379 + 'admin_bar' => array(
2926 2380 'description' => esc_html__( 'Include a small chart in your admin bar with a 48-hour traffic snapshot.', 'jetpack' ),
2927 2381 'type' => 'boolean',
2928 2382 'default' => 1,
2929 2383 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2928,9 +2382,9 @@
2928 2382 'default' => 1,
2929 2383 'validate_callback' => __CLASS__ . '::validate_boolean',
2930 2384 'jp_group' => 'stats',
2931 2385 ),
2932 - 'enable_odyssey_stats' => array(
2386 + 'enable_odyssey_stats' => array(
2933 2387 'description' => esc_html__( 'Preview the new Jetpack Stats experience (Experimental).', 'jetpack' ),
2934 2388 'type' => 'boolean',
2935 2389 'default' => 1,
2936 2390 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2935,9 +2389,9 @@
2935 2389 'default' => 1,
2936 2390 'validate_callback' => __CLASS__ . '::validate_boolean',
2937 2391 'jp_group' => 'stats',
2938 2392 ),
2939 - 'roles' => array(
2393 + 'roles' => array(
2940 2394 'description' => esc_html__( 'Select the roles that will be able to view stats reports.', 'jetpack' ),
2941 2395 'type' => 'array',
2942 2396 'items' => array(
2943 2397 'type' => 'string',
@@ -2946,9 +2400,9 @@
2946 2400 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2947 2401 'sanitize_callback' => __CLASS__ . '::sanitize_stats_allowed_roles',
2948 2402 'jp_group' => 'stats',
2949 2403 ),
2950 - 'count_roles' => array(
2404 + 'count_roles' => array(
2951 2405 'description' => esc_html__( 'Count the page views of registered users who are logged in.', 'jetpack' ),
2952 2406 'type' => 'array',
2953 2407 'items' => array(
2954 2408 'type' => 'string',
@@ -2956,9 +2410,9 @@
2956 2410 'default' => array( 'administrator' ),
2957 2411 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2958 2412 'jp_group' => 'stats',
2959 2413 ),
2960 - 'blog_id' => array(
2414 + 'blog_id' => array(
2961 2415 'description' => esc_html__( 'Blog ID.', 'jetpack' ),
2962 2416 'type' => 'boolean',
2963 2417 'default' => 0,
2964 2418 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2963,9 +2417,9 @@
2963 2417 'default' => 0,
2964 2418 'validate_callback' => __CLASS__ . '::validate_boolean',
2965 2419 'jp_group' => 'stats',
2966 2420 ),
2967 - 'do_not_track' => array(
2421 + 'do_not_track' => array(
2968 2422 'description' => esc_html__( 'Do not track.', 'jetpack' ),
2969 2423 'type' => 'boolean',
2970 2424 'default' => 1,
2971 2425 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2970,9 +2424,9 @@
2970 2424 'default' => 1,
2971 2425 'validate_callback' => __CLASS__ . '::validate_boolean',
2972 2426 'jp_group' => 'stats',
2973 2427 ),
2974 - 'version' => array(
2428 + 'version' => array(
2975 2429 'description' => esc_html__( 'Version.', 'jetpack' ),
2976 2430 'type' => 'integer',
2977 2431 'default' => 9,
2978 2432 'validate_callback' => __CLASS__ . '::validate_posint',
@@ -2977,9 +2431,9 @@
2977 2431 'default' => 9,
2978 2432 'validate_callback' => __CLASS__ . '::validate_posint',
2979 2433 'jp_group' => 'stats',
2980 2434 ),
2981 - 'collapse_nudges' => array(
2435 + 'collapse_nudges' => array(
2982 2436 'description' => esc_html__( 'Collapse upgrade nudges', 'jetpack' ),
2983 2437 'type' => 'boolean',
2984 2438 'default' => 0,
2985 2439 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2986,9 +2440,9 @@
2986 2440 'jp_group' => 'stats',
2987 2441 ),
2988 2442
2989 2443 // Whether to share stats views with WordPress.com Reader.
2990 - 'wpcom_reader_views_enabled' => array(
2444 + 'wpcom_reader_views_enabled' => array(
2991 2445 'description' => esc_html__( 'Show post views in the WordPress.com Reader.', 'jetpack' ),
2992 2446 'type' => 'boolean',
2993 2447 'default' => 1,
2994 2448 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2995,9 +2449,9 @@
2995 2449 'jp_group' => 'settings',
2996 2450 ),
2997 2451
2998 2452 // Akismet - Not a module, but a plugin. The options can be passed and handled differently.
2999 - 'akismet_show_user_comments_approved' => array(
2453 + 'akismet_show_user_comments_approved' => array(
3000 2454 'description' => '',
3001 2455 'type' => 'boolean',
3002 2456 'default' => 0,
3003 2457 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3003,9 +2457,9 @@
3003 2457 'validate_callback' => __CLASS__ . '::validate_boolean',
3004 2458 'jp_group' => 'settings',
3005 2459 ),
3006 2460
3007 - 'wordpress_api_key' => array(
2461 + 'wordpress_api_key' => array(
3008 2462 'description' => '',
3009 2463 'type' => 'string',
3010 2464 'default' => '',
3011 2465 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -3012,9 +2466,9 @@
3012 2466 'jp_group' => 'settings',
3013 2467 ),
3014 2468
3015 2469 // Empty stats card dismiss.
3016 - 'dismiss_empty_stats_card' => array(
2470 + 'dismiss_empty_stats_card' => array(
3017 2471 'description' => '',
3018 2472 'type' => 'boolean',
3019 2473 'default' => 0,
3020 2474 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3021,9 +2475,9 @@
3021 2475 'jp_group' => 'settings',
3022 2476 ),
3023 2477
3024 2478 // Backup Getting Started card on dashboard.
3025 - 'dismiss_dash_backup_getting_started' => array(
2479 + 'dismiss_dash_backup_getting_started' => array(
3026 2480 'description' => '',
3027 2481 'type' => 'boolean',
3028 2482 'default' => 0,
3029 2483 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3030,9 +2484,9 @@
3030 2484 'jp_group' => 'settings',
3031 2485 ),
3032 2486
3033 2487 // Agencies Learn More card on dashboard.
3034 - 'dismiss_dash_agencies_learn_more' => array(
2488 + 'dismiss_dash_agencies_learn_more' => array(
3035 2489 'description' => '',
3036 2490 'type' => 'boolean',
3037 2491 'default' => 0,
3038 2492 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3038,9 +2492,9 @@
3038 2492 'validate_callback' => __CLASS__ . '::validate_boolean',
3039 2493 'jp_group' => 'settings',
3040 2494 ),
3041 2495
3042 - 'lang_id' => array(
2496 + 'lang_id' => array(
3043 2497 'description' => esc_html__( 'Primary language for the site.', 'jetpack' ),
3044 2498 'type' => 'string',
3045 2499 'default' => 'en_US',
3046 2500 'jp_group' => 'settings',
@@ -3045,32 +2499,10 @@
3045 2499 'default' => 'en_US',
3046 2500 'jp_group' => 'settings',
3047 2501 ),
3048 2502
3049 - 'onboarding' => array(
3050 - 'description' => '',
3051 - 'type' => 'object',
3052 - 'default' => array(
3053 - 'siteTitle' => '',
3054 - 'siteDescription' => '',
3055 - 'siteType' => 'personal',
3056 - 'homepageFormat' => 'posts',
3057 - 'addContactForm' => 0,
3058 - 'businessAddress' => array(
3059 - 'name' => '',
3060 - 'street' => '',
3061 - 'city' => '',
3062 - 'state' => '',
3063 - 'zip' => '',
3064 - ),
3065 - 'installWooCommerce' => false,
3066 - ),
3067 - 'validate_callback' => __CLASS__ . '::validate_onboarding',
3068 - 'jp_group' => 'settings',
3069 - ),
3070 -
3071 2503 // SEO Tools.
3072 - 'advanced_seo_front_page_description' => array(
2504 + 'advanced_seo_front_page_description' => array(
3073 2505 'description' => esc_html__( 'Front page meta description.', 'jetpack' ),
3074 2506 'type' => 'string',
3075 2507 'default' => '',
3076 2508 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
@@ -3076,9 +2508,9 @@
3076 2508 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
3077 2509 'jp_group' => 'seo-tools',
3078 2510 ),
3079 2511
3080 - 'advanced_seo_title_formats' => array(
2512 + 'advanced_seo_title_formats' => array(
3081 2513 'description' => esc_html__( 'SEO page title structures.', 'jetpack' ),
3082 2514 'type' => 'object',
3083 2515 'default' => array(
3084 2516 'archives' => array(),
@@ -3091,10 +2523,34 @@
3091 2523 'validate_callback' => 'Jetpack_SEO_Titles::are_valid_title_formats',
3092 2524 'sanitize_callback' => 'Jetpack_SEO_Titles::sanitize_title_formats',
3093 2525 ),
3094 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 +
3095 2551 // VideoPress.
3096 - 'videopress_private_enabled_for_site' => array(
2552 + 'videopress_private_enabled_for_site' => array(
3097 2553 'description' => esc_html__( 'Video Privacy: Restrict views to members of this site', 'jetpack' ),
3098 2554 'type' => 'boolean',
3099 2555 'default' => 0,
3100 2556 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3101,8 +2557,21 @@
3101 2557 'jp_group' => 'videopress',
3102 2558 ),
3103 2559 );
3104 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 +
3105 2574 // Add modules to list so they can be toggled.
3106 2575 $modules = Jetpack::get_available_modules();
3107 2576 if ( is_array( $modules ) && ! empty( $modules ) ) {
3108 2577 $module_args = array(
@@ -3148,8 +2617,10 @@
3148 2617 * Validates that the parameters are proper values that can be set during Jetpack onboarding.
3149 2618 *
3150 2619 * @since 5.4.0
3151 2620 *
2621 + * @deprecated since 13.9
2622 + *
3152 2623 * @param array $onboarding_data Values to check.
3153 2624 * @param WP_REST_Request $request The request sent to the WP REST API.
3154 2625 * @param string $param Name of the parameter passed to endpoint holding $value.
3155 2626 *
@@ -3154,24 +2625,10 @@
3154 2625 * @param string $param Name of the parameter passed to endpoint holding $value.
3155 2626 *
3156 2627 * @return bool|WP_Error
3157 2628 */
3158 - public static function validate_onboarding( $onboarding_data, $request, $param ) {
3159 - if ( ! is_array( $onboarding_data ) ) {
3160 - return new WP_Error( 'invalid_param', esc_html__( 'Not valid onboarding data.', 'jetpack' ) );
3161 - }
3162 - foreach ( $onboarding_data as $value ) {
3163 - if ( is_string( $value ) ) {
3164 - $onboarding_choice = self::validate_string( $value, $request, $param );
3165 - } elseif ( is_array( $value ) ) {
3166 - $onboarding_choice = self::validate_onboarding( $value, $request, $param );
3167 - } else {
3168 - $onboarding_choice = self::validate_boolean( $value, $request, $param );
3169 - }
3170 - if ( is_wp_error( $onboarding_choice ) ) {
3171 - return $onboarding_choice;
3172 - }
3173 - }
2629 + public static function validate_onboarding( $onboarding_data, $request, $param ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
2630 + _deprecated_function( __METHOD__, '13.9' );
3174 2631 return true;
3175 2632 }
3176 2633
3177 2634 /**
@@ -3367,14 +2824,14 @@
3367 2824 *
3368 2825 * @return bool|WP_Error
3369 2826 */
3370 2827 public static function validate_verification_service( $value, $request, $param ) {
3371 - 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 ) ) ) {
3372 2829 return new WP_Error(
3373 2830 'invalid_param',
3374 2831 sprintf(
3375 2832 /* Translators: Placeholder is a verification string used to verify a service like Google Webmaster Console. */
3376 - 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' ),
3377 2834 $param
3378 2835 )
3379 2836 );
3380 2837 }
@@ -3385,9 +2842,9 @@
3385 2842 * Validates that the parameter is among the roles allowed for Stats.
3386 2843 *
3387 2844 * @since 4.3.0
3388 2845 *
3389 - * @param string|bool $value Value to check.
2846 + * @param mixed $value Value to check.
3390 2847 * @param WP_REST_Request $request The request sent to the WP REST API.
3391 2848 * @param string $param Name of the parameter passed to endpoint holding $value.
3392 2849 *
3393 2850 * @return bool|WP_Error
@@ -3392,16 +2849,37 @@
3392 2849 *
3393 2850 * @return bool|WP_Error
3394 2851 */
3395 2852 public static function validate_stats_roles( $value, $request, $param ) {
3396 - 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 ) ) {
3397 2860 return new WP_Error(
3398 2861 'invalid_param',
3399 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(
3400 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. */
3401 2879 esc_html__( '%1$s must be %2$s.', 'jetpack' ),
3402 2880 $param,
3403 - implode( ', ', self::$stats_roles )
2881 + implode( ', ', $editable_roles )
3404 2882 )
3405 2883 );
3406 2884 }
3407 2885 return true;
@@ -3718,9 +3196,12 @@
3718 3196 *
3719 3197 * @return bool|WP_Error
3720 3198 */
3721 3199 public static function validate_subscription_options( $values ) {
3722 - if ( is_object( $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 ) ) {
3723 3204 return new WP_Error(
3724 3205 'invalid_param',
3725 3206 /* Translators: subscription_options is a variable name, and shouldn't be translated. */
3726 3207 esc_html__( 'subscription_options must be an object.', 'jetpack' )
@@ -3726,9 +3207,9 @@
3726 3207 esc_html__( 'subscription_options must be an object.', 'jetpack' )
3727 3208 );
3728 3209 }
3729 3210 foreach ( array_keys( $values ) as $key ) {
3730 - if ( ! in_array( $key, array( 'welcome', 'invitation', 'comment_follow' ), true ) ) {
3211 + if ( ! in_array( $key, array( 'welcome', 'invitation', 'comment_follow', 'subscribe_modal_heading', 'free_tier_description', 'hide_free_tier' ), true ) ) {
3731 3212 return new WP_Error(
3732 3213 'invalid_param',
3733 3214 sprintf(
3734 3215 /* Translators: Placeholder is the invalid param being sent. */
@@ -3769,11 +3250,11 @@
3769 3250 * return an array with only 'administrator' as the allowed role and save it for 'roles' option.
3770 3251 *
3771 3252 * @since 4.3.0
3772 3253 *
3773 - * @param string|bool $value Value to check.
3254 + * @param mixed $value Value to check.
3774 3255 *
3775 - * @return bool|array
3256 + * @return mixed The value as submitted, or an array holding only 'administrator' when it is empty.
3776 3257 */
3777 3258 public static function sanitize_stats_allowed_roles( $value ) {
3778 3259 if ( empty( $value ) ) {
3779 3260 return array( 'administrator' );
@@ -3781,8 +3262,31 @@
3781 3262 return $value;
3782 3263 }
3783 3264
3784 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 + /**
3785 3289 * Get the currently accessed route and return the module slug in it.
3786 3290 *
3787 3291 * @since 4.3.0
3788 3292 *
@@ -3791,9 +3295,9 @@
3791 3295 * @return array|string
3792 3296 */
3793 3297 public static function get_module_requested( $route = '/module/(?P<slug>[a-z\-]+)' ) {
3794 3298
3795 - 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'] ) ) {
3796 3300 return '';
3797 3301 }
3798 3302
3799 3303 preg_match( "#$route#", $GLOBALS['wp']->query_vars['rest_route'], $module );
@@ -3844,8 +3348,40 @@
3844 3348 return $modules;
3845 3349 }
3846 3350
3847 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 + /**
3848 3384 * Remove 'validate_callback' item from options available for module.
3849 3385 * Fetch current option value and add to array of module options.
3850 3386 * Prepare values of module options that need special handling, like those saved in wpcom.
3851 3387 *
@@ -3908,9 +3444,9 @@
3908 3444 $options = self::split_options( $options, $sharer->get_global_options() );
3909 3445 $options['sharing_services']['current_value'] = $sharer->get_blog_services();
3910 3446 $other_sharedaddy_options = array( 'jetpack-twitter-cards-site-tag', 'sharedaddy_disable_resources', 'sharing_delete_service' );
3911 3447 foreach ( $other_sharedaddy_options as $key ) {
3912 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3448 + $default_value = $options[ $key ]['default'] ?? '';
3913 3449 $current_value = get_option( $key, $default_value );
3914 3450 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3915 3451 }
3916 3452 break;
@@ -3921,9 +3457,9 @@
3921 3457 break;
3922 3458 default:
3923 3459 // These option are just stored as plain WordPress options.
3924 3460 foreach ( $options as $key => $value ) {
3925 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3461 + $default_value = $options[ $key ]['default'] ?? '';
3926 3462 $current_value = get_option( $key, $default_value );
3927 3463 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3928 3464 }
3929 3465 }
@@ -3933,14 +3469,17 @@
3933 3469 // We don't need validate_callback in the response.
3934 3470 if ( isset( $options[ $key ]['validate_callback'] ) ) {
3935 3471 unset( $options[ $key ]['validate_callback'] );
3936 3472 }
3937 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3473 + $default_value = $options[ $key ]['default'] ?? '';
3938 3474 if ( ! array_key_exists( 'current_value', $options[ $key ] ) ) {
3939 3475 $options[ $key ]['current_value'] = self::cast_value( $default_value, $options[ $key ] );
3940 3476 }
3941 3477 }
3942 - 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 );
3943 3482 }
3944 3483
3945 3484 /**
3946 3485 * Splits module options saved as arrays like relatedposts or verification_services_codes into separate options to be returned in the response.
@@ -4445,60 +3984,52 @@
4445 3984 return rest_ensure_response( array( 'success' => $updated_option ) );
4446 3985 }
4447 3986
4448 3987 /**
4449 - * Fetch introdution offers.
3988 + * Return the list of available features.
4450 3989 *
4451 - * @since 10.9
4452 - *
4453 - * @return array|WP_Error
3990 + * @return array
4454 3991 */
4455 - public static function get_intro_offers() {
4456 - $site_id = Jetpack_Options::get_option( 'id' );
4457 -
4458 - if ( ! $site_id ) {
4459 - return new WP_Error(
4460 - 'site_id_missing',
4461 - esc_html__( 'Site ID is missing.', 'jetpack' ),
4462 - array( 'status' => 400 )
4463 - );
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 );
4464 3997 }
4465 3998
4466 - $response = Client::wpcom_json_api_request_as_user(
4467 - '/introductory-offers',
4468 - '2',
4469 - array(
4470 - 'method' => 'GET',
4471 - 'headers' => array(
4472 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
4473 - ),
4474 - )
4475 - );
3999 + return $modules;
4000 + }
4476 4001
4477 - $response_code = wp_remote_retrieve_response_code( $response );
4478 -
4479 - if ( 200 !== $response_code ) {
4480 - return new WP_Error(
4481 - 'intro_offers_fetch_failed',
4482 - esc_html__( 'Could not retrieve intro offers.', 'jetpack' ),
4483 - array( 'status' => $response_code )
4484 - );
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 );
4485 4012 }
4486 4013
4487 - $data = json_decode( wp_remote_retrieve_body( $response ) );
4014 + return $modules;
4015 + }
4488 4016
4489 - if ( ! isset( $data ) ) {
4490 - return new WP_Error(
4491 - 'intro_offers_error',
4492 - esc_html__( 'Could not parse intro offers.', 'jetpack' ),
4493 - 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'
4494 4029 );
4030 + return new WP_Error( 'invalid_permission_fetch_features', $message, array( 'status' => rest_authorization_required_code() ) );
4495 4031 }
4496 4032
4497 - return rest_ensure_response(
4498 - array(
4499 - 'code' => 'success',
4500 - 'data' => $data,
4501 - )
4502 - );
4033 + return true;
4503 4034 }
4504 4035 } // class end