Created
September 20, 2022 18:59
-
-
Save ajgagnon/9c5f265951d1c04a23f51e58023085cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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