When managing a Discuz forum, administrators may encounter situations that require bulk user deletion, such as clearing spam accounts or malicious users. However, Discuz does not provide a direct bulk delete feature in the backend. This article introduces some practical tips and specific code examples to help you effectively delete unnecessary users.
Before performing any bulk deletion operations, make sure to back up the database. Backing up data ensures that you can recover it if something goes wrong, avoiding unnecessary losses.
Before performing bulk deletion, it is recommended to filter users based on specific criteria such as registration date, post count, and last login time. Ensure that only users who meet the conditions are deleted, to avoid mistakenly deleting normal users.
If user deletion is necessary, consider notifying the users in advance through internal messages or announcements, giving them time to take action. This helps prevent disputes arising from sudden user deletions.
When performing bulk deletion, be extra cautious. It is strongly advised to first test the process in a test environment, ensuring everything works correctly before executing it in the live environment.
Administrators can use SQL queries to bulk delete users. Below is an example SQL query that deletes users who registered before a specific date:
DELETE
FROM
pre_common_member
WHERE
regdate < UNIX_TIMESTAMP(
'2022-01-01'
);
Discuz offers management APIs that can be used with a simple PHP script to delete users in bulk. Below is an example PHP script that uses the Discuz API to delete users who registered before a specific date:
<?php
define(
'IN_DISCUZ'
, true);
require
'./source/class/class_core.php'
;
$discuz
= C::app();
$discuz
->init();
$users
= C::t(
'common_member'
)->fetch_all_by_regdate(0, UNIX_TIMESTAMP(
'2022-01-01'
));
foreach
(
$users
as
$user
) {
C::t(
'common_member'
)->
delete
(
$user
[
'uid'
]);
}
This example code is for reference purposes, and should be customized as per your specific requirements.
By following the tips and examples provided in this article, administrators can efficiently perform bulk deletions of unwanted users, improving the management efficiency of their forum. Always proceed with caution to ensure data safety and a good user experience, so that the forum remains well-managed and runs smoothly.