PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0-beta1
Elementor Website Builder – more than just a page builder v3.1.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 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 All 457 releases
← All changes | core/editor/editor.php +542 -257 4.3.0 → 3.1.0-beta1 View file →
@@ -1,16 +1,22 @@
1 1 <?php
2 2 namespace Elementor\Core\Editor;
3 3
4 -use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
4 +use Elementor\Api;
5 5 use Elementor\Core\Common\Modules\Ajax\Module;
6 +use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
6 7 use Elementor\Core\Debug\Loading_Inspection_Manager;
7 -use Elementor\Core\Editor\Loader\Editor_Loader;
8 -use Elementor\Core\Utils\Assets_Config_Provider;
9 -use Elementor\Core\Utils\Collection;
8 +use Elementor\Core\Files\Assets\Files_Upload_Handler;
9 +use Elementor\Core\Responsive\Responsive;
10 +use Elementor\Core\Schemes\Manager as Schemes_Manager;
10 11 use Elementor\Core\Settings\Manager as SettingsManager;
12 +use Elementor\Icons_Manager;
11 13 use Elementor\Plugin;
14 +use Elementor\Settings;
15 +use Elementor\Shapes;
12 16 use Elementor\TemplateLibrary\Source_Local;
17 +use Elementor\Tools;
18 +use Elementor\User;
13 19 use Elementor\Utils;
14 20 use Elementor\Core\Editor\Data;
15 21
16 22 if ( ! defined( 'ABSPATH' ) ) {
@@ -27,8 +33,14 @@
27 33 */
28 34 class Editor {
29 35
30 36 /**
37 + * The nonce key for Elementor editor.
38 + * @deprecated 2.3.0
39 + */
40 + const EDITING_NONCE_KEY = 'elementor-editing';
41 +
42 + /**
31 43 * User capability required to access Elementor editor.
32 44 */
33 45 const EDITING_CAPABILITY = 'edit_posts';
34 46
@@ -61,18 +73,8 @@
61 73 */
62 74 public $notice_bar;
63 75
64 76 /**
65 - * @var Promotion
66 - */
67 - public $promotion;
68 -
69 - /**
70 - * @var Editor_Loader
71 - */
72 - private $loader;
73 -
74 - /**
75 77 * Init.
76 78 *
77 79 * Initialize Elementor editor. Registers all needed actions to run Elementor,
78 80 * removes conflicting actions etc.
@@ -81,11 +83,11 @@
81 83 *
82 84 * @since 1.0.0
83 85 * @access public
84 86 *
85 - * @param bool $to_die Optional. Whether to die at the end. Default is `true`.
87 + * @param bool $die Optional. Whether to die at the end. Default is `true`.
86 88 */
87 - public function init( $to_die = true ) {
89 + public function init( $die = true ) {
88 90 if ( empty( $_REQUEST['post'] ) ) {
89 91 return;
90 92 }
91 93
@@ -117,10 +119,8 @@
117 119
118 120 // Send MIME Type header like WP admin-header.
119 121 @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
120 122
121 - self::send_document_isolation_policy_header();
122 -
123 123 add_filter( 'show_admin_bar', '__return_false' );
124 124
125 125 // Remove all WordPress actions
126 126 remove_all_actions( 'wp_head' );
@@ -159,12 +159,12 @@
159 159 Utils::do_not_cache();
160 160
161 161 do_action( 'elementor/editor/init' );
162 162
163 - $this->get_loader()->print_root_template();
163 + $this->print_editor_template();
164 164
165 165 // From the action it's an empty string, from tests its `false`
166 - if ( false !== $to_die ) {
166 + if ( false !== $die ) {
167 167 die;
168 168 }
169 169 }
170 170
@@ -200,9 +200,9 @@
200 200
201 201 $document = Plugin::$instance->documents->get( get_the_ID() );
202 202
203 203 if ( ! $document ) {
204 - wp_die( esc_html__( 'Document not found.', 'elementor' ) );
204 + wp_die( __( 'Document not found.', 'elementor' ) );
205 205 }
206 206
207 207 if ( ! $document->is_editable_by_current_user() || ! $document->is_built_with_elementor() ) {
208 208 return;
@@ -212,67 +212,8 @@
212 212 die;
213 213 }
214 214
215 215 /**
216 - * Whether the current request targets the Elementor editor.
217 - *
218 - * Unlike `is_edit_mode()`, this is not affected by temporary `set_edit_mode()` overrides.
219 - *
220 - * @since 4.1.0
221 - * @access public
222 - *
223 - * @return bool Whether the current request targets the Elementor editor.
224 - */
225 - public function is_editor_request() {
226 - $common = Plugin::$instance->common;
227 -
228 - if ( $common ) {
229 - /** @var Module ajax */
230 - $ajax_data = $common->get_component( 'ajax' )->get_current_action_data();
231 -
232 - if ( ! empty( $ajax_data ) && 'get_document_config' === $ajax_data['action'] ) {
233 - return true;
234 - }
235 - }
236 -
237 - if ( $this->is_editor_admin_screen() ) {
238 - return true;
239 - }
240 -
241 - return $this->is_editor_ajax_request();
242 - }
243 -
244 - private function is_editor_admin_screen(): bool {
245 - if ( ! function_exists( 'get_current_screen' ) ) {
246 - return false;
247 - }
248 -
249 - $screen = get_current_screen();
250 -
251 - if ( ! $screen ) {
252 - return false;
253 - }
254 -
255 - return isset( $_GET['action'] ) && 'elementor' === $_GET['action'] && in_array( $screen->base, [ 'post', 'toplevel_page_elementor' ], true );
256 - }
257 -
258 - private function is_editor_ajax_request(): bool {
259 - $actions = apply_filters( 'elementor/editor/ajax_actions', [
260 - 'elementor',
261 -
262 - // Templates
263 - 'elementor_get_templates',
264 - 'elementor_save_template',
265 - 'elementor_get_template',
266 - 'elementor_delete_template',
267 - 'elementor_import_template',
268 - 'elementor_library_direct_actions',
269 - ] );
270 -
271 - return isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions, true );
272 - }
273 -
274 - /**
275 216 * Whether the edit mode is active.
276 217 *
277 218 * Used to determine whether we are in the edit mode.
278 219 *
@@ -369,10 +310,8 @@
369 310 return get_user_by( 'id', $locked_user );
370 311 }
371 312
372 313 /**
373 - * NOTICE: This method not in use, it's here for backward compatibility.
374 - *
375 314 * Print Editor Template.
376 315 *
377 316 * Include the wrapper template of the editor.
378 317 *
@@ -395,14 +334,173 @@
395 334 remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 );
396 335
397 336 global $wp_styles, $wp_scripts;
398 337
338 + $plugin = Plugin::$instance;
339 +
399 340 // Reset global variable
400 341 $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
401 342 $wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
402 343
403 - $this->get_loader()->register_scripts();
344 + $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS ) ? '' : '.min';
404 345
346 + wp_register_script(
347 + 'elementor-editor-modules',
348 + ELEMENTOR_ASSETS_URL . 'js/editor-modules' . $suffix . '.js',
349 + [
350 + 'elementor-common-modules',
351 + ],
352 + ELEMENTOR_VERSION,
353 + true
354 + );
355 +
356 + wp_register_script(
357 + 'elementor-editor-document',
358 + ELEMENTOR_ASSETS_URL . 'js/editor-document' . $suffix . '.js',
359 + [
360 + 'elementor-common-modules',
361 + ],
362 + ELEMENTOR_VERSION,
363 + true
364 + );
365 + // Hack for waypoint with editor mode.
366 + wp_register_script(
367 + 'elementor-waypoints',
368 + ELEMENTOR_ASSETS_URL . 'lib/waypoints/waypoints-for-editor.js',
369 + [
370 + 'jquery',
371 + ],
372 + '4.0.2',
373 + true
374 + );
375 +
376 + wp_register_script(
377 + 'perfect-scrollbar',
378 + ELEMENTOR_ASSETS_URL . 'lib/perfect-scrollbar/js/perfect-scrollbar' . $suffix . '.js',
379 + [],
380 + '1.4.0',
381 + true
382 + );
383 +
384 + wp_register_script(
385 + 'jquery-easing',
386 + ELEMENTOR_ASSETS_URL . 'lib/jquery-easing/jquery-easing' . $suffix . '.js',
387 + [
388 + 'jquery',
389 + ],
390 + '1.3.2',
391 + true
392 + );
393 +
394 + wp_register_script(
395 + 'nprogress',
396 + ELEMENTOR_ASSETS_URL . 'lib/nprogress/nprogress' . $suffix . '.js',
397 + [],
398 + '0.2.0',
399 + true
400 + );
401 +
402 + wp_register_script(
403 + 'tipsy',
404 + ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $suffix . '.js',
405 + [
406 + 'jquery',
407 + ],
408 + '1.0.0',
409 + true
410 + );
411 +
412 + wp_register_script(
413 + 'jquery-elementor-select2',
414 + ELEMENTOR_ASSETS_URL . 'lib/e-select2/js/e-select2.full' . $suffix . '.js',
415 + [
416 + 'jquery',
417 + ],
418 + '4.0.6-rc.1',
419 + true
420 + );
421 +
422 + wp_register_script(
423 + 'flatpickr',
424 + ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.js',
425 + [
426 + 'jquery',
427 + ],
428 + '1.12.0',
429 + true
430 + );
431 +
432 + wp_register_script(
433 + 'ace',
434 + 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js',
435 + [],
436 + '1.2.5',
437 + true
438 + );
439 +
440 + wp_register_script(
441 + 'ace-language-tools',
442 + 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ext-language_tools.js',
443 + [
444 + 'ace',
445 + ],
446 + '1.2.5',
447 + true
448 + );
449 +
450 + wp_register_script(
451 + 'jquery-hover-intent',
452 + ELEMENTOR_ASSETS_URL . 'lib/jquery-hover-intent/jquery-hover-intent' . $suffix . '.js',
453 + [],
454 + '1.0.0',
455 + true
456 + );
457 +
458 + wp_register_script(
459 + 'nouislider',
460 + ELEMENTOR_ASSETS_URL . 'lib/nouislider/nouislider' . $suffix . '.js',
461 + [],
462 + '13.0.0',
463 + true
464 + );
465 +
466 + wp_register_script(
467 + 'pickr',
468 + ELEMENTOR_ASSETS_URL . 'lib/pickr/pickr.min.js',
469 + [],
470 + '1.5.0',
471 + true
472 + );
473 +
474 + wp_register_script(
475 + 'elementor-editor',
476 + ELEMENTOR_ASSETS_URL . 'js/editor' . $suffix . '.js',
477 + [
478 + 'elementor-common',
479 + 'elementor-editor-modules',
480 + 'elementor-editor-document',
481 + 'wp-auth-check',
482 + 'jquery-ui-sortable',
483 + 'jquery-ui-resizable',
484 + 'perfect-scrollbar',
485 + 'nprogress',
486 + 'tipsy',
487 + 'imagesloaded',
488 + 'heartbeat',
489 + 'jquery-elementor-select2',
490 + 'flatpickr',
491 + 'ace',
492 + 'ace-language-tools',
493 + 'jquery-hover-intent',
494 + 'nouislider',
495 + 'pickr',
496 + 'react',
497 + 'react-dom',
498 + ],
499 + ELEMENTOR_VERSION,
500 + true
501 + );
502 +
405 503 /**
406 504 * Before editor enqueue scripts.
407 505 *
408 506 * Fires before Elementor editor scripts are enqueued.
@@ -413,13 +511,117 @@
413 511
414 512 // Tweak for WP Admin menu icons
415 513 wp_print_styles( 'editor-buttons' );
416 514
417 - $this->get_loader()->enqueue_scripts();
515 + $settings = SettingsManager::get_settings_managers_config();
516 + // Moved to document since 2.9.0.
517 + unset( $settings['page'] );
418 518
419 - Plugin::$instance->controls_manager->enqueue_control_scripts();
519 + $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post_id );
520 + $kits_manager = Plugin::$instance->kits_manager;
420 521
522 + $page_title_selector = $kits_manager->get_current_settings( 'page_title_selector' );
523 +
524 + $page_title_selector .= ', .elementor-page-title';
525 +
526 + $active_experimental_features = Plugin::$instance->experiments->get_active_features();
527 +
528 + $active_experimental_features = array_fill_keys( array_keys( $active_experimental_features ), true );
529 +
530 + $config = [
531 + 'initial_document' => $document->get_config(),
532 + 'version' => ELEMENTOR_VERSION,
533 + 'home_url' => home_url(),
534 + 'admin_settings_url' => admin_url( 'admin.php?page=' . Settings::PAGE_ID ),
535 + 'autosave_interval' => AUTOSAVE_INTERVAL,
536 + 'tabs' => $plugin->controls_manager->get_tabs(),
537 + 'controls' => $plugin->controls_manager->get_controls_data(),
538 + 'elements' => $plugin->elements_manager->get_element_types_config(),
539 + 'schemes' => [
540 + 'items' => $plugin->schemes_manager->get_registered_schemes_data(),
541 + 'enabled_schemes' => Schemes_Manager::get_enabled_schemes(),
542 + ],
543 + 'globals' => [
544 + 'defaults_enabled' => [
545 + 'colors' => $kits_manager->is_custom_colors_enabled(),
546 + 'typography' => $kits_manager->is_custom_typography_enabled(),
547 + ],
548 + ],
549 + 'icons' => [
550 + 'libraries' => Icons_Manager::get_icon_manager_tabs_config(),
551 + 'goProURL' => Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=icon-library&utm_campaign=gopro&utm_medium=wp-dash' ),
552 + ],
553 + 'filesUpload' => [
554 + 'unfilteredFiles' => Files_Upload_Handler::is_enabled(),
555 + ],
556 + 'fa4_to_fa5_mapping_url' => ELEMENTOR_ASSETS_URL . 'lib/font-awesome/migration/mapping.js',
557 + 'default_schemes' => $plugin->schemes_manager->get_schemes_defaults(),
558 + 'settings' => $settings,
559 + 'system_schemes' => $plugin->schemes_manager->get_system_schemes(),
560 + 'wp_editor' => $this->get_wp_editor_config(),
561 + 'settings_page_link' => Settings::get_url(),
562 + 'tools_page_link' => Tools::get_url(),
563 + 'elementor_site' => 'https://go.elementor.com/about-elementor/',
564 + 'docs_elementor_site' => 'https://go.elementor.com/docs/',
565 + 'help_the_content_url' => 'https://go.elementor.com/the-content-missing/',
566 + 'help_right_click_url' => 'https://go.elementor.com/meet-right-click/',
567 + 'help_flexbox_bc_url' => 'https://go.elementor.com/flexbox-layout-bc/',
568 + 'elementPromotionURL' => 'https://go.elementor.com/go-pro-%s',
569 + 'dynamicPromotionURL' => 'https://go.elementor.com/go-pro-dynamic-tag',
570 + 'additional_shapes' => Shapes::get_additional_shapes_for_config(),
571 + 'user' => [
572 + 'restrictions' => $plugin->role_manager->get_user_restrictions_array(),
573 + 'is_administrator' => current_user_can( 'manage_options' ),
574 + 'introduction' => User::get_introduction_meta(),
575 + ],
576 + 'preview' => [
577 + 'help_preview_error_url' => 'https://go.elementor.com/preview-not-loaded/',
578 + 'help_preview_http_error_url' => 'https://go.elementor.com/preview-not-loaded/#permissions',
579 + 'help_preview_http_error_500_url' => 'https://go.elementor.com/500-error/',
580 + 'debug_data' => Loading_Inspection_Manager::instance()->run_inspections(),
581 + ],
582 + 'locale' => get_locale(),
583 + 'rich_editing_enabled' => filter_var( get_user_meta( get_current_user_id(), 'rich_editing', true ), FILTER_VALIDATE_BOOLEAN ),
584 + 'page_title_selector' => $page_title_selector,
585 + 'tinymceHasCustomConfig' => class_exists( 'Tinymce_Advanced' ) || class_exists( 'Advanced_Editor_Tools' ),
586 + 'inlineEditing' => Plugin::$instance->widgets_manager->get_inline_editing_config(),
587 + 'dynamicTags' => Plugin::$instance->dynamic_tags->get_config(),
588 + 'ui' => [
589 + 'darkModeStylesheetURL' => ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css',
590 + 'defaultGenericFonts' => $kits_manager->get_current_settings( 'default_generic_fonts' ),
591 + ],
592 + // Empty array for BC to avoid errors.
593 + 'i18n' => [],
594 + 'experimentalFeatures' => $active_experimental_features,
595 + ];
596 +
597 + if ( ! Utils::has_pro() && current_user_can( 'manage_options' ) ) {
598 + $config['promotionWidgets'] = Api::get_promotion_widgets();
599 + }
600 +
601 + $this->bc_move_document_filters();
602 +
421 603 /**
604 + * Localize editor settings.
605 + *
606 + * Filters the editor localized settings.
607 + *
608 + * @since 1.0.0
609 + *
610 + * @param array $config Editor configuration.
611 + * @param int $post_id The ID of the current post being edited.
612 + */
613 + $config = apply_filters( 'elementor/editor/localize_settings', $config );
614 +
615 + Utils::print_js_config( 'elementor-editor', 'ElementorConfig', $config );
616 +
617 + wp_enqueue_script( 'elementor-editor' );
618 +
619 + wp_set_script_translations( 'elementor-editor', 'elementor' );
620 +
621 + $plugin->controls_manager->enqueue_control_scripts();
622 +
623 + /**
422 624 * After editor enqueue scripts.
423 625 *
424 626 * Fires after Elementor editor scripts are enqueued.
425 627 *
@@ -445,23 +647,90 @@
445 647 * @since 1.0.0
446 648 */
447 649 do_action( 'elementor/editor/before_enqueue_styles' );
448 650
449 - $this->get_loader()->register_styles();
450 - $this->get_loader()->enqueue_styles();
651 + $suffix = Utils::is_script_debug() ? '' : '.min';
451 652
452 - $this->enqueue_theme_ui_styles();
653 + $direction_suffix = is_rtl() ? '-rtl' : '';
453 654
454 - $breakpoints = Plugin::$instance->breakpoints->get_breakpoints();
655 + wp_register_style(
656 + 'font-awesome',
657 + ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome' . $suffix . '.css',
658 + [],
659 + '4.7.0'
660 + );
455 661
456 - // The two breakpoints under 'tablet' need to be checked for values.
457 - if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) {
458 - wp_add_inline_style(
459 - 'elementor-editor',
460 - '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . Plugin::$instance->breakpoints->get_device_min_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_TABLET ) . 'px; }'
662 + wp_register_style(
663 + 'elementor-select2',
664 + ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2' . $suffix . '.css',
665 + [],
666 + '4.0.6-rc.1'
667 + );
668 +
669 + wp_register_style(
670 + 'google-font-roboto',
671 + 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700',
672 + [],
673 + ELEMENTOR_VERSION
674 + );
675 +
676 + wp_register_style(
677 + 'flatpickr',
678 + ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.css',
679 + [],
680 + '1.12.0'
681 + );
682 +
683 + wp_register_style(
684 + 'pickr',
685 + ELEMENTOR_ASSETS_URL . 'lib/pickr/themes/monolith.min.css',
686 + [],
687 + '1.5.0'
688 + );
689 +
690 + wp_register_style(
691 + 'elementor-editor',
692 + ELEMENTOR_ASSETS_URL . 'css/editor' . $direction_suffix . $suffix . '.css',
693 + [
694 + 'elementor-common',
695 + 'elementor-select2',
696 + 'elementor-icons',
697 + 'wp-auth-check',
698 + 'google-font-roboto',
699 + 'flatpickr',
700 + 'pickr',
701 + ],
702 + ELEMENTOR_VERSION
703 + );
704 +
705 + wp_enqueue_style( 'elementor-editor' );
706 +
707 + $ui_theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' );
708 +
709 + if ( 'light' !== $ui_theme ) {
710 + $ui_theme_media_queries = 'all';
711 +
712 + if ( 'auto' === $ui_theme ) {
713 + $ui_theme_media_queries = '(prefers-color-scheme: dark)';
714 + }
715 +
716 + wp_enqueue_style(
717 + 'elementor-editor-dark-mode',
718 + ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css',
719 + [
720 + 'elementor-editor',
721 + ],
722 + ELEMENTOR_VERSION,
723 + $ui_theme_media_queries
461 724 );
462 725 }
463 726
727 + if ( Responsive::has_custom_breakpoints() ) {
728 + $breakpoints = Responsive::get_breakpoints();
729 +
730 + wp_add_inline_style( 'elementor-editor', '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . $breakpoints['md'] . 'px; }' );
731 + }
732 +
464 733 /**
465 734 * After editor enqueue styles.
466 735 *
467 736 * Fires after Elementor editor styles are enqueued.
@@ -470,44 +739,51 @@
470 739 */
471 740 do_action( 'elementor/editor/after_enqueue_styles' );
472 741 }
473 742
474 - private function enqueue_theme_ui_styles() {
475 - $ui_theme_selected = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' );
743 + /**
744 + * Get WordPress editor config.
745 + *
746 + * Config the default WordPress editor with custom settings for Elementor use.
747 + *
748 + * @since 1.9.0
749 + * @access private
750 + */
751 + private function get_wp_editor_config() {
752 + // Remove all TinyMCE plugins.
753 + remove_all_filters( 'mce_buttons', 10 );
754 + remove_all_filters( 'mce_external_plugins', 10 );
476 755
477 - $ui_themes = [
478 - 'light',
479 - 'dark',
480 - ];
756 + if ( ! class_exists( '\_WP_Editors', false ) ) {
757 + require ABSPATH . WPINC . '/class-wp-editor.php';
758 + }
481 759
482 - if ( 'auto' === $ui_theme_selected || ! in_array( $ui_theme_selected, $ui_themes, true ) ) {
483 - $ui_light_theme_media_queries = '(prefers-color-scheme: light)';
484 - $ui_dark_theme_media_queries = '(prefers-color-scheme: dark)';
485 - } else {
486 - $ui_light_theme_media_queries = 'none';
487 - $ui_dark_theme_media_queries = 'none';
760 + // WordPress 4.8 and higher
761 + if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) {
762 + \_WP_Editors::print_default_editor_scripts();
763 + \_WP_Editors::print_tinymce_scripts();
764 + }
765 + ob_start();
488 766
489 - if ( 'light' === $ui_theme_selected ) {
490 - $ui_light_theme_media_queries = 'all';
491 - } elseif ( 'dark' === $ui_theme_selected ) {
492 - $ui_dark_theme_media_queries = 'all';
493 - }
494 - }
767 + wp_editor(
768 + '%%EDITORCONTENT%%',
769 + 'elementorwpeditor',
770 + [
771 + 'editor_class' => 'elementor-wp-editor',
772 + 'editor_height' => 250,
773 + 'drag_drop_upload' => true,
774 + ]
775 + );
495 776
496 - $this->enqueue_theme_ui( 'light', $ui_light_theme_media_queries );
497 - $this->enqueue_theme_ui( 'dark', $ui_dark_theme_media_queries );
498 - }
777 + $config = ob_get_clean();
499 778
500 - private function enqueue_theme_ui( $ui_theme, $ui_theme_media_queries = 'all' ) {
501 - $suffix = Utils::is_script_debug() ? '' : '.min';
779 + // Don't call \_WP_Editors methods again
780 + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 );
781 + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 );
502 782
503 - wp_enqueue_style(
504 - 'e-theme-ui-' . $ui_theme,
505 - ELEMENTOR_ASSETS_URL . 'css/theme-' . $ui_theme . $suffix . '.css',
506 - [],
507 - ELEMENTOR_VERSION,
508 - $ui_theme_media_queries
509 - );
783 + \_WP_Editors::editor_js();
784 +
785 + return $config;
510 786 }
511 787
512 788 /**
513 789 * Editor head trigger.
@@ -531,8 +807,32 @@
531 807 do_action( 'elementor/editor/wp_head' );
532 808 }
533 809
534 810 /**
811 + * Add editor template.
812 + *
813 + * Registers new editor templates.
814 + *
815 + * @since 1.0.0
816 + * @deprecated 2.3.0 Use `Plugin::$instance->common->add_template()`
817 + * @access public
818 + *
819 + * @param string $template Can be either a link to template file or template
820 + * HTML content.
821 + * @param string $type Optional. Whether to handle the template as path
822 + * or text. Default is `path`.
823 + */
824 + public function add_editor_template( $template, $type = 'path' ) {
825 + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->add_template()' );
826 +
827 + $common = Plugin::$instance->common;
828 +
829 + if ( $common ) {
830 + Plugin::$instance->common->add_template( $template, $type );
831 + }
832 + }
833 +
834 + /**
535 835 * WP footer.
536 836 *
537 837 * Prints Elementor editor with all the editor templates, and render controls,
538 838 * widgets and content elements.
@@ -548,11 +848,13 @@
548 848 $plugin->controls_manager->render_controls();
549 849 $plugin->widgets_manager->render_widgets_content();
550 850 $plugin->elements_manager->render_elements_content();
551 851
852 + $plugin->schemes_manager->print_schemes_templates();
853 +
552 854 $plugin->dynamic_tags->print_templates();
553 855
554 - $this->get_loader()->register_additional_templates();
856 + $this->init_editor_templates();
555 857
556 858 /**
557 859 * Elementor editor footer.
558 860 *
@@ -588,12 +890,11 @@
588 890 * @since 1.0.0
589 891 * @access public
590 892 */
591 893 public function __construct() {
592 - Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() );
894 + Plugin::$instance->data_manager->register_controller( Data\Globals\Controller::class );
593 895
594 896 $this->notice_bar = new Notice_Bar();
595 - $this->promotion = new Promotion();
596 897
597 898 add_action( 'admin_action_elementor', [ $this, 'init' ] );
598 899 add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] );
599 900
@@ -599,89 +900,11 @@
599 900
600 901 // Handle autocomplete feature for URL control.
601 902 add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] );
602 903 add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] );
603 -
604 - add_filter( 'replace_editor', [ $this, 'filter_replace_editor' ], 10, 2 );
605 904 }
606 905
607 906 /**
608 - * Whether the Document-Isolation-Policy header should be sent on the
609 - * Elementor editor screen and the editor preview iframe.
610 - *
611 - * DIP places the document in its own agent cluster, which is the prerequisite
612 - * for cross-origin isolation features such as SharedArrayBuffer (required by
613 - * WordPress core's client-side media processing introduced in WP 7.1).
614 - *
615 - * Both the editor parent document and the preview iframe must send the same
616 - * DIP header so they join the same agent cluster and synchronous DOM access
617 - * between them (e.g. `iframe.contentWindow.elementorFrontend`) keeps working.
618 - *
619 - * The header is only honored by browsers on a secure context (HTTPS or
620 - * localhost) so the helper short-circuits on insecure origins to avoid
621 - * sending a header that the browser will ignore.
622 - *
623 - * @since 4.1.0
624 - *
625 - * @return bool
626 - */
627 - public static function should_use_document_isolation_policy() {
628 - if ( ! is_ssl() ) {
629 - $raw_host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
630 - $host = strtolower( (string) strtok( $raw_host, ':' ) );
631 -
632 - if ( 'localhost' !== $host && ! str_ends_with( $host, '.localhost' ) ) {
633 - return false;
634 - }
635 - }
636 -
637 - /**
638 - * Filters whether Elementor sends the Document-Isolation-Policy header
639 - * on the editor screen and preview iframe.
640 - *
641 - * @since 4.1.0
642 - *
643 - * @param bool $enabled Whether DIP is enabled. Defaults to true on a secure context.
644 - */
645 - return (bool) apply_filters( 'elementor/editor/use_document_isolation_policy', true );
646 - }
647 -
648 - /**
649 - * Send the Document-Isolation-Policy header for the current response.
650 - *
651 - * Safe to call from both the Elementor editor screen handler and the
652 - * preview iframe handler. No-op when {@see self::should_use_document_isolation_policy()}
653 - * returns false.
654 - *
655 - * @since 4.1.0
656 - */
657 - public static function send_document_isolation_policy_header() {
658 - if ( ! self::should_use_document_isolation_policy() || headers_sent() ) {
659 - return;
660 - }
661 -
662 - header( 'Document-Isolation-Policy: isolate-and-credentialless' );
663 - }
664 -
665 - /**
666 - * Signals to WordPress that Elementor is replacing the block editor on its own editor page,
667 - * so that block-editor-specific behaviour (e.g. WP 7.0 COOP/COEP isolation headers) is not
668 - * applied when the Elementor editor is active.
669 - *
670 - * @param bool $replace Whether the editor is being replaced.
671 - * @param \WP_Post $post The post being edited.
672 - *
673 - * @return bool
674 - */
675 - public function filter_replace_editor( $replace, $post ) {
676 - if ( isset( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
677 - return true;
678 - }
679 -
680 - return $replace;
681 - }
682 -
683 - /**
684 907 * @since 2.2.0
685 908 * @access public
686 909 */
687 910 public function filter_wp_link_query_args( $query ) {
@@ -697,11 +920,9 @@
697 920 * @since 2.2.0
698 921 * @access public
699 922 */
700 923 public function filter_wp_link_query( $results ) {
701 -
702 - // PHPCS - The user data is not used.
703 - if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
924 + if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) {
704 925 $post_type_object = get_post_type_object( 'post' );
705 926 $post_label = $post_type_object->labels->singular_name;
706 927
707 928 foreach ( $results as & $result ) {
@@ -713,82 +934,146 @@
713 934
714 935 return $results;
715 936 }
716 937
717 - public function set_post_id( $post_id ) {
718 - $this->post_id = $post_id;
938 + /**
939 + * Create nonce.
940 + *
941 + * If the user has edit capabilities, it creates a cryptographic token to
942 + * give him access to Elementor editor.
943 + *
944 + * @since 1.8.1
945 + * @since 1.8.7 The `$post_type` parameter was introduces.
946 + * @deprecated 2.3.0 Use `Plugin::$instance->common->get_component( 'ajax' )->create_nonce()` instead
947 + * @access public
948 + *
949 + * @param string $post_type The post type to check capabilities.
950 + *
951 + * @return null|string The nonce token, or `null` if the user has no edit
952 + * capabilities.
953 + */
954 + public function create_nonce( $post_type ) {
955 + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->get_component( \'ajax\' )->create_nonce()' );
956 +
957 + /** @var Ajax $ajax */
958 + $ajax = Plugin::$instance->common->get_component( 'ajax' );
959 +
960 + return $ajax->create_nonce();
719 961 }
720 962
721 963 /**
722 - * Get loader.
964 + * Verify nonce.
723 965 *
724 - * @return Editor_Loader
966 + * The user is given an amount of time to use the token, so therefore, since
967 + * the user ID and `$action` remain the same, the independent variable is
968 + * the time.
969 + *
970 + * @since 1.8.1
971 + * @deprecated 2.3.0
972 + * @access public
973 + *
974 + * @param string $nonce Nonce to verify.
975 + *
976 + * @return false|int If the nonce is invalid it returns `false`. If the
977 + * nonce is valid and generated between 0-12 hours ago it
978 + * returns `1`. If the nonce is valid and generated
979 + * between 12-24 hours ago it returns `2`.
725 980 */
726 - private function get_loader() {
727 - if ( ! $this->loader ) {
728 - $this->loader = new Editor_Loader(
729 - new Collection( [
730 - 'assets_url' => ELEMENTOR_ASSETS_URL,
731 - 'min_suffix' => ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min',
732 - 'direction_suffix' => is_rtl() ? '-rtl' : '',
733 - ] ),
734 - ( new Assets_Config_Provider() )->set_path_resolver(
735 - function ( $name ) {
736 - return ELEMENTOR_ASSETS_PATH . "js/packages/{$name}/{$name}.asset.php";
737 - }
738 - )
739 - );
981 + public function verify_nonce( $nonce ) {
982 + _deprecated_function( __METHOD__, '2.3.0', 'wp_verify_nonce()' );
740 983
741 - $this->loader->init();
742 - }
743 -
744 - return $this->loader;
984 + return wp_verify_nonce( $nonce );
745 985 }
746 986
747 987 /**
748 - * Get elements presets.
988 + * Verify request nonce.
749 989 *
750 - * @return array
990 + * Whether the request nonce verified or not.
991 + *
992 + * @since 1.8.1
993 + * @deprecated 2.3.0 Use `Plugin::$instance->common->get_component( 'ajax' )->verify_request_nonce()` instead
994 + * @access public
995 + *
996 + * @return bool True if request nonce verified, False otherwise.
751 997 */
752 - public function get_elements_presets() {
753 - $element_types = Plugin::$instance->elements_manager->get_element_types();
754 - $presets = [];
998 + public function verify_request_nonce() {
999 + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->get_component( \'ajax\' )->verify_request_nonce()' );
755 1000
756 - foreach ( $element_types as $el_type => $element ) {
757 - $this->check_element_for_presets( $element, $el_type, $presets );
758 - }
1001 + /** @var Ajax $ajax */
1002 + $ajax = Plugin::$instance->common->get_component( 'ajax' );
759 1003
760 - return $presets;
1004 + return $ajax->verify_request_nonce();
761 1005 }
762 1006
763 1007 /**
764 - * @return void
1008 + * Verify ajax nonce.
1009 + *
1010 + * Verify request nonce and send a JSON request, if not verified returns an
1011 + * error.
1012 + *
1013 + * @since 1.9.0
1014 + * @deprecated 2.3.0
1015 + * @access public
765 1016 */
766 - private function check_element_for_presets( $element, $el_type, &$presets ) {
767 - $element_presets = $element->get_panel_presets();
1017 + public function verify_ajax_nonce() {
1018 + _deprecated_function( __METHOD__, '2.3.0' );
768 1019
769 - if ( empty( $element_presets ) ) {
770 - return;
771 - }
1020 + /** @var Ajax $ajax */
1021 + $ajax = Plugin::$instance->common->get_component( 'ajax' );
772 1022
773 - foreach ( $element_presets as $key => $preset ) {
774 - $this->maybe_add_preset( $el_type, $preset, $key, $presets );
1023 + if ( ! $ajax->verify_request_nonce() ) {
1024 + wp_send_json_error( new \WP_Error( 'token_expired', 'Nonce token expired.' ) );
775 1025 }
776 1026 }
777 1027
778 1028 /**
779 - * @return void
1029 + * Init editor templates.
1030 + *
1031 + * Initialize default elementor templates used in the editor panel.
1032 + *
1033 + * @since 1.7.0
1034 + * @access private
780 1035 */
781 - private function maybe_add_preset( $el_type, $preset, $key, &$presets ) {
782 - if ( $this->is_valid_preset( $el_type, $preset ) ) {
783 - $presets[ $key ] = $preset;
1036 + private function init_editor_templates() {
1037 + $template_names = [
1038 + 'global',
1039 + 'panel',
1040 + 'panel-elements',
1041 + 'repeater',
1042 + 'templates',
1043 + 'navigator',
1044 + 'hotkeys',
1045 + ];
1046 +
1047 + foreach ( $template_names as $template_name ) {
1048 + Plugin::$instance->common->add_template( ELEMENTOR_PATH . "includes/editor-templates/$template_name.php" );
784 1049 }
785 1050 }
786 1051
787 - /**
788 - * @return boolean
789 - */
790 - private function is_valid_preset( $el_type, $preset ) {
791 - return isset( $preset['replacements']['custom']['originalWidget'] )
792 - && $el_type === $preset['replacements']['custom']['originalWidget'];
1052 + private function bc_move_document_filters() {
1053 + global $wp_filter;
1054 +
1055 + $old_tag = 'elementor/editor/localize_settings';
1056 + $new_tag = 'elementor/document/config';
1057 +
1058 + if ( ! has_filter( $old_tag ) ) {
1059 + return;
1060 + }
1061 +
1062 + foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) {
1063 + foreach ( $filters as $filter_id => $filter_args ) {
1064 + if ( 2 === $filter_args['accepted_args'] ) {
1065 + remove_filter( $old_tag, $filter_id, $priority );
1066 +
1067 + add_filter( $new_tag, $filter_args['function'], $priority, 2 );
1068 +
1069 + // TODO: Hard deprecation
1070 + // _deprecated_hook( '`' . $old_tag . ` is no longer using post_id', '2.9.0', $new_tag' );
1071 + }
1072 + }
1073 + }
1074 + }
1075 +
1076 + public function set_post_id( $post_id ) {
1077 + $this->post_id = $post_id;
793 1078 }
794 1079 }