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

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