Skip to content

Instantly share code, notes, and snippets.

@ajgagnon
Created September 20, 2022 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajgagnon/9c5f265951d1c04a23f51e58023085cb to your computer and use it in GitHub Desktop.
Save ajgagnon/9c5f265951d1c04a23f51e58023085cb to your computer and use it in GitHub Desktop.
<?php
// manually include the SDK.
if ( ! class_exists( 'SureCart\Licensing\Client' ) ) {
require_once __DIR__ . '/licensing/src/Client.php';
}
/**
* Validates license with license manager for SureCart
*
* @param Boolean $access true or false based on access.
* @param String $key the access key.
* @param WP_REST_Request $request full details about the request.
* @return Boolean based on if access should be granted.
*/
function custom_check_cloud_access( $access, $key, $request ) {
// class must exist.
if ( ! class_exists( 'SureCart\Licensing\Client' ) ) {
return $access;
}
// initialize client with your product name.
$client = new \SureCart\Licensing\Client( 'My Product Name', __FILE__ );
// is the license activated yet?
$activated = $client->license()->is_active();
// not yet activated, activate it.
if ( ! $activated ) {
$result = $client->license()->activate( $key );
// handle response.
return is_wp_error( $result ) ? false : $result;
}
// otherwise check the license validity.
$result = $client->license()->is_valid( $key );
// handle response.
return is_wp_error( $result ) ? false : $result;
}
add_filter( 'kadence_cloud_rest_request_access', 'custom_check_cloud_access', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment