Skip to content
Draft
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
78 changes: 78 additions & 0 deletions includes/class-convertkit-resource-landing-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,84 @@ public function __construct( $context = 'landing_pages' ) {

}

/**
* Returns all non-legacy landing pages (v4 pages with an `embed_url`
* property). Legacy landing pages have a `url` property instead and are
* excluded here.
*
* @since 3.3.7
*
* @return bool|array
*/
public function get_non_legacy() {

$resources = $this->get();
if ( ! $resources ) {
return false;
}

$non_legacy = array();
foreach ( $resources as $id => $landing_page ) {
if ( isset( $landing_page['url'] ) ) {
continue;
}
$non_legacy[ $id ] = $landing_page;
}

return $non_legacy;

}

/**
* Returns whether any non-legacy landing pages exist in the options table.
*
* @since 3.3.7
*
* @return bool
*/
public function non_legacy_exist() {

return (bool) $this->get_non_legacy();

}

/**
* Determines whether the given identifier refers to a legacy landing page.
*
* Handles both storage shapes: a URL string (as saved by Plugin versions
* < 1.9.6 which stored the landing page URL directly on the post), and a
* numeric ID that resolves to a resource entry containing a `url` key.
*
* @since 3.3.7
*
* @param int|string $id_or_url Landing Page ID or URL.
* @return bool
*/
public function is_legacy( $id_or_url ) {

// Bail if no value.
if ( ! $id_or_url ) {
return false;
}

// If the value is a URL string, it's a legacy landing page as stored
// by Plugin versions < 1.9.6.
if ( is_string( $id_or_url ) && strstr( $id_or_url, 'http' ) ) {
return true;
}

// Otherwise resolve the ID against the cached resources.
$landing_page = $this->get_by_id( (int) $id_or_url );

if ( ! $landing_page ) {
return false;
}

// Legacy landing pages carry a `url` key; v4 pages carry `embed_url`.
return isset( $landing_page['url'] );

}

/**
* Returns the HTML/JS markup for the given Landing Page ID
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,21 @@ public function get_fields() {
}
}

// Get Landing Pages.
$landing_pages = array(
// Get Landing Pages. Non-legacy pages populate the dropdown; legacy
// pages are exposed separately as a fallback so a previously-saved
// legacy landing page remains visible as the current selection
// without offering other legacy pages as new choices.
$landing_pages = array(
'0' => esc_html__( 'None', 'convertkit' ),
);
$legacy_landing_pages = array();
if ( $convertkit_landing_pages->exist() ) {
foreach ( $convertkit_landing_pages->get() as $landing_page ) {
$landing_pages[ absint( $landing_page['id'] ) ] = sanitize_text_field( $landing_page['name'] );
if ( isset( $landing_page['url'] ) ) {
$legacy_landing_pages[ absint( $landing_page['id'] ) ] = sanitize_text_field( $landing_page['name'] );
} else {
$landing_pages[ absint( $landing_page['id'] ) ] = sanitize_text_field( $landing_page['name'] );
}
}
}

Expand Down Expand Up @@ -251,6 +259,7 @@ public function get_fields() {
),
),
'values' => $landing_pages,
'legacy_values' => $legacy_landing_pages,
'post_type' => 'page',
'resource_type' => 'landing_pages',
),
Expand Down
144 changes: 67 additions & 77 deletions tests/EndToEnd/landing-pages/BlockEditorLandingPageCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,83 +173,6 @@ public function testLandingPageCharacterEncoding(EndToEndTester $I)
$I->seeInSource('Vantar þinn ungling sjálfstraust í stærðfræði?');
}

/**
* Test that the Legacy Landing Page specified in the Page Settings works when
* creating and viewing a new WordPress Page.
*
* @since 1.9.6.3
*
* @param EndToEndTester $I Tester.
*/
public function testAddNewPageUsingDefinedLegacyLandingPage(EndToEndTester $I)
{
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Landing Page: ' . $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_NAME']
);

// Configure metabox's Landing Page setting to value specified in the .env file.
$I->configurePluginSidebarSettings(
$I,
landingPage: $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_NAME']
);

// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);

// Confirm that the basic HTML structure is correct.
$I->seeLandingPageOutput($I);

// Confirm that the Kit Landing Page displays.
$I->dontSeeElementInDOM('body.page'); // WordPress didn't load its template, which is correct.
$I->seeInSource('<form id="ck_subscribe_form" class="ck_subscribe_form" action="https://app.kit.com/landing_pages/' . $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_ID'] . '/subscribe" data-remote="true">'); // Kit injected its Landing Page Form, which is correct.
}

/**
* Test that the WordPress site icon is output as the favicon on a Legacy Landing Page,
* when defined.
*
* @since 2.3.0
*
* @param EndToEndTester $I Tester.
*/
public function testLegacyLandingPageSiteIcon(EndToEndTester $I)
{
// Define a WordPress Site Icon.
$imageID = $I->haveAttachmentInDatabase(codecept_data_dir('icon.png'));
$I->haveOptionInDatabase('site_icon', $imageID);

// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Legacy Landing Page: Site Icon: ' . $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_NAME']
);

// Configure metabox's Landing Page setting to value specified in the .env file.
$I->configurePluginSidebarSettings(
$I,
landingPage: $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_NAME']
);

// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);

// Confirm that the basic HTML structure is correct.
$I->seeLandingPageOutput($I);

// Confirm the WordPress Site Icon displays.
$I->seeInSource('<link rel="icon" href="' . $_ENV['WORDPRESS_URL'] . '/wp-content/uploads/' . date( 'Y' ) . '/' . date( 'm' ) . '/icon-150x150.png" sizes="32x32">');
$I->seeInSource('<link rel="icon" href="' . $_ENV['WORDPRESS_URL'] . '/wp-content/uploads/' . date( 'Y' ) . '/' . date( 'm' ) . '/icon-300x300.png" sizes="192x192">');
$I->seeInSource('<link rel="apple-touch-icon" href="' . $_ENV['WORDPRESS_URL'] . '/wp-content/uploads/' . date( 'Y' ) . '/' . date( 'm' ) . '/icon-300x300.png">');
$I->seeInSource('<meta name="msapplication-TileImage" content="' . $_ENV['WORDPRESS_URL'] . '/wp-content/uploads/' . date( 'Y' ) . '/' . date( 'm' ) . '/icon-300x300.png">');
$I->dontSeeInSource('<link rel="shortcut icon" type="image/x-icon" href="https://pages.kit.com/templates/favicon.ico">');

// Confirm that the Kit Landing Page displays.
$I->dontSeeElementInDOM('body.page'); // WordPress didn't load its template, which is correct.
$I->seeInSource('<form id="ck_subscribe_form" class="ck_subscribe_form" action="https://app.kit.com/landing_pages/' . $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_ID'] . '/subscribe" data-remote="true">'); // Kit injected its Landing Page Form, which is correct.
}

/**
* Test that the Legacy Landing Page specified in the Page Settings works when
* the Landing Page was defined by the Kit Plugin < 1.9.6, which used a URL
Expand Down Expand Up @@ -572,6 +495,73 @@ public function testAddNewPostDoesNotDisplayLandingPageOption(EndToEndTester $I)
$I->publishGutenbergPage($I);
}

/**
* Test that the Gutenberg plugin sidebar's Landing Page dropdown does not
* offer legacy landing pages as a selection option.
*
* @since 3.3.7
*
* @param EndToEndTester $I Tester.
*/
public function testLegacyLandingPagesExcludedFromPluginSidebar(EndToEndTester $I)
{
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: No Legacy Landing Pages In Plugin Sidebar'
);

// Open the Plugin sidebar so the Landing Page dropdown renders.
$I->openPluginSidebarSettings($I);
$landingPageSelectXPath = '//label[text()="Landing Page"]/following::select[1]';
$I->waitForElementVisible($landingPageSelectXPath);
$I->dontSee(
$_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_NAME'],
$landingPageSelectXPath
);
}

/**
* Test that a Page preseeded with a legacy landing page ID in its post
* meta continues to display that legacy landing page as the selected
* option in the Gutenberg plugin sidebar.
*
* @since 3.3.7
*
* @param EndToEndTester $I Tester.
*/
public function testPluginSidebarPreservesSelectedLegacyLandingPage(EndToEndTester $I)
{
// Preseed a Page with a legacy landing page ID in its Kit post meta.
$pageID = $I->havePageInDatabase(
[
'post_type' => 'page',
'post_status' => 'publish',
'post_title' => 'Kit: Page: Plugin Sidebar Preserves Legacy Landing Page',
'post_name' => 'kit-plugin-sidebar-preserves-legacy-landing-page',
'meta_input' => [
'_wp_convertkit_post_meta' => [
'form' => '0',
'landing_page' => (string) $_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_ID'],
'tag' => '',
],
],
]
);

// Open the Gutenberg edit screen and the Plugin sidebar. Confirm the
// legacy landing page is the selected option, even though it is no
// longer offered as a new selection choice.
$I->amOnAdminPage('post.php?post=' . $pageID . '&action=edit');
$I->openPluginSidebarSettings($I);
$landingPageSelectXPath = '//label[text()="Landing Page"]/following::select[1]';
$I->waitForElementVisible($landingPageSelectXPath);
$I->seeOptionIsSelected(
$landingPageSelectXPath,
$_ENV['CONVERTKIT_API_LEGACY_LANDING_PAGE_NAME']
);
}

/**
* Deactivate and reset Plugin(s) after each test, if the test passes.
* We don't use _after, as this would provide a screenshot of the Plugin
Expand Down
Loading
Loading