Retrieving the license status for a key in Easy Digital Downloads

Easy Digital Downloads

As a user of Easy Digital Downloads software licensing, I was looking for a way to retrieve the Easy Digital Downloads license status. I use this to determine the license status on submit of the support form of the EDD websites.

Though I might have missed something, there doesn’t seem to be a direct way to retrieve a status. There is the function get_license_status, which is part of the edd_software_licensing class, but it is used in combination with the post status to retrieve the actual status.┬áSo after some digging into Easy Digital Downloads I came up with a solution which I thought would be good to share.

/*

Get license status by license key

*/

function rsp_get_license_status($key) {
//retrieve the license
$license = edd_software_licensing()->get_license( $key, true );

//retrieve status. This is not the end result yet.
$license_status = edd_software_licensing()->get_license_status( $license->ID );

$post_status = $license->post_status;

if (($post_status == ‘publish’) && ($license_status == ‘active’)){
$status = __(‘active’,”edd-gravity-forms-license-check”);
}

if (($post_status == ‘publish’) && ($license_status == ‘inactive’)){
$status = __(‘inactive’,”edd-gravity-forms-license-check”);
}

if ( ‘expired’ == $license_status) {
$status = __(‘expired’,”edd-gravity-forms-license-check”);
}

if ($post_status == ‘draft’) {
$status = __(‘revoked’,”edd-gravity-forms-license-check”);
}

return $status;
}

/*

Get the maximum number of activations possible on this license

*/

function rsp_get_activation_limit($key) {
$license = edd_software_licensing()->get_license( $key, true );
return $license->activation_limit;
}

/*

Get the number of actual activations on this license

*/

function rsp_get_activation_count($key){
$license = edd_software_licensing()->get_license( $key, true );
return $license->activation_count;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

×