← All changes
|
includes/class-convertkit-resource-landing-pages.php
+78
-0
3.3.1
→
3.4.4
View file →
| @@ -56,8 +56,86 @@ | ||
| 56 | 56 | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | + * Returns all non-legacy landing pages (v4 pages with an `embed_url` | |
| 61 | + * property). Legacy landing pages have a `url` property instead and are | |
| 62 | + * excluded here. | |
| 63 | + * | |
| 64 | + * @since 3.3.7 | |
| 65 | + * | |
| 66 | + * @return bool|array | |
| 67 | + */ | |
| 68 | + public function get_non_legacy() { | |
| 69 | + | |
| 70 | + $resources = $this->get(); | |
| 71 | + if ( ! $resources ) { | |
| 72 | + return false; | |
| 73 | + } | |
| 74 | + | |
| 75 | + $non_legacy = array(); | |
| 76 | + foreach ( $resources as $id => $landing_page ) { | |
| 77 | + if ( isset( $landing_page['url'] ) ) { | |
| 78 | + continue; | |
| 79 | + } | |
| 80 | + $non_legacy[ $id ] = $landing_page; | |
| 81 | + } | |
| 82 | + | |
| 83 | + return $non_legacy; | |
| 84 | + | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Returns whether any non-legacy landing pages exist in the options table. | |
| 89 | + * | |
| 90 | + * @since 3.3.7 | |
| 91 | + * | |
| 92 | + * @return bool | |
| 93 | + */ | |
| 94 | + public function non_legacy_exist() { | |
| 95 | + | |
| 96 | + return (bool) $this->get_non_legacy(); | |
| 97 | + | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Determines whether the given identifier refers to a legacy landing page. | |
| 102 | + * | |
| 103 | + * Handles both storage shapes: a URL string (as saved by Plugin versions | |
| 104 | + * < 1.9.6 which stored the landing page URL directly on the post), and a | |
| 105 | + * numeric ID that resolves to a resource entry containing a `url` key. | |
| 106 | + * | |
| 107 | + * @since 3.3.7 | |
| 108 | + * | |
| 109 | + * @param int|string $id_or_url Landing Page ID or URL. | |
| 110 | + * @return bool | |
| 111 | + */ | |
| 112 | + public function is_legacy( $id_or_url ) { | |
| 113 | + | |
| 114 | + // Bail if no value. | |
| 115 | + if ( ! $id_or_url ) { | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + | |
| 119 | + // If the value is a URL string, it's a legacy landing page as stored | |
| 120 | + // by Plugin versions < 1.9.6. | |
| 121 | + if ( is_string( $id_or_url ) && strstr( $id_or_url, 'http' ) ) { | |
| 122 | + return true; | |
| 123 | + } | |
| 124 | + | |
| 125 | + // Otherwise resolve the ID against the cached resources. | |
| 126 | + $landing_page = $this->get_by_id( (int) $id_or_url ); | |
| 127 | + | |
| 128 | + if ( ! $landing_page ) { | |
| 129 | + return false; | |
| 130 | + } | |
| 131 | + | |
| 132 | + // Legacy landing pages carry a `url` key; v4 pages carry `embed_url`. | |
| 133 | + return isset( $landing_page['url'] ); | |
| 134 | + | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 60 | 138 | * Returns the HTML/JS markup for the given Landing Page ID |
| 61 | 139 | * |
| 62 | 140 | * @since 1.9.6 |
| 63 | 141 | * |