LLMS_Helper_Keys::activate_keys( string|array $keys, bool $force = false )
Activate LifterLMS License Keys with the remote server.
Parameters Parameters
- $keys
-
(string|array) (Required) Array or a white-space separated list of API keys.
- $force
-
(bool) (Optional) Whether to force a remote check. Default
false.Default value: false
Return Return
(array)
Source Source
File: libraries/lifterlms-helper/includes/class-llms-helper-keys.php
public static function activate_keys( $keys, $force = false ) {
// Sanitize before sending.
if ( ! is_array( $keys ) ) {
$keys = explode( PHP_EOL, $keys );
}
$keys = array_map( 'sanitize_text_field', $keys );
$keys = array_map( 'trim', $keys );
$keys = array_unique( $keys );
$keys = array_filter( $keys ); // Remove empty keys.
$data = array(
'keys' => $keys,
'url' => get_site_url(),
);
// Check for a cached result based on the keys and url input.
$cache_hash = md5( wp_json_encode( $data ) );
if ( $force ) {
// Delete cache if forcing a remote check.
delete_site_transient( 'llms_helper_keys_activation_response_' . $cache_hash );
} else {
// Use the cached result if present.
$cached_req_result = get_site_transient( 'llms_helper_keys_activation_response_' . $cache_hash );
if ( ! empty( $cached_req_result ) ) {
return $cached_req_result;
}
}
$req = new LLMS_Dot_Com_API( '/license/activate', $data );
set_site_transient( 'llms_helper_keys_activation_response_' . $cache_hash, $req->get_result(), HOUR_IN_SECONDS );
return $req->get_result();
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.5.0 | Caching results. Added $force parameter. |
| 3.4.2 | Removed empty key lines. |
| 3.0.1 | Unknown. |
| 3.0.0 | Introduced. |