| @@ 946-968 (lines=23) @@ | ||
| 943 | * |
|
| 944 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 945 | */ |
|
| 946 | public static function get_user_tracking_settings( $request ) { |
|
| 947 | if ( ! Jetpack::is_user_connected() ) { |
|
| 948 | $response = array( |
|
| 949 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 950 | ); |
|
| 951 | } else { |
|
| 952 | $response = Jetpack_Client::wpcom_json_api_request_as_user( |
|
| 953 | '/jetpack-user-tracking', |
|
| 954 | 'v2', |
|
| 955 | array( |
|
| 956 | 'method' => 'GET', |
|
| 957 | 'headers' => array( |
|
| 958 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 959 | ), |
|
| 960 | ) |
|
| 961 | ); |
|
| 962 | if ( ! is_wp_error( $response ) ) { |
|
| 963 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 964 | } |
|
| 965 | } |
|
| 966 | ||
| 967 | return rest_ensure_response( $response ); |
|
| 968 | } |
|
| 969 | ||
| 970 | /** |
|
| 971 | * Updates current user's tracking settings. |
|
| @@ 979-1003 (lines=25) @@ | ||
| 976 | * |
|
| 977 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 978 | */ |
|
| 979 | public static function update_user_tracking_settings( $request ) { |
|
| 980 | if ( ! Jetpack::is_user_connected() ) { |
|
| 981 | $response = array( |
|
| 982 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 983 | ); |
|
| 984 | } else { |
|
| 985 | $response = Jetpack_Client::wpcom_json_api_request_as_user( |
|
| 986 | '/jetpack-user-tracking', |
|
| 987 | 'v2', |
|
| 988 | array( |
|
| 989 | 'method' => 'PUT', |
|
| 990 | 'headers' => array( |
|
| 991 | 'Content-Type' => 'application/json', |
|
| 992 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 993 | ), |
|
| 994 | ), |
|
| 995 | wp_json_encode( $request->get_params() ) |
|
| 996 | ); |
|
| 997 | if ( ! is_wp_error( $response ) ) { |
|
| 998 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 999 | } |
|
| 1000 | } |
|
| 1001 | ||
| 1002 | return rest_ensure_response( $response ); |
|
| 1003 | } |
|
| 1004 | ||
| 1005 | /** |
|
| 1006 | * Fetch site data from .com including the site's current plan. |
|