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
82 changes: 82 additions & 0 deletions admin/importers/class-convertkit-admin-importer-mailpoet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* ConvertKit Admin Importer Mailpoet class.
*
* @package ConvertKit
* @author ConvertKit
*/

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

/**
* Holds the shortcode name for Mailpoet forms.
*
* @since 3.1.6
*
* @var string
*/
public $shortcode_name = 'mailpoet_form';

/**
* Holds the ID attribute name for Mailpoet forms.
*
* @since 3.1.6
*
* @var string
*/
public $shortcode_id_attribute = 'id';

/**
* Holds the block name for Mailpoet forms.
*
* @since 3.1.6
*
* @var string
*/
public $block_name = 'mailpoet/subscription-form-block';

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

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

global $wpdb;

// Query wp_mailpoet_forms for forms that are not deleted.
$results = $wpdb->get_results(
"SELECT id, name FROM {$wpdb->prefix}mailpoet_forms WHERE deleted_at IS NULL"
);

if ( empty( $results ) ) {
return array();
}

$forms = array();
foreach ( $results as $form ) {
$forms[ $form->id ] = $form->name;
}

return $forms;

}

}
43 changes: 41 additions & 2 deletions admin/section/class-convertkit-admin-section-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function register_notices( $notices ) {
'import_configuration_success' => __( 'Configuration imported 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_import_configuration();
$this->maybe_migrate_aweber_configuration();
$this->maybe_migrate_mc4wp_configuration();
$this->maybe_migrate_mailpoet_configuration();

}

Expand Down Expand Up @@ -390,6 +392,42 @@ private function maybe_migrate_mc4wp_configuration() {

}

/**
* Replaces Mailpoet Form Shortcodes and Blocks with Kit Form Shortcodes and Blocks, if the user submitted the
* Mailpoet Migrate Configuration section.
*
* @since 3.1.6
*/
private function maybe_migrate_mailpoet_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 Mailpoet Form IDs were submitted.
if ( ! isset( $_REQUEST['_wp_convertkit_integration_mailpoet_settings'] ) ) {
return;
}

// Initialise the importer.
$mailpoet = new ConvertKit_Admin_Importer_Mailpoet();

// Iterate through the Mailpoet Form IDs and replace the shortcodes with the Kit Form Shortcodes.
foreach ( array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['_wp_convertkit_integration_mailpoet_settings'] ) ) as $mailpoet_form_id => $kit_form_id ) {
$mailpoet->replace_blocks_in_posts( (int) $mailpoet_form_id, (int) $kit_form_id );
$mailpoet->replace_shortcodes_in_posts( (int) $mailpoet_form_id, (int) $kit_form_id );
}

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

}

/**
* Outputs the Debug Log and System Info view.
*
Expand All @@ -412,8 +450,9 @@ public function render() {
$forms = new ConvertKit_Resource_Forms();

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

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