| @@ 1579-1601 (lines=23) @@ | ||
| 1576 | * |
|
| 1577 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1578 | */ |
|
| 1579 | public static function get_user_tracking_settings( $request ) { |
|
| 1580 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1581 | $response = array( |
|
| 1582 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1583 | ); |
|
| 1584 | } else { |
|
| 1585 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1586 | '/jetpack-user-tracking', |
|
| 1587 | 'v2', |
|
| 1588 | array( |
|
| 1589 | 'method' => 'GET', |
|
| 1590 | 'headers' => array( |
|
| 1591 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1592 | ), |
|
| 1593 | ) |
|
| 1594 | ); |
|
| 1595 | if ( ! is_wp_error( $response ) ) { |
|
| 1596 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1597 | } |
|
| 1598 | } |
|
| 1599 | ||
| 1600 | return rest_ensure_response( $response ); |
|
| 1601 | } |
|
| 1602 | ||
| 1603 | /** |
|
| 1604 | * Updates current user's tracking settings. |
|
| @@ 1612-1636 (lines=25) @@ | ||
| 1609 | * |
|
| 1610 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1611 | */ |
|
| 1612 | public static function update_user_tracking_settings( $request ) { |
|
| 1613 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1614 | $response = array( |
|
| 1615 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1616 | ); |
|
| 1617 | } else { |
|
| 1618 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1619 | '/jetpack-user-tracking', |
|
| 1620 | 'v2', |
|
| 1621 | array( |
|
| 1622 | 'method' => 'PUT', |
|
| 1623 | 'headers' => array( |
|
| 1624 | 'Content-Type' => 'application/json', |
|
| 1625 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1626 | ), |
|
| 1627 | ), |
|
| 1628 | wp_json_encode( $request->get_params() ) |
|
| 1629 | ); |
|
| 1630 | if ( ! is_wp_error( $response ) ) { |
|
| 1631 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1632 | } |
|
| 1633 | } |
|
| 1634 | ||
| 1635 | return rest_ensure_response( $response ); |
|
| 1636 | } |
|
| 1637 | ||
| 1638 | /** |
|
| 1639 | * Fetch site data from .com including the site's current plan. |
|