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