Current Location: Home> Latest Articles> Discuz Forum Management: Bulk User Deletion Tips and Code Explanation

Discuz Forum Management: Bulk User Deletion Tips and Code Explanation

M66 2025-07-11

Practical Tips for Bulk User Deletion

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.

Backup Data

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.

Filter Users

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.

Notify 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.

Proceed with Caution

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.

Example Code

Delete Users via SQL Query

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');

Delete Users via Discuz API

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.

Conclusion

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.