Skip to content
Open
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
85 changes: 85 additions & 0 deletions admin/importers/class-convertkit-admin-importer-activecampaign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* ConvertKit Admin Importer ActiveCampaign class.
*
* @package ConvertKit
* @author ConvertKit
*/

/**
* Import and migrate data from ActiveCampaign to Kit.
*
* @package ConvertKit
* @author ConvertKit
*/
class ConvertKit_Admin_Importer_ActiveCampaign extends ConvertKit_Admin_Importer {

/**
* Holds the shortcode name for MC4WP forms.
*
* @since 3.1.7
*
* @var string
*/
public $shortcode_name = 'activecampaign';

/**
* Holds the ID attribute name for MC4WP forms.
*
* @since 3.1.7
*
* @var string
*/
public $shortcode_id_attribute = 'form';

/**
* Holds the block name for MC4WP forms.
*
* @since 3.1.7
*
* @var string
*/
public $block_name = 'activecampaign-form/activecampaign-form-block';

/**
* Holds the ID attribute name for MC4WP forms.
*
* @since 3.1.7
*
* @var string
*/
public $block_id_attribute = 'formId';

/**
* Returns an array of MC4WP form IDs and titles.
*
* @since 3.1.7
*
* @return array
*/
public function get_forms() {

// Forms are cached in the Plugin Settings.
$settings = get_option( 'settings_activecampaign' );

// Bail if the ActiveCampaign Plugin Settings are not set.
if ( ! $settings ) {
return array();
}

// Bail if the ActiveCampaign Forms are not set.
if ( ! array_key_exists( 'forms', $settings ) ) {
return array();
}

// Build array of forms.
$forms = array();
foreach ( $settings['forms'] as $form ) {
$forms[ $form['id'] ] = $form['name'];
}

return $forms;

}

}
48 changes: 44 additions & 4 deletions admin/section/class-convertkit-admin-section-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function register_notices( $notices ) {
'import_configuration_invalid_file_type' => __( 'The uploaded configuration file isn\'t valid.', 'convertkit' ),
'import_configuration_empty' => __( 'The uploaded configuration file contains no settings.', 'convertkit' ),
'import_configuration_success' => __( 'Configuration imported successfully.', 'convertkit' ),
'migrate_activecampaign_configuration_success' => __( 'ActiveCampaign forms migrated successfully.', 'convertkit' ),
'migrate_aweber_configuration_success' => __( 'AWeber forms migrated successfully.', 'convertkit' ),
'migrate_mc4wp_configuration_success' => __( 'MC4WP forms migrated successfully.', 'convertkit' ),
'migrate_mailpoet_configuration_success' => __( 'MailPoet forms migrated successfully.', 'convertkit' ),
Expand All @@ -79,6 +80,7 @@ private function maybe_perform_actions() {
$this->maybe_download_system_info();
$this->maybe_export_configuration();
$this->maybe_import_configuration();
$this->maybe_migrate_activecampaign_configuration();
$this->maybe_migrate_aweber_configuration();
$this->maybe_migrate_mc4wp_configuration();
$this->maybe_migrate_mailpoet_configuration();
Expand Down Expand Up @@ -322,6 +324,43 @@ private function maybe_import_configuration() {

}

/**
* Replaces ActiveCampaign Form Shortcodes and Blocks with Kit Form Shortcodes and Blocks, if the user submitted the
* ActiveCampaign Migrate Configuration section.
*
* @since 3.1.7
*/
private function maybe_migrate_activecampaign_configuration() {

// Bail if nonce verification fails.
if ( ! isset( $_REQUEST['_convertkit_settings_tools_nonce'] ) ) {
return;
}

if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_convertkit_settings_tools_nonce'] ), 'convertkit-settings-tools' ) ) {
return;
}

// Bail if no ActiveCampaign Form IDs were submitted.
if ( ! isset( $_REQUEST['_wp_convertkit_integration_activecampaign_settings'] ) ) {
return;
}

// Initialise the importer.
$activecampaign = new ConvertKit_Admin_Importer_ActiveCampaign();

// Iterate through the ActiveCampaign Form IDs, replacing the shortcodes with the Kit Form Shortcodes
// and blocks with the Kit Form Blocks.
foreach ( array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['_wp_convertkit_integration_activecampaign_settings'] ) ) as $activecampaign_form_id => $kit_form_id ) {
$activecampaign->replace_blocks_in_posts( (int) $activecampaign_form_id, (int) $kit_form_id );
$activecampaign->replace_shortcodes_in_posts( (int) $activecampaign_form_id, (int) $kit_form_id );
}

// Redirect to Tools screen.
$this->redirect_with_success_notice( 'migrate_activecampaign_configuration_success' );

}

/**
* Replaces AWeber Form Shortcodes with Kit Form Shortcodes, if the user submitted the
* AWeber Migrate Configuration section.
Expand Down Expand Up @@ -488,10 +527,11 @@ public function render() {
$forms = new ConvertKit_Resource_Forms();

// Get Importers.
$aweber = new ConvertKit_Admin_Importer_AWeber();
$mc4wp = new ConvertKit_Admin_Importer_MC4WP();
$mailpoet = new ConvertKit_Admin_Importer_Mailpoet();
$newsletter = new ConvertKit_Admin_Importer_Newsletter();
$activecampaign = new ConvertKit_Admin_Importer_ActiveCampaign();
$aweber = new ConvertKit_Admin_Importer_AWeber();
$mc4wp = new ConvertKit_Admin_Importer_MC4WP();
$mailpoet = new ConvertKit_Admin_Importer_Mailpoet();
$newsletter = new ConvertKit_Admin_Importer_Newsletter();

// Output view.
require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/settings/tools.php';
Expand Down
Loading