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

admin.php in Elementor Website Builder – more than just a page builder 3.6.0-dev1, at trunk/core/admin/admin.php

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