# Code Snippets WHMCS Addon

# Description

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

## 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 &amp; 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 &amp; 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

<table id="bkmrk-requirement-minimum-"><thead><tr><th>Requirement</th><th>Minimum</th></tr></thead><tbody><tr><td>**WHMCS**</td><td>8.x, 9.x</td></tr><tr><td>**PHP**</td><td>8.1, 8.2+</td></tr><tr><td>**ionCube Loader**</td><td>v13 or newer (v14, v15)</td></tr></tbody></table>

- - - - - -

## Links

- **Product page:** [https://puqcloud.com/](https://puqcloud.com/)
- **Documentation:** [https://doc.puq.info/books/code-snippets-whmcs-addon](https://doc.puq.info/books/code-snippets-whmcs-addon)
- **Support:** [https://puqcloud.com/submitticket.php](https://puqcloud.com/submitticket.php?step=2&deptid=1)
- **Community:** [https://community.puqcloud.com/](https://community.puqcloud.com/)

</body># Changelog

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

## 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

</body># Installation and Update

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

## System Requirements

<table id="bkmrk-requirement-minimum-"><thead><tr><th>Requirement</th><th>Minimum</th></tr></thead><tbody><tr><td>**PHP**</td><td>8.1, 8.2 or newer</td></tr><tr><td>**WHMCS**</td><td>8.x, 9.x or newer</td></tr><tr><td>**ionCube Loader**</td><td>v13 or newer (v14, v15)</td></tr></tbody></table>

> **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](https://puqcloud.com/store/whmcs-addon-modules)
- **FAQ:** [https://community.puqcloud.com/](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/](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** &gt; **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](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-6zf1rbru.png)*01-addon-config-license.png*

### Step 4: Access the Module

Go to **Addons** &gt; **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:

1. Go to **Setup** &gt; **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** &gt; **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** &gt; **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

- 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

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

### Purchase a License

**[https://puqcloud.com/store/whmcs-addon-modules](https://puqcloud.com/store/whmcs-addon-modules)**

For license-related questions, please contact us via the ticket system:

**[https://puqcloud.com/submitticket.php](https://puqcloud.com/submitticket.php?step=2&deptid=1)**# Dashboard

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

The Dashboard is the home page of the module, available at: **Addons** &gt; **PUQ Code Snippets** &gt; **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](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-dxx7ufba.png)*02-dashboard.png*

- - - - - -

## Key Metrics

The top section displays four summary cards:

<table id="bkmrk-metric-description-t"><thead><tr><th>Metric</th><th>Description</th></tr></thead><tbody><tr><td>**Total Snippets**</td><td>Total number of snippets in the system</td></tr><tr><td>**Active Snippets**</td><td>Snippets that are currently enabled and will be injected</td></tr><tr><td>**Inactive Snippets**</td><td>Snippets that are disabled</td></tr><tr><td>**Scheduled Snippets**</td><td>Snippets with a future start date or an active date range</td></tr></tbody></table>

- - - - - -

## 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 &lt;head&gt; tag** — CSS, meta tags, analytics scripts
- **After opening &lt;body&gt;** — top banners, GTM noscript blocks
- **Before closing &lt;/body&gt;** — chat widgets, tracking pixels, JavaScript

- - - - - -

## Recent Changes

A table showing the latest snippet modifications:

<table id="bkmrk-column-description-d"><thead><tr><th>Column</th><th>Description</th></tr></thead><tbody><tr><td>**Date**</td><td>Timestamp of the change</td></tr><tr><td>**Action**</td><td>Type of change: Created, Updated, Deleted, Toggled, Restored, Imported</td></tr><tr><td>**Snippet**</td><td>Name of the affected snippet</td></tr><tr><td>**Admin**</td><td>Administrator who made the change</td></tr></tbody></table>

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](08-settings.md) for details on the kill switch.# Snippets

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

The Snippets section is available at: **Addons** &gt; **PUQ Code Snippets** &gt; **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](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-mohlc7gw.png)*03-snippets-list.png*

- - - - - -

## Navigation Menu

The Snippets dropdown menu provides quick access to filtered views:

![Snippets dropdown menu](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-maryrslq.png)*06-snippets-menu.png*

<table id="bkmrk-menu-item-descriptio"><thead><tr><th>Menu Item</th><th>Description</th></tr></thead><tbody><tr><td>**All Snippets**</td><td>Show all snippets regardless of area or status</td></tr><tr><td>**Add New**</td><td>Create a new snippet</td></tr><tr><td>**Client Area**</td><td>Show only snippets targeting the Client Area</td></tr><tr><td>**Admin Area**</td><td>Show only snippets targeting the Admin Area</td></tr><tr><td>**Active**</td><td>Show only enabled snippets</td></tr><tr><td>**Inactive**</td><td>Show only disabled snippets</td></tr><tr><td>**Scheduled**</td><td>Show only snippets with scheduling configured</td></tr></tbody></table>

- - - - - -

## Snippets List

The main table displays all snippets with sortable columns:

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

- - - - - -

## Actions

Each snippet has three action buttons:

<table id="bkmrk-button-description-e"><thead><tr><th>Button</th><th>Description</th></tr></thead><tbody><tr><td>**Edit** (pencil icon)</td><td>Open the snippet editor</td></tr><tr><td>**Toggle** (power icon)</td><td>Enable/disable the snippet with one click</td></tr><tr><td>**Delete** (trash icon)</td><td>Delete the snippet (with confirmation dialog)</td></tr></tbody></table>

- - - - - -

## 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](06-snippet-editor.md) for details on all available settings.# Snippet Editor

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

The Snippet Editor is available at: **Addons** &gt; **PUQ Code Snippets** &gt; **Snippets** &gt; **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)](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-jsoganw4.png)*04-snippet-editor-top.png*

![Snippet Editor — area, custom URL patterns, schedule, and code editor (bottom)](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-iql0mg5o.png)*05-snippet-editor-bottom.png*

- - - - - -

## Page Layout

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

<table id="bkmrk-column-sections-left"><thead><tr><th>Column</th><th>Sections</th></tr></thead><tbody><tr><td>**Left**</td><td>Settings, Position, Area</td></tr><tr><td>**Middle**</td><td>Page Targeting</td></tr><tr><td>**Right**</td><td>User Targeting, Product Targeting, Schedule</td></tr><tr><td>**Bottom**</td><td>Code Editor (full width)</td></tr></tbody></table>

- - - - - -

## Settings

<table id="bkmrk-field-description-sn"><thead><tr><th>Field</th><th>Description</th></tr></thead><tbody><tr><td>**Snippet Name**</td><td>A descriptive name for the snippet (required)</td></tr><tr><td>**Description**</td><td>Optional description for reference</td></tr><tr><td>**Status**</td><td>Enabled or Disabled</td></tr><tr><td>**Priority**</td><td>Numeric value — lower numbers are rendered first (default: 0)</td></tr></tbody></table>

- - - - - -

## Position

Choose where the code is injected on the page:

<table id="bkmrk-position-description"><thead><tr><th>Position</th><th>Description</th><th>Best For</th></tr></thead><tbody><tr><td>**Inside &lt;head&gt; tag**</td><td>Inserted inside the `<head>` section</td><td>CSS, meta tags, analytics scripts, SEO tags</td></tr><tr><td>**After opening &lt;body&gt; tag**</td><td>Inserted right after `<body>`</td><td>Top banners, GTM noscript blocks, cookie consent</td></tr><tr><td>**Before closing &lt;/body&gt; tag**</td><td>Inserted right before `</body>`</td><td>Chat widgets, tracking pixels, JavaScript</td></tr></tbody></table>

- - - - - -

## Area

Choose which WHMCS area the snippet targets:

<table id="bkmrk-area-description-cli"><thead><tr><th>Area</th><th>Description</th></tr></thead><tbody><tr><td>**Client Area**</td><td>Only visible on client-facing pages (storefront, client portal)</td></tr><tr><td>**Admin Area**</td><td>Only visible in the admin panel</td></tr><tr><td>**Both Areas**</td><td>Visible on both client and admin pages</td></tr></tbody></table>

> 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:

<table id="bkmrk-group-pages-general-"><thead><tr><th>Group</th><th>Pages</th></tr></thead><tbody><tr><td>**General**</td><td>Homepage, Client Dashboard, Login, Registration, Password Reset</td></tr><tr><td>**Account**</td><td>My Details, Contacts, Change Password, Security, Payment Methods, My Emails</td></tr><tr><td>**Services**</td><td>My Services, Product Details, My Domains, Domain Details, Add Funds, Upgrade</td></tr><tr><td>**Billing**</td><td>My Invoices, View Invoice, Quotes, View Quote, Credit Card</td></tr><tr><td>**Support**</td><td>Tickets List, View Ticket, Submit Ticket, Knowledge Base, Announcements, Network Issues</td></tr><tr><td>**Shopping**</td><td>Cart / Order Form, Cart Checkout, Cart Addons, Domain Checker</td></tr><tr><td>**Other**</td><td>Contact Us, Server Status, Downloads, Affiliates, Mass Domain Mgmt</td></tr></tbody></table>

### Admin Area Pages

Organized by groups:

<table id="bkmrk-group-pages-dashboar"><thead><tr><th>Group</th><th>Pages</th></tr></thead><tbody><tr><td>**Dashboard**</td><td>Dashboard, Search, System Health</td></tr><tr><td>**Clients**</td><td>Clients List, Client Summary, Client Profile, Client Contacts, Client (route)</td></tr><tr><td>**Client Management**</td><td>Products/Services, Domains, Client Invoices, Client Credits, Client Emails, Client Notes, Activity Log, Billable Items, Client Quotes, Client Transactions</td></tr><tr><td>**Billing**</td><td>Orders, Invoices, Transactions, Quotes, Billable Items, Billing (route)</td></tr><tr><td>**Support**</td><td>Support Tickets, View Ticket, Predefined Replies, Escalations</td></tr><tr><td>**Setup / Config**</td><td>General Settings, Products Setup, Addon Modules, Administrators, Servers, Registrars, Automation, Payment Gateways, Setup (route)</td></tr><tr><td>**Utilities / Logs**</td><td>Utilities, Module Log, Logs (route)</td></tr></tbody></table>

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):

<table id="bkmrk-option-description-a"><thead><tr><th>Option</th><th>Description</th></tr></thead><tbody><tr><td>**All Visitors**</td><td>Everyone — logged-in clients and guests</td></tr><tr><td>**Logged-in Clients Only**</td><td>Only authenticated clients</td></tr><tr><td>**Guests Only**</td><td>Only unauthenticated visitors</td></tr><tr><td>**Specific Client Groups**</td><td>Only clients belonging to selected WHMCS client groups</td></tr></tbody></table>

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):

<table id="bkmrk-option-description-a-0"><thead><tr><th>Option</th><th>Description</th></tr></thead><tbody><tr><td>**All (no product filtering)**</td><td>No product-based filtering applied</td></tr><tr><td>**Client HAS active service**</td><td>Show only to clients who have an active or suspended service for the selected products</td></tr><tr><td>**Client does NOT have active service**</td><td>Show only to clients who do NOT have the selected products</td></tr></tbody></table>

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:

<table id="bkmrk-field-description-sc"><thead><tr><th>Field</th><th>Description</th></tr></thead><tbody><tr><td>**Schedule Start**</td><td>The snippet will not render before this date/time</td></tr><tr><td>**Schedule End**</td><td>The snippet will stop rendering after this date/time</td></tr></tbody></table>

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

**Use cases:**

- Promotional banner visible only during Black Friday week
- Maintenance notice shown for a specific time window
- Seasonal holiday greeting

- - - - - -

## 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 &amp; 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](08-settings.md)

### What Code Can You Inject?

You can inject any valid HTML, including:

```html
<!-- 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.

</body># History

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

The History page is available at: **Addons** &gt; **PUQ Code Snippets** &gt; **History** &gt; **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](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-vwqlf67c.png)*07-history.png*

- - - - - -

## History Log

The main table displays all recorded changes:

<table id="bkmrk-column-description-%23"><thead><tr><th>Column</th><th>Description</th></tr></thead><tbody><tr><td>**\#**</td><td>Record number</td></tr><tr><td>**Date**</td><td>Timestamp of the change</td></tr><tr><td>**Action**</td><td>Type of change (see below)</td></tr><tr><td>**Snippet**</td><td>Name of the affected snippet</td></tr><tr><td>**Description**</td><td>Snippet description at the time of the change</td></tr><tr><td>**Admin**</td><td>Administrator who made the change</td></tr><tr><td>**Actions**</td><td>View Diff and Rollback buttons</td></tr></tbody></table>

### Action Types

<table id="bkmrk-action-description-c"><thead><tr><th>Action</th><th>Description</th></tr></thead><tbody><tr><td>**Created**</td><td>A new snippet was created</td></tr><tr><td>**Updated**</td><td>An existing snippet was modified</td></tr><tr><td>**Deleted**</td><td>A snippet was deleted</td></tr><tr><td>**Toggled**</td><td>A snippet was enabled or disabled</td></tr><tr><td>**Restored**</td><td>A snippet was rolled back to a previous version</td></tr><tr><td>**Imported**</td><td>A snippet was imported from a JSON file</td></tr></tbody></table>

- - - - - -

## 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](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-za9zg1xe.png)*08-history-diff.png*

The diff modal shows:

<table id="bkmrk-panel-description-be"><thead><tr><th>Panel</th><th>Description</th></tr></thead><tbody><tr><td>**Before**</td><td>The snippet code before the change</td></tr><tr><td>**After**</td><td>The snippet code after the change</td></tr></tbody></table>

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](08-settings.md). When the limit is reached, the oldest records are automatically removed. Default: 100 entries.# Settings

### Code Snippets addon **[WHMCS](https://puqcloud.com/link.php?id=77)**

##### [Order now](https://puqcloud.com/store/whmcs-addon-modules) | [Download](https://download.puqcloud.com/WHMCS/addons/PUQ_WHMCS-Code-Snippets/) | [FAQ](https://community.puqcloud.com/)

The Settings page is available at: **Addons** &gt; **PUQ Code Snippets** &gt; **Settings**

Configure module behavior, editor preferences, and emergency controls.

![Settings — general options, kill switch, and import/export](https://doc.puq.info/uploads/images/gallery/2026-02/embedded-image-1ctmoxt6.png)*09-settings.png*

- - - - - -

## General

<table id="bkmrk-setting-description-"><thead><tr><th>Setting</th><th>Description</th></tr></thead><tbody><tr><td>**Editor Theme**</td><td>CodeMirror color theme for the code editor. Choose from a variety of themes (Default Light, Dracula, Monokai, Material, etc.)</td></tr><tr><td>**Max History Entries**</td><td>Maximum number of history records to keep. Oldest records are removed when the limit is reached. Default: 100</td></tr></tbody></table>

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.

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

```

To deactivate, delete the file:

```bash
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.

```bash
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

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.