Theme Integration

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 )

ParameterTypeDescription
$license_server_urlstringBase URL of your SLSWC store (with trailing slash)
$base_filestringAbsolute path to the theme directory
$argsarrayConfiguration array (see below)

Args Array

KeyTypeRequiredDescription
license_keystringYesCustomer's license key
domainstringNoCurrent site URL (defaults to site_url())
versionstringNoTheme version (auto-detected from style.css)
text_domainstringNoTheme text domain (auto-detected from style.css)

How It Works

The Theme class constructor automatically calls init_hooks(), which registers:

HookPurpose
pre_set_site_transient_update_themesCheck for updates on the license server
extra_theme_headersRegister SLSWC custom headers

Update Check Flow

  1. WordPress triggers the pre_set_site_transient_update_themes filter during update checks.
  2. The Theme class sends a check_update request to the license server with the license key and current version.
  3. If a newer version is available, it adds the update info to the transient.
  4. 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

FeaturePluginTheme
init_hooks() callManual (you must call it)Automatic (called in constructor)
Update transientupdate_pluginsupdate_themes
DRM supportYes (built-in)Not built into Theme class
File parsingget_plugin_data()wp_get_theme()
IdentifierPlugin basename (folder/file.php)Text domain / directory name

Filters

FilterDescription
slswc_client_formatted_theme_dataModify 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_optionsModify default license option values
  • 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

Was this article helpful?