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
45 changes: 45 additions & 0 deletions includes/class-integrate-convertkit-wpforms-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,56 @@ public function update() {
$this->migrate_form_settings();
}

// Actions that should run regardless of the version number
// whenever the Plugin is updated.
$this->remove_v3_api_key_and_secret_from_settings();

// Update the installed version number in the options table.
update_option( 'integrate_convertkit_wpforms_version', INTEGRATE_CONVERTKIT_WPFORMS_VERSION );

}

/**
* Remove v3 API key and Secret from settings.
*
* @since 1.9.2
*/
private function remove_v3_api_key_and_secret_from_settings() {

// Bail if the wpforms_get_providers_options() function isn't available.
if ( ! function_exists( 'wpforms_get_providers_options' ) ) {
return;
}

// Get providers.
$providers = wpforms_get_providers_options();

// Bail if no providers exist.
if ( ! $providers ) {
return;
}

// Bail if no Kit connections exist.
if ( ! array_key_exists( 'convertkit', $providers ) ) {
return;
}

// Iterate through providers.
foreach ( $providers['convertkit'] as $account_id => $settings ) {
// Remove v3 API Secret from settings.
$settings['api_key'] = '';
$settings['api_secret'] = '';

// Save settings.
wpforms_update_providers_options(
'convertkit',
$settings,
$account_id
);
}

}

/**
* 1.7.2: Prefix any connection form settings with `form:`, now that
* the Plugin supports adding a subscriber to a Form, Tag or Sequence.
Expand Down
44 changes: 41 additions & 3 deletions tests/EndToEnd/general/UpgradePathsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ public function testMigrateFormSettingsToIntegration(EndToEndTester $I)

// Get first integration for ConvertKit, and confirm it has the expected array structure and values.
$account = reset( $providers['convertkit'] );
$I->assertArrayHasKey('api_key', $account);
$I->assertArrayHasKey('api_secret', $account);
$I->assertArrayHasKey('label', $account);
$I->assertArrayHasKey('date', $account);
$I->assertEquals($_ENV['CONVERTKIT_API_KEY'], $account['api_key']);
$I->assertEquals('Kit', $account['label']);
}

Expand Down Expand Up @@ -149,4 +146,45 @@ public function testFormSettingsPrefixAddedToSettingsOnUpgrade(EndToEndTester $I
]
);
}

/**
* Tests that the v3 API Key and Secret are removed from settings when upgrading to 1.9.2 or later.
*
* @since 1.9.2
*
* @param EndToEndTester $I Tester.
*/
public function testV3APIKeyAndSecretRemovedFromSettings(EndToEndTester $I)
{
// Setup Plugin's settings with an API Key and Secret.
$I->setupWPFormsIntegrationWithAPIKeyAndSecret($I);

// Define an installation version older than 1.9.2.
$I->haveOptionInDatabase('integrate_convertkit_wpforms_version', '1.9.0');

// Activate Plugins.
$I->activateThirdPartyPlugin($I, 'wpforms-lite');
$I->activateConvertKitPlugin($I);

// Confirm the provider connections no longer have a value for the v3 API Key and Secret.
$settings = $I->grabOptionFromDatabase('wpforms_providers');
$connection = reset($settings['convertkit']);
$I->assertEmpty($connection['api_key']);
$I->assertEmpty($connection['api_secret']);
}

/**
* Deactivate and reset Plugin(s) after each test, if the test passes.
* We don't use _after, as this would provide a screenshot of the Plugin
* deactivation and not the true test error.
*
* @since 1.9.2
*
* @param EndToEndTester $I Tester.
*/
public function _passed(EndToEndTester $I)
{
$I->deactivateConvertKitPlugin($I);
$I->deactivateThirdPartyPlugin($I, 'wpforms-lite');
}
}
Loading