Skip to content

Commit

Permalink
Updated - better detection of plugin/theme type, license timings
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiIgna committed Apr 1, 2020
1 parent 9e72920 commit 4279ae0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class Api {
private $slug;
private $type;

public function __construct($path, $slug) {
public function __construct($path, $slug, $type = null) {
$this->path = $path;
$this->slug = $slug;
$this->type = strpos($path, '/plugins/') !== false ? 'plugin' : 'theme';
$this->type = $type ?: (strpos($path, '/themes/') !== false ? 'theme' : 'plugin');

// Auto-update
$detailsUrl = add_query_arg([
Expand Down Expand Up @@ -51,13 +51,13 @@ public function getLicense() {

if (in_array(wp_remote_retrieve_response_code($response), [200, 400])) {
$licenseData = json_decode(wp_remote_retrieve_body($response), true);
set_transient($this->slug . '-license-data', $licenseData, 24 * WEEK_IN_SECONDS);
set_transient($this->slug . '-license-data', $licenseData, WEEK_IN_SECONDS);
} else {
$licenseData = [
'error_code' => 'license_invalid',
'error_message' => 'Could not verify the License Key'
];
set_transient($this->slug . '-license-data', $licenseData, DAY_IN_SECONDS);
set_transient($this->slug . '-license-data', $licenseData, 6 * HOUR_IN_SECONDS);
}
}

Expand Down

0 comments on commit 4279ae0

Please sign in to comment.