PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.0-beta1
Elementor Website Builder – more than just a page builder v3.22.0-beta1
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 4.0.7 All 451 releases
elementor / modules / conversion-center / module.php

module.php in Elementor Website Builder – more than just a page builder 3.22.0-beta1, at modules/conversion-center/module.php

302 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\ConversionCenter;
4
5 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
6 use Elementor\Core\Base\Module as BaseModule;
7 use Elementor\Core\Documents_Manager;
8 use Elementor\Core\Experiments\Manager;
9 use Elementor\Modules\ConversionCenter\AdminMenuItems\Conversion_Center_Menu_Item;
10 use Elementor\Modules\ConversionCenter\AdminMenuItems\Links_Empty_View_Menu_Item;
11 use Elementor\Modules\ConversionCenter\AdminMenuItems\Links_Menu_Item;
12 use Elementor\Modules\ConversionCenter\Documents\Links_Page;
13 use Elementor\Modules\LandingPages\Documents\Landing_Page;
14 use Elementor\Modules\LandingPages\Module as Landing_Pages_Module;
15 use Elementor\Plugin;
16 use Elementor\TemplateLibrary\Source_Local;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly
20 }
21
22 class Module extends BaseModule {
23
24 const EXPERIMENT_NAME = 'conversion-center';
25
26 const DOCUMENT_TYPE = 'links-page';
27 const CPT_LINKS_PAGES = 'e-link-pages';
28 const ADMIN_PAGE_SLUG_LIB = 'edit.php?post_type=' . self::CPT_LINKS_PAGES;
29
30 private $has_links_pages = null;
31 private $trashed_links_pages;
32 private $new_links_pages_url;
33
34 public static function is_active(): bool {
35 return Plugin::$instance->experiments->is_feature_active( static::EXPERIMENT_NAME );
36 }
37
38 public function get_name(): string {
39 return static::EXPERIMENT_NAME;
40 }
41
42 public function get_widgets(): array {
43 return [
44 'Link_In_Bio',
45 'Contact_Buttons',
46 ];
47 }
48
49 public static function get_experimental_data(): array {
50 return [
51 'name' => static::EXPERIMENT_NAME,
52 'title' => esc_html__( 'Conversion Center', 'elementor' ),
53 'description' => esc_html__( 'A powerful feature to enhance your online presence. With the ability to create compelling Link in bio pages and easily accessible contact buttons, the Conversion Center is tailored to significantly boost your conversions.', 'elementor' ),
54 'hidden' => true,
55 'default' => Manager::STATE_INACTIVE,
56 ];
57 }
58
59 private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) {
60 $menu_args = $this->get_menu_args();
61
62 $slug = $menu_args['menu_slug'];
63 $function = $menu_args['function'];
64 $parent_slug = $slug . '#';
65 $admin_menu->register( $parent_slug, new Conversion_Center_Menu_Item() );
66
67 if ( is_callable( $function ) ) {
68 $admin_menu->register( $slug, new Links_Empty_View_Menu_Item( $function, $parent_slug ) );
69 } else {
70 $admin_menu->register( $slug, new Links_Menu_Item( $parent_slug ) );
71 }
72
73 }
74
75 public function __construct() {
76 $this->register_links_pages_cpt();
77
78 add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) {
79 $documents_manager->register_document_type( self::DOCUMENT_TYPE, Links_Page::get_class_full_name() );
80 } );
81
82 add_action( 'elementor/admin-top-bar/is-active', function ( $is_top_bar_active, $current_screen ) {
83 if ( strpos( $current_screen->id ?? '', 'conversion-center' ) !== false ) {
84 return true;
85 }
86
87 return $is_top_bar_active;
88 }, 10, 2 );
89
90 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
91 $this->register_admin_menu_legacy( $admin_menu );
92 }, Source_Local::ADMIN_MENU_PRIORITY + 20 );
93
94 add_action( 'elementor/admin/localize_settings', function ( array $settings ) {
95 return $this->admin_localize_settings( $settings );
96 } );
97
98 add_action( 'admin_menu', function () {
99 global $submenu;
100 $menu_args = $this->get_menu_args();
101
102 $slug = $menu_args['menu_slug'] . '#';
103 unset( $submenu[ $slug ][0] );
104
105 }, 100 );
106
107 add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function ( array $cpts ) {
108 $cpts[] = self::CPT_LINKS_PAGES;
109
110 return $cpts;
111 } );
112
113 add_action( 'manage_' . self::CPT_LINKS_PAGES . '_posts_columns', function( $posts_columns ) {
114 $source_local = Plugin::$instance->templates_manager->get_source( 'local' );
115
116 return $source_local->admin_columns_headers( $posts_columns );
117 } );
118
119 add_action( 'manage_' . self::CPT_LINKS_PAGES . '_posts_custom_column', function( $column_name, $post_id ) {
120 $document = Plugin::$instance->documents->get( $post_id );
121
122 $document->admin_columns_content( $column_name );
123 }, 10, 2 );
124 add_action( 'admin_bar_menu', function ( $admin_bar ) {
125 $new_links_page_node = $admin_bar->get_node( 'new-e-links-page' );
126
127 if ( $new_links_page_node ) {
128 $new_links_page_node->href = $this->get_add_new_links_page_url();
129
130 $admin_bar->add_node( $new_links_page_node );
131 }
132 }, 100 );
133 }
134
135 private function get_trashed_lib_posts(): array {
136 if ( $this->trashed_links_pages ) {
137 return $this->trashed_links_pages;
138 }
139
140 // `'posts_per_page' => 1` is because this is only used as an indicator to whether there are any trashed landing pages.
141 $trashed_posts_query = new \WP_Query( [
142 'no_found_rows' => true,
143 'post_type' => self::CPT_LINKS_PAGES,
144 'post_status' => 'trash',
145 'posts_per_page' => 1,
146 'meta_key' => '_elementor_template_type',
147 'meta_value' => self::DOCUMENT_TYPE,
148 ] );
149
150 $this->trashed_links_pages = $trashed_posts_query->posts;
151
152 return $this->trashed_links_pages;
153 }
154
155 private function get_add_new_links_page_url() {
156 if ( ! $this->new_links_pages_url ) {
157 $this->new_links_pages_url = Plugin::$instance->documents->get_create_new_post_url(
158 self::CPT_LINKS_PAGES,
159 self::DOCUMENT_TYPE
160 ) . '#library';
161 }
162
163 return $this->new_links_pages_url;
164 }
165
166 public function print_empty_links_pages_page() {
167 $template_sources = Plugin::$instance->templates_manager->get_registered_sources();
168 $source_local = $template_sources['local'];
169 $trashed_posts = $this->get_trashed_lib_posts();
170
171 ?>
172 <div class="e-landing-pages-empty">
173 <?php
174 /** @var Source_Local $source_local */
175 $source_local->print_blank_state_template(
176 esc_html__( 'Links Page', 'elementor' ),
177 $this->get_add_new_links_page_url(),
178 esc_html__( 'Build Effective Landing Pages for your business\' marketing campaigns.', 'elementor' )
179 );
180
181 if ( ! empty( $trashed_posts ) ) : ?>
182 <div class="e-trashed-items">
183 <?php
184 printf(
185 /* translators: %1$s Link open tag, %2$s: Link close tag. */
186 esc_html__( 'Or view %1$sTrashed Items%1$s', 'elementor' ),
187 '<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT_LINKS_PAGES ) ) . '">',
188 '</a>'
189 );
190 ?>
191 </div>
192 <?php endif; ?>
193 </div>
194 <?php
195 }
196
197 private function is_links_page_admin_edit() {
198 $screen = get_current_screen();
199
200 if ( 'post' === $screen->base ) {
201 return $this->is_elementor_links_page( get_post() );
202 }
203
204 return false;
205 }
206
207 private function admin_localize_settings( $settings ) {
208 $additional_settings = [
209 'urls' => [
210 'addNewLinkUrl' => $this->get_add_new_links_page_url(),
211 ],
212 'linksPages' => [
213 'hasPages' => $this->has_links_pages(),
214 'isAdminEdit' => $this->is_links_page_admin_edit(),
215 ],
216 ];
217
218 return array_replace_recursive( $settings, $additional_settings );
219 }
220
221 private function register_links_pages_cpt() {
222 $labels = [
223 'name' => esc_html__( 'Links Pages', 'elementor' ),
224 'singular_name' => esc_html__( 'Links Page', 'elementor' ),
225 'add_new' => esc_html__( 'Add New', 'elementor' ),
226 'add_new_item' => esc_html__( 'Add New Links Page', 'elementor' ),
227 'edit_item' => esc_html__( 'Edit Links Page', 'elementor' ),
228 'new_item' => esc_html__( 'New Links Page', 'elementor' ),
229 'all_items' => esc_html__( 'All Links Pages', 'elementor' ),
230 'view_item' => esc_html__( 'View Links Page', 'elementor' ),
231 'search_items' => esc_html__( 'Search Links Pages', 'elementor' ),
232 'not_found' => esc_html__( 'No Links Pages found', 'elementor' ),
233 'not_found_in_trash' => esc_html__( 'No Links Pages found in trash', 'elementor' ),
234 'parent_item_colon' => '',
235 'menu_name' => esc_html__( 'Links Pages', 'elementor' ),
236 ];
237
238 $args = [
239 'labels' => $labels,
240 'public' => true,
241 'show_in_menu' => 'edit.php?post_type=elementor_library&tabs_group=library',
242 'capability_type' => 'page',
243 'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ],
244 'supports' => [
245 'title',
246 'editor',
247 'comments',
248 'revisions',
249 'trackbacks',
250 'author',
251 'excerpt',
252 'page-attributes',
253 'thumbnail',
254 'custom-fields',
255 'post-formats',
256 'elementor',
257 ],
258 ];
259
260 register_post_type( self::CPT_LINKS_PAGES, $args );
261 }
262
263 private function has_links_pages(): bool {
264 if ( null !== $this->has_links_pages ) {
265 return $this->has_links_pages;
266 }
267
268 $posts_query = new \WP_Query( [
269 'no_found_rows' => true,
270 'post_type' => self::CPT_LINKS_PAGES,
271 'post_status' => 'any',
272 'posts_per_page' => 1,
273 'meta_key' => '_elementor_template_type',
274 'meta_value' => self::DOCUMENT_TYPE,
275 ] );
276
277 $this->has_links_pages = $posts_query->post_count > 0;
278
279 return $this->has_links_pages;
280 }
281
282 public function is_elementor_links_page( \WP_Post $post ): bool {
283 return self::CPT_LINKS_PAGES === $post->post_type;
284 }
285
286 private function get_menu_args(): array {
287 if ( $this->has_links_pages() ) {
288 $menu_slug = self::ADMIN_PAGE_SLUG_LIB;
289 $function = null;
290 } else {
291 $menu_slug = self::CPT_LINKS_PAGES;
292 $function = [ $this, 'print_empty_links_pages_page' ];
293 }
294
295 return [
296 'menu_slug' => $menu_slug,
297 'function' => $function,
298 ];
299 }
300
301 }
302