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