| @@ 1512-1534 (lines=23) @@ | ||
| 1509 | * |
|
| 1510 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1511 | */ |
|
| 1512 | public static function get_user_tracking_settings( $request ) { |
|
| 1513 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1514 | $response = array( |
|
| 1515 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1516 | ); |
|
| 1517 | } else { |
|
| 1518 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1519 | '/jetpack-user-tracking', |
|
| 1520 | 'v2', |
|
| 1521 | array( |
|
| 1522 | 'method' => 'GET', |
|
| 1523 | 'headers' => array( |
|
| 1524 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1525 | ), |
|
| 1526 | ) |
|
| 1527 | ); |
|
| 1528 | if ( ! is_wp_error( $response ) ) { |
|
| 1529 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1530 | } |
|
| 1531 | } |
|
| 1532 | ||
| 1533 | return rest_ensure_response( $response ); |
|
| 1534 | } |
|
| 1535 | ||
| 1536 | /** |
|
| 1537 | * Updates current user's tracking settings. |
|
| @@ 1545-1569 (lines=25) @@ | ||
| 1542 | * |
|
| 1543 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1544 | */ |
|
| 1545 | public static function update_user_tracking_settings( $request ) { |
|
| 1546 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1547 | $response = array( |
|
| 1548 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1549 | ); |
|
| 1550 | } else { |
|
| 1551 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1552 | '/jetpack-user-tracking', |
|
| 1553 | 'v2', |
|
| 1554 | array( |
|
| 1555 | 'method' => 'PUT', |
|
| 1556 | 'headers' => array( |
|
| 1557 | 'Content-Type' => 'application/json', |
|
| 1558 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1559 | ), |
|
| 1560 | ), |
|
| 1561 | wp_json_encode( $request->get_params() ) |
|
| 1562 | ); |
|
| 1563 | if ( ! is_wp_error( $response ) ) { |
|
| 1564 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1565 | } |
|
| 1566 | } |
|
| 1567 | ||
| 1568 | return rest_ensure_response( $response ); |
|
| 1569 | } |
|
| 1570 | ||
| 1571 | /** |
|
| 1572 | * Fetch site data from .com including the site's current plan. |
|