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