| @@ -3,10 +3,10 @@ | ||
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 5 | 5 | use Elementor\Core\Common\Modules\Ajax\Module; |
| 6 | 6 | 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; | |
| 7 | +use Elementor\Core\Editor\Config_Providers\Config_Provider_Factory; | |
| 8 | +use Elementor\Core\Experiments\Manager as Experiments_Manager; | |
| 9 | 9 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 10 | 10 | use Elementor\Plugin; |
| 11 | 11 | use Elementor\TemplateLibrary\Source_Local; |
| 12 | 12 | use Elementor\Utils; |
| @@ -30,8 +30,10 @@ | ||
| 30 | 30 | * User capability required to access Elementor editor. |
| 31 | 31 | */ |
| 32 | 32 | const EDITING_CAPABILITY = 'edit_posts'; |
| 33 | 33 | |
| 34 | + const EDITOR_V2_EXPERIMENT_NAME = 'editor_v2'; | |
| 35 | + | |
| 34 | 36 | /** |
| 35 | 37 | * Post ID. |
| 36 | 38 | * |
| 37 | 39 | * Holds the ID of the current post being edited. |
| @@ -65,9 +67,9 @@ | ||
| 65 | 67 | */ |
| 66 | 68 | public $promotion; |
| 67 | 69 | |
| 68 | 70 | /** |
| 69 | - * @var Editor_Loader_Interface | |
| 71 | + * @var Editor_Loader | |
| 70 | 72 | */ |
| 71 | 73 | private $loader; |
| 72 | 74 | |
| 73 | 75 | /** |
| @@ -80,11 +82,11 @@ | ||
| 80 | 82 | * |
| 81 | 83 | * @since 1.0.0 |
| 82 | 84 | * @access public |
| 83 | 85 | * |
| 84 | - * @param bool $to_die Optional. Whether to die at the end. Default is `true`. | |
| 86 | + * @param bool $die Optional. Whether to die at the end. Default is `true`. | |
| 85 | 87 | */ |
| 86 | - public function init( $to_die = true ) { | |
| 88 | + public function init( $die = true ) { | |
| 87 | 89 | if ( empty( $_REQUEST['post'] ) ) { |
| 88 | 90 | return; |
| 89 | 91 | } |
| 90 | 92 | |
| @@ -116,10 +118,8 @@ | ||
| 116 | 118 | |
| 117 | 119 | // Send MIME Type header like WP admin-header. |
| 118 | 120 | @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); |
| 119 | 121 | |
| 120 | - self::send_document_isolation_policy_header(); | |
| 121 | - | |
| 122 | 122 | add_filter( 'show_admin_bar', '__return_false' ); |
| 123 | 123 | |
| 124 | 124 | // Remove all WordPress actions |
| 125 | 125 | remove_all_actions( 'wp_head' ); |
| @@ -161,9 +161,9 @@ | ||
| 161 | 161 | |
| 162 | 162 | $this->get_loader()->print_root_template(); |
| 163 | 163 | |
| 164 | 164 | // From the action it's an empty string, from tests its `false` |
| 165 | - if ( false !== $to_die ) { | |
| 165 | + if ( false !== $die ) { | |
| 166 | 166 | die; |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| @@ -353,9 +353,11 @@ | ||
| 353 | 353 | |
| 354 | 354 | // Tweak for WP Admin menu icons |
| 355 | 355 | wp_print_styles( 'editor-buttons' ); |
| 356 | 356 | |
| 357 | + $this->get_loader()->print_client_settings(); | |
| 357 | 358 | $this->get_loader()->enqueue_scripts(); |
| 359 | + $this->get_loader()->load_scripts_translations(); | |
| 358 | 360 | |
| 359 | 361 | Plugin::$instance->controls_manager->enqueue_control_scripts(); |
| 360 | 362 | |
| 361 | 363 | /** |
| @@ -488,8 +490,10 @@ | ||
| 488 | 490 | $plugin->controls_manager->render_controls(); |
| 489 | 491 | $plugin->widgets_manager->render_widgets_content(); |
| 490 | 492 | $plugin->elements_manager->render_elements_content(); |
| 491 | 493 | |
| 494 | + $plugin->schemes_manager->print_schemes_templates(); | |
| 495 | + | |
| 492 | 496 | $plugin->dynamic_tags->print_templates(); |
| 493 | 497 | |
| 494 | 498 | $this->get_loader()->register_additional_templates(); |
| 495 | 499 | |
| @@ -536,92 +540,16 @@ | ||
| 536 | 540 | |
| 537 | 541 | add_action( 'admin_action_elementor', [ $this, 'init' ] ); |
| 538 | 542 | add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] ); |
| 539 | 543 | |
| 544 | + $this->register_editor_v2_experiment(); | |
| 545 | + | |
| 540 | 546 | // Handle autocomplete feature for URL control. |
| 541 | 547 | add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] ); |
| 542 | 548 | add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] ); |
| 543 | - | |
| 544 | - add_filter( 'replace_editor', [ $this, 'filter_replace_editor' ], 10, 2 ); | |
| 545 | 549 | } |
| 546 | 550 | |
| 547 | 551 | /** |
| 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 | 552 | * @since 2.2.0 |
| 625 | 553 | * @access public |
| 626 | 554 | */ |
| 627 | 555 | public function filter_wp_link_query_args( $query ) { |
| @@ -660,15 +588,14 @@ | ||
| 660 | 588 | |
| 661 | 589 | /** |
| 662 | 590 | * Get loader. |
| 663 | 591 | * |
| 664 | - * @return Editor_Loader_Interface | |
| 592 | + * @return Editor_Loader | |
| 665 | 593 | */ |
| 666 | 594 | private function get_loader() { |
| 667 | 595 | if ( ! $this->loader ) { |
| 668 | - $this->loader = Editor_Loader_Factory::create(); | |
| 669 | - | |
| 670 | - $this->loader->init(); | |
| 596 | + $this->loader = new Editor_Loader( Config_Provider_Factory::create() ); | |
| 597 | + $this->loader->register_hooks(); | |
| 671 | 598 | } |
| 672 | 599 | |
| 673 | 600 | return $this->loader; |
| 674 | 601 | } |
| @@ -673,51 +600,25 @@ | ||
| 673 | 600 | return $this->loader; |
| 674 | 601 | } |
| 675 | 602 | |
| 676 | 603 | /** |
| 677 | - * Get elements presets. | |
| 604 | + * Adding Editor V2 experiment. | |
| 678 | 605 | * |
| 679 | - * @return array | |
| 680 | - */ | |
| 681 | - public function get_elements_presets() { | |
| 682 | - $element_types = Plugin::$instance->elements_manager->get_element_types(); | |
| 683 | - $presets = []; | |
| 684 | - | |
| 685 | - foreach ( $element_types as $el_type => $element ) { | |
| 686 | - $this->check_element_for_presets( $element, $el_type, $presets ); | |
| 687 | - } | |
| 688 | - | |
| 689 | - return $presets; | |
| 690 | - } | |
| 691 | - | |
| 692 | - /** | |
| 693 | 606 | * @return void |
| 607 | + * @throws \Exception | |
| 694 | 608 | */ |
| 695 | - private function check_element_for_presets( $element, $el_type, &$presets ) { | |
| 696 | - $element_presets = $element->get_panel_presets(); | |
| 697 | - | |
| 698 | - if ( empty( $element_presets ) ) { | |
| 699 | - return; | |
| 700 | - } | |
| 701 | - | |
| 702 | - foreach ( $element_presets as $key => $preset ) { | |
| 703 | - $this->maybe_add_preset( $el_type, $preset, $key, $presets ); | |
| 704 | - } | |
| 705 | - } | |
| 706 | - | |
| 707 | - /** | |
| 708 | - * @return void | |
| 709 | - */ | |
| 710 | - private function maybe_add_preset( $el_type, $preset, $key, &$presets ) { | |
| 711 | - if ( $this->is_valid_preset( $el_type, $preset ) ) { | |
| 712 | - $presets[ $key ] = $preset; | |
| 713 | - } | |
| 714 | - } | |
| 715 | - | |
| 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']; | |
| 609 | + private function register_editor_v2_experiment() { | |
| 610 | + Plugin::$instance->experiments->add_feature( [ | |
| 611 | + 'name' => static::EDITOR_V2_EXPERIMENT_NAME, | |
| 612 | + 'title' => esc_html__( 'Editor Top Bar', 'elementor' ), | |
| 613 | + 'description' => sprintf( | |
| 614 | + esc_html__( | |
| 615 | + 'Get a sneak peek of the new Editor powered by React. The beautiful design and experimental layout of the Top bar are just some of the exciting tools on their way. %s', | |
| 616 | + 'elementor' | |
| 617 | + ), | |
| 618 | + '<a href="https://go.elementor.com/wp-dash-elementor-top-bar/" target="_blank">' . esc_html__( 'Learn more', 'elementor' ) . '</a>' | |
| 619 | + ), | |
| 620 | + 'default' => Experiments_Manager::STATE_INACTIVE, | |
| 621 | + 'status' => Experiments_Manager::RELEASE_STATUS_ALPHA, | |
| 622 | + ] ); | |
| 722 | 623 | } |
| 723 | 624 | } |