Jump to content


WHMCS Technical Analyst
  • Content count

  • Joined

  • Last visited

  • Days Won


WHMCS Josh last won the day on May 9

WHMCS Josh had the most liked content!

Community Reputation

14 Good

About WHMCS Josh

  • Rank
    WHMCS Staff

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. WHMCS Josh

    Mass Delete Spam Clients not working

    Thanks everyone for the feedback! To clarify, this file is not meant to run with the WHMCS hooks system as there is no add_hook() function call being made, so placing it in the /includes/hooks directory may not work. This file was meant to be a one-off solution to be used for removing the mass spam clients that were being created. In order to use it properly, you would simply place the file in your WHMCS root directory and then access the file from your browser to run it. It should provide you with the output of what clients were able to be deleted or which clients were not (if any). You can run the script as many times as needed until all of the spam clients have been removed. When you are done using the script, it should be removed from the server as it does contain code that destroys data (deletes clients). It shouldn't ever be an issue, but to be safe it is good practice to remove utility scripts when they aren't needed anymore. As always, please remember to take a database backup before using this tool.
  2. 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
  3. Hello Remitur, I can confirm that this hook does not block the use of TLDs such as .co.uk because the hook only affects the SLD field on the shopping cart. The TLD field will remain unaffected and allow the user to proceed through the checkout process. I have attached a couple screenshots to show how this looked on my test installation.
  4. When it comes time to order a hosting plan, sometimes you don't want your users to be able to enter in a subdomain when using an existing domain for their order. In this post I am going to walk you through a basic hook that prevents entering a subdomain by using some client-side JavaScript. Our first order of business will be to check out the WHMCS hooks index to see if there is a hook point that will fit our needs: https://developers.whmcs.com/hooks/hook-index/ It turns out, the ClientAreaFooterOutput hook will do nicely: https://developers.whmcs.com/hooks-reference/output/#clientareafooteroutput The reason for this is because that hook point will allow you to inject HTML code, which also can contain JavaScript, into the client-side template so you can make the magic happen. Before getting into more detail, let's go ahead and dive right into the code. You can also download it from this link block_subdomains.txt (then rename the extension to .php). Here is the entire snippet: <?php add_hook('ClientAreaFooterOutput', 1, function($vars) { $jqueryCode = '<script> $("#owndomainsld").on("keyup", function(e) { var str = $("#owndomainsld").val(); if ( str.indexOf(".") != -1 ) { $("#owndomainsld").val(""); alert("Subdomains are not allowed!"); } }); </script>'; if (strpos($_SERVER['REQUEST_URI'], 'cart.php') !== false ) { return $jqueryCode; } }); The first thing to notice is the add_hook function is being called with the ClientAreaFooterOutput hook point as the first argument and an anonymous function as the second argument. The anonymous function also has a $vars variable being passed into it. For this example the $vars variable is not actually being used in the body of the function, but it does contain some useful parameters should you need to access them. Those parameters can be found in the documentation for the hook point linked above. The next thing to notice is the $jqueryCode variable. which is actually a PHP string that contains the JavaScript code we will be injecting into our client-side page. Since WHMCS uses the jQuery JavaScript library and loads it on the page, we can use it in our code. First, we need to bind an event listener to the keyup event on the domain text box and provide it a callback function to execute when that event occurs. This can be easily done by targeting the element's HTML ID attribute. That is what is happening here: $("#owndomainsld").on("keyup", function(e) {... After that, the value of the domain text field is stored in a JavaScript variable called str. Since this code is inside our callback function, it will be executed every time the user presses a key on the keyboard and then releases it: var str = $("#owndomainsld").val(); Once we have that text stored in our str variable, we need to check it for a dot or period '.' character to see if it is a subdomain. This can be done with indexOf string function in JavaScript. If the text appears to be a subdomain, we'll go ahead and empty out the text field and then show an alert to the user to let them know that subdomains are not allowed: if ( str.indexOf(".") != -1 ) { $("#owndomainsld").val(""); alert("Subdomains are not allowed!"); } Finally, the last part of the hook does a case-insensitive string search on the $_SERVER['REQUEST_URI'] (the URL of the page you're visiting), to check and see if a cart page is being rendered. If a cart page is detected, the JavaScript code is injected into that page so it can run. if (strpos($_SERVER['REQUEST_URI'], 'cart.php') !== false ) { return $jqueryCode; } Putting it all together, we get the final results in WHMCS which look like the picture here: I hope this post proved helpful and gives some insight on some of the ways that WHMCS can be extended to do many different things outside the box! At the time of writing this post, this hook was tested on the latest stable release of WHMCS 7.4.2 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!
  5. WHMCS Josh

    Remove Menu Items - v6

    I did some quick testing on my WHMCS installation and was able to get the following hook function working to remove the 'Network Status' submenu item from the 'Support' menu. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support')->removeChild('Network Status'); } }); I simply placed this inside the /includes/hooks directory in a file called remove_network_status.php

Important Information

By using this site, you agree to our Terms of Use & Guidelines