PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0-beta1
Elementor Website Builder – more than just a page builder v3.1.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 All 457 releases
← All changes | modules/landing-pages/module.php +176 -350 4.2.4 → 3.1.0-beta1 View file →
@@ -1,16 +1,16 @@
1 1 <?php
2 2 namespace Elementor\Modules\LandingPages;
3 3
4 +use Elementor\Core\Base\Document;
4 5 use Elementor\Core\Base\Module as BaseModule;
5 6 use Elementor\Core\Documents_Manager;
6 7 use Elementor\Core\Experiments\Manager as Experiments_Manager;
7 8 use Elementor\Modules\LandingPages\Documents\Landing_Page;
8 -use Elementor\Modules\LandingPages\AdminMenuItems\Editor_One_Landing_Pages_Menu;
9 -use Elementor\Modules\LandingPages\Module as Landing_Pages_Module;
10 -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
11 9 use Elementor\Plugin;
12 10 use Elementor\TemplateLibrary\Source_Local;
11 +use Elementor\User;
12 +use Elementor\Utils;
13 13
14 14 if ( ! defined( 'ABSPATH' ) ) {
15 15 exit; // Exit if accessed directly.
16 16 }
@@ -17,77 +17,25 @@
17 17
18 18 class Module extends BaseModule {
19 19
20 20 const DOCUMENT_TYPE = 'landing-page';
21 - const CPT = 'e-landing-page';
22 - const ADMIN_PAGE_SLUG = 'edit.php?post_type=' . self::CPT;
23 - const ACTIVATION_KEY = 'elementor_landing_pages_activation';
21 + const ADMIN_PAGE_SLUG = 'edit.php?post_type=page&elementor_library_type=landing-page';
24 22
25 - private $has_pages = null;
23 + private $posts;
26 24 private $trashed_posts;
27 - private $new_lp_url;
28 - private $permalink_structure;
29 25
30 26 public function get_name() {
31 27 return 'landing-pages';
32 28 }
33 29
34 - /**
35 - * Register Experimental Feature
36 - *
37 - * Implementation of this method makes the module an experiment.
38 - *
39 - * @since 3.28.0
40 - */
41 - private function register_experiment() {
42 - Plugin::$instance->experiments->add_feature( [
30 + public static function get_experimental_data() {
31 + return [
43 32 'name' => 'landing-pages',
44 - 'title' => esc_html__( 'Landing Pages', 'elementor' ),
45 - 'description' => esc_html__( 'Adds a new Elementor content type that allows creating beautiful landing pages instantly in a streamlined workflow.', 'elementor' ),
46 - 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA,
47 - 'default' => Experiments_Manager::STATE_ACTIVE,
48 - 'new_site' => [
49 - 'default_inactive' => true,
50 - 'minimum_installation_version' => '3.22.0',
51 - ],
52 - 'deprecated' => true,
53 - ] );
33 + 'title' => __( 'Landing Pages', 'elementor' ),
34 + 'description' => __( 'Adds a new Elementor content type that allows creating beautiful landing pages instantly in a streamlined workflow.', 'elementor' ),
35 + ];
54 36 }
55 37
56 - /**
57 - * Should activate landing pages
58 - *
59 - * Checks whether the Landing Pages should be activated.
60 - *
61 - * If the activation key set to `1` in wp_options, the Landing Pages feature should be active. Otherwise not.
62 - * This is a backwards compatibility for websites that had Landing Pages, therefore couldn't be deactivated.
63 - * When deleting posts in Landing Pages CPT, Elementor checks again whether this feature should be activated.
64 - *
65 - * @since 3.31.0
66 - */
67 - private function should_activate_landing_pages() {
68 - if ( '1' === get_option( self::ACTIVATION_KEY ) ) {
69 - return true;
70 - }
71 -
72 - if ( $this->has_landing_pages() ) {
73 - update_option( self::ACTIVATION_KEY, '1' );
74 - return true;
75 - }
76 -
77 - update_option( self::ACTIVATION_KEY, '0' );
78 - return false;
79 - }
80 -
81 - /**
82 - * Get Trashed Landing Pages Posts
83 - *
84 - * Returns the posts property of a WP_Query run for Landing Pages with post_status of 'trash'.
85 - *
86 - * @since 3.1.0
87 - *
88 - * @return array trashed posts
89 - */
90 38 private function get_trashed_landing_page_posts() {
91 39 if ( $this->trashed_posts ) {
92 40 return $this->trashed_posts;
93 41 }
@@ -92,39 +40,35 @@
92 40 return $this->trashed_posts;
93 41 }
94 42
95 43 // `'posts_per_page' => 1` is because this is only used as an indicator to whether there are any trashed landing pages.
96 - $trashed_posts_query = new \WP_Query( [
97 - 'no_found_rows' => true,
98 - 'post_type' => self::CPT,
44 + $this->trashed_posts = new \WP_Query( [
45 + 'post_type' => 'page',
99 46 'post_status' => 'trash',
100 47 'posts_per_page' => 1,
48 + 'elementor_library_type' => self::DOCUMENT_TYPE,
101 49 'meta_key' => '_elementor_template_type',
102 50 'meta_value' => self::DOCUMENT_TYPE,
103 51 ] );
104 52
105 - $this->trashed_posts = $trashed_posts_query->posts;
106 -
107 53 return $this->trashed_posts;
108 54 }
109 55
110 - private function has_landing_pages() {
111 - if ( null !== $this->has_pages ) {
112 - return $this->has_pages;
56 + private function get_landing_page_posts() {
57 + if ( $this->posts ) {
58 + return $this->posts;
113 59 }
114 60
115 - $posts_query = new \WP_Query( [
116 - 'no_found_rows' => true,
117 - 'post_type' => self::CPT,
118 - 'post_status' => 'any',
61 + // `'posts_per_page' => 1` is because this is only used as an indicator to whether there are any landing pages.
62 + $this->posts = new \WP_Query( [
63 + 'post_type' => 'page',
119 64 'posts_per_page' => 1,
65 + 'elementor_library_type' => self::DOCUMENT_TYPE,
120 66 'meta_key' => '_elementor_template_type',
121 67 'meta_value' => self::DOCUMENT_TYPE,
122 68 ] );
123 69
124 - $this->has_pages = $posts_query->post_count > 0;
125 -
126 - return $this->has_pages;
70 + return $this->posts;
127 71 }
128 72
129 73 /**
130 74 * Is Elementor Landing Page.
@@ -133,51 +77,71 @@
133 77 *
134 78 * @since 3.1.0
135 79 * @access public
136 80 *
137 - * @param \WP_Post $post Post Object.
81 + * @param \WP_Post $post Post Object
138 82 *
139 83 * @return bool Whether the post was built with Elementor.
140 84 */
141 85 public function is_elementor_landing_page( $post ) {
142 - return self::CPT === $post->post_type;
86 + // If the post is not a page, save a call to the DB.
87 + if ( 'page' !== $post->post_type ) {
88 + return false;
89 + }
90 +
91 + return 'landing-page' === get_post_meta( $post->ID, Document::TYPE_META_KEY, true );
143 92 }
144 93
145 - public function get_menu_args() {
146 - if ( $this->has_landing_pages() ) {
147 - $menu_slug = self::ADMIN_PAGE_SLUG;
148 - $function = null;
94 + /**
95 + * Add Submenu Page
96 + *
97 + * Adds the 'Landing Pages' submenu item to the 'Templates' menu item.
98 + *
99 + * @since 3.1.0
100 + */
101 + private function add_submenu_page() {
102 + $posts = $this->get_landing_page_posts();
103 +
104 + // If there are no Landing Pages, show the "Create Your First Landing Page" page.
105 + // If there are, show the pages table.
106 + if ( ! empty( $posts->posts ) ) {
107 + $this->landing_page_menu_slug = self::ADMIN_PAGE_SLUG;
108 + $landing_page_menu_callback = null;
149 109 } else {
150 - $menu_slug = self::CPT;
151 - $function = [ $this, 'print_empty_landing_pages_page' ];
110 + $this->landing_page_menu_slug = self::DOCUMENT_TYPE;
111 + $landing_page_menu_callback = [ $this, 'print_empty_landing_pages_page' ];
152 112 }
153 113
154 - return [
155 - 'menu_slug' => $menu_slug,
156 - 'function' => $function,
157 - ];
114 + $landing_pages_title = __( 'Landing Pages', 'elementor' );
115 +
116 + add_submenu_page(
117 + Source_Local::ADMIN_MENU_SLUG,
118 + $landing_pages_title,
119 + $landing_pages_title,
120 + 'manage_options',
121 + $this->landing_page_menu_slug,
122 + $landing_page_menu_callback
123 + );
158 124 }
159 125
160 - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ): void {
161 - $menu_data_provider->register_menu( new Editor_One_Landing_Pages_Menu( $this ) );
126 + private function get_add_new_landing_page_url() {
127 + return Utils::get_create_new_post_url( 'page', self::DOCUMENT_TYPE ) . '#library';
162 128 }
163 129
164 130 /**
165 - * Get 'Add New' Landing Page URL
131 + * Remove Type Column
166 132 *
167 - * Retrieves the custom URL for the admin dashboard's 'Add New' button in the Landing Pages admin screen. This URL
168 - * creates a new Landing Pages and directly opens the Elementor Editor with the Template Library modal open on the
169 - * Landing Pages tab.
133 + * Removes the "Type" column from the pages table.
170 134 *
171 135 * @since 3.1.0
172 136 *
173 - * @return string
137 + * @param array $columns
138 + * @return array $columns
174 139 */
175 - private function get_add_new_landing_page_url() {
176 - if ( ! $this->new_lp_url ) {
177 - $this->new_lp_url = Plugin::$instance->documents->get_create_new_post_url( self::CPT, self::DOCUMENT_TYPE ) . '#library';
178 - }
179 - return $this->new_lp_url;
140 + private function remove_type_column( $columns ) {
141 + unset( $columns['taxonomy-elementor_library_type'] );
142 +
143 + return $columns;
180 144 }
181 145
182 146 /**
183 147 * Get Empty Landing Pages Page
@@ -195,328 +159,190 @@
195 159 ?>
196 160 <div class="e-landing-pages-empty">
197 161 <?php
198 162 /** @var Source_Local $source_local */
199 - $source_local->print_blank_state_template( esc_html__( 'Landing Page', 'elementor' ), $this->get_add_new_landing_page_url(), esc_html__( 'Build Effective Landing Pages for your business\' marketing campaigns.', 'elementor' ) );
163 + $source_local->print_blank_state_template( __( 'Landing Page', 'elementor' ), $this->get_add_new_landing_page_url(), __( 'Build Effective Landing Pages for your business\' marketing campaigns.', 'elementor' ) );
200 164
201 - if ( ! empty( $trashed_posts ) ) : ?>
165 + if ( ! empty( $trashed_posts->posts ) ) { ?>
202 166 <div class="e-trashed-items">
203 - <?php
204 - printf(
205 - /* translators: %1$s Link open tag, %2$s: Link close tag. */
206 - esc_html__( 'Or view %1$sTrashed Items%2$s', 'elementor' ),
207 - '<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT ) ) . '">',
208 - '</a>'
209 - );
210 - ?>
167 + <?php echo sprintf( __( 'Or view <a href="%s">Trashed Items</a>', 'elementor' ), admin_url( 'edit.php?post_status=trash&post_type=page&elementor_library_type=landing-page' ) ); ?>
211 168 </div>
212 - <?php endif; ?>
169 + <?php } ?>
213 170 </div>
214 171 <?php
215 172 }
216 173
217 174 /**
218 - * Is Current Admin Page Edit LP
175 + * Add Finder Items
219 176 *
220 - * Checks whether the current page is a native WordPress edit page for a landing page.
221 - */
222 - private function is_landing_page_admin_edit() {
223 - $screen = get_current_screen();
224 -
225 - if ( 'post' === $screen->base ) {
226 - return $this->is_elementor_landing_page( get_post() );
227 - }
228 -
229 - return false;
230 - }
231 -
232 - /**
233 - * Admin Localize Settings
177 + * Adds Items to the Finder index to make them searchable in the Elementor Editor Finder modal.
234 178 *
235 - * Enables adding properties to the globally available elementorAdmin.config JS object in the Admin Dashboard.
236 - * Runs on the 'elementor/admin/localize_settings' filter.
237 - *
238 179 * @since 3.1.0
239 180 *
240 - * @param $settings
241 - * @return array|null
181 + * @param array $categories
182 + * @return array $categories
242 183 */
243 - private function admin_localize_settings( $settings ) {
244 - $additional_settings = [
245 - 'urls' => [
246 - 'addNewLandingPageUrl' => $this->get_add_new_landing_page_url(),
247 - ],
248 - 'landingPages' => [
249 - 'landingPagesHasPages' => $this->has_landing_pages(),
250 - 'isLandingPageAdminEdit' => $this->is_landing_page_admin_edit(),
251 - ],
184 + private function add_finder_items( array $categories ) {
185 + $categories['general']['items']['landing-pages'] = [
186 + 'title' => __( 'Landing Pages', 'elementor' ),
187 + 'icon' => 'single-page',
188 + 'url' => admin_url( self::ADMIN_PAGE_SLUG ),
189 + 'keywords' => [ self::DOCUMENT_TYPE, 'landing', 'page', 'library' ],
252 190 ];
253 191
254 - return array_replace_recursive( $settings, $additional_settings );
255 - }
256 -
257 - /**
258 - * Register Landing Pages CPT
259 - *
260 - * @since 3.1.0
261 - */
262 - private function register_landing_page_cpt() {
263 - $labels = [
264 - 'name' => esc_html__( 'Landing Pages', 'elementor' ),
265 - 'singular_name' => esc_html__( 'Landing Page', 'elementor' ),
266 - 'add_new' => esc_html__( 'Add New', 'elementor' ),
267 - 'add_new_item' => esc_html__( 'Add New Landing Page', 'elementor' ),
268 - 'edit_item' => esc_html__( 'Edit Landing Page', 'elementor' ),
269 - 'new_item' => esc_html__( 'New Landing Page', 'elementor' ),
270 - 'all_items' => esc_html__( 'All Landing Pages', 'elementor' ),
271 - 'view_item' => esc_html__( 'View Landing Page', 'elementor' ),
272 - 'search_items' => esc_html__( 'Search Landing Pages', 'elementor' ),
273 - 'not_found' => esc_html__( 'No landing pages found', 'elementor' ),
274 - 'not_found_in_trash' => esc_html__( 'No landing pages found in trash', 'elementor' ),
275 - 'parent_item_colon' => '',
276 - 'menu_name' => esc_html__( 'Landing Pages', 'elementor' ),
192 + $categories['create']['items']['landing-pages'] = [
193 + 'title' => __( 'Add New Landing Page', 'elementor' ),
194 + 'icon' => 'single-page',
195 + 'url' => esc_url( Utils::get_create_new_post_url( 'page', self::DOCUMENT_TYPE ) ) . '#library',
196 + 'keywords' => [ 'landing-page', 'landing', 'page', 'new', 'create', 'library' ],
277 197 ];
278 198
279 - $args = [
280 - 'labels' => $labels,
281 - 'public' => true,
282 - 'show_in_menu' => 'edit.php?post_type=elementor_library&tabs_group=library',
283 - 'capability_type' => 'page',
284 - 'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ],
285 - 'supports' => [ 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields', 'post-formats', 'elementor' ],
286 - ];
287 -
288 - register_post_type( self::CPT, $args );
199 + return $categories;
289 200 }
290 201
291 202 /**
292 - * Remove Post Type Slug
203 + * Change Admin Page Title
293 204 *
294 - * Landing Pages are supposed to act exactly like pages. This includes their URLs being directly under the site's
295 - * domain name. Since "Landing Pages" is a CPT, WordPress automatically adds the landing page slug as a prefix to
296 - * it's posts' permalinks. This method checks if the post's post type is Landing Pages, and if it is, it removes
297 - * the CPT slug from the requested post URL.
205 + * Changes the page title of the "Landing Pages" Admin page which displays the "Pages" table,
206 + * from "Pages" to the "Landing Pages" translation string.
298 207 *
299 - * Runs on the 'post_type_link' filter.
300 - *
301 208 * @since 3.1.0
302 - *
303 - * @param $post_link
304 - * @param $post
305 - * @param $leavename
306 - * @return string|string[]
307 209 */
308 - private function remove_post_type_slug( $post_link, $post, $leavename ) {
309 - // Only try to modify the permalink if the post is a Landing Page.
310 - if ( self::CPT !== $post->post_type || 'publish' !== $post->post_status ) {
311 - return $post_link;
210 + private function change_admin_page_title() {
211 + global $wp_post_types;
212 +
213 + if ( $this->is_landing_pages_page() ) {
214 + $wp_post_types['page']->labels->name = __( 'Landing Pages', 'elementor' );
312 215 }
313 -
314 - // Any slug prefixes need to be removed from the post link.
315 - return trailingslashit( get_home_url() ) . trailingslashit( $post->post_name );
316 216 }
317 217
318 218 /**
319 - * Adjust Landing Page Query
219 + * Change Admin Meta Title
320 220 *
321 - * Since Landing Pages are a CPT but should act like pages, the WP_Query that is used to fetch the page from the
322 - * database needs to be adjusted. This method adds the Landing Pages CPT to the list of queried post types, to
323 - * make sure the database query finds the correct Landing Page to display.
324 - * Runs on the 'pre_get_posts' action.
221 + * Changes the contents of the meta <title> tag in the "Landing Pages" Admin page which displays the "Pages" table,
222 + * from "Pages" to "Landing Pages".
325 223 *
326 224 * @since 3.1.0
327 225 *
328 - * @param \WP_Query $query
226 + * @param string $title meta title contents
227 + * @return string $title
329 228 */
330 - private function adjust_landing_page_query( \WP_Query $query ) {
331 - // Only handle actual pages.
332 - if (
333 - ! $query->is_main_query()
334 - // If the query is not for a page.
335 - || ! isset( $query->query['page'] )
336 - // If the query is for a static home/blog page.
337 - || is_home()
338 - // If the post type comes already set, the main query is probably a custom one made by another plugin.
339 - // In this case we do not want to intervene in order to not cause a conflict.
340 - || isset( $query->query['post_type'] )
341 - ) {
342 - return;
229 + private function change_admin_meta_title( $title ) {
230 + if ( $this->is_landing_pages_page() ) {
231 + // Get WordPress' default 'Pages' translation string, since the original title comes from WordPress core.
232 + return str_replace( __( 'Pages', 'elementor' ), __( 'Landing Pages', 'elementor' ), $title ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
343 233 }
344 234
345 - // Create the post types property as an array and include the landing pages CPT in it.
346 - $query_post_types = [ 'post', 'page', self::CPT ];
235 + return $title;
236 + }
347 237
348 - // Since WordPress determined this is supposed to be a page, we'll pre-set the post_type query arg to make sure
349 - // it includes the Landing Page CPT, so when the query is parsed, our CPT will be a legitimate match to the
350 - // Landing Page's permalink (that is directly under the domain, without a CPT slug prefix). In some cases,
351 - // The 'name' property will be set, and in others it is the 'pagename', so we have to cover both cases.
352 - if ( ! empty( $query->query['name'] ) ) {
353 - $query->set( 'post_type', $query_post_types );
354 - } elseif ( ! empty( $query->query['pagename'] ) && false === strpos( $query->query['pagename'], '/' ) ) {
355 - $query->set( 'post_type', $query_post_types );
238 + private function is_landing_pages_page() {
239 + global $wp_the_query;
356 240
357 - // We also need to set the name query var since redirect_guess_404_permalink() relies on it.
358 - add_filter( 'pre_redirect_guess_404_permalink', function( $value ) use ( $query ) {
359 - set_query_var( 'name', $query->query['pagename'] );
360 -
361 - return $value;
362 - } );
363 - }
241 + return isset( $wp_the_query->query['post_type'] )
242 + && isset( $wp_the_query->query['elementor_library_type'] )
243 + && 'page' === $wp_the_query->query['post_type']
244 + && self::DOCUMENT_TYPE === $wp_the_query->query['elementor_library_type'];
364 245 }
365 246
366 247 /**
367 - * Handle 404
248 + * Add Landing Page post state.
368 249 *
369 - * This method runs after a page is not found in the database, but before a page is returned as a 404.
370 - * These cases are handled in this filter callback, that runs on the 'pre_handle_404' filter.
250 + * Adds a new "Landing Page" post state to the post table.
371 251 *
372 - * In some cases (such as when a site uses custom permalink structures), WordPress's WP_Query does not identify a
373 - * Landing Page's URL as a post belonging to the Landing Page CPT. Some cases are handled successfully by the
374 - * adjust_landing_page_query() method, but some are not and still trigger a 404 process. This method handles such
375 - * cases by overriding the $wp_query global to fetch the correct landing page post entry.
252 + * Fired by `display_post_states` filter.
376 253 *
377 - * For example, since Landing Pages slugs come directly after the site domain name, WP_Query might parse the post
378 - * as a category page. Since there is no category matching the slug, it triggers a 404 process. In this case, we
379 - * run a query for a Landing Page post with the passed slug ($query->query['category_name']. If a Landing Page
380 - * with the passed slug is found, we override the global $wp_query with the new, correct query.
254 + * @since 1.8.0
255 + * @access public
381 256 *
382 - * @param $current_value
383 - * @param $query
384 - * @return false
257 + * @param array $post_states An array of post display states.
258 + * @param \WP_Post $post The current post object.
259 + *
260 + * @return array A filtered array of post display states.
385 261 */
386 - private function handle_404( $current_value, $query ) {
387 - global $wp_query;
388 -
389 - // If another plugin/theme already used this filter, exit here to avoid conflicts.
390 - if ( $current_value ) {
391 - return $current_value;
262 + public function add_landing_page_post_state( $post_states, $post ) {
263 + if ( User::is_current_user_can_edit( $post->ID ) && $this->is_elementor_landing_page( $post ) ) {
264 + $post_states['landing-page'] = __( 'Landing Page', 'elementor' );
392 265 }
393 266
394 - if (
395 - // Make sure we only intervene in the main query.
396 - ! $query->is_main_query()
397 - // If a post was found, this is not a 404 case, so do not intervene.
398 - || ! empty( $query->posts )
399 - // This filter is only meant to deal with wrong queries where the only query var is 'category_name'.
400 - // If there is no 'category_name' query var, do not intervene.
401 - || empty( $query->query['category_name'] )
402 - // If the query is for a real taxonomy (determined by it including a table to search in, such as the
403 - // wp_term_relationships table), do not intervene.
404 - || ! empty( $query->tax_query->table_aliases )
405 - ) {
406 - return false;
407 - }
267 + return $post_states;
268 + }
408 269
409 - // Search for a Landing Page with the same name passed as the 'category name'.
410 - $possible_new_query = new \WP_Query( [
411 - 'no_found_rows' => true,
412 - 'post_type' => self::CPT,
413 - 'name' => $query->query['category_name'],
414 - ] );
270 + /**
271 + * Is Current Admin Page Edit LP
272 + *
273 + * Checks whether the current page is a native WordPress edit page for a landing page.
274 + */
275 + private function is_landing_page_admin_edit() {
276 + $screen = get_current_screen();
415 277
416 - // Only if such a Landing Page is found, override the query to fetch the correct page.
417 - if ( ! empty( $possible_new_query->posts ) ) {
418 - $wp_query = $possible_new_query; //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
278 + if ( 'post' === $screen->base ) {
279 + return $this->is_elementor_landing_page( get_post() );
419 280 }
420 281
421 282 return false;
422 283 }
423 284
424 - public function __construct() {
425 - if ( ! $this->should_activate_landing_pages() ) {
426 - return;
427 - }
285 + private function admin_localize_settings( $settings ) {
286 + $additional_settings = [
287 + 'urls' => [
288 + 'addNewLandingPageUrl' => $this->get_add_new_landing_page_url(),
289 + ],
290 + 'landingPages' => [
291 + 'landingPagesHasPages' => [] !== $this->get_landing_page_posts(),
292 + 'isLandingPageAdminEdit' => $this->is_landing_page_admin_edit(),
293 + ],
294 + ];
428 295
429 - $this->register_experiment();
296 + return array_replace_recursive( $settings, $additional_settings );
297 + }
430 298
431 - if ( ! Plugin::$instance->experiments->is_feature_active( 'landing-pages' ) ) {
432 - return;
433 - }
299 + public function __construct() {
300 + add_action( 'elementor/documents/register', function( Documents_Manager $documents_manager ) {
301 + $documents_manager->register_document_type( self::DOCUMENT_TYPE, Landing_Page::get_class_full_name() );
302 + } );
434 303
435 - $this->permalink_structure = get_option( 'permalink_structure' );
304 + add_action( 'admin_menu', function() {
305 + $this->add_submenu_page();
306 + }, 30 );
436 307
437 - $this->register_landing_page_cpt();
308 + // This is a hack to change the H1 title of the Landing Pages table page from 'Pages' to 'Landing Pages'.
309 + add_action( 'admin_head', function() {
310 + $this->change_admin_page_title();
311 + } );
438 312
439 - // If there is a permalink structure set to the site, run the hooks that modify the Landing Pages permalinks to
440 - // match WordPress' native 'Pages' post type.
441 - if ( '' !== $this->permalink_structure ) {
442 - // Landing Pages' post link needs to be modified to be identical to the pages permalink structure. This
443 - // needs to happen in both the admin and the front end, since post links are also used in the admin pages.
444 - add_filter( 'post_type_link', function( $post_link, $post, $leavename ) {
445 - return $this->remove_post_type_slug( $post_link, $post, $leavename );
446 - }, 10, 3 );
313 + // When visiting the Landing Pages Table page, the default title is 'Pages'. This filter callback changes it
314 + // to the 'Landing Pages' translation string.
315 + add_filter( 'admin_title', function( $title ) {
316 + return $this->change_admin_meta_title( $title );
317 + } );
447 318
448 - // The query itself only has to be manipulated when pages are viewed in the front end.
449 - if ( ! is_admin() || wp_doing_ajax() ) {
450 - add_action( 'pre_get_posts', function ( $query ) {
451 - $this->adjust_landing_page_query( $query );
452 - } );
319 + // Since Landing Pages are actually Pages ('page' post type), the 'Pages' menu is highlighted by default in
320 + // the admin. This overrides that and highlights the Templates menu instead, where the 'Landing Pages' submenu
321 + // item is located.
322 + add_action( 'parent_file', function( $parent_file ) {
323 + global $current_screen;
453 324
454 - // Handle cases where visiting a Landing Page's URL returns 404.
455 - add_filter( 'pre_handle_404', function ( $value, $query ) {
456 - return $this->handle_404( $value, $query );
457 - }, 10, 2 );
325 + if ( 'post' === $current_screen->base && $this->is_elementor_landing_page( get_post() ) ) {
326 + return Source_Local::ADMIN_MENU_SLUG;
458 327 }
459 - }
460 328
461 - add_action( 'elementor/documents/register', function( Documents_Manager $documents_manager ) {
462 - $documents_manager->register_document_type( self::DOCUMENT_TYPE, Landing_Page::get_class_full_name() );
329 + return $parent_file;
463 330 } );
464 331
465 - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
466 - $this->register_editor_one_menu( $menu_data_provider );
467 - } );
468 -
469 - add_filter( 'elementor/editor-one/menu/elementor_post_types', function ( array $elementor_post_types ): array {
470 - $elementor_post_types[ static::CPT ] = [
471 - 'menu_slug' => 'elementor-editor-templates',
472 - 'child_slug' => 'edit.php?post_type=' . static::CPT,
473 - ];
474 - return $elementor_post_types;
475 - } );
476 -
477 332 // Add the custom 'Add New' link for Landing Pages into Elementor's admin config.
478 - add_action( 'elementor/admin/localize_settings', function( array $settings ) {
333 + add_action( 'elementor/admin/localize_settings', function( $settings ) {
479 334 return $this->admin_localize_settings( $settings );
480 335 } );
481 336
482 - add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function( array $cpts ) {
483 - $cpts[] = self::CPT;
484 -
485 - return $cpts;
337 + add_filter( 'elementor/finder/categories', function( $categories ) {
338 + return $this->add_finder_items( $categories );
486 339 } );
487 340
488 - // When deleting posts in Landing Page CPT, force Elementor to check again whether this feature should be activated.
489 - add_action( 'deleted_post_' . self::CPT, function () {
490 - delete_option( self::ACTIVATION_KEY );
341 + // Remove the "Type" column added to the Pages table by the Landing Page document.
342 + add_filter( 'manage_page_posts_columns', function( $columns ) {
343 + return $this->remove_type_column( $columns );
491 344 } );
492 345
493 - // In the Landing Pages Admin Table page - Overwrite Template type column header title.
494 - add_action( 'manage_' . Landing_Pages_Module::CPT . '_posts_columns', function( $posts_columns ) {
495 - /** @var Source_Local $source_local */
496 - $source_local = Plugin::$instance->templates_manager->get_source( 'local' );
497 -
498 - return $source_local->admin_columns_headers( $posts_columns );
499 - } );
500 -
501 - // In the Landing Pages Admin Table page - Overwrite Template type column row values.
502 - add_action( 'manage_' . Landing_Pages_Module::CPT . '_posts_custom_column', function( $column_name, $post_id ) {
503 - /** @var Landing_Page $document */
504 - $document = Plugin::$instance->documents->get( $post_id );
505 -
506 - $document->admin_columns_content( $column_name );
507 - }, 10, 2 );
508 -
509 - // Overwrite the Admin Bar's 'New +' Landing Page URL with the link that creates the new LP in Elementor
510 - // with the Template Library modal open.
511 - add_action( 'admin_bar_menu', function( $admin_bar ) {
512 - // Get the Landing Page menu node.
513 - $new_landing_page_node = $admin_bar->get_node( 'new-e-landing-page' );
514 -
515 - if ( $new_landing_page_node ) {
516 - $new_landing_page_node->href = $this->get_add_new_landing_page_url();
517 -
518 - $admin_bar->add_node( $new_landing_page_node );
519 - }
520 - }, 100 );
346 + add_filter( 'display_post_states', [ $this, 'add_landing_page_post_state' ], 20, 2 );
521 347 }
522 348 }