| @@ 1375-1397 (lines=23) @@ | ||
| 1372 | * |
|
| 1373 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1374 | */ |
|
| 1375 | public static function get_user_tracking_settings( $request ) { |
|
| 1376 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1377 | $response = array( |
|
| 1378 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1379 | ); |
|
| 1380 | } else { |
|
| 1381 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1382 | '/jetpack-user-tracking', |
|
| 1383 | 'v2', |
|
| 1384 | array( |
|
| 1385 | 'method' => 'GET', |
|
| 1386 | 'headers' => array( |
|
| 1387 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1388 | ), |
|
| 1389 | ) |
|
| 1390 | ); |
|
| 1391 | if ( ! is_wp_error( $response ) ) { |
|
| 1392 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1393 | } |
|
| 1394 | } |
|
| 1395 | ||
| 1396 | return rest_ensure_response( $response ); |
|
| 1397 | } |
|
| 1398 | ||
| 1399 | /** |
|
| 1400 | * Updates current user's tracking settings. |
|
| @@ 1408-1432 (lines=25) @@ | ||
| 1405 | * |
|
| 1406 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1407 | */ |
|
| 1408 | public static function update_user_tracking_settings( $request ) { |
|
| 1409 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1410 | $response = array( |
|
| 1411 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1412 | ); |
|
| 1413 | } else { |
|
| 1414 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1415 | '/jetpack-user-tracking', |
|
| 1416 | 'v2', |
|
| 1417 | array( |
|
| 1418 | 'method' => 'PUT', |
|
| 1419 | 'headers' => array( |
|
| 1420 | 'Content-Type' => 'application/json', |
|
| 1421 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1422 | ), |
|
| 1423 | ), |
|
| 1424 | wp_json_encode( $request->get_params() ) |
|
| 1425 | ); |
|
| 1426 | if ( ! is_wp_error( $response ) ) { |
|
| 1427 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1428 | } |
|
| 1429 | } |
|
| 1430 | ||
| 1431 | return rest_ensure_response( $response ); |
|
| 1432 | } |
|
| 1433 | ||
| 1434 | /** |
|
| 1435 | * Fetch site data from .com including the site's current plan. |
|