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()andis_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_pluginsandplugins_api, so updates and changelogs appear natively.
Adding it to your plugin#
- Copy the file into your plugin and rename the class and the
example-plugintext domain to match your plugin. - 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'
) );
- Gate every premium backend entry point:
$allowed = $my_plugin_license->authorize_premium_operation();
if ( is_wp_error( $allowed ) ) {
return $allowed;
}
- 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) whenWP_DEBUGis on. is_active()is true when the cached status isactiveorgraceanddomain_activeis 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?
Tell us what was missing
