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

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