Use the slm_check to verify if the license is active or not. This example code will throw a JavaScript alert if the license comes back activated or deactivated.
/*** Verify license key is active ***/
$api_params = array(
'slm_action' => 'slm_check',
'secret_key' => 'YOUR_SECRET_KEY_GOES_HERE',
'license_key' => get_option('sample_license_key'), //replace with your license key field name.
);
// Send query to the license manager server
$response = wp_remote_get(add_query_arg($api_params, YOUR_LICENSE_SERVER_URL), array('timeout' => 20, 'sslverify' => false));
$license_data = json_decode(wp_remote_retrieve_body($response));
global $active, $message;
if($license_data->result == 'success'){?>
<script>alert('Activated');</script>
<?php }else{ ?>
<script>alert('Deactivated');</script>
<?php }
You could even go a step further and check if the license is active and as well as if it is past the expiration date.
/*** Verify license key is active and expire date has not passed ***/
$api_params = array(
'slm_action' => 'slm_check',
'secret_key' => 'YOUR_SECRET_KEY_GOES_HERE',
'license_key' => get_option('sample_license_key'), //replace with your license key field name.
);
// Send query to the license manager server
$response = wp_remote_get(add_query_arg($api_params, YOUR_LICENSE_SERVER_URL), array('timeout' => 20, 'sslverify' => false));
$license_data = json_decode(wp_remote_retrieve_body($response));
global $active, $message;
if($license_data->result == 'success' && $license_data->date_expiry >= date('Y-m-d')){?>
<script>alert('Activated');</script>
<?php }else{ ?>
<script>alert('Deactivated');</script>
<?php }
Running this will show you an alert that will verify it works. After you have verified that it works, just replace the JavaScript alerts with whatever functions you want to run for activated and deactivated.
I’m using this same code to activate the shortcode in my plugin if the license is activated and the expiration date hasn’t passed. If the expiration date has passed and the license is still active, then my shortcode still isn’t usable.