| @@ 1326-1348 (lines=23) @@ | ||
| 1323 | * |
|
| 1324 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1325 | */ |
|
| 1326 | public static function get_user_tracking_settings( $request ) { |
|
| 1327 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1328 | $response = array( |
|
| 1329 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1330 | ); |
|
| 1331 | } else { |
|
| 1332 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1333 | '/jetpack-user-tracking', |
|
| 1334 | 'v2', |
|
| 1335 | array( |
|
| 1336 | 'method' => 'GET', |
|
| 1337 | 'headers' => array( |
|
| 1338 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1339 | ), |
|
| 1340 | ) |
|
| 1341 | ); |
|
| 1342 | if ( ! is_wp_error( $response ) ) { |
|
| 1343 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1344 | } |
|
| 1345 | } |
|
| 1346 | ||
| 1347 | return rest_ensure_response( $response ); |
|
| 1348 | } |
|
| 1349 | ||
| 1350 | /** |
|
| 1351 | * Updates current user's tracking settings. |
|
| @@ 1359-1383 (lines=25) @@ | ||
| 1356 | * |
|
| 1357 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1358 | */ |
|
| 1359 | public static function update_user_tracking_settings( $request ) { |
|
| 1360 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1361 | $response = array( |
|
| 1362 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1363 | ); |
|
| 1364 | } else { |
|
| 1365 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1366 | '/jetpack-user-tracking', |
|
| 1367 | 'v2', |
|
| 1368 | array( |
|
| 1369 | 'method' => 'PUT', |
|
| 1370 | 'headers' => array( |
|
| 1371 | 'Content-Type' => 'application/json', |
|
| 1372 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1373 | ), |
|
| 1374 | ), |
|
| 1375 | wp_json_encode( $request->get_params() ) |
|
| 1376 | ); |
|
| 1377 | if ( ! is_wp_error( $response ) ) { |
|
| 1378 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1379 | } |
|
| 1380 | } |
|
| 1381 | ||
| 1382 | return rest_ensure_response( $response ); |
|
| 1383 | } |
|
| 1384 | ||
| 1385 | /** |
|
| 1386 | * Fetch site data from .com including the site's current plan. |
|