diff --git a/includes/class-convertkit-resource-landing-pages.php b/includes/class-convertkit-resource-landing-pages.php index 642f5deb5..bda4af770 100644 --- a/includes/class-convertkit-resource-landing-pages.php +++ b/includes/class-convertkit-resource-landing-pages.php @@ -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 * diff --git a/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php b/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php index bd68e3a06..36ceadbc7 100644 --- a/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php +++ b/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php @@ -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'] ); + } } } @@ -251,6 +259,7 @@ public function get_fields() { ), ), 'values' => $landing_pages, + 'legacy_values' => $legacy_landing_pages, 'post_type' => 'page', 'resource_type' => 'landing_pages', ), diff --git a/tests/EndToEnd/landing-pages/BlockEditorLandingPageCest.php b/tests/EndToEnd/landing-pages/BlockEditorLandingPageCest.php index bdd82bf29..b210fd1e0 100644 --- a/tests/EndToEnd/landing-pages/BlockEditorLandingPageCest.php +++ b/tests/EndToEnd/landing-pages/BlockEditorLandingPageCest.php @@ -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('