PUQ Mautic

Code Snippets WHMCS Addon

WHMCS addon module for injecting custom HTML, CSS, and JavaScript code into client area and admin area pages. Features CodeMirror editor, page/user/product targeting, custom URL patterns, scheduling, version history with rollback, emergency kill switch, and import/export.

Description

Code Snippets addon WHMCS

Order now | Download | FAQ

PUQ Code Snippets — WHMCS Addon

PUQ Code Snippets is an addon module for WHMCS that lets you inject custom HTML, CSS, and JavaScript code into the client area and admin area pages — without editing any template files. Manage unlimited snippets with a built-in CodeMirror code editor, advanced page/user/product targeting, scheduling, version history with one-click rollback, and an emergency kill switch.


Key Features


Use Cases


System Requirements

Requirement Minimum
WHMCS 8.x, 9.x
PHP 8.1, 8.2+
ionCube Loader v13 or newer (v14, v15)

Changelog

Code Snippets addon WHMCS

Order now | Download | FAQ

v1.0 — 2026-02-16

First release.

New Features

Installation and Update

Code Snippets addon WHMCS

Order now | Download | FAQ

System Requirements

Requirement Minimum
PHP 8.1, 8.2 or newer
WHMCS 8.x, 9.x or newer
ionCube Loader v13 or newer (v14, v15)

Note: The module uses ionCube encoding. Make sure ionCube Loader is installed and active on your server.


Download

The module can be ordered and downloaded from PUQ Cloud:

PHP 8.1:

wget https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/php81/PUQ_WHMCS-Code-Snippets-latest.zip

PHP 8.2+:

wget https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/php82/PUQ_WHMCS-Code-Snippets-latest.zip

All versions are available at: https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/

After downloading, extract the archive:

unzip PUQ_WHMCS-Code-Snippets-latest.zip

Installation

Step 1: Upload Files

Extract the module archive and upload the puq_code_snippets directory to the WHMCS addons directory:

/your-whmcs/modules/addons/puq_code_snippets/

Directory structure after upload:

modules/addons/puq_code_snippets/
    puq_code_snippets.php
    hooks.php
    whmcs.json
    version
    logo.png
    lib/
        puqCodeSnippets.php
    lang/
        english.php
    templates/
        ...

Step 2: Activate the Module

  1. Log in to the WHMCS admin panel
  2. Go to Setup > Addon Modules
  3. Find PUQ Code Snippets in the list
  4. Click Activate

On activation, the module creates three database tables: puq_code_snippets, puq_code_snippets_settings, and puq_code_snippets_history.

Step 3: Configure the License Key

  1. After activation, click Configure next to the module
  2. Enter your license key in the License key field
  3. Select admin role groups that should have access to the module
  4. Click Save Changes

After saving, a verification status will appear below the license key field (e.g., success: 2027-02-16T21:32:28+01:00).

Module configuration with license key and access control 01-addon-config-license.png

Step 4: Access the Module

Go to Addons > PUQ Code Snippets to access the dashboard.


Update

Step 1: Backup

Before updating, we recommend backing up:

Tip: Use the Export feature in Settings to save all your snippets before updating.

Step 2: Upload New Files

Extract the new version and overwrite all files in:

/your-whmcs/modules/addons/puq_code_snippets/

Step 3: Re-activate (if needed)

If the update adds new database columns, deactivate and re-activate the module:

  1. Go to Setup > Addon Modules
  2. Click Deactivate, then Activate again

This is safe — the module only creates tables/columns if they don't already exist. Your snippets and settings are preserved.

Step 4: Verify

  1. Go to Addons > PUQ Code Snippets
  2. Check the version number in the top-right corner of the navigation bar (e.g., v1.0)

Deactivation

  1. Go to Setup > Addon Modules
  2. Click Deactivate next to PUQ Code Snippets
  3. Confirm the deactivation

Warning: Deactivation drops the module's database tables (puq_code_snippets, puq_code_snippets_settings, puq_code_snippets_history). All your snippets, settings, and history will be lost. Export your snippets before deactivating if you want to preserve them.


License

The module requires an active license for full functionality. The license is verified through the PUQ Cloud license server.

How License Verification Works

Without an Active License

After Activating a License

  1. The warning banner disappears
  2. All pages and features become accessible
  3. Enter your license key in Setup > Addon Modules > PUQ Code Snippets > Configure

Purchase a License

https://puqcloud.com/store/whmcs-addon-modules

https://puqcloud.com/submitticket.php

Dashboard

Code Snippets addon WHMCS

Order now | Download | FAQ

The Dashboard is the home page of the module, available at: Addons > PUQ Code Snippets > Dashboard

It provides a complete overview of all your code snippets — key metrics, distribution charts, and a log of recent changes.

Dashboard — metrics, charts, and recent changes 02-dashboard.png


Key Metrics

The top section displays four summary cards:

Metric Description
Total Snippets Total number of snippets in the system
Active Snippets Snippets that are currently enabled and will be injected
Inactive Snippets Snippets that are disabled
Scheduled Snippets Snippets with a future start date or an active date range

Snippets by Area

A horizontal bar chart showing the distribution of snippets across target areas:


Snippets by Position

A horizontal bar chart showing the distribution by injection position:


Recent Changes

A table showing the latest snippet modifications:

Column Description
Date Timestamp of the change
Action Type of change: Created, Updated, Deleted, Toggled, Restored, Imported
Snippet Name of the affected snippet
Admin Administrator who made the change

This section helps you quickly see what's been modified recently without navigating to the full History page.


Kill Switch Warning

If the kill switch is active (via database setting or flag file), a prominent red alert banner appears at the top of the dashboard warning that all snippets are currently disabled. See Settings for details on the kill switch.

Snippets

Code Snippets addon WHMCS

Order now | Download | FAQ

The Snippets section is available at: Addons > PUQ Code Snippets > Snippets

This is where you manage all your code snippets — view, filter, create, edit, toggle, duplicate, and delete.

Snippets list — all snippets with filtering and actions 03-snippets-list.png


Navigation Menu

The Snippets dropdown menu provides quick access to filtered views:

Snippets dropdown menu 06-snippets-menu.png

Menu Item Description
All Snippets Show all snippets regardless of area or status
Add New Create a new snippet
Client Area Show only snippets targeting the Client Area
Admin Area Show only snippets targeting the Admin Area
Active Show only enabled snippets
Inactive Show only disabled snippets
Scheduled Show only snippets with scheduling configured

Snippets List

The main table displays all snippets with sortable columns:

Column Description
# Priority number (lower = rendered first)
Status icon Color indicator — enabled or disabled
Name Snippet name and description
Position Injection position: Head, After, Before
Area Target area badge: CLIENT (blue), ADMIN (green), BOTH (purple)
User Targeting Who sees the snippet: All, Logged-in, Guests, Client Group
Schedule Date range or "Always" if no schedule is set
Status ENABLED (green) or DISABLED (grey) badge
Actions Action buttons (see below)

Actions

Each snippet has three action buttons:

Button Description
Edit (pencil icon) Open the snippet editor
Toggle (power icon) Enable/disable the snippet with one click
Delete (trash icon) Delete the snippet (with confirmation dialog)

Use the search field in the top-right corner to filter snippets by name or description. The search works client-side and filters the table in real time.


Add New Snippet

Click the + Add New button to open the snippet editor and create a new snippet. See Snippet Editor for details on all available settings.

Snippet Editor

Code Snippets addon WHMCS

Order now | Download | FAQ

The Snippet Editor is available at: Addons > PUQ Code Snippets > Snippets > Add New or Edit

This page is where you create and edit code snippets. It provides a full-featured code editor and all targeting options in a single, organized view.

Snippet Editor — settings, targeting, and code editor (top) 04-snippet-editor-top.png

Snippet Editor — area, custom URL patterns, schedule, and code editor (bottom) 05-snippet-editor-bottom.png


Page Layout

The editor is organized in three columns with the code editor below:

Column Sections
Left Settings, Position, Area
Middle Page Targeting
Right User Targeting, Product Targeting, Schedule
Bottom Code Editor (full width)

Settings

Field Description
Snippet Name A descriptive name for the snippet (required)
Description Optional description for reference
Status Enabled or Disabled
Priority Numeric value — lower numbers are rendered first (default: 0)

Position

Choose where the code is injected on the page:

Position Description Best For
Inside <head> tag Inserted inside the <head> section CSS, meta tags, analytics scripts, SEO tags
After opening <body> tag Inserted right after <body> Top banners, GTM noscript blocks, cookie consent
Before closing </body> tag Inserted right before </body> Chat widgets, tracking pixels, JavaScript

Area

Choose which WHMCS area the snippet targets:

Area Description
Client Area Only visible on client-facing pages (storefront, client portal)
Admin Area Only visible in the admin panel
Both Areas Visible on both client and admin pages

When Admin Area is selected, the User Targeting and Product Targeting panels are hidden since admin users are always authenticated.


Page Targeting

By default, a snippet is rendered on all pages in the selected area. To restrict it to specific pages, check the pages you want.

Rule: None selected = all pages. Any selection = only those pages.

Client Area Pages

Organized by groups:

Group Pages
General Homepage, Client Dashboard, Login, Registration, Password Reset
Account My Details, Contacts, Change Password, Security, Payment Methods, My Emails
Services My Services, Product Details, My Domains, Domain Details, Add Funds, Upgrade
Billing My Invoices, View Invoice, Quotes, View Quote, Credit Card
Support Tickets List, View Ticket, Submit Ticket, Knowledge Base, Announcements, Network Issues
Shopping Cart / Order Form, Cart Checkout, Cart Addons, Domain Checker
Other Contact Us, Server Status, Downloads, Affiliates, Mass Domain Mgmt

Admin Area Pages

Organized by groups:

Group Pages
Dashboard Dashboard, Search, System Health
Clients Clients List, Client Summary, Client Profile, Client Contacts, Client (route)
Client Management Products/Services, Domains, Client Invoices, Client Credits, Client Emails, Client Notes, Activity Log, Billable Items, Client Quotes, Client Transactions
Billing Orders, Invoices, Transactions, Quotes, Billable Items, Billing (route)
Support Support Tickets, View Ticket, Predefined Replies, Escalations
Setup / Config General Settings, Products Setup, Addon Modules, Administrators, Servers, Registrars, Automation, Payment Gateways, Setup (route)
Utilities / Logs Utilities, Module Log, Logs (route)

Use the Select All / Deselect All links at the top of each section to quickly check or uncheck all pages.

Custom URL Patterns

For pages not covered by the checkboxes, use the Custom URL Patterns textarea at the bottom of the Page Targeting panel.

Enter one pattern per line. The snippet fires if the request URL contains the pattern string.

Examples:

/billing/invoice
configauto.php
/client/1/tickets
/store/web-hosting

This works for both Client Area and Admin Area URLs, including WHMCS friendly URLs and admin route-based URLs.


User Targeting

Control who sees the snippet (only visible when area is Client Area or Both):

Option Description
All Visitors Everyone — logged-in clients and guests
Logged-in Clients Only Only authenticated clients
Guests Only Only unauthenticated visitors
Specific Client Groups Only clients belonging to selected WHMCS client groups

When Specific Client Groups is selected, a multi-select dropdown appears with all client groups from WHMCS. Hold Ctrl/Cmd to select multiple groups.


Product Targeting

Show or hide the snippet based on the client's active products/services (only visible when area is Client Area or Both):

Option Description
All (no product filtering) No product-based filtering applied
Client HAS active service Show only to clients who have an active or suspended service for the selected products
Client does NOT have active service Show only to clients who do NOT have the selected products

When a product filter is selected, a multi-select dropdown appears with all products from WHMCS, organized by product group.

Note: Product targeting only works for logged-in clients in the Client Area. Guests are treated as "not having" any product.


Schedule

Set a time range for the snippet to be active:

Field Description
Schedule Start The snippet will not render before this date/time
Schedule End The snippet will stop rendering after this date/time

Leave both fields empty for the snippet to be active at all times (as long as its status is Enabled).

Use cases:


Code Editor

The code editor uses CodeMirror 5 with full HTML/CSS/JavaScript support.

Editor Features

What Code Can You Inject?

You can inject any valid HTML, including:

<!-- CSS styles -->
<style>
  .my-banner { background: #ff6600; color: white; padding: 10px; text-align: center; }
</style>

<!-- HTML content -->
<div class="my-banner">Special offer! Use code SAVE20 for 20% off.</div>

<!-- JavaScript -->
<script>
  console.log('Snippet loaded!');
</script>

<!-- External scripts -->
<script src="https://example.com/widget.js" async></script>

<!-- Meta tags (for head position) -->
<meta name="description" content="My WHMCS site">

Warning: Be careful with the code you inject. Malicious or broken code can break your WHMCS pages. Always test snippets in a development environment first. Use the kill switch if something goes wrong.

History

Code Snippets addon WHMCS

Order now | Download | FAQ

The History page is available at: Addons > PUQ Code Snippets > History > All Changes

It provides a complete audit log of all snippet changes with diff view and one-click rollback.

History — complete log of all snippet changes 07-history.png


History Log

The main table displays all recorded changes:

Column Description
# Record number
Date Timestamp of the change
Action Type of change (see below)
Snippet Name of the affected snippet
Description Snippet description at the time of the change
Admin Administrator who made the change
Actions View Diff and Rollback buttons

Action Types

Action Description
Created A new snippet was created
Updated An existing snippet was modified
Deleted A snippet was deleted
Toggled A snippet was enabled or disabled
Restored A snippet was rolled back to a previous version
Imported A snippet was imported from a JSON file

View Diff

Click the View Diff button to see a side-by-side comparison of the code before and after the change.

View Diff — side-by-side code comparison 08-history-diff.png

The diff modal shows:

Panel Description
Before The snippet code before the change
After The snippet code after the change

This helps you understand exactly what was changed and review modifications made by other administrators.


Rollback

Click the Rollback button to restore a snippet to a previous version. A confirmation dialog appears before the rollback is executed.

The rollback:

Tip: Use rollback when a snippet update breaks something — quickly revert to the last known working version.


Max History Entries

The number of history records is configurable in Settings. When the limit is reached, the oldest records are automatically removed. Default: 100 entries.

Settings

Code Snippets addon WHMCS

Order now | Download | FAQ

The Settings page is available at: Addons > PUQ Code Snippets > Settings

Configure module behavior, editor preferences, and emergency controls.

Settings — general options, kill switch, and import/export 09-settings.png


General

Setting Description
Editor Theme CodeMirror color theme for the code editor. Choose from a variety of themes (Default Light, Dracula, Monokai, Material, etc.)
Max History Entries Maximum number of history records to keep. Oldest records are removed when the limit is reached. Default: 100

Click Save Settings to apply changes.


Kill Switch

The kill switch is an emergency mechanism to instantly disable all snippets from rendering on any page. This is useful when a snippet breaks your site or causes issues.

How It Works

When the kill switch is active, no snippets are injected into any page — neither client area nor admin area. The snippets remain in the database and can be re-enabled once the issue is resolved.

Three Ways to Activate the Kill Switch

1. Database Toggle (recommended)

Click the Toggle Kill Switch button on the Settings page. This sets a flag in the database that the rendering engine checks on every page load.

2. Flag File — Module Directory

Create a file named KILL_SWITCH in the module directory:

/your-whmcs/modules/addons/puq_code_snippets/KILL_SWITCH

The file contents don't matter — its mere existence activates the kill switch. This method works even if the database is unreachable.

touch /your-whmcs/modules/addons/puq_code_snippets/KILL_SWITCH

To deactivate, delete the file:

rm /your-whmcs/modules/addons/puq_code_snippets/KILL_SWITCH

3. Flag File — WHMCS Root

Create a file named KILL_SWITCH_SNIPPETS in the WHMCS root directory:

/your-whmcs/KILL_SWITCH_SNIPPETS

This is useful when you don't have easy access to the module directory but can access the WHMCS root.

touch /your-whmcs/KILL_SWITCH_SNIPPETS

Note: The Settings page displays the full server paths for both flag file locations, so you can quickly copy them.

Kill Switch Secret URL

A unique URL is generated that allows you to activate the kill switch externally — for example, from a monitoring system or a bookmark. Access the URL in a browser, and the kill switch toggles on.

Security: The secret URL contains a random hash and does not require authentication. Keep it private.


Import / Export

Export All Snippets

Click the Export All Snippets button to download a JSON file containing all your snippets with their settings, targeting rules, and code (base64-encoded).

The export file includes:

Import Snippets

  1. Click Choose File and select a previously exported JSON file
  2. Click Import Snippets

The import will create new snippets from the file. Existing snippets are not modified or deleted — imported snippets are added alongside them.

Tip: Import is useful for migrating snippets between WHMCS instances, sharing snippets between environments (dev/staging/production), or restoring from a backup.

Each imported snippet creates a history record of type "Imported" so you can track what was added.