| @@ -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 | |
| @@ -156,12 +159,12 @@ | ||
| 156 | 159 | Utils::do_not_cache(); |
| 157 | 160 | |
| 158 | 161 | do_action( 'elementor/editor/init' ); |
| 159 | 162 | |
| 160 | - $this->get_loader()->print_root_template(); | |
| 163 | + $this->print_editor_template(); | |
| 161 | 164 | |
| 162 | 165 | // From the action it's an empty string, from tests its `false` |
| 163 | - if ( false !== $to_die ) { | |
| 166 | + if ( false !== $die ) { | |
| 164 | 167 | die; |
| 165 | 168 | } |
| 166 | 169 | } |
| 167 | 170 | |
| @@ -197,9 +200,9 @@ | ||
| 197 | 200 | |
| 198 | 201 | $document = Plugin::$instance->documents->get( get_the_ID() ); |
| 199 | 202 | |
| 200 | 203 | if ( ! $document ) { |
| 201 | - wp_die( esc_html__( 'Document not found.', 'elementor' ) ); | |
| 204 | + wp_die( __( 'Document not found.', 'elementor' ) ); | |
| 202 | 205 | } |
| 203 | 206 | |
| 204 | 207 | if ( ! $document->is_editable_by_current_user() || ! $document->is_built_with_elementor() ) { |
| 205 | 208 | return; |
| @@ -307,10 +310,8 @@ | ||
| 307 | 310 | return get_user_by( 'id', $locked_user ); |
| 308 | 311 | } |
| 309 | 312 | |
| 310 | 313 | /** |
| 311 | - * NOTICE: This method not in use, it's here for backward compatibility. | |
| 312 | - * | |
| 313 | 314 | * Print Editor Template. |
| 314 | 315 | * |
| 315 | 316 | * Include the wrapper template of the editor. |
| 316 | 317 | * |
| @@ -333,14 +334,173 @@ | ||
| 333 | 334 | remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 ); |
| 334 | 335 | |
| 335 | 336 | global $wp_styles, $wp_scripts; |
| 336 | 337 | |
| 338 | + $plugin = Plugin::$instance; | |
| 339 | + | |
| 337 | 340 | // Reset global variable |
| 338 | 341 | $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 339 | 342 | $wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 340 | 343 | |
| 341 | - $this->get_loader()->register_scripts(); | |
| 344 | + $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS ) ? '' : '.min'; | |
| 342 | 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 | + | |
| 343 | 503 | /** |
| 344 | 504 | * Before editor enqueue scripts. |
| 345 | 505 | * |
| 346 | 506 | * Fires before Elementor editor scripts are enqueued. |
| @@ -351,13 +511,115 @@ | ||
| 351 | 511 | |
| 352 | 512 | // Tweak for WP Admin menu icons |
| 353 | 513 | wp_print_styles( 'editor-buttons' ); |
| 354 | 514 | |
| 355 | - $this->get_loader()->enqueue_scripts(); | |
| 515 | + $settings = SettingsManager::get_settings_managers_config(); | |
| 516 | + // Moved to document since 2.9.0. | |
| 517 | + unset( $settings['page'] ); | |
| 356 | 518 | |
| 357 | - 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; | |
| 358 | 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 | + 'experimentalFeatures' => $active_experimental_features, | |
| 593 | + ]; | |
| 594 | + | |
| 595 | + if ( ! Utils::has_pro() && current_user_can( 'manage_options' ) ) { | |
| 596 | + $config['promotionWidgets'] = Api::get_promotion_widgets(); | |
| 597 | + } | |
| 598 | + | |
| 599 | + $this->bc_move_document_filters(); | |
| 600 | + | |
| 359 | 601 | /** |
| 602 | + * Localize editor settings. | |
| 603 | + * | |
| 604 | + * Filters the editor localized settings. | |
| 605 | + * | |
| 606 | + * @since 1.0.0 | |
| 607 | + * | |
| 608 | + * @param array $config Editor configuration. | |
| 609 | + * @param int $post_id The ID of the current post being edited. | |
| 610 | + */ | |
| 611 | + $config = apply_filters( 'elementor/editor/localize_settings', $config ); | |
| 612 | + | |
| 613 | + Utils::print_js_config( 'elementor-editor', 'ElementorConfig', $config ); | |
| 614 | + | |
| 615 | + wp_enqueue_script( 'elementor-editor' ); | |
| 616 | + | |
| 617 | + wp_set_script_translations( 'elementor-editor', 'elementor' ); | |
| 618 | + | |
| 619 | + $plugin->controls_manager->enqueue_control_scripts(); | |
| 620 | + | |
| 621 | + /** | |
| 360 | 622 | * After editor enqueue scripts. |
| 361 | 623 | * |
| 362 | 624 | * Fires after Elementor editor scripts are enqueued. |
| 363 | 625 | * |
| @@ -383,23 +645,90 @@ | ||
| 383 | 645 | * @since 1.0.0 |
| 384 | 646 | */ |
| 385 | 647 | do_action( 'elementor/editor/before_enqueue_styles' ); |
| 386 | 648 | |
| 387 | - $this->get_loader()->register_styles(); | |
| 388 | - $this->get_loader()->enqueue_styles(); | |
| 649 | + $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 389 | 650 | |
| 390 | - $this->enqueue_theme_ui_styles(); | |
| 651 | + $direction_suffix = is_rtl() ? '-rtl' : ''; | |
| 391 | 652 | |
| 392 | - $breakpoints = Plugin::$instance->breakpoints->get_breakpoints(); | |
| 653 | + wp_register_style( | |
| 654 | + 'font-awesome', | |
| 655 | + ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome' . $suffix . '.css', | |
| 656 | + [], | |
| 657 | + '4.7.0' | |
| 658 | + ); | |
| 393 | 659 | |
| 394 | - // The two breakpoints under 'tablet' need to be checked for values. | |
| 395 | - if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) { | |
| 396 | - wp_add_inline_style( | |
| 397 | - 'elementor-editor', | |
| 398 | - '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . Plugin::$instance->breakpoints->get_device_min_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_TABLET ) . 'px; }' | |
| 660 | + wp_register_style( | |
| 661 | + 'elementor-select2', | |
| 662 | + ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2' . $suffix . '.css', | |
| 663 | + [], | |
| 664 | + '4.0.6-rc.1' | |
| 665 | + ); | |
| 666 | + | |
| 667 | + wp_register_style( | |
| 668 | + 'google-font-roboto', | |
| 669 | + 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700', | |
| 670 | + [], | |
| 671 | + ELEMENTOR_VERSION | |
| 672 | + ); | |
| 673 | + | |
| 674 | + wp_register_style( | |
| 675 | + 'flatpickr', | |
| 676 | + ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.css', | |
| 677 | + [], | |
| 678 | + '1.12.0' | |
| 679 | + ); | |
| 680 | + | |
| 681 | + wp_register_style( | |
| 682 | + 'pickr', | |
| 683 | + ELEMENTOR_ASSETS_URL . 'lib/pickr/themes/monolith.min.css', | |
| 684 | + [], | |
| 685 | + '1.5.0' | |
| 686 | + ); | |
| 687 | + | |
| 688 | + wp_register_style( | |
| 689 | + 'elementor-editor', | |
| 690 | + ELEMENTOR_ASSETS_URL . 'css/editor' . $direction_suffix . $suffix . '.css', | |
| 691 | + [ | |
| 692 | + 'elementor-common', | |
| 693 | + 'elementor-select2', | |
| 694 | + 'elementor-icons', | |
| 695 | + 'wp-auth-check', | |
| 696 | + 'google-font-roboto', | |
| 697 | + 'flatpickr', | |
| 698 | + 'pickr', | |
| 699 | + ], | |
| 700 | + ELEMENTOR_VERSION | |
| 701 | + ); | |
| 702 | + | |
| 703 | + wp_enqueue_style( 'elementor-editor' ); | |
| 704 | + | |
| 705 | + $ui_theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); | |
| 706 | + | |
| 707 | + if ( 'light' !== $ui_theme ) { | |
| 708 | + $ui_theme_media_queries = 'all'; | |
| 709 | + | |
| 710 | + if ( 'auto' === $ui_theme ) { | |
| 711 | + $ui_theme_media_queries = '(prefers-color-scheme: dark)'; | |
| 712 | + } | |
| 713 | + | |
| 714 | + wp_enqueue_style( | |
| 715 | + 'elementor-editor-dark-mode', | |
| 716 | + ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css', | |
| 717 | + [ | |
| 718 | + 'elementor-editor', | |
| 719 | + ], | |
| 720 | + ELEMENTOR_VERSION, | |
| 721 | + $ui_theme_media_queries | |
| 399 | 722 | ); |
| 400 | 723 | } |
| 401 | 724 | |
| 725 | + if ( Responsive::has_custom_breakpoints() ) { | |
| 726 | + $breakpoints = Responsive::get_breakpoints(); | |
| 727 | + | |
| 728 | + wp_add_inline_style( 'elementor-editor', '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . $breakpoints['md'] . 'px; }' ); | |
| 729 | + } | |
| 730 | + | |
| 402 | 731 | /** |
| 403 | 732 | * After editor enqueue styles. |
| 404 | 733 | * |
| 405 | 734 | * Fires after Elementor editor styles are enqueued. |
| @@ -408,44 +737,51 @@ | ||
| 408 | 737 | */ |
| 409 | 738 | do_action( 'elementor/editor/after_enqueue_styles' ); |
| 410 | 739 | } |
| 411 | 740 | |
| 412 | - private function enqueue_theme_ui_styles() { | |
| 413 | - $ui_theme_selected = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); | |
| 741 | + /** | |
| 742 | + * Get WordPress editor config. | |
| 743 | + * | |
| 744 | + * Config the default WordPress editor with custom settings for Elementor use. | |
| 745 | + * | |
| 746 | + * @since 1.9.0 | |
| 747 | + * @access private | |
| 748 | + */ | |
| 749 | + private function get_wp_editor_config() { | |
| 750 | + // Remove all TinyMCE plugins. | |
| 751 | + remove_all_filters( 'mce_buttons', 10 ); | |
| 752 | + remove_all_filters( 'mce_external_plugins', 10 ); | |
| 414 | 753 | |
| 415 | - $ui_themes = [ | |
| 416 | - 'light', | |
| 417 | - 'dark', | |
| 418 | - ]; | |
| 754 | + if ( ! class_exists( '\_WP_Editors', false ) ) { | |
| 755 | + require ABSPATH . WPINC . '/class-wp-editor.php'; | |
| 756 | + } | |
| 419 | 757 | |
| 420 | - if ( 'auto' === $ui_theme_selected || ! in_array( $ui_theme_selected, $ui_themes, true ) ) { | |
| 421 | - $ui_light_theme_media_queries = '(prefers-color-scheme: light)'; | |
| 422 | - $ui_dark_theme_media_queries = '(prefers-color-scheme: dark)'; | |
| 423 | - } else { | |
| 424 | - $ui_light_theme_media_queries = 'none'; | |
| 425 | - $ui_dark_theme_media_queries = 'none'; | |
| 758 | + // WordPress 4.8 and higher | |
| 759 | + if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) { | |
| 760 | + \_WP_Editors::print_default_editor_scripts(); | |
| 761 | + \_WP_Editors::print_tinymce_scripts(); | |
| 762 | + } | |
| 763 | + ob_start(); | |
| 426 | 764 | |
| 427 | - if ( 'light' === $ui_theme_selected ) { | |
| 428 | - $ui_light_theme_media_queries = 'all'; | |
| 429 | - } elseif ( 'dark' === $ui_theme_selected ) { | |
| 430 | - $ui_dark_theme_media_queries = 'all'; | |
| 431 | - } | |
| 432 | - } | |
| 765 | + wp_editor( | |
| 766 | + '%%EDITORCONTENT%%', | |
| 767 | + 'elementorwpeditor', | |
| 768 | + [ | |
| 769 | + 'editor_class' => 'elementor-wp-editor', | |
| 770 | + 'editor_height' => 250, | |
| 771 | + 'drag_drop_upload' => true, | |
| 772 | + ] | |
| 773 | + ); | |
| 433 | 774 | |
| 434 | - $this->enqueue_theme_ui( 'light', $ui_light_theme_media_queries ); | |
| 435 | - $this->enqueue_theme_ui( 'dark', $ui_dark_theme_media_queries ); | |
| 436 | - } | |
| 775 | + $config = ob_get_clean(); | |
| 437 | 776 | |
| 438 | - private function enqueue_theme_ui( $ui_theme, $ui_theme_media_queries = 'all' ) { | |
| 439 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 777 | + // Don't call \_WP_Editors methods again | |
| 778 | + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 ); | |
| 779 | + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 ); | |
| 440 | 780 | |
| 441 | - wp_enqueue_style( | |
| 442 | - 'e-theme-ui-' . $ui_theme, | |
| 443 | - ELEMENTOR_ASSETS_URL . 'css/theme-' . $ui_theme . $suffix . '.css', | |
| 444 | - [], | |
| 445 | - ELEMENTOR_VERSION, | |
| 446 | - $ui_theme_media_queries | |
| 447 | - ); | |
| 781 | + \_WP_Editors::editor_js(); | |
| 782 | + | |
| 783 | + return $config; | |
| 448 | 784 | } |
| 449 | 785 | |
| 450 | 786 | /** |
| 451 | 787 | * Editor head trigger. |
| @@ -469,8 +805,32 @@ | ||
| 469 | 805 | do_action( 'elementor/editor/wp_head' ); |
| 470 | 806 | } |
| 471 | 807 | |
| 472 | 808 | /** |
| 809 | + * Add editor template. | |
| 810 | + * | |
| 811 | + * Registers new editor templates. | |
| 812 | + * | |
| 813 | + * @since 1.0.0 | |
| 814 | + * @deprecated 2.3.0 Use `Plugin::$instance->common->add_template()` | |
| 815 | + * @access public | |
| 816 | + * | |
| 817 | + * @param string $template Can be either a link to template file or template | |
| 818 | + * HTML content. | |
| 819 | + * @param string $type Optional. Whether to handle the template as path | |
| 820 | + * or text. Default is `path`. | |
| 821 | + */ | |
| 822 | + public function add_editor_template( $template, $type = 'path' ) { | |
| 823 | + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->add_template()' ); | |
| 824 | + | |
| 825 | + $common = Plugin::$instance->common; | |
| 826 | + | |
| 827 | + if ( $common ) { | |
| 828 | + Plugin::$instance->common->add_template( $template, $type ); | |
| 829 | + } | |
| 830 | + } | |
| 831 | + | |
| 832 | + /** | |
| 473 | 833 | * WP footer. |
| 474 | 834 | * |
| 475 | 835 | * Prints Elementor editor with all the editor templates, and render controls, |
| 476 | 836 | * widgets and content elements. |
| @@ -486,11 +846,13 @@ | ||
| 486 | 846 | $plugin->controls_manager->render_controls(); |
| 487 | 847 | $plugin->widgets_manager->render_widgets_content(); |
| 488 | 848 | $plugin->elements_manager->render_elements_content(); |
| 489 | 849 | |
| 850 | + $plugin->schemes_manager->print_schemes_templates(); | |
| 851 | + | |
| 490 | 852 | $plugin->dynamic_tags->print_templates(); |
| 491 | 853 | |
| 492 | - $this->get_loader()->register_additional_templates(); | |
| 854 | + $this->init_editor_templates(); | |
| 493 | 855 | |
| 494 | 856 | /** |
| 495 | 857 | * Elementor editor footer. |
| 496 | 858 | * |
| @@ -526,12 +888,11 @@ | ||
| 526 | 888 | * @since 1.0.0 |
| 527 | 889 | * @access public |
| 528 | 890 | */ |
| 529 | 891 | public function __construct() { |
| 530 | - Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() ); | |
| 892 | + Plugin::$instance->data_manager->register_controller( Data\Globals\Controller::class ); | |
| 531 | 893 | |
| 532 | 894 | $this->notice_bar = new Notice_Bar(); |
| 533 | - $this->promotion = new Promotion(); | |
| 534 | 895 | |
| 535 | 896 | add_action( 'admin_action_elementor', [ $this, 'init' ] ); |
| 536 | 897 | add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] ); |
| 537 | 898 | |
| @@ -537,31 +898,11 @@ | ||
| 537 | 898 | |
| 538 | 899 | // Handle autocomplete feature for URL control. |
| 539 | 900 | add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] ); |
| 540 | 901 | add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] ); |
| 541 | - | |
| 542 | - add_filter( 'replace_editor', [ $this, 'filter_replace_editor' ], 10, 2 ); | |
| 543 | 902 | } |
| 544 | 903 | |
| 545 | 904 | /** |
| 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 | 905 | * @since 2.2.0 |
| 565 | 906 | * @access public |
| 566 | 907 | */ |
| 567 | 908 | public function filter_wp_link_query_args( $query ) { |
| @@ -577,11 +918,9 @@ | ||
| 577 | 918 | * @since 2.2.0 |
| 578 | 919 | * @access public |
| 579 | 920 | */ |
| 580 | 921 | public function filter_wp_link_query( $results ) { |
| 581 | - | |
| 582 | - // PHPCS - The user data is not used. | |
| 583 | - if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 922 | + if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { | |
| 584 | 923 | $post_type_object = get_post_type_object( 'post' ); |
| 585 | 924 | $post_label = $post_type_object->labels->singular_name; |
| 586 | 925 | |
| 587 | 926 | foreach ( $results as & $result ) { |
| @@ -593,71 +932,146 @@ | ||
| 593 | 932 | |
| 594 | 933 | return $results; |
| 595 | 934 | } |
| 596 | 935 | |
| 597 | - public function set_post_id( $post_id ) { | |
| 598 | - $this->post_id = $post_id; | |
| 936 | + /** | |
| 937 | + * Create nonce. | |
| 938 | + * | |
| 939 | + * If the user has edit capabilities, it creates a cryptographic token to | |
| 940 | + * give him access to Elementor editor. | |
| 941 | + * | |
| 942 | + * @since 1.8.1 | |
| 943 | + * @since 1.8.7 The `$post_type` parameter was introduces. | |
| 944 | + * @deprecated 2.3.0 Use `Plugin::$instance->common->get_component( 'ajax' )->create_nonce()` instead | |
| 945 | + * @access public | |
| 946 | + * | |
| 947 | + * @param string $post_type The post type to check capabilities. | |
| 948 | + * | |
| 949 | + * @return null|string The nonce token, or `null` if the user has no edit | |
| 950 | + * capabilities. | |
| 951 | + */ | |
| 952 | + public function create_nonce( $post_type ) { | |
| 953 | + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->get_component( \'ajax\' )->create_nonce()' ); | |
| 954 | + | |
| 955 | + /** @var Ajax $ajax */ | |
| 956 | + $ajax = Plugin::$instance->common->get_component( 'ajax' ); | |
| 957 | + | |
| 958 | + return $ajax->create_nonce(); | |
| 599 | 959 | } |
| 600 | 960 | |
| 601 | 961 | /** |
| 602 | - * Get loader. | |
| 962 | + * Verify nonce. | |
| 603 | 963 | * |
| 604 | - * @return Editor_Loader_Interface | |
| 964 | + * The user is given an amount of time to use the token, so therefore, since | |
| 965 | + * the user ID and `$action` remain the same, the independent variable is | |
| 966 | + * the time. | |
| 967 | + * | |
| 968 | + * @since 1.8.1 | |
| 969 | + * @deprecated 2.3.0 | |
| 970 | + * @access public | |
| 971 | + * | |
| 972 | + * @param string $nonce Nonce to verify. | |
| 973 | + * | |
| 974 | + * @return false|int If the nonce is invalid it returns `false`. If the | |
| 975 | + * nonce is valid and generated between 0-12 hours ago it | |
| 976 | + * returns `1`. If the nonce is valid and generated | |
| 977 | + * between 12-24 hours ago it returns `2`. | |
| 605 | 978 | */ |
| 606 | - private function get_loader() { | |
| 607 | - if ( ! $this->loader ) { | |
| 608 | - $this->loader = Editor_Loader_Factory::create(); | |
| 979 | + public function verify_nonce( $nonce ) { | |
| 980 | + _deprecated_function( __METHOD__, '2.3.0', 'wp_verify_nonce()' ); | |
| 609 | 981 | |
| 610 | - $this->loader->init(); | |
| 611 | - } | |
| 612 | - | |
| 613 | - return $this->loader; | |
| 982 | + return wp_verify_nonce( $nonce ); | |
| 614 | 983 | } |
| 615 | 984 | |
| 616 | 985 | /** |
| 617 | - * Get elements presets. | |
| 986 | + * Verify request nonce. | |
| 618 | 987 | * |
| 619 | - * @return array | |
| 988 | + * Whether the request nonce verified or not. | |
| 989 | + * | |
| 990 | + * @since 1.8.1 | |
| 991 | + * @deprecated 2.3.0 Use `Plugin::$instance->common->get_component( 'ajax' )->verify_request_nonce()` instead | |
| 992 | + * @access public | |
| 993 | + * | |
| 994 | + * @return bool True if request nonce verified, False otherwise. | |
| 620 | 995 | */ |
| 621 | - public function get_elements_presets() { | |
| 622 | - $element_types = Plugin::$instance->elements_manager->get_element_types(); | |
| 623 | - $presets = []; | |
| 996 | + public function verify_request_nonce() { | |
| 997 | + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->get_component( \'ajax\' )->verify_request_nonce()' ); | |
| 624 | 998 | |
| 625 | - foreach ( $element_types as $el_type => $element ) { | |
| 626 | - $this->check_element_for_presets( $element, $el_type, $presets ); | |
| 627 | - } | |
| 999 | + /** @var Ajax $ajax */ | |
| 1000 | + $ajax = Plugin::$instance->common->get_component( 'ajax' ); | |
| 628 | 1001 | |
| 629 | - return $presets; | |
| 1002 | + return $ajax->verify_request_nonce(); | |
| 630 | 1003 | } |
| 631 | 1004 | |
| 632 | 1005 | /** |
| 633 | - * @return void | |
| 1006 | + * Verify ajax nonce. | |
| 1007 | + * | |
| 1008 | + * Verify request nonce and send a JSON request, if not verified returns an | |
| 1009 | + * error. | |
| 1010 | + * | |
| 1011 | + * @since 1.9.0 | |
| 1012 | + * @deprecated 2.3.0 | |
| 1013 | + * @access public | |
| 634 | 1014 | */ |
| 635 | - private function check_element_for_presets( $element, $el_type, &$presets ) { | |
| 636 | - $element_presets = $element->get_panel_presets(); | |
| 1015 | + public function verify_ajax_nonce() { | |
| 1016 | + _deprecated_function( __METHOD__, '2.3.0' ); | |
| 637 | 1017 | |
| 638 | - if ( empty( $element_presets ) ) { | |
| 639 | - return; | |
| 640 | - } | |
| 1018 | + /** @var Ajax $ajax */ | |
| 1019 | + $ajax = Plugin::$instance->common->get_component( 'ajax' ); | |
| 641 | 1020 | |
| 642 | - foreach ( $element_presets as $key => $preset ) { | |
| 643 | - $this->maybe_add_preset( $el_type, $preset, $key, $presets ); | |
| 1021 | + if ( ! $ajax->verify_request_nonce() ) { | |
| 1022 | + wp_send_json_error( new \WP_Error( 'token_expired', 'Nonce token expired.' ) ); | |
| 644 | 1023 | } |
| 645 | 1024 | } |
| 646 | 1025 | |
| 647 | 1026 | /** |
| 648 | - * @return void | |
| 1027 | + * Init editor templates. | |
| 1028 | + * | |
| 1029 | + * Initialize default elementor templates used in the editor panel. | |
| 1030 | + * | |
| 1031 | + * @since 1.7.0 | |
| 1032 | + * @access private | |
| 649 | 1033 | */ |
| 650 | - private function maybe_add_preset( $el_type, $preset, $key, &$presets ) { | |
| 651 | - if ( $this->is_valid_preset( $el_type, $preset ) ) { | |
| 652 | - $presets[ $key ] = $preset; | |
| 1034 | + private function init_editor_templates() { | |
| 1035 | + $template_names = [ | |
| 1036 | + 'global', | |
| 1037 | + 'panel', | |
| 1038 | + 'panel-elements', | |
| 1039 | + 'repeater', | |
| 1040 | + 'templates', | |
| 1041 | + 'navigator', | |
| 1042 | + 'hotkeys', | |
| 1043 | + ]; | |
| 1044 | + | |
| 1045 | + foreach ( $template_names as $template_name ) { | |
| 1046 | + Plugin::$instance->common->add_template( ELEMENTOR_PATH . "includes/editor-templates/$template_name.php" ); | |
| 653 | 1047 | } |
| 654 | 1048 | } |
| 655 | 1049 | |
| 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']; | |
| 1050 | + private function bc_move_document_filters() { | |
| 1051 | + global $wp_filter; | |
| 1052 | + | |
| 1053 | + $old_tag = 'elementor/editor/localize_settings'; | |
| 1054 | + $new_tag = 'elementor/document/config'; | |
| 1055 | + | |
| 1056 | + if ( ! has_filter( $old_tag ) ) { | |
| 1057 | + return; | |
| 1058 | + } | |
| 1059 | + | |
| 1060 | + foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) { | |
| 1061 | + foreach ( $filters as $filter_id => $filter_args ) { | |
| 1062 | + if ( 2 === $filter_args['accepted_args'] ) { | |
| 1063 | + remove_filter( $old_tag, $filter_id, $priority ); | |
| 1064 | + | |
| 1065 | + add_filter( $new_tag, $filter_args['function'], $priority, 2 ); | |
| 1066 | + | |
| 1067 | + // TODO: Hard deprecation | |
| 1068 | + // _deprecated_hook( '`' . $old_tag . ` is no longer using post_id', '2.9.0', $new_tag' ); | |
| 1069 | + } | |
| 1070 | + } | |
| 1071 | + } | |
| 1072 | + } | |
| 1073 | + | |
| 1074 | + public function set_post_id( $post_id ) { | |
| 1075 | + $this->post_id = $post_id; | |
| 662 | 1076 | } |
| 663 | 1077 | } |