| @@ 1245-1267 (lines=23) @@ | ||
| 1242 | * |
|
| 1243 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1244 | */ |
|
| 1245 | public static function get_user_tracking_settings( $request ) { |
|
| 1246 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1247 | $response = array( |
|
| 1248 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1249 | ); |
|
| 1250 | } else { |
|
| 1251 | $response = Jetpack_Client::wpcom_json_api_request_as_user( |
|
| 1252 | '/jetpack-user-tracking', |
|
| 1253 | 'v2', |
|
| 1254 | array( |
|
| 1255 | 'method' => 'GET', |
|
| 1256 | 'headers' => array( |
|
| 1257 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1258 | ), |
|
| 1259 | ) |
|
| 1260 | ); |
|
| 1261 | if ( ! is_wp_error( $response ) ) { |
|
| 1262 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1263 | } |
|
| 1264 | } |
|
| 1265 | ||
| 1266 | return rest_ensure_response( $response ); |
|
| 1267 | } |
|
| 1268 | ||
| 1269 | /** |
|
| 1270 | * Updates current user's tracking settings. |
|
| @@ 1278-1302 (lines=25) @@ | ||
| 1275 | * |
|
| 1276 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1277 | */ |
|
| 1278 | public static function update_user_tracking_settings( $request ) { |
|
| 1279 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1280 | $response = array( |
|
| 1281 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1282 | ); |
|
| 1283 | } else { |
|
| 1284 | $response = Jetpack_Client::wpcom_json_api_request_as_user( |
|
| 1285 | '/jetpack-user-tracking', |
|
| 1286 | 'v2', |
|
| 1287 | array( |
|
| 1288 | 'method' => 'PUT', |
|
| 1289 | 'headers' => array( |
|
| 1290 | 'Content-Type' => 'application/json', |
|
| 1291 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1292 | ), |
|
| 1293 | ), |
|
| 1294 | wp_json_encode( $request->get_params() ) |
|
| 1295 | ); |
|
| 1296 | if ( ! is_wp_error( $response ) ) { |
|
| 1297 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1298 | } |
|
| 1299 | } |
|
| 1300 | ||
| 1301 | return rest_ensure_response( $response ); |
|
| 1302 | } |
|
| 1303 | ||
| 1304 | /** |
|
| 1305 | * Fetch site data from .com including the site's current plan. |
|