-
-
Notifications
You must be signed in to change notification settings - Fork 1
Integrate PluginPass
To be able to use PluginPass functions you need to define plugin as a dependency to your plugin or theme.
Following option(-s) can be suggested to achieve this.
Add the following code snippet to the activation hook of your plugin:
<?php
register_activation_hook( __FILE__, 'my_plugin_activate' );
function my_plugin_activate() {
$pluginpass_slug = 'pluginpass-pro-plugintheme-licensing';
$pluginpass_folder = "$pluginpass_slug/pluginpass.php";
// Require PluginPass plugin
if ( is_admin() && current_user_can( 'activate_plugins' ) && ! is_plugin_active( $pluginpass_folder ) ) {
// plugin installed but not activated
if ( array_key_exists( $pluginpass_folder, get_plugins() ) ) {
$pluginpass_activate_url = wp_nonce_url(
self_admin_url( 'plugins.php?action=activate&plugin=' . $pluginpass_folder ),
'activate-plugin_' . $pluginpass_folder
);
wp_die( sprintf(
'This plugin/theme requires PluginPass plugin to be installed and active.<br><br> <a class="button button-primary" href="%s">%s</a>',
$pluginpass_activate_url,
'Activate PluginPass now »'
)
);
}
$pluginpass_install_url = wp_nonce_url(
self_admin_url( 'update.php?action=install-plugin&plugin=' . $pluginpass_slug ),
'install-plugin_' . $pluginpass_slug
);
wp_die( sprintf(
'This plugin/theme requires PluginPass plugin to be installed and active.<br><br> <a class="button button-primary" href="%s">%s</a>',
$pluginpass_install_url,
'Install PluginPass now »'
)
);
}
}
The \PluginPass\Inc\Common\PluginPass_Guard class contains methods for performing plugin/theme validation, as well as other useful functions to work with the NetLicensing RESTful API.
- string $api_key : NetLicensing API Key (API Key with role Licensee is recommended)
- string $product_number : NetLicensing product number
- string $plugin_folder : Relative path to your plugin folder
<?php
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
To be able to validate plugin or theme installed in customer's WordPress instance, user consent should be given to process personal data.
All validate() requests without user consent will always return false.
Method set_consent() need to be called only once. After a successful call, user consent will be stored in the database and used for all NetLicensing call.
<?php
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$module = 'My Product Module Number'
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
print_r($quard->validate($model)); // validate() request will not be sent and return false
$quard->set_concent();
print_r($quard->validate($model)); // validate() request will be sent and return plugin/theme validation status
Method has_consent() returns true if user consent is available and his personal data can be processed.
-
boolean :
trueif user consent is available
<?php
function my_some_function() {
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$module = 'My Product Module Number';
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
if ( ! $quard->has_consent() ) {
if ( isset( $_GET['has_consent'] ) ) {
if ( $_GET['has_consent'] === true ) {
$quard->set_consent();
} else {
wp_die( 'User consent must be available to process personal data!' )ж
}
} else {
my_function_get_user_consent();
exit();
}
}
if ( $quard->validate( $module ) ) {
// some code
}
}
function my_function_get_user_consent() {
// show popup or page to obtain user consent
global $wp;
$accept_url = esc_url( add_query_arg( array_merge( $wp->query_vars, [ 'has_consent' => true ] ), admin_url( $wp->request ) ) );
$cancel_url = esc_url( add_query_arg( array_merge( $wp->query_vars, [ 'has_consent' => false ] ), admin_url( $wp->request ) ) );
return "<a href='$accept_url'>Accept</a> <a href='$cancel_url'>Cancel</a>";
}
Validate plugin or theme module(-s) for the current WordPress instance.
- string $module : The plugin or theme module to be validated.
-
boolean : Validation status -
trueif requested feature is available and can be used, otherwisefalse.
Validation for license models:
<?php
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
$feature = 'PRODUCT_MODULE_NUMBER'; // "PRODUCT_MODULE_NUMBER" is the number of product module
if ( $quard->validate( $feature ) ) {
// user has a valid license for product module with the number "PRODUCT_MODULE_NUMBER"
// ...
}
Validation for license models:
Note: For this license model $module argument should be provided as a concatenation of the product module number and the license template number to be validated; e.g. PRODUCT_MODULE_NUMBER.LICENSE_TEMPLATE_NUMBER.
<?php
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
if ( $quard->validate( 'PRODUCT_MODULE_NUMBER.FEATURE1' ) ) {
// user has a valid license for product module with number "PRODUCT_MODULE_NUMBER" and license template with the number "FEATURE1"
// ...
}
if ( $quard->validate( 'PRODUCT_MODULE_NUMBER.FEATURE2' ) ) {
// user has a valid license for product module with number "PRODUCT_MODULE_NUMBER" and license template with the number "FEATURE2"
// ...
}
Note: Following NetLicensing license models aren't tested with PluginPass yet: Pricing Table, Rental, Floating, Node-Locked. Please do not hesitate to provide your use case, which might include the above models. We'll be happy to elaborate on this.
Return validation result as an array.
- string $module : (optional) The plugin's module validation result. If not provided returns the complete validation result.
- array || null : Return validation result array or null if the validation doesn't exist.
<?php
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
print_r($quard->validation_result());
/*
* Array
* (
* [Some Product Module Number] => Array
* (
* [valid] => true
* [licensingModel] => Subscription
* [expires] => 2019-08-19T19:44:00.224Z
* [productModuleName] => Product Module Name
* [productModuleNumber] => PRODUCT_MODULE_NUMBER
* )
*
* )
*/
print_r($quard->validation_result('PRODUCT_MODULE_NUMBER'));
/*
* Array
* (
* [valid] => true
* [licensingModel] => Subscription
* [expires] => 2019-08-19T19:44:00.224Z
* [productModuleName] => Product Module Name
* [productModuleNumber] => PRODUCT_MODULE_NUMBER
* )
*/
Redirect the user to the NetLicensing Shop for license acquisition.
- string $successUrl : (optional) Forward customer to this URL after successful checkout.
- string $successUrlTitle : (optional) Link title for successful checkout.
- string $cancelUrl : (optional) Forward customer to this URL after cancelled checkout.
- string $cancelUrlTitle : (optional) Link title for cancelled checkout.
<?php
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
$feature = 'PRODUCT_MODULE_NUMBER'; // "PRODUCT_MODULE_NUMBER" is the number of product module
if ( !$quard->validate( $feature ) ) {
// user doesn't have a valid license for product module with the number "PRODUCT_MODULE_NUMBER"
// open shop
$quard->open_shop('https://my-domain.com/success', 'Back to site', 'https://my-domain.com/cancel', 'Cancel and Back to site');
}
Generate shop NetLicensing URL for license acquisition.
- string $successUrl : (optional) Forward customer to this URL after successful checkout.
- string $successUrlTitle : (optional) Link title for successful checkout.
- string $cancelUrl : (optional) Forward customer to this URL after cancelled checkout.
- string $cancelUrlTitle : (optional) Link title for cancelled checkout.
- string $url : NetLicensing Shop URL.
<?php
$api_key = 'My NetLicensing API Key';
$product_number = 'My Product Number';
$plugin_folder = 'my-plugin/my-plugin.php';
$quard = new \PluginPass\Inc\Common\PluginPass_Guard( $api_key, $product_number, $plugin_folder );
$feature = 'PRODUCT_MODULE_NUMBER'; // "PRODUCT_MODULE_NUMBER" is the number of product module
if ( !$quard->validate( $feature ) ) {
// user doesn't have a valid license for product module with the number "PRODUCT_MODULE_NUMBER"
// get shop url
echo $quard->get_shop_url(); // https://go.netlicensing.io/shop/v2/?shoptoken=686f5554-5978-4a68-a7f0-0b4996e8826c
}
Labs64 NetLicensing - Innovative License Management Solution
NetLicensing.IO | Licensing Models | Getting Started | NetLicensing API | PluginPass