| @@ 1616-1638 (lines=23) @@ | ||
| 1613 | * |
|
| 1614 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1615 | */ |
|
| 1616 | public static function get_user_tracking_settings( $request ) { |
|
| 1617 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1618 | $response = array( |
|
| 1619 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1620 | ); |
|
| 1621 | } else { |
|
| 1622 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1623 | '/jetpack-user-tracking', |
|
| 1624 | 'v2', |
|
| 1625 | array( |
|
| 1626 | 'method' => 'GET', |
|
| 1627 | 'headers' => array( |
|
| 1628 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1629 | ), |
|
| 1630 | ) |
|
| 1631 | ); |
|
| 1632 | if ( ! is_wp_error( $response ) ) { |
|
| 1633 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1634 | } |
|
| 1635 | } |
|
| 1636 | ||
| 1637 | return rest_ensure_response( $response ); |
|
| 1638 | } |
|
| 1639 | ||
| 1640 | /** |
|
| 1641 | * Updates current user's tracking settings. |
|
| @@ 1649-1673 (lines=25) @@ | ||
| 1646 | * |
|
| 1647 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1648 | */ |
|
| 1649 | public static function update_user_tracking_settings( $request ) { |
|
| 1650 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1651 | $response = array( |
|
| 1652 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1653 | ); |
|
| 1654 | } else { |
|
| 1655 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1656 | '/jetpack-user-tracking', |
|
| 1657 | 'v2', |
|
| 1658 | array( |
|
| 1659 | 'method' => 'PUT', |
|
| 1660 | 'headers' => array( |
|
| 1661 | 'Content-Type' => 'application/json', |
|
| 1662 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1663 | ), |
|
| 1664 | ), |
|
| 1665 | wp_json_encode( $request->get_params() ) |
|
| 1666 | ); |
|
| 1667 | if ( ! is_wp_error( $response ) ) { |
|
| 1668 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1669 | } |
|
| 1670 | } |
|
| 1671 | ||
| 1672 | return rest_ensure_response( $response ); |
|
| 1673 | } |
|
| 1674 | ||
| 1675 | /** |
|
| 1676 | * Fetch site data from .com including the site's current plan. |
|