Ei kuvausta

class-wc-importer-tracking.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * WooCommerce Import Tracking
  4. *
  5. * @package WooCommerce\Tracks
  6. */
  7. defined( 'ABSPATH' ) || exit;
  8. /**
  9. * This class adds actions to track usage of WooCommerce Imports.
  10. */
  11. class WC_Importer_Tracking {
  12. /**
  13. * Init tracking.
  14. */
  15. public function init() {
  16. add_action( 'product_page_product_importer', array( $this, 'track_product_importer' ) );
  17. }
  18. /**
  19. * Route product importer action to the right callback.
  20. *
  21. * @return void
  22. */
  23. public function track_product_importer() {
  24. // phpcs:disable WordPress.Security.NonceVerification.Recommended
  25. if ( ! isset( $_REQUEST['step'] ) ) {
  26. return;
  27. }
  28. if ( 'import' === $_REQUEST['step'] ) {
  29. return $this->track_product_importer_start();
  30. }
  31. if ( 'done' === $_REQUEST['step'] ) {
  32. return $this->track_product_importer_complete();
  33. }
  34. // phpcs:enable
  35. }
  36. /**
  37. * Send a Tracks event when the product importer is started.
  38. *
  39. * @return void
  40. */
  41. public function track_product_importer_start() {
  42. // phpcs:disable WordPress.Security.NonceVerification.Recommended
  43. if ( ! isset( $_REQUEST['file'] ) || ! isset( $_REQUEST['_wpnonce'] ) ) {
  44. return;
  45. }
  46. $properties = array(
  47. 'update_existing' => isset( $_REQUEST['update_existing'] ) ? (bool) $_REQUEST['update_existing'] : false,
  48. 'delimiter' => empty( $_REQUEST['delimiter'] ) ? ',' : wc_clean( wp_unslash( $_REQUEST['delimiter'] ) ),
  49. );
  50. // phpcs:enable
  51. WC_Tracks::record_event( 'product_import_start', $properties );
  52. }
  53. /**
  54. * Send a Tracks event when the product importer has finished.
  55. *
  56. * @return void
  57. */
  58. public function track_product_importer_complete() {
  59. // phpcs:disable WordPress.Security.NonceVerification.Recommended
  60. if ( ! isset( $_REQUEST['nonce'] ) ) {
  61. return;
  62. }
  63. $properties = array(
  64. 'imported' => isset( $_GET['products-imported'] ) ? absint( $_GET['products-imported'] ) : 0,
  65. 'updated' => isset( $_GET['products-updated'] ) ? absint( $_GET['products-updated'] ) : 0,
  66. 'failed' => isset( $_GET['products-failed'] ) ? absint( $_GET['products-failed'] ) : 0,
  67. 'skipped' => isset( $_GET['products-skipped'] ) ? absint( $_GET['products-skipped'] ) : 0,
  68. );
  69. // phpcs:enable
  70. WC_Tracks::record_event( 'product_import_complete', $properties );
  71. }
  72. }