| @@ 1712-1734 (lines=23) @@ | ||
| 1709 | * |
|
| 1710 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1711 | */ |
|
| 1712 | public static function get_user_tracking_settings( $request ) { |
|
| 1713 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1714 | $response = array( |
|
| 1715 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1716 | ); |
|
| 1717 | } else { |
|
| 1718 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1719 | '/jetpack-user-tracking', |
|
| 1720 | 'v2', |
|
| 1721 | array( |
|
| 1722 | 'method' => 'GET', |
|
| 1723 | 'headers' => array( |
|
| 1724 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1725 | ), |
|
| 1726 | ) |
|
| 1727 | ); |
|
| 1728 | if ( ! is_wp_error( $response ) ) { |
|
| 1729 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1730 | } |
|
| 1731 | } |
|
| 1732 | ||
| 1733 | return rest_ensure_response( $response ); |
|
| 1734 | } |
|
| 1735 | ||
| 1736 | /** |
|
| 1737 | * Updates current user's tracking settings. |
|
| @@ 1745-1769 (lines=25) @@ | ||
| 1742 | * |
|
| 1743 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1744 | */ |
|
| 1745 | public static function update_user_tracking_settings( $request ) { |
|
| 1746 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1747 | $response = array( |
|
| 1748 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1749 | ); |
|
| 1750 | } else { |
|
| 1751 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1752 | '/jetpack-user-tracking', |
|
| 1753 | 'v2', |
|
| 1754 | array( |
|
| 1755 | 'method' => 'PUT', |
|
| 1756 | 'headers' => array( |
|
| 1757 | 'Content-Type' => 'application/json', |
|
| 1758 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1759 | ), |
|
| 1760 | ), |
|
| 1761 | wp_json_encode( $request->get_params() ) |
|
| 1762 | ); |
|
| 1763 | if ( ! is_wp_error( $response ) ) { |
|
| 1764 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1765 | } |
|
| 1766 | } |
|
| 1767 | ||
| 1768 | return rest_ensure_response( $response ); |
|
| 1769 | } |
|
| 1770 | ||
| 1771 | /** |
|
| 1772 | * Fetch site data from .com including the site's current plan and the site's products. |
|