WC_Privacy::delete_inactive_accounts_query( int $timestamp, int $limit = 20 )
Delete inactive accounts.
Description Description
Parameters Parameters
- $timestamp
-
(Required) Timestamp to delete customers before.
- $limit
-
(Optional) Limit number of users to delete per run.
Default value: 20
Return Return
(int) Count of customers that were deleted.
Source Source
File: includes/class-wc-privacy.php
protected static function delete_inactive_accounts_query( $timestamp, $limit = 20 ) { $count = 0; $user_query = new WP_User_Query( array( 'fields' => 'ID', 'number' => $limit, 'role__in' => apply_filters( 'woocommerce_delete_inactive_account_roles', array( 'Customer', 'Subscriber', ) ), 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query 'relation' => 'AND', array( 'key' => 'wc_last_active', 'value' => (string) $timestamp, 'compare' => '<', 'type' => 'NUMERIC', ), array( 'key' => 'wc_last_active', 'value' => '0', 'compare' => '>', 'type' => 'NUMERIC', ), ), ) ); $user_ids = $user_query->get_results(); if ( $user_ids ) { if ( ! function_exists( 'wp_delete_user' ) ) { require_once ABSPATH . 'wp-admin/includes/user.php'; } foreach ( $user_ids as $user_id ) { wp_delete_user( $user_id ); $count ++; } } return $count; }
Changelog Changelog
Version | Description |
---|---|
3.4.0 | Introduced. |