-
Notifications
You must be signed in to change notification settings - Fork 8
Licensing
A class for performing license code checks. Currently, only the Software Licensing addon for WHMCS is supported. In the future, it is intended to add more licensing services.
See this simple plugin for example usage. For more information on the attribute values, see the WHMCS Licensing Addon documentation.
You can provide the necessary attribute values with an array. Example:
$args = array(
'plugin' => array(
'path' => __DIR__ // The base path to the plugin
),
'whmcs' => array(
'url' => "http://www.yourdomain.com/whmcs/", // URL to your WHMCS installation
'product_key' => "your_product_secret_key ", // "Secret Key" as set in WHMCS licensed product
'local_key_expire_days' => 15, // The number of days between license checks.
'allow_check_fail_days' => 5 // The number of days to allow failed validations
)
);
$license_check = new \WordPress_ToolKit\Licensing\WHMCS_License( $args );
Alternatively, you can store these values in a JSON file (example). In this example, we're storing them in a file called plugin.json
. Note that we also need to add the plugin path, which will vary by installation.
$license_check = new \WordPress_ToolKit\Licensing\WHMCS_License( __DIR__ . '/plugin.json', array( 'plugin' => array( 'path' => __DIR__ ) ) );
You will want to replace the license_key
and local_key
(see What is a Local Key?) with the license key entered by the user and the local key returned from the last check, respectively, presumably prefixed and stored in the WordPress options table.
// Validate the user's license code
$result = $license_check->validate( get_option( 'license_key' ), get_option( 'local_key' ) );
if( isset( $result['remotecheck'] ) ) update_option( 'local_key', isset( $result['localkey'] ) ? $result['localkey'] : '' );
// Display a notice if license code is invalid
if( $result['status'] != 'Active' ) {
// Display an admin notice: https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices
return;
} else {
// Run plugin logic
}