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