Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for validation of a license key without a Resource object #94

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
26 changes: 18 additions & 8 deletions src/Uplink/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,28 @@ protected function request( $method, $endpoint, $args ) {
* Validates the license.
*
* @since 1.0.0
* @since 2.3.0 Added support for validation license using a plan/product slug in addition to a Resource object.
*
* @param Resource $resource Resource to validate.
* @param string|null $key License key.
* @param string $validation_type Validation type (local or network).
* @param bool $force Force the validation.
* @param Resource|string $resource Resource or plan/product slug to validate.
* @param string|null $key License key.
* @param string $validation_type Validation type (local or network).
* @param bool $force Force the validation.
*
* @return mixed
*/
public function validate_license( Resource $resource, string $key = null, string $validation_type = 'local', bool $force = false ) {
public function validate_license( $resource, string $key = null, string $validation_type = 'local', bool $force = false ) {
/** @var Data */
$site_data = $this->container->get( Data::class );
$args = $resource->get_validation_args();
$site_data = $this->container->get( Data::class );
$is_network_activated = false;

$args = [];

if ( $resource instanceof Resource ) {
$args = $resource->get_validation_args();
$is_network_activated = $resource->is_network_activated();
} else {
$args['plugin'] = $resource;
}

if ( ! empty( $key ) ) {
$args['key'] = Utils\Sanitize::key( $key );
Expand All @@ -206,7 +216,7 @@ public function validate_license( Resource $resource, string $key = null, string
$args['domain'] = $site_data->get_domain();
$args['stats'] = $site_data->get_stats();

$args['stats']['network']['network_activated'] = $resource->is_network_activated();
$args['stats']['network']['network_activated'] = $is_network_activated;

/**
* Filter the license validation arguments.
Expand Down
Loading