| @@ 1545-1567 (lines=23) @@ | ||
| 1542 | * |
|
| 1543 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1544 | */ |
|
| 1545 | public static function get_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' => 'GET', |
|
| 1556 | 'headers' => array( |
|
| 1557 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1558 | ), |
|
| 1559 | ) |
|
| 1560 | ); |
|
| 1561 | if ( ! is_wp_error( $response ) ) { |
|
| 1562 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1563 | } |
|
| 1564 | } |
|
| 1565 | ||
| 1566 | return rest_ensure_response( $response ); |
|
| 1567 | } |
|
| 1568 | ||
| 1569 | /** |
|
| 1570 | * Updates current user's tracking settings. |
|
| @@ 1578-1602 (lines=25) @@ | ||
| 1575 | * |
|
| 1576 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1577 | */ |
|
| 1578 | public static function update_user_tracking_settings( $request ) { |
|
| 1579 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1580 | $response = array( |
|
| 1581 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1582 | ); |
|
| 1583 | } else { |
|
| 1584 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1585 | '/jetpack-user-tracking', |
|
| 1586 | 'v2', |
|
| 1587 | array( |
|
| 1588 | 'method' => 'PUT', |
|
| 1589 | 'headers' => array( |
|
| 1590 | 'Content-Type' => 'application/json', |
|
| 1591 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1592 | ), |
|
| 1593 | ), |
|
| 1594 | wp_json_encode( $request->get_params() ) |
|
| 1595 | ); |
|
| 1596 | if ( ! is_wp_error( $response ) ) { |
|
| 1597 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1598 | } |
|
| 1599 | } |
|
| 1600 | ||
| 1601 | return rest_ensure_response( $response ); |
|
| 1602 | } |
|
| 1603 | ||
| 1604 | /** |
|
| 1605 | * Fetch site data from .com including the site's current plan. |
|