PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0-dev2
Elementor Website Builder – more than just a page builder v3.1.0-dev2
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 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/landing-pages/module.php +162 -365 4.0.73.1.0-dev2 View file →
@@ -2,15 +2,13 @@
2 2 namespace Elementor\Modules\LandingPages;
3 3
4 4 use Elementor\Core\Base\Module as BaseModule;
5 5 use Elementor\Core\Documents_Manager;
6 -use Elementor\Core\Experiments\Manager as Experiments_Manager;
7 6 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 7 use Elementor\Plugin;
12 8 use Elementor\TemplateLibrary\Source_Local;
9 +use Elementor\User;
10 +use Elementor\Utils;
13 11
14 12 if ( ! defined( 'ABSPATH' ) ) {
15 13 exit; // Exit if accessed directly.
16 14 }
@@ -17,167 +15,107 @@
17 15
18 16 class Module extends BaseModule {
19 17
20 18 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';
19 + const ADMIN_PAGE_SLUG = 'edit.php?post_type=page&elementor_library_type=landing-page';
20 + const ADMIN_PAGE_NO_LPS_SLUG = 'edit.php?post_type=elementor_library&page=landing-page';
24 21
25 - private $has_pages = null;
22 + private $posts;
26 23 private $trashed_posts;
27 - private $new_lp_url;
28 - private $permalink_structure;
29 24
30 25 public function get_name() {
31 26 return 'landing-pages';
32 27 }
33 28
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( [
29 + public static function get_experimental_data() {
30 + return [
43 31 '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 - ] );
32 + 'title' => __( 'Landing Pages', 'elementor' ),
33 + 'description' => __( 'Adds a new Elementor content type that allows creating beautiful landing pages instantly in a streamlined workflow.', 'elementor' ),
34 + ];
54 35 }
55 36
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 37 private function get_trashed_landing_page_posts() {
91 - if ( $this->trashed_posts ) {
38 + if ( isset( $this->trashed_posts ) ) {
92 39 return $this->trashed_posts;
93 40 }
94 41
95 - // `'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,
42 + $this->trashed_posts = new \WP_Query( [
43 + 'post_type' => 'page',
99 44 'post_status' => 'trash',
100 - 'posts_per_page' => 1,
45 + 'elementor_library_type' => self::DOCUMENT_TYPE,
101 46 'meta_key' => '_elementor_template_type',
102 - 'meta_value' => self::DOCUMENT_TYPE,
47 + 'meta_value' => 'landing-page',
103 48 ] );
104 49
105 - $this->trashed_posts = $trashed_posts_query->posts;
106 -
107 50 return $this->trashed_posts;
108 51 }
109 52
110 - private function has_landing_pages() {
111 - if ( null !== $this->has_pages ) {
112 - return $this->has_pages;
53 + private function get_landing_page_posts() {
54 + if ( isset( $this->posts ) ) {
55 + return $this->posts;
113 56 }
114 57
115 - $posts_query = new \WP_Query( [
116 - 'no_found_rows' => true,
117 - 'post_type' => self::CPT,
118 - 'post_status' => 'any',
119 - 'posts_per_page' => 1,
58 + $this->posts = new \WP_Query( [
59 + 'post_type' => 'page',
60 + 'elementor_library_type' => self::DOCUMENT_TYPE,
120 61 'meta_key' => '_elementor_template_type',
121 - 'meta_value' => self::DOCUMENT_TYPE,
62 + 'meta_value' => 'landing-page',
122 63 ] );
123 64
124 - $this->has_pages = $posts_query->post_count > 0;
125 -
126 - return $this->has_pages;
65 + return $this->posts;
127 66 }
128 67
129 68 /**
130 - * Is Elementor Landing Page.
69 + * Add Submenu Page
131 70 *
132 - * Check whether the post is an Elementor Landing Page.
71 + * Adds the 'Landing Pages' submenu item to the 'Templates' menu item.
133 72 *
134 73 * @since 3.1.0
135 - * @access public
136 - *
137 - * @param \WP_Post $post Post Object.
138 - *
139 - * @return bool Whether the post was built with Elementor.
140 74 */
141 - public function is_elementor_landing_page( $post ) {
142 - return self::CPT === $post->post_type;
143 - }
75 + private function add_submenu_page() {
76 + $posts = $this->get_landing_page_posts();
144 77
145 - public function get_menu_args() {
146 - if ( $this->has_landing_pages() ) {
147 - $menu_slug = self::ADMIN_PAGE_SLUG;
148 - $function = null;
78 + // If there are no Landing Pages, show the "Create Your First Landing Page" page.
79 + // If there are, show the pages table.
80 + if ( ! empty( $posts->posts ) ) {
81 + $this->landing_page_menu_slug = self::ADMIN_PAGE_SLUG;
82 + $landing_page_menu_callback = null;
149 83 } else {
150 - $menu_slug = self::CPT;
151 - $function = [ $this, 'print_empty_landing_pages_page' ];
84 + $this->landing_page_menu_slug = self::DOCUMENT_TYPE;
85 + $landing_page_menu_callback = [ $this, 'print_empty_landing_pages_page' ];
152 86 }
153 87
154 - return [
155 - 'menu_slug' => $menu_slug,
156 - 'function' => $function,
157 - ];
88 + $landing_pages_title = __( 'Landing Pages', 'elementor' );
89 +
90 + add_submenu_page(
91 + Source_Local::ADMIN_MENU_SLUG,
92 + $landing_pages_title,
93 + $landing_pages_title,
94 + 'manage_options',
95 + $this->landing_page_menu_slug,
96 + $landing_page_menu_callback
97 + );
158 98 }
159 99
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 ) );
100 + private function get_add_new_landing_page_url() {
101 + return Utils::get_create_new_post_url( 'page', self::DOCUMENT_TYPE ) . '#library';
162 102 }
163 103
164 104 /**
165 - * Get 'Add New' Landing Page URL
105 + * Remove Type Column
166 106 *
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.
107 + * Removes the "Type" column from the pages table.
170 108 *
171 109 * @since 3.1.0
172 110 *
173 - * @return string
111 + * @param array $columns
112 + * @return array $columns
174 113 */
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;
114 + private function remove_type_column( $columns ) {
115 + unset( $columns['taxonomy-elementor_library_type'] );
116 +
117 + return $columns;
180 118 }
181 119
182 120 /**
183 121 * Get Empty Landing Pages Page
@@ -195,328 +133,187 @@
195 133 ?>
196 134 <div class="e-landing-pages-empty">
197 135 <?php
198 136 /** @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' ) );
137 + $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 138
201 - if ( ! empty( $trashed_posts ) ) : ?>
139 + if ( ! empty( $trashed_posts->posts ) ) { ?>
202 140 <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 - ?>
141 + <?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 142 </div>
212 - <?php endif; ?>
143 + <?php } ?>
213 144 </div>
214 145 <?php
215 146 }
216 147
217 148 /**
218 - * Is Current Admin Page Edit LP
149 + * Add Finder Items
219 150 *
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
151 + * Adds Items to the Finder index to make them searchable in the Elementor Editor Finder modal.
234 152 *
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 153 * @since 3.1.0
239 154 *
240 - * @param $settings
241 - * @return array|null
155 + * @param array $categories
156 + * @return array $categories
242 157 */
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 - ],
158 + private function add_finder_items( array $categories ) {
159 + $categories['general']['items']['landing-pages'] = [
160 + 'title' => __( 'Landing Pages', 'elementor' ),
161 + 'icon' => 'single-page',
162 + 'url' => admin_url( self::ADMIN_PAGE_SLUG ),
163 + 'keywords' => [ self::DOCUMENT_TYPE, 'landing', 'page', 'library' ],
252 164 ];
253 165
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' ),
166 + $categories['create']['items']['landing-pages'] = [
167 + 'title' => __( 'Add New Landing Page', 'elementor' ),
168 + 'icon' => 'single-page',
169 + 'url' => esc_url( Utils::get_create_new_post_url( 'page', self::DOCUMENT_TYPE ) ) . '#library',
170 + 'keywords' => [ 'landing-page', 'landing', 'page', 'new', 'create', 'library' ],
277 171 ];
278 172
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 );
173 + return $categories;
289 174 }
290 175
291 176 /**
292 - * Remove Post Type Slug
177 + * Change Admin Page Title
293 178 *
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.
179 + * Changes the page title of the "Landing Pages" Admin page which displays the "Pages" table,
180 + * from "Pages" to the "Landing Pages" translation string.
298 181 *
299 - * Runs on the 'post_type_link' filter.
300 - *
301 182 * @since 3.1.0
302 - *
303 - * @param $post_link
304 - * @param $post
305 - * @param $leavename
306 - * @return string|string[]
307 183 */
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;
184 + private function change_admin_page_title() {
185 + global $wp_post_types;
186 +
187 + if ( $this->is_landing_pages_page() ) {
188 + $wp_post_types['page']->labels->name = __( 'Landing Pages', 'elementor' );
312 189 }
313 -
314 - // Any slug prefixes need to be removed from the post link.
315 - return trailingslashit( get_home_url() ) . trailingslashit( $post->post_name );
316 190 }
317 191
318 192 /**
319 - * Adjust Landing Page Query
193 + * Change Admin Meta Title
320 194 *
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.
195 + * Changes the contents of the meta <title> tag in the "Landing Pages" Admin page which displays the "Pages" table,
196 + * from "Pages" to "Landing Pages".
325 197 *
326 198 * @since 3.1.0
327 199 *
328 - * @param \WP_Query $query
200 + * @param string $title meta title contents
201 + * @return string $title
329 202 */
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;
203 + private function change_admin_meta_title( $title ) {
204 + if ( $this->is_landing_pages_page() ) {
205 + // Get WordPress' default 'Pages' translation string, since the original title comes from WordPress core.
206 + return str_replace( __( 'Pages', 'elementor' ), __( 'Landing Pages', 'elementor' ), $title ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
343 207 }
344 208
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 ];
209 + return $title;
210 + }
347 211
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 );
212 + private function is_landing_pages_page() {
213 + global $wp_the_query;
356 214
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 - }
215 + return isset( $wp_the_query->query['post_type'] )
216 + && isset( $wp_the_query->query['elementor_library_type'] )
217 + && 'page' === $wp_the_query->query['post_type']
218 + && self::DOCUMENT_TYPE === $wp_the_query->query['elementor_library_type'];
364 219 }
365 220
366 221 /**
367 - * Handle 404
222 + * Add Landing Page post state.
368 223 *
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.
224 + * Adds a new "Landing Page" post state to the post table.
371 225 *
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.
226 + * Fired by `display_post_states` filter.
376 227 *
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.
228 + * @since 1.8.0
229 + * @access public
381 230 *
382 - * @param $current_value
383 - * @param $query
384 - * @return false
231 + * @param array $post_states An array of post display states.
232 + * @param \WP_Post $post The current post object.
233 + *
234 + * @return array A filtered array of post display states.
385 235 */
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;
236 + public function add_landing_page_post_state( $post_states, $post ) {
237 + if ( User::is_current_user_can_edit( $post->ID ) && Plugin::$instance->db->is_elementor_landing_page( $post ) ) {
238 + $post_states['landing-page'] = __( 'Landing Page', 'elementor' );
392 239 }
393 240
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 - }
241 + return $post_states;
242 + }
408 243
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 - ] );
244 + /**
245 + * Is Current Admin Page Edit LP
246 + *
247 + * Checks whether the current page is a native WordPress edit page for a landing page.
248 + */
249 + private function is_current_admin_page_edit_lp() {
250 + $screen = get_current_screen();
415 251
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
252 + if ( 'post' === $screen->base ) {
253 + return Plugin::$instance->db->is_elementor_landing_page( get_post() );
419 254 }
420 255
421 256 return false;
422 257 }
423 258
424 - public function __construct() {
425 - if ( ! $this->should_activate_landing_pages() ) {
426 - return;
427 - }
259 + private function admin_localize_settings( $settings ) {
260 + $additional_settings = [
261 + 'urls' => [
262 + 'addNewLandingPageUrl' => $this->get_add_new_landing_page_url(),
263 + ],
264 + 'landingPages' => [
265 + 'landingPagesHasPages' => [] !== $this->get_landing_page_posts(),
266 + 'isCurrentPageLPAdminEdit' => $this->is_current_admin_page_edit_lp(),
267 + ],
268 + ];
428 269
429 - $this->register_experiment();
270 + return array_replace_recursive( $settings, $additional_settings );
271 + }
430 272
431 - if ( ! Plugin::$instance->experiments->is_feature_active( 'landing-pages' ) ) {
432 - return;
433 - }
273 + public function __construct() {
274 + add_action( 'elementor/documents/register', function( Documents_Manager $documents_manager ) {
275 + $documents_manager->register_document_type( self::DOCUMENT_TYPE, Landing_Page::get_class_full_name() );
276 + } );
434 277
435 - $this->permalink_structure = get_option( 'permalink_structure' );
278 + add_action( 'admin_menu', function() {
279 + $this->add_submenu_page();
280 + }, 30 );
436 281
437 - $this->register_landing_page_cpt();
282 + // This is a hack to change the H1 title of the Landing Pages table page from 'Pages' to 'Landing Pages'.
283 + add_action( 'admin_head', function() {
284 + $this->change_admin_page_title();
285 + } );
438 286
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 );
287 + // When visiting the Landing Pages Table page, the default title is 'Pages'. This filter callback changes it
288 + // to the 'Landing Pages' translation string.
289 + add_filter( 'admin_title', function( $title ) {
290 + return $this->change_admin_meta_title( $title );
291 + } );
447 292
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 - } );
293 + add_action( 'parent_file', function( $parent_file ) {
294 + global $current_screen;
453 295
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 );
296 + if ( 'post' === $current_screen->base && Plugin::$instance->db->is_elementor_landing_page( get_post() ) ) {
297 + return Source_Local::ADMIN_MENU_SLUG;
458 298 }
459 - }
460 299
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() );
300 + return $parent_file;
463 301 } );
464 302
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 303 // Add the custom 'Add New' link for Landing Pages into Elementor's admin config.
478 - add_action( 'elementor/admin/localize_settings', function( array $settings ) {
304 + add_action( 'elementor/admin/localize_settings', function( $settings ) {
479 305 return $this->admin_localize_settings( $settings );
480 306 } );
481 307
482 - add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function( array $cpts ) {
483 - $cpts[] = self::CPT;
484 -
485 - return $cpts;
308 + add_filter( 'elementor/finder/categories', function( $categories ) {
309 + return $this->add_finder_items( $categories );
486 310 } );
487 311
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 );
312 + // Remove the "Type" column added to the Pages table by the Landing Page document.
313 + add_filter( 'manage_page_posts_columns', function( $columns ) {
314 + return $this->remove_type_column( $columns );
491 315 } );
492 316
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 );
317 + add_filter( 'display_post_states', [ $this, 'add_landing_page_post_state' ], 20, 2 );
521 318 }
522 319 }