Black Friday: 79% off every plugin Shop the sale →

Client SDK Template

What ships with the plugin#

example-client/example-license-client.php inside the License Cart folder is a complete, single-file client you copy into the plugin you sell. It contains no credentials, only the API URL, product slug and the customer’s own license state. It provides:

  • a License settings page (activate / deactivate form with status, activations and expiry),
  • admin notices when no key is entered or the license is not active,
  • activate(), deactivate(), check_status() and is_active(),
  • authorize_premium_operation() to gate backend code,
  • a 12-hour status cache with a 24-hour grace period when your server is unreachable (HTTP 429, 5xx or network errors), and
  • WordPress update integration through pre_set_site_transient_update_plugins and plugins_api, so updates and changelogs appear natively.

Adding it to your plugin#

  1. Copy the file into your plugin and rename the class and the example-plugin text domain to match your plugin.
  2. Bootstrap it from your main plugin file:
require_once __DIR__ . '/includes/class-my-plugin-license-client.php';

$my_plugin_license = new My_Plugin_License_Client( array(
    'api_url'       => 'https://your-site.com/wp-json/license-cart/v1',
    'product_slug'  => 'my-plugin',            // slug from License Cart → Products
    'version'       => MY_PLUGIN_VERSION,
    'plugin_file'   => __FILE__,
    'option_prefix' => 'my_plugin',
    'menu_parent'   => 'my-plugin-menu',       // or 'options-general.php'
) );
  1. Gate every premium backend entry point:
$allowed = $my_plugin_license->authorize_premium_operation();
if ( is_wp_error( $allowed ) ) {
    return $allowed;
}
  1. Build your plugin ZIP with your existing build command and upload it as a release in License Cart.

Behaviour details#

  • The client refuses to talk to a non-HTTPS API URL except on local hosts (localhost, 127.0.0.1, ::1, .test) when WP_DEBUG is on.
  • is_active() is true when the cached status is active or grace and domain_active is true.
  • Two filters let you tune caching per plugin: {option_prefix}_license_cache_ttl (default 12 hours) and {option_prefix}_license_grace_period (default 24 hours).
  • Update checks only run while the license is active, and the download URL must be HTTPS.
Was this article helpful?