From ba52c856c9af5db7950ba07d9ee6045cf7383a3f Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 10 Feb 2026 15:25:06 +0800 Subject: [PATCH] Importers: Support Single Quotes on Shortcodes --- .../class-convertkit-admin-importer.php | 17 ++++++++++------- ...SettingsToolsImporterCampaignMonitorCest.php | 2 +- tests/Integration/ImporterTest.php | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/admin/importers/class-convertkit-admin-importer.php b/admin/importers/class-convertkit-admin-importer.php index 000ae0557..174b4eac6 100644 --- a/admin/importers/class-convertkit-admin-importer.php +++ b/admin/importers/class-convertkit-admin-importer.php @@ -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. } @@ -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() + ) ) ); diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterCampaignMonitorCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterCampaignMonitorCest.php index b8eec7774..304402fed 100644 --- a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterCampaignMonitorCest.php +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterCampaignMonitorCest.php @@ -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', diff --git a/tests/Integration/ImporterTest.php b/tests/Integration/ImporterTest.php index 29336d7f6..c11f99668 100644 --- a/tests/Integration/ImporterTest.php +++ b/tests/Integration/ImporterTest.php @@ -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 ); @@ -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]', ];