Client Library

The LicenceForge client library is a set of PHP classes that you bundle with your WordPress plugin or theme. It handles license activation, validation, feature gating, and automatic updates -- all by communicating with your LicenceForge server over its REST API.

LicenceForge offers two integration approaches. Both work with plugins and themes, and both connect to the same server-side API. Choose the one that best fits your project.

Integration approaches

Three-class system

The standard integration uses three dedicated classes, each responsible for a single concern:

Class File Responsibility
WPLF_Client class-wplf-client.php Core license operations: activation, deactivation, validation, feature checking, and caching.
WPLF_Client_Admin class-wplf-client-admin.php Admin UI: settings page, license input form, status display, and admin notices.
WPLF_Client_Updater class-wplf-client-updater.php Auto-updates: hooks into the WordPress update system, verifies package integrity.

This approach gives you full control over each layer. You can customise the admin page, replace the updater with your own, or use only the core client without the other two.

// Typical bootstrap in your plugin's main file
require_once __DIR__ . '/includes/class-wplf-client.php';
require_once __DIR__ . '/includes/class-wplf-client-admin.php';
require_once __DIR__ . '/includes/class-wplf-client-updater.php';

$client  = new WPLF_Client( 'my-plugin', 'https://licences.example.com', __FILE__ );
$admin   = new WPLF_Client_Admin( $client );
$updater = new WPLF_Client_Updater( $client );

Full details: WordPress Integration (3-class)

Drop-in single file

The WPLF_Licensing class combines all three responsibilities into a single file. It uses a static initialiser and a singleton pattern per product slug, making setup as concise as possible.

// Single line in your plugin or theme
require_once __DIR__ . '/includes/wplf-licensing.php';
WPLF_Licensing::init( 'my-plugin', 'https://licences.example.com', __FILE__ );

WPLF_Licensing auto-detects whether it is running inside a plugin or a theme and registers its admin menu accordingly (under Settings for themes, under the plugin's own menu for plugins).

Full details: Drop-in Single File

Choosing an approach

Consideration 3-class system Drop-in single file
Files to include 3 files 1 file
Lines of bootstrap code 5–10 2
Admin page customisation Full control (branding, layout, parent menu) Limited (standard layout, auto-detected menu)
Selective usage Use any class independently All-or-nothing
Caching default 3600 seconds (1 hour) 43200 seconds (12 hours)
Best for Products that need custom admin UX or selective class usage Quick integrations where defaults are acceptable

Tip

If you are unsure which approach to use, start with the drop-in single file. You can migrate to the 3-class system later without changing your server configuration -- both approaches use the same REST API endpoints.

How it works

Regardless of which approach you choose, the client library follows the same lifecycle:

  1. Activation -- The end user enters their license key in the admin page. The client sends the key and the site URL to your LicenceForge server, which registers an activation record.
  2. Validation -- On a configurable schedule (controlled by cache_duration), the client re-validates the license with the server. The result is cached in a WordPress transient to minimise API calls.
  3. Feature gating -- Your code calls has_feature() or is_active() to conditionally enable functionality based on the license tier.
  4. Updates -- The updater hooks into pre_set_site_transient_update_plugins to check for new versions. Downloads are verified with SHA-256 hashes before installation.
  5. Deactivation -- The user can deactivate their license from the admin page, freeing up an activation slot for use on another site.

Non-WordPress usage

If you need to validate licenses from a non-WordPress application (a Laravel project, a SaaS backend, or any HTTP client), you can call the LicenceForge REST API directly. See Non-WordPress Integration for request formats and examples.

Section contents