Skip to content

Commit

Permalink
Merge pull request #94 from stellarwp/fix/validate-without-resource
Browse files Browse the repository at this point in the history
Allow for validation of a license key without a Resource object
  • Loading branch information
borkweb authored Jan 9, 2025
2 parents 5bc1f11 + 9871efb commit 9d22b71
Showing 1 changed file with 18 additions and 8 deletions.
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

0 comments on commit 9d22b71

Please sign in to comment.