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

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

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