WHMCS Josh Posted April 27, 2018 Share Posted April 27, 2018 An unfortunate trait of the internet is spam and automated bots disseminating that spam. As a business operator on the internet, you may also receive orders submitted in bulk by automated bots. There can be situations where you need to delete lots of clients with the same first name. This small script leverages the local API to cleanly delete all clients who match the specified term. This script is provided as-is, without warranty, and in the understanding for the potential to permanently and irreversibly delete data. Before running this script, please make a database backup: <?php /** * Delete spam clients where the firstname contains 5666Q.COM * using advanced database interaction and the DeleteClient API * * @link https://developers.whmcs.com/advanced/db-interaction/ * @link https://developers.whmcs.com/api-reference/deleteclient/ * * @author WHMCS Limited <development@whmcs.com> * @copyright Copyright (c) WHMCS Limited 2005-2018 * @license https://www.whmcs.com/eula/ WHMCS Eula */ require 'init.php'; use WHMCS\Database\Capsule; // Replace ADMIN_USERNAME with your admin username $adminUsername = 'ADMIN_USERNAME'; echo '<pre>'; // Loop through all clients where firstname contains 5666Q.COM foreach (Capsule::table('tblclients')->where('firstname', 'like', '%5666Q.COM%')->get() as $client) { // Delete the client with DeleteClient API $results = localAPI('DeleteClient', ['clientid' => $client->id], $adminUsername); // Check for errors if ($results['result'] == 'success') { echo "Deleted Client ID: " . $client->id; } else { echo "Error deleting Client ID: " . $client->id; } } echo '</pre>'; Begin by entering your adminstrator's username on line 19: $adminUsername = 'ADMIN_USERNAME'; Upload the script to your WHMCS directory, and visit in your browser. The script will search through all the clients matching the criteria specified in this line: 'firstname', 'like', '%5666Q.COM%' It will then properly and permanently delete matching clients and associated records. The last step is to show which clients are deleted, and if a problem was occurred. The file should then be deleted from your server. At the time of writing this post, this script was tested on the latest stable release of WHMCS 7.5.1 and should work with any that fall under Active Support as per the LTS schedule here: https://docs.whmcs.com/Long_Term_Support#WHMCS_Version_.26_LTS_Schedule If you have any feedback, questions, or concerns that I did not cover in this post, please feel free to reach out! delete_spam_clients.php 2 Quote Link to comment Share on other sites More sharing options...
CoDesk Posted December 13, 2020 Share Posted December 13, 2020 On 27/04/2018 at 8:46 AM, WHMCS Josh said: An unfortunate trait of the internet is spam and automated bots disseminating that spam. As a business operator on the internet, you may also receive orders submitted in bulk by automated bots. There can be situations where you need to delete lots of clients with the same first name. This small script leverages the local API to cleanly delete all clients who match the specified term. This script is provided as-is, without warranty, and in the understanding for the potential to permanently and irreversibly delete data. Before running this script, please make a database backup: <?php /** * Delete spam clients where the firstname contains 5666Q.COM * using advanced database interaction and the DeleteClient API * * @link https://developers.whmcs.com/advanced/db-interaction/ * @link https://developers.whmcs.com/api-reference/deleteclient/ * * @author WHMCS Limited <development@whmcs.com> * @copyright Copyright (c) WHMCS Limited 2005-2018 * @license https://www.whmcs.com/eula/ WHMCS Eula */ require 'init.php'; use WHMCS\Database\Capsule; // Replace ADMIN_USERNAME with your admin username $adminUsername = 'ADMIN_USERNAME'; echo '<pre>'; // Loop through all clients where firstname contains 5666Q.COM foreach (Capsule::table('tblclients')->where('firstname', 'like', '%5666Q.COM%')->get() as $client) { // Delete the client with DeleteClient API $results = localAPI('DeleteClient', ['clientid' => $client->id], $adminUsername); // Check for errors if ($results['result'] == 'success') { echo "Deleted Client ID: " . $client->id; } else { echo "Error deleting Client ID: " . $client->id; } } echo '</pre>'; Begin by entering your adminstrator's username on line 19: $adminUsername = 'ADMIN_USERNAME'; Upload the script to your WHMCS directory, and visit in your browser. The script will search through all the clients matching the criteria specified in this line: 'firstname', 'like', '%5666Q.COM%' It will then properly and permanently delete matching clients and associated records. The last step is to show which clients are deleted, and if a problem was occurred. The file should then be deleted from your server. At the time of writing this post, this script was tested on the latest stable release of WHMCS 7.5.1 and should work with any that fall under Active Support as per the LTS schedule here: https://docs.whmcs.com/Long_Term_Support#WHMCS_Version_.26_LTS_Schedule If you have any feedback, questions, or concerns that I did not cover in this post, please feel free to reach out! delete_spam_clients.php 1.07 kB · 131 downloads Please advice where to upload the file delete_spam_clients.php 0 Quote Link to comment Share on other sites More sharing options...
mystica555 Posted August 23, 2022 Share Posted August 23, 2022 Why can't I just select accounts with checkboxes from "view/search clients" and have the ability to just "delete" and not only "send message"? This functionality should just be there. Why isnt it? 1 Quote Link to comment Share on other sites More sharing options...
jwldub Posted February 15, 2023 Share Posted February 15, 2023 I was able to mass delete 500 at a time in Cpanel, using phpMyAdmin. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.