| @@ -8,9 +8,10 @@ | ||
| 8 | 8 | use Automattic\Jetpack\Connection\Client; |
| 9 | 9 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 10 | 10 | use Automattic\Jetpack\Connection\Rest_Authentication; |
| 11 | 11 | use Automattic\Jetpack\Connection\REST_Connector; |
| 12 | -use Automattic\Jetpack\Current_Plan as Jetpack_Plan; | |
| 12 | +use Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT; | |
| 13 | +use Automattic\Jetpack\Connection\SSO; | |
| 13 | 14 | use Automattic\Jetpack\Jetpack_CRM_Data; |
| 14 | 15 | use Automattic\Jetpack\Plugins_Installer; |
| 15 | 16 | use Automattic\Jetpack\Stats\Options as Stats_Options; |
| 16 | 17 | use Automattic\Jetpack\Status\Host; |
| @@ -19,9 +20,9 @@ | ||
| 19 | 20 | use Automattic\Jetpack\Waf\Waf_Compatibility; |
| 20 | 21 | |
| 21 | 22 | // Disable direct access. |
| 22 | 23 | if ( ! defined( 'ABSPATH' ) ) { |
| 23 | - exit; | |
| 24 | + exit( 0 ); | |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | 27 | // Load WP_Error for error messages. |
| 27 | 28 | require_once ABSPATH . '/wp-includes/class-wp-error.php'; |
| @@ -31,8 +32,10 @@ | ||
| 31 | 32 | // Load API endpoints that are synced with WP.com |
| 32 | 33 | // Each of these is a class that will register its own routes on 'rest_api_init'. |
| 33 | 34 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/load-wpcom-endpoints.php'; |
| 34 | 35 | |
| 36 | +require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php'; | |
| 37 | + | |
| 35 | 38 | /** |
| 36 | 39 | * Class Jetpack_Core_Json_Api_Endpoints |
| 37 | 40 | * |
| 38 | 41 | * @since 4.3.0 |
| @@ -69,23 +72,10 @@ | ||
| 69 | 72 | $module_toggle_endpoint = new Jetpack_Core_API_Module_Toggle_Endpoint( new Jetpack_IXR_Client() ); |
| 70 | 73 | $site_endpoint = new Jetpack_Core_API_Site_Endpoint(); |
| 71 | 74 | $widget_endpoint = new Jetpack_Core_API_Widget_Endpoint(); |
| 72 | 75 | |
| 73 | - /** | |
| 74 | - * TODO: Move me somewhere that makes more sense. | |
| 75 | - * Also give me permissions that aren't awful. | |
| 76 | - */ | |
| 77 | - register_rest_route( | |
| 78 | - 'jetpack/v4', | |
| 79 | - 'jetpack-ai-jwt', | |
| 80 | - array( | |
| 81 | - 'methods' => WP_REST_Server::EDITABLE, | |
| 82 | - 'callback' => __CLASS__ . '::get_openai_jwt', | |
| 83 | - 'permission_callback' => function () { | |
| 84 | - return ( new Connection_Manager( 'jetpack' ) )->is_user_connected() && current_user_can( 'edit_posts' ); | |
| 85 | - }, | |
| 86 | - ) | |
| 87 | - ); | |
| 76 | + // My Jetpack and Agents Manager register the same controller; its guard keeps the route registered once. | |
| 77 | + ( new REST_Jetpack_AI_JWT() )->register_rest_route(); | |
| 88 | 78 | |
| 89 | 79 | register_rest_route( |
| 90 | 80 | 'jetpack/v4', |
| 91 | 81 | 'plans', |
| @@ -115,32 +105,10 @@ | ||
| 115 | 105 | 'permission_callback' => __CLASS__ . '::disconnect_site_permission_callback', |
| 116 | 106 | ) |
| 117 | 107 | ); |
| 118 | 108 | |
| 119 | - // Test current connection status of Jetpack. | |
| 120 | 109 | register_rest_route( |
| 121 | 110 | 'jetpack/v4', |
| 122 | - '/connection/test', | |
| 123 | - array( | |
| 124 | - 'methods' => WP_REST_Server::READABLE, | |
| 125 | - 'callback' => __CLASS__ . '::jetpack_connection_test', | |
| 126 | - 'permission_callback' => __CLASS__ . '::manage_modules_permission_check', | |
| 127 | - ) | |
| 128 | - ); | |
| 129 | - | |
| 130 | - // Endpoint specific for privileged servers to request detailed debug information. | |
| 131 | - register_rest_route( | |
| 132 | - 'jetpack/v4', | |
| 133 | - '/connection/test-wpcom/', | |
| 134 | - array( | |
| 135 | - 'methods' => WP_REST_Server::READABLE, | |
| 136 | - 'callback' => __CLASS__ . '::jetpack_connection_test_for_external', | |
| 137 | - 'permission_callback' => __CLASS__ . '::view_jetpack_connection_test_check', | |
| 138 | - ) | |
| 139 | - ); | |
| 140 | - | |
| 141 | - register_rest_route( | |
| 142 | - 'jetpack/v4', | |
| 143 | 111 | '/rewind', |
| 144 | 112 | array( |
| 145 | 113 | 'methods' => WP_REST_Server::READABLE, |
| 146 | 114 | 'callback' => __CLASS__ . '::get_rewind_data', |
| @@ -193,33 +161,11 @@ | ||
| 193 | 161 | ), |
| 194 | 162 | ) |
| 195 | 163 | ); |
| 196 | 164 | |
| 197 | - // Disconnect/unlink user from WordPress.com servers. | |
| 165 | + // Get current site features. | |
| 198 | 166 | register_rest_route( |
| 199 | 167 | 'jetpack/v4', |
| 200 | - '/connection/user', | |
| 201 | - array( | |
| 202 | - 'methods' => WP_REST_Server::EDITABLE, | |
| 203 | - 'callback' => __CLASS__ . '::unlink_user', | |
| 204 | - 'permission_callback' => __CLASS__ . '::unlink_user_permission_callback', | |
| 205 | - ) | |
| 206 | - ); | |
| 207 | - | |
| 208 | - // Get current site data. | |
| 209 | - register_rest_route( | |
| 210 | - 'jetpack/v4', | |
| 211 | - '/site', | |
| 212 | - array( | |
| 213 | - 'methods' => WP_REST_Server::READABLE, | |
| 214 | - 'callback' => __CLASS__ . '::get_site_data', | |
| 215 | - 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check', | |
| 216 | - ) | |
| 217 | - ); | |
| 218 | - | |
| 219 | - // Get current site data. | |
| 220 | - register_rest_route( | |
| 221 | - 'jetpack/v4', | |
| 222 | 168 | '/site/features', |
| 223 | 169 | array( |
| 224 | 170 | 'methods' => WP_REST_Server::READABLE, |
| 225 | 171 | 'callback' => array( $site_endpoint, 'get_features' ), |
| @@ -764,42 +710,108 @@ | ||
| 764 | 710 | 'callback' => __CLASS__ . '::get_intro_offers', |
| 765 | 711 | 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check', |
| 766 | 712 | ) |
| 767 | 713 | ); |
| 714 | + | |
| 715 | + // Save subscriber token and redirect | |
| 716 | + register_rest_route( | |
| 717 | + 'jetpack/v4', | |
| 718 | + '/subscribers/auth', | |
| 719 | + array( | |
| 720 | + 'methods' => WP_REST_Server::READABLE, | |
| 721 | + 'callback' => __CLASS__ . '::set_subscriber_cookie_and_redirect', | |
| 722 | + 'permission_callback' => '__return_true', | |
| 723 | + 'args' => array( | |
| 724 | + 'redirect_url' => array( | |
| 725 | + 'required' => true, | |
| 726 | + 'description' => __( 'The URL to redirect to.', 'jetpack' ), | |
| 727 | + 'validate_callback' => 'wp_http_validate_url', | |
| 728 | + 'sanitize_callback' => 'sanitize_url', | |
| 729 | + 'type' => 'string', | |
| 730 | + 'format' => 'uri', | |
| 731 | + ), | |
| 732 | + ), | |
| 733 | + ) | |
| 734 | + ); | |
| 735 | + | |
| 736 | + /** | |
| 737 | + * Get the list of available Jetpack features. | |
| 738 | + * | |
| 739 | + * @since 13.9 | |
| 740 | + */ | |
| 741 | + register_rest_route( | |
| 742 | + 'jetpack/v4', | |
| 743 | + '/features/available', | |
| 744 | + array( | |
| 745 | + 'methods' => WP_REST_Server::READABLE, | |
| 746 | + 'callback' => array( static::class, 'get_features_available' ), | |
| 747 | + 'permission_callback' => array( static::class, 'get_features_permission_check' ), | |
| 748 | + ) | |
| 749 | + ); | |
| 750 | + | |
| 751 | + /** | |
| 752 | + * Get the list of enabled Jetpack features. | |
| 753 | + * | |
| 754 | + * @since 13.9 | |
| 755 | + */ | |
| 756 | + register_rest_route( | |
| 757 | + 'jetpack/v4', | |
| 758 | + '/features/enabled', | |
| 759 | + array( | |
| 760 | + 'methods' => WP_REST_Server::READABLE, | |
| 761 | + 'callback' => array( static::class, 'get_features_enabled' ), | |
| 762 | + 'permission_callback' => array( static::class, 'get_features_permission_check' ), | |
| 763 | + ) | |
| 764 | + ); | |
| 768 | 765 | } |
| 769 | 766 | |
| 770 | 767 | /** |
| 771 | 768 | * Ask WPCOM for a JWT token to use for OpenAI conversations. |
| 772 | - * 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. | |
| 773 | 774 | */ |
| 774 | 775 | public static function get_openai_jwt() { |
| 775 | - $blog_id = \Jetpack_Options::get_option( 'id' ); | |
| 776 | + _deprecated_function( __METHOD__, 'jetpack-16.2', '\Automattic\Jetpack\Connection\REST_Jetpack_AI_JWT::get_jwt' ); | |
| 776 | 777 | |
| 777 | - $response = \Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user( | |
| 778 | - "/sites/$blog_id/jetpack-openai-query/jwt", | |
| 779 | - '2', | |
| 780 | - array( | |
| 781 | - 'method' => 'POST', | |
| 782 | - 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ), | |
| 783 | - ), | |
| 784 | - wp_json_encode( array() ), | |
| 785 | - 'wpcom' | |
| 786 | - ); | |
| 778 | + $response = ( new REST_Jetpack_AI_JWT() )->get_jwt(); | |
| 787 | 779 | |
| 788 | 780 | if ( is_wp_error( $response ) ) { |
| 789 | 781 | return $response; |
| 790 | 782 | } |
| 791 | 783 | |
| 792 | - $json = json_decode( wp_remote_retrieve_body( $response ) ); | |
| 784 | + // Pre-deprecation callers expect the raw array, not a WP_REST_Response. | |
| 785 | + return $response->get_data(); | |
| 786 | + } | |
| 793 | 787 | |
| 794 | - if ( ! isset( $json->token ) ) { | |
| 795 | - return new WP_Error( 'no-token', 'No token returned from WPCOM' ); | |
| 788 | + /** | |
| 789 | + * Set subscriber cookie and redirect | |
| 790 | + * | |
| 791 | + * @param \WP_Rest_Request $request The URL to redirect to. | |
| 792 | + * | |
| 793 | + * @return WP_Error|WP_REST_Response | |
| 794 | + */ | |
| 795 | + public static function set_subscriber_cookie_and_redirect( $request ) { | |
| 796 | + require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php'; | |
| 797 | + $subscription_service = \Automattic\Jetpack\Extensions\Premium_Content\subscription_service(); | |
| 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 ) ); | |
| 796 | 805 | } |
| 797 | 806 | |
| 798 | - return array( | |
| 799 | - 'token' => $json->token, | |
| 800 | - 'blog_id' => $blog_id, | |
| 801 | - ); | |
| 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 ) ); | |
| 802 | 814 | } |
| 803 | 815 | |
| 804 | 816 | /** |
| 805 | 817 | * Get the data for the recommendations |
| @@ -859,9 +871,9 @@ | ||
| 859 | 871 | } |
| 860 | 872 | |
| 861 | 873 | $user_connected = ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() ); |
| 862 | 874 | if ( ! $user_connected ) { |
| 863 | - return wp_json_encode( array() ); | |
| 875 | + return wp_json_encode( array(), JSON_UNESCAPED_SLASHES ); | |
| 864 | 876 | } |
| 865 | 877 | |
| 866 | 878 | $request_path = sprintf( '/sites/%s/jetpack-recommendations/product-suggestions?locale=' . get_user_locale(), $blog_id ); |
| 867 | 879 | $wpcom_request = Client::wpcom_json_api_request_as_user( |
| @@ -1102,9 +1114,9 @@ | ||
| 1102 | 1114 | * @since 6.6.0 |
| 1103 | 1115 | * |
| 1104 | 1116 | * @param WP_REST_Request $request The request sent to the WP REST API. |
| 1105 | 1117 | * |
| 1106 | - * @return array|wp-error | |
| 1118 | + * @return array|WP_Error | |
| 1107 | 1119 | */ |
| 1108 | 1120 | public static function is_site_verified_and_token( $request ) { |
| 1109 | 1121 | /** |
| 1110 | 1122 | * Return an error if the site uses a Maintenance / Coming Soon plugin |
| @@ -1130,8 +1142,9 @@ | ||
| 1130 | 1142 | || Jetpack::is_plugin_active( 'mojo-under-construction/mojo-contruction.php' ) && 1 == $under_construction_activation_status // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual |
| 1131 | 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 |
| 1132 | 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 |
| 1133 | 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 | + || | |
| 1134 | 1147 | /** |
| 1135 | 1148 | * Allow plugins to mark a site as "under construction". |
| 1136 | 1149 | * |
| 1137 | 1150 | * @since 6.7.0 |
| @@ -1137,9 +1150,9 @@ | ||
| 1137 | 1150 | * @since 6.7.0 |
| 1138 | 1151 | * |
| 1139 | 1152 | * @param false bool Is the site under construction? Default to false. |
| 1140 | 1153 | */ |
| 1141 | - || true === apply_filters( 'jetpack_is_under_construction_plugin', false ) | |
| 1154 | + true === apply_filters( 'jetpack_is_under_construction_plugin', false ) | |
| 1142 | 1155 | ) { |
| 1143 | 1156 | return new WP_Error( 'forbidden', __( 'Site is under construction and cannot be verified', 'jetpack' ) ); |
| 1144 | 1157 | } |
| 1145 | 1158 | |
| @@ -1211,9 +1224,9 @@ | ||
| 1211 | 1224 | * @since 4.3.0 |
| 1212 | 1225 | * |
| 1213 | 1226 | * @param WP_REST_Request $request The request sent to the WP REST API. |
| 1214 | 1227 | * |
| 1215 | - * @return array|wp-error | |
| 1228 | + * @return array|WP_Error | |
| 1216 | 1229 | */ |
| 1217 | 1230 | public static function dismiss_notice( $request ) { |
| 1218 | 1231 | $notice = $request['notice']; |
| 1219 | 1232 | |
| @@ -1278,24 +1291,20 @@ | ||
| 1278 | 1291 | |
| 1279 | 1292 | /** |
| 1280 | 1293 | * Verify that a user can use the /connection/user endpoint. Has to be a registered user and be currently linked. |
| 1281 | 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 | + * | |
| 1282 | 1300 | * @since 4.3.0 |
| 1283 | 1301 | * |
| 1284 | - * @uses Automattic\Jetpack\Connection\Manager::is_user_connected();) | |
| 1285 | - * | |
| 1286 | 1302 | * @return bool|WP_Error True if user is able to unlink. |
| 1287 | 1303 | */ |
| 1288 | 1304 | public static function unlink_user_permission_callback() { |
| 1289 | - if ( current_user_can( 'jetpack_connect_user' ) && ( new Connection_Manager( 'jetpack' ) )->is_user_connected( get_current_user_id() ) ) { | |
| 1290 | - return true; | |
| 1291 | - } | |
| 1292 | - | |
| 1293 | - return new WP_Error( | |
| 1294 | - 'invalid_user_permission_unlink_user', | |
| 1295 | - REST_Connector::get_user_permissions_error_msg(), | |
| 1296 | - array( 'status' => rest_authorization_required_code() ) | |
| 1297 | - ); | |
| 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(); | |
| 1298 | 1307 | } |
| 1299 | 1308 | |
| 1300 | 1309 | /** |
| 1301 | 1310 | * Verify that user can manage Jetpack modules. |
| @@ -1430,139 +1439,8 @@ | ||
| 1430 | 1439 | ); |
| 1431 | 1440 | } |
| 1432 | 1441 | |
| 1433 | 1442 | /** |
| 1434 | - * Test connection status for this Jetpack site. | |
| 1435 | - * | |
| 1436 | - * @since 6.8.0 | |
| 1437 | - * | |
| 1438 | - * @return array|WP_Error WP_Error returned if connection test does not succeed. | |
| 1439 | - */ | |
| 1440 | - public static function jetpack_connection_test() { | |
| 1441 | - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php'; | |
| 1442 | - $cxntests = new Jetpack_Cxn_Tests(); | |
| 1443 | - | |
| 1444 | - if ( $cxntests->pass() ) { | |
| 1445 | - return rest_ensure_response( | |
| 1446 | - array( | |
| 1447 | - 'code' => 'success', | |
| 1448 | - 'message' => __( 'All connection tests passed.', 'jetpack' ), | |
| 1449 | - ) | |
| 1450 | - ); | |
| 1451 | - } else { | |
| 1452 | - return $cxntests->output_fails_as_wp_error(); | |
| 1453 | - } | |
| 1454 | - } | |
| 1455 | - | |
| 1456 | - /** | |
| 1457 | - * Test connection permission check method. | |
| 1458 | - * | |
| 1459 | - * @since 7.1.0 | |
| 1460 | - * | |
| 1461 | - * @return bool | |
| 1462 | - */ | |
| 1463 | - public static function view_jetpack_connection_test_check() { | |
| 1464 | - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- This is verifying the trusted caller via a shared private key and timestamp. | |
| 1465 | - if ( ! isset( $_GET['signature'] ) || ! isset( $_GET['timestamp'] ) || ! isset( $_GET['url'] ) ) { | |
| 1466 | - return false; | |
| 1467 | - } | |
| 1468 | - $signature = base64_decode( wp_unslash( $_GET['signature'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 1469 | - | |
| 1470 | - $signature_data = wp_json_encode( | |
| 1471 | - array( | |
| 1472 | - 'rest_route' => isset( $_GET['rest_route'] ) ? filter_var( wp_unslash( $_GET['rest_route'] ) ) : null, | |
| 1473 | - 'timestamp' => (int) $_GET['timestamp'], | |
| 1474 | - 'url' => esc_url_raw( wp_unslash( $_GET['url'] ) ), | |
| 1475 | - ) | |
| 1476 | - ); | |
| 1477 | - | |
| 1478 | - if ( | |
| 1479 | - ! function_exists( 'openssl_verify' ) | |
| 1480 | - || 1 !== openssl_verify( | |
| 1481 | - $signature_data, | |
| 1482 | - $signature, | |
| 1483 | - JETPACK__DEBUGGER_PUBLIC_KEY | |
| 1484 | - ) | |
| 1485 | - ) { | |
| 1486 | - return false; | |
| 1487 | - } | |
| 1488 | - | |
| 1489 | - // signature timestamp must be within 5min of current time. | |
| 1490 | - if ( abs( time() - (int) $_GET['timestamp'] ) > 300 ) { | |
| 1491 | - return false; | |
| 1492 | - } | |
| 1493 | - | |
| 1494 | - // phpcs:enable WordPress.Security.NonceVerification.Recommended | |
| 1495 | - | |
| 1496 | - return true; | |
| 1497 | - } | |
| 1498 | - | |
| 1499 | - /** | |
| 1500 | - * Test connection status for this Jetpack site, encrypt the results for decryption by a third-party. | |
| 1501 | - * | |
| 1502 | - * @since 7.1.0 | |
| 1503 | - * | |
| 1504 | - * @return array|mixed|object|WP_Error | |
| 1505 | - */ | |
| 1506 | - public static function jetpack_connection_test_for_external() { | |
| 1507 | - // 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. | |
| 1508 | - add_filter( 'jetpack_debugger_run_self_test', '__return_false' ); | |
| 1509 | - require_once JETPACK__PLUGIN_DIR . '_inc/lib/debugger.php'; | |
| 1510 | - $cxntests = new Jetpack_Cxn_Tests(); | |
| 1511 | - | |
| 1512 | - if ( $cxntests->pass() ) { | |
| 1513 | - $result = array( | |
| 1514 | - 'code' => 'success', | |
| 1515 | - 'message' => __( 'All connection tests passed.', 'jetpack' ), | |
| 1516 | - ); | |
| 1517 | - } else { | |
| 1518 | - $error = $cxntests->output_fails_as_wp_error(); // Using this so the output is similar both ways. | |
| 1519 | - $errors = array(); | |
| 1520 | - | |
| 1521 | - // Borrowed from WP_REST_Server::error_to_response(). | |
| 1522 | - foreach ( (array) $error->errors as $code => $messages ) { | |
| 1523 | - foreach ( (array) $messages as $message ) { | |
| 1524 | - $errors[] = array( | |
| 1525 | - 'code' => $code, | |
| 1526 | - 'message' => $message, | |
| 1527 | - 'data' => $error->get_error_data( $code ), | |
| 1528 | - ); | |
| 1529 | - } | |
| 1530 | - } | |
| 1531 | - | |
| 1532 | - $result = ( ! empty( $errors ) ) ? $errors[0] : null; | |
| 1533 | - if ( count( $errors ) > 1 ) { | |
| 1534 | - // Remove the primary error. | |
| 1535 | - array_shift( $errors ); | |
| 1536 | - $result['additional_errors'] = $errors; | |
| 1537 | - } | |
| 1538 | - } | |
| 1539 | - | |
| 1540 | - $result = wp_json_encode( $result ); | |
| 1541 | - | |
| 1542 | - $encrypted = $cxntests->encrypt_string_for_wpcom( $result ); | |
| 1543 | - | |
| 1544 | - if ( ! $encrypted || ! is_array( $encrypted ) ) { | |
| 1545 | - return rest_ensure_response( | |
| 1546 | - array( | |
| 1547 | - 'code' => 'action_required', | |
| 1548 | - 'message' => 'Please request results from the in-plugin debugger', | |
| 1549 | - ) | |
| 1550 | - ); | |
| 1551 | - } | |
| 1552 | - | |
| 1553 | - return rest_ensure_response( | |
| 1554 | - array( | |
| 1555 | - 'code' => 'response', | |
| 1556 | - 'debug' => array( | |
| 1557 | - 'data' => $encrypted['data'], | |
| 1558 | - 'key' => $encrypted['key'], | |
| 1559 | - ), | |
| 1560 | - ) | |
| 1561 | - ); | |
| 1562 | - } | |
| 1563 | - | |
| 1564 | - /** | |
| 1565 | 1443 | * Fetch information about the Rewind status of the site. |
| 1566 | 1444 | */ |
| 1567 | 1445 | public static function rewind_data() { |
| 1568 | 1446 | $site_id = Jetpack_Options::get_option( 'id' ); |
| @@ -1605,9 +1483,9 @@ | ||
| 1605 | 1483 | return rest_ensure_response( |
| 1606 | 1484 | array( |
| 1607 | 1485 | 'code' => 'success', |
| 1608 | 1486 | 'message' => esc_html__( 'Backup & Scan data correctly received.', 'jetpack' ), |
| 1609 | - 'data' => wp_json_encode( $rewind_data ), | |
| 1487 | + 'data' => wp_json_encode( $rewind_data, JSON_UNESCAPED_SLASHES ), | |
| 1610 | 1488 | ) |
| 1611 | 1489 | ); |
| 1612 | 1490 | } |
| 1613 | 1491 | |
| @@ -1688,9 +1566,9 @@ | ||
| 1688 | 1566 | return rest_ensure_response( |
| 1689 | 1567 | array( |
| 1690 | 1568 | 'code' => 'success', |
| 1691 | 1569 | 'message' => esc_html__( 'Scan state correctly received.', 'jetpack' ), |
| 1692 | - 'data' => wp_json_encode( $scan_state ), | |
| 1570 | + 'data' => wp_json_encode( $scan_state, JSON_UNESCAPED_SLASHES ), | |
| 1693 | 1571 | ) |
| 1694 | 1572 | ); |
| 1695 | 1573 | } |
| 1696 | 1574 | |
| @@ -1737,41 +1615,8 @@ | ||
| 1737 | 1615 | return new WP_Error( 'disconnect_failed', esc_html__( 'Was not able to disconnect the site. Please try again.', 'jetpack' ), array( 'status' => 400 ) ); |
| 1738 | 1616 | } |
| 1739 | 1617 | |
| 1740 | 1618 | /** |
| 1741 | - * Registers the Jetpack site | |
| 1742 | - * | |
| 1743 | - * @deprecated since Jetpack 9.7.0 | |
| 1744 | - * @see Automattic\Jetpack\Connection\REST_Connector::connection_register() | |
| 1745 | - * | |
| 1746 | - * @param WP_REST_Request $request The request sent to the WP REST API. | |
| 1747 | - * | |
| 1748 | - * @return bool|WP_Error True if Jetpack successfully registered | |
| 1749 | - */ | |
| 1750 | - public static function register_site( $request ) { | |
| 1751 | - _deprecated_function( __METHOD__, 'jetpack-9.7.0', '\Automattic\Jetpack\Connection\REST_Connector::connection_register' ); | |
| 1752 | - | |
| 1753 | - if ( ! wp_verify_nonce( $request->get_param( 'registration_nonce' ), 'jetpack-registration-nonce' ) ) { | |
| 1754 | - return new WP_Error( 'invalid_nonce', __( 'Unable to verify your request.', 'jetpack' ), array( 'status' => 403 ) ); | |
| 1755 | - } | |
| 1756 | - | |
| 1757 | - if ( isset( $request['from'] ) ) { | |
| 1758 | - Jetpack::connection()->add_register_request_param( 'from', (string) $request['from'] ); | |
| 1759 | - } | |
| 1760 | - $response = Jetpack::connection()->try_registration(); | |
| 1761 | - | |
| 1762 | - if ( is_wp_error( $response ) ) { | |
| 1763 | - return $response; | |
| 1764 | - } | |
| 1765 | - | |
| 1766 | - return rest_ensure_response( | |
| 1767 | - array( | |
| 1768 | - 'authorizeUrl' => Jetpack::build_authorize_url( false ), | |
| 1769 | - ) | |
| 1770 | - ); | |
| 1771 | - } | |
| 1772 | - | |
| 1773 | - /** | |
| 1774 | 1619 | * Gets a new connect raw URL with fresh nonce. |
| 1775 | 1620 | * |
| 1776 | 1621 | * @uses Jetpack::disconnect(); |
| 1777 | 1622 | * @since 4.3.0 |
| @@ -1780,10 +1625,10 @@ | ||
| 1780 | 1625 | * |
| 1781 | 1626 | * @return string|WP_Error A raw URL if the connection URL could be built; error message otherwise. |
| 1782 | 1627 | */ |
| 1783 | 1628 | public static function build_connect_url( $request = array() ) { |
| 1784 | - $from = isset( $request['from'] ) ? $request['from'] : false; | |
| 1785 | - $redirect = isset( $request['redirect'] ) ? $request['redirect'] : false; | |
| 1629 | + $from = $request['from'] ?? false; | |
| 1630 | + $redirect = $request['redirect'] ?? false; | |
| 1786 | 1631 | |
| 1787 | 1632 | $url = Jetpack::init()->build_connect_url( true, $redirect, $from ); |
| 1788 | 1633 | if ( $url ) { |
| 1789 | 1634 | return rest_ensure_response( $url ); |
| @@ -1821,30 +1666,21 @@ | ||
| 1821 | 1666 | |
| 1822 | 1667 | /** |
| 1823 | 1668 | * Unlinks current user from the WordPress.com Servers. |
| 1824 | 1669 | * |
| 1825 | - * @since 4.3.0 | |
| 1670 | + * @param WP_REST_Request $request The request sent to the WP REST API. | |
| 1826 | 1671 | * @uses Automattic\Jetpack\Connection\Manager->disconnect_user |
| 1827 | 1672 | * |
| 1828 | - * @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() | |
| 1829 | 1675 | * |
| 1676 | + * @since 4.3.0 | |
| 1677 | + * | |
| 1830 | 1678 | * @return bool|WP_Error True if user successfully unlinked. |
| 1831 | 1679 | */ |
| 1832 | 1680 | public static function unlink_user( $request ) { |
| 1833 | - | |
| 1834 | - if ( ! isset( $request['linked'] ) || false !== $request['linked'] ) { | |
| 1835 | - return new WP_Error( 'invalid_param', esc_html__( 'Invalid Parameter', 'jetpack' ), array( 'status' => 404 ) ); | |
| 1836 | - } | |
| 1837 | - | |
| 1838 | - if ( ( new Connection_Manager( 'jetpack' ) )->disconnect_user() ) { | |
| 1839 | - return rest_ensure_response( | |
| 1840 | - array( | |
| 1841 | - 'code' => 'success', | |
| 1842 | - ) | |
| 1843 | - ); | |
| 1844 | - } | |
| 1845 | - | |
| 1846 | - 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 ); | |
| 1847 | 1683 | } |
| 1848 | 1684 | |
| 1849 | 1685 | /** |
| 1850 | 1686 | * Gets current user's tracking settings. |
| @@ -1903,9 +1739,9 @@ | ||
| 1903 | 1739 | 'Content-Type' => 'application/json', |
| 1904 | 1740 | 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ), |
| 1905 | 1741 | ), |
| 1906 | 1742 | ), |
| 1907 | - wp_json_encode( $request->get_params() ) | |
| 1743 | + wp_json_encode( $request->get_params(), JSON_UNESCAPED_SLASHES ) | |
| 1908 | 1744 | ); |
| 1909 | 1745 | if ( ! is_wp_error( $response ) ) { |
| 1910 | 1746 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 1911 | 1747 | } |
| @@ -1917,93 +1753,30 @@ | ||
| 1917 | 1753 | /** |
| 1918 | 1754 | * Fetch site data from .com including the site's current plan and the site's products. |
| 1919 | 1755 | * |
| 1920 | 1756 | * @since 5.5.0 |
| 1757 | + * @deprecated 16.2 Use Automattic\Jetpack\Connection\Manager::get_connected_site_data(). | |
| 1921 | 1758 | * |
| 1922 | 1759 | * @return stdClass|WP_Error |
| 1923 | 1760 | */ |
| 1924 | 1761 | public static function site_data() { |
| 1925 | - $site_id = Jetpack_Options::get_option( 'id' ); | |
| 1762 | + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\Manager::get_connected_site_data' ); | |
| 1926 | 1763 | |
| 1927 | - if ( ! $site_id ) { | |
| 1928 | - return new WP_Error( 'site_id_missing', '', array( 'api_error_code' => __( 'site_id_missing', 'jetpack' ) ) ); | |
| 1929 | - } | |
| 1764 | + return ( new Connection_Manager() )->get_connected_site_data(); | |
| 1765 | + } | |
| 1930 | 1766 | |
| 1931 | - $args = array( 'headers' => array() ); | |
| 1932 | - | |
| 1933 | - // Allow use a store sandbox. Internal ref: PCYsg-IA-p2. | |
| 1934 | - if ( isset( $_COOKIE ) && isset( $_COOKIE['store_sandbox'] ) ) { | |
| 1935 | - $secret = filter_var( wp_unslash( $_COOKIE['store_sandbox'] ) ); | |
| 1936 | - $args['headers']['Cookie'] = "store_sandbox=$secret;"; | |
| 1937 | - } | |
| 1938 | - | |
| 1939 | - $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ) . '?force=wpcom', '1.1', $args ); | |
| 1940 | - $body = wp_remote_retrieve_body( $response ); | |
| 1941 | - $data = $body ? json_decode( $body ) : null; | |
| 1942 | - | |
| 1943 | - if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { | |
| 1944 | - $error_info = array( | |
| 1945 | - 'api_error_code' => null, | |
| 1946 | - 'api_http_code' => wp_remote_retrieve_response_code( $response ), | |
| 1947 | - ); | |
| 1948 | - | |
| 1949 | - if ( is_wp_error( $response ) ) { | |
| 1950 | - $error_info['api_error_code'] = $response->get_error_code() ? wp_strip_all_tags( $response->get_error_code() ) : null; | |
| 1951 | - } elseif ( $data && ! empty( $data->error ) ) { | |
| 1952 | - $error_info['api_error_code'] = $data->error; | |
| 1953 | - } | |
| 1954 | - | |
| 1955 | - return new WP_Error( 'site_data_fetch_failed', '', $error_info ); | |
| 1956 | - } | |
| 1957 | - | |
| 1958 | - Jetpack_Plan::update_from_sites_response( $response ); | |
| 1959 | - | |
| 1960 | - return $data; | |
| 1961 | - } | |
| 1962 | 1767 | /** |
| 1963 | 1768 | * Get site data, including for example, the site's current plan. |
| 1964 | 1769 | * |
| 1770 | + * @since 4.3.0 | |
| 1771 | + * @deprecated 16.2 Use Automattic\Jetpack\Connection\REST_Connector::site_data_response(). | |
| 1772 | + * | |
| 1965 | 1773 | * @return WP_Error|WP_HTTP_Response|WP_REST_Response |
| 1966 | - * @since 4.3.0 | |
| 1967 | 1774 | */ |
| 1968 | 1775 | public static function get_site_data() { |
| 1969 | - $site_data = self::site_data(); | |
| 1776 | + _deprecated_function( __METHOD__, 'jetpack-16.2', 'Automattic\Jetpack\Connection\REST_Connector::site_data_response' ); | |
| 1970 | 1777 | |
| 1971 | - if ( ! is_wp_error( $site_data ) ) { | |
| 1972 | - | |
| 1973 | - /** | |
| 1974 | - * Fires when the site data was successfully returned from the /sites/%d wpcom endpoint. | |
| 1975 | - * | |
| 1976 | - * @since 8.7.0 | |
| 1977 | - */ | |
| 1978 | - do_action( 'jetpack_get_site_data_success' ); | |
| 1979 | - return rest_ensure_response( | |
| 1980 | - array( | |
| 1981 | - 'code' => 'success', | |
| 1982 | - 'message' => esc_html__( 'Site data correctly received.', 'jetpack' ), | |
| 1983 | - 'data' => wp_json_encode( $site_data ), | |
| 1984 | - ) | |
| 1985 | - ); | |
| 1986 | - } | |
| 1987 | - | |
| 1988 | - $error_data = $site_data->get_error_data(); | |
| 1989 | - | |
| 1990 | - if ( empty( $error_data['api_error_code'] ) ) { | |
| 1991 | - $error_message = esc_html__( 'Failed fetching site data from WordPress.com. If the problem persists, try reconnecting Jetpack.', 'jetpack' ); | |
| 1992 | - } else { | |
| 1993 | - /* translators: %s is an error code (e.g. `token_mismatch`) */ | |
| 1994 | - $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'] ); | |
| 1995 | - } | |
| 1996 | - | |
| 1997 | - return new WP_Error( | |
| 1998 | - $site_data->get_error_code(), | |
| 1999 | - $error_message, | |
| 2000 | - array( | |
| 2001 | - 'status' => 400, | |
| 2002 | - 'api_error_code' => empty( $error_data['api_error_code'] ) ? null : $error_data['api_error_code'], | |
| 2003 | - 'api_http_code' => empty( $error_data['api_http_code'] ) ? null : $error_data['api_http_code'], | |
| 2004 | - ) | |
| 2005 | - ); | |
| 1778 | + return REST_Connector::site_data_response(); | |
| 2006 | 1779 | } |
| 2007 | 1780 | |
| 2008 | 1781 | /** |
| 2009 | 1782 | * Fetch AL data for this site and return it. |
| @@ -2218,9 +1991,9 @@ | ||
| 2218 | 1991 | public static function get_updateable_data_list( $selector = '' ) { |
| 2219 | 1992 | |
| 2220 | 1993 | $options = array( |
| 2221 | 1994 | // Blocks. |
| 2222 | - 'jetpack_blocks_disabled' => array( | |
| 1995 | + 'jetpack_blocks_disabled' => array( | |
| 2223 | 1996 | 'description' => esc_html__( 'Jetpack Blocks disabled.', 'jetpack' ), |
| 2224 | 1997 | 'type' => 'boolean', |
| 2225 | 1998 | 'default' => false, |
| 2226 | 1999 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2227,9 +2000,9 @@ | ||
| 2227 | 2000 | 'jp_group' => 'settings', |
| 2228 | 2001 | ), |
| 2229 | 2002 | |
| 2230 | 2003 | // Carousel |
| 2231 | - 'carousel_background_color' => array( | |
| 2004 | + 'carousel_background_color' => array( | |
| 2232 | 2005 | 'description' => esc_html__( 'Color scheme.', 'jetpack' ), |
| 2233 | 2006 | 'type' => 'string', |
| 2234 | 2007 | 'default' => 'black', |
| 2235 | 2008 | 'enum' => array( |
| @@ -2242,9 +2015,9 @@ | ||
| 2242 | 2015 | ), |
| 2243 | 2016 | 'validate_callback' => __CLASS__ . '::validate_list_item', |
| 2244 | 2017 | 'jp_group' => 'carousel', |
| 2245 | 2018 | ), |
| 2246 | - 'carousel_display_exif' => array( | |
| 2019 | + 'carousel_display_exif' => array( | |
| 2247 | 2020 | 'description' => wp_kses( |
| 2248 | 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' ) ), |
| 2249 | 2022 | array( |
| 2250 | 2023 | 'a' => array( |
| @@ -2257,9 +2030,9 @@ | ||
| 2257 | 2030 | 'default' => 0, |
| 2258 | 2031 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2259 | 2032 | 'jp_group' => 'carousel', |
| 2260 | 2033 | ), |
| 2261 | - 'carousel_display_comments' => array( | |
| 2034 | + 'carousel_display_comments' => array( | |
| 2262 | 2035 | 'description' => esc_html__( 'Show comments area in carousel', 'jetpack' ), |
| 2263 | 2036 | 'type' => 'boolean', |
| 2264 | 2037 | 'default' => 1, |
| 2265 | 2038 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2266,9 +2039,9 @@ | ||
| 2266 | 2039 | 'jp_group' => 'carousel', |
| 2267 | 2040 | ), |
| 2268 | 2041 | |
| 2269 | 2042 | // Comments. |
| 2270 | - 'highlander_comment_form_prompt' => array( | |
| 2043 | + 'highlander_comment_form_prompt' => array( | |
| 2271 | 2044 | 'description' => esc_html__( 'Greeting Text', 'jetpack' ), |
| 2272 | 2045 | 'type' => 'string', |
| 2273 | 2046 | 'default' => esc_html__( 'Leave a Reply', 'jetpack' ), |
| 2274 | 2047 | 'sanitize_callback' => 'sanitize_text_field', |
| @@ -2273,9 +2046,9 @@ | ||
| 2273 | 2046 | 'default' => esc_html__( 'Leave a Reply', 'jetpack' ), |
| 2274 | 2047 | 'sanitize_callback' => 'sanitize_text_field', |
| 2275 | 2048 | 'jp_group' => 'comments', |
| 2276 | 2049 | ), |
| 2277 | - 'jetpack_comment_form_color_scheme' => array( | |
| 2050 | + 'jetpack_comment_form_color_scheme' => array( | |
| 2278 | 2051 | 'description' => esc_html__( 'Color scheme', 'jetpack' ), |
| 2279 | 2052 | 'type' => 'string', |
| 2280 | 2053 | 'default' => 'light', |
| 2281 | 2054 | 'enum' => array( |
| @@ -2292,39 +2065,38 @@ | ||
| 2292 | 2065 | 'jp_group' => 'comments', |
| 2293 | 2066 | ), |
| 2294 | 2067 | |
| 2295 | 2068 | // Custom Content Types. |
| 2296 | - 'jetpack_portfolio' => array( | |
| 2069 | + 'jetpack_portfolio' => array( | |
| 2297 | 2070 | 'description' => esc_html__( 'Enable or disable Jetpack portfolio post type.', 'jetpack' ), |
| 2298 | 2071 | 'type' => 'boolean', |
| 2299 | 2072 | 'default' => 0, |
| 2300 | 2073 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2301 | - 'jp_group' => 'custom-content-types', | |
| 2074 | + 'jp_group' => 'settings', | |
| 2302 | 2075 | ), |
| 2303 | - 'jetpack_portfolio_posts_per_page' => array( | |
| 2076 | + 'jetpack_portfolio_posts_per_page' => array( | |
| 2304 | 2077 | 'description' => esc_html__( 'Number of entries to show at most in Portfolio pages.', 'jetpack' ), |
| 2305 | 2078 | 'type' => 'integer', |
| 2306 | 2079 | 'default' => 10, |
| 2307 | 2080 | 'validate_callback' => __CLASS__ . '::validate_posint', |
| 2308 | - 'jp_group' => 'custom-content-types', | |
| 2081 | + 'jp_group' => 'settings', | |
| 2309 | 2082 | ), |
| 2310 | - 'jetpack_testimonial' => array( | |
| 2083 | + 'jetpack_testimonial' => array( | |
| 2311 | 2084 | 'description' => esc_html__( 'Enable or disable Jetpack testimonial post type.', 'jetpack' ), |
| 2312 | 2085 | 'type' => 'boolean', |
| 2313 | 2086 | 'default' => 0, |
| 2314 | 2087 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2315 | - 'jp_group' => 'custom-content-types', | |
| 2088 | + 'jp_group' => 'settings', | |
| 2316 | 2089 | ), |
| 2317 | - 'jetpack_testimonial_posts_per_page' => array( | |
| 2090 | + 'jetpack_testimonial_posts_per_page' => array( | |
| 2318 | 2091 | 'description' => esc_html__( 'Number of entries to show at most in Testimonial pages.', 'jetpack' ), |
| 2319 | 2092 | 'type' => 'integer', |
| 2320 | 2093 | 'default' => 10, |
| 2321 | 2094 | 'validate_callback' => __CLASS__ . '::validate_posint', |
| 2322 | - 'jp_group' => 'custom-content-types', | |
| 2095 | + 'jp_group' => 'settings', | |
| 2323 | 2096 | ), |
| 2324 | - | |
| 2325 | 2097 | // WAF. |
| 2326 | - 'jetpack_waf_automatic_rules' => array( | |
| 2098 | + 'jetpack_waf_automatic_rules' => array( | |
| 2327 | 2099 | 'description' => esc_html__( 'Enable automatic rules - Protect your site against untrusted traffic sources with automatic security rules.', 'jetpack' ), |
| 2328 | 2100 | 'type' => 'boolean', |
| 2329 | 2101 | 'default' => Waf_Compatibility::get_default_automatic_rules_option(), |
| 2330 | 2102 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2329,16 +2101,16 @@ | ||
| 2329 | 2101 | 'default' => Waf_Compatibility::get_default_automatic_rules_option(), |
| 2330 | 2102 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2331 | 2103 | 'jp_group' => 'waf', |
| 2332 | 2104 | ), |
| 2333 | - 'jetpack_waf_ip_list' => array( | |
| 2334 | - 'description' => esc_html__( 'Allow / Block list - Block or allow a specific request IP.', 'jetpack' ), | |
| 2105 | + 'jetpack_waf_ip_block_list_enabled' => array( | |
| 2106 | + 'description' => esc_html__( 'Block list - Block a specific request IP.', 'jetpack' ), | |
| 2335 | 2107 | 'type' => 'boolean', |
| 2336 | 2108 | 'default' => 0, |
| 2337 | 2109 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2338 | 2110 | 'jp_group' => 'waf', |
| 2339 | 2111 | ), |
| 2340 | - 'jetpack_waf_ip_block_list' => array( | |
| 2112 | + 'jetpack_waf_ip_block_list' => array( | |
| 2341 | 2113 | 'description' => esc_html__( 'Blocked IP addresses', 'jetpack' ), |
| 2342 | 2114 | 'type' => 'string', |
| 2343 | 2115 | 'default' => '', |
| 2344 | 2116 | 'validate_callback' => __CLASS__ . '::validate_string', |
| @@ -2344,9 +2116,16 @@ | ||
| 2344 | 2116 | 'validate_callback' => __CLASS__ . '::validate_string', |
| 2345 | 2117 | 'sanitize_callback' => 'esc_textarea', |
| 2346 | 2118 | 'jp_group' => 'waf', |
| 2347 | 2119 | ), |
| 2348 | - 'jetpack_waf_ip_allow_list' => array( | |
| 2120 | + 'jetpack_waf_ip_allow_list_enabled' => array( | |
| 2121 | + 'description' => esc_html__( 'Allow list - Allow a specific request IP.', 'jetpack' ), | |
| 2122 | + 'type' => 'boolean', | |
| 2123 | + 'default' => 0, | |
| 2124 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2125 | + 'jp_group' => 'settings', | |
| 2126 | + ), | |
| 2127 | + 'jetpack_waf_ip_allow_list' => array( | |
| 2349 | 2128 | 'description' => esc_html__( 'Always allowed IP addresses', 'jetpack' ), |
| 2350 | 2129 | 'type' => 'string', |
| 2351 | 2130 | 'default' => '', |
| 2352 | 2131 | 'validate_callback' => __CLASS__ . '::validate_string', |
| @@ -2352,17 +2131,24 @@ | ||
| 2352 | 2131 | 'validate_callback' => __CLASS__ . '::validate_string', |
| 2353 | 2132 | 'sanitize_callback' => 'esc_textarea', |
| 2354 | 2133 | 'jp_group' => 'settings', |
| 2355 | 2134 | ), |
| 2356 | - 'jetpack_waf_share_data' => array( | |
| 2357 | - 'description' => esc_html__( 'Share data with Jetpack.', 'jetpack' ), | |
| 2135 | + 'jetpack_waf_share_data' => array( | |
| 2136 | + 'description' => esc_html__( 'Share basic data with Jetpack.', 'jetpack' ), | |
| 2358 | 2137 | 'type' => 'boolean', |
| 2359 | 2138 | 'default' => 0, |
| 2360 | 2139 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2361 | 2140 | 'jp_group' => 'waf', |
| 2362 | 2141 | ), |
| 2142 | + 'jetpack_waf_share_debug_data' => array( | |
| 2143 | + 'description' => esc_html__( 'Share detailed data with Jetpack.', 'jetpack' ), | |
| 2144 | + 'type' => 'boolean', | |
| 2145 | + 'default' => 0, | |
| 2146 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2147 | + 'jp_group' => 'waf', | |
| 2148 | + ), | |
| 2363 | 2149 | // Galleries. |
| 2364 | - 'tiled_galleries' => array( | |
| 2150 | + 'tiled_galleries' => array( | |
| 2365 | 2151 | 'description' => esc_html__( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ), |
| 2366 | 2152 | 'type' => 'boolean', |
| 2367 | 2153 | 'default' => 0, |
| 2368 | 2154 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2368,9 +2154,9 @@ | ||
| 2368 | 2154 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2369 | 2155 | 'jp_group' => 'tiled-gallery', |
| 2370 | 2156 | ), |
| 2371 | 2157 | |
| 2372 | - 'gravatar_disable_hovercards' => array( | |
| 2158 | + 'gravatar_disable_hovercards' => array( | |
| 2373 | 2159 | 'description' => esc_html__( "View people's profiles when you mouse over their Gravatars", 'jetpack' ), |
| 2374 | 2160 | 'type' => 'string', |
| 2375 | 2161 | 'default' => 'enabled', |
| 2376 | 2162 | // Not visible. This is used as the checkbox value. |
| @@ -2386,9 +2172,9 @@ | ||
| 2386 | 2172 | 'jp_group' => 'gravatar-hovercards', |
| 2387 | 2173 | ), |
| 2388 | 2174 | |
| 2389 | 2175 | // Infinite Scroll. |
| 2390 | - 'infinite_scroll' => array( | |
| 2176 | + 'infinite_scroll' => array( | |
| 2391 | 2177 | 'description' => esc_html__( 'To infinity and beyond', 'jetpack' ), |
| 2392 | 2178 | 'type' => 'boolean', |
| 2393 | 2179 | 'default' => 1, |
| 2394 | 2180 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2393,9 +2179,9 @@ | ||
| 2393 | 2179 | 'default' => 1, |
| 2394 | 2180 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2395 | 2181 | 'jp_group' => 'infinite-scroll', |
| 2396 | 2182 | ), |
| 2397 | - 'infinite_scroll_google_analytics' => array( | |
| 2183 | + 'infinite_scroll_google_analytics' => array( | |
| 2398 | 2184 | 'description' => esc_html__( 'Use Google Analytics with Infinite Scroll', 'jetpack' ), |
| 2399 | 2185 | 'type' => 'boolean', |
| 2400 | 2186 | 'default' => 0, |
| 2401 | 2187 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2402,9 +2188,9 @@ | ||
| 2402 | 2188 | 'jp_group' => 'infinite-scroll', |
| 2403 | 2189 | ), |
| 2404 | 2190 | |
| 2405 | 2191 | // Likes. |
| 2406 | - 'wpl_default' => array( | |
| 2192 | + 'wpl_default' => array( | |
| 2407 | 2193 | 'description' => esc_html__( 'WordPress.com Likes are', 'jetpack' ), |
| 2408 | 2194 | 'type' => 'string', |
| 2409 | 2195 | 'default' => 'on', |
| 2410 | 2196 | 'enum' => array( |
| @@ -2417,9 +2203,9 @@ | ||
| 2417 | 2203 | ), |
| 2418 | 2204 | 'validate_callback' => __CLASS__ . '::validate_list_item', |
| 2419 | 2205 | 'jp_group' => 'likes', |
| 2420 | 2206 | ), |
| 2421 | - 'social_notifications_like' => array( | |
| 2207 | + 'social_notifications_like' => array( | |
| 2422 | 2208 | 'description' => esc_html__( 'Send email notification when someone likes a post', 'jetpack' ), |
| 2423 | 2209 | 'type' => 'boolean', |
| 2424 | 2210 | 'default' => 1, |
| 2425 | 2211 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2426,9 +2212,9 @@ | ||
| 2426 | 2212 | 'jp_group' => 'likes', |
| 2427 | 2213 | ), |
| 2428 | 2214 | |
| 2429 | 2215 | // Markdown. |
| 2430 | - 'wpcom_publish_comments_with_markdown' => array( | |
| 2216 | + 'wpcom_publish_comments_with_markdown' => array( | |
| 2431 | 2217 | 'description' => esc_html__( 'Use Markdown for comments.', 'jetpack' ), |
| 2432 | 2218 | 'type' => 'boolean', |
| 2433 | 2219 | 'default' => 0, |
| 2434 | 2220 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2433,9 +2219,9 @@ | ||
| 2433 | 2219 | 'default' => 0, |
| 2434 | 2220 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2435 | 2221 | 'jp_group' => 'markdown', |
| 2436 | 2222 | ), |
| 2437 | - 'wpcom_publish_posts_with_markdown' => array( | |
| 2223 | + 'wpcom_publish_posts_with_markdown' => array( | |
| 2438 | 2224 | 'description' => esc_html__( 'Use Markdown for posts.', 'jetpack' ), |
| 2439 | 2225 | 'type' => 'boolean', |
| 2440 | 2226 | 'default' => 0, |
| 2441 | 2227 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2442,9 +2228,9 @@ | ||
| 2442 | 2228 | 'jp_group' => 'markdown', |
| 2443 | 2229 | ), |
| 2444 | 2230 | |
| 2445 | 2231 | // Monitor. |
| 2446 | - 'monitor_receive_notifications' => array( | |
| 2232 | + 'monitor_receive_notifications' => array( | |
| 2447 | 2233 | 'description' => esc_html__( 'Receive Monitor Email Notifications.', 'jetpack' ), |
| 2448 | 2234 | 'type' => 'boolean', |
| 2449 | 2235 | 'default' => 0, |
| 2450 | 2236 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2451,9 +2237,9 @@ | ||
| 2451 | 2237 | 'jp_group' => 'monitor', |
| 2452 | 2238 | ), |
| 2453 | 2239 | |
| 2454 | 2240 | // Post by Email. |
| 2455 | - 'post_by_email_address' => array( | |
| 2241 | + 'post_by_email_address' => array( | |
| 2456 | 2242 | 'description' => esc_html__( 'Email Address', 'jetpack' ), |
| 2457 | 2243 | 'type' => 'string', |
| 2458 | 2244 | 'default' => 'noop', |
| 2459 | 2245 | 'enum' => array( |
| @@ -2472,9 +2258,9 @@ | ||
| 2472 | 2258 | 'jp_group' => 'post-by-email', |
| 2473 | 2259 | ), |
| 2474 | 2260 | |
| 2475 | 2261 | // Protect. |
| 2476 | - 'jetpack_protect_key' => array( | |
| 2262 | + 'jetpack_protect_key' => array( | |
| 2477 | 2263 | 'description' => esc_html__( 'Protect API key', 'jetpack' ), |
| 2478 | 2264 | 'type' => 'string', |
| 2479 | 2265 | 'default' => '', |
| 2480 | 2266 | 'validate_callback' => __CLASS__ . '::validate_alphanum', |
| @@ -2479,9 +2265,9 @@ | ||
| 2479 | 2265 | 'default' => '', |
| 2480 | 2266 | 'validate_callback' => __CLASS__ . '::validate_alphanum', |
| 2481 | 2267 | 'jp_group' => 'protect', |
| 2482 | 2268 | ), |
| 2483 | - 'jetpack_protect_global_whitelist' => array( | |
| 2269 | + 'jetpack_protect_global_whitelist' => array( | |
| 2484 | 2270 | 'description' => esc_html__( 'Protect global IP allow list', 'jetpack' ), |
| 2485 | 2271 | 'type' => 'string', |
| 2486 | 2272 | 'default' => '', |
| 2487 | 2273 | 'validate_callback' => __CLASS__ . '::validate_string', |
| @@ -2489,9 +2275,9 @@ | ||
| 2489 | 2275 | 'jp_group' => 'protect', |
| 2490 | 2276 | ), |
| 2491 | 2277 | |
| 2492 | 2278 | // Sharing. |
| 2493 | - 'sharing_services' => array( | |
| 2279 | + 'sharing_services' => array( | |
| 2494 | 2280 | 'description' => esc_html__( 'Enabled Services and those hidden behind a button', 'jetpack' ), |
| 2495 | 2281 | 'type' => 'object', |
| 2496 | 2282 | 'default' => array( |
| 2497 | 2283 | 'visible' => array( 'facebook', 'x' ), |
| @@ -2499,9 +2285,9 @@ | ||
| 2499 | 2285 | ), |
| 2500 | 2286 | 'validate_callback' => __CLASS__ . '::validate_services', |
| 2501 | 2287 | 'jp_group' => 'sharedaddy', |
| 2502 | 2288 | ), |
| 2503 | - 'button_style' => array( | |
| 2289 | + 'button_style' => array( | |
| 2504 | 2290 | 'description' => esc_html__( 'Button Style', 'jetpack' ), |
| 2505 | 2291 | 'type' => 'string', |
| 2506 | 2292 | 'default' => 'icon', |
| 2507 | 2293 | 'enum' => array( |
| @@ -2518,9 +2304,9 @@ | ||
| 2518 | 2304 | ), |
| 2519 | 2305 | 'validate_callback' => __CLASS__ . '::validate_list_item', |
| 2520 | 2306 | 'jp_group' => 'sharedaddy', |
| 2521 | 2307 | ), |
| 2522 | - 'sharing_label' => array( | |
| 2308 | + 'sharing_label' => array( | |
| 2523 | 2309 | 'description' => esc_html__( 'Sharing Label', 'jetpack' ), |
| 2524 | 2310 | 'type' => 'string', |
| 2525 | 2311 | 'default' => '', |
| 2526 | 2312 | 'validate_callback' => __CLASS__ . '::validate_string', |
| @@ -2526,9 +2312,9 @@ | ||
| 2526 | 2312 | 'validate_callback' => __CLASS__ . '::validate_string', |
| 2527 | 2313 | 'sanitize_callback' => 'esc_html', |
| 2528 | 2314 | 'jp_group' => 'sharedaddy', |
| 2529 | 2315 | ), |
| 2530 | - 'show' => array( | |
| 2316 | + 'show' => array( | |
| 2531 | 2317 | 'description' => esc_html__( 'Views where buttons are shown', 'jetpack' ), |
| 2532 | 2318 | 'type' => 'array', |
| 2533 | 2319 | 'items' => array( |
| 2534 | 2320 | 'type' => 'string', |
| @@ -2536,9 +2322,9 @@ | ||
| 2536 | 2322 | 'default' => array( 'post' ), |
| 2537 | 2323 | 'validate_callback' => __CLASS__ . '::validate_sharing_show', |
| 2538 | 2324 | 'jp_group' => 'sharedaddy', |
| 2539 | 2325 | ), |
| 2540 | - 'jetpack-twitter-cards-site-tag' => array( | |
| 2326 | + 'jetpack-twitter-cards-site-tag' => array( | |
| 2541 | 2327 | 'description' => esc_html__( "The Twitter username of the owner of this site's domain.", 'jetpack' ), |
| 2542 | 2328 | 'type' => 'string', |
| 2543 | 2329 | 'default' => '', |
| 2544 | 2330 | 'validate_callback' => __CLASS__ . '::validate_twitter_username', |
| @@ -2544,9 +2330,9 @@ | ||
| 2544 | 2330 | 'validate_callback' => __CLASS__ . '::validate_twitter_username', |
| 2545 | 2331 | 'sanitize_callback' => 'esc_html', |
| 2546 | 2332 | 'jp_group' => 'sharedaddy', |
| 2547 | 2333 | ), |
| 2548 | - 'sharedaddy_disable_resources' => array( | |
| 2334 | + 'sharedaddy_disable_resources' => array( | |
| 2549 | 2335 | 'description' => esc_html__( 'Disable CSS and JS', 'jetpack' ), |
| 2550 | 2336 | 'type' => 'boolean', |
| 2551 | 2337 | 'default' => 0, |
| 2552 | 2338 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2551,9 +2337,9 @@ | ||
| 2551 | 2337 | 'default' => 0, |
| 2552 | 2338 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2553 | 2339 | 'jp_group' => 'sharedaddy', |
| 2554 | 2340 | ), |
| 2555 | - 'custom' => array( | |
| 2341 | + 'custom' => array( | |
| 2556 | 2342 | 'description' => esc_html__( 'Custom sharing services added by user.', 'jetpack' ), |
| 2557 | 2343 | 'type' => 'object', |
| 2558 | 2344 | 'default' => array( |
| 2559 | 2345 | 'sharing_name' => '', |
| @@ -2562,10 +2348,10 @@ | ||
| 2562 | 2348 | ), |
| 2563 | 2349 | 'validate_callback' => __CLASS__ . '::validate_custom_service', |
| 2564 | 2350 | 'jp_group' => 'sharedaddy', |
| 2565 | 2351 | ), |
| 2566 | - // Not an option, but an action that can be perfomed on the list of custom services passing the service ID. | |
| 2567 | - 'sharing_delete_service' => array( | |
| 2352 | + // Not an option, but an action that can be performed on the list of custom services passing the service ID. | |
| 2353 | + 'sharing_delete_service' => array( | |
| 2568 | 2354 | 'description' => esc_html__( 'Delete custom sharing service.', 'jetpack' ), |
| 2569 | 2355 | 'type' => 'string', |
| 2570 | 2356 | 'default' => '', |
| 2571 | 2357 | 'validate_callback' => __CLASS__ . '::validate_custom_service_id', |
| @@ -2572,16 +2358,16 @@ | ||
| 2572 | 2358 | 'jp_group' => 'sharedaddy', |
| 2573 | 2359 | ), |
| 2574 | 2360 | |
| 2575 | 2361 | // SSO. |
| 2576 | - 'jetpack_sso_require_two_step' => array( | |
| 2362 | + 'jetpack_sso_require_two_step' => array( | |
| 2577 | 2363 | 'description' => esc_html__( 'Require Two-Step Authentication', 'jetpack' ), |
| 2578 | 2364 | 'type' => 'boolean', |
| 2579 | - 'default' => 0, | |
| 2365 | + 'default' => SSO\Helpers::is_require_two_step_checkbox_disabled(), | |
| 2580 | 2366 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2581 | 2367 | 'jp_group' => 'sso', |
| 2582 | 2368 | ), |
| 2583 | - 'jetpack_sso_match_by_email' => array( | |
| 2369 | + 'jetpack_sso_match_by_email' => array( | |
| 2584 | 2370 | 'description' => esc_html__( 'Match by Email', 'jetpack' ), |
| 2585 | 2371 | 'type' => 'boolean', |
| 2586 | 2372 | 'default' => 1, |
| 2587 | 2373 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2588,9 +2374,9 @@ | ||
| 2588 | 2374 | 'jp_group' => 'sso', |
| 2589 | 2375 | ), |
| 2590 | 2376 | |
| 2591 | 2377 | // Subscriptions. |
| 2592 | - 'stb_enabled' => array( | |
| 2378 | + 'stb_enabled' => array( | |
| 2593 | 2379 | 'description' => esc_html__( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ), |
| 2594 | 2380 | 'type' => 'boolean', |
| 2595 | 2381 | 'default' => 1, |
| 2596 | 2382 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2595,9 +2381,9 @@ | ||
| 2595 | 2381 | 'default' => 1, |
| 2596 | 2382 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2597 | 2383 | 'jp_group' => 'subscriptions', |
| 2598 | 2384 | ), |
| 2599 | - 'stc_enabled' => array( | |
| 2385 | + 'stc_enabled' => array( | |
| 2600 | 2386 | 'description' => esc_html__( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ), |
| 2601 | 2387 | 'type' => 'boolean', |
| 2602 | 2388 | 'default' => 1, |
| 2603 | 2389 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2602,9 +2388,79 @@ | ||
| 2602 | 2388 | 'default' => 1, |
| 2603 | 2389 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2604 | 2390 | 'jp_group' => 'subscriptions', |
| 2605 | 2391 | ), |
| 2606 | - 'sm_enabled' => array( | |
| 2392 | + 'wpcom_newsletter_categories' => array( | |
| 2393 | + 'description' => esc_html__( 'Array of post category ids that are marked as newsletter categories', 'jetpack' ), | |
| 2394 | + 'type' => 'array', | |
| 2395 | + 'default' => array(), | |
| 2396 | + 'validate_callback' => __CLASS__ . '::validate_array', | |
| 2397 | + 'jp_group' => 'subscriptions', | |
| 2398 | + ), | |
| 2399 | + 'wpcom_newsletter_categories_enabled' => array( | |
| 2400 | + 'description' => esc_html__( 'Whether the newsletter categories are enabled or not', 'jetpack' ), | |
| 2401 | + 'type' => 'boolean', | |
| 2402 | + 'default' => 0, | |
| 2403 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2404 | + 'jp_group' => 'subscriptions', | |
| 2405 | + ), | |
| 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( | |
| 2414 | + 'description' => esc_html__( 'Whether to include the featured image in the email or not', 'jetpack' ), | |
| 2415 | + 'type' => 'boolean', | |
| 2416 | + 'default' => 0, | |
| 2417 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2418 | + 'jp_group' => 'subscriptions', | |
| 2419 | + ), | |
| 2420 | + 'jetpack_gravatar_in_email' => array( | |
| 2421 | + 'description' => esc_html__( 'Whether to show author avatar in the email byline', 'jetpack' ), | |
| 2422 | + 'type' => 'boolean', | |
| 2423 | + 'default' => 1, | |
| 2424 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2425 | + 'jp_group' => 'subscriptions', | |
| 2426 | + ), | |
| 2427 | + 'jetpack_author_in_email' => array( | |
| 2428 | + 'description' => esc_html__( 'Whether to show author display name in the email byline', 'jetpack' ), | |
| 2429 | + 'type' => 'boolean', | |
| 2430 | + 'default' => 1, | |
| 2431 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2432 | + 'jp_group' => 'subscriptions', | |
| 2433 | + ), | |
| 2434 | + 'jetpack_post_date_in_email' => array( | |
| 2435 | + 'description' => esc_html__( 'Whether to show date in the email byline', 'jetpack' ), | |
| 2436 | + 'type' => 'boolean', | |
| 2437 | + 'default' => 1, | |
| 2438 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2439 | + 'jp_group' => 'subscriptions', | |
| 2440 | + ), | |
| 2441 | + 'wpcom_subscription_emails_use_excerpt' => array( | |
| 2442 | + 'description' => esc_html__( 'Whether to use the excerpt in the email or not', 'jetpack' ), | |
| 2443 | + 'type' => 'boolean', | |
| 2444 | + 'default' => 0, | |
| 2445 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2446 | + 'jp_group' => 'subscriptions', | |
| 2447 | + ), | |
| 2448 | + 'jetpack_subscriptions_reply_to' => array( | |
| 2449 | + 'description' => esc_html__( 'Reply to email behaviour for newsletters emails', 'jetpack' ), | |
| 2450 | + 'type' => 'string', | |
| 2451 | + 'default' => Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to, | |
| 2452 | + 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to', | |
| 2453 | + 'jp_group' => 'subscriptions', | |
| 2454 | + ), | |
| 2455 | + 'jetpack_subscriptions_from_name' => array( | |
| 2456 | + 'description' => esc_html__( 'From name for newsletters emails', 'jetpack' ), | |
| 2457 | + 'type' => 'string', | |
| 2458 | + 'default' => '', | |
| 2459 | + 'validate_callback' => __CLASS__ . '::validate_subscriptions_reply_to_name', | |
| 2460 | + 'jp_group' => 'subscriptions', | |
| 2461 | + ), | |
| 2462 | + 'sm_enabled' => array( | |
| 2607 | 2463 | 'description' => esc_html__( 'Show popup Subscribe modal to readers.', 'jetpack' ), |
| 2608 | 2464 | 'type' => 'boolean', |
| 2609 | 2465 | 'default' => 0, |
| 2610 | 2466 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2609,18 +2465,67 @@ | ||
| 2609 | 2465 | 'default' => 0, |
| 2610 | 2466 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2611 | 2467 | 'jp_group' => 'subscriptions', |
| 2612 | 2468 | ), |
| 2613 | - 'social_notifications_subscribe' => array( | |
| 2614 | - 'description' => esc_html__( 'Send email notification when someone follows my blog', 'jetpack' ), | |
| 2469 | + 'jetpack_subscribe_overlay_enabled' => array( | |
| 2470 | + 'description' => esc_html__( 'Show subscribe overlay on homepage.', 'jetpack' ), | |
| 2615 | 2471 | 'type' => 'boolean', |
| 2616 | 2472 | 'default' => 0, |
| 2617 | 2473 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2618 | 2474 | 'jp_group' => 'subscriptions', |
| 2619 | 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 | + ), | |
| 2483 | + 'jetpack_subscriptions_subscribe_post_end_enabled' => array( | |
| 2484 | + 'description' => esc_html__( 'Add Subscribe block at the end of each post.', 'jetpack' ), | |
| 2485 | + 'type' => 'boolean', | |
| 2486 | + 'default' => 0, | |
| 2487 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2488 | + 'jp_group' => 'subscriptions', | |
| 2489 | + ), | |
| 2490 | + 'jetpack_subscriptions_login_navigation_enabled' => array( | |
| 2491 | + 'description' => esc_html__( 'Add Subscriber Login block to the navigation.', 'jetpack' ), | |
| 2492 | + 'type' => 'boolean', | |
| 2493 | + 'default' => 0, | |
| 2494 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2495 | + 'jp_group' => 'subscriptions', | |
| 2496 | + ), | |
| 2497 | + 'jetpack_subscriptions_subscribe_navigation_enabled' => array( | |
| 2498 | + 'description' => esc_html__( 'Add Subscribe block to the navigation.', 'jetpack' ), | |
| 2499 | + 'type' => 'boolean', | |
| 2500 | + 'default' => 0, | |
| 2501 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2502 | + 'jp_group' => 'subscriptions', | |
| 2503 | + ), | |
| 2504 | + 'social_notifications_subscribe' => array( | |
| 2505 | + 'description' => esc_html__( 'Send email notification when someone subscribes to my blog', 'jetpack' ), | |
| 2506 | + 'type' => 'boolean', | |
| 2507 | + 'default' => 0, | |
| 2508 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2509 | + 'jp_group' => 'subscriptions', | |
| 2510 | + ), | |
| 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' ), | |
| 2513 | + 'type' => 'object', | |
| 2514 | + 'default' => array( | |
| 2515 | + 'invitation' => '', | |
| 2516 | + 'welcome' => '', | |
| 2517 | + 'comment_follow' => '', | |
| 2518 | + 'subscribe_modal_heading' => '', | |
| 2519 | + 'free_tier_description' => '', | |
| 2520 | + 'hide_free_tier' => false, | |
| 2521 | + ), | |
| 2522 | + 'validate_callback' => __CLASS__ . '::validate_subscription_options', | |
| 2523 | + 'jp_group' => 'subscriptions', | |
| 2524 | + ), | |
| 2620 | 2525 | |
| 2621 | 2526 | // Related Posts. |
| 2622 | - 'show_headline' => array( | |
| 2527 | + 'show_headline' => array( | |
| 2623 | 2528 | 'description' => esc_html__( 'Highlight related content with a heading', 'jetpack' ), |
| 2624 | 2529 | 'type' => 'boolean', |
| 2625 | 2530 | 'default' => 1, |
| 2626 | 2531 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2625,9 +2530,9 @@ | ||
| 2625 | 2530 | 'default' => 1, |
| 2626 | 2531 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2627 | 2532 | 'jp_group' => 'related-posts', |
| 2628 | 2533 | ), |
| 2629 | - 'show_thumbnails' => array( | |
| 2534 | + 'show_thumbnails' => array( | |
| 2630 | 2535 | 'description' => esc_html__( 'Show a thumbnail image where available', 'jetpack' ), |
| 2631 | 2536 | 'type' => 'boolean', |
| 2632 | 2537 | 'default' => 0, |
| 2633 | 2538 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2634,9 +2539,9 @@ | ||
| 2634 | 2539 | 'jp_group' => 'related-posts', |
| 2635 | 2540 | ), |
| 2636 | 2541 | |
| 2637 | 2542 | // Search. |
| 2638 | - 'instant_search_enabled' => array( | |
| 2543 | + 'instant_search_enabled' => array( | |
| 2639 | 2544 | 'description' => esc_html__( 'Enable Instant Search', 'jetpack' ), |
| 2640 | 2545 | 'type' => 'boolean', |
| 2641 | 2546 | 'default' => 0, |
| 2642 | 2547 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2642,9 +2547,9 @@ | ||
| 2642 | 2547 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2643 | 2548 | 'jp_group' => 'search', |
| 2644 | 2549 | ), |
| 2645 | 2550 | |
| 2646 | - 'has_jetpack_search_product' => array( | |
| 2551 | + 'has_jetpack_search_product' => array( | |
| 2647 | 2552 | 'description' => esc_html__( 'Has an active Jetpack Search product purchase', 'jetpack' ), |
| 2648 | 2553 | 'type' => 'boolean', |
| 2649 | 2554 | 'default' => 0, |
| 2650 | 2555 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2650,9 +2555,9 @@ | ||
| 2650 | 2555 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2651 | 2556 | 'jp_group' => 'settings', |
| 2652 | 2557 | ), |
| 2653 | 2558 | |
| 2654 | - 'search_auto_config' => array( | |
| 2559 | + 'search_auto_config' => array( | |
| 2655 | 2560 | 'description' => esc_html__( 'Trigger an auto config of instant search', 'jetpack' ), |
| 2656 | 2561 | 'type' => 'boolean', |
| 2657 | 2562 | 'default' => 0, |
| 2658 | 2563 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2659,9 +2564,9 @@ | ||
| 2659 | 2564 | 'jp_group' => 'search', |
| 2660 | 2565 | ), |
| 2661 | 2566 | |
| 2662 | 2567 | // Verification Tools. |
| 2663 | - 'google' => array( | |
| 2568 | + 'google' => array( | |
| 2664 | 2569 | 'description' => esc_html__( 'Google Search Console', 'jetpack' ), |
| 2665 | 2570 | 'type' => 'string', |
| 2666 | 2571 | 'default' => '', |
| 2667 | 2572 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| @@ -2666,9 +2571,9 @@ | ||
| 2666 | 2571 | 'default' => '', |
| 2667 | 2572 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| 2668 | 2573 | 'jp_group' => 'verification-tools', |
| 2669 | 2574 | ), |
| 2670 | - 'bing' => array( | |
| 2575 | + 'bing' => array( | |
| 2671 | 2576 | 'description' => esc_html__( 'Bing Webmaster Center', 'jetpack' ), |
| 2672 | 2577 | 'type' => 'string', |
| 2673 | 2578 | 'default' => '', |
| 2674 | 2579 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| @@ -2673,9 +2578,9 @@ | ||
| 2673 | 2578 | 'default' => '', |
| 2674 | 2579 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| 2675 | 2580 | 'jp_group' => 'verification-tools', |
| 2676 | 2581 | ), |
| 2677 | - 'pinterest' => array( | |
| 2582 | + 'pinterest' => array( | |
| 2678 | 2583 | 'description' => esc_html__( 'Pinterest Site Verification', 'jetpack' ), |
| 2679 | 2584 | 'type' => 'string', |
| 2680 | 2585 | 'default' => '', |
| 2681 | 2586 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| @@ -2680,9 +2585,9 @@ | ||
| 2680 | 2585 | 'default' => '', |
| 2681 | 2586 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| 2682 | 2587 | 'jp_group' => 'verification-tools', |
| 2683 | 2588 | ), |
| 2684 | - 'yandex' => array( | |
| 2589 | + 'yandex' => array( | |
| 2685 | 2590 | 'description' => esc_html__( 'Yandex Site Verification', 'jetpack' ), |
| 2686 | 2591 | 'type' => 'string', |
| 2687 | 2592 | 'default' => '', |
| 2688 | 2593 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| @@ -2687,9 +2592,9 @@ | ||
| 2687 | 2592 | 'default' => '', |
| 2688 | 2593 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| 2689 | 2594 | 'jp_group' => 'verification-tools', |
| 2690 | 2595 | ), |
| 2691 | - 'facebook' => array( | |
| 2596 | + 'facebook' => array( | |
| 2692 | 2597 | 'description' => esc_html__( 'Facebook Domain Verification', 'jetpack' ), |
| 2693 | 2598 | 'type' => 'string', |
| 2694 | 2599 | 'default' => '', |
| 2695 | 2600 | 'validate_callback' => __CLASS__ . '::validate_verification_service', |
| @@ -2696,9 +2601,9 @@ | ||
| 2696 | 2601 | 'jp_group' => 'verification-tools', |
| 2697 | 2602 | ), |
| 2698 | 2603 | |
| 2699 | 2604 | // WordAds. |
| 2700 | - 'enable_header_ad' => array( | |
| 2605 | + 'enable_header_ad' => array( | |
| 2701 | 2606 | 'description' => esc_html__( 'Display an ad unit at the top of each page.', 'jetpack' ), |
| 2702 | 2607 | 'type' => 'boolean', |
| 2703 | 2608 | 'default' => 1, |
| 2704 | 2609 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2703,9 +2608,9 @@ | ||
| 2703 | 2608 | 'default' => 1, |
| 2704 | 2609 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2705 | 2610 | 'jp_group' => 'wordads', |
| 2706 | 2611 | ), |
| 2707 | - 'wordads_approved' => array( | |
| 2612 | + 'wordads_approved' => array( | |
| 2708 | 2613 | 'description' => esc_html__( 'Is site approved for WordAds?', 'jetpack' ), |
| 2709 | 2614 | 'type' => 'boolean', |
| 2710 | 2615 | 'default' => 0, |
| 2711 | 2616 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2710,9 +2615,9 @@ | ||
| 2710 | 2615 | 'default' => 0, |
| 2711 | 2616 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2712 | 2617 | 'jp_group' => 'wordads', |
| 2713 | 2618 | ), |
| 2714 | - 'wordads_second_belowpost' => array( | |
| 2619 | + 'wordads_second_belowpost' => array( | |
| 2715 | 2620 | 'description' => esc_html__( 'Display second ad below post?', 'jetpack' ), |
| 2716 | 2621 | 'type' => 'boolean', |
| 2717 | 2622 | 'default' => 1, |
| 2718 | 2623 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2717,9 +2622,16 @@ | ||
| 2717 | 2622 | 'default' => 1, |
| 2718 | 2623 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2719 | 2624 | 'jp_group' => 'wordads', |
| 2720 | 2625 | ), |
| 2721 | - 'wordads_display_front_page' => array( | |
| 2626 | + 'wordads_inline_enabled' => array( | |
| 2627 | + 'description' => esc_html__( 'Display inline ad within post content?', 'jetpack' ), | |
| 2628 | + 'type' => 'boolean', | |
| 2629 | + 'default' => 1, | |
| 2630 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2631 | + 'jp_group' => 'wordads', | |
| 2632 | + ), | |
| 2633 | + 'wordads_display_front_page' => array( | |
| 2722 | 2634 | 'description' => esc_html__( 'Display ads on the front page?', 'jetpack' ), |
| 2723 | 2635 | 'type' => 'boolean', |
| 2724 | 2636 | 'default' => 1, |
| 2725 | 2637 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2724,9 +2636,9 @@ | ||
| 2724 | 2636 | 'default' => 1, |
| 2725 | 2637 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2726 | 2638 | 'jp_group' => 'wordads', |
| 2727 | 2639 | ), |
| 2728 | - 'wordads_display_post' => array( | |
| 2640 | + 'wordads_display_post' => array( | |
| 2729 | 2641 | 'description' => esc_html__( 'Display ads on posts?', 'jetpack' ), |
| 2730 | 2642 | 'type' => 'boolean', |
| 2731 | 2643 | 'default' => 1, |
| 2732 | 2644 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2731,9 +2643,9 @@ | ||
| 2731 | 2643 | 'default' => 1, |
| 2732 | 2644 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2733 | 2645 | 'jp_group' => 'wordads', |
| 2734 | 2646 | ), |
| 2735 | - 'wordads_display_page' => array( | |
| 2647 | + 'wordads_display_page' => array( | |
| 2736 | 2648 | 'description' => esc_html__( 'Display ads on pages?', 'jetpack' ), |
| 2737 | 2649 | 'type' => 'boolean', |
| 2738 | 2650 | 'default' => 1, |
| 2739 | 2651 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2738,9 +2650,9 @@ | ||
| 2738 | 2650 | 'default' => 1, |
| 2739 | 2651 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2740 | 2652 | 'jp_group' => 'wordads', |
| 2741 | 2653 | ), |
| 2742 | - 'wordads_display_archive' => array( | |
| 2654 | + 'wordads_display_archive' => array( | |
| 2743 | 2655 | 'description' => esc_html__( 'Display ads on archive pages?', 'jetpack' ), |
| 2744 | 2656 | 'type' => 'boolean', |
| 2745 | 2657 | 'default' => 1, |
| 2746 | 2658 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2745,9 +2657,9 @@ | ||
| 2745 | 2657 | 'default' => 1, |
| 2746 | 2658 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2747 | 2659 | 'jp_group' => 'wordads', |
| 2748 | 2660 | ), |
| 2749 | - 'wordads_custom_adstxt_enabled' => array( | |
| 2661 | + 'wordads_custom_adstxt_enabled' => array( | |
| 2750 | 2662 | 'description' => esc_html__( 'Custom ads.txt', 'jetpack' ), |
| 2751 | 2663 | 'type' => 'boolean', |
| 2752 | 2664 | 'default' => 0, |
| 2753 | 2665 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2752,9 +2664,9 @@ | ||
| 2752 | 2664 | 'default' => 0, |
| 2753 | 2665 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2754 | 2666 | 'jp_group' => 'wordads', |
| 2755 | 2667 | ), |
| 2756 | - 'wordads_custom_adstxt' => array( | |
| 2668 | + 'wordads_custom_adstxt' => array( | |
| 2757 | 2669 | 'description' => esc_html__( 'Custom ads.txt entries', 'jetpack' ), |
| 2758 | 2670 | 'type' => 'string', |
| 2759 | 2671 | 'default' => '', |
| 2760 | 2672 | 'validate_callback' => __CLASS__ . '::validate_string', |
| @@ -2760,9 +2672,9 @@ | ||
| 2760 | 2672 | 'validate_callback' => __CLASS__ . '::validate_string', |
| 2761 | 2673 | 'sanitize_callback' => 'sanitize_textarea_field', |
| 2762 | 2674 | 'jp_group' => 'wordads', |
| 2763 | 2675 | ), |
| 2764 | - 'wordads_ccpa_enabled' => array( | |
| 2676 | + 'wordads_ccpa_enabled' => array( | |
| 2765 | 2677 | 'description' => esc_html__( 'Enable support for California Consumer Privacy Act', 'jetpack' ), |
| 2766 | 2678 | 'type' => 'boolean', |
| 2767 | 2679 | 'default' => 0, |
| 2768 | 2680 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2767,9 +2679,9 @@ | ||
| 2767 | 2679 | 'default' => 0, |
| 2768 | 2680 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2769 | 2681 | 'jp_group' => 'wordads', |
| 2770 | 2682 | ), |
| 2771 | - 'wordads_ccpa_privacy_policy_url' => array( | |
| 2683 | + 'wordads_ccpa_privacy_policy_url' => array( | |
| 2772 | 2684 | 'description' => esc_html__( 'Privacy Policy URL', 'jetpack' ), |
| 2773 | 2685 | 'type' => 'string', |
| 2774 | 2686 | 'default' => '', |
| 2775 | 2687 | 'validate_callback' => __CLASS__ . '::validate_string', |
| @@ -2775,11 +2687,18 @@ | ||
| 2775 | 2687 | 'validate_callback' => __CLASS__ . '::validate_string', |
| 2776 | 2688 | 'sanitize_callback' => 'sanitize_text_field', |
| 2777 | 2689 | 'jp_group' => 'wordads', |
| 2778 | 2690 | ), |
| 2691 | + 'wordads_cmp_enabled' => array( | |
| 2692 | + 'description' => esc_html__( 'Enable GDPR Consent Management Banner for WordAds', 'jetpack' ), | |
| 2693 | + 'type' => 'boolean', | |
| 2694 | + 'default' => 0, | |
| 2695 | + 'validate_callback' => __CLASS__ . '::validate_boolean', | |
| 2696 | + 'jp_group' => 'wordads', | |
| 2697 | + ), | |
| 2779 | 2698 | |
| 2780 | 2699 | // Google Analytics. |
| 2781 | - 'google_analytics_tracking_id' => array( | |
| 2700 | + 'google_analytics_tracking_id' => array( | |
| 2782 | 2701 | 'description' => esc_html__( 'Google Analytics', 'jetpack' ), |
| 2783 | 2702 | 'type' => 'string', |
| 2784 | 2703 | 'default' => '', |
| 2785 | 2704 | 'validate_callback' => __CLASS__ . '::validate_alphanum', |
| @@ -2784,11 +2703,16 @@ | ||
| 2784 | 2703 | 'default' => '', |
| 2785 | 2704 | 'validate_callback' => __CLASS__ . '::validate_alphanum', |
| 2786 | 2705 | 'jp_group' => 'google-analytics', |
| 2787 | 2706 | ), |
| 2707 | + 'jetpack_wga' => array( | |
| 2708 | + 'description' => esc_html__( 'Google Analytics', 'jetpack' ), | |
| 2709 | + 'type' => 'object', | |
| 2710 | + 'jp_group' => 'settings', | |
| 2711 | + ), | |
| 2788 | 2712 | |
| 2789 | 2713 | // Stats. |
| 2790 | - 'admin_bar' => array( | |
| 2714 | + 'admin_bar' => array( | |
| 2791 | 2715 | 'description' => esc_html__( 'Include a small chart in your admin bar with a 48-hour traffic snapshot.', 'jetpack' ), |
| 2792 | 2716 | 'type' => 'boolean', |
| 2793 | 2717 | 'default' => 1, |
| 2794 | 2718 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2793,9 +2717,9 @@ | ||
| 2793 | 2717 | 'default' => 1, |
| 2794 | 2718 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2795 | 2719 | 'jp_group' => 'stats', |
| 2796 | 2720 | ), |
| 2797 | - 'enable_odyssey_stats' => array( | |
| 2721 | + 'enable_odyssey_stats' => array( | |
| 2798 | 2722 | 'description' => esc_html__( 'Preview the new Jetpack Stats experience (Experimental).', 'jetpack' ), |
| 2799 | 2723 | 'type' => 'boolean', |
| 2800 | 2724 | 'default' => 1, |
| 2801 | 2725 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2800,9 +2724,9 @@ | ||
| 2800 | 2724 | 'default' => 1, |
| 2801 | 2725 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2802 | 2726 | 'jp_group' => 'stats', |
| 2803 | 2727 | ), |
| 2804 | - 'roles' => array( | |
| 2728 | + 'roles' => array( | |
| 2805 | 2729 | 'description' => esc_html__( 'Select the roles that will be able to view stats reports.', 'jetpack' ), |
| 2806 | 2730 | 'type' => 'array', |
| 2807 | 2731 | 'items' => array( |
| 2808 | 2732 | 'type' => 'string', |
| @@ -2811,9 +2735,9 @@ | ||
| 2811 | 2735 | 'validate_callback' => __CLASS__ . '::validate_stats_roles', |
| 2812 | 2736 | 'sanitize_callback' => __CLASS__ . '::sanitize_stats_allowed_roles', |
| 2813 | 2737 | 'jp_group' => 'stats', |
| 2814 | 2738 | ), |
| 2815 | - 'count_roles' => array( | |
| 2739 | + 'count_roles' => array( | |
| 2816 | 2740 | 'description' => esc_html__( 'Count the page views of registered users who are logged in.', 'jetpack' ), |
| 2817 | 2741 | 'type' => 'array', |
| 2818 | 2742 | 'items' => array( |
| 2819 | 2743 | 'type' => 'string', |
| @@ -2821,9 +2745,9 @@ | ||
| 2821 | 2745 | 'default' => array( 'administrator' ), |
| 2822 | 2746 | 'validate_callback' => __CLASS__ . '::validate_stats_roles', |
| 2823 | 2747 | 'jp_group' => 'stats', |
| 2824 | 2748 | ), |
| 2825 | - 'blog_id' => array( | |
| 2749 | + 'blog_id' => array( | |
| 2826 | 2750 | 'description' => esc_html__( 'Blog ID.', 'jetpack' ), |
| 2827 | 2751 | 'type' => 'boolean', |
| 2828 | 2752 | 'default' => 0, |
| 2829 | 2753 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2828,9 +2752,9 @@ | ||
| 2828 | 2752 | 'default' => 0, |
| 2829 | 2753 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2830 | 2754 | 'jp_group' => 'stats', |
| 2831 | 2755 | ), |
| 2832 | - 'do_not_track' => array( | |
| 2756 | + 'do_not_track' => array( | |
| 2833 | 2757 | 'description' => esc_html__( 'Do not track.', 'jetpack' ), |
| 2834 | 2758 | 'type' => 'boolean', |
| 2835 | 2759 | 'default' => 1, |
| 2836 | 2760 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2835,9 +2759,9 @@ | ||
| 2835 | 2759 | 'default' => 1, |
| 2836 | 2760 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2837 | 2761 | 'jp_group' => 'stats', |
| 2838 | 2762 | ), |
| 2839 | - 'version' => array( | |
| 2763 | + 'version' => array( | |
| 2840 | 2764 | 'description' => esc_html__( 'Version.', 'jetpack' ), |
| 2841 | 2765 | 'type' => 'integer', |
| 2842 | 2766 | 'default' => 9, |
| 2843 | 2767 | 'validate_callback' => __CLASS__ . '::validate_posint', |
| @@ -2842,9 +2766,9 @@ | ||
| 2842 | 2766 | 'default' => 9, |
| 2843 | 2767 | 'validate_callback' => __CLASS__ . '::validate_posint', |
| 2844 | 2768 | 'jp_group' => 'stats', |
| 2845 | 2769 | ), |
| 2846 | - 'collapse_nudges' => array( | |
| 2770 | + 'collapse_nudges' => array( | |
| 2847 | 2771 | 'description' => esc_html__( 'Collapse upgrade nudges', 'jetpack' ), |
| 2848 | 2772 | 'type' => 'boolean', |
| 2849 | 2773 | 'default' => 0, |
| 2850 | 2774 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2851,9 +2775,9 @@ | ||
| 2851 | 2775 | 'jp_group' => 'stats', |
| 2852 | 2776 | ), |
| 2853 | 2777 | |
| 2854 | 2778 | // Whether to share stats views with WordPress.com Reader. |
| 2855 | - 'wpcom_reader_views_enabled' => array( | |
| 2779 | + 'wpcom_reader_views_enabled' => array( | |
| 2856 | 2780 | 'description' => esc_html__( 'Show post views in the WordPress.com Reader.', 'jetpack' ), |
| 2857 | 2781 | 'type' => 'boolean', |
| 2858 | 2782 | 'default' => 1, |
| 2859 | 2783 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2860,9 +2784,9 @@ | ||
| 2860 | 2784 | 'jp_group' => 'settings', |
| 2861 | 2785 | ), |
| 2862 | 2786 | |
| 2863 | 2787 | // Akismet - Not a module, but a plugin. The options can be passed and handled differently. |
| 2864 | - 'akismet_show_user_comments_approved' => array( | |
| 2788 | + 'akismet_show_user_comments_approved' => array( | |
| 2865 | 2789 | 'description' => '', |
| 2866 | 2790 | 'type' => 'boolean', |
| 2867 | 2791 | 'default' => 0, |
| 2868 | 2792 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2868,9 +2792,9 @@ | ||
| 2868 | 2792 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2869 | 2793 | 'jp_group' => 'settings', |
| 2870 | 2794 | ), |
| 2871 | 2795 | |
| 2872 | - 'wordpress_api_key' => array( | |
| 2796 | + 'wordpress_api_key' => array( | |
| 2873 | 2797 | 'description' => '', |
| 2874 | 2798 | 'type' => 'string', |
| 2875 | 2799 | 'default' => '', |
| 2876 | 2800 | 'validate_callback' => __CLASS__ . '::validate_alphanum', |
| @@ -2877,9 +2801,9 @@ | ||
| 2877 | 2801 | 'jp_group' => 'settings', |
| 2878 | 2802 | ), |
| 2879 | 2803 | |
| 2880 | 2804 | // Empty stats card dismiss. |
| 2881 | - 'dismiss_empty_stats_card' => array( | |
| 2805 | + 'dismiss_empty_stats_card' => array( | |
| 2882 | 2806 | 'description' => '', |
| 2883 | 2807 | 'type' => 'boolean', |
| 2884 | 2808 | 'default' => 0, |
| 2885 | 2809 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2886,9 +2810,9 @@ | ||
| 2886 | 2810 | 'jp_group' => 'settings', |
| 2887 | 2811 | ), |
| 2888 | 2812 | |
| 2889 | 2813 | // Backup Getting Started card on dashboard. |
| 2890 | - 'dismiss_dash_backup_getting_started' => array( | |
| 2814 | + 'dismiss_dash_backup_getting_started' => array( | |
| 2891 | 2815 | 'description' => '', |
| 2892 | 2816 | 'type' => 'boolean', |
| 2893 | 2817 | 'default' => 0, |
| 2894 | 2818 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2895,9 +2819,9 @@ | ||
| 2895 | 2819 | 'jp_group' => 'settings', |
| 2896 | 2820 | ), |
| 2897 | 2821 | |
| 2898 | 2822 | // Agencies Learn More card on dashboard. |
| 2899 | - 'dismiss_dash_agencies_learn_more' => array( | |
| 2823 | + 'dismiss_dash_agencies_learn_more' => array( | |
| 2900 | 2824 | 'description' => '', |
| 2901 | 2825 | 'type' => 'boolean', |
| 2902 | 2826 | 'default' => 0, |
| 2903 | 2827 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2903,9 +2827,9 @@ | ||
| 2903 | 2827 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| 2904 | 2828 | 'jp_group' => 'settings', |
| 2905 | 2829 | ), |
| 2906 | 2830 | |
| 2907 | - 'lang_id' => array( | |
| 2831 | + 'lang_id' => array( | |
| 2908 | 2832 | 'description' => esc_html__( 'Primary language for the site.', 'jetpack' ), |
| 2909 | 2833 | 'type' => 'string', |
| 2910 | 2834 | 'default' => 'en_US', |
| 2911 | 2835 | 'jp_group' => 'settings', |
| @@ -2910,32 +2834,10 @@ | ||
| 2910 | 2834 | 'default' => 'en_US', |
| 2911 | 2835 | 'jp_group' => 'settings', |
| 2912 | 2836 | ), |
| 2913 | 2837 | |
| 2914 | - 'onboarding' => array( | |
| 2915 | - 'description' => '', | |
| 2916 | - 'type' => 'object', | |
| 2917 | - 'default' => array( | |
| 2918 | - 'siteTitle' => '', | |
| 2919 | - 'siteDescription' => '', | |
| 2920 | - 'siteType' => 'personal', | |
| 2921 | - 'homepageFormat' => 'posts', | |
| 2922 | - 'addContactForm' => 0, | |
| 2923 | - 'businessAddress' => array( | |
| 2924 | - 'name' => '', | |
| 2925 | - 'street' => '', | |
| 2926 | - 'city' => '', | |
| 2927 | - 'state' => '', | |
| 2928 | - 'zip' => '', | |
| 2929 | - ), | |
| 2930 | - 'installWooCommerce' => false, | |
| 2931 | - ), | |
| 2932 | - 'validate_callback' => __CLASS__ . '::validate_onboarding', | |
| 2933 | - 'jp_group' => 'settings', | |
| 2934 | - ), | |
| 2935 | - | |
| 2936 | 2838 | // SEO Tools. |
| 2937 | - 'advanced_seo_front_page_description' => array( | |
| 2839 | + 'advanced_seo_front_page_description' => array( | |
| 2938 | 2840 | 'description' => esc_html__( 'Front page meta description.', 'jetpack' ), |
| 2939 | 2841 | 'type' => 'string', |
| 2940 | 2842 | 'default' => '', |
| 2941 | 2843 | 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description', |
| @@ -2941,9 +2843,9 @@ | ||
| 2941 | 2843 | 'sanitize_callback' => 'Jetpack_SEO_Utils::sanitize_front_page_meta_description', |
| 2942 | 2844 | 'jp_group' => 'seo-tools', |
| 2943 | 2845 | ), |
| 2944 | 2846 | |
| 2945 | - 'advanced_seo_title_formats' => array( | |
| 2847 | + 'advanced_seo_title_formats' => array( | |
| 2946 | 2848 | 'description' => esc_html__( 'SEO page title structures.', 'jetpack' ), |
| 2947 | 2849 | 'type' => 'object', |
| 2948 | 2850 | 'default' => array( |
| 2949 | 2851 | 'archives' => array(), |
| @@ -2956,10 +2858,34 @@ | ||
| 2956 | 2858 | 'validate_callback' => 'Jetpack_SEO_Titles::are_valid_title_formats', |
| 2957 | 2859 | 'sanitize_callback' => 'Jetpack_SEO_Titles::sanitize_title_formats', |
| 2958 | 2860 | ), |
| 2959 | 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 | + | |
| 2960 | 2886 | // VideoPress. |
| 2961 | - 'videopress_private_enabled_for_site' => array( | |
| 2887 | + 'videopress_private_enabled_for_site' => array( | |
| 2962 | 2888 | 'description' => esc_html__( 'Video Privacy: Restrict views to members of this site', 'jetpack' ), |
| 2963 | 2889 | 'type' => 'boolean', |
| 2964 | 2890 | 'default' => 0, |
| 2965 | 2891 | 'validate_callback' => __CLASS__ . '::validate_boolean', |
| @@ -2966,8 +2892,21 @@ | ||
| 2966 | 2892 | 'jp_group' => 'videopress', |
| 2967 | 2893 | ), |
| 2968 | 2894 | ); |
| 2969 | 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 | + | |
| 2970 | 2909 | // Add modules to list so they can be toggled. |
| 2971 | 2910 | $modules = Jetpack::get_available_modules(); |
| 2972 | 2911 | if ( is_array( $modules ) && ! empty( $modules ) ) { |
| 2973 | 2912 | $module_args = array( |
| @@ -3013,8 +2952,10 @@ | ||
| 3013 | 2952 | * Validates that the parameters are proper values that can be set during Jetpack onboarding. |
| 3014 | 2953 | * |
| 3015 | 2954 | * @since 5.4.0 |
| 3016 | 2955 | * |
| 2956 | + * @deprecated since 13.9 | |
| 2957 | + * | |
| 3017 | 2958 | * @param array $onboarding_data Values to check. |
| 3018 | 2959 | * @param WP_REST_Request $request The request sent to the WP REST API. |
| 3019 | 2960 | * @param string $param Name of the parameter passed to endpoint holding $value. |
| 3020 | 2961 | * |
| @@ -3019,24 +2960,10 @@ | ||
| 3019 | 2960 | * @param string $param Name of the parameter passed to endpoint holding $value. |
| 3020 | 2961 | * |
| 3021 | 2962 | * @return bool|WP_Error |
| 3022 | 2963 | */ |
| 3023 | - public static function validate_onboarding( $onboarding_data, $request, $param ) { | |
| 3024 | - if ( ! is_array( $onboarding_data ) ) { | |
| 3025 | - return new WP_Error( 'invalid_param', esc_html__( 'Not valid onboarding data.', 'jetpack' ) ); | |
| 3026 | - } | |
| 3027 | - foreach ( $onboarding_data as $value ) { | |
| 3028 | - if ( is_string( $value ) ) { | |
| 3029 | - $onboarding_choice = self::validate_string( $value, $request, $param ); | |
| 3030 | - } elseif ( is_array( $value ) ) { | |
| 3031 | - $onboarding_choice = self::validate_onboarding( $value, $request, $param ); | |
| 3032 | - } else { | |
| 3033 | - $onboarding_choice = self::validate_boolean( $value, $request, $param ); | |
| 3034 | - } | |
| 3035 | - if ( is_wp_error( $onboarding_choice ) ) { | |
| 3036 | - return $onboarding_choice; | |
| 3037 | - } | |
| 3038 | - } | |
| 2964 | + public static function validate_onboarding( $onboarding_data, $request, $param ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 2965 | + _deprecated_function( __METHOD__, '13.9' ); | |
| 3039 | 2966 | return true; |
| 3040 | 2967 | } |
| 3041 | 2968 | |
| 3042 | 2969 | /** |
| @@ -3250,9 +3177,9 @@ | ||
| 3250 | 3177 | * Validates that the parameter is among the roles allowed for Stats. |
| 3251 | 3178 | * |
| 3252 | 3179 | * @since 4.3.0 |
| 3253 | 3180 | * |
| 3254 | - * @param string|bool $value Value to check. | |
| 3181 | + * @param mixed $value Value to check. | |
| 3255 | 3182 | * @param WP_REST_Request $request The request sent to the WP REST API. |
| 3256 | 3183 | * @param string $param Name of the parameter passed to endpoint holding $value. |
| 3257 | 3184 | * |
| 3258 | 3185 | * @return bool|WP_Error |
| @@ -3257,16 +3184,37 @@ | ||
| 3257 | 3184 | * |
| 3258 | 3185 | * @return bool|WP_Error |
| 3259 | 3186 | */ |
| 3260 | 3187 | public static function validate_stats_roles( $value, $request, $param ) { |
| 3261 | - 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 ) ) { | |
| 3262 | 3195 | return new WP_Error( |
| 3263 | 3196 | 'invalid_param', |
| 3264 | 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( | |
| 3265 | 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. */ |
| 3266 | 3214 | esc_html__( '%1$s must be %2$s.', 'jetpack' ), |
| 3267 | 3215 | $param, |
| 3268 | - implode( ', ', self::$stats_roles ) | |
| 3216 | + implode( ', ', $editable_roles ) | |
| 3269 | 3217 | ) |
| 3270 | 3218 | ); |
| 3271 | 3219 | } |
| 3272 | 3220 | return true; |
| @@ -3309,8 +3257,59 @@ | ||
| 3309 | 3257 | return true; |
| 3310 | 3258 | } |
| 3311 | 3259 | |
| 3312 | 3260 | /** |
| 3261 | + * Validates that the parameter is among the valid reply-to types for subscriptions. | |
| 3262 | + * | |
| 3263 | + * @since 4.3.0 | |
| 3264 | + * | |
| 3265 | + * @param string|bool $value Value to check. | |
| 3266 | + * @param WP_REST_Request $request The request sent to the WP REST API. | |
| 3267 | + * @param string $param Name of the parameter passed to endpoint holding $value. | |
| 3268 | + * | |
| 3269 | + * @return bool|WP_Error | |
| 3270 | + */ | |
| 3271 | + public static function validate_subscriptions_reply_to( $value, $request, $param ) { | |
| 3272 | + require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php'; | |
| 3273 | + if ( ! empty( $value ) && ! Automattic\Jetpack\Modules\Subscriptions\Settings::is_valid_reply_to( $value ) ) { | |
| 3274 | + return new WP_Error( | |
| 3275 | + 'invalid_param', | |
| 3276 | + sprintf( | |
| 3277 | + /* Translators: Placeholder is a parameter name. */ | |
| 3278 | + esc_html__( '%s must be a valid type.', 'jetpack' ), | |
| 3279 | + $param | |
| 3280 | + ) | |
| 3281 | + ); | |
| 3282 | + } | |
| 3283 | + return true; | |
| 3284 | + } | |
| 3285 | + | |
| 3286 | + /** | |
| 3287 | + * Validates that the parameter is among the valid reply-to types for subscriptions. | |
| 3288 | + * | |
| 3289 | + * @since 4.3.0 | |
| 3290 | + * | |
| 3291 | + * @param string|bool $value Value to check. | |
| 3292 | + * @param WP_REST_Request $request The request sent to the WP REST API. | |
| 3293 | + * @param string $param Name of the parameter passed to endpoint holding $value. | |
| 3294 | + * | |
| 3295 | + * @return bool|WP_Error | |
| 3296 | + */ | |
| 3297 | + public static function validate_subscriptions_reply_to_name( $value, $request, $param ) { | |
| 3298 | + if ( ! empty( $value ) && ! is_string( $value ) ) { | |
| 3299 | + return new WP_Error( | |
| 3300 | + 'invalid_param', | |
| 3301 | + sprintf( | |
| 3302 | + /* Translators: Placeholder is a parameter name. */ | |
| 3303 | + esc_html__( '%s must be a valid type.', 'jetpack' ), | |
| 3304 | + $param | |
| 3305 | + ) | |
| 3306 | + ); | |
| 3307 | + } | |
| 3308 | + return true; | |
| 3309 | + } | |
| 3310 | + | |
| 3311 | + /** | |
| 3313 | 3312 | * Validates that the parameter is among the views where the Sharing can be displayed. |
| 3314 | 3313 | * |
| 3315 | 3314 | * @since 4.3.0 |
| 3316 | 3315 | * |
| @@ -3525,16 +3524,72 @@ | ||
| 3525 | 3524 | return true; |
| 3526 | 3525 | } |
| 3527 | 3526 | |
| 3528 | 3527 | /** |
| 3528 | + * Validates the subscription_options parameter. | |
| 3529 | + * | |
| 3530 | + * @param array $values Value to check. | |
| 3531 | + * | |
| 3532 | + * @return bool|WP_Error | |
| 3533 | + */ | |
| 3534 | + public static function validate_subscription_options( $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 ) ) { | |
| 3539 | + return new WP_Error( | |
| 3540 | + 'invalid_param', | |
| 3541 | + /* Translators: subscription_options is a variable name, and shouldn't be translated. */ | |
| 3542 | + esc_html__( 'subscription_options must be an object.', 'jetpack' ) | |
| 3543 | + ); | |
| 3544 | + } | |
| 3545 | + foreach ( array_keys( $values ) as $key ) { | |
| 3546 | + if ( ! in_array( $key, array( 'welcome', 'invitation', 'comment_follow', 'subscribe_modal_heading', 'free_tier_description', 'hide_free_tier' ), true ) ) { | |
| 3547 | + return new WP_Error( | |
| 3548 | + 'invalid_param', | |
| 3549 | + sprintf( | |
| 3550 | + /* Translators: Placeholder is the invalid param being sent. */ | |
| 3551 | + esc_html__( '%s is not one of the allowed members of subscription_options.', 'jetpack' ), | |
| 3552 | + $key | |
| 3553 | + ) | |
| 3554 | + ); | |
| 3555 | + } | |
| 3556 | + } | |
| 3557 | + return true; | |
| 3558 | + } | |
| 3559 | + | |
| 3560 | + /** | |
| 3561 | + * Validates that the parameter is an array. | |
| 3562 | + * | |
| 3563 | + * @param array $values Value to check. | |
| 3564 | + * @param WP_REST_Request $request The request sent to the WP REST API. | |
| 3565 | + * @param string $param Name of the parameter passed to the endpoint holding $value. | |
| 3566 | + * | |
| 3567 | + * @return bool|WP_Error | |
| 3568 | + */ | |
| 3569 | + public static function validate_array( $values, $request, $param ) { | |
| 3570 | + if ( ! is_array( $values ) ) { | |
| 3571 | + return new WP_Error( | |
| 3572 | + 'invalid_param', | |
| 3573 | + sprintf( | |
| 3574 | + /* Translators: Placeholder is a parameter name. */ | |
| 3575 | + esc_html__( '%s must be an object.', 'jetpack' ), | |
| 3576 | + $param | |
| 3577 | + ) | |
| 3578 | + ); | |
| 3579 | + } | |
| 3580 | + return true; | |
| 3581 | + } | |
| 3582 | + | |
| 3583 | + /** | |
| 3529 | 3584 | * If for some reason the roles allowed to see Stats are empty (for example, user tampering with checkboxes), |
| 3530 | 3585 | * return an array with only 'administrator' as the allowed role and save it for 'roles' option. |
| 3531 | 3586 | * |
| 3532 | 3587 | * @since 4.3.0 |
| 3533 | 3588 | * |
| 3534 | - * @param string|bool $value Value to check. | |
| 3589 | + * @param mixed $value Value to check. | |
| 3535 | 3590 | * |
| 3536 | - * @return bool|array | |
| 3591 | + * @return mixed The value as submitted, or an array holding only 'administrator' when it is empty. | |
| 3537 | 3592 | */ |
| 3538 | 3593 | public static function sanitize_stats_allowed_roles( $value ) { |
| 3539 | 3594 | if ( empty( $value ) ) { |
| 3540 | 3595 | return array( 'administrator' ); |
| @@ -3542,8 +3597,31 @@ | ||
| 3542 | 3597 | return $value; |
| 3543 | 3598 | } |
| 3544 | 3599 | |
| 3545 | 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 | + /** | |
| 3546 | 3624 | * Get the currently accessed route and return the module slug in it. |
| 3547 | 3625 | * |
| 3548 | 3626 | * @since 4.3.0 |
| 3549 | 3627 | * |
| @@ -3552,9 +3630,9 @@ | ||
| 3552 | 3630 | * @return array|string |
| 3553 | 3631 | */ |
| 3554 | 3632 | public static function get_module_requested( $route = '/module/(?P<slug>[a-z\-]+)' ) { |
| 3555 | 3633 | |
| 3556 | - 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'] ) ) { | |
| 3557 | 3635 | return ''; |
| 3558 | 3636 | } |
| 3559 | 3637 | |
| 3560 | 3638 | preg_match( "#$route#", $GLOBALS['wp']->query_vars['rest_route'], $module ); |
| @@ -3605,8 +3683,40 @@ | ||
| 3605 | 3683 | return $modules; |
| 3606 | 3684 | } |
| 3607 | 3685 | |
| 3608 | 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 | + /** | |
| 3609 | 3719 | * Remove 'validate_callback' item from options available for module. |
| 3610 | 3720 | * Fetch current option value and add to array of module options. |
| 3611 | 3721 | * Prepare values of module options that need special handling, like those saved in wpcom. |
| 3612 | 3722 | * |
| @@ -3669,9 +3779,9 @@ | ||
| 3669 | 3779 | $options = self::split_options( $options, $sharer->get_global_options() ); |
| 3670 | 3780 | $options['sharing_services']['current_value'] = $sharer->get_blog_services(); |
| 3671 | 3781 | $other_sharedaddy_options = array( 'jetpack-twitter-cards-site-tag', 'sharedaddy_disable_resources', 'sharing_delete_service' ); |
| 3672 | 3782 | foreach ( $other_sharedaddy_options as $key ) { |
| 3673 | - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : ''; | |
| 3783 | + $default_value = $options[ $key ]['default'] ?? ''; | |
| 3674 | 3784 | $current_value = get_option( $key, $default_value ); |
| 3675 | 3785 | $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] ); |
| 3676 | 3786 | } |
| 3677 | 3787 | break; |
| @@ -3682,9 +3792,9 @@ | ||
| 3682 | 3792 | break; |
| 3683 | 3793 | default: |
| 3684 | 3794 | // These option are just stored as plain WordPress options. |
| 3685 | 3795 | foreach ( $options as $key => $value ) { |
| 3686 | - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : ''; | |
| 3796 | + $default_value = $options[ $key ]['default'] ?? ''; | |
| 3687 | 3797 | $current_value = get_option( $key, $default_value ); |
| 3688 | 3798 | $options[ $key ]['current_value'] = self::cast_value( $current_value, $options[ $key ] ); |
| 3689 | 3799 | } |
| 3690 | 3800 | } |
| @@ -3694,14 +3804,17 @@ | ||
| 3694 | 3804 | // We don't need validate_callback in the response. |
| 3695 | 3805 | if ( isset( $options[ $key ]['validate_callback'] ) ) { |
| 3696 | 3806 | unset( $options[ $key ]['validate_callback'] ); |
| 3697 | 3807 | } |
| 3698 | - $default_value = isset( $options[ $key ]['default'] ) ? $options[ $key ]['default'] : ''; | |
| 3808 | + $default_value = $options[ $key ]['default'] ?? ''; | |
| 3699 | 3809 | if ( ! array_key_exists( 'current_value', $options[ $key ] ) ) { |
| 3700 | 3810 | $options[ $key ]['current_value'] = self::cast_value( $default_value, $options[ $key ] ); |
| 3701 | 3811 | } |
| 3702 | 3812 | } |
| 3703 | - 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 ); | |
| 3704 | 3817 | } |
| 3705 | 3818 | |
| 3706 | 3819 | /** |
| 3707 | 3820 | * Splits module options saved as arrays like relatedposts or verification_services_codes into separate options to be returned in the response. |
| @@ -4260,6 +4373,55 @@ | ||
| 4260 | 4373 | 'code' => 'success', |
| 4261 | 4374 | 'data' => $data, |
| 4262 | 4375 | ) |
| 4263 | 4376 | ); |
| 4377 | + } | |
| 4378 | + | |
| 4379 | + /** | |
| 4380 | + * Return the list of available features. | |
| 4381 | + * | |
| 4382 | + * @return array | |
| 4383 | + */ | |
| 4384 | + public static function get_features_available() { | |
| 4385 | + $raw_modules = Jetpack::get_available_modules(); | |
| 4386 | + $modules = array(); | |
| 4387 | + foreach ( $raw_modules as $module ) { | |
| 4388 | + $modules[] = Jetpack::get_module_slug( $module ); | |
| 4389 | + } | |
| 4390 | + | |
| 4391 | + return $modules; | |
| 4392 | + } | |
| 4393 | + | |
| 4394 | + /** | |
| 4395 | + * Returns what features are enabled. Uses the slug of the modules files. | |
| 4396 | + * | |
| 4397 | + * @return array | |
| 4398 | + */ | |
| 4399 | + public static function get_features_enabled() { | |
| 4400 | + $raw_modules = Jetpack::get_active_modules(); | |
| 4401 | + $modules = array(); | |
| 4402 | + foreach ( $raw_modules as $module ) { | |
| 4403 | + $modules[] = Jetpack::get_module_slug( $module ); | |
| 4404 | + } | |
| 4405 | + | |
| 4406 | + return $modules; | |
| 4407 | + } | |
| 4408 | + | |
| 4409 | + /** | |
| 4410 | + * Verify that the API client is allowed to replace user token. | |
| 4411 | + * | |
| 4412 | + * @since 1.29.0 | |
| 4413 | + * | |
| 4414 | + * @return bool|WP_Error | |
| 4415 | + */ | |
| 4416 | + public static function get_features_permission_check() { | |
| 4417 | + if ( ! Rest_Authentication::is_signed_with_blog_token() ) { | |
| 4418 | + $message = esc_html__( | |
| 4419 | + 'You do not have the correct user permissions to perform this action. Please contact your site admin if you think this is a mistake.', | |
| 4420 | + 'jetpack' | |
| 4421 | + ); | |
| 4422 | + return new WP_Error( 'invalid_permission_fetch_features', $message, array( 'status' => rest_authorization_required_code() ) ); | |
| 4423 | + } | |
| 4424 | + | |
| 4425 | + return true; | |
| 4264 | 4426 | } |
| 4265 | 4427 | } // class end |