PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 13.9.2 14.0.1 All 504 releases
← All changes | _inc/lib/class.core-rest-api-endpoints.php +321 -443 13.9.216.3-a.1 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' ),
@@ -820,38 +765,25 @@
820 765 }
821 766
822 767 /**
823 768 * Ask WPCOM for a JWT token to use for OpenAI conversations.
824 - * TODO: Clean me up. This is ugly hack code.
769 + *
770 + * @deprecated since 16.2
771 + * @see Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT::get_jwt()
772 + *
773 + * @return array|WP_Error The token and blog ID, or the error from WPCOM.
825 774 */
826 775 public static function get_openai_jwt() {
827 - $blog_id = \Jetpack_Options::get_option( 'id' );
776 + _deprecated_function( __METHOD__, 'jetpack-16.2', '\Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT::get_jwt' );
828 777
829 - $response = \Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user(
830 - "/sites/$blog_id/jetpack-openai-query/jwt",
831 - '2',
832 - array(
833 - 'method' => 'POST',
834 - 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ),
835 - ),
836 - wp_json_encode( array() ),
837 - 'wpcom'
838 - );
778 + $response = ( new REST_Jetpack_AI_JWT() )->get_jwt();
839 779
840 780 if ( is_wp_error( $response ) ) {
841 781 return $response;
842 782 }
843 783
844 - $json = json_decode( wp_remote_retrieve_body( $response ) );
845 -
846 - if ( ! isset( $json->token ) ) {
847 - return new WP_Error( 'no-token', 'No token returned from WPCOM' );
848 - }
849 -
850 - return array(
851 - 'token' => $json->token,
852 - 'blog_id' => $blog_id,
853 - );
784 + // Pre-deprecation callers expect the raw array, not a WP_REST_Response.
785 + return $response->get_data();
854 786 }
855 787
856 788 /**
857 789 * Set subscriber cookie and redirect
@@ -862,15 +794,24 @@
862 794 */
863 795 public static function set_subscriber_cookie_and_redirect( $request ) {
864 796 require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
865 797 $subscription_service = \Automattic\Jetpack\Extensions\Premium_Content\subscription_service();
866 - $token = $subscription_service->get_and_set_token_from_request();
867 - $payload = $subscription_service->decode_token( $token );
868 - $is_valid_token = ! empty( $payload );
869 - if ( $is_valid_token ) {
870 - return new WP_REST_Response( null, 302, array( 'location' => $request['redirect_url'] ) );
798 + // Note: get_and_set_token_from_request() sets the subscriber cookie as a side effect.
799 + // The cookie is set regardless of the redirect target below; only the redirect is gated.
800 + $token = $subscription_service->get_and_set_token_from_request();
801 + $payload = $subscription_service->decode_token( $token );
802 + $is_valid_token = ! empty( $payload );
803 + if ( ! $is_valid_token ) {
804 + return new WP_Error( 'invalid-token', 'Invalid Token', array( 'status' => 403 ) );
871 805 }
872 - return new WP_Error( 'invalid-token', 'Invalid Token' );
806 +
807 + // Only redirect to the current site, not to an arbitrary host.
808 + $redirect_url = wp_validate_redirect( $request['redirect_url'], '' );
809 + if ( ! $redirect_url ) {
810 + return new WP_Error( 'invalid-redirect', 'Invalid Redirect URL', array( 'status' => 400 ) );
811 + }
812 +
813 + return new WP_REST_Response( null, 302, array( 'location' => $redirect_url ) );
873 814 }
874 815
875 816 /**
876 817 * Get the data for the recommendations
@@ -930,9 +871,9 @@
930 871 }
931 872
932 873 $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() );
933 874 if ( ! $user_connected ) {
934 - return wp_json_encode( array() );
875 + return wp_json_encode( array(), JSON_UNESCAPED_SLASHES );
935 876 }
936 877
937 878 $request_path = sprintf( '/sites/%s/jetpack-recommendations/product-suggestions?locale=' . get_user_locale(), $blog_id );
938 879 $wpcom_request = Client::wpcom_json_api_request_as_user(
@@ -1201,8 +1142,9 @@
1201 1142 || Jetpack::is_plugin_active( 'mojo-under-construction/mojo-contruction.php' ) && 1 == $under_construction_activation_status // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1202 1143 || ( Jetpack::is_plugin_active( 'under-construction-page/under-construction.php' ) && isset( $ucp_options['status'] ) && 1 == $ucp_options['status'] ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1203 1144 || ( 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
1204 1145 || ( Jetpack::is_plugin_active( 'coming-soon/coming-soon.php' ) && isset( $csp4['status'] ) && ( 1 == $csp4['status'] || 2 == $csp4['status'] ) ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1146 + ||
1205 1147 /**
1206 1148 * Allow plugins to mark a site as "under construction".
1207 1149 *
1208 1150 * @since 6.7.0
@@ -1208,9 +1150,9 @@
1208 1150 * @since 6.7.0
1209 1151 *
1210 1152 * @param false bool Is the site under construction? Default to false.
1211 1153 */
1212 - || true === apply_filters( 'jetpack_is_under_construction_plugin', false )
1154 + true === apply_filters( 'jetpack_is_under_construction_plugin', false )
1213 1155 ) {
1214 1156 return new WP_Error( 'forbidden', __( 'Site is under construction and cannot be verified', 'jetpack' ) );
1215 1157 }
1216 1158
@@ -1349,24 +1291,20 @@
1349 1291
1350 1292 /**
1351 1293 * Verify that a user can use the /connection/user endpoint. Has to be a registered user and be currently linked.
1352 1294 *
1295 + * @uses Automattic\Jetpack\Connection\Manager::is_user_connected();)
1296 + *
1297 + * @deprecated since Jetpack 14.4.0
1298 + * @see Automattic\Jetpack\Connection\REST_Connector::unlink_user_permission_callback()
1299 + *
1353 1300 * @since 4.3.0
1354 1301 *
1355 - * @uses Automattic\Jetpack\Connection\Manager::is_user_connected();)
1356 - *
1357 1302 * @return bool|WP_Error True if user is able to unlink.
1358 1303 */
1359 1304 public static function unlink_user_permission_callback() {
1360 - if ( current_user_can( 'jetpack_connect_user' ) && ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() ) ) {
1361 - return true;
1362 - }
1363 -
1364 - return new WP_Error(
1365 - 'invalid_user_permission_unlink_user',
1366 - REST_Connector::get_user_permissions_error_msg(),
1367 - array( 'status' => rest_authorization_required_code() )
1368 - );
1305 + _deprecated_function( __METHOD__, 'jetpack-14.4.0', 'Automattic\Jetpack\Connection\REST_Connector::unlink_user_permission_callback()' );
1306 + return REST_Connector::unlink_user_permission_callback();
1369 1307 }
1370 1308
1371 1309 /**
1372 1310 * Verify that user can manage Jetpack modules.
@@ -1501,136 +1439,8 @@
1501 1439 );
1502 1440 }
1503 1441
1504 1442 /**
1505 - * Test connection status for this Jetpack site.
1506 - *
1507 - * @since 6.8.0
1508 - *
1509 - * @return array|WP_Error WP_Error returned if connection test does not succeed.
1510 - */
1511 - public static function jetpack_connection_test() {
1512 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1513 - $cxntests = new Jetpack_Cxn_Tests();
1514 -
1515 - if ( $cxntests->pass() ) {
1516 - return rest_ensure_response(
1517 - array(
1518 - 'code' => 'success',
1519 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1520 - )
1521 - );
1522 - } else {
1523 - return $cxntests->output_fails_as_wp_error();
1524 - }
1525 - }
1526 -
1527 - /**
1528 - * Test connection permission check method.
1529 - *
1530 - * @since 7.1.0
1531 - *
1532 - * @return bool
1533 - */
1534 - public static function view_jetpack_connection_test_check() {
1535 - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- This is verifying the trusted caller via a shared private key and timestamp.
1536 - if ( ! isset( $_GET['signature'] ) || ! isset( $_GET['timestamp'] ) || ! isset( $_GET['url'] ) ) {
1537 - return false;
1538 - }
1539 - $signature = base64_decode( wp_unslash( $_GET['signature'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1540 -
1541 - $signature_data = wp_json_encode(
1542 - array(
1543 - 'rest_route' => isset( $_GET['rest_route'] ) ? filter_var( wp_unslash( $_GET['rest_route'] ) ) : null,
1544 - 'timestamp' => (int) $_GET['timestamp'],
1545 - 'url' => esc_url_raw( wp_unslash( $_GET['url'] ) ),
1546 - )
1547 - );
1548 -
1549 - if (
1550 - ! function_exists( 'openssl_verify' )
1551 - || 1 !== openssl_verify(
1552 - $signature_data,
1553 - $signature,
1554 - JETPACK__DEBUGGER_PUBLIC_KEY
1555 - )
1556 - ) {
1557 - return false;
1558 - }
1559 -
1560 - // signature timestamp must be within 5min of current time.
1561 - if ( abs( time() - (int) $_GET['timestamp'] ) > 300 ) {
1562 - return false;
1563 - }
1564 -
1565 - // phpcs:enable WordPress.Security.NonceVerification.Recommended
1566 -
1567 - return true;
1568 - }
1569 -
1570 - /**
1571 - * Test connection status for this Jetpack site, encrypt the results for decryption by a third-party.
1572 - *
1573 - * @since 7.1.0
1574 - *
1575 - * @return array|mixed|object|WP_Error
1576 - */
1577 - public static function jetpack_connection_test_for_external() {
1578 - // 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.
1579 - add_filter( 'jetpack_debugger_run_self_test', '__return_false' );
1580 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php';
1581 - $cxntests = new Jetpack_Cxn_Tests();
1582 -
1583 - if ( $cxntests->pass() ) {
1584 - $result = array(
1585 - 'code' => 'success',
1586 - 'message' => __( 'All connection tests passed.', 'jetpack' ),
1587 - );
1588 - } else {
1589 - $error = $cxntests->output_fails_as_wp_error(); // Using this so the output is similar both ways.
1590 - $errors = array();
1591 -
1592 - // Borrowed from WP_REST_Server::error_to_response().
1593 - foreach ( (array) $error->errors as $code => $messages ) {
1594 - foreach ( (array) $messages as $message ) {
1595 - $errors[] = array(
1596 - 'code' => $code,
1597 - 'message' => $message,
1598 - 'data' => $error->get_error_data( $code ),
1599 - );
1600 - }
1601 - }
1602 -
1603 - $result = ( ! empty( $errors ) ) ? $errors[0] : null;
1604 - if ( count( $errors ) > 1 ) {
1605 - // Remove the primary error.
1606 - array_shift( $errors );
1607 - $result['additional_errors'] = $errors;
1608 - }
1609 - }
1610 -
1611 - $result = wp_json_encode( $result );
1612 -
1613 - $encrypted = $cxntests->encrypt_string_for_wpcom( $result );
1614 -
1615 - if ( ! $encrypted || ! is_array( $encrypted ) ) {
1616 - return rest_ensure_response(
1617 - array(
1618 - 'code' => 'action_required',
1619 - 'message' => 'Please request results from the in-plugin debugger',
1620 - )
1621 - );
1622 - }
1623 -
1624 - return rest_ensure_response(
1625 - array(
1626 - 'code' => 'response',
1627 - 'debug' => $encrypted,
1628 - )
1629 - );
1630 - }
1631 -
1632 - /**
1633 1443 * Fetch information about the Rewind status of the site.
1634 1444 */
1635 1445 public static function rewind_data() {
1636 1446 $site_id = Jetpack_Options::get_option( 'id' );
@@ -1673,9 +1483,9 @@
1673 1483 return rest_ensure_response(
1674 1484 array(
1675 1485 'code' => 'success',
1676 1486 'message' => esc_html__( 'Backup & Scan data correctly received.', 'jetpack' ),
1677 - 'data' => wp_json_encode( $rewind_data ),
1487 + 'data' => wp_json_encode( $rewind_data, JSON_UNESCAPED_SLASHES ),
1678 1488 )
1679 1489 );
1680 1490 }
1681 1491
@@ -1756,9 +1566,9 @@
1756 1566 return rest_ensure_response(
1757 1567 array(
1758 1568 'code' => 'success',
1759 1569 'message' => esc_html__( 'Scan state correctly received.', 'jetpack' ),
1760 - 'data' => wp_json_encode( $scan_state ),
1570 + 'data' => wp_json_encode( $scan_state, JSON_UNESCAPED_SLASHES ),
1761 1571 )
1762 1572 );
1763 1573 }
1764 1574
@@ -1815,10 +1625,10 @@
1815 1625 *
1816 1626 * @return string|WP_Error A raw URL if the connection URL could be built; error message otherwise.
1817 1627 */
1818 1628 public static function build_connect_url( $request = array() ) {
1819 - $from = isset( $request['from'] ) ? $request['from'] : false;
1820 - $redirect = isset( $request['redirect'] ) ? $request['redirect'] : false;
1629 + $from = $request['from'] ?? false;
1630 + $redirect = $request['redirect'] ?? false;
1821 1631
1822 1632 $url = Jetpack::init()->build_connect_url( true, $redirect, $from );
1823 1633 if ( $url ) {
1824 1634 return rest_ensure_response( $url );
@@ -1856,30 +1666,21 @@
1856 1666
1857 1667 /**
1858 1668 * Unlinks current user from the WordPress.com Servers.
1859 1669 *
1860 - * @since 4.3.0
1670 + * @param WP_REST_Request $request The request sent to the WP REST API.
1861 1671 * @uses Automattic\Jetpack\Connection\Manager->disconnect_user
1862 1672 *
1863 - * @param WP_REST_Request $request The request sent to the WP REST API.
1673 + * @deprecated since Jetpack 14.4.0
1674 + * @see Automattic\Jetpack\Connection\REST_Connector::unlink_user()
1864 1675 *
1676 + * @since 4.3.0
1677 + *
1865 1678 * @return bool|WP_Error True if user successfully unlinked.
1866 1679 */
1867 1680 public static function unlink_user( $request ) {
1868 -
1869 - if ( ! isset( $request['linked'] ) || false !== $request['linked'] ) {
1870 - return new WP_Error( 'invalid_param', esc_html__( 'Invalid Parameter', 'jetpack' ), array( 'status' => 404 ) );
1871 - }
1872 -
1873 - if ( ( new Connection_Manager( 'jetpack' ) )->disconnect_user() ) {
1874 - return rest_ensure_response(
1875 - array(
1876 - 'code' => 'success',
1877 - )
1878 - );
1879 - }
1880 -
1881 - return new WP_Error( 'unlink_user_failed', esc_html__( 'Was not able to unlink the user. Please try again.', 'jetpack' ), array( 'status' => 400 ) );
1681 + _deprecated_function( __METHOD__, 'jetpack-14.4.0', 'Automattic\Jetpack\Connection\REST_Connector::unlink_user()' );
1682 + return REST_Connector::unlink_user( $request );
1882 1683 }
1883 1684
1884 1685 /**
1885 1686 * Gets current user's tracking settings.
@@ -1938,9 +1739,9 @@
1938 1739 'Content-Type' => 'application/json',
1939 1740 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
1940 1741 ),
1941 1742 ),
1942 - wp_json_encode( $request->get_params() )
1743 + wp_json_encode( $request->get_params(), JSON_UNESCAPED_SLASHES )
1943 1744 );
1944 1745 if ( ! is_wp_error( $response ) ) {
1945 1746 $response = json_decode( wp_remote_retrieve_body( $response ), true );
1946 1747 }
@@ -1952,93 +1753,30 @@
1952 1753 /**
1953 1754 * Fetch site data from .com including the site's current plan and the site's products.
1954 1755 *
1955 1756 * @since 5.5.0
1757 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\Manager::get_connected_site_data().
1956 1758 *
1957 1759 * @return stdClass|WP_Error
1958 1760 */
1959 1761 public static function site_data() {
1960 - $site_id = Jetpack_Options::get_option( 'id' );
1762 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\Manager::get_connected_site_data' );
1961 1763
1962 - if ( ! $site_id ) {
1963 - return new WP_Error( 'site_id_missing', '', array( 'api_error_code' => __( 'site_id_missing', 'jetpack' ) ) );
1964 - }
1764 + return ( new Connection_Manager() )->get_connected_site_data();
1765 + }
1965 1766
1966 - $args = array( 'headers' => array() );
1967 -
1968 - // Allow use a store sandbox. Internal ref: PCYsg-IA-p2.
1969 - if ( isset( $_COOKIE ) && isset( $_COOKIE['store_sandbox'] ) ) {
1970 - $secret = filter_var( wp_unslash( $_COOKIE['store_sandbox'] ) );
1971 - $args['headers']['Cookie'] = "store_sandbox=$secret;";
1972 - }
1973 -
1974 - $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ) . '?force=wpcom', '1.1', $args );
1975 - $body = wp_remote_retrieve_body( $response );
1976 - $data = $body ? json_decode( $body ) : null;
1977 -
1978 - if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
1979 - $error_info = array(
1980 - 'api_error_code' => null,
1981 - 'api_http_code' => wp_remote_retrieve_response_code( $response ),
1982 - );
1983 -
1984 - if ( is_wp_error( $response ) ) {
1985 - $error_info['api_error_code'] = $response->get_error_code() ? wp_strip_all_tags( $response->get_error_code() ) : null;
1986 - } elseif ( $data && ! empty( $data->error ) ) {
1987 - $error_info['api_error_code'] = $data->error;
1988 - }
1989 -
1990 - return new WP_Error( 'site_data_fetch_failed', '', $error_info );
1991 - }
1992 -
1993 - Jetpack_Plan::update_from_sites_response( $response );
1994 -
1995 - return $data;
1996 - }
1997 1767 /**
1998 1768 * Get site data, including for example, the site's current plan.
1999 1769 *
1770 + * @since 4.3.0
1771 + * @deprecated 16.2 Use Automattic\Jetpack\Connection\REST_Connector::site_data_response().
1772 + *
2000 1773 * @return WP_Error|WP_HTTP_Response|WP_REST_Response
2001 - * @since 4.3.0
2002 1774 */
2003 1775 public static function get_site_data() {
2004 - $site_data = self::site_data();
1776 + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\REST_Connector::site_data_response' );
2005 1777
2006 - if ( ! is_wp_error( $site_data ) ) {
2007 -
2008 - /**
2009 - * Fires when the site data was successfully returned from the /sites/%d wpcom endpoint.
2010 - *
2011 - * @since 8.7.0
2012 - */
2013 - do_action( 'jetpack_get_site_data_success' );
2014 - return rest_ensure_response(
2015 - array(
2016 - 'code' => 'success',
2017 - 'message' => esc_html__( 'Site data correctly received.', 'jetpack' ),
2018 - 'data' => wp_json_encode( $site_data ),
2019 - )
2020 - );
2021 - }
2022 -
2023 - $error_data = $site_data->get_error_data();
2024 -
2025 - if ( empty( $error_data['api_error_code'] ) ) {
2026 - $error_message = esc_html__( 'Failed fetching site data from WordPress.com. If the problem persists, try reconnecting Jetpack.', 'jetpack' );
2027 - } else {
2028 - /* translators: %s is an error code (e.g. `token_mismatch`) */
2029 - $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'] );
2030 - }
2031 -
2032 - return new WP_Error(
2033 - $site_data->get_error_code(),
2034 - $error_message,
2035 - array(
2036 - 'status' => 400,
2037 - 'api_error_code' => empty( $error_data['api_error_code'] ) ? null : $error_data['api_error_code'],
2038 - 'api_http_code' => empty( $error_data['api_http_code'] ) ? null : $error_data['api_http_code'],
2039 - )
2040 - );
1778 + return REST_Connector::site_data_response();
2041 1779 }
2042 1780
2043 1781 /**
2044 1782 * Fetch AL data for this site and return it.
@@ -2253,9 +1991,9 @@
2253 1991 public static function get_updateable_data_list( $selector = '' ) {
2254 1992
2255 1993 $options = array(
2256 1994 // Blocks.
2257 - 'jetpack_blocks_disabled' => array(
1995 + 'jetpack_blocks_disabled' => array(
2258 1996 'description' => esc_html__( 'Jetpack Blocks disabled.', 'jetpack' ),
2259 1997 'type' => 'boolean',
2260 1998 'default' => false,
2261 1999 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2262,9 +2000,9 @@
2262 2000 'jp_group' => 'settings',
2263 2001 ),
2264 2002
2265 2003 // Carousel
2266 - 'carousel_background_color' => array(
2004 + 'carousel_background_color' => array(
2267 2005 'description' => esc_html__( 'Color scheme.', 'jetpack' ),
2268 2006 'type' => 'string',
2269 2007 'default' => 'black',
2270 2008 'enum' => array(
@@ -2277,9 +2015,9 @@
2277 2015 ),
2278 2016 'validate_callback' => __CLASS__ . '::validate_list_item',
2279 2017 'jp_group' => 'carousel',
2280 2018 ),
2281 - 'carousel_display_exif' => array(
2019 + 'carousel_display_exif' => array(
2282 2020 'description' => wp_kses(
2283 2021 sprintf( __( 'Show photo metadata (<a href="https://en.wikipedia.org/wiki/Exchangeable_image_file_format" target="_blank">Exif</a>) in carousel, when available.', 'jetpack' ) ),
2284 2022 array(
2285 2023 'a' => array(
@@ -2292,9 +2030,9 @@
2292 2030 'default' => 0,
2293 2031 'validate_callback' => __CLASS__ . '::validate_boolean',
2294 2032 'jp_group' => 'carousel',
2295 2033 ),
2296 - 'carousel_display_comments' => array(
2034 + 'carousel_display_comments' => array(
2297 2035 'description' => esc_html__( 'Show comments area in carousel', 'jetpack' ),
2298 2036 'type' => 'boolean',
2299 2037 'default' => 1,
2300 2038 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2301,9 +2039,9 @@
2301 2039 'jp_group' => 'carousel',
2302 2040 ),
2303 2041
2304 2042 // Comments.
2305 - 'highlander_comment_form_prompt' => array(
2043 + 'highlander_comment_form_prompt' => array(
2306 2044 'description' => esc_html__( 'Greeting Text', 'jetpack' ),
2307 2045 'type' => 'string',
2308 2046 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2309 2047 'sanitize_callback' => 'sanitize_text_field',
@@ -2308,9 +2046,9 @@
2308 2046 'default' => esc_html__( 'Leave a Reply', 'jetpack' ),
2309 2047 'sanitize_callback' => 'sanitize_text_field',
2310 2048 'jp_group' => 'comments',
2311 2049 ),
2312 - 'jetpack_comment_form_color_scheme' => array(
2050 + 'jetpack_comment_form_color_scheme' => array(
2313 2051 'description' => esc_html__( 'Color scheme', 'jetpack' ),
2314 2052 'type' => 'string',
2315 2053 'default' => 'light',
2316 2054 'enum' => array(
@@ -2327,39 +2065,38 @@
2327 2065 'jp_group' => 'comments',
2328 2066 ),
2329 2067
2330 2068 // Custom Content Types.
2331 - 'jetpack_portfolio' => array(
2069 + 'jetpack_portfolio' => array(
2332 2070 'description' => esc_html__( 'Enable or disable Jetpack portfolio post type.', 'jetpack' ),
2333 2071 'type' => 'boolean',
2334 2072 'default' => 0,
2335 2073 'validate_callback' => __CLASS__ . '::validate_boolean',
2336 - 'jp_group' => 'custom-content-types',
2074 + 'jp_group' => 'settings',
2337 2075 ),
2338 - 'jetpack_portfolio_posts_per_page' => array(
2076 + 'jetpack_portfolio_posts_per_page' => array(
2339 2077 'description' => esc_html__( 'Number of entries to show at most in Portfolio pages.', 'jetpack' ),
2340 2078 'type' => 'integer',
2341 2079 'default' => 10,
2342 2080 'validate_callback' => __CLASS__ . '::validate_posint',
2343 - 'jp_group' => 'custom-content-types',
2081 + 'jp_group' => 'settings',
2344 2082 ),
2345 - 'jetpack_testimonial' => array(
2083 + 'jetpack_testimonial' => array(
2346 2084 'description' => esc_html__( 'Enable or disable Jetpack testimonial post type.', 'jetpack' ),
2347 2085 'type' => 'boolean',
2348 2086 'default' => 0,
2349 2087 'validate_callback' => __CLASS__ . '::validate_boolean',
2350 - 'jp_group' => 'custom-content-types',
2088 + 'jp_group' => 'settings',
2351 2089 ),
2352 - 'jetpack_testimonial_posts_per_page' => array(
2090 + 'jetpack_testimonial_posts_per_page' => array(
2353 2091 'description' => esc_html__( 'Number of entries to show at most in Testimonial pages.', 'jetpack' ),
2354 2092 'type' => 'integer',
2355 2093 'default' => 10,
2356 2094 'validate_callback' => __CLASS__ . '::validate_posint',
2357 - 'jp_group' => 'custom-content-types',
2095 + 'jp_group' => 'settings',
2358 2096 ),
2359 -
2360 2097 // WAF.
2361 - 'jetpack_waf_automatic_rules' => array(
2098 + 'jetpack_waf_automatic_rules' => array(
2362 2099 'description' => esc_html__( 'Enable automatic rules - Protect your site against untrusted traffic sources with automatic security rules.', 'jetpack' ),
2363 2100 'type' => 'boolean',
2364 2101 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2365 2102 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2364,9 +2101,9 @@
2364 2101 'default' => Waf_Compatibility::get_default_automatic_rules_option(),
2365 2102 'validate_callback' => __CLASS__ . '::validate_boolean',
2366 2103 'jp_group' => 'waf',
2367 2104 ),
2368 - 'jetpack_waf_ip_block_list_enabled' => array(
2105 + 'jetpack_waf_ip_block_list_enabled' => array(
2369 2106 'description' => esc_html__( 'Block list - Block a specific request IP.', 'jetpack' ),
2370 2107 'type' => 'boolean',
2371 2108 'default' => 0,
2372 2109 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2371,9 +2108,9 @@
2371 2108 'default' => 0,
2372 2109 'validate_callback' => __CLASS__ . '::validate_boolean',
2373 2110 'jp_group' => 'waf',
2374 2111 ),
2375 - 'jetpack_waf_ip_block_list' => array(
2112 + 'jetpack_waf_ip_block_list' => array(
2376 2113 'description' => esc_html__( 'Blocked IP addresses', 'jetpack' ),
2377 2114 'type' => 'string',
2378 2115 'default' => '',
2379 2116 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2379,9 +2116,9 @@
2379 2116 'validate_callback' => __CLASS__ . '::validate_string',
2380 2117 'sanitize_callback' => 'esc_textarea',
2381 2118 'jp_group' => 'waf',
2382 2119 ),
2383 - 'jetpack_waf_ip_allow_list_enabled' => array(
2120 + 'jetpack_waf_ip_allow_list_enabled' => array(
2384 2121 'description' => esc_html__( 'Allow list - Allow a specific request IP.', 'jetpack' ),
2385 2122 'type' => 'boolean',
2386 2123 'default' => 0,
2387 2124 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2386,9 +2123,9 @@
2386 2123 'default' => 0,
2387 2124 'validate_callback' => __CLASS__ . '::validate_boolean',
2388 2125 'jp_group' => 'settings',
2389 2126 ),
2390 - 'jetpack_waf_ip_allow_list' => array(
2127 + 'jetpack_waf_ip_allow_list' => array(
2391 2128 'description' => esc_html__( 'Always allowed IP addresses', 'jetpack' ),
2392 2129 'type' => 'string',
2393 2130 'default' => '',
2394 2131 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2394,9 +2131,9 @@
2394 2131 'validate_callback' => __CLASS__ . '::validate_string',
2395 2132 'sanitize_callback' => 'esc_textarea',
2396 2133 'jp_group' => 'settings',
2397 2134 ),
2398 - 'jetpack_waf_share_data' => array(
2135 + 'jetpack_waf_share_data' => array(
2399 2136 'description' => esc_html__( 'Share basic data with Jetpack.', 'jetpack' ),
2400 2137 'type' => 'boolean',
2401 2138 'default' => 0,
2402 2139 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2401,9 +2138,9 @@
2401 2138 'default' => 0,
2402 2139 'validate_callback' => __CLASS__ . '::validate_boolean',
2403 2140 'jp_group' => 'waf',
2404 2141 ),
2405 - 'jetpack_waf_share_debug_data' => array(
2142 + 'jetpack_waf_share_debug_data' => array(
2406 2143 'description' => esc_html__( 'Share detailed data with Jetpack.', 'jetpack' ),
2407 2144 'type' => 'boolean',
2408 2145 'default' => 0,
2409 2146 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2409,9 +2146,9 @@
2409 2146 'validate_callback' => __CLASS__ . '::validate_boolean',
2410 2147 'jp_group' => 'waf',
2411 2148 ),
2412 2149 // Galleries.
2413 - 'tiled_galleries' => array(
2150 + 'tiled_galleries' => array(
2414 2151 'description' => esc_html__( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ),
2415 2152 'type' => 'boolean',
2416 2153 'default' => 0,
2417 2154 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2417,9 +2154,9 @@
2417 2154 'validate_callback' => __CLASS__ . '::validate_boolean',
2418 2155 'jp_group' => 'tiled-gallery',
2419 2156 ),
2420 2157
2421 - 'gravatar_disable_hovercards' => array(
2158 + 'gravatar_disable_hovercards' => array(
2422 2159 'description' => esc_html__( "View people's profiles when you mouse over their Gravatars", 'jetpack' ),
2423 2160 'type' => 'string',
2424 2161 'default' => 'enabled',
2425 2162 // Not visible. This is used as the checkbox value.
@@ -2435,9 +2172,9 @@
2435 2172 'jp_group' => 'gravatar-hovercards',
2436 2173 ),
2437 2174
2438 2175 // Infinite Scroll.
2439 - 'infinite_scroll' => array(
2176 + 'infinite_scroll' => array(
2440 2177 'description' => esc_html__( 'To infinity and beyond', 'jetpack' ),
2441 2178 'type' => 'boolean',
2442 2179 'default' => 1,
2443 2180 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2442,9 +2179,9 @@
2442 2179 'default' => 1,
2443 2180 'validate_callback' => __CLASS__ . '::validate_boolean',
2444 2181 'jp_group' => 'infinite-scroll',
2445 2182 ),
2446 - 'infinite_scroll_google_analytics' => array(
2183 + 'infinite_scroll_google_analytics' => array(
2447 2184 'description' => esc_html__( 'Use Google Analytics with Infinite Scroll', 'jetpack' ),
2448 2185 'type' => 'boolean',
2449 2186 'default' => 0,
2450 2187 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2451,9 +2188,9 @@
2451 2188 'jp_group' => 'infinite-scroll',
2452 2189 ),
2453 2190
2454 2191 // Likes.
2455 - 'wpl_default' => array(
2192 + 'wpl_default' => array(
2456 2193 'description' => esc_html__( 'WordPress.com Likes are', 'jetpack' ),
2457 2194 'type' => 'string',
2458 2195 'default' => 'on',
2459 2196 'enum' => array(
@@ -2466,9 +2203,9 @@
2466 2203 ),
2467 2204 'validate_callback' => __CLASS__ . '::validate_list_item',
2468 2205 'jp_group' => 'likes',
2469 2206 ),
2470 - 'social_notifications_like' => array(
2207 + 'social_notifications_like' => array(
2471 2208 'description' => esc_html__( 'Send email notification when someone likes a post', 'jetpack' ),
2472 2209 'type' => 'boolean',
2473 2210 'default' => 1,
2474 2211 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2475,9 +2212,9 @@
2475 2212 'jp_group' => 'likes',
2476 2213 ),
2477 2214
2478 2215 // Markdown.
2479 - 'wpcom_publish_comments_with_markdown' => array(
2216 + 'wpcom_publish_comments_with_markdown' => array(
2480 2217 'description' => esc_html__( 'Use Markdown for comments.', 'jetpack' ),
2481 2218 'type' => 'boolean',
2482 2219 'default' => 0,
2483 2220 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2482,9 +2219,9 @@
2482 2219 'default' => 0,
2483 2220 'validate_callback' => __CLASS__ . '::validate_boolean',
2484 2221 'jp_group' => 'markdown',
2485 2222 ),
2486 - 'wpcom_publish_posts_with_markdown' => array(
2223 + 'wpcom_publish_posts_with_markdown' => array(
2487 2224 'description' => esc_html__( 'Use Markdown for posts.', 'jetpack' ),
2488 2225 'type' => 'boolean',
2489 2226 'default' => 0,
2490 2227 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2491,9 +2228,9 @@
2491 2228 'jp_group' => 'markdown',
2492 2229 ),
2493 2230
2494 2231 // Monitor.
2495 - 'monitor_receive_notifications' => array(
2232 + 'monitor_receive_notifications' => array(
2496 2233 'description' => esc_html__( 'Receive Monitor Email Notifications.', 'jetpack' ),
2497 2234 'type' => 'boolean',
2498 2235 'default' => 0,
2499 2236 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2500,9 +2237,9 @@
2500 2237 'jp_group' => 'monitor',
2501 2238 ),
2502 2239
2503 2240 // Post by Email.
2504 - 'post_by_email_address' => array(
2241 + 'post_by_email_address' => array(
2505 2242 'description' => esc_html__( 'Email Address', 'jetpack' ),
2506 2243 'type' => 'string',
2507 2244 'default' => 'noop',
2508 2245 'enum' => array(
@@ -2521,9 +2258,9 @@
2521 2258 'jp_group' => 'post-by-email',
2522 2259 ),
2523 2260
2524 2261 // Protect.
2525 - 'jetpack_protect_key' => array(
2262 + 'jetpack_protect_key' => array(
2526 2263 'description' => esc_html__( 'Protect API key', 'jetpack' ),
2527 2264 'type' => 'string',
2528 2265 'default' => '',
2529 2266 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2528,9 +2265,9 @@
2528 2265 'default' => '',
2529 2266 'validate_callback' => __CLASS__ . '::validate_alphanum',
2530 2267 'jp_group' => 'protect',
2531 2268 ),
2532 - 'jetpack_protect_global_whitelist' => array(
2269 + 'jetpack_protect_global_whitelist' => array(
2533 2270 'description' => esc_html__( 'Protect global IP allow list', 'jetpack' ),
2534 2271 'type' => 'string',
2535 2272 'default' => '',
2536 2273 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2538,9 +2275,9 @@
2538 2275 'jp_group' => 'protect',
2539 2276 ),
2540 2277
2541 2278 // Sharing.
2542 - 'sharing_services' => array(
2279 + 'sharing_services' => array(
2543 2280 'description' => esc_html__( 'Enabled Services and those hidden behind a button', 'jetpack' ),
2544 2281 'type' => 'object',
2545 2282 'default' => array(
2546 2283 'visible' => array( 'facebook', 'x' ),
@@ -2548,9 +2285,9 @@
2548 2285 ),
2549 2286 'validate_callback' => __CLASS__ . '::validate_services',
2550 2287 'jp_group' => 'sharedaddy',
2551 2288 ),
2552 - 'button_style' => array(
2289 + 'button_style' => array(
2553 2290 'description' => esc_html__( 'Button Style', 'jetpack' ),
2554 2291 'type' => 'string',
2555 2292 'default' => 'icon',
2556 2293 'enum' => array(
@@ -2567,9 +2304,9 @@
2567 2304 ),
2568 2305 'validate_callback' => __CLASS__ . '::validate_list_item',
2569 2306 'jp_group' => 'sharedaddy',
2570 2307 ),
2571 - 'sharing_label' => array(
2308 + 'sharing_label' => array(
2572 2309 'description' => esc_html__( 'Sharing Label', 'jetpack' ),
2573 2310 'type' => 'string',
2574 2311 'default' => '',
2575 2312 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2575,9 +2312,9 @@
2575 2312 'validate_callback' => __CLASS__ . '::validate_string',
2576 2313 'sanitize_callback' => 'esc_html',
2577 2314 'jp_group' => 'sharedaddy',
2578 2315 ),
2579 - 'show' => array(
2316 + 'show' => array(
2580 2317 'description' => esc_html__( 'Views where buttons are shown', 'jetpack' ),
2581 2318 'type' => 'array',
2582 2319 'items' => array(
2583 2320 'type' => 'string',
@@ -2585,9 +2322,9 @@
2585 2322 'default' => array( 'post' ),
2586 2323 'validate_callback' => __CLASS__ . '::validate_sharing_show',
2587 2324 'jp_group' => 'sharedaddy',
2588 2325 ),
2589 - 'jetpack-twitter-cards-site-tag' => array(
2326 + 'jetpack-twitter-cards-site-tag' => array(
2590 2327 'description' => esc_html__( "The Twitter username of the owner of this site's domain.", 'jetpack' ),
2591 2328 'type' => 'string',
2592 2329 'default' => '',
2593 2330 'validate_callback' => __CLASS__ . '::validate_twitter_username',
@@ -2593,9 +2330,9 @@
2593 2330 'validate_callback' => __CLASS__ . '::validate_twitter_username',
2594 2331 'sanitize_callback' => 'esc_html',
2595 2332 'jp_group' => 'sharedaddy',
2596 2333 ),
2597 - 'sharedaddy_disable_resources' => array(
2334 + 'sharedaddy_disable_resources' => array(
2598 2335 'description' => esc_html__( 'Disable CSS and JS', 'jetpack' ),
2599 2336 'type' => 'boolean',
2600 2337 'default' => 0,
2601 2338 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2600,9 +2337,9 @@
2600 2337 'default' => 0,
2601 2338 'validate_callback' => __CLASS__ . '::validate_boolean',
2602 2339 'jp_group' => 'sharedaddy',
2603 2340 ),
2604 - 'custom' => array(
2341 + 'custom' => array(
2605 2342 'description' => esc_html__( 'Custom sharing services added by user.', 'jetpack' ),
2606 2343 'type' => 'object',
2607 2344 'default' => array(
2608 2345 'sharing_name' => '',
@@ -2612,9 +2349,9 @@
2612 2349 'validate_callback' => __CLASS__ . '::validate_custom_service',
2613 2350 'jp_group' => 'sharedaddy',
2614 2351 ),
2615 2352 // Not an option, but an action that can be performed on the list of custom services passing the service ID.
2616 - 'sharing_delete_service' => array(
2353 + 'sharing_delete_service' => array(
2617 2354 'description' => esc_html__( 'Delete custom sharing service.', 'jetpack' ),
2618 2355 'type' => 'string',
2619 2356 'default' => '',
2620 2357 'validate_callback' => __CLASS__ . '::validate_custom_service_id',
@@ -2621,9 +2358,9 @@
2621 2358 'jp_group' => 'sharedaddy',
2622 2359 ),
2623 2360
2624 2361 // SSO.
2625 - 'jetpack_sso_require_two_step' => array(
2362 + 'jetpack_sso_require_two_step' => array(
2626 2363 'description' => esc_html__( 'Require Two-Step Authentication', 'jetpack' ),
2627 2364 'type' => 'boolean',
2628 2365 'default' => SSO\Helpers::is_require_two_step_checkbox_disabled(),
2629 2366 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2628,9 +2365,9 @@
2628 2365 'default' => SSO\Helpers::is_require_two_step_checkbox_disabled(),
2629 2366 'validate_callback' => __CLASS__ . '::validate_boolean',
2630 2367 'jp_group' => 'sso',
2631 2368 ),
2632 - 'jetpack_sso_match_by_email' => array(
2369 + 'jetpack_sso_match_by_email' => array(
2633 2370 'description' => esc_html__( 'Match by Email', 'jetpack' ),
2634 2371 'type' => 'boolean',
2635 2372 'default' => 1,
2636 2373 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2637,9 +2374,9 @@
2637 2374 'jp_group' => 'sso',
2638 2375 ),
2639 2376
2640 2377 // Subscriptions.
2641 - 'stb_enabled' => array(
2378 + 'stb_enabled' => array(
2642 2379 'description' => esc_html__( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ),
2643 2380 'type' => 'boolean',
2644 2381 'default' => 1,
2645 2382 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2644,9 +2381,9 @@
2644 2381 'default' => 1,
2645 2382 'validate_callback' => __CLASS__ . '::validate_boolean',
2646 2383 'jp_group' => 'subscriptions',
2647 2384 ),
2648 - 'stc_enabled' => array(
2385 + 'stc_enabled' => array(
2649 2386 'description' => esc_html__( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ),
2650 2387 'type' => 'boolean',
2651 2388 'default' => 1,
2652 2389 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2651,9 +2388,9 @@
2651 2388 'default' => 1,
2652 2389 'validate_callback' => __CLASS__ . '::validate_boolean',
2653 2390 'jp_group' => 'subscriptions',
2654 2391 ),
2655 - 'wpcom_newsletter_categories' => array(
2392 + 'wpcom_newsletter_categories' => array(
2656 2393 'description' => esc_html__( 'Array of post category ids that are marked as newsletter categories', 'jetpack' ),
2657 2394 'type' => 'array',
2658 2395 'default' => array(),
2659 2396 'validate_callback' => __CLASS__ . '::validate_array',
@@ -2658,9 +2395,9 @@
2658 2395 'default' => array(),
2659 2396 'validate_callback' => __CLASS__ . '::validate_array',
2660 2397 'jp_group' => 'subscriptions',
2661 2398 ),
2662 - 'wpcom_newsletter_categories_enabled' => array(
2399 + 'wpcom_newsletter_categories_enabled' => array(
2663 2400 'description' => esc_html__( 'Whether the newsletter categories are enabled or not', 'jetpack' ),
2664 2401 'type' => 'boolean',
2665 2402 'default' => 0,
2666 2403 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2665,16 +2402,23 @@
2665 2402 'default' => 0,
2666 2403 'validate_callback' => __CLASS__ . '::validate_boolean',
2667 2404 'jp_group' => 'subscriptions',
2668 2405 ),
2669 - 'wpcom_featured_image_in_email' => array(
2406 + 'wpcom_newsletter_send_default' => array(
2407 + 'description' => esc_html__( 'Whether to send newsletter emails by default when publishing a post', 'jetpack' ),
2408 + 'type' => 'boolean',
2409 + 'default' => 1,
2410 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2411 + 'jp_group' => 'subscriptions',
2412 + ),
2413 + 'wpcom_featured_image_in_email' => array(
2670 2414 'description' => esc_html__( 'Whether to include the featured image in the email or not', 'jetpack' ),
2671 2415 'type' => 'boolean',
2672 - 'default' => 1,
2416 + 'default' => 0,
2673 2417 'validate_callback' => __CLASS__ . '::validate_boolean',
2674 2418 'jp_group' => 'subscriptions',
2675 2419 ),
2676 - 'jetpack_gravatar_in_email' => array(
2420 + 'jetpack_gravatar_in_email' => array(
2677 2421 'description' => esc_html__( 'Whether to show author avatar in the email byline', 'jetpack' ),
2678 2422 'type' => 'boolean',
2679 2423 'default' => 1,
2680 2424 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2679,9 +2423,9 @@
2679 2423 'default' => 1,
2680 2424 'validate_callback' => __CLASS__ . '::validate_boolean',
2681 2425 'jp_group' => 'subscriptions',
2682 2426 ),
2683 - 'jetpack_author_in_email' => array(
2427 + 'jetpack_author_in_email' => array(
2684 2428 'description' => esc_html__( 'Whether to show author display name in the email byline', 'jetpack' ),
2685 2429 'type' => 'boolean',
2686 2430 'default' => 1,
2687 2431 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2686,9 +2430,9 @@
2686 2430 'default' => 1,
2687 2431 'validate_callback' => __CLASS__ . '::validate_boolean',
2688 2432 'jp_group' => 'subscriptions',
2689 2433 ),
2690 - 'jetpack_post_date_in_email' => array(
2434 + 'jetpack_post_date_in_email' => array(
2691 2435 'description' => esc_html__( 'Whether to show date in the email byline', 'jetpack' ),
2692 2436 'type' => 'boolean',
2693 2437 'default' => 1,
2694 2438 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2693,9 +2437,9 @@
2693 2437 'default' => 1,
2694 2438 'validate_callback' => __CLASS__ . '::validate_boolean',
2695 2439 'jp_group' => 'subscriptions',
2696 2440 ),
2697 - 'wpcom_subscription_emails_use_excerpt' => array(
2441 + 'wpcom_subscription_emails_use_excerpt' => array(
2698 2442 'description' => esc_html__( 'Whether to use the excerpt in the email or not', 'jetpack' ),
2699 2443 'type' => 'boolean',
2700 2444 'default' => 0,
2701 2445 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2700,16 +2444,16 @@
2700 2444 'default' => 0,
2701 2445 'validate_callback' => __CLASS__ . '::validate_boolean',
2702 2446 'jp_group' => 'subscriptions',
2703 2447 ),
2704 - 'jetpack_subscriptions_reply_to' => array(
2448 + 'jetpack_subscriptions_reply_to' => array(
2705 2449 'description' => esc_html__( 'Reply to email behaviour for newsletters emails', 'jetpack' ),
2706 2450 'type' => 'string',
2707 - 'default' => 'no-reply',
2451 + 'default' => Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to,
2708 2452 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to',
2709 2453 'jp_group' => 'subscriptions',
2710 2454 ),
2711 - 'jetpack_subscriptions_from_name' => array(
2455 + 'jetpack_subscriptions_from_name' => array(
2712 2456 'description' => esc_html__( 'From name for newsletters emails', 'jetpack' ),
2713 2457 'type' => 'string',
2714 2458 'default' => '',
2715 2459 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to_name',
@@ -2714,9 +2458,9 @@
2714 2458 'default' => '',
2715 2459 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to_name',
2716 2460 'jp_group' => 'subscriptions',
2717 2461 ),
2718 - 'sm_enabled' => array(
2462 + 'sm_enabled' => array(
2719 2463 'description' => esc_html__( 'Show popup Subscribe modal to readers.', 'jetpack' ),
2720 2464 'type' => 'boolean',
2721 2465 'default' => 0,
2722 2466 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2721,9 +2465,9 @@
2721 2465 'default' => 0,
2722 2466 'validate_callback' => __CLASS__ . '::validate_boolean',
2723 2467 'jp_group' => 'subscriptions',
2724 2468 ),
2725 - 'jetpack_subscribe_overlay_enabled' => array(
2469 + 'jetpack_subscribe_overlay_enabled' => array(
2726 2470 'description' => esc_html__( 'Show subscribe overlay on homepage.', 'jetpack' ),
2727 2471 'type' => 'boolean',
2728 2472 'default' => 0,
2729 2473 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2728,8 +2472,15 @@
2728 2472 'default' => 0,
2729 2473 'validate_callback' => __CLASS__ . '::validate_boolean',
2730 2474 'jp_group' => 'subscriptions',
2731 2475 ),
2476 + 'jetpack_subscribe_floating_button_enabled' => array(
2477 + 'description' => esc_html__( 'Show a floating subscribe button.', 'jetpack' ),
2478 + 'type' => 'boolean',
2479 + 'default' => 0,
2480 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2481 + 'jp_group' => 'subscriptions',
2482 + ),
2732 2483 'jetpack_subscriptions_subscribe_post_end_enabled' => array(
2733 2484 'description' => esc_html__( 'Add Subscribe block at the end of each post.', 'jetpack' ),
2734 2485 'type' => 'boolean',
2735 2486 'default' => 0,
@@ -2749,9 +2500,9 @@
2749 2500 'default' => 0,
2750 2501 'validate_callback' => __CLASS__ . '::validate_boolean',
2751 2502 'jp_group' => 'subscriptions',
2752 2503 ),
2753 - 'social_notifications_subscribe' => array(
2504 + 'social_notifications_subscribe' => array(
2754 2505 'description' => esc_html__( 'Send email notification when someone subscribes to my blog', 'jetpack' ),
2755 2506 'type' => 'boolean',
2756 2507 'default' => 0,
2757 2508 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2756,15 +2507,18 @@
2756 2507 'default' => 0,
2757 2508 'validate_callback' => __CLASS__ . '::validate_boolean',
2758 2509 'jp_group' => 'subscriptions',
2759 2510 ),
2760 - 'subscription_options' => array(
2761 - 'description' => esc_html__( 'Three options used in subscription email templates: \'invitation\', \'welcome\' and \'comment_follow\'.', 'jetpack' ),
2511 + 'subscription_options' => array(
2512 + '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' ),
2762 2513 'type' => 'object',
2763 2514 'default' => array(
2764 - 'invitation' => '',
2765 - 'welcome' => '',
2766 - 'comment_follow' => '',
2515 + 'invitation' => '',
2516 + 'welcome' => '',
2517 + 'comment_follow' => '',
2518 + 'subscribe_modal_heading' => '',
2519 + 'free_tier_description' => '',
2520 + 'hide_free_tier' => false,
2767 2521 ),
2768 2522 'validate_callback' => __CLASS__ . '::validate_subscription_options',
2769 2523 'jp_group' => 'subscriptions',
2770 2524 ),
@@ -2769,9 +2523,9 @@
2769 2523 'jp_group' => 'subscriptions',
2770 2524 ),
2771 2525
2772 2526 // Related Posts.
2773 - 'show_headline' => array(
2527 + 'show_headline' => array(
2774 2528 'description' => esc_html__( 'Highlight related content with a heading', 'jetpack' ),
2775 2529 'type' => 'boolean',
2776 2530 'default' => 1,
2777 2531 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2776,9 +2530,9 @@
2776 2530 'default' => 1,
2777 2531 'validate_callback' => __CLASS__ . '::validate_boolean',
2778 2532 'jp_group' => 'related-posts',
2779 2533 ),
2780 - 'show_thumbnails' => array(
2534 + 'show_thumbnails' => array(
2781 2535 'description' => esc_html__( 'Show a thumbnail image where available', 'jetpack' ),
2782 2536 'type' => 'boolean',
2783 2537 'default' => 0,
2784 2538 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2785,9 +2539,9 @@
2785 2539 'jp_group' => 'related-posts',
2786 2540 ),
2787 2541
2788 2542 // Search.
2789 - 'instant_search_enabled' => array(
2543 + 'instant_search_enabled' => array(
2790 2544 'description' => esc_html__( 'Enable Instant Search', 'jetpack' ),
2791 2545 'type' => 'boolean',
2792 2546 'default' => 0,
2793 2547 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2793,9 +2547,9 @@
2793 2547 'validate_callback' => __CLASS__ . '::validate_boolean',
2794 2548 'jp_group' => 'search',
2795 2549 ),
2796 2550
2797 - 'has_jetpack_search_product' => array(
2551 + 'has_jetpack_search_product' => array(
2798 2552 'description' => esc_html__( 'Has an active Jetpack Search product purchase', 'jetpack' ),
2799 2553 'type' => 'boolean',
2800 2554 'default' => 0,
2801 2555 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2801,9 +2555,9 @@
2801 2555 'validate_callback' => __CLASS__ . '::validate_boolean',
2802 2556 'jp_group' => 'settings',
2803 2557 ),
2804 2558
2805 - 'search_auto_config' => array(
2559 + 'search_auto_config' => array(
2806 2560 'description' => esc_html__( 'Trigger an auto config of instant search', 'jetpack' ),
2807 2561 'type' => 'boolean',
2808 2562 'default' => 0,
2809 2563 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2810,9 +2564,9 @@
2810 2564 'jp_group' => 'search',
2811 2565 ),
2812 2566
2813 2567 // Verification Tools.
2814 - 'google' => array(
2568 + 'google' => array(
2815 2569 'description' => esc_html__( 'Google Search Console', 'jetpack' ),
2816 2570 'type' => 'string',
2817 2571 'default' => '',
2818 2572 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2817,9 +2571,9 @@
2817 2571 'default' => '',
2818 2572 'validate_callback' => __CLASS__ . '::validate_verification_service',
2819 2573 'jp_group' => 'verification-tools',
2820 2574 ),
2821 - 'bing' => array(
2575 + 'bing' => array(
2822 2576 'description' => esc_html__( 'Bing Webmaster Center', 'jetpack' ),
2823 2577 'type' => 'string',
2824 2578 'default' => '',
2825 2579 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2824,9 +2578,9 @@
2824 2578 'default' => '',
2825 2579 'validate_callback' => __CLASS__ . '::validate_verification_service',
2826 2580 'jp_group' => 'verification-tools',
2827 2581 ),
2828 - 'pinterest' => array(
2582 + 'pinterest' => array(
2829 2583 'description' => esc_html__( 'Pinterest Site Verification', 'jetpack' ),
2830 2584 'type' => 'string',
2831 2585 'default' => '',
2832 2586 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2831,9 +2585,9 @@
2831 2585 'default' => '',
2832 2586 'validate_callback' => __CLASS__ . '::validate_verification_service',
2833 2587 'jp_group' => 'verification-tools',
2834 2588 ),
2835 - 'yandex' => array(
2589 + 'yandex' => array(
2836 2590 'description' => esc_html__( 'Yandex Site Verification', 'jetpack' ),
2837 2591 'type' => 'string',
2838 2592 'default' => '',
2839 2593 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2838,9 +2592,9 @@
2838 2592 'default' => '',
2839 2593 'validate_callback' => __CLASS__ . '::validate_verification_service',
2840 2594 'jp_group' => 'verification-tools',
2841 2595 ),
2842 - 'facebook' => array(
2596 + 'facebook' => array(
2843 2597 'description' => esc_html__( 'Facebook Domain Verification', 'jetpack' ),
2844 2598 'type' => 'string',
2845 2599 'default' => '',
2846 2600 'validate_callback' => __CLASS__ . '::validate_verification_service',
@@ -2847,9 +2601,9 @@
2847 2601 'jp_group' => 'verification-tools',
2848 2602 ),
2849 2603
2850 2604 // WordAds.
2851 - 'enable_header_ad' => array(
2605 + 'enable_header_ad' => array(
2852 2606 'description' => esc_html__( 'Display an ad unit at the top of each page.', 'jetpack' ),
2853 2607 'type' => 'boolean',
2854 2608 'default' => 1,
2855 2609 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2854,9 +2608,9 @@
2854 2608 'default' => 1,
2855 2609 'validate_callback' => __CLASS__ . '::validate_boolean',
2856 2610 'jp_group' => 'wordads',
2857 2611 ),
2858 - 'wordads_approved' => array(
2612 + 'wordads_approved' => array(
2859 2613 'description' => esc_html__( 'Is site approved for WordAds?', 'jetpack' ),
2860 2614 'type' => 'boolean',
2861 2615 'default' => 0,
2862 2616 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2861,9 +2615,9 @@
2861 2615 'default' => 0,
2862 2616 'validate_callback' => __CLASS__ . '::validate_boolean',
2863 2617 'jp_group' => 'wordads',
2864 2618 ),
2865 - 'wordads_second_belowpost' => array(
2619 + 'wordads_second_belowpost' => array(
2866 2620 'description' => esc_html__( 'Display second ad below post?', 'jetpack' ),
2867 2621 'type' => 'boolean',
2868 2622 'default' => 1,
2869 2623 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2868,9 +2622,9 @@
2868 2622 'default' => 1,
2869 2623 'validate_callback' => __CLASS__ . '::validate_boolean',
2870 2624 'jp_group' => 'wordads',
2871 2625 ),
2872 - 'wordads_inline_enabled' => array(
2626 + 'wordads_inline_enabled' => array(
2873 2627 'description' => esc_html__( 'Display inline ad within post content?', 'jetpack' ),
2874 2628 'type' => 'boolean',
2875 2629 'default' => 1,
2876 2630 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2875,9 +2629,9 @@
2875 2629 'default' => 1,
2876 2630 'validate_callback' => __CLASS__ . '::validate_boolean',
2877 2631 'jp_group' => 'wordads',
2878 2632 ),
2879 - 'wordads_display_front_page' => array(
2633 + 'wordads_display_front_page' => array(
2880 2634 'description' => esc_html__( 'Display ads on the front page?', 'jetpack' ),
2881 2635 'type' => 'boolean',
2882 2636 'default' => 1,
2883 2637 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2882,9 +2636,9 @@
2882 2636 'default' => 1,
2883 2637 'validate_callback' => __CLASS__ . '::validate_boolean',
2884 2638 'jp_group' => 'wordads',
2885 2639 ),
2886 - 'wordads_display_post' => array(
2640 + 'wordads_display_post' => array(
2887 2641 'description' => esc_html__( 'Display ads on posts?', 'jetpack' ),
2888 2642 'type' => 'boolean',
2889 2643 'default' => 1,
2890 2644 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2889,9 +2643,9 @@
2889 2643 'default' => 1,
2890 2644 'validate_callback' => __CLASS__ . '::validate_boolean',
2891 2645 'jp_group' => 'wordads',
2892 2646 ),
2893 - 'wordads_display_page' => array(
2647 + 'wordads_display_page' => array(
2894 2648 'description' => esc_html__( 'Display ads on pages?', 'jetpack' ),
2895 2649 'type' => 'boolean',
2896 2650 'default' => 1,
2897 2651 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2896,9 +2650,9 @@
2896 2650 'default' => 1,
2897 2651 'validate_callback' => __CLASS__ . '::validate_boolean',
2898 2652 'jp_group' => 'wordads',
2899 2653 ),
2900 - 'wordads_display_archive' => array(
2654 + 'wordads_display_archive' => array(
2901 2655 'description' => esc_html__( 'Display ads on archive pages?', 'jetpack' ),
2902 2656 'type' => 'boolean',
2903 2657 'default' => 1,
2904 2658 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2903,9 +2657,9 @@
2903 2657 'default' => 1,
2904 2658 'validate_callback' => __CLASS__ . '::validate_boolean',
2905 2659 'jp_group' => 'wordads',
2906 2660 ),
2907 - 'wordads_custom_adstxt_enabled' => array(
2661 + 'wordads_custom_adstxt_enabled' => array(
2908 2662 'description' => esc_html__( 'Custom ads.txt', 'jetpack' ),
2909 2663 'type' => 'boolean',
2910 2664 'default' => 0,
2911 2665 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2910,9 +2664,9 @@
2910 2664 'default' => 0,
2911 2665 'validate_callback' => __CLASS__ . '::validate_boolean',
2912 2666 'jp_group' => 'wordads',
2913 2667 ),
2914 - 'wordads_custom_adstxt' => array(
2668 + 'wordads_custom_adstxt' => array(
2915 2669 'description' => esc_html__( 'Custom ads.txt entries', 'jetpack' ),
2916 2670 'type' => 'string',
2917 2671 'default' => '',
2918 2672 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2918,9 +2672,9 @@
2918 2672 'validate_callback' => __CLASS__ . '::validate_string',
2919 2673 'sanitize_callback' => 'sanitize_textarea_field',
2920 2674 'jp_group' => 'wordads',
2921 2675 ),
2922 - 'wordads_ccpa_enabled' => array(
2676 + 'wordads_ccpa_enabled' => array(
2923 2677 'description' => esc_html__( 'Enable support for California Consumer Privacy Act', 'jetpack' ),
2924 2678 'type' => 'boolean',
2925 2679 'default' => 0,
2926 2680 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2925,9 +2679,9 @@
2925 2679 'default' => 0,
2926 2680 'validate_callback' => __CLASS__ . '::validate_boolean',
2927 2681 'jp_group' => 'wordads',
2928 2682 ),
2929 - 'wordads_ccpa_privacy_policy_url' => array(
2683 + 'wordads_ccpa_privacy_policy_url' => array(
2930 2684 'description' => esc_html__( 'Privacy Policy URL', 'jetpack' ),
2931 2685 'type' => 'string',
2932 2686 'default' => '',
2933 2687 'validate_callback' => __CLASS__ . '::validate_string',
@@ -2933,9 +2687,9 @@
2933 2687 'validate_callback' => __CLASS__ . '::validate_string',
2934 2688 'sanitize_callback' => 'sanitize_text_field',
2935 2689 'jp_group' => 'wordads',
2936 2690 ),
2937 - 'wordads_cmp_enabled' => array(
2691 + 'wordads_cmp_enabled' => array(
2938 2692 'description' => esc_html__( 'Enable GDPR Consent Management Banner for WordAds', 'jetpack' ),
2939 2693 'type' => 'boolean',
2940 2694 'default' => 0,
2941 2695 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2942,9 +2696,9 @@
2942 2696 'jp_group' => 'wordads',
2943 2697 ),
2944 2698
2945 2699 // Google Analytics.
2946 - 'google_analytics_tracking_id' => array(
2700 + 'google_analytics_tracking_id' => array(
2947 2701 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2948 2702 'type' => 'string',
2949 2703 'default' => '',
2950 2704 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -2949,11 +2703,16 @@
2949 2703 'default' => '',
2950 2704 'validate_callback' => __CLASS__ . '::validate_alphanum',
2951 2705 'jp_group' => 'google-analytics',
2952 2706 ),
2707 + 'jetpack_wga' => array(
2708 + 'description' => esc_html__( 'Google Analytics', 'jetpack' ),
2709 + 'type' => 'object',
2710 + 'jp_group' => 'settings',
2711 + ),
2953 2712
2954 2713 // Stats.
2955 - 'admin_bar' => array(
2714 + 'admin_bar' => array(
2956 2715 'description' => esc_html__( 'Include a small chart in your admin bar with a 48-hour traffic snapshot.', 'jetpack' ),
2957 2716 'type' => 'boolean',
2958 2717 'default' => 1,
2959 2718 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2958,9 +2717,9 @@
2958 2717 'default' => 1,
2959 2718 'validate_callback' => __CLASS__ . '::validate_boolean',
2960 2719 'jp_group' => 'stats',
2961 2720 ),
2962 - 'enable_odyssey_stats' => array(
2721 + 'enable_odyssey_stats' => array(
2963 2722 'description' => esc_html__( 'Preview the new Jetpack Stats experience (Experimental).', 'jetpack' ),
2964 2723 'type' => 'boolean',
2965 2724 'default' => 1,
2966 2725 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2965,9 +2724,9 @@
2965 2724 'default' => 1,
2966 2725 'validate_callback' => __CLASS__ . '::validate_boolean',
2967 2726 'jp_group' => 'stats',
2968 2727 ),
2969 - 'roles' => array(
2728 + 'roles' => array(
2970 2729 'description' => esc_html__( 'Select the roles that will be able to view stats reports.', 'jetpack' ),
2971 2730 'type' => 'array',
2972 2731 'items' => array(
2973 2732 'type' => 'string',
@@ -2976,9 +2735,9 @@
2976 2735 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2977 2736 'sanitize_callback' => __CLASS__ . '::sanitize_stats_allowed_roles',
2978 2737 'jp_group' => 'stats',
2979 2738 ),
2980 - 'count_roles' => array(
2739 + 'count_roles' => array(
2981 2740 'description' => esc_html__( 'Count the page views of registered users who are logged in.', 'jetpack' ),
2982 2741 'type' => 'array',
2983 2742 'items' => array(
2984 2743 'type' => 'string',
@@ -2986,9 +2745,9 @@
2986 2745 'default' => array( 'administrator' ),
2987 2746 'validate_callback' => __CLASS__ . '::validate_stats_roles',
2988 2747 'jp_group' => 'stats',
2989 2748 ),
2990 - 'blog_id' => array(
2749 + 'blog_id' => array(
2991 2750 'description' => esc_html__( 'Blog ID.', 'jetpack' ),
2992 2751 'type' => 'boolean',
2993 2752 'default' => 0,
2994 2753 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -2993,9 +2752,9 @@
2993 2752 'default' => 0,
2994 2753 'validate_callback' => __CLASS__ . '::validate_boolean',
2995 2754 'jp_group' => 'stats',
2996 2755 ),
2997 - 'do_not_track' => array(
2756 + 'do_not_track' => array(
2998 2757 'description' => esc_html__( 'Do not track.', 'jetpack' ),
2999 2758 'type' => 'boolean',
3000 2759 'default' => 1,
3001 2760 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3000,9 +2759,9 @@
3000 2759 'default' => 1,
3001 2760 'validate_callback' => __CLASS__ . '::validate_boolean',
3002 2761 'jp_group' => 'stats',
3003 2762 ),
3004 - 'version' => array(
2763 + 'version' => array(
3005 2764 'description' => esc_html__( 'Version.', 'jetpack' ),
3006 2765 'type' => 'integer',
3007 2766 'default' => 9,
3008 2767 'validate_callback' => __CLASS__ . '::validate_posint',
@@ -3007,9 +2766,9 @@
3007 2766 'default' => 9,
3008 2767 'validate_callback' => __CLASS__ . '::validate_posint',
3009 2768 'jp_group' => 'stats',
3010 2769 ),
3011 - 'collapse_nudges' => array(
2770 + 'collapse_nudges' => array(
3012 2771 'description' => esc_html__( 'Collapse upgrade nudges', 'jetpack' ),
3013 2772 'type' => 'boolean',
3014 2773 'default' => 0,
3015 2774 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3016,9 +2775,9 @@
3016 2775 'jp_group' => 'stats',
3017 2776 ),
3018 2777
3019 2778 // Whether to share stats views with WordPress.com Reader.
3020 - 'wpcom_reader_views_enabled' => array(
2779 + 'wpcom_reader_views_enabled' => array(
3021 2780 'description' => esc_html__( 'Show post views in the WordPress.com Reader.', 'jetpack' ),
3022 2781 'type' => 'boolean',
3023 2782 'default' => 1,
3024 2783 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3025,9 +2784,9 @@
3025 2784 'jp_group' => 'settings',
3026 2785 ),
3027 2786
3028 2787 // Akismet - Not a module, but a plugin. The options can be passed and handled differently.
3029 - 'akismet_show_user_comments_approved' => array(
2788 + 'akismet_show_user_comments_approved' => array(
3030 2789 'description' => '',
3031 2790 'type' => 'boolean',
3032 2791 'default' => 0,
3033 2792 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3033,9 +2792,9 @@
3033 2792 'validate_callback' => __CLASS__ . '::validate_boolean',
3034 2793 'jp_group' => 'settings',
3035 2794 ),
3036 2795
3037 - 'wordpress_api_key' => array(
2796 + 'wordpress_api_key' => array(
3038 2797 'description' => '',
3039 2798 'type' => 'string',
3040 2799 'default' => '',
3041 2800 'validate_callback' => __CLASS__ . '::validate_alphanum',
@@ -3042,9 +2801,9 @@
3042 2801 'jp_group' => 'settings',
3043 2802 ),
3044 2803
3045 2804 // Empty stats card dismiss.
3046 - 'dismiss_empty_stats_card' => array(
2805 + 'dismiss_empty_stats_card' => array(
3047 2806 'description' => '',
3048 2807 'type' => 'boolean',
3049 2808 'default' => 0,
3050 2809 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3051,9 +2810,9 @@
3051 2810 'jp_group' => 'settings',
3052 2811 ),
3053 2812
3054 2813 // Backup Getting Started card on dashboard.
3055 - 'dismiss_dash_backup_getting_started' => array(
2814 + 'dismiss_dash_backup_getting_started' => array(
3056 2815 'description' => '',
3057 2816 'type' => 'boolean',
3058 2817 'default' => 0,
3059 2818 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3060,9 +2819,9 @@
3060 2819 'jp_group' => 'settings',
3061 2820 ),
3062 2821
3063 2822 // Agencies Learn More card on dashboard.
3064 - 'dismiss_dash_agencies_learn_more' => array(
2823 + 'dismiss_dash_agencies_learn_more' => array(
3065 2824 'description' => '',
3066 2825 'type' => 'boolean',
3067 2826 'default' => 0,
3068 2827 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3068,9 +2827,9 @@
3068 2827 'validate_callback' => __CLASS__ . '::validate_boolean',
3069 2828 'jp_group' => 'settings',
3070 2829 ),
3071 2830
3072 - 'lang_id' => array(
2831 + 'lang_id' => array(
3073 2832 'description' => esc_html__( 'Primary language for the site.', 'jetpack' ),
3074 2833 'type' => 'string',
3075 2834 'default' => 'en_US',
3076 2835 'jp_group' => 'settings',
@@ -3076,9 +2835,9 @@
3076 2835 'jp_group' => 'settings',
3077 2836 ),
3078 2837
3079 2838 // SEO Tools.
3080 - 'advanced_seo_front_page_description' => array(
2839 + 'advanced_seo_front_page_description' => array(
3081 2840 'description' => esc_html__( 'Front page meta description.', 'jetpack' ),
3082 2841 'type' => 'string',
3083 2842 'default' => '',
3084 2843 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
@@ -3084,9 +2843,9 @@
3084 2843 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description',
3085 2844 'jp_group' => 'seo-tools',
3086 2845 ),
3087 2846
3088 - 'advanced_seo_title_formats' => array(
2847 + 'advanced_seo_title_formats' => array(
3089 2848 'description' => esc_html__( 'SEO page title structures.', 'jetpack' ),
3090 2849 'type' => 'object',
3091 2850 'default' => array(
3092 2851 'archives' => array(),
@@ -3099,10 +2858,34 @@
3099 2858 'validate_callback' => 'Jetpack_SEO_Titles::are_valid_title_formats',
3100 2859 'sanitize_callback' => 'Jetpack_SEO_Titles::sanitize_title_formats',
3101 2860 ),
3102 2861
2862 + // AI tab (Jetpack > SEO). Plain option the SEO package reads to serve
2863 + // /llms.txt. The front-end behavior is gated inside the package; this
2864 + // only round-trips the persisted state alongside the other seo-tools
2865 + // settings.
2866 + 'jetpack_seo_llms_txt_enabled' => array(
2867 + 'description' => esc_html__( 'Generate an llms.txt file to guide AI assistants around your content.', 'jetpack' ),
2868 + 'type' => 'boolean',
2869 + 'default' => 0,
2870 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2871 + 'jp_group' => 'seo-tools',
2872 + ),
2873 +
2874 + // AI tab (Jetpack > SEO). Sparse per-crawler override map the SEO
2875 + // package reads to emit robots.txt directives for blocked AI crawlers.
2876 + // Stored as `slug => bool` (true = blocked); catalog validation and
2877 + // default-pruning happen in `Ai_Crawlers::get_overrides()`.
2878 + 'jetpack_seo_ai_crawler_overrides' => array(
2879 + 'description' => esc_html__( 'AI crawler allow/block overrides.', 'jetpack' ),
2880 + 'type' => 'object',
2881 + 'default' => array(),
2882 + 'jp_group' => 'seo-tools',
2883 + 'sanitize_callback' => __CLASS__ . '::sanitize_ai_crawler_overrides',
2884 + ),
2885 +
3103 2886 // VideoPress.
3104 - 'videopress_private_enabled_for_site' => array(
2887 + 'videopress_private_enabled_for_site' => array(
3105 2888 'description' => esc_html__( 'Video Privacy: Restrict views to members of this site', 'jetpack' ),
3106 2889 'type' => 'boolean',
3107 2890 'default' => 0,
3108 2891 'validate_callback' => __CLASS__ . '::validate_boolean',
@@ -3109,8 +2892,21 @@
3109 2892 'jp_group' => 'videopress',
3110 2893 ),
3111 2894 );
3112 2895
2896 + // SEO Tools - SEO Enhancer.
2897 + // TODO: move this to the main options array? The filter was there while developing the feature.
2898 + // It might come in handy to hold its availability behind the filter since it still depends on AI to be available.
2899 + if ( apply_filters( 'ai_seo_enhancer_enabled', true ) ) {
2900 + $options['ai_seo_enhancer_enabled'] = array(
2901 + 'description' => esc_html__( 'Automatically generate SEO title, SEO description, and image alt text for new posts.', 'jetpack' ),
2902 + 'type' => 'boolean',
2903 + 'default' => 0,
2904 + 'validate_callback' => __CLASS__ . '::validate_boolean',
2905 + 'jp_group' => 'seo-tools',
2906 + );
2907 + }
2908 +
3113 2909 // Add modules to list so they can be toggled.
3114 2910 $modules = Jetpack::get_available_modules();
3115 2911 if ( is_array( $modules ) && ! empty( $modules ) ) {
3116 2912 $module_args = array(
@@ -3381,9 +3177,9 @@
3381 3177 * Validates that the parameter is among the roles allowed for Stats.
3382 3178 *
3383 3179 * @since 4.3.0
3384 3180 *
3385 - * @param string|bool $value Value to check.
3181 + * @param mixed $value Value to check.
3386 3182 * @param WP_REST_Request $request The request sent to the WP REST API.
3387 3183 * @param string $param Name of the parameter passed to endpoint holding $value.
3388 3184 *
3389 3185 * @return bool|WP_Error
@@ -3388,16 +3184,37 @@
3388 3184 *
3389 3185 * @return bool|WP_Error
3390 3186 */
3391 3187 public static function validate_stats_roles( $value, $request, $param ) {
3392 - if ( ! empty( $value ) && ! array_intersect( self::$stats_roles, $value ) ) {
3188 + // An empty value clears the setting; sanitize_stats_allowed_roles() falls back to 'administrator'.
3189 + if ( empty( $value ) ) {
3190 + return true;
3191 + }
3192 +
3193 + // Enforce the schema's list-of-strings contract before array_intersect() below sees the value.
3194 + if ( ! is_array( $value ) || count( array_filter( $value, 'is_string' ) ) !== count( $value ) ) {
3393 3195 return new WP_Error(
3394 3196 'invalid_param',
3395 3197 sprintf(
3198 + /* Translators: Placeholder is a parameter name. */
3199 + esc_html__( '%s must be an array of user roles.', 'jetpack' ),
3200 + $param
3201 + )
3202 + );
3203 + }
3204 +
3205 + if ( ! function_exists( 'get_editable_roles' ) ) {
3206 + require_once ABSPATH . 'wp-admin/includes/user.php';
3207 + }
3208 + $editable_roles = array_keys( get_editable_roles() );
3209 + if ( ! array_intersect( $editable_roles, $value ) ) {
3210 + return new WP_Error(
3211 + 'invalid_param',
3212 + sprintf(
3396 3213 /* 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. */
3397 3214 esc_html__( '%1$s must be %2$s.', 'jetpack' ),
3398 3215 $param,
3399 - implode( ', ', self::$stats_roles )
3216 + implode( ', ', $editable_roles )
3400 3217 )
3401 3218 );
3402 3219 }
3403 3220 return true;
@@ -3714,9 +3531,12 @@
3714 3531 *
3715 3532 * @return bool|WP_Error
3716 3533 */
3717 3534 public static function validate_subscription_options( $values ) {
3718 - if ( is_object( $values ) ) {
3535 + // A REST "object" decodes to a PHP associative array. Reject any other
3536 + // type (object, string, int, null, ...) up front so the array_keys()
3537 + // loop below never runs against a non-array and triggers a PHP warning.
3538 + if ( ! is_array( $values ) ) {
3719 3539 return new WP_Error(
3720 3540 'invalid_param',
3721 3541 /* Translators: subscription_options is a variable name, and shouldn't be translated. */
3722 3542 esc_html__( 'subscription_options must be an object.', 'jetpack' )
@@ -3722,9 +3542,9 @@
3722 3542 esc_html__( 'subscription_options must be an object.', 'jetpack' )
3723 3543 );
3724 3544 }
3725 3545 foreach ( array_keys( $values ) as $key ) {
3726 - if ( ! in_array( $key, array( 'welcome', 'invitation', 'comment_follow' ), true ) ) {
3546 + if ( ! in_array( $key, array( 'welcome', 'invitation', 'comment_follow', 'subscribe_modal_heading', 'free_tier_description', 'hide_free_tier' ), true ) ) {
3727 3547 return new WP_Error(
3728 3548 'invalid_param',
3729 3549 sprintf(
3730 3550 /* Translators: Placeholder is the invalid param being sent. */
@@ -3765,11 +3585,11 @@
3765 3585 * return an array with only 'administrator' as the allowed role and save it for 'roles' option.
3766 3586 *
3767 3587 * @since 4.3.0
3768 3588 *
3769 - * @param string|bool $value Value to check.
3589 + * @param mixed $value Value to check.
3770 3590 *
3771 - * @return bool|array
3591 + * @return mixed The value as submitted, or an array holding only 'administrator' when it is empty.
3772 3592 */
3773 3593 public static function sanitize_stats_allowed_roles( $value ) {
3774 3594 if ( empty( $value ) ) {
3775 3595 return array( 'administrator' );
@@ -3777,8 +3597,31 @@
3777 3597 return $value;
3778 3598 }
3779 3599
3780 3600 /**
3601 + * Sanitize the AI crawler override map.
3602 + *
3603 + * Keeps the value package-agnostic: each key is normalized with sanitize_key()
3604 + * and each value cast to bool. Catalog validation and default-pruning happen in
3605 + * `Automattic\Jetpack\SEO\Ai_Crawlers::get_overrides()`.
3606 + *
3607 + * @param mixed $value The submitted override map.
3608 + *
3609 + * @return array<string, bool> Sanitized `slug => bool` map.
3610 + */
3611 + public static function sanitize_ai_crawler_overrides( $value ) {
3612 + if ( ! is_array( $value ) ) {
3613 + return array();
3614 + }
3615 +
3616 + $sanitized = array();
3617 + foreach ( $value as $k => $v ) {
3618 + $sanitized[ sanitize_key( $k ) ] = (bool) $v;
3619 + }
3620 + return $sanitized;
3621 + }
3622 +
3623 + /**
3781 3624 * Get the currently accessed route and return the module slug in it.
3782 3625 *
3783 3626 * @since 4.3.0
3784 3627 *
@@ -3787,9 +3630,9 @@
3787 3630 * @return array|string
3788 3631 */
3789 3632 public static function get_module_requested( $route = '/module/(?P<slug>[a-z\-]+)' ) {
3790 3633
3791 - if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
3634 + if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) || ! is_string( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
3792 3635 return '';
3793 3636 }
3794 3637
3795 3638 preg_match( "#$route#", $GLOBALS['wp']->query_vars['rest_route'], $module );
@@ -3840,8 +3683,40 @@
3840 3683 return $modules;
3841 3684 }
3842 3685
3843 3686 /**
3687 + * Remove options the current user cannot read.
3688 + *
3689 + * Covers every `jetpack_waf_*` option, plus the two Protect options that expose the
3690 + * same data under a different name: `jetpack_protect_global_whitelist` is populated
3691 + * from `jetpack_waf_ip_allow_list`, and `jetpack_protect_key` is a shared secret.
3692 + *
3693 + * @since 16.2
3694 + *
3695 + * @param array $options Option definitions keyed by option name.
3696 + * @return array
3697 + */
3698 + public static function filter_options_for_response( $options ) {
3699 + if ( current_user_can( 'manage_options' ) ) {
3700 + return $options;
3701 + }
3702 +
3703 + $restricted = array(
3704 + 'jetpack_protect_key',
3705 + 'jetpack_protect_global_whitelist',
3706 + );
3707 +
3708 + return array_filter(
3709 + $options,
3710 + static function ( $option_name ) use ( $restricted ) {
3711 + return 0 !== strpos( $option_name, 'jetpack_waf_' )
3712 + && ! in_array( $option_name, $restricted, true );
3713 + },
3714 + ARRAY_FILTER_USE_KEY
3715 + );
3716 + }
3717 +
3718 + /**
3844 3719 * Remove 'validate_callback' item from options available for module.
3845 3720 * Fetch current option value and add to array of module options.
3846 3721 * Prepare values of module options that need special handling, like those saved in wpcom.
3847 3722 *
@@ -3904,9 +3779,9 @@
3904 3779 $options = self::split_options( $options, $sharer->get_global_options() );
3905 3780 $options['sharing_services']['current_value'] = $sharer->get_blog_services();
3906 3781 $other_sharedaddy_options = array( 'jetpack-twitter-cards-site-tag', 'sharedaddy_disable_resources', 'sharing_delete_service' );
3907 3782 foreach ( $other_sharedaddy_options as $key ) {
3908 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3783 + $default_value = $options[ $key ]['default'] ?? '';
3909 3784 $current_value = get_option( $key, $default_value );
3910 3785 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3911 3786 }
3912 3787 break;
@@ -3917,9 +3792,9 @@
3917 3792 break;
3918 3793 default:
3919 3794 // These option are just stored as plain WordPress options.
3920 3795 foreach ( $options as $key => $value ) {
3921 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3796 + $default_value = $options[ $key ]['default'] ?? '';
3922 3797 $current_value = get_option( $key, $default_value );
3923 3798 $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] );
3924 3799 }
3925 3800 }
@@ -3929,14 +3804,17 @@
3929 3804 // We don't need validate_callback in the response.
3930 3805 if ( isset( $options[ $key ]['validate_callback'] ) ) {
3931 3806 unset( $options[ $key ]['validate_callback'] );
3932 3807 }
3933 - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : '';
3808 + $default_value = $options[ $key ]['default'] ?? '';
3934 3809 if ( ! array_key_exists( 'current_value', $options[ $key ] ) ) {
3935 3810 $options[ $key ]['current_value'] = self::cast_value( $default_value, $options[ $key ] );
3936 3811 }
3937 3812 }
3938 - return $options;
3813 +
3814 + // Filter last: the switch above assigns current_value by key without isset(),
3815 + // so filtering earlier would let those assignments re-add a removed option.
3816 + return self::filter_options_for_response( $options );
3939 3817 }
3940 3818
3941 3819 /**
3942 3820 * Splits module options saved as arrays like relatedposts or verification_services_codes into separate options to be returned in the response.