diff --git a/README.md b/README.md index 27b2e74..8404f73 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,9 @@ $client->set_textdomain( 'your-project-textdomain' ); ``` ## Example Plugin -[surecart-plugin-license.zip](https://d.pr/f/DVzMC0) +[surecart-plugin-license.zip](https://d.pr/f/6ZyfAS) ## Example Theme -[surecart-theme-license.zip](https://d.pr/f/m51Tt5) +[surecart-theme-license.zip](https://d.pr/f/RK8NFS) + +For full setup and functionality details, see the official documentation: [Licensing Setup and Functionality](https://surecart.com/docs/licensing-setup-and-functionality/). diff --git a/src/Client.php b/src/Client.php index 0a7f4ff..fd2ad0b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -12,7 +12,7 @@ class Client { * * @var string */ - public $version = '1.2.0'; + public $version = '1.2.1'; /** * Name of the plugin diff --git a/src/Settings.php b/src/Settings.php index 8e32a5e..2d6d04f 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -293,18 +293,33 @@ public function print_css() { /** * Get the activation. * + * A read never writes to stored options; it only surfaces an error message. + * On a 404 the stale activation_id is left in the database (it gets overwritten + * on reactivation), but this still returns false so the page shows "Activate + * License" instead of a "Deactivate License" button that would just keep failing. + * * @return Object|false */ public function get_activation() { - $activation = false; - if ( $this->activation_id ) { - $activation = $this->client->activation()->get( $this->activation_id ); - if ( is_wp_error( $activation ) ) { - $this->add_error( 'deactivaed', $this->client->__( 'Your license has been deactivated for this site.', 'surecart' ) ); - $this->clear_options(); - } + if ( ! $this->activation_id ) { + return false; + } + + $activation = $this->client->activation()->get( $this->activation_id ); + + if ( ! is_wp_error( $activation ) ) { + return $activation; } - return $activation; + + if ( 'not_found' === $activation->get_error_code() ) { + $this->add_error( 'activation_removed', $this->client->__( 'The activation for this site was removed. Click Activate License to reconnect it.' ) ); + return false; + } + + $this->add_error( 'unverified', $this->client->__( 'Could not verify your license right now. Your license key has been kept; please try again later.' ) ); + + // Keep the form in "activated" state so the user is not asked to re-enter the key. + return (object) array( 'id' => $this->activation_id ); } /**