Skip to content

Commit 64e7e5b

Browse files
committed
Remove rocket-loader.min.js from landing pages
1 parent 7736b19 commit 64e7e5b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/class-convertkit-api-traits.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,12 @@ public function convert_relative_to_absolute_urls(\DOMNodeList $elements, string
16621662
continue;
16631663
}
16641664

1665+
// Remove element if it's rocket-loader.min.js. Including it prevents landing page redirects from working.
1666+
if (strpos($element->getAttribute($attribute), 'rocket-loader.min.js') !== false) {
1667+
$element->parentNode->removeChild($element);
1668+
continue;
1669+
}
1670+
16651671
// If here, the attribute's value is a relative URL, missing the http(s) and domain.
16661672
// Prepend the URL to the attribute's value.
16671673
$element->setAttribute($attribute, $url . $element->getAttribute($attribute));

tests/wpunit/APITest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6141,6 +6141,9 @@ public function testGetLandingPageHTML()
61416141
$result = $this->api->get_landing_page_html($_ENV['CONVERTKIT_API_LANDING_PAGE_URL']);
61426142
$this->assertNotInstanceOf(WP_Error::class, $result);
61436143
$this->assertStringContainsString('<form method="POST" action="https://app.convertkit.com/forms/' . $_ENV['CONVERTKIT_API_LANDING_PAGE_ID'] . '/subscriptions" data-sv-form="' . $_ENV['CONVERTKIT_API_LANDING_PAGE_ID'] . '" data-uid="99f1db6843" class="formkit-form"', $result);
6144+
6145+
// Check that rocket-loader.min.js has been removed, as including it breaks landing page redirects.
6146+
$this->assertStringNotContainsString('rocket-loader.min.js', $result);
61446147
}
61456148

61466149
/**
@@ -6157,6 +6160,9 @@ public function testGetLandingPageWithCharacterEncodingHTML()
61576160

61586161
// Assert that character encoding works, and that special characters are not malformed.
61596162
$this->assertStringContainsString('Vantar þinn ungling sjálfstraust í stærðfræði?', $result);
6163+
6164+
// Check that rocket-loader.min.js has been removed, as including it breaks landing page redirects.
6165+
$this->assertStringNotContainsString('rocket-loader.min.js', $result);
61606166
}
61616167

61626168
/**
@@ -6170,6 +6176,9 @@ public function testGetLegacyLandingPageHTML()
61706176
$result = $this->api->get_landing_page_html($_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_URL']);
61716177
$this->assertNotInstanceOf(WP_Error::class, $result);
61726178
$this->assertStringContainsString('<form id="ck_subscribe_form" class="ck_subscribe_form" action="https://app.convertkit.com/landing_pages/' . $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_ID'] . '/subscribe" data-remote="true">', $result);
6179+
6180+
// Check that rocket-loader.min.js has been removed, as including it breaks landing page redirects.
6181+
$this->assertStringNotContainsString('rocket-loader.min.js', $result);
61736182
}
61746183

61756184
/**

0 commit comments

Comments
 (0)