| @@ 1565-1587 (lines=23) @@ | ||
| 1562 | * |
|
| 1563 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1564 | */ |
|
| 1565 | public static function get_user_tracking_settings( $request ) { |
|
| 1566 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1567 | $response = array( |
|
| 1568 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1569 | ); |
|
| 1570 | } else { |
|
| 1571 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1572 | '/jetpack-user-tracking', |
|
| 1573 | 'v2', |
|
| 1574 | array( |
|
| 1575 | 'method' => 'GET', |
|
| 1576 | 'headers' => array( |
|
| 1577 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1578 | ), |
|
| 1579 | ) |
|
| 1580 | ); |
|
| 1581 | if ( ! is_wp_error( $response ) ) { |
|
| 1582 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1583 | } |
|
| 1584 | } |
|
| 1585 | ||
| 1586 | return rest_ensure_response( $response ); |
|
| 1587 | } |
|
| 1588 | ||
| 1589 | /** |
|
| 1590 | * Updates current user's tracking settings. |
|
| @@ 1598-1622 (lines=25) @@ | ||
| 1595 | * |
|
| 1596 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1597 | */ |
|
| 1598 | public static function update_user_tracking_settings( $request ) { |
|
| 1599 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1600 | $response = array( |
|
| 1601 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1602 | ); |
|
| 1603 | } else { |
|
| 1604 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1605 | '/jetpack-user-tracking', |
|
| 1606 | 'v2', |
|
| 1607 | array( |
|
| 1608 | 'method' => 'PUT', |
|
| 1609 | 'headers' => array( |
|
| 1610 | 'Content-Type' => 'application/json', |
|
| 1611 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1612 | ), |
|
| 1613 | ), |
|
| 1614 | wp_json_encode( $request->get_params() ) |
|
| 1615 | ); |
|
| 1616 | if ( ! is_wp_error( $response ) ) { |
|
| 1617 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1618 | } |
|
| 1619 | } |
|
| 1620 | ||
| 1621 | return rest_ensure_response( $response ); |
|
| 1622 | } |
|
| 1623 | ||
| 1624 | /** |
|
| 1625 | * Fetch site data from .com including the site's current plan. |
|