This guide explains how to integrate the SLSWC Client library into a WordPress plugin for automatic updates, license management, and optional DRM enforcement.
Prerequisites
- Your plugin is listed as a product on an SLSWC-powered WooCommerce store.
- The SLSWC Client library is bundled in your plugin (typically via Strauss or a similar prefixing tool).
Plugin File Headers
SLSWC reads custom headers from your plugin's main file:
/**
* Plugin Name: My Plugin
* Version: 1.0.0
* Text Domain: my-plugin
*
* SLSWC: plugin
* SLSWC Documentation URL: https://example.com/docs
* SLSWC Compatible To: 6.9
*/
The SLSWC header tells the server this is a plugin. The product slug defaults to the plugin's text domain (Text Domain header). To use a custom slug, pass the slug parameter in the $args array (see Basic Integration).
Basic Integration
use SLSWC\Client\Plugin;
add_action( 'init', function () {
$client = Plugin::get_instance(
'https://your-license-server.com/', // License server URL
__FILE__, // Plugin main file
array(
'license_key' => get_option( 'my_plugin_license_key', '' ),
'slug' => 'my-plugin-slug',
)
);
$client->init_hooks();
} );
Parameters
Plugin::get_instance( $license_server_url, $plugin_file, $args )
| Parameter | Type | Description |
|---|---|---|
$license_server_url | string | Base URL of your SLSWC store (with trailing slash) |
$plugin_file | string | Absolute path to the plugin's main PHP file (__FILE__) |
$args | array | Configuration array (see below) |
Args Array
| Key | Type | Required | Description |
|---|---|---|---|
license_key | string | Yes | Customer's license key |
slug | string | No | Product slug (auto-detected from file headers if not set) |
version | string | No | Current version (auto-detected from file headers) |
domain | string | No | Current site domain (defaults to home_url()) |
text_domain | string | No | Plugin text domain (auto-detected) |
drm | array | No | DRM configuration (see DRM docs) |
Real-World Example
This is the actual integration used by the SLSWC plugin itself (from slswc.php):
use SLSWC\Client\Plugin;
function slswc_license_client() {
global $slswc_client;
$license_details = array(
'license_key' => get_option( 'slswc_license_key', '' ),
'slug' => 'software-license-server-for-woocommerce',
'drm' => array(
'enabled' => true,
'product_name' => 'License Server for WooCommerce',
'parent_menu_slug' => 'slswc-dashboard',
'page_hook_prefix' => 'license-server',
'submenu_slugs' => array(
'slswc-licenses',
'slswc-subscriptions',
'slswc-reports',
'slswc-support',
'slswc-settings',
),
'license_page_url' => admin_url( 'admin.php?page=slswc-settings&tab=license' ),
'purchase_url' => 'https://licenseserver.io/',
'logo_url' => SLSWC_ASSETS_URL . 'images/logo/license_server_icon.svg',
'text_domain' => 'slswc',
),
);
$slswc_client = Plugin::get_instance(
'https://licenseserver.io/',
SLSWC_PLUGIN_FILE,
$license_details
);
$slswc_client->init_hooks();
}
What init_hooks() Registers
When you call $client->init_hooks(), the following WordPress hooks are registered:
| Hook | Purpose |
|---|---|
pre_set_site_transient_update_plugins | Check for updates on the license server |
plugins_api | Provide plugin information to the WordPress updater UI |
plugin_row_meta | Add "Check for updates" link in the plugins list |
extra_plugin_headers | Register SLSWC custom headers |
site_transient_update_plugins | Modify update info (download URL, etc.) |
in_plugin_update_message-{file} | Show "license required" message if not activated |
http_request_host_is_external | Allow downloads from the license server host |
If DRM is configured, additional hooks are registered for admin notices, interstitial pages, and AJAX handlers. See DRM.
License Status Flow
inactive -> activate -> active
active -> deactivate -> inactive
active -> expire -> expired
expired -> renew -> active
The client checks the license server on each WordPress update check cycle. Status is stored in the {text_domain}_license_details option.
Filters
| Filter | Description |
|---|---|
slswc_request_info_{text_domain} | Modify request data before sending to server |
slswc_request_options_{text_domain} | Modify wp_safe_remote_get options |
slswc_client_get_actions | Actions that use GET method (default: product, products) |
slswc_client_formatted_plugin_data | Modify parsed plugin file data |
slswc_client_default_license_options | Modify default license option values |
slswc_client_license_option_name | Modify the option key used to store license data |
slswc_api_connected_{text_domain} | Filter the connected flag before saving |
Related Pages
- Client Library Overview โ Architecture and class reference
- Theme Integration โ Integration guide for WordPress themes
- DRM โ Grace periods, admin notices, and interstitial lock (configured via the
drmargs key) - Auto-Updates โ How update checks and download URLs work under the hood
- Hooks Reference โ All
slswc_*actions and filters