PluginProbe
Elementor Website Builder – more than just a page builder / 3.9.1
Elementor Website Builder – more than just a page builder v3.9.1
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 / core / admin / admin.php

admin.php in Elementor Website Builder – more than just a page builder 3.9.1, at core/admin/admin.php

812 lines 24.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Admin;
3
4 use Elementor\Api;
5 use Elementor\Beta_Testers;
6 use Elementor\Core\Admin\Menu\Main as MainMenu;
7 use Elementor\App\Modules\Onboarding\Module as Onboarding_Module;
8 use Elementor\Core\Base\App;
9 use Elementor\Core\Upgrade\Manager as Upgrade_Manager;
10 use Elementor\Core\Utils\Collection;
11 use Elementor\Plugin;
12 use Elementor\Settings;
13 use Elementor\User;
14 use Elementor\Utils;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 class Admin extends App {
21
22 private $menus = [];
23
24 /**
25 * Get module name.
26 *
27 * Retrieve the module name.
28 *
29 * @since 2.3.0
30 * @access public
31 *
32 * @return string Module name.
33 */
34 public function get_name() {
35 return 'admin';
36 }
37
38 /**
39 * @since 2.2.0
40 * @access public
41 */
42 public function maybe_redirect_to_getting_started() {
43 if ( ! get_transient( 'elementor_activation_redirect' ) ) {
44 return;
45 }
46
47 if ( wp_doing_ajax() ) {
48 return;
49 }
50
51 delete_transient( 'elementor_activation_redirect' );
52
53 if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
54 return;
55 }
56
57 $already_had_onboarding = get_option( Onboarding_Module::ONBOARDING_OPTION );
58
59 // Get the latest installation from Elementor's Install log in the DB.
60 $latest_install = key( Upgrade_Manager::get_installs_history() );
61
62 if ( ! empty( $latest_install ) ) {
63 $is_new_install = version_compare( $latest_install, '3.6.0-beta', '>=' );
64 } else {
65 // If `$latest_install` is not set, Elementor was never installed on this site.
66 $is_new_install = true;
67 }
68
69 if ( $already_had_onboarding || ! $is_new_install ) {
70 return;
71 }
72
73 wp_safe_redirect( admin_url( 'admin.php?page=elementor-app#onboarding' ) );
74
75 exit;
76 }
77
78 /**
79 * Enqueue admin scripts.
80 *
81 * Registers all the admin scripts and enqueues them.
82 *
83 * Fired by `admin_enqueue_scripts` action.
84 *
85 * @since 1.0.0
86 * @access public
87 */
88 public function enqueue_scripts() {
89 wp_register_script(
90 'elementor-admin-modules',
91 $this->get_js_assets_url( 'admin-modules' ),
92 [],
93 ELEMENTOR_VERSION,
94 true
95 );
96
97 wp_register_script(
98 'elementor-admin',
99 $this->get_js_assets_url( 'admin' ),
100 [
101 'elementor-common',
102 'elementor-admin-modules',
103 ],
104 ELEMENTOR_VERSION,
105 true
106 );
107
108 wp_enqueue_script( 'elementor-admin' );
109
110 $this->print_config();
111 }
112
113 /**
114 * Enqueue admin styles.
115 *
116 * Registers all the admin styles and enqueues them.
117 *
118 * Fired by `admin_enqueue_scripts` action.
119 *
120 * @since 1.0.0
121 * @access public
122 */
123 public function enqueue_styles() {
124 $direction_suffix = is_rtl() ? '-rtl' : '';
125
126 wp_register_style(
127 'elementor-admin',
128 $this->get_css_assets_url( 'admin' . $direction_suffix ),
129 [
130 'elementor-common',
131 ],
132 ELEMENTOR_VERSION
133 );
134
135 wp_enqueue_style( 'elementor-admin' );
136
137 // It's for upgrade notice.
138 // TODO: enqueue this just if needed.
139 add_thickbox();
140 }
141
142 /**
143 * Print switch mode button.
144 *
145 * Adds a switch button in post edit screen (which has cpt support). To allow
146 * the user to switch from the native WordPress editor to Elementor builder.
147 *
148 * Fired by `edit_form_after_title` action.
149 *
150 * @since 1.0.0
151 * @access public
152 *
153 * @param \WP_Post $post The current post object.
154 */
155 public function print_switch_mode_button( $post ) {
156 // Exit if Gutenberg are active.
157 if ( did_action( 'enqueue_block_editor_assets' ) ) {
158 return;
159 }
160
161 $document = Plugin::$instance->documents->get( $post->ID );
162
163 if ( ! $document || ! $document->is_editable_by_current_user() ) {
164 return;
165 }
166
167 wp_nonce_field( basename( __FILE__ ), '_elementor_edit_mode_nonce' );
168 ?>
169 <div id="elementor-switch-mode">
170 <input id="elementor-switch-mode-input" type="hidden" name="_elementor_post_mode" value="<?php echo esc_attr( $document->is_built_with_elementor() ); ?>" />
171 <button id="elementor-switch-mode-button" type="button" class="button button-primary button-hero">
172 <span class="elementor-switch-mode-on">
173 <i class="eicon-arrow-<?php echo ( is_rtl() ) ? 'right' : 'left'; ?>" aria-hidden="true"></i>
174 <?php echo esc_html__( 'Back to WordPress Editor', 'elementor' ); ?>
175 </span>
176 <span class="elementor-switch-mode-off">
177 <i class="eicon-elementor-square" aria-hidden="true"></i>
178 <?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?>
179 </span>
180 </button>
181 </div>
182 <div id="elementor-editor">
183 <a id="elementor-go-to-edit-page-link" href="<?php echo esc_url( $document->get_edit_url() ); ?>">
184 <div id="elementor-editor-button" class="button button-primary button-hero">
185 <i class="eicon-elementor-square" aria-hidden="true"></i>
186 <?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?>
187 </div>
188 <div class="elementor-loader-wrapper">
189 <div class="elementor-loader">
190 <div class="elementor-loader-boxes">
191 <div class="elementor-loader-box"></div>
192 <div class="elementor-loader-box"></div>
193 <div class="elementor-loader-box"></div>
194 <div class="elementor-loader-box"></div>
195 </div>
196 </div>
197 <div class="elementor-loading-title"><?php echo esc_html__( 'Loading', 'elementor' ); ?></div>
198 </div>
199 </a>
200 </div>
201 <?php
202 }
203
204 /**
205 * Save post.
206 *
207 * Flag the post mode when the post is saved.
208 *
209 * Fired by `save_post` action.
210 *
211 * @since 1.0.0
212 * @access public
213 *
214 * @param int $post_id Post ID.
215 */
216 public function save_post( $post_id ) {
217 if ( ! isset( $_POST['_elementor_edit_mode_nonce'] ) || ! wp_verify_nonce( $_POST['_elementor_edit_mode_nonce'], basename( __FILE__ ) ) ) {
218 return;
219 }
220
221 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
222 return;
223 }
224
225 Plugin::$instance->documents->get( $post_id )->set_is_built_with_elementor( ! empty( $_POST['_elementor_post_mode'] ) );
226 }
227
228 /**
229 * Add Elementor post state.
230 *
231 * Adds a new "Elementor" post state to the post table.
232 *
233 * Fired by `display_post_states` filter.
234 *
235 * @since 1.8.0
236 * @access public
237 *
238 * @param array $post_states An array of post display states.
239 * @param \WP_Post $post The current post object.
240 *
241 * @return array A filtered array of post display states.
242 */
243 public function add_elementor_post_state( $post_states, $post ) {
244 $document = Plugin::$instance->documents->get( $post->ID );
245
246 if ( $document && $document->is_built_with_elementor() && $document->is_editable_by_current_user() ) {
247 $post_states['elementor'] = esc_html__( 'Elementor', 'elementor' );
248 }
249
250 return $post_states;
251 }
252
253 /**
254 * Body status classes.
255 *
256 * Adds CSS classes to the admin body tag.
257 *
258 * Fired by `admin_body_class` filter.
259 *
260 * @since 1.0.0
261 * @access public
262 *
263 * @param string $classes Space-separated list of CSS classes.
264 *
265 * @return string Space-separated list of CSS classes.
266 */
267 public function body_status_classes( $classes ) {
268 global $pagenow;
269
270 if ( in_array( $pagenow, [ 'post.php', 'post-new.php' ], true ) && Utils::is_post_support() ) {
271 $post = get_post();
272
273 $document = Plugin::$instance->documents->get( $post->ID );
274
275 $mode_class = $document && $document->is_built_with_elementor() ? 'elementor-editor-active' : 'elementor-editor-inactive';
276
277 $classes .= ' ' . $mode_class;
278 }
279
280 return $classes;
281 }
282
283 /**
284 * Plugin action links.
285 *
286 * Adds action links to the plugin list table
287 *
288 * Fired by `plugin_action_links` filter.
289 *
290 * @since 1.0.0
291 * @access public
292 *
293 * @param array $links An array of plugin action links.
294 *
295 * @return array An array of plugin action links.
296 */
297 public function plugin_action_links( $links ) {
298 $settings_link = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=' . Settings::PAGE_ID ), esc_html__( 'Settings', 'elementor' ) );
299
300 array_unshift( $links, $settings_link );
301
302 $links['go_pro'] = sprintf( '<a href="%1$s" target="_blank" class="elementor-plugins-gopro">%2$s</a>', 'https://go.elementor.com/go-pro-wp-plugins/', esc_html__( 'Get Elementor Pro', 'elementor' ) );
303
304 return $links;
305 }
306
307 /**
308 * Plugin row meta.
309 *
310 * Adds row meta links to the plugin list table
311 *
312 * Fired by `plugin_row_meta` filter.
313 *
314 * @since 1.1.4
315 * @access public
316 *
317 * @param array $plugin_meta An array of the plugin's metadata, including
318 * the version, author, author URI, and plugin URI.
319 * @param string $plugin_file Path to the plugin file, relative to the plugins
320 * directory.
321 *
322 * @return array An array of plugin row meta links.
323 */
324 public function plugin_row_meta( $plugin_meta, $plugin_file ) {
325 if ( ELEMENTOR_PLUGIN_BASE === $plugin_file ) {
326 $row_meta = [
327 'docs' => '<a href="https://go.elementor.com/docs-admin-plugins/" aria-label="' . esc_attr( esc_html__( 'View Elementor Documentation', 'elementor' ) ) . '" target="_blank">' . esc_html__( 'Docs & FAQs', 'elementor' ) . '</a>',
328 'ideo' => '<a href="https://go.elementor.com/yt-admin-plugins/" aria-label="' . esc_attr( esc_html__( 'View Elementor Video Tutorials', 'elementor' ) ) . '" target="_blank">' . esc_html__( 'Video Tutorials', 'elementor' ) . '</a>',
329 ];
330
331 $plugin_meta = array_merge( $plugin_meta, $row_meta );
332 }
333
334 return $plugin_meta;
335 }
336
337 /**
338 * Admin footer text.
339 *
340 * Modifies the "Thank you" text displayed in the admin footer.
341 *
342 * Fired by `admin_footer_text` filter.
343 *
344 * @since 1.0.0
345 * @access public
346 *
347 * @param string $footer_text The content that will be printed.
348 *
349 * @return string The content that will be printed.
350 */
351 public function admin_footer_text( $footer_text ) {
352 $current_screen = get_current_screen();
353 $is_elementor_screen = ( $current_screen && false !== strpos( $current_screen->id, 'elementor' ) );
354
355 if ( $is_elementor_screen ) {
356 $footer_text = sprintf(
357 /* translators: 1: Elementor, 2: Link to plugin review */
358 __( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'elementor' ),
359 '<strong>' . esc_html__( 'Elementor', 'elementor' ) . '</strong>',
360 '<a href="https://go.elementor.com/admin-review/" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
361 );
362 }
363
364 return $footer_text;
365 }
366
367 /**
368 * Register dashboard widgets.
369 *
370 * Adds a new Elementor widgets to WordPress dashboard.
371 *
372 * Fired by `wp_dashboard_setup` action.
373 *
374 * @since 1.9.0
375 * @access public
376 */
377 public function register_dashboard_widgets() {
378 wp_add_dashboard_widget( 'e-dashboard-overview', esc_html__( 'Elementor Overview', 'elementor' ), [ $this, 'elementor_dashboard_overview_widget' ] );
379
380 // Move our widget to top.
381 global $wp_meta_boxes;
382
383 $dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
384 $ours = [
385 'e-dashboard-overview' => $dashboard['e-dashboard-overview'],
386 ];
387
388 $wp_meta_boxes['dashboard']['normal']['core'] = array_merge( $ours, $dashboard ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
389 }
390
391 /**
392 * Elementor dashboard widget.
393 *
394 * Displays the Elementor dashboard widget.
395 *
396 * Fired by `wp_add_dashboard_widget` function.
397 *
398 * @since 1.9.0
399 * @access public
400 */
401 public function elementor_dashboard_overview_widget() {
402 $elementor_feed = Api::get_feed_data();
403 $recently_edited_query = Utils::get_recently_edited_posts_query();
404
405 if ( User::is_current_user_can_edit_post_type( 'page' ) ) {
406 $create_new_label = esc_html__( 'Create New Page', 'elementor' );
407 $create_new_post_type = 'page';
408 } elseif ( User::is_current_user_can_edit_post_type( 'post' ) ) {
409 $create_new_label = esc_html__( 'Create New Post', 'elementor' );
410 $create_new_post_type = 'post';
411 }
412 ?>
413 <div class="e-dashboard-widget">
414 <div class="e-overview__header">
415 <div class="e-overview__logo"><div class="e-logo-wrapper"><i class="eicon-elementor"></i></div></div>
416 <div class="e-overview__versions">
417 <span class="e-overview__version"><?php echo esc_html__( 'Elementor', 'elementor' ); ?> v<?php echo ELEMENTOR_VERSION; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
418 <?php
419 /**
420 * Elementor dashboard widget after the version.
421 *
422 * Fires after Elementor version display in the dashboard widget.
423 *
424 * @since 1.9.0
425 */
426 do_action( 'elementor/admin/dashboard_overview_widget/after_version' );
427 ?>
428 </div>
429 <?php if ( ! empty( $create_new_post_type ) ) : ?>
430 <div class="e-overview__create">
431 <a href="<?php echo esc_url( Plugin::$instance->documents->get_create_new_post_url( $create_new_post_type ) ); ?>" class="button"><span aria-hidden="true" class="dashicons dashicons-plus"></span> <?php echo esc_html( $create_new_label ); ?></a>
432 </div>
433 <?php endif; ?>
434 </div>
435 <?php if ( $recently_edited_query->have_posts() ) : ?>
436 <div class="e-overview__recently-edited">
437 <h3 class="e-heading e-divider_bottom"><?php echo esc_html__( 'Recently Edited', 'elementor' ); ?></h3>
438 <ul class="e-overview__posts">
439 <?php
440 while ( $recently_edited_query->have_posts() ) :
441 $recently_edited_query->the_post();
442 $document = Plugin::$instance->documents->get( get_the_ID() );
443
444 $date = date_i18n( _x( 'M jS', 'Dashboard Overview Widget Recently Date', 'elementor' ), get_the_modified_time( 'U' ) );
445 ?>
446 <li class="e-overview__post">
447 <a href="<?php echo esc_attr( $document->get_edit_url() ); ?>" class="e-overview__post-link"><?php echo esc_html( get_the_title() ); ?> <span class="dashicons dashicons-edit"></span></a> <span><?php echo $date; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>, <?php the_modified_time(); ?></span>
448 </li>
449 <?php endwhile; ?>
450 </ul>
451 </div>
452 <?php endif; ?>
453 <?php if ( ! empty( $elementor_feed ) ) : ?>
454 <div class="e-overview__feed">
455 <h3 class="e-heading e-divider_bottom"><?php echo esc_html__( 'News & Updates', 'elementor' ); ?></h3>
456 <ul class="e-overview__posts">
457 <?php foreach ( $elementor_feed as $feed_item ) : ?>
458 <li class="e-overview__post">
459 <a href="<?php echo esc_url( $feed_item['url'] ); ?>" class="e-overview__post-link" target="_blank">
460 <?php if ( ! empty( $feed_item['badge'] ) ) : ?>
461 <span class="e-overview__badge"><?php echo esc_html( $feed_item['badge'] ); ?></span>
462 <?php endif; ?>
463 <?php echo esc_html( $feed_item['title'] ); ?>
464 </a>
465 <p class="e-overview__post-description"><?php echo esc_html( $feed_item['excerpt'] ); ?></p>
466 </li>
467 <?php endforeach; ?>
468 </ul>
469 </div>
470 <?php endif; ?>
471 <div class="e-overview__footer e-divider_top">
472 <ul>
473 <?php foreach ( $this->get_dashboard_overview_widget_footer_actions() as $action_id => $action ) : ?>
474 <li class="e-overview__<?php echo esc_attr( $action_id ); ?>"><a href="<?php echo esc_attr( $action['link'] ); ?>" target="_blank"><?php echo esc_html( $action['title'] ); ?> <span class="screen-reader-text"><?php echo esc_html__( '(opens in a new window)', 'elementor' ); ?></span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></li>
475 <?php endforeach; ?>
476 </ul>
477 </div>
478 </div>
479 <?php
480 }
481
482 /**
483 * Get elementor dashboard overview widget footer actions.
484 *
485 * Retrieves the footer action links displayed in elementor dashboard widget.
486 *
487 * @since 1.9.0
488 * @access private
489 */
490 private function get_dashboard_overview_widget_footer_actions() {
491 $base_actions = [
492 'blog' => [
493 'title' => esc_html__( 'Blog', 'elementor' ),
494 'link' => 'https://go.elementor.com/overview-widget-blog/',
495 ],
496 'help' => [
497 'title' => esc_html__( 'Help', 'elementor' ),
498 'link' => 'https://go.elementor.com/overview-widget-docs/',
499 ],
500 ];
501
502 $additions_actions = [
503 'go-pro' => [
504 'title' => esc_html__( 'Upgrade', 'elementor' ),
505 'link' => 'https://go.elementor.com/go-pro-wp-overview-widget/',
506 ],
507 ];
508
509 // Visible to all core users when Elementor Pro is not installed.
510 $additions_actions['find_an_expert'] = [
511 'title' => esc_html__( 'Find an Expert', 'elementor' ),
512 'link' => 'https://go.elementor.com/go-pro-find-an-expert/',
513 ];
514
515 /**
516 * Dashboard widget footer actions.
517 *
518 * Filters the additions actions displayed in Elementor dashboard widget.
519 *
520 * Developers can add new action links to Elementor dashboard widget
521 * footer using this filter.
522 *
523 * @since 1.9.0
524 *
525 * @param array $additions_actions Elementor dashboard widget footer actions.
526 */
527 $additions_actions = apply_filters( 'elementor/admin/dashboard_overview_widget/footer_actions', $additions_actions );
528
529 $actions = $base_actions + $additions_actions;
530
531 return $actions;
532 }
533
534 /**
535 * Admin action new post.
536 *
537 * When a new post action is fired the title is set to 'Elementor' and the post ID.
538 *
539 * Fired by `admin_action_elementor_new_post` action.
540 *
541 * @since 1.9.0
542 * @access public
543 */
544 public function admin_action_new_post() {
545 check_admin_referer( 'elementor_action_new_post' );
546
547 if ( empty( $_GET['post_type'] ) ) {
548 $post_type = 'post';
549 } else {
550 $post_type = $_GET['post_type'];
551 }
552
553 if ( ! User::is_current_user_can_edit_post_type( $post_type ) ) {
554 return;
555 }
556
557 if ( empty( $_GET['template_type'] ) ) {
558 $type = 'post';
559 } else {
560 $type = sanitize_text_field( $_GET['template_type'] );
561 }
562
563 $post_data = isset( $_GET['post_data'] ) ? $_GET['post_data'] : [];
564
565 /**
566 * Create new post meta data.
567 *
568 * Filters the meta data of any new post created.
569 *
570 * @since 2.0.0
571 *
572 * @param array $meta Post meta data.
573 */
574 $meta = [];
575
576 if ( isset( $_GET['meta'] ) && is_array( $_GET['meta'] ) ) {
577 $meta = array_map( 'sanitize_text_field', $_GET['meta'] );
578 }
579
580 $meta = apply_filters( 'elementor/admin/create_new_post/meta', $meta );
581
582 $post_data['post_type'] = $post_type;
583
584 $document = Plugin::$instance->documents->create( $type, $post_data, $meta );
585
586 if ( is_wp_error( $document ) ) {
587 wp_die( $document ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
588 }
589
590 wp_redirect( $document->get_edit_url() );
591
592 die;
593 }
594
595 /**
596 * @since 2.3.0
597 * @access public
598 */
599 public function add_new_template_template() {
600 Plugin::$instance->common->add_template( ELEMENTOR_PATH . 'includes/admin-templates/new-template.php' );
601 }
602
603 /**
604 * @access public
605 */
606 public function enqueue_new_template_scripts() {
607 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
608
609 wp_enqueue_script(
610 'elementor-new-template',
611 ELEMENTOR_ASSETS_URL . 'js/new-template' . $suffix . '.js',
612 [],
613 ELEMENTOR_VERSION,
614 true
615 );
616 }
617
618 /**
619 * @since 2.6.0
620 * @access public
621 */
622 public function add_beta_tester_template() {
623 Plugin::$instance->common->add_template( ELEMENTOR_PATH . 'includes/admin-templates/beta-tester.php' );
624 }
625
626 /**
627 * @access public
628 */
629 public function enqueue_beta_tester_scripts() {
630 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
631
632 wp_enqueue_script(
633 'elementor-beta-tester',
634 ELEMENTOR_ASSETS_URL . 'js/beta-tester' . $suffix . '.js',
635 [],
636 ELEMENTOR_VERSION,
637 true
638 );
639 }
640
641 /**
642 * @access public
643 */
644 public function init_new_template() {
645 if ( 'edit-elementor_library' !== get_current_screen()->id ) {
646 return;
647 }
648
649 // Allow plugins to add their templates on admin_head.
650 add_action( 'admin_head', [ $this, 'add_new_template_template' ] );
651 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_new_template_scripts' ] );
652 }
653
654 public function version_update_warning( $current_version, $new_version ) {
655 $current_version_minor_part = explode( '.', $current_version )[1];
656 $new_version_minor_part = explode( '.', $new_version )[1];
657
658 if ( $current_version_minor_part === $new_version_minor_part ) {
659 return;
660 }
661 ?>
662 <hr class="e-major-update-warning__separator" />
663 <div class="e-major-update-warning">
664 <div class="e-major-update-warning__icon">
665 <i class="eicon-info-circle"></i>
666 </div>
667 <div>
668 <div class="e-major-update-warning__title">
669 <?php echo esc_html__( 'Heads up, Please backup before upgrade!', 'elementor' ); ?>
670 </div>
671 <div class="e-major-update-warning__message">
672 <?php
673 printf(
674 /* translators: %1$s Link open tag, %2$s: Link close tag. */
675 esc_html__( 'The latest update includes some substantial changes across different areas of the plugin. We highly recommend you %1$sbackup your site before upgrading%2$s, and make sure you first update in a staging environment', 'elementor' ),
676 '<a href="https://go.elementor.com/wp-dash-update-backup/">',
677 '</a>'
678 );
679 ?>
680 </div>
681 </div>
682 </div>
683 <?php
684 }
685
686 /**
687 * @access public
688 */
689 public function init_beta_tester( $current_screen ) {
690 if ( ( 'toplevel_page_elementor' === $current_screen->base ) || 'elementor_page_elementor-tools' === $current_screen->id ) {
691 add_action( 'admin_head', [ $this, 'add_beta_tester_template' ] );
692 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_beta_tester_scripts' ] );
693 }
694 }
695
696 /**
697 * Admin constructor.
698 *
699 * Initializing Elementor in WordPress admin.
700 *
701 * @since 1.0.0
702 * @access public
703 */
704 public function __construct() {
705 Plugin::$instance->init_common();
706
707 $this->add_component( 'feedback', new Feedback() );
708 $this->add_component( 'admin-notices', new Admin_Notices() );
709
710 if ( Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) {
711 $this->register_menu();
712 }
713
714 add_action( 'admin_init', [ $this, 'maybe_redirect_to_getting_started' ] );
715
716 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
717 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] );
718
719 add_action( 'edit_form_after_title', [ $this, 'print_switch_mode_button' ] );
720 add_action( 'save_post', [ $this, 'save_post' ] );
721
722 add_filter( 'display_post_states', [ $this, 'add_elementor_post_state' ], 10, 2 );
723
724 add_filter( 'plugin_action_links_' . ELEMENTOR_PLUGIN_BASE, [ $this, 'plugin_action_links' ] );
725 add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 );
726
727 add_filter( 'admin_body_class', [ $this, 'body_status_classes' ] );
728 add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
729
730 // Register Dashboard Widgets.
731 add_action( 'wp_dashboard_setup', [ $this, 'register_dashboard_widgets' ] );
732
733 // Admin Actions
734 add_action( 'admin_action_elementor_new_post', [ $this, 'admin_action_new_post' ] );
735
736 add_action( 'current_screen', [ $this, 'init_new_template' ] );
737 add_action( 'current_screen', [ $this, 'init_beta_tester' ] );
738
739 add_action( 'in_plugin_update_message-' . ELEMENTOR_PLUGIN_BASE, function( $plugin_data ) {
740 $this->version_update_warning( ELEMENTOR_VERSION, $plugin_data['new_version'] );
741 } );
742 }
743
744 /**
745 * @since 2.3.0
746 * @access protected
747 */
748 protected function get_init_settings() {
749 $beta_tester_email = get_user_meta( get_current_user_id(), User::BETA_TESTER_META_KEY, true );
750 $elementor_beta = get_option( 'elementor_beta', 'no' );
751 $all_introductions = User::get_introduction_meta();
752 $beta_tester_signup_dismissed = array_key_exists( Beta_Testers::BETA_TESTER_SIGNUP, $all_introductions );
753
754 $settings = [
755 'home_url' => home_url(),
756 'settings_url' => Settings::get_url(),
757 'user' => [
758 'introduction' => User::get_introduction_meta(),
759 ],
760 'beta_tester' => [
761 'beta_tester_signup' => Beta_Testers::BETA_TESTER_SIGNUP,
762 'has_email' => $beta_tester_email,
763 'option_enabled' => 'no' !== $elementor_beta,
764 'signup_dismissed' => $beta_tester_signup_dismissed,
765 ],
766 'experiments' => $this->get_experiments(),
767 ];
768
769 /**
770 * Localize settings.
771 *
772 * Filters the initial localize settings in the admin.
773 *
774 * WordPress has it's own way to pass localized data from PHP (backend) to
775 * JS (frontend). Elementor uses this method to pass localize data in the
776 * admin. This hook can be used to add more localized settings in addition
777 * to the initial Elementor settings.
778 *
779 * @since 2.3.0
780 *
781 * @param array $settings Initial localize settings.
782 */
783 $settings = apply_filters( 'elementor/admin/localize_settings', $settings );
784
785 return $settings;
786 }
787
788 private function get_experiments() {
789 return ( new Collection( Plugin::$instance->experiments->get_features() ) )
790 ->map( function ( $experiment_data ) {
791 $dependencies = $experiment_data['dependencies'] ?? [];
792
793 $dependencies = ( new Collection( $dependencies ) )
794 ->map( function ( $dependency ) {
795 return $dependency->get_name();
796 } )->all();
797
798 return [
799 'name' => $experiment_data['name'],
800 'title' => $experiment_data['title'] ?? $experiment_data['name'],
801 'state' => $experiment_data['state'],
802 'default' => $experiment_data['default'],
803 'dependencies' => $dependencies,
804 ];
805 } )->all();
806 }
807
808 private function register_menu() {
809 $this->menus['main'] = new MainMenu();
810 }
811 }
812