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

Add Notice Recommending Official Add-On #107

Merged
merged 4 commits into from
Feb 9, 2024
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
1 change: 1 addition & 0 deletions convertkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
// Load files that are always used.
require_once CKGF_PLUGIN_PATH . '/includes/functions.php';
require_once CKGF_PLUGIN_PATH . '/includes/class-ckgf-api.php';
require_once CKGF_PLUGIN_PATH . '/includes/class-ckgf-notices.php';
require_once CKGF_PLUGIN_PATH . '/includes/class-wp-ckgf.php';

/**
Expand Down
84 changes: 84 additions & 0 deletions includes/class-ckgf-notices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Notices class.
*
* @package CKWC
* @author ConvertKit
*/

/**
* Notices class.
*
* @package CKWC
* @author ConvertKit
*/
class CKGF_Notices {

/**
* Constructor.
*
* @since 1.4.2
*/
public function __construct() {

add_action( 'admin_init', array( $this, 'maybe_deactivate_plugin' ) );

}

/**
* Deactivates this Plugin if the official Gravity Forms ConvertKit Add-On is active.
*
* @since 1.4.2
*/
public function maybe_deactivate_plugin() {

// If the official Gravity Forms ConvertKit Add-On is active, deactivate
// our Plugin.
if ( is_plugin_active( 'gravityformsconvertkit/convertkit.php' ) ) {
deactivate_plugins( 'convertkit-gravity-forms/convertkit.php' );
return;
}

// The official Gravity Forms ConvertKit Add-On is not installed.
// Recommend the user install it by showing a notice.
add_action( 'admin_notices', array( $this, 'output_notice' ) );

}

/**
* Output a persistent notice in the WordPress Administration
* telling users to migrate to the official Add-on.
*
* @since 1.4.2
*/
public function output_notice() {

?>
<div class="notice notice-warning">
<p>
<?php
printf(
'%s <a href="%s" target="_blank">%s</a>. %s',
esc_html__( 'ConvertKit Gravity Forms Add-On: Please install the official', 'convertkit' ),
esc_url( 'https://www.gravityforms.com/blog/convertkit-add-on/' ),
esc_html__( 'Gravity Forms ConvertKit Add-On', 'convertkit' ),
esc_html__( 'Your existing settings will automatically migrate once installed and active.', 'convertkit' )
);
?>
</p>
</div>
<?php

}

}

// Initialize class.
add_action(
'convertkit_gravity_forms_initialize_admin',
function () {

new CKGF_Notices();

}
);
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ConvertKit is an email marketing platform for capturing leads from your WordPres

== Description ==

** Please use the official [Gravity Forms ConvertKit Add-On](https://www.gravityforms.com/blog/convertkit-add-on/). Your existing settings will automatically migrate once installed and active. This Add-on will only receive security updates. **

[ConvertKit](https://convertkit.com) makes it easy to capture more leads and sell more products by easily embedding email capture forms anywhere.

This Plugin integrates Gravity Forms with ConvertKit, allowing form submissions to be automatically sent to your ConvertKit account.
Expand Down
4 changes: 0 additions & 4 deletions tests/_support/Helper/Acceptance/GravityForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ public function createGravityFormsForm($I)
// Wait for the Form Edit screen to load.
$I->waitForElementVisible('#no-fields');

// Open Advanced Fields Panel.
$I->click('button[aria-controls="add_advanced_fields"]');
$I->wait(2);

// Add Name Field.
$I->click('#add_advanced_fields button[data-type="name"]');
$I->wait(2);
Expand Down
8 changes: 8 additions & 0 deletions tests/_support/Helper/Acceptance/ThirdPartyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function activateThirdPartyPlugin($I, $name)
$I->seePluginActivated('gravityforms');
break;

case 'gravity-forms-convertkit-add-on':
$I->seePluginActivated('gravityformsconvertkit');
break;

default:
$I->seePluginActivated($name);
break;
Expand Down Expand Up @@ -72,6 +76,10 @@ public function deactivateThirdPartyPlugin($I, $name)
$I->deactivatePlugin('gravityforms');
break;

case 'gravity-forms-convertkit-add-on':
$I->deactivatePlugin('gravityformsconvertkit');
break;

default:
$I->deactivatePlugin($name);
break;
Expand Down
18 changes: 9 additions & 9 deletions tests/acceptance/forms/FormCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testCreateFormAndFeed(AcceptanceTester $I)
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);

// Submit Form.
$I->click('Submit');
Expand Down Expand Up @@ -135,7 +135,7 @@ public function testCreateFormAndFeedWithNoConvertKitFormSelected(AcceptanceTest
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);

// Submit Form.
$I->click('Submit');
Expand Down Expand Up @@ -320,7 +320,7 @@ public function testCreateFormAndFeedWithTagAndFieldTagSelected(AcceptanceTester
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);
$I->selectOption('select.gfield_select', $_ENV['CONVERTKIT_API_ADDITIONAL_TAG_NAME']);

// Submit Form.
Expand Down Expand Up @@ -399,7 +399,7 @@ public function testCreateFormAndFeedWithFieldTagSelected(AcceptanceTester $I)
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);
$I->selectOption('select.gfield_select', $_ENV['CONVERTKIT_API_ADDITIONAL_TAG_NAME']);

// Submit Form.
Expand Down Expand Up @@ -478,7 +478,7 @@ public function testCreateFormAndFeedWithInvalidFieldTagSelected(AcceptanceTeste
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);
$I->selectOption( 'select.gfield_select', 'fakeTagNotInConvertKit' );

// Submit Form.
Expand Down Expand Up @@ -557,7 +557,7 @@ public function testCreateFormAndFeedWithTagSelected(AcceptanceTester $I)
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);

// Submit Form.
$I->click('Submit');
Expand Down Expand Up @@ -641,7 +641,7 @@ public function testCreateFormAndFeedWithConditionalLogicMatching(AcceptanceTest
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);

// Submit Form.
$I->click('Submit');
Expand Down Expand Up @@ -720,7 +720,7 @@ public function testCreateFormAndFeedWithConditionalLogicDoesNotMatch(Acceptance
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);

// Submit Form.
$I->click('Submit');
Expand Down Expand Up @@ -790,7 +790,7 @@ public function testCreateFormAndFeedDisabled(AcceptanceTester $I)
// Complete Form Fields.
$I->fillField('.name_first input[type=text]', $firstName);
$I->fillField('.name_last input[type=text]', $lastName);
$I->fillField('.ginput_container_email input[type=text]', $emailAddress);
$I->fillField('.ginput_container_email input[type=email]', $emailAddress);

// Submit Form.
$I->click('Submit');
Expand Down
90 changes: 90 additions & 0 deletions tests/acceptance/general/NoticesCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Tests the notices output recommending the official add-on.
*
* @since 1.4.2
*/
class NoticesCest
{
/**
* Holds the expected notice text.
*
* @since 1.4.2
*
* @var string
*/
public $expectedNoticeText = 'ConvertKit Gravity Forms Add-On: Please install the official Gravity Forms ConvertKit Add-On. Your existing settings will automatically migrate once installed and active.';

/**
* Run common actions before running the test functions in this class.
*
* @since 1.4.2
*
* @param AcceptanceTester $I Tester.
*/
public function _before(AcceptanceTester $I)
{
$I->activateConvertKitPlugin($I);
}

/**
* Test that the persistent notice displays with expected wording when the Plugin is active.
*
* @since 1.4.2
*
* @param AcceptanceTester $I Tester.
*/
public function testPersistentNoticeDisplays(AcceptanceTester $I)
{
// Confirm notice displays with expected text.
$I->seeElement('.notice-warning');
$I->see($this->expectedNoticeText);

// Confirm the link is valid.
$I->assertEquals(
$I->grabAttributeFrom('.notice-warning a', 'href'),
'https://www.gravityforms.com/blog/convertkit-add-on/'
);

// Deactivate Plugin.
$I->deactivateConvertKitPlugin($I);

// Confirm no notice from this Plugin displays.
$I->dontSee($this->expectedNoticeText);
}

/**
* Test that the persistent notice does not display when the official add-on is active.
*
* @since 1.4.2
*
* @param AcceptanceTester $I Tester.
*/
public function testPersistentNoticeNotDisplayedWhenOfficialAddonActive(AcceptanceTester $I)
{
// Activate Gravity Forms and official add-on.
$I->activateThirdPartyPlugin($I, 'gravity-forms');
$I->activateThirdPartyPlugin($I, 'gravity-forms-convertkit-add-on');

// Confirm no notice from this Plugin displays.
$I->dontSee($this->expectedNoticeText);

// When the official add-on is activated, it checks whether this Plugin is also active, deactivating it if so.
// Confirm the official add-on displays its notice that it deactivated this Plugin.
$I->see('In order to prevent conflicts, we disabled the existing ConvertKit for Gravity Forms plugin.');
}

/**
* 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.2.2
*
* @param AcceptanceTester $I Tester.
*/
public function _passed(AcceptanceTester $I)
{
$I->resetConvertKitPlugin($I);
}
}
Loading