| @@ -1,15 +1,25 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Core\Editor; |
| 3 | 3 | |
| 4 | +use Elementor\Api; | |
| 5 | +use Elementor\Core\Breakpoints\Breakpoint; | |
| 4 | 6 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 5 | 7 | use Elementor\Core\Common\Modules\Ajax\Module; |
| 8 | +use Elementor\Core\Common\Modules\Ajax\Module as Ajax; | |
| 6 | 9 | 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; | |
| 10 | +use Elementor\Core\Editor\Config_Providers\Config_Provider_Factory; | |
| 11 | +use Elementor\Core\Experiments\Manager as Experiments_Manager; | |
| 12 | +use Elementor\Core\Files\Uploads_Manager; | |
| 13 | +use Elementor\Core\Schemes\Manager as Schemes_Manager; | |
| 9 | 14 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 15 | +use Elementor\Icons_Manager; | |
| 10 | 16 | use Elementor\Plugin; |
| 17 | +use Elementor\Settings; | |
| 18 | +use Elementor\Shapes; | |
| 11 | 19 | use Elementor\TemplateLibrary\Source_Local; |
| 20 | +use Elementor\Tools; | |
| 21 | +use Elementor\User; | |
| 12 | 22 | use Elementor\Utils; |
| 13 | 23 | use Elementor\Core\Editor\Data; |
| 14 | 24 | |
| 15 | 25 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -30,8 +40,10 @@ | ||
| 30 | 40 | * User capability required to access Elementor editor. |
| 31 | 41 | */ |
| 32 | 42 | const EDITING_CAPABILITY = 'edit_posts'; |
| 33 | 43 | |
| 44 | + const EDITOR_V2_EXPERIMENT_NAME = 'editor_v2'; | |
| 45 | + | |
| 34 | 46 | /** |
| 35 | 47 | * Post ID. |
| 36 | 48 | * |
| 37 | 49 | * Holds the ID of the current post being edited. |
| @@ -65,9 +77,9 @@ | ||
| 65 | 77 | */ |
| 66 | 78 | public $promotion; |
| 67 | 79 | |
| 68 | 80 | /** |
| 69 | - * @var Editor_Loader_Interface | |
| 81 | + * @var Editor_Loader | |
| 70 | 82 | */ |
| 71 | 83 | private $loader; |
| 72 | 84 | |
| 73 | 85 | /** |
| @@ -80,11 +92,11 @@ | ||
| 80 | 92 | * |
| 81 | 93 | * @since 1.0.0 |
| 82 | 94 | * @access public |
| 83 | 95 | * |
| 84 | - * @param bool $to_die Optional. Whether to die at the end. Default is `true`. | |
| 96 | + * @param bool $die Optional. Whether to die at the end. Default is `true`. | |
| 85 | 97 | */ |
| 86 | - public function init( $to_die = true ) { | |
| 98 | + public function init( $die = true ) { | |
| 87 | 99 | if ( empty( $_REQUEST['post'] ) ) { |
| 88 | 100 | return; |
| 89 | 101 | } |
| 90 | 102 | |
| @@ -116,10 +128,8 @@ | ||
| 116 | 128 | |
| 117 | 129 | // Send MIME Type header like WP admin-header. |
| 118 | 130 | @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); |
| 119 | 131 | |
| 120 | - self::send_document_isolation_policy_header(); | |
| 121 | - | |
| 122 | 132 | add_filter( 'show_admin_bar', '__return_false' ); |
| 123 | 133 | |
| 124 | 134 | // Remove all WordPress actions |
| 125 | 135 | remove_all_actions( 'wp_head' ); |
| @@ -161,9 +171,9 @@ | ||
| 161 | 171 | |
| 162 | 172 | $this->get_loader()->print_root_template(); |
| 163 | 173 | |
| 164 | 174 | // From the action it's an empty string, from tests its `false` |
| 165 | - if ( false !== $to_die ) { | |
| 175 | + if ( false !== $die ) { | |
| 166 | 176 | die; |
| 167 | 177 | } |
| 168 | 178 | } |
| 169 | 179 | |
| @@ -335,12 +345,16 @@ | ||
| 335 | 345 | remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 ); |
| 336 | 346 | |
| 337 | 347 | global $wp_styles, $wp_scripts; |
| 338 | 348 | |
| 349 | + $plugin = Plugin::$instance; | |
| 350 | + | |
| 339 | 351 | // Reset global variable |
| 340 | 352 | $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 341 | 353 | $wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 342 | 354 | |
| 355 | + $suffix = ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min'; | |
| 356 | + | |
| 343 | 357 | $this->get_loader()->register_scripts(); |
| 344 | 358 | |
| 345 | 359 | /** |
| 346 | 360 | * Before editor enqueue scripts. |
| @@ -353,11 +367,116 @@ | ||
| 353 | 367 | |
| 354 | 368 | // Tweak for WP Admin menu icons |
| 355 | 369 | wp_print_styles( 'editor-buttons' ); |
| 356 | 370 | |
| 371 | + $settings = SettingsManager::get_settings_managers_config(); | |
| 372 | + // Moved to document since 2.9.0. | |
| 373 | + unset( $settings['page'] ); | |
| 374 | + | |
| 375 | + $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post_id ); | |
| 376 | + $kits_manager = Plugin::$instance->kits_manager; | |
| 377 | + | |
| 378 | + $page_title_selector = $kits_manager->get_current_settings( 'page_title_selector' ); | |
| 379 | + | |
| 380 | + $page_title_selector .= ', .elementor-page-title .elementor-heading-title'; | |
| 381 | + | |
| 382 | + $config = [ | |
| 383 | + 'initial_document' => $document->get_config(), | |
| 384 | + 'version' => ELEMENTOR_VERSION, | |
| 385 | + 'home_url' => home_url(), | |
| 386 | + 'admin_settings_url' => admin_url( 'admin.php?page=' . Settings::PAGE_ID ), | |
| 387 | + 'admin_tools_url' => admin_url( 'admin.php?page=' . Tools::PAGE_ID ), | |
| 388 | + 'autosave_interval' => AUTOSAVE_INTERVAL, | |
| 389 | + 'tabs' => $plugin->controls_manager->get_tabs(), | |
| 390 | + 'controls' => $plugin->controls_manager->get_controls_data(), | |
| 391 | + 'elements' => $plugin->elements_manager->get_element_types_config(), | |
| 392 | + 'schemes' => [ | |
| 393 | + 'items' => $plugin->schemes_manager->get_registered_schemes_data(), | |
| 394 | + 'enabled_schemes' => Schemes_Manager::get_enabled_schemes(), | |
| 395 | + ], | |
| 396 | + 'globals' => [ | |
| 397 | + 'defaults_enabled' => [ | |
| 398 | + 'colors' => $kits_manager->is_custom_colors_enabled(), | |
| 399 | + 'typography' => $kits_manager->is_custom_typography_enabled(), | |
| 400 | + ], | |
| 401 | + ], | |
| 402 | + 'icons' => [ | |
| 403 | + 'libraries' => Icons_Manager::get_icon_manager_tabs_config(), | |
| 404 | + 'goProURL' => 'https://go.elementor.com/go-pro-icon-library/', | |
| 405 | + ], | |
| 406 | + 'fa4_to_fa5_mapping_url' => ELEMENTOR_ASSETS_URL . 'lib/font-awesome/migration/mapping.js', | |
| 407 | + 'default_schemes' => $plugin->schemes_manager->get_schemes_defaults(), | |
| 408 | + 'settings' => $settings, | |
| 409 | + 'system_schemes' => $plugin->schemes_manager->get_system_schemes(), | |
| 410 | + 'wp_editor' => $this->get_wp_editor_config(), | |
| 411 | + 'settings_page_link' => Settings::get_url(), | |
| 412 | + 'tools_page_link' => Tools::get_url(), | |
| 413 | + 'tools_page_nonce' => wp_create_nonce( 'tools-page-from-editor' ), | |
| 414 | + 'elementor_site' => 'https://go.elementor.com/about-elementor/', | |
| 415 | + 'docs_elementor_site' => 'https://go.elementor.com/docs/', | |
| 416 | + 'help_the_content_url' => 'https://go.elementor.com/the-content-missing/', | |
| 417 | + 'help_flexbox_bc_url' => 'https://go.elementor.com/flexbox-layout-bc/', | |
| 418 | + 'elementPromotionURL' => 'https://go.elementor.com/go-pro-%s', | |
| 419 | + 'dynamicPromotionURL' => 'https://go.elementor.com/go-pro-dynamic-tag', | |
| 420 | + 'additional_shapes' => Shapes::get_additional_shapes_for_config(), | |
| 421 | + 'user' => [ | |
| 422 | + 'restrictions' => $plugin->role_manager->get_user_restrictions_array(), | |
| 423 | + 'is_administrator' => current_user_can( 'manage_options' ), | |
| 424 | + 'introduction' => User::get_introduction_meta(), | |
| 425 | + 'locale' => get_user_locale(), | |
| 426 | + ], | |
| 427 | + 'preview' => [ | |
| 428 | + 'help_preview_error_url' => 'https://go.elementor.com/preview-not-loaded/', | |
| 429 | + 'help_preview_http_error_url' => 'https://go.elementor.com/preview-not-loaded/#permissions', | |
| 430 | + 'help_preview_http_error_500_url' => 'https://go.elementor.com/500-error/', | |
| 431 | + 'debug_data' => Loading_Inspection_Manager::instance()->run_inspections(), | |
| 432 | + ], | |
| 433 | + 'locale' => get_locale(), | |
| 434 | + 'rich_editing_enabled' => filter_var( get_user_meta( get_current_user_id(), 'rich_editing', true ), FILTER_VALIDATE_BOOLEAN ), | |
| 435 | + 'page_title_selector' => $page_title_selector, | |
| 436 | + 'tinymceHasCustomConfig' => class_exists( 'Tinymce_Advanced' ) || class_exists( 'Advanced_Editor_Tools' ), | |
| 437 | + 'inlineEditing' => Plugin::$instance->widgets_manager->get_inline_editing_config(), | |
| 438 | + 'dynamicTags' => Plugin::$instance->dynamic_tags->get_config(), | |
| 439 | + 'ui' => [ | |
| 440 | + 'darkModeStylesheetURL' => ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css', | |
| 441 | + 'defaultGenericFonts' => $kits_manager->get_current_settings( 'default_generic_fonts' ), | |
| 442 | + ], | |
| 443 | + // Empty array for BC to avoid errors. | |
| 444 | + 'i18n' => [], | |
| 445 | + // 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0 | |
| 446 | + 'responsive' => [ | |
| 447 | + 'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(), | |
| 448 | + 'icons_map' => Plugin::$instance->breakpoints->get_responsive_icons_classes_map(), | |
| 449 | + ], | |
| 450 | + 'promotion' => [ | |
| 451 | + 'elements' => $this->promotion->get_elements_promotion(), | |
| 452 | + ], | |
| 453 | + ]; | |
| 454 | + | |
| 455 | + if ( ! Utils::has_pro() && current_user_can( 'manage_options' ) ) { | |
| 456 | + $config['promotionWidgets'] = Api::get_promotion_widgets(); | |
| 457 | + } | |
| 458 | + | |
| 459 | + $this->bc_move_document_filters(); | |
| 460 | + | |
| 461 | + /** | |
| 462 | + * Localize editor settings. | |
| 463 | + * | |
| 464 | + * Filters the editor localized settings. | |
| 465 | + * | |
| 466 | + * @since 1.0.0 | |
| 467 | + * | |
| 468 | + * @param array $config Editor configuration. | |
| 469 | + * @param int $post_id The ID of the current post being edited. | |
| 470 | + */ | |
| 471 | + $config = apply_filters( 'elementor/editor/localize_settings', $config ); | |
| 472 | + | |
| 473 | + Utils::print_js_config( 'elementor-editor', 'ElementorConfig', $config ); | |
| 474 | + | |
| 357 | 475 | $this->get_loader()->enqueue_scripts(); |
| 476 | + $this->get_loader()->load_scripts_translations(); | |
| 358 | 477 | |
| 359 | - Plugin::$instance->controls_manager->enqueue_control_scripts(); | |
| 478 | + $plugin->controls_manager->enqueue_control_scripts(); | |
| 360 | 479 | |
| 361 | 480 | /** |
| 362 | 481 | * After editor enqueue scripts. |
| 363 | 482 | * |
| @@ -385,13 +504,33 @@ | ||
| 385 | 504 | * @since 1.0.0 |
| 386 | 505 | */ |
| 387 | 506 | do_action( 'elementor/editor/before_enqueue_styles' ); |
| 388 | 507 | |
| 508 | + $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 509 | + | |
| 389 | 510 | $this->get_loader()->register_styles(); |
| 390 | 511 | $this->get_loader()->enqueue_styles(); |
| 391 | 512 | |
| 392 | - $this->enqueue_theme_ui_styles(); | |
| 513 | + $ui_theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); | |
| 393 | 514 | |
| 515 | + if ( 'light' !== $ui_theme ) { | |
| 516 | + $ui_theme_media_queries = 'all'; | |
| 517 | + | |
| 518 | + if ( 'auto' === $ui_theme ) { | |
| 519 | + $ui_theme_media_queries = '(prefers-color-scheme: dark)'; | |
| 520 | + } | |
| 521 | + | |
| 522 | + wp_enqueue_style( | |
| 523 | + 'elementor-editor-dark-mode', | |
| 524 | + ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css', | |
| 525 | + [ | |
| 526 | + 'elementor-editor', | |
| 527 | + ], | |
| 528 | + ELEMENTOR_VERSION, | |
| 529 | + $ui_theme_media_queries | |
| 530 | + ); | |
| 531 | + } | |
| 532 | + | |
| 394 | 533 | $breakpoints = Plugin::$instance->breakpoints->get_breakpoints(); |
| 395 | 534 | |
| 396 | 535 | // The two breakpoints under 'tablet' need to be checked for values. |
| 397 | 536 | if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) { |
| @@ -410,44 +549,51 @@ | ||
| 410 | 549 | */ |
| 411 | 550 | do_action( 'elementor/editor/after_enqueue_styles' ); |
| 412 | 551 | } |
| 413 | 552 | |
| 414 | - private function enqueue_theme_ui_styles() { | |
| 415 | - $ui_theme_selected = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); | |
| 553 | + /** | |
| 554 | + * Get WordPress editor config. | |
| 555 | + * | |
| 556 | + * Config the default WordPress editor with custom settings for Elementor use. | |
| 557 | + * | |
| 558 | + * @since 1.9.0 | |
| 559 | + * @access private | |
| 560 | + */ | |
| 561 | + private function get_wp_editor_config() { | |
| 562 | + // Remove all TinyMCE plugins. | |
| 563 | + remove_all_filters( 'mce_buttons', 10 ); | |
| 564 | + remove_all_filters( 'mce_external_plugins', 10 ); | |
| 416 | 565 | |
| 417 | - $ui_themes = [ | |
| 418 | - 'light', | |
| 419 | - 'dark', | |
| 420 | - ]; | |
| 566 | + if ( ! class_exists( '\_WP_Editors', false ) ) { | |
| 567 | + require ABSPATH . WPINC . '/class-wp-editor.php'; | |
| 568 | + } | |
| 421 | 569 | |
| 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'; | |
| 570 | + // WordPress 4.8 and higher | |
| 571 | + if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) { | |
| 572 | + \_WP_Editors::print_default_editor_scripts(); | |
| 573 | + \_WP_Editors::print_tinymce_scripts(); | |
| 574 | + } | |
| 575 | + ob_start(); | |
| 428 | 576 | |
| 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 | - } | |
| 577 | + wp_editor( | |
| 578 | + '%%EDITORCONTENT%%', | |
| 579 | + 'elementorwpeditor', | |
| 580 | + [ | |
| 581 | + 'editor_class' => 'elementor-wp-editor', | |
| 582 | + 'editor_height' => 250, | |
| 583 | + 'drag_drop_upload' => true, | |
| 584 | + ] | |
| 585 | + ); | |
| 435 | 586 | |
| 436 | - $this->enqueue_theme_ui( 'light', $ui_light_theme_media_queries ); | |
| 437 | - $this->enqueue_theme_ui( 'dark', $ui_dark_theme_media_queries ); | |
| 438 | - } | |
| 587 | + $config = ob_get_clean(); | |
| 439 | 588 | |
| 440 | - private function enqueue_theme_ui( $ui_theme, $ui_theme_media_queries = 'all' ) { | |
| 441 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 589 | + // Don't call \_WP_Editors methods again | |
| 590 | + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 ); | |
| 591 | + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 ); | |
| 442 | 592 | |
| 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 | - ); | |
| 593 | + \_WP_Editors::editor_js(); | |
| 594 | + | |
| 595 | + return $config; | |
| 450 | 596 | } |
| 451 | 597 | |
| 452 | 598 | /** |
| 453 | 599 | * Editor head trigger. |
| @@ -488,11 +634,13 @@ | ||
| 488 | 634 | $plugin->controls_manager->render_controls(); |
| 489 | 635 | $plugin->widgets_manager->render_widgets_content(); |
| 490 | 636 | $plugin->elements_manager->render_elements_content(); |
| 491 | 637 | |
| 638 | + $plugin->schemes_manager->print_schemes_templates(); | |
| 639 | + | |
| 492 | 640 | $plugin->dynamic_tags->print_templates(); |
| 493 | 641 | |
| 494 | - $this->get_loader()->register_additional_templates(); | |
| 642 | + $this->init_editor_templates(); | |
| 495 | 643 | |
| 496 | 644 | /** |
| 497 | 645 | * Elementor editor footer. |
| 498 | 646 | * |
| @@ -536,92 +684,16 @@ | ||
| 536 | 684 | |
| 537 | 685 | add_action( 'admin_action_elementor', [ $this, 'init' ] ); |
| 538 | 686 | add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] ); |
| 539 | 687 | |
| 688 | + $this->register_editor_v2_experiment(); | |
| 689 | + | |
| 540 | 690 | // Handle autocomplete feature for URL control. |
| 541 | 691 | add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] ); |
| 542 | 692 | add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] ); |
| 543 | - | |
| 544 | - add_filter( 'replace_editor', [ $this, 'filter_replace_editor' ], 10, 2 ); | |
| 545 | 693 | } |
| 546 | 694 | |
| 547 | 695 | /** |
| 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 | 696 | * @since 2.2.0 |
| 625 | 697 | * @access public |
| 626 | 698 | */ |
| 627 | 699 | public function filter_wp_link_query_args( $query ) { |
| @@ -653,71 +725,88 @@ | ||
| 653 | 725 | |
| 654 | 726 | return $results; |
| 655 | 727 | } |
| 656 | 728 | |
| 657 | - public function set_post_id( $post_id ) { | |
| 658 | - $this->post_id = $post_id; | |
| 659 | - } | |
| 660 | - | |
| 661 | 729 | /** |
| 662 | - * Get loader. | |
| 730 | + * Init editor templates. | |
| 663 | 731 | * |
| 664 | - * @return Editor_Loader_Interface | |
| 732 | + * Initialize default elementor templates used in the editor panel. | |
| 733 | + * | |
| 734 | + * @since 1.7.0 | |
| 735 | + * @access private | |
| 665 | 736 | */ |
| 666 | - private function get_loader() { | |
| 667 | - if ( ! $this->loader ) { | |
| 668 | - $this->loader = Editor_Loader_Factory::create(); | |
| 737 | + private function init_editor_templates() { | |
| 738 | + $template_names = [ | |
| 739 | + 'global', | |
| 740 | + 'panel', | |
| 741 | + 'panel-elements', | |
| 742 | + 'repeater', | |
| 743 | + 'templates', | |
| 744 | + 'navigator', | |
| 745 | + 'hotkeys', | |
| 746 | + 'responsive-bar', | |
| 747 | + ]; | |
| 669 | 748 | |
| 670 | - $this->loader->init(); | |
| 749 | + foreach ( $template_names as $template_name ) { | |
| 750 | + Plugin::$instance->common->add_template( ELEMENTOR_PATH . "includes/editor-templates/$template_name.php" ); | |
| 671 | 751 | } |
| 752 | + } | |
| 672 | 753 | |
| 673 | - return $this->loader; | |
| 674 | - } | |
| 754 | + private function bc_move_document_filters() { | |
| 755 | + global $wp_filter; | |
| 675 | 756 | |
| 676 | - /** | |
| 677 | - * Get elements presets. | |
| 678 | - * | |
| 679 | - * @return array | |
| 680 | - */ | |
| 681 | - public function get_elements_presets() { | |
| 682 | - $element_types = Plugin::$instance->elements_manager->get_element_types(); | |
| 683 | - $presets = []; | |
| 757 | + $old_tag = 'elementor/editor/localize_settings'; | |
| 758 | + $new_tag = 'elementor/document/config'; | |
| 684 | 759 | |
| 685 | - foreach ( $element_types as $el_type => $element ) { | |
| 686 | - $this->check_element_for_presets( $element, $el_type, $presets ); | |
| 760 | + if ( ! has_filter( $old_tag ) ) { | |
| 761 | + return; | |
| 687 | 762 | } |
| 688 | 763 | |
| 689 | - return $presets; | |
| 690 | - } | |
| 764 | + foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) { | |
| 765 | + foreach ( $filters as $filter_id => $filter_args ) { | |
| 766 | + if ( 2 === $filter_args['accepted_args'] ) { | |
| 767 | + remove_filter( $old_tag, $filter_id, $priority ); | |
| 691 | 768 | |
| 692 | - /** | |
| 693 | - * @return void | |
| 694 | - */ | |
| 695 | - private function check_element_for_presets( $element, $el_type, &$presets ) { | |
| 696 | - $element_presets = $element->get_panel_presets(); | |
| 769 | + add_filter( $new_tag, $filter_args['function'], $priority, 2 ); | |
| 697 | 770 | |
| 698 | - if ( empty( $element_presets ) ) { | |
| 699 | - return; | |
| 771 | + // TODO: Hard deprecation | |
| 772 | + // _deprecated_hook( '`' . $old_tag . ` is no longer using post_id', '2.9.0', $new_tag' ); | |
| 773 | + } | |
| 774 | + } | |
| 700 | 775 | } |
| 776 | + } | |
| 701 | 777 | |
| 702 | - foreach ( $element_presets as $key => $preset ) { | |
| 703 | - $this->maybe_add_preset( $el_type, $preset, $key, $presets ); | |
| 704 | - } | |
| 778 | + public function set_post_id( $post_id ) { | |
| 779 | + $this->post_id = $post_id; | |
| 705 | 780 | } |
| 706 | 781 | |
| 707 | 782 | /** |
| 708 | - * @return void | |
| 783 | + * Get loader. | |
| 784 | + * | |
| 785 | + * @return Editor_Loader | |
| 709 | 786 | */ |
| 710 | - private function maybe_add_preset( $el_type, $preset, $key, &$presets ) { | |
| 711 | - if ( $this->is_valid_preset( $el_type, $preset ) ) { | |
| 712 | - $presets[ $key ] = $preset; | |
| 787 | + private function get_loader() { | |
| 788 | + if ( ! $this->loader ) { | |
| 789 | + $this->loader = new Editor_Loader( Config_Provider_Factory::create() ); | |
| 790 | + $this->loader->register_hooks(); | |
| 713 | 791 | } |
| 792 | + | |
| 793 | + return $this->loader; | |
| 714 | 794 | } |
| 715 | 795 | |
| 716 | 796 | /** |
| 717 | - * @return boolean | |
| 797 | + * Adding Editor V2 experiment. | |
| 798 | + * | |
| 799 | + * @return void | |
| 800 | + * @throws \Exception | |
| 718 | 801 | */ |
| 719 | - private function is_valid_preset( $el_type, $preset ) { | |
| 720 | - return isset( $preset['replacements']['custom']['originalWidget'] ) | |
| 721 | - && $el_type === $preset['replacements']['custom']['originalWidget']; | |
| 802 | + private function register_editor_v2_experiment() { | |
| 803 | + Plugin::$instance->experiments->add_feature( [ | |
| 804 | + 'name' => static::EDITOR_V2_EXPERIMENT_NAME, | |
| 805 | + 'title' => esc_html__( 'Editor V2', 'elementor' ), | |
| 806 | + 'description' => esc_html__( 'Enable the new editor.', 'elementor' ), | |
| 807 | + 'hidden' => true, | |
| 808 | + 'default' => Experiments_Manager::STATE_INACTIVE, | |
| 809 | + 'status' => Experiments_Manager::RELEASE_STATUS_ALPHA, | |
| 810 | + ] ); | |
| 722 | 811 | } |
| 723 | 812 | } |