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
- Unlimited Code Snippets — create as many snippets as you need, each with its own settings
- CodeMirror Editor — syntax-highlighted code editor with HTML/CSS/JS support, code folding, search, auto-close tags and brackets
-
Three Injection Positions — insert code inside
<head>, after opening<body>, or before closing</body> - Area Targeting — target Client Area, Admin Area, or both
- Page Targeting — target specific pages with checkboxes for 35+ client area pages and 40+ admin area pages
- Custom URL Patterns — target any page by URL pattern matching (if URL contains the pattern, the snippet fires)
- User Targeting — show snippets to all visitors, logged-in clients only, guests only, or specific client groups
- Product/Service Targeting — show or hide snippets based on client's active products/services
- Scheduling — set start and end dates for time-limited snippets (promotions, announcements)
- Priority System — control the order in which snippets are rendered
- Version History — complete log of all changes with side-by-side diff view
- One-Click Rollback — restore any previous version of a snippet instantly
- Kill Switch — emergency disable all snippets instantly via database toggle, flag file, or secret URL
- Import / Export — export all snippets to JSON, import on another WHMCS instance
- Dashboard — overview with key metrics, charts by area and position, recent changes log
- License system — online/offline license verification with graceful degradation
- English language interface
Use Cases
- Analytics & Tracking — Google Analytics, GTM, Meta Pixel, Hotjar, etc.
- Chat Widgets — Tawk.to, LiveChat, Crisp, Intercom, etc.
- Custom CSS — style overrides, theme tweaks, branding adjustments
- Banners & Announcements — promotional banners, maintenance notices, holiday messages
- Custom JavaScript — form validation, UI enhancements, integrations
- SEO Tags — meta tags, Open Graph, structured data
- Cookie Consent — GDPR/cookie consent banners
- A/B Testing — inject different code for different user segments
System Requirements
| Requirement | Minimum |
|---|---|
| WHMCS | 8.x, 9.x |
| PHP | 8.1, 8.2+ |
| ionCube Loader | v13 or newer (v14, v15) |
Links
- Product page: https://puqcloud.com/
- Documentation: https://doc.puq.info/books/code-snippets-whmcs-addon
- Support: https://puqcloud.com/submitticket.php
- Community: https://community.puqcloud.com/
Changelog
Code Snippets addon WHMCS
Order now | Download | FAQ
v1.0 — 2026-02-16
First release.
New Features
- Unlimited code snippets with CodeMirror syntax-highlighted editor (HTML/CSS/JS)
- Three injection positions: inside
<head>, after<body>, before</body> - Area targeting: Client Area, Admin Area, or Both
- Page targeting with checkboxes for 35+ client area pages and 40+ admin area pages
- Custom URL pattern matching for targeting any page by URL substring
- User targeting: All Visitors, Logged-in Clients Only, Guests Only, Specific Client Groups
- Product/Service targeting: show or hide snippets based on client's active products
- Scheduling with start and end dates
- Priority system for controlling snippet rendering order
- Complete version history log with side-by-side diff view
- One-click rollback to any previous snippet version
- Emergency kill switch via database toggle, flag file (module dir or WHMCS root), or secret URL
- Import/Export of all snippets as JSON with base64-encoded code
- Dashboard with key metrics, area/position charts, and recent changes
- Snippets list with filtering by area (Client/Admin), status (Active/Inactive/Scheduled)
- AJAX-based save/load for all pages
- WHMCS friendly URL support for page detection
- Admin area route-based URL support (e.g.,
/admin/index.php/admin/billing/invoice/123) - License verification system with online/offline modes
- Dashboard accessible without active license, other pages restricted
- English language interface
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:
- Order / Download: https://puqcloud.com/store/whmcs-addon-modules
- FAQ: https://community.puqcloud.com/
- Direct download links:
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
- Log in to the WHMCS admin panel
- Go to Setup > Addon Modules
- Find PUQ Code Snippets in the list
- Click Activate
On activation, the module creates three database tables:
puq_code_snippets,puq_code_snippets_settings, andpuq_code_snippets_history.
Step 3: Configure the License Key
- After activation, click Configure next to the module
- Enter your license key in the License key field
- Select admin role groups that should have access to the module
- 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).
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:
- Your WHMCS database
- Module files in
modules/addons/puq_code_snippets/
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:
- Go to Setup > Addon Modules
- 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
- Go to Addons > PUQ Code Snippets
- Check the version number in the top-right corner of the navigation bar (e.g.,
v1.0)
Deactivation
- Go to Setup > Addon Modules
- Click Deactivate next to PUQ Code Snippets
- 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
- The module periodically checks license validity at
https://license.puqcloud.com/ - Verification results are cached in the database for 5 days
- If the license server is temporarily unreachable, the module uses the last cached result
Without an Active License
- Dashboard (Home page) remains fully accessible
- All other pages (Snippets, History, Settings) display a license required page
- All AJAX controllers (except Dashboard data) return a 403 error
- Snippets continue to render on the frontend — they are not disabled without a license
After Activating a License
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.
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:
- Client Area — snippets targeting only the client-facing pages
- Admin Area — snippets targeting only the admin panel
- Both — snippets targeting both areas
Snippets by Position
A horizontal bar chart showing the distribution by injection position:
- Inside <head> tag — CSS, meta tags, analytics scripts
- After opening <body> — top banners, GTM noscript blocks
- Before closing </body> — chat widgets, tracking pixels, JavaScript
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.
03-snippets-list.png
Navigation Menu
The Snippets dropdown menu provides quick access to filtered views:
| 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) |
Search
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.
04-snippet-editor-top.png
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
- Syntax highlighting for HTML, CSS, and JavaScript (htmlmixed mode)
- Line numbers for easy reference
- Code folding — collapse/expand HTML tags and code blocks
- Auto-close tags — automatically closes HTML tags
-
Auto-close brackets — automatically closes
(),[],{} - Tag matching — highlights matching opening/closing tags
- Search & replace — press Ctrl+F to search, Ctrl+H to replace
- Selection highlighting — highlights all occurrences of the selected text
- Configurable theme — change the editor theme in Settings
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.
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.
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:
- Restores the snippet's code to the version stored in that history record
- Creates a new history entry of type "Restored"
- Does not affect other snippet settings (name, targeting, schedule, etc.)
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.
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.
- Green indicator — Kill switch is inactive, snippets running normally
- Red indicator — Kill switch is ACTIVE, all snippets disabled
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:
- All snippet data (name, description, code, position, area, status, priority)
- All targeting rules (pages, user targeting, product targeting, client groups)
- Scheduling settings
- Module version and export timestamp
Import Snippets
- Click Choose File and select a previously exported JSON file
- 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.