Plugin Integration

This guide explains how to integrate the SLSWC Client library into a WordPress plugin for automatic updates, license management, and optional DRM enforcement.

Prerequisites

  1. Your plugin is listed as a product on an SLSWC-powered WooCommerce store.
  2. 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 )

ParameterTypeDescription
$license_server_urlstringBase URL of your SLSWC store (with trailing slash)
$plugin_filestringAbsolute path to the plugin's main PHP file (__FILE__)
$argsarrayConfiguration array (see below)

Args Array

KeyTypeRequiredDescription
license_keystringYesCustomer's license key
slugstringNoProduct slug (auto-detected from file headers if not set)
versionstringNoCurrent version (auto-detected from file headers)
domainstringNoCurrent site domain (defaults to home_url())
text_domainstringNoPlugin text domain (auto-detected)
drmarrayNoDRM 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:

HookPurpose
pre_set_site_transient_update_pluginsCheck for updates on the license server
plugins_apiProvide plugin information to the WordPress updater UI
plugin_row_metaAdd "Check for updates" link in the plugins list
extra_plugin_headersRegister SLSWC custom headers
site_transient_update_pluginsModify update info (download URL, etc.)
in_plugin_update_message-{file}Show "license required" message if not activated
http_request_host_is_externalAllow 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

FilterDescription
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_actionsActions that use GET method (default: product, products)
slswc_client_formatted_plugin_dataModify parsed plugin file data
slswc_client_default_license_optionsModify default license option values
slswc_client_license_option_nameModify the option key used to store license data
slswc_api_connected_{text_domain}Filter the connected flag before saving
  • 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 drm args key)
  • Auto-Updates โ€” How update checks and download URLs work under the hood
  • Hooks Reference โ€” All slswc_* actions and filters

Was this article helpful?