Skip to content

Commit

Permalink
Merge pull request #765 from Kit/add-intercom-to-settings-screens
Browse files Browse the repository at this point in the history
Add Intercom to Settings and Setup Wizard Screens
  • Loading branch information
n7studios authored Jan 30, 2025
2 parents 1f81530 + c3d7a2b commit 53eceb7
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 4 deletions.
5 changes: 5 additions & 0 deletions admin/class-convertkit-admin-settings-restrict-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public function __construct() {
// Enqueue scripts.
add_action( 'convertkit_admin_settings_enqueue_scripts', array( $this, 'enqueue_scripts' ) );

// Output the Intercom messenger.
if ( $this->on_settings_screen( $this->name ) ) {
add_action( 'admin_footer', array( $this, 'output_intercom' ) );
}

parent::__construct();

}
Expand Down
3 changes: 2 additions & 1 deletion admin/section/class-convertkit-admin-settings-broadcasts.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public function __construct() {
),
);

// Register and maybe output notices for this settings screen.
// Register and maybe output notices for this settings screen, and the Intercom messenger.
if ( $this->on_settings_screen( $this->name ) ) {
add_filter( 'convertkit_settings_base_register_notices', array( $this, 'register_notices' ) );
add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
add_action( 'admin_footer', array( $this, 'output_intercom' ) );
}

// Enqueue scripts and CSS.
Expand Down
11 changes: 11 additions & 0 deletions admin/section/class-convertkit-settings-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,15 @@ public function sanitize_settings( $settings ) {

}

/**
* Outputs the Intercom help widget in the footer of the Plugin's settings screens.
*
* @since 2.7.2
*/
public function output_intercom() {

convertkit_output_intercom_messenger();

}

}
3 changes: 2 additions & 1 deletion admin/section/class-convertkit-settings-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ public function __construct() {
),
);

// Register and maybe output notices for this settings screen.
// Register and maybe output notices for this settings screen, and the Intercom messenger.
if ( $this->on_settings_screen( $this->name ) ) {
add_filter( 'convertkit_settings_base_register_notices', array( $this, 'register_notices' ) );
add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
add_action( 'admin_footer', array( $this, 'output_intercom' ) );
}

// Enqueue scripts and CSS.
Expand Down
3 changes: 2 additions & 1 deletion admin/section/class-convertkit-settings-oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public function __construct() {
$this->title = __( 'OAuth', 'convertkit' );
$this->tab_text = __( 'OAuth', 'convertkit' );

// Output notices for this settings screen.
// Maybe output notices for this settings screen, and the Intercom messenger.
if ( $this->on_settings_screen( 'general' ) ) {
add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
add_action( 'admin_footer', array( $this, 'output_intercom' ) );
}

parent::__construct();
Expand Down
3 changes: 2 additions & 1 deletion admin/section/class-convertkit-settings-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public function __construct() {
$this->title = __( 'Tools', 'convertkit' );
$this->tab_text = __( 'Tools', 'convertkit' );

// Register and maybe output notices for this settings screen.
// Register and maybe output notices for this settings screen, and the Intercom messenger.
if ( $this->on_settings_screen( $this->name ) ) {
add_filter( 'convertkit_settings_base_register_notices', array( $this, 'register_notices' ) );
add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
add_action( 'admin_footer', array( $this, 'output_intercom' ) );
}

parent::__construct();
Expand Down
23 changes: 23 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,26 @@ function convertkit_get_current_screen( $property ) {
return $screen->$property;

}

/**
* Outputs the Intercom help widget script.
*
* @since 2.7.2
*/
function convertkit_output_intercom_messenger() {

?>
<script>
const KIT_INTERCOM_APP_ID = 'e4n3xtxz';
window.intercomSettings = {
api_base: 'https://api-iam.intercom.io',
app_id: KIT_INTERCOM_APP_ID
};
</script>

<script>
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/' + KIT_INTERCOM_APP_ID;var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
</script>
<?php

}
123 changes: 123 additions & 0 deletions tests/acceptance/general/PluginIntercomCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Tests for the Settings > Kit > General screens.
*
* @since 2.7.2
*/
class PluginIntercomCest
{
/**
* Run common actions before running the test functions in this class.
*
* @since 2.7.2
*
* @param AcceptanceTester $I Tester.
*/
public function _before(AcceptanceTester $I)
{
$I->activateConvertKitPlugin($I);
}

/**
* Test that the Intercom script is loaded on the Plugin settings screens.
*
* @since 2.7.2
*
* @param AcceptanceTester $I Tester.
*/
public function testIntercomDisplaysOnPluginScreens(AcceptanceTester $I)
{
// Go to the Plugin's Settings screen, which will show the OAuth Connect button.
$I->loadConvertKitSettingsGeneralScreen($I);

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);

// Authenticate the Plugin.
$I->setupConvertKitPlugin($I);

// Go to the Plugin's Settings screen, which will show all settings.
$I->loadConvertKitSettingsGeneralScreen($I);

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);

// Go to the Plugin's Tools screen.
$I->loadConvertKitSettingsToolsScreen($I);

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);

// Go to the Plugin's Restrict Content Settings screen.
$I->loadConvertKitSettingsRestrictContentScreen($I);

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);

// Go to the Plugin's Broadcasts screen.
$I->loadConvertKitSettingsBroadcastsScreen($I);

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);
}

/**
* Test that the Intercom script is loaded on the Setup Wizard screens.
*
* @since 2.7.2
*
* @param AcceptanceTester $I Tester.
*/
public function testIntercomDisplaysOnSetupWizardScreens(AcceptanceTester $I)
{
// Setup Plugin.
$I->setupConvertKitPlugin($I);

// Go to the Plugin's Setup Wizard screen.
$I->amOnAdminPage('options.php?page=convertkit-setup');

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);

// Go to the Plugin's Landing Page Wizard screen.
$I->amOnAdminPage('options.php?page=convertkit-landing-page-setup&ck_post_type=page');

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);

// Go to the Plugin's Member Content Wizard screen.
$I->amOnAdminPage('options.php?page=convertkit-restrict-content-setup&ck_post_type=page');

// Confirm the Intercom script is loaded.
$this->_seeIntercomScript($I);
}

/**
* Assert that the Intercom script is loaded.
*
* @since 2.7.2
*
* @param AcceptanceTester $I Tester.
*/
private function _seeIntercomScript(AcceptanceTester $I)
{
$I->waitForElementVisible('.intercom-lightweight-app-launcher-icon');
$I->click('.intercom-lightweight-app-launcher-icon');
$I->waitForElementVisible('iframe[data-intercom-frame="true"]');
}

/**
* 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 2.7.2
*
* @param AcceptanceTester $I Tester.
*/
public function _passed(AcceptanceTester $I)
{
$I->deactivateConvertKitPlugin($I);
$I->resetConvertKitPlugin($I);
}
}
3 changes: 3 additions & 0 deletions views/backend/setup-wizard/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
</div>
<?php
}

// Output Intercom.
convertkit_output_intercom_messenger();
?>
</div>
</body>
Expand Down

0 comments on commit 53eceb7

Please sign in to comment.