| @@ 1236-1258 (lines=23) @@ | ||
| 1233 | * |
|
| 1234 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1235 | */ |
|
| 1236 | public static function get_user_tracking_settings( $request ) { |
|
| 1237 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1238 | $response = array( |
|
| 1239 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1240 | ); |
|
| 1241 | } else { |
|
| 1242 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1243 | '/jetpack-user-tracking', |
|
| 1244 | 'v2', |
|
| 1245 | array( |
|
| 1246 | 'method' => 'GET', |
|
| 1247 | 'headers' => array( |
|
| 1248 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1249 | ), |
|
| 1250 | ) |
|
| 1251 | ); |
|
| 1252 | if ( ! is_wp_error( $response ) ) { |
|
| 1253 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1254 | } |
|
| 1255 | } |
|
| 1256 | ||
| 1257 | return rest_ensure_response( $response ); |
|
| 1258 | } |
|
| 1259 | ||
| 1260 | /** |
|
| 1261 | * Updates current user's tracking settings. |
|
| @@ 1269-1293 (lines=25) @@ | ||
| 1266 | * |
|
| 1267 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1268 | */ |
|
| 1269 | public static function update_user_tracking_settings( $request ) { |
|
| 1270 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1271 | $response = array( |
|
| 1272 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1273 | ); |
|
| 1274 | } else { |
|
| 1275 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1276 | '/jetpack-user-tracking', |
|
| 1277 | 'v2', |
|
| 1278 | array( |
|
| 1279 | 'method' => 'PUT', |
|
| 1280 | 'headers' => array( |
|
| 1281 | 'Content-Type' => 'application/json', |
|
| 1282 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1283 | ), |
|
| 1284 | ), |
|
| 1285 | wp_json_encode( $request->get_params() ) |
|
| 1286 | ); |
|
| 1287 | if ( ! is_wp_error( $response ) ) { |
|
| 1288 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1289 | } |
|
| 1290 | } |
|
| 1291 | ||
| 1292 | return rest_ensure_response( $response ); |
|
| 1293 | } |
|
| 1294 | ||
| 1295 | /** |
|
| 1296 | * Fetch site data from .com including the site's current plan. |
|