← All changes
|
modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-trait.php
+9
-27
13.8.3
→
16.3-a.7
View file →
| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | /** |
| 12 | 12 | * Bail if accessed directly |
| 13 | 13 | */ |
| 14 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | - exit; | |
| 15 | + exit( 0 ); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Jetpack_WooCommerce_Analytics_Trait |
| @@ -88,9 +88,9 @@ | ||
| 88 | 88 | } |
| 89 | 89 | $products[] = $data; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - return wp_json_encode( $products ); | |
| 92 | + return wp_json_encode( $products, JSON_UNESCAPED_SLASHES ); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * Get Cart/Checkout page view shared data |
| @@ -277,28 +277,8 @@ | ||
| 277 | 277 | $cart_checkout_info = $this->get_cart_checkout_info(); |
| 278 | 278 | return array_merge( $site_info, $cart_checkout_info ); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - /** | |
| 282 | - * Render tracks event properties as string of JavaScript object props. | |
| 283 | - * | |
| 284 | - * @deprecated 13.3 | |
| 285 | - * | |
| 286 | - * @param array $properties Array of key/value pairs. | |
| 287 | - * @return string String of the form "key1: value1, key2: value2, " (etc). | |
| 288 | - */ | |
| 289 | - private function render_properties_as_js( $properties ) { | |
| 290 | - $js_args_string = ''; | |
| 291 | - foreach ( $properties as $key => $value ) { | |
| 292 | - if ( is_array( $value ) ) { | |
| 293 | - $js_args_string = $js_args_string . "'$key': " . wp_json_encode( $value ) . ','; | |
| 294 | - } else { | |
| 295 | - $js_args_string = $js_args_string . "'$key': '" . esc_js( $value ) . "', "; | |
| 296 | - } | |
| 297 | - } | |
| 298 | - return $js_args_string; | |
| 299 | - } | |
| 300 | - | |
| 301 | 281 | /** |
| 302 | 282 | * Record an event with optional product and custom properties. |
| 303 | 283 | * |
| 304 | 284 | * @deprecated 13.3 |
| @@ -400,17 +380,19 @@ | ||
| 400 | 380 | $properties |
| 401 | 381 | ) |
| 402 | 382 | ); |
| 403 | 383 | |
| 404 | - $js = "{'_en': '" . esc_js( $event_name ) . "'"; | |
| 405 | - | |
| 406 | 384 | if ( isset( $product_details ) ) { |
| 407 | 385 | $all_props = array_merge( $all_props, $product_details ); |
| 408 | 386 | } |
| 409 | 387 | |
| 410 | - $js .= ',' . $this->render_properties_as_js( $all_props ) . '}'; | |
| 411 | - | |
| 412 | - return $js; | |
| 388 | + return wp_json_encode( | |
| 389 | + array_merge( | |
| 390 | + array( '_en' => $event_name ), | |
| 391 | + $all_props | |
| 392 | + ), | |
| 393 | + JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP | |
| 394 | + ); | |
| 413 | 395 | } |
| 414 | 396 | |
| 415 | 397 | /** |
| 416 | 398 | * Get the current user id |