-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from ConvertKit/add-notice-for-official-addon
Add Notice Recommending Official Add-On
- Loading branch information
Showing
7 changed files
with
194 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |