WC_Privacy::delete_inactive_accounts_query()
Delete inactive accounts.
Метод класса: WC_Privacy{}
Хуки из метода
Возвращает
int
. Count of customers that were deleted.
Использование
$result = WC_Privacy::delete_inactive_accounts_query( $timestamp, $limit );
- $timestamp(int) (обязательный)
- Timestamp to delete customers before.
- $limit(int)
- Limit number of users to delete per run.
По умолчанию: 20
Список изменений
С версии 3.4.0 | Введена. |
Код WC_Privacy::delete_inactive_accounts_query() WC Privacy::delete inactive accounts query WC 9.5.1
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, 0 ); wc_get_logger()->info( sprintf( /* translators: %d user ID. */ __( "User #%d was deleted by WooCommerce in accordance with the site's personal data retention settings. Any content belonging to that user has been retained but unassigned.", 'woocommerce' ), $user_id ) ); $count ++; } } return $count; }