| @@ 1089-1111 (lines=23) @@ | ||
| 1086 | * |
|
| 1087 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1088 | */ |
|
| 1089 | public static function get_user_tracking_settings( $request ) { |
|
| 1090 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1091 | $response = array( |
|
| 1092 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1093 | ); |
|
| 1094 | } else { |
|
| 1095 | $response = Jetpack_Client::wpcom_json_api_request_as_user( |
|
| 1096 | '/jetpack-user-tracking', |
|
| 1097 | 'v2', |
|
| 1098 | array( |
|
| 1099 | 'method' => 'GET', |
|
| 1100 | 'headers' => array( |
|
| 1101 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1102 | ), |
|
| 1103 | ) |
|
| 1104 | ); |
|
| 1105 | if ( ! is_wp_error( $response ) ) { |
|
| 1106 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1107 | } |
|
| 1108 | } |
|
| 1109 | ||
| 1110 | return rest_ensure_response( $response ); |
|
| 1111 | } |
|
| 1112 | ||
| 1113 | /** |
|
| 1114 | * Updates current user's tracking settings. |
|
| @@ 1122-1146 (lines=25) @@ | ||
| 1119 | * |
|
| 1120 | * @return WP_REST_Response|WP_Error Response, else error. |
|
| 1121 | */ |
|
| 1122 | public static function update_user_tracking_settings( $request ) { |
|
| 1123 | if ( ! Jetpack::is_user_connected() ) { |
|
| 1124 | $response = array( |
|
| 1125 | 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. |
|
| 1126 | ); |
|
| 1127 | } else { |
|
| 1128 | $response = Jetpack_Client::wpcom_json_api_request_as_user( |
|
| 1129 | '/jetpack-user-tracking', |
|
| 1130 | 'v2', |
|
| 1131 | array( |
|
| 1132 | 'method' => 'PUT', |
|
| 1133 | 'headers' => array( |
|
| 1134 | 'Content-Type' => 'application/json', |
|
| 1135 | 'X-Forwarded-For' => Jetpack::current_user_ip( true ), |
|
| 1136 | ), |
|
| 1137 | ), |
|
| 1138 | wp_json_encode( $request->get_params() ) |
|
| 1139 | ); |
|
| 1140 | if ( ! is_wp_error( $response ) ) { |
|
| 1141 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 1142 | } |
|
| 1143 | } |
|
| 1144 | ||
| 1145 | return rest_ensure_response( $response ); |
|
| 1146 | } |
|
| 1147 | ||
| 1148 | /** |
|
| 1149 | * Fetch site data from .com including the site's current plan. |
|