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
17 changes: 10 additions & 7 deletions admin/importers/class-convertkit-admin-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function replace_shortcodes_in_content( $content, $third_party_form_id, $
. '[^\]]*?' // Match any characters that are not a closing square bracket, non-greedy.
. '\b' . preg_quote( $this->shortcode_id_attribute, '/' ) // Match the id attribute word boundary and escape as needed.
. '\s*=\s*' // Match optional whitespace around an equals sign.
. '(?:"' . preg_quote( (string) $third_party_form_id, '/' ) . '"|' . preg_quote( (string) $third_party_form_id, '/' ) . ')' // Match the form ID, quoted or unquoted.
. '(?:"' . preg_quote( (string) $third_party_form_id, '/' ) . '"|\'' . preg_quote( (string) $third_party_form_id, '/' ) . '\'|' . preg_quote( (string) $third_party_form_id, '/' ) . ')' // Match the form ID, double quotes, single quotes or unquoted.
. '[^\]]*?\]/i'; // Match any other characters (non-greedy) up to the closing square bracket, case-insensitive.
}

Expand Down Expand Up @@ -365,16 +365,19 @@ public function get_form_ids_from_content( $content ) {
. '(?:\s+[^\]]*)?' // Optionally match any attributes (key/value pairs), non-greedy.
. preg_quote( $this->shortcode_id_attribute, '/' ) // Match the id attribute name.
. '\s*=\s*' // Optional whitespace, equals sign, optional whitespace.
. '(?:"([^"]+)"|([^\s\]]+))' // Capture quoted or unquoted value.
. '(?:"([^"]+)"|\'([^\']+)\'|([^\s\]]+))' // Capture double quoted, single quoted or unquoted value.
. '[^\]]*?\]/i'; // Match up to closing bracket, case-insensitive.

preg_match_all( $pattern, $content, $matches );

// Extract form IDs: They could be in either $matches[1] (quoted) or $matches[2] (unquoted).
$form_ids = array_filter(
array_merge(
isset( $matches[1] ) ? $matches[1] : array(),
isset( $matches[2] ) ? $matches[2] : array()
// Extract form IDs: They could be in either $matches[1] (double quoted), $matches[2] (single quoted) or $matches[3] (unquoted).
$form_ids = array_values(
array_filter(
array_merge(
isset( $matches[1] ) ? $matches[1] : array(),
isset( $matches[2] ) ? $matches[2] : array(),
isset( $matches[3] ) ? $matches[3] : array()
)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private function _createPagesWithCampaignMonitorFormShortcodes(EndToEndTester $I
'post_type' => 'page',
'post_status' => 'publish',
'post_title' => 'Page with Campaign Monitor Form #' . $campaignMonitorFormID,
'post_content' => '[cm_form form_id="' . $campaignMonitorFormID . '"]',
'post_content' => '[cm_form form_id=\'' . $campaignMonitorFormID . '\']',
'meta_input' => [
'_wp_convertkit_post_meta' => [
'form' => '0',
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/ImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public function testCampaignMonitorGetFormIDsFromContent()
$this->assertNotInstanceOf(\WP_Error::class, $this->importer);

// Define the content to test.
$content = '[cm_form form_id="cm_6912dba75db2d"] some content [cm_form form_id="cm_6982a693a0095"] some other content [aweber formid="12"] different shortcode to ignore';
$content = '[cm_form form_id="cm_6912dba75db2d"] some content [cm_form form_id=\'cm_6982a693a0095\'] some other content [aweber formid="12"] different shortcode to ignore';

// Extract form IDs from content.
$form_ids = $this->importer->get_form_ids_from_content( $content );
Expand All @@ -428,6 +428,7 @@ public function testCampaignMonitorReplaceShortcodesInContent()
// Define the shortcodes to test.
$shortcodes = [
'[cm_form form_id="cm_6912dba75db2d"]',
'[cm_form form_id=\'cm_6912dba75db2d\']',
'[cm_form form_id=cm_6912dba75db2d]',
];

Expand Down