PluginProbe
Elementor Website Builder – more than just a page builder / 3.8.0
Elementor Website Builder – more than just a page builder v3.8.0
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 / app / modules / import-export / module.php

module.php in Elementor Website Builder – more than just a page builder 3.8.0, at app/modules/import-export/module.php

681 lines 21.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App\Modules\ImportExport;
3
4 use Elementor\App\Modules\ImportExport\Processes\Export;
5 use Elementor\App\Modules\ImportExport\Processes\Import;
6 use Elementor\App\Modules\ImportExport\Processes\Revert;
7 use Elementor\Core\Base\Module as BaseModule;
8 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
9 use Elementor\Core\Files\Uploads_Manager;
10 use Elementor\Modules\System_Info\Reporters\Server;
11 use Elementor\Plugin;
12 use Elementor\Tools;
13 use Elementor\Utils as ElementorUtils;
14 use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly
18 }
19
20 /**
21 * Import Export Module
22 *
23 * Responsible for initializing Elementor App functionality
24 */
25 class Module extends BaseModule {
26 const FORMAT_VERSION = '2.0';
27
28 const EXPORT_TRIGGER_KEY = 'elementor_export_kit';
29
30 const UPLOAD_TRIGGER_KEY = 'elementor_upload_kit';
31
32 const IMPORT_TRIGGER_KEY = 'elementor_import_kit';
33
34 const REFERRER_KIT_LIBRARY = 'kit-library';
35
36 const REFERRER_LOCAL = 'local';
37
38 const PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error';
39
40 const NO_WRITE_PERMISSIONS_KEY = 'no-write-permissions';
41
42 const OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS = 'elementor_import_sessions';
43
44 const OPTION_KEY_ELEMENTOR_REVERT_SESSIONS = 'elementor_revert_sessions';
45
46 const META_KEY_ELEMENTOR_IMPORT_SESSION_ID = '_elementor_import_session_id';
47
48 const META_KEY_ELEMENTOR_EDIT_MODE = '_elementor_edit_mode';
49
50 /**
51 * Assigning the export process to a property, so we can use the process from outside the class.
52 *
53 * @var Export
54 */
55 public $export;
56
57 /**
58 * Assigning the import process to a property, so we can use the process from outside the class.
59 *
60 * @var Import
61 */
62 public $import;
63
64 /**
65 * Assigning the revert process to a property, so we can use the process from outside the class.
66 *
67 * @var Revert
68 */
69 public $revert;
70
71 /**
72 * Get name.
73 *
74 * @access public
75 *
76 * @return string
77 */
78 public function get_name() {
79 return 'import-export';
80 }
81
82 public function __construct() {
83 $this->register_actions();
84
85 if ( ElementorUtils::is_wp_cli() ) {
86 \WP_CLI::add_command( 'elementor kit', WP_CLI::class );
87 }
88
89 ( new Usage() )->register();
90 }
91
92 public function get_init_settings() {
93 if ( ! Plugin::$instance->app->is_current() ) {
94 return [];
95 }
96
97 return $this->get_config_data();
98 }
99
100 /**
101 * Register the import/export tab in elementor tools.
102 */
103 public function register_settings_tab( Tools $tools ) {
104 $tools->add_tab( 'import-export-kit', [
105 'label' => esc_html__( 'Import / Export Kit', 'elementor' ),
106 'sections' => [
107 'intro' => [
108 'label' => esc_html__( 'Template Kits', 'elementor' ),
109 'callback' => function() {
110 $this->render_import_export_tab_content();
111 },
112 'fields' => [],
113 ],
114 ],
115 ] );
116 }
117
118 /**
119 * Render the import/export tab content.
120 */
121 private function render_import_export_tab_content() {
122 $intro_text_link = sprintf( '<a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%s</a>', esc_html__( 'Learn more', 'elementor' ) );
123
124 $intro_text = sprintf(
125 /* translators: 1: New line break, 2: Learn More link. */
126 __( 'Design sites faster with a template kit that contains some or all components of a complete site, like templates, content & site settings.%1$sYou can import a kit and apply it to your site, or export the elements from this site to be used anywhere else. %2$s', 'elementor' ),
127 '<br>',
128 $intro_text_link
129 );
130
131 $content_data = [
132 'export' => [
133 'title' => esc_html__( 'Export a Template Kit', 'elementor' ),
134 'button' => [
135 'url' => Plugin::$instance->app->get_base_url() . '#/export',
136 'text' => esc_html__( 'Start Export', 'elementor' ),
137 ],
138 'description' => esc_html__( 'Bundle your whole site - or just some of its elements - to be used for another website.', 'elementor' ),
139 'link' => [
140 'url' => 'https://go.elementor.com/wp-dash-import-export-export-flow/',
141 'text' => esc_html__( 'Learn More', 'elementor' ),
142 ],
143 ],
144 'import' => [
145 'title' => esc_html__( 'Import a Template Kit', 'elementor' ),
146 'button' => [
147 'url' => Plugin::$instance->app->get_base_url() . '#/import',
148 'text' => esc_html__( 'Start Import', 'elementor' ),
149 ],
150 'description' => esc_html__( 'Apply the design and settings of another site to this one.', 'elementor' ),
151 'link' => [
152 'url' => 'https://go.elementor.com/wp-dash-import-export-import-flow/',
153 'text' => esc_html__( 'Learn More', 'elementor' ),
154 ],
155 ],
156 ];
157
158 $this->revert = new Revert();
159 $last_imported_kit = $this->revert->get_last_import_session();
160 $penultimate_imported_kit = $this->revert->get_penultimate_import_session();
161
162 $user_date_format = get_option( 'date_format' );
163 $user_time_format = get_option( 'time_format' );
164 $date_format = $user_date_format . ' ' . $user_time_format;
165
166 $should_show_revert_section = $this->should_show_revert_section( $last_imported_kit );
167
168 if ( $should_show_revert_section ) {
169 if ( ! empty( $penultimate_imported_kit ) ) {
170 $revert_text = sprintf(
171 esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s %3$s and revert to the site setting that came with "%4$s" on %5$s.', 'elementor' ),
172 ! empty( $last_imported_kit['kit_name'] ) ? $last_imported_kit['kit_name'] : esc_html__( 'imported kit', 'elementor' ),
173 gmdate( $date_format, $last_imported_kit['start_timestamp'] ),
174 '<br>',
175 ! empty( $penultimate_imported_kit['kit_name'] ) ? $penultimate_imported_kit['kit_name'] : esc_html__( 'imported kit', 'elementor' ),
176 gmdate( $date_format, $penultimate_imported_kit['start_timestamp'] )
177 );
178 } else {
179 $revert_text = sprintf(
180 esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s.%3$s Your original site settings will be restored.', 'elementor' ),
181 ! empty( $last_imported_kit['kit_name'] ) ? $last_imported_kit['kit_name'] : esc_html__( 'imported kit', 'elementor' ),
182 gmdate( $date_format, $last_imported_kit['start_timestamp'] ),
183 '<br>'
184 );
185 }
186 }
187 ?>
188
189 <div class="tab-import-export-kit__content">
190 <p class="tab-import-export-kit__info"><?php ElementorUtils::print_unescaped_internal_string( $intro_text ); ?></p>
191
192 <div class="tab-import-export-kit__wrapper">
193 <?php foreach ( $content_data as $data ) { ?>
194 <div class="tab-import-export-kit__container">
195 <div class="tab-import-export-kit__box">
196 <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2>
197 <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button elementor-button-success">
198 <?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?>
199 </a>
200 </div>
201 <p><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p>
202 <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a>
203 </div>
204 <?php } ?>
205 </div>
206
207 <?php
208 if ( $should_show_revert_section ) {
209 $link_attributes = [
210 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=elementor_revert_kit' ), 'elementor_revert_kit' ),
211 'id' => 'elementor-import-export__revert_kit',
212 'class' => 'button',
213 ];
214 ?>
215 <div class="tab-import-export-kit__revert">
216 <h2>
217 <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove the most recent Kit', 'elementor' ) ); ?>
218 </h2>
219 <p class="tab-import-export-kit__info">
220 <?php ElementorUtils::print_unescaped_internal_string( $revert_text ); ?>
221 </p>
222 <a <?php ElementorUtils::print_html_attributes( $link_attributes ); ?> >
223 <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove Kit', 'elementor' ) ); ?>
224 </a>
225 </div>
226 <?php } ?>
227 </div>
228 <?php
229 }
230
231 /**
232 * Upload a kit zip file and get the kit data.
233 *
234 * Assigning the Import process to the 'import' property,
235 * so it will be available to use in different places such as: WP_Cli, Pro, etc.
236 *
237 * @param string $file Path to the file.
238 * @param string $referrer Referrer of the file 'local' or 'kit-library'.
239 * @return array
240 * @throws \Exception
241 */
242 public function upload_kit( $file, $referrer ) {
243 $this->ensure_writing_permissions();
244
245 $this->import = new Import( $file, [ 'referrer' => $referrer ] );
246
247 return [
248 'session' => $this->import->get_session_id(),
249 'manifest' => $this->import->get_manifest(),
250 'conflicts' => $this->import->get_settings_conflicts(),
251 ];
252 }
253
254 /**
255 * Import a kit by session_id.
256 * Upload and import a kit by kit zip file.
257 *
258 * Assigning the Import process to the 'import' property,
259 * so it will be available to use in different places such as: WP_Cli, Pro, etc.
260 *
261 * @param string $path Path to the file or session_id.
262 * @param array $settings Settings the import use to determine which content to import.
263 * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.)
264 * @return array
265 * @throws \Exception
266 */
267 public function import_kit( $path, $settings ) {
268 $this->ensure_writing_permissions();
269
270 $this->import = new Import( $path, $settings );
271 $this->import->register_default_runners();
272
273 do_action( 'elementor/import-export/import-kit', $this->import );
274
275 return $this->import->run();
276 }
277
278 /**
279 * Export a kit.
280 *
281 * Assigning the Export process to the 'export' property,
282 * so it will be available to use in different places such as: WP_Cli, Pro, etc.
283 *
284 * @param array $settings Settings the export use to determine which content to export.
285 * (e.g: include, kit_info, selected_plugins, selected_cpt, etc.)
286 * @return array
287 * @throws \Exception
288 */
289 public function export_kit( $settings ) {
290 $this->ensure_writing_permissions();
291
292 $this->export = new Export( $settings );
293 $this->export->register_default_runners();
294
295 do_action( 'elementor/import-export/export-kit', $this->export );
296
297 return $this->export->run();
298 }
299
300 /**
301 * Handle revert kit ajax request.
302 */
303 public function revert_last_imported_kit() {
304 $this->revert = new Revert();
305 $this->revert->register_default_runners();
306
307 do_action( 'elementor/import-export/revert-kit', $this->revert );
308
309 $this->revert->run();
310 }
311
312
313 /**
314 * Handle revert last imported kit ajax request.
315 */
316 public function handle_revert_last_imported_kit() {
317 check_admin_referer( 'elementor_revert_kit' );
318
319 $this->revert_last_imported_kit();
320
321 wp_safe_redirect( admin_url( 'admin.php?page=' . Tools::PAGE_ID . '#tab-import-export-kit' ) );
322 die;
323 }
324
325 /**
326 * Register appropriate actions.
327 */
328 private function register_actions() {
329 add_action( 'admin_init', function() {
330 if ( wp_doing_ajax() &&
331 isset( $_POST['action'] ) &&
332 isset( $_POST['_nonce'] ) &&
333 wp_verify_nonce( $_POST['_nonce'], Ajax::NONCE_KEY ) &&
334 current_user_can( 'manage_options' )
335 ) {
336 $this->maybe_handle_ajax();
337 }
338 } );
339
340 add_action( 'admin_post_elementor_revert_kit', [ $this, 'handle_revert_last_imported_kit' ] );
341
342 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
343
344 $page_id = Tools::PAGE_ID;
345
346 add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] );
347 }
348
349 private function ensure_writing_permissions() {
350 $server = new Server();
351
352 $paths_to_check = [
353 Server::KEY_PATH_WP_CONTENT_DIR => $server->get_system_path( Server::KEY_PATH_WP_CONTENT_DIR ),
354 Server::KEY_PATH_UPLOADS_DIR => $server->get_system_path( Server::KEY_PATH_UPLOADS_DIR ),
355 Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR => $server->get_system_path( Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ),
356 ];
357
358 $permissions = $server->get_paths_permissions( $paths_to_check );
359
360 // WP Content dir has to be exists and writable.
361 if ( ! $permissions[ Server::KEY_PATH_WP_CONTENT_DIR ]['write'] ) {
362 throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_WP_CONTENT_DIR );
363 }
364
365 // WP Uploads dir has to be exists and writable.
366 if ( ! $permissions[ Server::KEY_PATH_UPLOADS_DIR ]['write'] ) {
367 throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_UPLOADS_DIR );
368 }
369
370 // Elementor uploads dir permissions is divided to 2 cases:
371 // 1. If the dir exists, it has to be writable.
372 // 2. If the dir doesn't exist, the parent dir has to be writable (wp uploads dir), so we can create it.
373 if ( $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) {
374 throw new \Error( self::NO_WRITE_PERMISSIONS_KEY . 'in - ' . Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR );
375 }
376 }
377
378 /**
379 * Enqueue admin scripts
380 */
381 public function enqueue_scripts() {
382 wp_enqueue_script(
383 'elementor-import-export-admin',
384 $this->get_js_assets_url( 'import-export-admin' ),
385 [ 'elementor-common' ],
386 ELEMENTOR_VERSION,
387 true
388 );
389 }
390
391 /**
392 * Assign each ajax action to a method.
393 */
394 private function maybe_handle_ajax() {
395 // phpcs:ignore WordPress.Security.NonceVerification.Missing
396 switch ( $_POST['action'] ) {
397 case static::EXPORT_TRIGGER_KEY:
398 $this->handle_export_kit();
399 break;
400
401 case static::UPLOAD_TRIGGER_KEY:
402 $this->handle_upload_kit();
403 break;
404
405 case static::IMPORT_TRIGGER_KEY:
406 $this->handle_import_kit();
407 break;
408
409 default:
410 break;
411 }
412 }
413
414 /**
415 * Handle upload kit ajax request.
416 */
417 private function handle_upload_kit() {
418 // PHPCS - Already validated in caller function.
419 if ( ! empty( $_POST['e_import_file'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
420 if (
421 ! isset( $_POST['e_kit_library_nonce'] ) ||
422 ! wp_verify_nonce( $_POST['e_kit_library_nonce'], 'kit-library-import' )
423 ) {
424 throw new \Error( esc_html__( 'Invalid kit library nonce', 'elementor' ) );
425 }
426
427 $file_url = $_POST['e_import_file'];
428
429 if ( ! filter_var( $file_url, FILTER_VALIDATE_URL ) || 0 !== strpos( $file_url, 'http' ) ) {
430 throw new \Error( esc_html__( 'Invalid URL', 'elementor' ) );
431 }
432
433 $remote_zip_request = wp_remote_get( $file_url );
434
435 if ( is_wp_error( $remote_zip_request ) ) {
436 throw new \Error( $remote_zip_request->get_error_message() );
437 }
438
439 if ( 200 !== $remote_zip_request['response']['code'] ) {
440 throw new \Error( $remote_zip_request['response']['message'] );
441 }
442
443 $file_name = Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' );
444 $referrer = static::REFERRER_KIT_LIBRARY;
445 } else {
446 // PHPCS - Already validated in caller function.
447 $file_name = $_FILES['e_import_file']['tmp_name']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
448 $referrer = static::REFERRER_LOCAL;
449 }
450
451 $uploaded_kit = $this->upload_kit( $file_name, $referrer );
452 $session_dir = $uploaded_kit['session'];
453 $manifest = $uploaded_kit['manifest'];
454 $conflicts = $uploaded_kit['conflicts'];
455
456 if ( ! empty( $file_url ) ) {
457 Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) );
458 }
459
460 if ( isset( $manifest['plugins'] ) && ! current_user_can( 'install_plugins' ) ) {
461 throw new \Error( static::PERMISSIONS_ERROR_KEY );
462 }
463
464 $result = [
465 'session' => $session_dir,
466 'manifest' => $manifest,
467 ];
468
469 if ( ! empty( $conflicts ) ) {
470 $result['conflicts'] = $conflicts;
471 } else {
472 // Moved into the IE process \Elementor\App\Modules\ImportExport\Processes\Import::get_default_settings_conflicts
473 // TODO: remove in 3.10.0
474 $result = apply_filters( 'elementor/import/stage_1/result', $result );
475 }
476
477 wp_send_json_success( $result );
478 }
479
480 /**
481 * Handle import kit ajax request.
482 */
483 private function handle_import_kit() {
484 // PHPCS - Already validated in caller function
485 $settings = json_decode( stripslashes( $_POST['data'] ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
486 $tmp_folder_id = $settings['session'];
487
488 $import = $this->import_kit( $tmp_folder_id, $settings );
489
490 // get_settings_config() added manually because the frontend Ajax request doesn't trigger the get_init_settings().
491 $import['configData'] = $this->get_config_data();
492
493 wp_send_json_success( $import );
494 }
495
496 /**
497 * Handle export kit ajax request.
498 */
499 private function handle_export_kit() {
500 // PHPCS - Already validated in caller function
501 $settings = json_decode( stripslashes( $_POST['data'] ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
502 $export = $this->export_kit( $settings );
503
504 $file_name = $export['file_name'];
505 $file = ElementorUtils::file_get_contents( $file_name );
506
507 if ( ! $file ) {
508 throw new \Error( esc_html__( 'Could not read the exported file', 'elementor' ) );
509 }
510
511 Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) );
512
513 $result = [
514 'manifest' => $export['manifest'],
515 'file' => base64_encode( $file ),
516 ];
517
518 wp_send_json_success( $result );
519 }
520
521 /**
522 * Get config data that will be exposed to the frontend.
523 */
524 private function get_config_data() {
525 $export_nonce = wp_create_nonce( 'elementor_export' );
526 $export_url = add_query_arg( [ '_nonce' => $export_nonce ], Plugin::$instance->app->get_base_url() );
527
528 return [
529 'exportURL' => $export_url,
530 'summaryTitles' => $this->get_summary_titles(),
531 'builtinWpPostTypes' => ImportExportUtils::get_builtin_wp_post_types(),
532 'elementorPostTypes' => ImportExportUtils::get_elementor_post_types(),
533 'isUnfilteredFilesEnabled' => Uploads_Manager::are_unfiltered_uploads_enabled(),
534 'elementorHomePageUrl' => $this->get_elementor_home_page_url(),
535 'recentlyEditedElementorPageUrl' => $this->get_recently_edited_elementor_page_url(),
536 ];
537 }
538
539 /**
540 * Get labels of Elementor document types, Elementor Post types, WordPress Post types and Custom Post types.
541 */
542 private function get_summary_titles() {
543 $summary_titles = [];
544
545 $document_types = Plugin::$instance->documents->get_document_types();
546
547 foreach ( $document_types as $name => $document_type ) {
548 $summary_titles['templates'][ $name ] = [
549 'single' => $document_type::get_title(),
550 'plural' => $document_type::get_plural_title(),
551 ];
552 }
553
554 $elementor_post_types = ImportExportUtils::get_elementor_post_types();
555 $wp_builtin_post_types = ImportExportUtils::get_builtin_wp_post_types();
556 $post_types = array_merge( $elementor_post_types, $wp_builtin_post_types );
557
558 foreach ( $post_types as $post_type ) {
559 $post_type_object = get_post_type_object( $post_type );
560
561 $summary_titles['content'][ $post_type ] = [
562 'single' => $post_type_object->labels->singular_name,
563 'plural' => $post_type_object->label,
564 ];
565 }
566
567 $custom_post_types = ImportExportUtils::get_registered_cpt_names();
568 if ( ! empty( $custom_post_types ) ) {
569 foreach ( $custom_post_types as $custom_post_type ) {
570
571 $custom_post_types_object = get_post_type_object( $custom_post_type );
572 // CPT data appears in two arrays:
573 // 1. content object: in order to show the export summary when completed in getLabel function
574 $summary_titles['content'][ $custom_post_type ] = [
575 'single' => $custom_post_types_object->labels->singular_name,
576 'plural' => $custom_post_types_object->label,
577 ];
578
579 // 2. customPostTypes object: in order to actually export the data
580 $summary_titles['content']['customPostTypes'][ $custom_post_type ] = [
581 'single' => $custom_post_types_object->labels->singular_name,
582 'plural' => $custom_post_types_object->label,
583 ];
584 }
585 }
586
587 $active_kit = Plugin::$instance->kits_manager->get_active_kit();
588
589 foreach ( $active_kit->get_tabs() as $key => $tab ) {
590 $summary_titles['site-settings'][ $key ] = $tab->get_title();
591 }
592
593 return $summary_titles;
594 }
595
596 public function should_show_revert_section( $last_imported_kit ) {
597 if ( empty( $last_imported_kit ) ) {
598 return false;
599 }
600
601 // TODO: BC - remove in the future
602 // The 'templates' runner was in core and moved to the Pro plugin. (Part of it still exits in the Core for BC)
603 // The runner that is in the core version is missing the revert functionality,
604 // therefore we shouldn't display the revert section if the import process done with the core version.
605 $is_import_templates_ran = isset( $last_imported_kit['runners']['templates'] );
606 if ( $this->has_pro() && $is_import_templates_ran ) {
607 $has_imported_templates = ! empty( $last_imported_kit['runners']['templates'] );
608
609 return $has_imported_templates;
610 }
611
612 return true;
613 }
614
615 public function has_pro(): bool {
616 return ElementorUtils::has_pro();
617 }
618
619 private function get_elementor_editor_home_page_url() {
620 if ( 'page' !== get_option( 'show_on_front' ) ) {
621 return '';
622 }
623
624 $frontpage_id = get_option( 'page_on_front' );
625
626 return $this->get_elementor_editor_page_url( $frontpage_id );
627 }
628
629 private function get_elementor_home_page_url() {
630 if ( 'page' !== get_option( 'show_on_front' ) ) {
631 return '';
632 }
633
634 $frontpage_id = get_option( 'page_on_front' );
635
636 return $this->get_elementor_page_url( $frontpage_id );
637 }
638
639 private function get_recently_edited_elementor_page_url() {
640 $query = ElementorUtils::get_recently_edited_posts_query( [ 'posts_per_page' => 1 ] );
641
642 if ( ! isset( $query->post ) ) {
643 return '';
644 }
645
646 return $this->get_elementor_page_url( $query->post->ID );
647 }
648
649 private function get_recently_edited_elementor_editor_page_url() {
650 $query = ElementorUtils::get_recently_edited_posts_query( [ 'posts_per_page' => 1 ] );
651
652 if ( ! isset( $query->post ) ) {
653 return '';
654 }
655
656 return $this->get_elementor_editor_page_url( $query->post->ID );
657 }
658
659 private function get_elementor_document( $page_id ) {
660 $document = Plugin::$instance->documents->get( $page_id );
661
662 if ( ! $document || ! $document->is_built_with_elementor() ) {
663 return false;
664 }
665
666 return $document;
667 }
668
669 private function get_elementor_page_url( $page_id ) {
670 $document = $this->get_elementor_document( $page_id );
671
672 return $document ? $document->get_preview_url() : '';
673 }
674
675 private function get_elementor_editor_page_url( $page_id ) {
676 $document = $this->get_elementor_document( $page_id );
677
678 return $document ? $document->get_edit_url() : '';
679 }
680 }
681