Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Now run:
```php
$license = \get_option(\Dwnload\EddSoftwareLicenseManager\Edd\AbstractLicenceManager::LICENSE_SETTING, []);
$data = [
'api_url' => 'https://frosty.media/',
'license' => $license[$plugin_id]['license'] ?? '',
'item_name' => 'Custom Login Style Pack #1', // Name of this plugin (matching your EDD Download title).
'author' => 'Frosty Media',
Expand All @@ -38,6 +39,6 @@ $data = [
];
\TheFrosty\WpUtilities\Plugin\Plugin $plugin
->add(new Edd\LicenseManager($plugin, $data))
->add(new Edd\PluginUpdater('https://frosty.media/', __FILE__, $data))
->add(new Edd\PluginUpdater($data['api_url'], __FILE__, $data))
->initialize();
```
```
15 changes: 11 additions & 4 deletions src/Edd/AbstractLicenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Dwnload\WpSettingsApi\WpSettingsApi;
use TheFrosty\WpUtilities\Api\TransientsTrait;
use TheFrosty\WpUtilities\Plugin\Plugin;
use Throwable;
use function __;
use function add_query_arg;
use function date_i18n;
Expand All @@ -29,6 +30,7 @@
use function strtotime;
use function time;
use function trim;
use function untrailingslashit;
use function update_option;
use function wp_get_environment_type;
use function wp_remote_post;
Expand Down Expand Up @@ -346,11 +348,16 @@ private function getApiResponse(array $api_params): array
);

// Make sure the response came back okay.
if (is_wp_error($response)) {
$code = wp_remote_retrieve_response_code($response);
if (is_wp_error($response) || is_wp_error($code) || $code !== 200) {
return [];
}

return json_decode(wp_remote_retrieve_body($response), true);
try {
return json_decode(wp_remote_retrieve_body($response), true, 512, JSON_THROW_ON_ERROR);
} catch (Throwable) {
return [];
}
}

/**
Expand All @@ -361,7 +368,7 @@ private function getApiResponse(array $api_params): array
*/
private function getRenewalUrl(string $license_key = '', ?int $item_id = null): string
{
if (!empty($license_key) || !empty($item_id)) {
if (!empty($license_key) || $item_id !== null) {
return add_query_arg(
[
'edd_license' => $license_key,
Expand All @@ -370,7 +377,7 @@ private function getRenewalUrl(string $license_key = '', ?int $item_id = null):
'utm_medium' => 'edd-software-licence',
'utm_campaign' => 'licence',
],
sprintf('%s/checkout/', \untrailingslashit($this->pluginData->getApiUrl()))
sprintf('%s/checkout/', untrailingslashit($this->pluginData->getApiUrl()))
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Edd/LicenseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LicenseManager extends AbstractLicenceManager implements WpHooksInterface

public const string AJAX_ACTION = __CLASS__;
public const string HANDLE = 'license-manager';
public const string VERSION = '2.2.0';
public const string VERSION = '2.2.1';

public function addHooks(): void
{
Expand Down Expand Up @@ -76,6 +76,7 @@ protected function init(
])
);

$plugin_id = $this->parent->getSlug();
$field_manager->addField(
new SettingField(
[
Expand Down