| @@ 1284-1306 (lines=23) @@ | ||
| 1281 | * |
|
| 1282 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1283 | */ |
|
| 1284 | public static function get_user_tracking_settings( $request ) { |
|
| 1285 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1286 | $response = array( |
|
| 1287 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1288 | ); |
|
| 1289 | } else { |
|
| 1290 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1291 | '/jetpack-user-tracking', |
|
| 1292 | 'v2', |
|
| 1293 | array( |
|
| 1294 | 'method' => 'GET', |
|
| 1295 | 'headers' => array( |
|
| 1296 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1297 | ), |
|
| 1298 | ) |
|
| 1299 | ); |
|
| 1300 | if ( ! is_wp_error( $response ) ) { |
|
| 1301 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1302 | } |
|
| 1303 | } |
|
| 1304 | ||
| 1305 | return rest_ensure_response( $response ); |
|
| 1306 | } |
|
| 1307 | ||
| 1308 | /** |
|
| 1309 | * Updates current user's tracking settings. |
|
| @@ 1317-1341 (lines=25) @@ | ||
| 1314 | * |
|
| 1315 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1316 | */ |
|
| 1317 | public static function update_user_tracking_settings( $request ) { |
|
| 1318 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1319 | $response = array( |
|
| 1320 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1321 | ); |
|
| 1322 | } else { |
|
| 1323 | $response = Client::wpcom_json_api_request_as_user( |
|
| 1324 | '/jetpack-user-tracking', |
|
| 1325 | 'v2', |
|
| 1326 | array( |
|
| 1327 | 'method' => 'PUT', |
|
| 1328 | 'headers' => array( |
|
| 1329 | 'Content-Type' => 'application/json', |
|
| 1330 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1331 | ), |
|
| 1332 | ), |
|
| 1333 | wp_json_encode( $request->get_params() ) |
|
| 1334 | ); |
|
| 1335 | if ( ! is_wp_error( $response ) ) { |
|
| 1336 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1337 | } |
|
| 1338 | } |
|
| 1339 | ||
| 1340 | return rest_ensure_response( $response ); |
|
| 1341 | } |
|
| 1342 | ||
| 1343 | /** |
|
| 1344 | * Fetch site data from .com including the site's current plan. |
|