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
12 changes: 11 additions & 1 deletion src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ private function handle_sync() {
$response = $this->integration->client->check_license( $key );

if ( is_wp_error( $response ) ) {
if ( 'invalid_license' === $response->get_error_code() ) {
$this->integration->delete_license_code();
$this->integration->delete_license_data();
}

wp_redirect(
add_query_arg(
'error',
Expand Down Expand Up @@ -164,7 +169,7 @@ private function handle_save() {
$base_url = remove_query_arg( [ 'm' ] );

if ( empty( $_POST['wprepo_license'] ) ) {
delete_option( $this->integration->get_license_code_key() );
$this->integration->delete_license_code();
$this->integration->clear_updates_transient();
wp_redirect(
add_query_arg(
Expand All @@ -180,6 +185,11 @@ private function handle_save() {
$response = $this->integration->client->check_license( $key );

if ( is_wp_error( $response ) ) {
if ( 'invalid_license' === $response->get_error_code() ) {
$this->integration->delete_license_code();
$this->integration->delete_license_data();
}

wp_redirect(
add_query_arg(
'error',
Expand Down
22 changes: 22 additions & 0 deletions src/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,28 @@ public function update_license_data( $data ) {
return update_option( $this->get_license_data_key(), $data );
}

/**
* Deletes the license code from the database.
*
* @since 1.2
*
* @return bool True if the option was deleted, false otherwise.
*/
public function delete_license_code() {
return delete_option( $this->get_license_code_key() );
}

/**
* Deletes the license data from the database.
*
* @since 1.2
*
* @return bool True if the option was deleted, false otherwise.
*/
public function delete_license_data() {
return delete_option( $this->get_license_data_key() );
}

/**
* Checks if the license is currently active.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function sync_license_data() {

$response = $this->integration->client->check_license();
if ( is_wp_error( $response ) ) {
if ( 'invalid_license' === $response->get_error_code() ) {
$this->integration->delete_license_code();
$this->integration->delete_license_data();
}

return;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/IntegrationLicenseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,30 @@ public function get_license_renewal_url_handles_missing_license_code() {
);
}

/** @test */
public function delete_license_code_calls_delete_option() {
$integration = $this->create_integration();

Functions\expect( 'delete_option' )
->once()
->with( 'my-plugin42_code' )
->andReturn( true );

$this->assertTrue( $integration->delete_license_code() );
}

/** @test */
public function delete_license_data_calls_delete_option() {
$integration = $this->create_integration();

Functions\expect( 'delete_option' )
->once()
->with( 'my-plugin42_data' )
->andReturn( true );

$this->assertTrue( $integration->delete_license_data() );
}

/** @test */
public function get_license_renewal_url_returns_url_without_placeholders() {
$integration = $this->create_integration();
Expand Down