| @@ -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 | |
| @@ -159,9 +161,9 @@ | ||
| 159 | 161 | |
| 160 | 162 | $this->get_loader()->print_root_template(); |
| 161 | 163 | |
| 162 | 164 | // From the action it's an empty string, from tests its `false` |
| 163 | - if ( false !== $to_die ) { | |
| 165 | + if ( false !== $die ) { | |
| 164 | 166 | die; |
| 165 | 167 | } |
| 166 | 168 | } |
| 167 | 169 | |
| @@ -351,9 +353,11 @@ | ||
| 351 | 353 | |
| 352 | 354 | // Tweak for WP Admin menu icons |
| 353 | 355 | wp_print_styles( 'editor-buttons' ); |
| 354 | 356 | |
| 357 | + $this->get_loader()->print_client_settings(); | |
| 355 | 358 | $this->get_loader()->enqueue_scripts(); |
| 359 | + $this->get_loader()->load_scripts_translations(); | |
| 356 | 360 | |
| 357 | 361 | Plugin::$instance->controls_manager->enqueue_control_scripts(); |
| 358 | 362 | |
| 359 | 363 | /** |
| @@ -486,8 +490,10 @@ | ||
| 486 | 490 | $plugin->controls_manager->render_controls(); |
| 487 | 491 | $plugin->widgets_manager->render_widgets_content(); |
| 488 | 492 | $plugin->elements_manager->render_elements_content(); |
| 489 | 493 | |
| 494 | + $plugin->schemes_manager->print_schemes_templates(); | |
| 495 | + | |
| 490 | 496 | $plugin->dynamic_tags->print_templates(); |
| 491 | 497 | |
| 492 | 498 | $this->get_loader()->register_additional_templates(); |
| 493 | 499 | |
| @@ -534,34 +540,16 @@ | ||
| 534 | 540 | |
| 535 | 541 | add_action( 'admin_action_elementor', [ $this, 'init' ] ); |
| 536 | 542 | add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] ); |
| 537 | 543 | |
| 544 | + $this->register_editor_v2_experiment(); | |
| 545 | + | |
| 538 | 546 | // Handle autocomplete feature for URL control. |
| 539 | 547 | add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] ); |
| 540 | 548 | add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] ); |
| 541 | - | |
| 542 | - add_filter( 'replace_editor', [ $this, 'filter_replace_editor' ], 10, 2 ); | |
| 543 | 549 | } |
| 544 | 550 | |
| 545 | 551 | /** |
| 546 | - * Signals to WordPress that Elementor is replacing the block editor on its own editor page, | |
| 547 | - * so that block-editor-specific behaviour (e.g. WP 7.0 COOP/COEP isolation headers) is not | |
| 548 | - * applied when the Elementor editor is active. | |
| 549 | - * | |
| 550 | - * @param bool $replace Whether the editor is being replaced. | |
| 551 | - * @param \WP_Post $post The post being edited. | |
| 552 | - * | |
| 553 | - * @return bool | |
| 554 | - */ | |
| 555 | - public function filter_replace_editor( $replace, $post ) { | |
| 556 | - if ( isset( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 557 | - return true; | |
| 558 | - } | |
| 559 | - | |
| 560 | - return $replace; | |
| 561 | - } | |
| 562 | - | |
| 563 | - /** | |
| 564 | 552 | * @since 2.2.0 |
| 565 | 553 | * @access public |
| 566 | 554 | */ |
| 567 | 555 | public function filter_wp_link_query_args( $query ) { |
| @@ -600,15 +588,14 @@ | ||
| 600 | 588 | |
| 601 | 589 | /** |
| 602 | 590 | * Get loader. |
| 603 | 591 | * |
| 604 | - * @return Editor_Loader_Interface | |
| 592 | + * @return Editor_Loader | |
| 605 | 593 | */ |
| 606 | 594 | private function get_loader() { |
| 607 | 595 | if ( ! $this->loader ) { |
| 608 | - $this->loader = Editor_Loader_Factory::create(); | |
| 609 | - | |
| 610 | - $this->loader->init(); | |
| 596 | + $this->loader = new Editor_Loader( Config_Provider_Factory::create() ); | |
| 597 | + $this->loader->register_hooks(); | |
| 611 | 598 | } |
| 612 | 599 | |
| 613 | 600 | return $this->loader; |
| 614 | 601 | } |
| @@ -613,51 +600,25 @@ | ||
| 613 | 600 | return $this->loader; |
| 614 | 601 | } |
| 615 | 602 | |
| 616 | 603 | /** |
| 617 | - * Get elements presets. | |
| 604 | + * Adding Editor V2 experiment. | |
| 618 | 605 | * |
| 619 | - * @return array | |
| 620 | - */ | |
| 621 | - public function get_elements_presets() { | |
| 622 | - $element_types = Plugin::$instance->elements_manager->get_element_types(); | |
| 623 | - $presets = []; | |
| 624 | - | |
| 625 | - foreach ( $element_types as $el_type => $element ) { | |
| 626 | - $this->check_element_for_presets( $element, $el_type, $presets ); | |
| 627 | - } | |
| 628 | - | |
| 629 | - return $presets; | |
| 630 | - } | |
| 631 | - | |
| 632 | - /** | |
| 633 | 606 | * @return void |
| 607 | + * @throws \Exception | |
| 634 | 608 | */ |
| 635 | - private function check_element_for_presets( $element, $el_type, &$presets ) { | |
| 636 | - $element_presets = $element->get_panel_presets(); | |
| 637 | - | |
| 638 | - if ( empty( $element_presets ) ) { | |
| 639 | - return; | |
| 640 | - } | |
| 641 | - | |
| 642 | - foreach ( $element_presets as $key => $preset ) { | |
| 643 | - $this->maybe_add_preset( $el_type, $preset, $key, $presets ); | |
| 644 | - } | |
| 645 | - } | |
| 646 | - | |
| 647 | - /** | |
| 648 | - * @return void | |
| 649 | - */ | |
| 650 | - private function maybe_add_preset( $el_type, $preset, $key, &$presets ) { | |
| 651 | - if ( $this->is_valid_preset( $el_type, $preset ) ) { | |
| 652 | - $presets[ $key ] = $preset; | |
| 653 | - } | |
| 654 | - } | |
| 655 | - | |
| 656 | - /** | |
| 657 | - * @return boolean | |
| 658 | - */ | |
| 659 | - private function is_valid_preset( $el_type, $preset ) { | |
| 660 | - return isset( $preset['replacements']['custom']['originalWidget'] ) | |
| 661 | - && $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 | + ] ); | |
| 662 | 623 | } |
| 663 | 624 | } |