> first comm 2 jaren geleden KN.js 77628cf8bf first comm 2 jaren geleden KP.js 77628cf8bf first comm 2 jaren geleden KR.js 77628cf8bf first comm 2 jaren geleden KW.js 77628cf8bf first comm 2 jaren geleden KY.js 77628cf8bf first comm 2 jaren geleden KZ.js 77628cf8bf first comm 2 jaren geleden LA.js 77628cf8bf first comm 2 jaren geleden LB.js 77628cf8bf first comm 2 jaren geleden LC.js 77628cf8bf first comm 2 jaren geleden LI.js 77628cf8bf first comm 2 jaren geleden LK.js 77628cf8bf first comm 2 jaren geleden LR.js 77628cf8bf first comm 2 jaren geleden LS.js 77628cf8bf first comm 2 jaren geleden LT.js 77628cf8bf first comm 2 jaren geleden LU.js 77628cf8bf first comm 2 jaren geleden LV.js 77628cf8bf first comm 2 jaren geleden LY.js 77628cf8bf first comm 2 jaren geleden MA.js 77628cf8bf first comm 2 jaren geleden MC.js 77628cf8bf first comm 2 jaren geleden MD.js 77628cf8bf first comm 2 jaren geleden ME.js 77628cf8bf first comm 2 jaren geleden MG.js 77628cf8bf first comm 2 jaren geleden MH.js 77628cf8bf first comm 2 jaren geleden MK.js 77628cf8bf first comm 2 jaren geleden ML.js 77628cf8bf first comm 2 jaren geleden MM.js 77628cf8bf first comm 2 jaren geleden MN.js 77628cf8bf first comm 2 jaren geleden MO.js 77628cf8bf first comm 2 jaren geleden MP.js 77628cf8bf first comm 2 jaren geleden MQ.js 77628cf8bf first comm 2 jaren geleden MR.js 77628cf8bf first comm 2 jaren geleden MS.js 77628cf8bf first comm 2 jaren geleden MT.js 77628cf8bf first comm 2 jaren geleden MU.js 77628cf8bf first comm 2 jaren geleden MV.js 77628cf8bf first comm 2 jaren geleden MW.js 77628cf8bf first comm 2 jaren geleden MX.js 77628cf8bf first comm 2 jaren geleden MY.js 77628cf8bf first comm 2 jaren geleden MZ.js 77628cf8bf first comm 2 jaren geleden NA.js 77628cf8bf first comm 2 jaren geleden NC.js 77628cf8bf first comm 2 jaren geleden NE.js 77628cf8bf first comm 2 jaren geleden NF.js 77628cf8bf first comm 2 jaren geleden NG.js 77628cf8bf first comm 2 jaren geleden NI.js 77628cf8bf first comm 2 jaren geleden NL.js 77628cf8bf first comm 2 jaren geleden NO.js 77628cf8bf first comm 2 jaren geleden NP.js 77628cf8bf first comm 2 jaren geleden NR.js 77628cf8bf first comm 2 jaren geleden NU.js 77628cf8bf first comm 2 jaren geleden NZ.js 77628cf8bf first comm 2 jaren geleden OM.js 77628cf8bf first comm 2 jaren geleden PA.js 77628cf8bf first comm 2 jaren geleden PE.js 77628cf8bf first comm 2 jaren geleden PF.js 77628cf8bf first comm 2 jaren geleden PG.js 77628cf8bf first comm 2 jaren geleden PH.js 77628cf8bf first comm 2 jaren geleden PK.js 77628cf8bf first comm 2 jaren geleden PL.js 77628cf8bf first comm 2 jaren geleden PM.js 77628cf8bf first comm 2 jaren geleden PN.js 77628cf8bf first comm 2 jaren geleden PR.js 77628cf8bf first comm 2 jaren geleden PS.js 77628cf8bf first comm 2 jaren geleden PT.js 77628cf8bf first comm 2 jaren geleden PW.js 77628cf8bf first comm 2 jaren geleden PY.js 77628cf8bf first comm 2 jaren geleden QA.js 77628cf8bf first comm 2 jaren geleden RE.js 77628cf8bf first comm 2 jaren geleden RO.js 77628cf8bf first comm 2 jaren geleden RS.js 77628cf8bf first comm 2 jaren geleden RU.js 77628cf8bf first comm 2 jaren geleden RW.js 77628cf8bf first comm 2 jaren geleden SA.js 77628cf8bf first comm 2 jaren geleden SB.js 77628cf8bf first comm 2 jaren geleden SC.js 77628cf8bf first comm 2 jaren geleden SD.js 77628cf8bf first comm 2 jaren geleden SE.js 77628cf8bf first comm 2 jaren geleden SG.js 77628cf8bf first comm 2 jaren geleden SH.js 77628cf8bf first comm 2 jaren geleden SI.js 77628cf8bf first comm 2 jaren geleden SK.js 77628cf8bf first comm 2 jaren geleden SL.js 77628cf8bf first comm 2 jaren geleden SM.js 77628cf8bf first comm 2 jaren geleden SN.js 77628cf8bf first comm 2 jaren geleden SO.js 77628cf8bf first comm 2 jaren geleden SR.js 77628cf8bf first comm 2 jaren geleden ST.js 77628cf8bf first comm 2 jaren geleden SV.js 77628cf8bf first comm 2 jaren geleden SY.js 77628cf8bf first comm 2 jaren geleden SZ.js 77628cf8bf first comm 2 jaren geleden TC.js 77628cf8bf first comm 2 jaren geleden TD.js 77628cf8bf first comm 2 jaren geleden TG.js 77628cf8bf first comm 2 jaren geleden TH.js 77628cf8bf first comm 2 jaren geleden TJ.js 77628cf8bf first comm 2 jaren geleden TK.js 77628cf8bf first comm 2 jaren geleden TL.js 77628cf8bf first comm 2 jaren geleden TM.js 77628cf8bf first comm 2 jaren geleden TN.js 77628cf8bf first comm 2 jaren geleden TO.js 77628cf8bf first comm 2 jaren geleden TR.js 77628cf8bf first comm 2 jaren geleden TT.js 77628cf8bf first comm 2 jaren geleden TV.js 77628cf8bf first comm 2 jaren geleden TW.js 77628cf8bf first comm 2 jaren geleden TZ.js 77628cf8bf first comm 2 jaren geleden UA.js 77628cf8bf first comm 2 jaren geleden UG.js 77628cf8bf first comm 2 jaren geleden US.js 77628cf8bf first comm 2 jaren geleden UY.js 77628cf8bf first comm 2 jaren geleden UZ.js 77628cf8bf first comm 2 jaren geleden VA.js 77628cf8bf first comm 2 jaren geleden VC.js 77628cf8bf first comm 2 jaren geleden VE.js 77628cf8bf first comm 2 jaren geleden VG.js 77628cf8bf first comm 2 jaren geleden VI.js 77628cf8bf first comm 2 jaren geleden VN.js 77628cf8bf first comm 2 jaren geleden VU.js 77628cf8bf first comm 2 jaren geleden WF.js 77628cf8bf first comm 2 jaren geleden WS.js 77628cf8bf first comm 2 jaren geleden YE.js 77628cf8bf first comm 2 jaren geleden YT.js 77628cf8bf first comm 2 jaren geleden ZA.js 77628cf8bf first comm 2 jaren geleden ZM.js 77628cf8bf first comm 2 jaren geleden ZW.js 77628cf8bf first comm 2 jaren geleden alt-af.js 77628cf8bf first comm 2 jaren geleden alt-an.js 77628cf8bf first comm 2 jaren geleden alt-as.js 77628cf8bf first comm 2 jaren geleden alt-eu.js 77628cf8bf first comm 2 jaren geleden alt-na.js 77628cf8bf first comm 2 jaren geleden alt-oc.js 77628cf8bf first comm 2 jaren geleden alt-sa.js 77628cf8bf first comm 2 jaren geleden alt-ww.js 77628cf8bf first comm 2 jaren geleden tum/whitesports - Gogs: Simplico Git Service

説明なし

class-wc-privacy.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <?php
  2. /**
  3. * Privacy/GDPR related functionality which ties into WordPress functionality.
  4. *
  5. * @since 3.4.0
  6. * @package WooCommerce\Classes
  7. */
  8. defined( 'ABSPATH' ) || exit;
  9. if ( ! class_exists( 'WC_Privacy_Background_Process', false ) ) {
  10. include_once __DIR__ . '/class-wc-privacy-background-process.php';
  11. }
  12. /**
  13. * WC_Privacy Class.
  14. */
  15. class WC_Privacy extends WC_Abstract_Privacy {
  16. /**
  17. * Background process to clean up orders.
  18. *
  19. * @var WC_Privacy_Background_Process
  20. */
  21. protected static $background_process;
  22. /**
  23. * Init - hook into events.
  24. */
  25. public function __construct() {
  26. parent::__construct();
  27. // Initialize data exporters and erasers.
  28. add_action( 'plugins_loaded', array( $this, 'register_erasers_exporters' ) );
  29. // Cleanup orders daily - this is a callback on a daily cron event.
  30. add_action( 'woocommerce_cleanup_personal_data', array( $this, 'queue_cleanup_personal_data' ) );
  31. // Handles custom anonomization types not included in core.
  32. add_filter( 'wp_privacy_anonymize_data', array( $this, 'anonymize_custom_data_types' ), 10, 3 );
  33. // When this is fired, data is removed in a given order. Called from bulk actions.
  34. add_action( 'woocommerce_remove_order_personal_data', array( 'WC_Privacy_Erasers', 'remove_order_personal_data' ) );
  35. }
  36. /**
  37. * Initial registration of privacy erasers and exporters.
  38. *
  39. * Due to the use of translation functions, this should run only after plugins loaded.
  40. */
  41. public function register_erasers_exporters() {
  42. $this->name = __( 'WooCommerce', 'woocommerce' );
  43. if ( ! self::$background_process ) {
  44. self::$background_process = new WC_Privacy_Background_Process();
  45. }
  46. // Include supporting classes.
  47. include_once __DIR__ . '/class-wc-privacy-erasers.php';
  48. include_once __DIR__ . '/class-wc-privacy-exporters.php';
  49. // This hook registers WooCommerce data exporters.
  50. $this->add_exporter( 'woocommerce-customer-data', __( 'WooCommerce Customer Data', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'customer_data_exporter' ) );
  51. $this->add_exporter( 'woocommerce-customer-orders', __( 'WooCommerce Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'order_data_exporter' ) );
  52. $this->add_exporter( 'woocommerce-customer-downloads', __( 'WooCommerce Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'download_data_exporter' ) );
  53. $this->add_exporter( 'woocommerce-customer-tokens', __( 'WooCommerce Customer Payment Tokens', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'customer_tokens_exporter' ) );
  54. // This hook registers WooCommerce data erasers.
  55. $this->add_eraser( 'woocommerce-customer-data', __( 'WooCommerce Customer Data', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'customer_data_eraser' ) );
  56. $this->add_eraser( 'woocommerce-customer-orders', __( 'WooCommerce Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'order_data_eraser' ) );
  57. $this->add_eraser( 'woocommerce-customer-downloads', __( 'WooCommerce Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'download_data_eraser' ) );
  58. $this->add_eraser( 'woocommerce-customer-tokens', __( 'WooCommerce Customer Payment Tokens', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'customer_tokens_eraser' ) );
  59. }
  60. /**
  61. * Add privacy policy content for the privacy policy page.
  62. *
  63. * @since 3.4.0
  64. */
  65. public function get_privacy_message() {
  66. $content = '<div class="wp-suggested-text">' .
  67. '<p class="privacy-policy-tutorial">' .
  68. __( 'This sample language includes the basics around what personal data your store may be collecting, storing and sharing, as well as who may have access to that data. Depending on what settings are enabled and which additional plugins are used, the specific information shared by your store will vary. We recommend consulting with a lawyer when deciding what information to disclose on your privacy policy.', 'woocommerce' ) .
  69. '</p>' .
  70. '<p>' . __( 'We collect information about you during the checkout process on our store.', 'woocommerce' ) . '</p>' .
  71. '<h2>' . __( 'What we collect and store', 'woocommerce' ) . '</h2>' .
  72. '<p>' . __( 'While you visit our site, we’ll track:', 'woocommerce' ) . '</p>' .
  73. '<ul>' .
  74. '<li>' . __( 'Products you’ve viewed: we’ll use this to, for example, show you products you’ve recently viewed', 'woocommerce' ) . '</li>' .
  75. '<li>' . __( 'Location, IP address and browser type: we’ll use this for purposes like estimating taxes and shipping', 'woocommerce' ) . '</li>' .
  76. '<li>' . __( 'Shipping address: we’ll ask you to enter this so we can, for instance, estimate shipping before you place an order, and send you the order!', 'woocommerce' ) . '</li>' .
  77. '</ul>' .
  78. '<p>' . __( 'We’ll also use cookies to keep track of cart contents while you’re browsing our site.', 'woocommerce' ) . '</p>' .
  79. '<p class="privacy-policy-tutorial">' .
  80. __( 'Note: you may want to further detail your cookie policy, and link to that section from here.', 'woocommerce' ) .
  81. '</p>' .
  82. '<p>' . __( 'When you purchase from us, we’ll ask you to provide information including your name, billing address, shipping address, email address, phone number, credit card/payment details and optional account information like username and password. We’ll use this information for purposes, such as, to:', 'woocommerce' ) . '</p>' .
  83. '<ul>' .
  84. '<li>' . __( 'Send you information about your account and order', 'woocommerce' ) . '</li>' .
  85. '<li>' . __( 'Respond to your requests, including refunds and complaints', 'woocommerce' ) . '</li>' .
  86. '<li>' . __( 'Process payments and prevent fraud', 'woocommerce' ) . '</li>' .
  87. '<li>' . __( 'Set up your account for our store', 'woocommerce' ) . '</li>' .
  88. '<li>' . __( 'Comply with any legal obligations we have, such as calculating taxes', 'woocommerce' ) . '</li>' .
  89. '<li>' . __( 'Improve our store offerings', 'woocommerce' ) . '</li>' .
  90. '<li>' . __( 'Send you marketing messages, if you choose to receive them', 'woocommerce' ) . '</li>' .
  91. '</ul>' .
  92. '<p>' . __( 'If you create an account, we will store your name, address, email and phone number, which will be used to populate the checkout for future orders.', 'woocommerce' ) . '</p>' .
  93. '<p>' . __( 'We generally store information about you for as long as we need the information for the purposes for which we collect and use it, and we are not legally required to continue to keep it. For example, we will store order information for XXX years for tax and accounting purposes. This includes your name, email address and billing and shipping addresses.', 'woocommerce' ) . '</p>' .
  94. '<p>' . __( 'We will also store comments or reviews, if you choose to leave them.', 'woocommerce' ) . '</p>' .
  95. '<h2>' . __( 'Who on our team has access', 'woocommerce' ) . '</h2>' .
  96. '<p>' . __( 'Members of our team have access to the information you provide us. For example, both Administrators and Shop Managers can access:', 'woocommerce' ) . '</p>' .
  97. '<ul>' .
  98. '<li>' . __( 'Order information like what was purchased, when it was purchased and where it should be sent, and', 'woocommerce' ) . '</li>' .
  99. '<li>' . __( 'Customer information like your name, email address, and billing and shipping information.', 'woocommerce' ) . '</li>' .
  100. '</ul>' .
  101. '<p>' . __( 'Our team members have access to this information to help fulfill orders, process refunds and support you.', 'woocommerce' ) . '</p>' .
  102. '<h2>' . __( 'What we share with others', 'woocommerce' ) . '</h2>' .
  103. '<p class="privacy-policy-tutorial">' .
  104. __( 'In this section you should list who you’re sharing data with, and for what purpose. This could include, but may not be limited to, analytics, marketing, payment gateways, shipping providers, and third party embeds.', 'woocommerce' ) .
  105. '</p>' .
  106. '<p>' . __( 'We share information with third parties who help us provide our orders and store services to you; for example --', 'woocommerce' ) . '</p>' .
  107. '<h3>' . __( 'Payments', 'woocommerce' ) . '</h3>' .
  108. '<p class="privacy-policy-tutorial">' .
  109. __( 'In this subsection you should list which third party payment processors you’re using to take payments on your store since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'woocommerce' ) .
  110. '</p>' .
  111. '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'woocommerce' ) . '</p>' .
  112. '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'woocommerce' ) . '</p>' .
  113. '</div>';
  114. return apply_filters( 'wc_privacy_policy_content', $content );
  115. }
  116. /**
  117. * Spawn events for order cleanup.
  118. */
  119. public function queue_cleanup_personal_data() {
  120. self::$background_process->push_to_queue( array( 'task' => 'trash_pending_orders' ) );
  121. self::$background_process->push_to_queue( array( 'task' => 'trash_failed_orders' ) );
  122. self::$background_process->push_to_queue( array( 'task' => 'trash_cancelled_orders' ) );
  123. self::$background_process->push_to_queue( array( 'task' => 'anonymize_completed_orders' ) );
  124. self::$background_process->push_to_queue( array( 'task' => 'delete_inactive_accounts' ) );
  125. self::$background_process->save()->dispatch();
  126. }
  127. /**
  128. * Handle some custom types of data and anonymize them.
  129. *
  130. * @param string $anonymous Anonymized string.
  131. * @param string $type Type of data.
  132. * @param string $data The data being anonymized.
  133. * @return string Anonymized string.
  134. */
  135. public function anonymize_custom_data_types( $anonymous, $type, $data ) {
  136. switch ( $type ) {
  137. case 'address_state':
  138. case 'address_country':
  139. $anonymous = ''; // Empty string - we don't want to store anything after removal.
  140. break;
  141. case 'phone':
  142. $anonymous = preg_replace( '/\d/u', '0', $data );
  143. break;
  144. case 'numeric_id':
  145. $anonymous = 0;
  146. break;
  147. }
  148. return $anonymous;
  149. }
  150. /**
  151. * Find and trash old orders.
  152. *
  153. * @since 3.4.0
  154. * @param int $limit Limit orders to process per batch.
  155. * @return int Number of orders processed.
  156. */
  157. public static function trash_pending_orders( $limit = 20 ) {
  158. $option = wc_parse_relative_date_option( get_option( 'woocommerce_trash_pending_orders' ) );
  159. if ( empty( $option['number'] ) ) {
  160. return 0;
  161. }
  162. return self::trash_orders_query(
  163. apply_filters(
  164. 'woocommerce_trash_pending_orders_query_args',
  165. array(
  166. 'date_created' => '<' . strtotime( '-' . $option['number'] . ' ' . $option['unit'] ),
  167. 'limit' => $limit, // Batches of 20.
  168. 'status' => 'wc-pending',
  169. 'type' => 'shop_order',
  170. )
  171. )
  172. );
  173. }
  174. /**
  175. * Find and trash old orders.
  176. *
  177. * @since 3.4.0
  178. * @param int $limit Limit orders to process per batch.
  179. * @return int Number of orders processed.
  180. */
  181. public static function trash_failed_orders( $limit = 20 ) {
  182. $option = wc_parse_relative_date_option( get_option( 'woocommerce_trash_failed_orders' ) );
  183. if ( empty( $option['number'] ) ) {
  184. return 0;
  185. }
  186. return self::trash_orders_query(
  187. apply_filters(
  188. 'woocommerce_trash_failed_orders_query_args',
  189. array(
  190. 'date_created' => '<' . strtotime( '-' . $option['number'] . ' ' . $option['unit'] ),
  191. 'limit' => $limit, // Batches of 20.
  192. 'status' => 'wc-failed',
  193. 'type' => 'shop_order',
  194. )
  195. )
  196. );
  197. }
  198. /**
  199. * Find and trash old orders.
  200. *
  201. * @since 3.4.0
  202. * @param int $limit Limit orders to process per batch.
  203. * @return int Number of orders processed.
  204. */
  205. public static function trash_cancelled_orders( $limit = 20 ) {
  206. $option = wc_parse_relative_date_option( get_option( 'woocommerce_trash_cancelled_orders' ) );
  207. if ( empty( $option['number'] ) ) {
  208. return 0;
  209. }
  210. return self::trash_orders_query(
  211. apply_filters(
  212. 'woocommerce_trash_cancelled_orders_query_args',
  213. array(
  214. 'date_created' => '<' . strtotime( '-' . $option['number'] . ' ' . $option['unit'] ),
  215. 'limit' => $limit, // Batches of 20.
  216. 'status' => 'wc-cancelled',
  217. 'type' => 'shop_order',
  218. )
  219. )
  220. );
  221. }
  222. /**
  223. * For a given query trash all matches.
  224. *
  225. * @since 3.4.0
  226. * @param array $query Query array to pass to wc_get_orders().
  227. * @return int Count of orders that were trashed.
  228. */
  229. protected static function trash_orders_query( $query ) {
  230. $orders = wc_get_orders( $query );
  231. $count = 0;
  232. if ( $orders ) {
  233. foreach ( $orders as $order ) {
  234. $order->delete( false );
  235. $count ++;
  236. }
  237. }
  238. return $count;
  239. }
  240. /**
  241. * Anonymize old completed orders.
  242. *
  243. * @since 3.4.0
  244. * @param int $limit Limit orders to process per batch.
  245. * @return int Number of orders processed.
  246. */
  247. public static function anonymize_completed_orders( $limit = 20 ) {
  248. $option = wc_parse_relative_date_option( get_option( 'woocommerce_anonymize_completed_orders' ) );
  249. if ( empty( $option['number'] ) ) {
  250. return 0;
  251. }
  252. return self::anonymize_orders_query(
  253. apply_filters(
  254. 'woocommerce_anonymize_completed_orders_query_args',
  255. array(
  256. 'date_created' => '<' . strtotime( '-' . $option['number'] . ' ' . $option['unit'] ),
  257. 'limit' => $limit, // Batches of 20.
  258. 'status' => 'wc-completed',
  259. 'anonymized' => false,
  260. 'type' => 'shop_order',
  261. )
  262. )
  263. );
  264. }
  265. /**
  266. * For a given query, anonymize all matches.
  267. *
  268. * @since 3.4.0
  269. * @param array $query Query array to pass to wc_get_orders().
  270. * @return int Count of orders that were anonymized.
  271. */
  272. protected static function anonymize_orders_query( $query ) {
  273. $orders = wc_get_orders( $query );
  274. $count = 0;
  275. if ( $orders ) {
  276. foreach ( $orders as $order ) {
  277. WC_Privacy_Erasers::remove_order_personal_data( $order );
  278. $count ++;
  279. }
  280. }
  281. return $count;
  282. }
  283. /**
  284. * Delete inactive accounts.
  285. *
  286. * @since 3.4.0
  287. * @param int $limit Limit users to process per batch.
  288. * @return int Number of users processed.
  289. */
  290. public static function delete_inactive_accounts( $limit = 20 ) {
  291. $option = wc_parse_relative_date_option( get_option( 'woocommerce_delete_inactive_accounts' ) );
  292. if ( empty( $option['number'] ) ) {
  293. return 0;
  294. }
  295. return self::delete_inactive_accounts_query( strtotime( '-' . $option['number'] . ' ' . $option['unit'] ), $limit );
  296. }
  297. /**
  298. * Delete inactive accounts.
  299. *
  300. * @since 3.4.0
  301. * @param int $timestamp Timestamp to delete customers before.
  302. * @param int $limit Limit number of users to delete per run.
  303. * @return int Count of customers that were deleted.
  304. */
  305. protected static function delete_inactive_accounts_query( $timestamp, $limit = 20 ) {
  306. $count = 0;
  307. $user_query = new WP_User_Query(
  308. array(
  309. 'fields' => 'ID',
  310. 'number' => $limit,
  311. 'role__in' => apply_filters(
  312. 'woocommerce_delete_inactive_account_roles',
  313. array(
  314. 'Customer',
  315. 'Subscriber',
  316. )
  317. ),
  318. 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
  319. 'relation' => 'AND',
  320. array(
  321. 'key' => 'wc_last_active',
  322. 'value' => (string) $timestamp,
  323. 'compare' => '<',
  324. 'type' => 'NUMERIC',
  325. ),
  326. array(
  327. 'key' => 'wc_last_active',
  328. 'value' => '0',
  329. 'compare' => '>',
  330. 'type' => 'NUMERIC',
  331. ),
  332. ),
  333. )
  334. );
  335. $user_ids = $user_query->get_results();
  336. if ( $user_ids ) {
  337. if ( ! function_exists( 'wp_delete_user' ) ) {
  338. require_once ABSPATH . 'wp-admin/includes/user.php';
  339. }
  340. foreach ( $user_ids as $user_id ) {
  341. wp_delete_user( $user_id );
  342. $count ++;
  343. }
  344. }
  345. return $count;
  346. }
  347. }
  348. new WC_Privacy();