diff --git a/admin/class-convertkit-admin-setup-wizard.php b/admin/class-convertkit-admin-setup-wizard.php
index 4e3096048..92cf0cf83 100644
--- a/admin/class-convertkit-admin-setup-wizard.php
+++ b/admin/class-convertkit-admin-setup-wizard.php
@@ -51,9 +51,9 @@ class ConvertKit_Admin_Setup_Wizard {
*
* @since 1.9.8.4
*
- * @var int
+ * @var string
*/
- public $step = 1;
+ public $step = 'start';
/**
* The programmatic name of the setup screen.
@@ -170,7 +170,7 @@ public function maybe_load_setup_screen() {
}
// Define the step the user is on in the setup process.
- $this->step = ( filter_has_var( INPUT_GET, 'step' ) ? absint( filter_input( INPUT_GET, 'step', FILTER_SANITIZE_NUMBER_INT ) ) : 1 );
+ $this->step = $this->get_current_step();
// Process any posted form data.
$this->process_form();
@@ -193,6 +193,66 @@ public function maybe_load_setup_screen() {
}
+ /**
+ * Returns the current step in the setup process.
+ *
+ * @since 3.1.7
+ *
+ * @return string Current step.
+ */
+ public function get_current_step() {
+
+ $step = ( filter_has_var( INPUT_GET, 'step' ) ? filter_input( INPUT_GET, 'step', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : 'start' );
+
+ // Fallback to 'start' if the step is a registered step.
+ if ( ! array_key_exists( $step, $this->steps ) ) {
+ $step = 'start';
+ }
+
+ return $step;
+
+ }
+
+ /**
+ * Get the number of the current step.
+ *
+ * @since 3.1.7
+ *
+ * @return int Step number.
+ */
+ public function get_current_step_number() {
+
+ return array_search( $this->step, array_keys( $this->steps ), true ) + 1;
+
+ }
+
+ /**
+ * Get the step by number.
+ *
+ * @since 3.1.7
+ *
+ * @param int $number Step number (1 based index).
+ * @return string Step name/key.
+ */
+ public function get_step_key_by_number( $number ) {
+
+ return array_keys( $this->steps )[ $number - 1 ];
+
+ }
+
+ /**
+ * Get the total number of steps.
+ *
+ * @since 3.1.7
+ *
+ * @return int Total steps.
+ */
+ public function get_total_steps() {
+
+ return count( $this->steps );
+
+ }
+
/**
* Process submitted form data for the given setup wizard name and current step.
*
@@ -205,7 +265,7 @@ private function process_form() {
*
* @since 1.9.8.4
*
- * @param int $step Current step number.
+ * @param string $step Current step.
*/
do_action( 'convertkit_admin_setup_wizard_process_form_' . $this->page_name, $this->step );
@@ -231,24 +291,24 @@ private function define_step_urls() {
);
// Define the previous step URL if we're not on the first or last step.
- if ( $this->step > 1 && $this->step < count( $this->steps ) ) {
+ if ( $this->get_current_step_number() > 1 && $this->get_current_step_number() < $this->get_total_steps() ) {
$this->previous_step_url = add_query_arg(
array(
'page' => $this->page_name,
'convertkit-modal' => $this->is_modal(),
- 'step' => ( $this->step - 1 ),
+ 'step' => $this->get_step_key_by_number( $this->get_current_step_number() - 1 ),
),
admin_url( 'options.php' )
);
}
// Define the next step URL if we're not on the last page.
- if ( $this->step < count( $this->steps ) ) {
+ if ( $this->get_current_step_number() < $this->get_total_steps() ) {
$this->next_step_url = add_query_arg(
array(
'page' => $this->page_name,
'convertkit-modal' => $this->is_modal(),
- 'step' => ( $this->step + 1 ),
+ 'step' => $this->get_step_key_by_number( $this->get_current_step_number() + 1 ),
),
admin_url( 'options.php' )
);
@@ -268,7 +328,7 @@ private function load_screen_data() {
*
* @since 1.9.8.4
*
- * @param int $step Current step number.
+ * @param string $step Current step.
*/
do_action( 'convertkit_admin_setup_wizard_load_screen_data_' . $this->page_name, $this->step );
diff --git a/admin/importers/class-convertkit-admin-importer-campaignmonitor.php b/admin/importers/class-convertkit-admin-importer-campaignmonitor.php
new file mode 100644
index 000000000..7cbde17b3
--- /dev/null
+++ b/admin/importers/class-convertkit-admin-importer-campaignmonitor.php
@@ -0,0 +1,98 @@
+ $form ) {
+ // $form is a Campaign Monitor forms\core\Form object. It'll be a __PHP_Incomplete_Class if the Campaign Monitor plugin is not active.
+ // To consistently access the protected form name property, we have to cast to an array.
+ $form = (array) $form;
+
+ // Access the protected form name property.
+ // When casting __PHP_Incomplete_Class to an array, protected properties are prefixed with \0*\0.
+ $forms[ $form_id ] = $form["\0*\0name"];
+ }
+
+ return $forms;
+
+ }
+
+}
diff --git a/admin/importers/class-convertkit-admin-importer.php b/admin/importers/class-convertkit-admin-importer.php
index 94877e72e..000ae0557 100644
--- a/admin/importers/class-convertkit-admin-importer.php
+++ b/admin/importers/class-convertkit-admin-importer.php
@@ -119,8 +119,17 @@ public function import( $mappings ) {
// Iterate through the mappings, replacing the third party form shortcodes and blocks with the Kit form shortcodes and blocks.
foreach ( $mappings as $third_party_form_id => $kit_form_id ) {
- $this->replace_blocks_in_posts( (int) $third_party_form_id, (int) $kit_form_id );
- $this->replace_shortcodes_in_posts( (int) $third_party_form_id, (int) $kit_form_id );
+ // Skip empty Kit Form IDs i.e. no mapping was provided for this third party form.
+ if ( empty( $kit_form_id ) ) {
+ continue;
+ }
+
+ if ( $this->block_name ) {
+ $this->replace_blocks_in_posts( $third_party_form_id, (int) $kit_form_id );
+ }
+ if ( $this->shortcode_name ) {
+ $this->replace_shortcodes_in_posts( $third_party_form_id, (int) $kit_form_id );
+ }
}
}
@@ -136,24 +145,49 @@ public function get_forms_in_posts() {
global $wpdb;
- // Search post_content for the third party form block or shortcode and return array of post IDs.
- $results = $wpdb->get_col(
- $wpdb->prepare(
- "
- SELECT ID
- FROM {$wpdb->posts}
- WHERE post_status = %s
- AND (
- post_content LIKE %s
- OR post_content LIKE %s
- )
- ",
- 'publish',
- '%[' . $this->shortcode_name . '%',
- '%
Some content with characters !@£$%^&*()_+~!@£$%^&*()_+\\\
',
+
+ // Configure Kit Plugin to not display a default Form, so we test against the Kit Form in the content.
+ 'meta_input' => [
+ '_wp_convertkit_post_meta' => [
+ 'form' => '0',
+ 'landing_page' => '',
+ 'tag' => '',
+ ],
+ ],
+ ]
+ ),
+ ];
+
+ // Load Form Importer screen of Setup Wizard.
+ $I->amOnAdminPage('options.php?page=convertkit-setup&step=form-importer');
+
+ // Select the Kit Forms to replace the ActiveCampaign Forms.
+ $I->fillSelect2Field(
+ $I,
+ container: '#select2-form-importer-activecampaign-1-container',
+ value: $_ENV['CONVERTKIT_API_FORM_NAME']
+ );
+ $I->fillSelect2Field(
+ $I,
+ container: '#select2-form-importer-activecampaign-2-container',
+ value: $_ENV['CONVERTKIT_API_FORM_NAME']
+ );
+
+ // Click the Finish Setup button.
+ $I->click('Finish Setup');
+
+ // Confirm expected setup wizard screen is displayed.
+ $this->_seeExpectedSetupWizardScreen(
+ $I,
+ step: 'finish',
+ stepCount: 4,
+ totalSteps: 4,
+ title: 'Setup complete'
+ );
+
+ // Test each Page.
+ foreach ($pageIDs as $pageID) {
+ $I->amOnPage('?p=' . $pageID);
+
+ // Check Kit Forms are displayed.
+ $I->seeElementInDOM('form[data-sv-form]');
+ }
+ }
+
/**
* Tests that a link to the Setup Wizard exists on the Plugins screen, and works when clicked.
*
@@ -483,7 +668,12 @@ public function testSetupWizardLinkOnPluginsScreen(EndToEndTester $I)
$I->click('tr[data-slug="convertkit"] td div.row-actions span.setup_wizard a');
// Confirm expected setup wizard screen is displayed.
- $this->_seeExpectedSetupWizardScreen($I, 1, 'Welcome to the Kit Setup Wizard');
+ $this->_seeExpectedSetupWizardScreen(
+ $I,
+ step: 'start',
+ stepCount: 1,
+ title: 'Welcome to the Kit Setup Wizard'
+ );
}
/**
@@ -520,12 +710,14 @@ private function _activatePlugin(EndToEndTester $I)
*
* @since 1.9.8.4
*
- * @param EndToEndTester $I Tester.
- * @param int $step Current step.
- * @param string $title Expected title.
+ * @param EndToEndTester $I Tester.
+ * @param string $step Current step.
+ * @param int $stepCount Current step count.
+ * @param string $title Expected title.
* @param bool $nextButtonIsLink Check that next button is a link (false = must be a