PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.4
Elementor Website Builder – more than just a page builder v3.6.4
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 / editor / editor.php

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

965 lines 24.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Editor;
3
4 use Elementor\Api;
5 use Elementor\Core\Breakpoints\Breakpoint;
6 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
7 use Elementor\Core\Common\Modules\Ajax\Module;
8 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
9 use Elementor\Core\Debug\Loading_Inspection_Manager;
10 use Elementor\Core\Files\Uploads_Manager;
11 use Elementor\Core\Schemes\Manager as Schemes_Manager;
12 use Elementor\Core\Settings\Manager as SettingsManager;
13 use Elementor\Icons_Manager;
14 use Elementor\Plugin;
15 use Elementor\Settings;
16 use Elementor\Shapes;
17 use Elementor\TemplateLibrary\Source_Local;
18 use Elementor\Tools;
19 use Elementor\User;
20 use Elementor\Utils;
21 use Elementor\Core\Editor\Data;
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit; // Exit if accessed directly.
25 }
26
27 /**
28 * Elementor editor.
29 *
30 * Elementor editor handler class is responsible for initializing Elementor
31 * editor and register all the actions needed to display the editor.
32 *
33 * @since 1.0.0
34 */
35 class Editor {
36
37 /**
38 * User capability required to access Elementor editor.
39 */
40 const EDITING_CAPABILITY = 'edit_posts';
41
42 /**
43 * Post ID.
44 *
45 * Holds the ID of the current post being edited.
46 *
47 * @since 1.0.0
48 * @access private
49 *
50 * @var int Post ID.
51 */
52 private $post_id;
53
54 /**
55 * Whether the edit mode is active.
56 *
57 * Used to determine whether we are in edit mode.
58 *
59 * @since 1.0.0
60 * @access private
61 *
62 * @var bool Whether the edit mode is active.
63 */
64 private $is_edit_mode;
65
66 /**
67 * @var Notice_Bar
68 */
69 public $notice_bar;
70
71 /**
72 * Init.
73 *
74 * Initialize Elementor editor. Registers all needed actions to run Elementor,
75 * removes conflicting actions etc.
76 *
77 * Fired by `admin_action_elementor` action.
78 *
79 * @since 1.0.0
80 * @access public
81 *
82 * @param bool $die Optional. Whether to die at the end. Default is `true`.
83 */
84 public function init( $die = true ) {
85 if ( empty( $_REQUEST['post'] ) ) {
86 return;
87 }
88
89 $this->set_post_id( absint( $_REQUEST['post'] ) );
90
91 if ( ! $this->is_edit_mode( $this->post_id ) ) {
92 return;
93 }
94
95 // BC: From 2.9.0, the editor shouldn't handle the global post / current document.
96 // Use requested id and not the global in order to avoid conflicts with plugins that changes the global post.
97 query_posts( [
98 'p' => $this->post_id,
99 'post_type' => get_post_type( $this->post_id ),
100 ] );
101
102 Plugin::$instance->db->switch_to_post( $this->post_id );
103
104 $document = Plugin::$instance->documents->get( $this->post_id );
105
106 Plugin::$instance->documents->switch_to_document( $document );
107
108 // Change mode to Builder
109 $document->set_is_built_with_elementor( true );
110
111 // End BC.
112
113 Loading_Inspection_Manager::instance()->register_inspections();
114
115 // Send MIME Type header like WP admin-header.
116 @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
117
118 add_filter( 'show_admin_bar', '__return_false' );
119
120 // Remove all WordPress actions
121 remove_all_actions( 'wp_head' );
122 remove_all_actions( 'wp_print_styles' );
123 remove_all_actions( 'wp_print_head_scripts' );
124 remove_all_actions( 'wp_footer' );
125
126 // Handle `wp_head`
127 add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
128 add_action( 'wp_head', 'wp_print_styles', 8 );
129 add_action( 'wp_head', 'wp_print_head_scripts', 9 );
130 add_action( 'wp_head', 'wp_site_icon' );
131 add_action( 'wp_head', [ $this, 'editor_head_trigger' ], 30 );
132
133 // Handle `wp_footer`
134 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
135 add_action( 'wp_footer', 'wp_auth_check_html', 30 );
136 add_action( 'wp_footer', [ $this, 'wp_footer' ] );
137
138 // Handle `wp_enqueue_scripts`
139 remove_all_actions( 'wp_enqueue_scripts' );
140
141 // Also remove all scripts hooked into after_wp_tiny_mce.
142 remove_all_actions( 'after_wp_tiny_mce' );
143
144 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 999999 );
145 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], 999999 );
146
147 // Setup default heartbeat options
148 add_filter( 'heartbeat_settings', function( $settings ) {
149 $settings['interval'] = 15;
150 return $settings;
151 } );
152
153 // Tell to WP Cache plugins do not cache this request.
154 Utils::do_not_cache();
155
156 do_action( 'elementor/editor/init' );
157
158 $this->print_editor_template();
159
160 // From the action it's an empty string, from tests its `false`
161 if ( false !== $die ) {
162 die;
163 }
164 }
165
166 /**
167 * Retrieve post ID.
168 *
169 * Get the ID of the current post.
170 *
171 * @since 1.8.0
172 * @access public
173 *
174 * @return int Post ID.
175 */
176 public function get_post_id() {
177 return $this->post_id;
178 }
179
180 /**
181 * Redirect to new URL.
182 *
183 * Used as a fallback function for the old URL structure of Elementor page
184 * edit URL.
185 *
186 * Fired by `template_redirect` action.
187 *
188 * @since 1.6.0
189 * @access public
190 */
191 public function redirect_to_new_url() {
192 if ( ! isset( $_GET['elementor'] ) ) {
193 return;
194 }
195
196 $document = Plugin::$instance->documents->get( get_the_ID() );
197
198 if ( ! $document ) {
199 wp_die( esc_html__( 'Document not found.', 'elementor' ) );
200 }
201
202 if ( ! $document->is_editable_by_current_user() || ! $document->is_built_with_elementor() ) {
203 return;
204 }
205
206 wp_safe_redirect( $document->get_edit_url() );
207 die;
208 }
209
210 /**
211 * Whether the edit mode is active.
212 *
213 * Used to determine whether we are in the edit mode.
214 *
215 * @since 1.0.0
216 * @access public
217 *
218 * @param int $post_id Optional. Post ID. Default is `null`, the current
219 * post ID.
220 *
221 * @return bool Whether the edit mode is active.
222 */
223 public function is_edit_mode( $post_id = null ) {
224 if ( null !== $this->is_edit_mode ) {
225 return $this->is_edit_mode;
226 }
227
228 if ( empty( $post_id ) ) {
229 $post_id = $this->post_id;
230 }
231
232 $document = Plugin::$instance->documents->get( $post_id );
233
234 if ( ! $document || ! $document->is_editable_by_current_user() ) {
235 return false;
236 }
237
238 /** @var Module ajax */
239 $ajax_data = Plugin::$instance->common->get_component( 'ajax' )->get_current_action_data();
240
241 if ( ! empty( $ajax_data ) && 'get_document_config' === $ajax_data['action'] ) {
242 return true;
243 }
244
245 // Ajax request as Editor mode
246 $actions = [
247 'elementor',
248
249 // Templates
250 'elementor_get_templates',
251 'elementor_save_template',
252 'elementor_get_template',
253 'elementor_delete_template',
254 'elementor_import_template',
255 'elementor_library_direct_actions',
256 ];
257
258 if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions ) ) {
259 return true;
260 }
261
262 return false;
263 }
264
265 /**
266 * Lock post.
267 *
268 * Mark the post as currently being edited by the current user.
269 *
270 * @since 1.0.0
271 * @access public
272 *
273 * @param int $post_id The ID of the post being edited.
274 */
275 public function lock_post( $post_id ) {
276 if ( ! function_exists( 'wp_set_post_lock' ) ) {
277 require_once ABSPATH . 'wp-admin/includes/post.php';
278 }
279
280 wp_set_post_lock( $post_id );
281 }
282
283 /**
284 * Get locked user.
285 *
286 * Check what user is currently editing the post.
287 *
288 * @since 1.0.0
289 * @access public
290 *
291 * @param int $post_id The ID of the post being edited.
292 *
293 * @return \WP_User|false User information or false if the post is not locked.
294 */
295 public function get_locked_user( $post_id ) {
296 if ( ! function_exists( 'wp_check_post_lock' ) ) {
297 require_once ABSPATH . 'wp-admin/includes/post.php';
298 }
299
300 $locked_user = wp_check_post_lock( $post_id );
301 if ( ! $locked_user ) {
302 return false;
303 }
304
305 return get_user_by( 'id', $locked_user );
306 }
307
308 /**
309 * Print Editor Template.
310 *
311 * Include the wrapper template of the editor.
312 *
313 * @since 2.2.0
314 * @access public
315 */
316 public function print_editor_template() {
317 include ELEMENTOR_PATH . 'includes/editor-templates/editor-wrapper.php';
318 }
319
320 /**
321 * Enqueue scripts.
322 *
323 * Registers all the editor scripts and enqueues them.
324 *
325 * @since 1.0.0
326 * @access public
327 */
328 public function enqueue_scripts() {
329 remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 );
330
331 global $wp_styles, $wp_scripts;
332
333 $plugin = Plugin::$instance;
334
335 // Reset global variable
336 $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
337 $wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
338
339 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS ) ? '' : '.min';
340
341 wp_register_script(
342 'elementor-editor-modules',
343 ELEMENTOR_ASSETS_URL . 'js/editor-modules' . $suffix . '.js',
344 [
345 'elementor-common-modules',
346 ],
347 ELEMENTOR_VERSION,
348 true
349 );
350
351 wp_register_script(
352 'elementor-editor-document',
353 ELEMENTOR_ASSETS_URL . 'js/editor-document' . $suffix . '.js',
354 [
355 'elementor-common-modules',
356 ],
357 ELEMENTOR_VERSION,
358 true
359 );
360 // Hack for waypoint with editor mode.
361 wp_register_script(
362 'elementor-waypoints',
363 ELEMENTOR_ASSETS_URL . 'lib/waypoints/waypoints-for-editor.js',
364 [
365 'jquery',
366 ],
367 '4.0.2',
368 true
369 );
370
371 wp_register_script(
372 'perfect-scrollbar',
373 ELEMENTOR_ASSETS_URL . 'lib/perfect-scrollbar/js/perfect-scrollbar' . $suffix . '.js',
374 [],
375 '1.4.0',
376 true
377 );
378
379 wp_register_script(
380 'jquery-easing',
381 ELEMENTOR_ASSETS_URL . 'lib/jquery-easing/jquery-easing' . $suffix . '.js',
382 [
383 'jquery',
384 ],
385 '1.3.2',
386 true
387 );
388
389 wp_register_script(
390 'nprogress',
391 ELEMENTOR_ASSETS_URL . 'lib/nprogress/nprogress' . $suffix . '.js',
392 [],
393 '0.2.0',
394 true
395 );
396
397 wp_register_script(
398 'tipsy',
399 ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $suffix . '.js',
400 [
401 'jquery',
402 ],
403 '1.0.0',
404 true
405 );
406
407 wp_register_script(
408 'jquery-elementor-select2',
409 ELEMENTOR_ASSETS_URL . 'lib/e-select2/js/e-select2.full' . $suffix . '.js',
410 [
411 'jquery',
412 ],
413 '4.0.6-rc.1',
414 true
415 );
416
417 wp_register_script(
418 'flatpickr',
419 ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.js',
420 [
421 'jquery',
422 ],
423 '1.12.0',
424 true
425 );
426
427 wp_register_script(
428 'ace',
429 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js',
430 [],
431 '1.2.5',
432 true
433 );
434
435 wp_register_script(
436 'ace-language-tools',
437 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ext-language_tools.js',
438 [
439 'ace',
440 ],
441 '1.2.5',
442 true
443 );
444
445 wp_register_script(
446 'jquery-hover-intent',
447 ELEMENTOR_ASSETS_URL . 'lib/jquery-hover-intent/jquery-hover-intent' . $suffix . '.js',
448 [],
449 '1.0.0',
450 true
451 );
452
453 wp_register_script(
454 'nouislider',
455 ELEMENTOR_ASSETS_URL . 'lib/nouislider/nouislider' . $suffix . '.js',
456 [],
457 '13.0.0',
458 true
459 );
460
461 wp_register_script(
462 'pickr',
463 ELEMENTOR_ASSETS_URL . 'lib/pickr/pickr.min.js',
464 [],
465 '1.5.0',
466 true
467 );
468
469 wp_register_script(
470 'elementor-editor',
471 ELEMENTOR_ASSETS_URL . 'js/editor' . $suffix . '.js',
472 [
473 'elementor-common',
474 'elementor-editor-modules',
475 'elementor-editor-document',
476 'wp-auth-check',
477 'jquery-ui-sortable',
478 'jquery-ui-resizable',
479 'perfect-scrollbar',
480 'nprogress',
481 'tipsy',
482 'imagesloaded',
483 'heartbeat',
484 'jquery-elementor-select2',
485 'flatpickr',
486 'ace',
487 'ace-language-tools',
488 'jquery-hover-intent',
489 'nouislider',
490 'pickr',
491 'react',
492 'react-dom',
493 ],
494 ELEMENTOR_VERSION,
495 true
496 );
497
498 /**
499 * Before editor enqueue scripts.
500 *
501 * Fires before Elementor editor scripts are enqueued.
502 *
503 * @since 1.0.0
504 */
505 do_action( 'elementor/editor/before_enqueue_scripts' );
506
507 // Tweak for WP Admin menu icons
508 wp_print_styles( 'editor-buttons' );
509
510 $settings = SettingsManager::get_settings_managers_config();
511 // Moved to document since 2.9.0.
512 unset( $settings['page'] );
513
514 $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post_id );
515 $kits_manager = Plugin::$instance->kits_manager;
516
517 $page_title_selector = $kits_manager->get_current_settings( 'page_title_selector' );
518
519 $page_title_selector .= ', .elementor-page-title .elementor-heading-title';
520
521 $config = [
522 'initial_document' => $document->get_config(),
523 'version' => ELEMENTOR_VERSION,
524 'home_url' => home_url(),
525 'admin_settings_url' => admin_url( 'admin.php?page=' . Settings::PAGE_ID ),
526 'admin_tools_url' => admin_url( 'admin.php?page=' . Tools::PAGE_ID ),
527 'autosave_interval' => AUTOSAVE_INTERVAL,
528 'tabs' => $plugin->controls_manager->get_tabs(),
529 'controls' => $plugin->controls_manager->get_controls_data(),
530 'elements' => $plugin->elements_manager->get_element_types_config(),
531 'schemes' => [
532 'items' => $plugin->schemes_manager->get_registered_schemes_data(),
533 'enabled_schemes' => Schemes_Manager::get_enabled_schemes(),
534 ],
535 'globals' => [
536 'defaults_enabled' => [
537 'colors' => $kits_manager->is_custom_colors_enabled(),
538 'typography' => $kits_manager->is_custom_typography_enabled(),
539 ],
540 ],
541 'icons' => [
542 'libraries' => Icons_Manager::get_icon_manager_tabs_config(),
543 'goProURL' => Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=icon-library&utm_campaign=gopro&utm_medium=wp-dash' ),
544 ],
545 'fa4_to_fa5_mapping_url' => ELEMENTOR_ASSETS_URL . 'lib/font-awesome/migration/mapping.js',
546 'default_schemes' => $plugin->schemes_manager->get_schemes_defaults(),
547 'settings' => $settings,
548 'system_schemes' => $plugin->schemes_manager->get_system_schemes(),
549 'wp_editor' => $this->get_wp_editor_config(),
550 'settings_page_link' => Settings::get_url(),
551 'tools_page_link' => Tools::get_url(),
552 'elementor_site' => 'https://go.elementor.com/about-elementor/',
553 'docs_elementor_site' => 'https://go.elementor.com/docs/',
554 'help_the_content_url' => 'https://go.elementor.com/the-content-missing/',
555 'help_flexbox_bc_url' => 'https://go.elementor.com/flexbox-layout-bc/',
556 'elementPromotionURL' => 'https://go.elementor.com/go-pro-%s',
557 'dynamicPromotionURL' => 'https://go.elementor.com/go-pro-dynamic-tag',
558 'additional_shapes' => Shapes::get_additional_shapes_for_config(),
559 'user' => [
560 'restrictions' => $plugin->role_manager->get_user_restrictions_array(),
561 'is_administrator' => current_user_can( 'manage_options' ),
562 'introduction' => User::get_introduction_meta(),
563 ],
564 'preview' => [
565 'help_preview_error_url' => 'https://go.elementor.com/preview-not-loaded/',
566 'help_preview_http_error_url' => 'https://go.elementor.com/preview-not-loaded/#permissions',
567 'help_preview_http_error_500_url' => 'https://go.elementor.com/500-error/',
568 'debug_data' => Loading_Inspection_Manager::instance()->run_inspections(),
569 ],
570 'locale' => get_locale(),
571 'rich_editing_enabled' => filter_var( get_user_meta( get_current_user_id(), 'rich_editing', true ), FILTER_VALIDATE_BOOLEAN ),
572 'page_title_selector' => $page_title_selector,
573 'tinymceHasCustomConfig' => class_exists( 'Tinymce_Advanced' ) || class_exists( 'Advanced_Editor_Tools' ),
574 'inlineEditing' => Plugin::$instance->widgets_manager->get_inline_editing_config(),
575 'dynamicTags' => Plugin::$instance->dynamic_tags->get_config(),
576 'ui' => [
577 'darkModeStylesheetURL' => ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css',
578 'defaultGenericFonts' => $kits_manager->get_current_settings( 'default_generic_fonts' ),
579 ],
580 // Empty array for BC to avoid errors.
581 'i18n' => [],
582 // 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0
583 'responsive' => [
584 'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(),
585 'icons_map' => Plugin::$instance->breakpoints->get_responsive_icons_classes_map(),
586 ],
587 ];
588
589 if ( ! Utils::has_pro() && current_user_can( 'manage_options' ) ) {
590 $config['promotionWidgets'] = Api::get_promotion_widgets();
591 }
592
593 $this->bc_move_document_filters();
594
595 /**
596 * Localize editor settings.
597 *
598 * Filters the editor localized settings.
599 *
600 * @since 1.0.0
601 *
602 * @param array $config Editor configuration.
603 * @param int $post_id The ID of the current post being edited.
604 */
605 $config = apply_filters( 'elementor/editor/localize_settings', $config );
606
607 Utils::print_js_config( 'elementor-editor', 'ElementorConfig', $config );
608
609 wp_enqueue_script( 'elementor-editor' );
610
611 wp_set_script_translations( 'elementor-editor', 'elementor' );
612
613 $plugin->controls_manager->enqueue_control_scripts();
614
615 /**
616 * After editor enqueue scripts.
617 *
618 * Fires after Elementor editor scripts are enqueued.
619 *
620 * @since 1.0.0
621 */
622 do_action( 'elementor/editor/after_enqueue_scripts' );
623 }
624
625 /**
626 * Enqueue styles.
627 *
628 * Registers all the editor styles and enqueues them.
629 *
630 * @since 1.0.0
631 * @access public
632 */
633 public function enqueue_styles() {
634 /**
635 * Before editor enqueue styles.
636 *
637 * Fires before Elementor editor styles are enqueued.
638 *
639 * @since 1.0.0
640 */
641 do_action( 'elementor/editor/before_enqueue_styles' );
642
643 $suffix = Utils::is_script_debug() ? '' : '.min';
644
645 $direction_suffix = is_rtl() ? '-rtl' : '';
646
647 wp_register_style(
648 'font-awesome',
649 ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome' . $suffix . '.css',
650 [],
651 '4.7.0'
652 );
653
654 wp_register_style(
655 'elementor-select2',
656 ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2' . $suffix . '.css',
657 [],
658 '4.0.6-rc.1'
659 );
660
661 wp_register_style(
662 'google-font-roboto',
663 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700',
664 [],
665 ELEMENTOR_VERSION
666 );
667
668 wp_register_style(
669 'flatpickr',
670 ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.css',
671 [],
672 '1.12.0'
673 );
674
675 wp_register_style(
676 'pickr',
677 ELEMENTOR_ASSETS_URL . 'lib/pickr/themes/monolith.min.css',
678 [],
679 '1.5.0'
680 );
681
682 wp_register_style(
683 'elementor-editor',
684 ELEMENTOR_ASSETS_URL . 'css/editor' . $direction_suffix . $suffix . '.css',
685 [
686 'elementor-common',
687 'elementor-select2',
688 'elementor-icons',
689 'wp-auth-check',
690 'google-font-roboto',
691 'flatpickr',
692 'pickr',
693 ],
694 ELEMENTOR_VERSION
695 );
696
697 wp_enqueue_style( 'elementor-editor' );
698
699 $ui_theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' );
700
701 if ( 'light' !== $ui_theme ) {
702 $ui_theme_media_queries = 'all';
703
704 if ( 'auto' === $ui_theme ) {
705 $ui_theme_media_queries = '(prefers-color-scheme: dark)';
706 }
707
708 wp_enqueue_style(
709 'elementor-editor-dark-mode',
710 ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css',
711 [
712 'elementor-editor',
713 ],
714 ELEMENTOR_VERSION,
715 $ui_theme_media_queries
716 );
717 }
718
719 $breakpoints = Plugin::$instance->breakpoints->get_breakpoints();
720
721 // The two breakpoints under 'tablet' need to be checked for values.
722 if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) {
723 wp_add_inline_style(
724 'elementor-editor',
725 '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . Plugin::$instance->breakpoints->get_device_min_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_TABLET ) . 'px; }'
726 );
727 }
728
729 /**
730 * After editor enqueue styles.
731 *
732 * Fires after Elementor editor styles are enqueued.
733 *
734 * @since 1.0.0
735 */
736 do_action( 'elementor/editor/after_enqueue_styles' );
737 }
738
739 /**
740 * Get WordPress editor config.
741 *
742 * Config the default WordPress editor with custom settings for Elementor use.
743 *
744 * @since 1.9.0
745 * @access private
746 */
747 private function get_wp_editor_config() {
748 // Remove all TinyMCE plugins.
749 remove_all_filters( 'mce_buttons', 10 );
750 remove_all_filters( 'mce_external_plugins', 10 );
751
752 if ( ! class_exists( '\_WP_Editors', false ) ) {
753 require ABSPATH . WPINC . '/class-wp-editor.php';
754 }
755
756 // WordPress 4.8 and higher
757 if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) {
758 \_WP_Editors::print_default_editor_scripts();
759 \_WP_Editors::print_tinymce_scripts();
760 }
761 ob_start();
762
763 wp_editor(
764 '%%EDITORCONTENT%%',
765 'elementorwpeditor',
766 [
767 'editor_class' => 'elementor-wp-editor',
768 'editor_height' => 250,
769 'drag_drop_upload' => true,
770 ]
771 );
772
773 $config = ob_get_clean();
774
775 // Don't call \_WP_Editors methods again
776 remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 );
777 remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 );
778
779 \_WP_Editors::editor_js();
780
781 return $config;
782 }
783
784 /**
785 * Editor head trigger.
786 *
787 * Fires the 'elementor/editor/wp_head' action in the head tag in Elementor
788 * editor.
789 *
790 * @since 1.0.0
791 * @access public
792 */
793 public function editor_head_trigger() {
794 /**
795 * Elementor editor head.
796 *
797 * Fires on Elementor editor head tag.
798 *
799 * Used to prints scripts or any other data in the head tag.
800 *
801 * @since 1.0.0
802 */
803 do_action( 'elementor/editor/wp_head' );
804 }
805
806 /**
807 * WP footer.
808 *
809 * Prints Elementor editor with all the editor templates, and render controls,
810 * widgets and content elements.
811 *
812 * Fired by `wp_footer` action.
813 *
814 * @since 1.0.0
815 * @access public
816 */
817 public function wp_footer() {
818 $plugin = Plugin::$instance;
819
820 $plugin->controls_manager->render_controls();
821 $plugin->widgets_manager->render_widgets_content();
822 $plugin->elements_manager->render_elements_content();
823
824 $plugin->schemes_manager->print_schemes_templates();
825
826 $plugin->dynamic_tags->print_templates();
827
828 $this->init_editor_templates();
829
830 /**
831 * Elementor editor footer.
832 *
833 * Fires on Elementor editor before closing the body tag.
834 *
835 * Used to prints scripts or any other HTML before closing the body tag.
836 *
837 * @since 1.0.0
838 */
839 do_action( 'elementor/editor/footer' );
840 }
841
842 /**
843 * Set edit mode.
844 *
845 * Used to update the edit mode.
846 *
847 * @since 1.0.0
848 * @access public
849 *
850 * @param bool $edit_mode Whether the edit mode is active.
851 */
852 public function set_edit_mode( $edit_mode ) {
853 $this->is_edit_mode = $edit_mode;
854 }
855
856 /**
857 * Editor constructor.
858 *
859 * Initializing Elementor editor and redirect from old URL structure of
860 * Elementor editor.
861 *
862 * @since 1.0.0
863 * @access public
864 */
865 public function __construct() {
866 Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() );
867
868 $this->notice_bar = new Notice_Bar();
869
870 add_action( 'admin_action_elementor', [ $this, 'init' ] );
871 add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] );
872
873 // Handle autocomplete feature for URL control.
874 add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] );
875 add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] );
876 }
877
878 /**
879 * @since 2.2.0
880 * @access public
881 */
882 public function filter_wp_link_query_args( $query ) {
883 $library_cpt_key = array_search( Source_Local::CPT, $query['post_type'], true );
884 if ( false !== $library_cpt_key ) {
885 unset( $query['post_type'][ $library_cpt_key ] );
886 }
887
888 return $query;
889 }
890
891 /**
892 * @since 2.2.0
893 * @access public
894 */
895 public function filter_wp_link_query( $results ) {
896
897 // PHPCS - The user data is not used.
898 if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
899 $post_type_object = get_post_type_object( 'post' );
900 $post_label = $post_type_object->labels->singular_name;
901
902 foreach ( $results as & $result ) {
903 if ( 'post' === get_post_type( $result['ID'] ) ) {
904 $result['info'] = $post_label;
905 }
906 }
907 }
908
909 return $results;
910 }
911
912 /**
913 * Init editor templates.
914 *
915 * Initialize default elementor templates used in the editor panel.
916 *
917 * @since 1.7.0
918 * @access private
919 */
920 private function init_editor_templates() {
921 $template_names = [
922 'global',
923 'panel',
924 'panel-elements',
925 'repeater',
926 'templates',
927 'navigator',
928 'hotkeys',
929 'responsive-bar',
930 ];
931
932 foreach ( $template_names as $template_name ) {
933 Plugin::$instance->common->add_template( ELEMENTOR_PATH . "includes/editor-templates/$template_name.php" );
934 }
935 }
936
937 private function bc_move_document_filters() {
938 global $wp_filter;
939
940 $old_tag = 'elementor/editor/localize_settings';
941 $new_tag = 'elementor/document/config';
942
943 if ( ! has_filter( $old_tag ) ) {
944 return;
945 }
946
947 foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) {
948 foreach ( $filters as $filter_id => $filter_args ) {
949 if ( 2 === $filter_args['accepted_args'] ) {
950 remove_filter( $old_tag, $filter_id, $priority );
951
952 add_filter( $new_tag, $filter_args['function'], $priority, 2 );
953
954 // TODO: Hard deprecation
955 // _deprecated_hook( '`' . $old_tag . ` is no longer using post_id', '2.9.0', $new_tag' );
956 }
957 }
958 }
959 }
960
961 public function set_post_id( $post_id ) {
962 $this->post_id = $post_id;
963 }
964 }
965