This guide explains how to integrate the SLSWC Client library into a WordPress theme for automatic updates and license management.
Theme File Headers
SLSWC reads custom headers from your theme's style.css:
/*
Theme Name: My Theme
Version: 1.0.0
Text Domain: my-theme
SLSWC: theme
SLSWC Updated: 2025-01-15
SLSWC Compatible To: 6.9
SLSWC Documentation URL: https://example.com/docs
*/
Basic Integration
Add this to your theme's functions.php:
use SLSWC\Client\Theme;
add_action( 'after_setup_theme', function () {
Theme::get_instance(
'https://your-license-server.com/',
WP_CONTENT_DIR . '/themes/my-theme',
array(
'license_key' => get_option( 'my_theme_license_key', '' ),
'domain' => site_url(),
)
);
} );
Parameters
Theme::get_instance( $license_server_url, $base_file, $args )
| Parameter | Type | Description |
|---|---|---|
$license_server_url | string | Base URL of your SLSWC store (with trailing slash) |
$base_file | string | Absolute path to the theme directory |
$args | array | Configuration array (see below) |
Args Array
| Key | Type | Required | Description |
|---|---|---|---|
license_key | string | Yes | Customer's license key |
domain | string | No | Current site URL (defaults to site_url()) |
version | string | No | Theme version (auto-detected from style.css) |
text_domain | string | No | Theme text domain (auto-detected from style.css) |
How It Works
The Theme class constructor automatically calls init_hooks(), which registers:
| Hook | Purpose |
|---|---|
pre_set_site_transient_update_themes | Check for updates on the license server |
extra_theme_headers | Register SLSWC custom headers |
Update Check Flow
- WordPress triggers the
pre_set_site_transient_update_themesfilter during update checks. - The
Themeclass sends acheck_updaterequest to the license server with the license key and current version. - If a newer version is available, it adds the update info to the transient.
- WordPress shows the update notification in the admin dashboard.
The theme identifier in the update transient is the text_domain property, which defaults to the theme directory name.
Differences from Plugin Integration
| Feature | Plugin | Theme |
|---|---|---|
init_hooks() call | Manual (you must call it) | Automatic (called in constructor) |
| Update transient | update_plugins | update_themes |
| DRM support | Yes (built-in) | Not built into Theme class |
| File parsing | get_plugin_data() | wp_get_theme() |
| Identifier | Plugin basename (folder/file.php) | Text domain / directory name |
Filters
| Filter | Description |
|---|---|
slswc_client_formatted_theme_data | Modify parsed theme file data |
slswc_request_info_{text_domain} | Modify request data before sending to server |
slswc_request_options_{text_domain} | Modify HTTP request options |
slswc_client_default_license_options | Modify default license option values |
Related Pages
- Client Library Overview โ Architecture and class reference
- Plugin Integration โ Integration guide for WordPress plugins (includes DRM support)
- Auto-Updates โ How update checks work for both plugins and themes
- DRM โ DRM enforcement (not built into the Theme class, but can be implemented separately)
- Hooks Reference โ All
slswc_*actions and filters