| @@ -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 | |
| @@ -107,9 +110,9 @@ | ||
| 107 | 110 | |
| 108 | 111 | Plugin::$instance->documents->switch_to_document( $document ); |
| 109 | 112 | |
| 110 | 113 | // Change mode to Builder |
| 111 | - $document->set_is_built_with_elementor( true ); | |
| 114 | + Plugin::$instance->db->set_is_elementor_page( $this->post_id ); | |
| 112 | 115 | |
| 113 | 116 | // End BC. |
| 114 | 117 | |
| 115 | 118 | Loading_Inspection_Manager::instance()->register_inspections(); |
| @@ -116,8 +119,11 @@ | ||
| 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 | |
| 123 | + // Temp: Allow plugins to know that the editor route is ready. TODO: Remove on 2.7.3. | |
| 124 | + define( 'ELEMENTOR_EDITOR_USE_ROUTER', true ); | |
| 125 | + | |
| 120 | 126 | add_filter( 'show_admin_bar', '__return_false' ); |
| 121 | 127 | |
| 122 | 128 | // Remove all WordPress actions |
| 123 | 129 | remove_all_actions( 'wp_head' ); |
| @@ -156,12 +162,12 @@ | ||
| 156 | 162 | Utils::do_not_cache(); |
| 157 | 163 | |
| 158 | 164 | do_action( 'elementor/editor/init' ); |
| 159 | 165 | |
| 160 | - $this->get_loader()->print_root_template(); | |
| 166 | + $this->print_editor_template(); | |
| 161 | 167 | |
| 162 | 168 | // From the action it's an empty string, from tests its `false` |
| 163 | - if ( false !== $to_die ) { | |
| 169 | + if ( false !== $die ) { | |
| 164 | 170 | die; |
| 165 | 171 | } |
| 166 | 172 | } |
| 167 | 173 | |
| @@ -197,9 +203,9 @@ | ||
| 197 | 203 | |
| 198 | 204 | $document = Plugin::$instance->documents->get( get_the_ID() ); |
| 199 | 205 | |
| 200 | 206 | if ( ! $document ) { |
| 201 | - wp_die( esc_html__( 'Document not found.', 'elementor' ) ); | |
| 207 | + wp_die( __( 'Document not found.', 'elementor' ) ); | |
| 202 | 208 | } |
| 203 | 209 | |
| 204 | 210 | if ( ! $document->is_editable_by_current_user() || ! $document->is_built_with_elementor() ) { |
| 205 | 211 | return; |
| @@ -307,10 +313,8 @@ | ||
| 307 | 313 | return get_user_by( 'id', $locked_user ); |
| 308 | 314 | } |
| 309 | 315 | |
| 310 | 316 | /** |
| 311 | - * NOTICE: This method not in use, it's here for backward compatibility. | |
| 312 | - * | |
| 313 | 317 | * Print Editor Template. |
| 314 | 318 | * |
| 315 | 319 | * Include the wrapper template of the editor. |
| 316 | 320 | * |
| @@ -333,14 +337,173 @@ | ||
| 333 | 337 | remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 ); |
| 334 | 338 | |
| 335 | 339 | global $wp_styles, $wp_scripts; |
| 336 | 340 | |
| 341 | + $plugin = Plugin::$instance; | |
| 342 | + | |
| 337 | 343 | // Reset global variable |
| 338 | 344 | $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 339 | 345 | $wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 340 | 346 | |
| 341 | - $this->get_loader()->register_scripts(); | |
| 347 | + $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS ) ? '' : '.min'; | |
| 342 | 348 | |
| 349 | + wp_register_script( | |
| 350 | + 'elementor-editor-modules', | |
| 351 | + ELEMENTOR_ASSETS_URL . 'js/editor-modules' . $suffix . '.js', | |
| 352 | + [ | |
| 353 | + 'elementor-common-modules', | |
| 354 | + ], | |
| 355 | + ELEMENTOR_VERSION, | |
| 356 | + true | |
| 357 | + ); | |
| 358 | + | |
| 359 | + wp_register_script( | |
| 360 | + 'elementor-editor-document', | |
| 361 | + ELEMENTOR_ASSETS_URL . 'js/editor-document' . $suffix . '.js', | |
| 362 | + [ | |
| 363 | + 'elementor-common-modules', | |
| 364 | + ], | |
| 365 | + ELEMENTOR_VERSION, | |
| 366 | + true | |
| 367 | + ); | |
| 368 | + // Hack for waypoint with editor mode. | |
| 369 | + wp_register_script( | |
| 370 | + 'elementor-waypoints', | |
| 371 | + ELEMENTOR_ASSETS_URL . 'lib/waypoints/waypoints-for-editor.js', | |
| 372 | + [ | |
| 373 | + 'jquery', | |
| 374 | + ], | |
| 375 | + '4.0.2', | |
| 376 | + true | |
| 377 | + ); | |
| 378 | + | |
| 379 | + wp_register_script( | |
| 380 | + 'perfect-scrollbar', | |
| 381 | + ELEMENTOR_ASSETS_URL . 'lib/perfect-scrollbar/js/perfect-scrollbar' . $suffix . '.js', | |
| 382 | + [], | |
| 383 | + '1.4.0', | |
| 384 | + true | |
| 385 | + ); | |
| 386 | + | |
| 387 | + wp_register_script( | |
| 388 | + 'jquery-easing', | |
| 389 | + ELEMENTOR_ASSETS_URL . 'lib/jquery-easing/jquery-easing' . $suffix . '.js', | |
| 390 | + [ | |
| 391 | + 'jquery', | |
| 392 | + ], | |
| 393 | + '1.3.2', | |
| 394 | + true | |
| 395 | + ); | |
| 396 | + | |
| 397 | + wp_register_script( | |
| 398 | + 'nprogress', | |
| 399 | + ELEMENTOR_ASSETS_URL . 'lib/nprogress/nprogress' . $suffix . '.js', | |
| 400 | + [], | |
| 401 | + '0.2.0', | |
| 402 | + true | |
| 403 | + ); | |
| 404 | + | |
| 405 | + wp_register_script( | |
| 406 | + 'tipsy', | |
| 407 | + ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $suffix . '.js', | |
| 408 | + [ | |
| 409 | + 'jquery', | |
| 410 | + ], | |
| 411 | + '1.0.0', | |
| 412 | + true | |
| 413 | + ); | |
| 414 | + | |
| 415 | + wp_register_script( | |
| 416 | + 'jquery-elementor-select2', | |
| 417 | + ELEMENTOR_ASSETS_URL . 'lib/e-select2/js/e-select2.full' . $suffix . '.js', | |
| 418 | + [ | |
| 419 | + 'jquery', | |
| 420 | + ], | |
| 421 | + '4.0.6-rc.1', | |
| 422 | + true | |
| 423 | + ); | |
| 424 | + | |
| 425 | + wp_register_script( | |
| 426 | + 'flatpickr', | |
| 427 | + ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.js', | |
| 428 | + [ | |
| 429 | + 'jquery', | |
| 430 | + ], | |
| 431 | + '1.12.0', | |
| 432 | + true | |
| 433 | + ); | |
| 434 | + | |
| 435 | + wp_register_script( | |
| 436 | + 'ace', | |
| 437 | + 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js', | |
| 438 | + [], | |
| 439 | + '1.2.5', | |
| 440 | + true | |
| 441 | + ); | |
| 442 | + | |
| 443 | + wp_register_script( | |
| 444 | + 'ace-language-tools', | |
| 445 | + 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ext-language_tools.js', | |
| 446 | + [ | |
| 447 | + 'ace', | |
| 448 | + ], | |
| 449 | + '1.2.5', | |
| 450 | + true | |
| 451 | + ); | |
| 452 | + | |
| 453 | + wp_register_script( | |
| 454 | + 'jquery-hover-intent', | |
| 455 | + ELEMENTOR_ASSETS_URL . 'lib/jquery-hover-intent/jquery-hover-intent' . $suffix . '.js', | |
| 456 | + [], | |
| 457 | + '1.0.0', | |
| 458 | + true | |
| 459 | + ); | |
| 460 | + | |
| 461 | + wp_register_script( | |
| 462 | + 'nouislider', | |
| 463 | + ELEMENTOR_ASSETS_URL . 'lib/nouislider/nouislider' . $suffix . '.js', | |
| 464 | + [], | |
| 465 | + '13.0.0', | |
| 466 | + true | |
| 467 | + ); | |
| 468 | + | |
| 469 | + wp_register_script( | |
| 470 | + 'pickr', | |
| 471 | + ELEMENTOR_ASSETS_URL . 'lib/pickr/pickr.min.js', | |
| 472 | + [], | |
| 473 | + '1.5.0', | |
| 474 | + true | |
| 475 | + ); | |
| 476 | + | |
| 477 | + wp_register_script( | |
| 478 | + 'elementor-editor', | |
| 479 | + ELEMENTOR_ASSETS_URL . 'js/editor' . $suffix . '.js', | |
| 480 | + [ | |
| 481 | + 'elementor-common', | |
| 482 | + 'elementor-editor-modules', | |
| 483 | + 'elementor-editor-document', | |
| 484 | + 'wp-auth-check', | |
| 485 | + 'jquery-ui-sortable', | |
| 486 | + 'jquery-ui-resizable', | |
| 487 | + 'perfect-scrollbar', | |
| 488 | + 'nprogress', | |
| 489 | + 'tipsy', | |
| 490 | + 'imagesloaded', | |
| 491 | + 'heartbeat', | |
| 492 | + 'jquery-elementor-select2', | |
| 493 | + 'flatpickr', | |
| 494 | + 'ace', | |
| 495 | + 'ace-language-tools', | |
| 496 | + 'jquery-hover-intent', | |
| 497 | + 'nouislider', | |
| 498 | + 'pickr', | |
| 499 | + 'react', | |
| 500 | + 'react-dom', | |
| 501 | + ], | |
| 502 | + ELEMENTOR_VERSION, | |
| 503 | + true | |
| 504 | + ); | |
| 505 | + | |
| 343 | 506 | /** |
| 344 | 507 | * Before editor enqueue scripts. |
| 345 | 508 | * |
| 346 | 509 | * Fires before Elementor editor scripts are enqueued. |
| @@ -351,13 +514,318 @@ | ||
| 351 | 514 | |
| 352 | 515 | // Tweak for WP Admin menu icons |
| 353 | 516 | wp_print_styles( 'editor-buttons' ); |
| 354 | 517 | |
| 355 | - $this->get_loader()->enqueue_scripts(); | |
| 518 | + $page_title_selector = Plugin::$instance->kits_manager->get_current_settings( 'page_title_selector' ); | |
| 356 | 519 | |
| 357 | - Plugin::$instance->controls_manager->enqueue_control_scripts(); | |
| 520 | + $page_title_selector .= ', .elementor-page-title'; | |
| 358 | 521 | |
| 522 | + $settings = SettingsManager::get_settings_managers_config(); | |
| 523 | + // Moved to document since 2.9.0. | |
| 524 | + unset( $settings['page'] ); | |
| 525 | + | |
| 526 | + $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post_id ); | |
| 527 | + $kits_manager = Plugin::$instance->kits_manager; | |
| 528 | + | |
| 529 | + $config = [ | |
| 530 | + 'initial_document' => $document->get_config(), | |
| 531 | + 'version' => ELEMENTOR_VERSION, | |
| 532 | + 'home_url' => home_url(), | |
| 533 | + 'admin_settings_url' => admin_url( 'admin.php?page=' . Settings::PAGE_ID ), | |
| 534 | + 'autosave_interval' => AUTOSAVE_INTERVAL, | |
| 535 | + 'tabs' => $plugin->controls_manager->get_tabs(), | |
| 536 | + 'controls' => $plugin->controls_manager->get_controls_data(), | |
| 537 | + 'elements' => $plugin->elements_manager->get_element_types_config(), | |
| 538 | + 'schemes' => [ | |
| 539 | + 'items' => $plugin->schemes_manager->get_registered_schemes_data(), | |
| 540 | + 'enabled_schemes' => Schemes_Manager::get_enabled_schemes(), | |
| 541 | + ], | |
| 542 | + 'globals' => [ | |
| 543 | + 'defaults_enabled' => [ | |
| 544 | + 'colors' => $kits_manager->is_custom_colors_enabled(), | |
| 545 | + 'typography' => $kits_manager->is_custom_typography_enabled(), | |
| 546 | + ], | |
| 547 | + ], | |
| 548 | + 'icons' => [ | |
| 549 | + 'libraries' => Icons_Manager::get_icon_manager_tabs_config(), | |
| 550 | + 'goProURL' => Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=icon-library&utm_campaign=gopro&utm_medium=wp-dash' ), | |
| 551 | + ], | |
| 552 | + 'filesUpload' => [ | |
| 553 | + 'unfilteredFiles' => Files_Upload_Handler::is_enabled(), | |
| 554 | + ], | |
| 555 | + 'fa4_to_fa5_mapping_url' => ELEMENTOR_ASSETS_URL . 'lib/font-awesome/migration/mapping.js', | |
| 556 | + 'default_schemes' => $plugin->schemes_manager->get_schemes_defaults(), | |
| 557 | + 'settings' => $settings, | |
| 558 | + 'system_schemes' => $plugin->schemes_manager->get_system_schemes(), | |
| 559 | + 'wp_editor' => $this->get_wp_editor_config(), | |
| 560 | + 'settings_page_link' => Settings::get_url(), | |
| 561 | + 'tools_page_link' => Tools::get_url(), | |
| 562 | + 'elementor_site' => 'https://go.elementor.com/about-elementor/', | |
| 563 | + 'docs_elementor_site' => 'https://go.elementor.com/docs/', | |
| 564 | + 'help_the_content_url' => 'https://go.elementor.com/the-content-missing/', | |
| 565 | + 'help_right_click_url' => 'https://go.elementor.com/meet-right-click/', | |
| 566 | + 'help_flexbox_bc_url' => 'https://go.elementor.com/flexbox-layout-bc/', | |
| 567 | + 'elementPromotionURL' => 'https://go.elementor.com/go-pro-%s', | |
| 568 | + 'dynamicPromotionURL' => 'https://go.elementor.com/go-pro-dynamic-tag', | |
| 569 | + 'additional_shapes' => Shapes::get_additional_shapes_for_config(), | |
| 570 | + 'user' => [ | |
| 571 | + 'restrictions' => $plugin->role_manager->get_user_restrictions_array(), | |
| 572 | + 'is_administrator' => current_user_can( 'manage_options' ), | |
| 573 | + 'introduction' => User::get_introduction_meta(), | |
| 574 | + ], | |
| 575 | + 'preview' => [ | |
| 576 | + 'help_preview_error_url' => 'https://go.elementor.com/preview-not-loaded/', | |
| 577 | + 'help_preview_http_error_url' => 'https://go.elementor.com/preview-not-loaded/#permissions', | |
| 578 | + 'help_preview_http_error_500_url' => 'https://go.elementor.com/500-error/', | |
| 579 | + 'debug_data' => Loading_Inspection_Manager::instance()->run_inspections(), | |
| 580 | + ], | |
| 581 | + 'locale' => get_locale(), | |
| 582 | + 'rich_editing_enabled' => filter_var( get_user_meta( get_current_user_id(), 'rich_editing', true ), FILTER_VALIDATE_BOOLEAN ), | |
| 583 | + 'page_title_selector' => $page_title_selector, | |
| 584 | + 'tinymceHasCustomConfig' => class_exists( 'Tinymce_Advanced' ), | |
| 585 | + 'inlineEditing' => Plugin::$instance->widgets_manager->get_inline_editing_config(), | |
| 586 | + 'dynamicTags' => Plugin::$instance->dynamic_tags->get_config(), | |
| 587 | + 'ui' => [ | |
| 588 | + 'darkModeStylesheetURL' => ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css', | |
| 589 | + ], | |
| 590 | + // Legacy Mode - for backwards compatibility of older HTML markup. | |
| 591 | + 'legacyMode' => [ | |
| 592 | + 'elementWrappers' => Plugin::instance()->get_legacy_mode( 'elementWrappers' ), | |
| 593 | + ], | |
| 594 | + 'i18n' => [ | |
| 595 | + 'elementor' => __( 'Elementor', 'elementor' ), | |
| 596 | + 'edit' => __( 'Edit', 'elementor' ), | |
| 597 | + 'delete' => __( 'Delete', 'elementor' ), | |
| 598 | + 'cancel' => __( 'Cancel', 'elementor' ), | |
| 599 | + 'clear' => __( 'Clear', 'elementor' ), | |
| 600 | + 'done' => __( 'Done', 'elementor' ), | |
| 601 | + 'got_it' => __( 'Got It', 'elementor' ), | |
| 602 | + /* translators: %s: Element type. */ | |
| 603 | + 'add_element' => __( 'Add %s', 'elementor' ), | |
| 604 | + /* translators: %s: Element name. */ | |
| 605 | + 'edit_element' => __( 'Edit %s', 'elementor' ), | |
| 606 | + /* translators: %s: Element type. */ | |
| 607 | + 'duplicate_element' => __( 'Duplicate %s', 'elementor' ), | |
| 608 | + /* translators: %s: Element type. */ | |
| 609 | + 'delete_element' => __( 'Delete %s', 'elementor' ), | |
| 610 | + 'flexbox_attention_header' => __( 'Note: Flexbox Changes', 'elementor' ), | |
| 611 | + 'flexbox_attention_message' => __( 'Elementor 2.5 introduces key changes to the layout using CSS Flexbox. Your existing pages might have been affected, please review your page before publishing.', 'elementor' ), | |
| 612 | + 'color_picker' => __( 'Color Picker', 'elementor' ), | |
| 613 | + | |
| 614 | + // Global Styles | |
| 615 | + 'new_global_color' => __( 'New Global Color', 'elementor' ), | |
| 616 | + 'global_colors_title' => __( 'Global Colors', 'elementor' ), | |
| 617 | + 'manage_global_colors' => __( 'Manage Global Colors', 'elementor' ), | |
| 618 | + 'create_global_color' => __( 'Create New Global Color', 'elementor' ), | |
| 619 | + 'delete_global_color' => __( 'Delete Global Color', 'elementor' ), | |
| 620 | + 'delete_global_color_info' => __( 'You\'re about to delete a Global Color. Note that if it\'s being used anywhere on your site, it will inherit a default color.', 'elementor' ), | |
| 621 | + 'global_colors_info' => __( 'Global Colors help you work smarter. Save a color, and use it anywhere throughout your site. Access and edit your global colors by clicking the Manage button.', 'elementor' ), | |
| 622 | + 'typography' => __( 'Typography', 'elementor' ), | |
| 623 | + 'new_typography_setting' => __( 'New Typography Setting', 'elementor' ), | |
| 624 | + 'global_fonts_title' => __( 'Global Fonts', 'elementor' ), | |
| 625 | + 'manage_global_fonts' => __( 'Manage Global Fonts', 'elementor' ), | |
| 626 | + 'create_global_font' => __( 'Create New Global Font', 'elementor' ), | |
| 627 | + 'delete_global_font' => __( 'Delete Global Font', 'elementor' ), | |
| 628 | + 'delete_global_font_info' => __( 'You\'re about to delete a Global Font. Note that if it\'s being used anywhere on your site, it will inherit a default typography.', 'elementor' ), | |
| 629 | + 'global_fonts_info' => __( 'Global Fonts help you work smarter. Save a Typography, and use it anywhere throughout your site. Access and edit your Global Fonts by clicking the Manage button.', 'elementor' ), | |
| 630 | + 'default' => __( 'Default', 'elementor' ), | |
| 631 | + 'create' => __( 'Create', 'elementor' ), | |
| 632 | + 'global_color_confirm_text' => __( 'Are you sure you want to create a new Global Color?', 'elementor' ), | |
| 633 | + 'global_color_already_exists' => __( 'Please note that the same exact color already exists in your Global Colors list. Are you sure you want to create it?', 'elementor' ), | |
| 634 | + 'global_color_name_already_exists' => __( 'Please note that a color with the same exact name already exists in your Global Colors list. Are you sure you want to create it?', 'elementor' ), | |
| 635 | + 'global_fonts_confirm_text' => __( 'Are you sure you want to create a new Global Font setting?', 'elementor' ), | |
| 636 | + 'custom' => __( 'Custom', 'elementor' ), | |
| 637 | + | |
| 638 | + // Menu. | |
| 639 | + 'site_settings' => __( 'Site Settings', 'elementor' ), | |
| 640 | + 'theme_builder' => __( 'Theme Builder', 'elementor' ), | |
| 641 | + 'user_preferences' => __( 'User Preferences', 'elementor' ), | |
| 642 | + 'settings' => __( 'Settings', 'elementor' ), | |
| 643 | + 'more' => __( 'More', 'elementor' ), | |
| 644 | + 'navigate_from_page' => __( 'Navigate From Page', 'elementor' ), | |
| 645 | + 'view_page' => __( 'View Page', 'elementor' ), | |
| 646 | + 'exit_to_dashboard' => __( 'Exit To Dashboard', 'elementor' ), | |
| 647 | + | |
| 648 | + // Elements. | |
| 649 | + 'inner_section' => __( 'Inner Section', 'elementor' ), | |
| 650 | + | |
| 651 | + // Control Order. | |
| 652 | + 'asc' => __( 'Ascending order', 'elementor' ), | |
| 653 | + 'desc' => __( 'Descending order', 'elementor' ), | |
| 654 | + | |
| 655 | + // Clear Page. | |
| 656 | + 'clear_page' => __( 'Delete All Content', 'elementor' ), | |
| 657 | + 'dialog_confirm_clear_page' => __( 'Attention: We are going to DELETE ALL CONTENT from this page. Are you sure you want to do that?', 'elementor' ), | |
| 658 | + | |
| 659 | + // Enable unfiltered file uploads. | |
| 660 | + 'enable_unfiltered_files_upload' => __( 'Enable Unfiltered File Uploads', 'elementor' ), | |
| 661 | + 'dialog_confirm_enable_unfiltered_files_upload' => __( 'Before you enable unfiltered files upload, note that this kind of files include a security risk. Elementor does run a process to remove possible malicious code, but there is still risk involved when using such files.', 'elementor' ), | |
| 662 | + | |
| 663 | + // Enable fontawesome 5 if needed. | |
| 664 | + 'enable_fa5' => __( 'Elementor\'s New Icon Library', 'elementor' ), | |
| 665 | + 'dialog_confirm_enable_fa5' => __( 'Elementor v2.6 includes an upgrade from Font Awesome 4 to 5. In order to continue using icons, be sure to click "Upgrade".', 'elementor' ) . ' <a href="https://go.elementor.com/fontawesome-migration/" target="_blank">' . __( 'Learn More', 'elementor' ) . '</a>', | |
| 666 | + | |
| 667 | + // Panel Preview Mode. | |
| 668 | + 'back_to_editor' => __( 'Show Panel', 'elementor' ), | |
| 669 | + 'preview' => __( 'Hide Panel', 'elementor' ), | |
| 670 | + | |
| 671 | + // Inline Editing. | |
| 672 | + 'type_here' => __( 'Type Here', 'elementor' ), | |
| 673 | + | |
| 674 | + // Library. | |
| 675 | + 'an_error_occurred' => __( 'An error occurred', 'elementor' ), | |
| 676 | + 'category' => __( 'Category', 'elementor' ), | |
| 677 | + 'delete_template' => __( 'Delete Template', 'elementor' ), | |
| 678 | + 'delete_template_confirm' => __( 'Are you sure you want to delete this template?', 'elementor' ), | |
| 679 | + 'import_template_dialog_header' => __( 'Import Document Settings', 'elementor' ), | |
| 680 | + 'import_template_dialog_message' => __( 'Do you want to also import the document settings of the template?', 'elementor' ), | |
| 681 | + 'import_template_dialog_message_attention' => __( 'Attention: Importing may override previous settings.', 'elementor' ), | |
| 682 | + 'library' => __( 'Library', 'elementor' ), | |
| 683 | + 'no' => __( 'No', 'elementor' ), | |
| 684 | + 'page' => __( 'Page', 'elementor' ), | |
| 685 | + /* translators: %s: Template type. */ | |
| 686 | + 'save_your_template' => __( 'Save Your %s to Library', 'elementor' ), | |
| 687 | + 'save_your_template_description' => __( 'Your designs will be available for export and reuse on any page or website', 'elementor' ), | |
| 688 | + 'section' => __( 'Section', 'elementor' ), | |
| 689 | + 'templates_empty_message' => __( 'This is where your templates should be. Design it. Save it. Reuse it.', 'elementor' ), | |
| 690 | + 'templates_empty_title' => __( 'Haven’t Saved Templates Yet?', 'elementor' ), | |
| 691 | + 'templates_no_favorites_message' => __( 'You can mark any pre-designed template as a favorite.', 'elementor' ), | |
| 692 | + 'templates_no_favorites_title' => __( 'No Favorite Templates', 'elementor' ), | |
| 693 | + 'templates_no_results_message' => __( 'Please make sure your search is spelled correctly or try a different words.', 'elementor' ), | |
| 694 | + 'templates_no_results_title' => __( 'No Results Found', 'elementor' ), | |
| 695 | + 'templates_request_error' => __( 'The following error(s) occurred while processing the request:', 'elementor' ), | |
| 696 | + 'yes' => __( 'Yes', 'elementor' ), | |
| 697 | + 'blocks' => __( 'Blocks', 'elementor' ), | |
| 698 | + 'pages' => __( 'Pages', 'elementor' ), | |
| 699 | + 'my_templates' => __( 'My Templates', 'elementor' ), | |
| 700 | + | |
| 701 | + // Incompatible Device. | |
| 702 | + 'device_incompatible_header' => __( 'Your browser isn\'t compatible', 'elementor' ), | |
| 703 | + 'device_incompatible_message' => __( 'Your browser isn\'t compatible with all of Elementor\'s editing features. We recommend you switch to another browser like Chrome or Firefox.', 'elementor' ), | |
| 704 | + 'proceed_anyway' => __( 'Proceed Anyway', 'elementor' ), | |
| 705 | + | |
| 706 | + // Preview not loaded. | |
| 707 | + 'learn_more' => __( 'Learn More', 'elementor' ), | |
| 708 | + 'preview_el_not_found_header' => __( 'Sorry, the content area was not found in your page.', 'elementor' ), | |
| 709 | + 'preview_el_not_found_message' => __( 'You must call \'the_content\' function in the current template, in order for Elementor to work on this page.', 'elementor' ), | |
| 710 | + | |
| 711 | + // Gallery. | |
| 712 | + 'delete_gallery' => __( 'Reset Gallery', 'elementor' ), | |
| 713 | + 'dialog_confirm_gallery_delete' => __( 'Are you sure you want to reset this gallery?', 'elementor' ), | |
| 714 | + /* translators: %s: The number of images. */ | |
| 715 | + 'gallery_images_selected' => __( '%s Images Selected', 'elementor' ), | |
| 716 | + 'gallery_no_images_selected' => __( 'No Images Selected', 'elementor' ), | |
| 717 | + 'insert_media' => __( 'Insert Media', 'elementor' ), | |
| 718 | + | |
| 719 | + // Take Over. | |
| 720 | + /* translators: %s: User name. */ | |
| 721 | + 'dialog_user_taken_over' => __( '%s has taken over and is currently editing. Do you want to take over this page editing?', 'elementor' ), | |
| 722 | + 'go_back' => __( 'Go Back', 'elementor' ), | |
| 723 | + 'take_over' => __( 'Take Over', 'elementor' ), | |
| 724 | + | |
| 725 | + // Revisions. | |
| 726 | + /* translators: %s: Template type. */ | |
| 727 | + 'dialog_confirm_delete' => __( 'Are you sure you want to remove this %s?', 'elementor' ), | |
| 728 | + | |
| 729 | + // Saver. | |
| 730 | + 'before_unload_alert' => __( 'Please note: All unsaved changes will be lost.', 'elementor' ), | |
| 731 | + 'published' => __( 'Published', 'elementor' ), | |
| 732 | + 'publish' => __( 'Publish', 'elementor' ), | |
| 733 | + 'save' => __( 'Save', 'elementor' ), | |
| 734 | + 'saved' => __( 'Saved', 'elementor' ), | |
| 735 | + 'update' => __( 'Update', 'elementor' ), | |
| 736 | + 'enable' => __( 'Enable', 'elementor' ), | |
| 737 | + 'submit' => __( 'Submit', 'elementor' ), | |
| 738 | + 'working_on_draft_notification' => __( 'This is just a draft. Play around and when you\'re done - click update.', 'elementor' ), | |
| 739 | + 'keep_editing' => __( 'Keep Editing', 'elementor' ), | |
| 740 | + 'have_a_look' => __( 'Have a look', 'elementor' ), | |
| 741 | + 'view_all_revisions' => __( 'View All Revisions', 'elementor' ), | |
| 742 | + 'dismiss' => __( 'Dismiss', 'elementor' ), | |
| 743 | + 'saving_disabled' => __( 'Saving has been disabled until you’re reconnected.', 'elementor' ), | |
| 744 | + | |
| 745 | + // Ajax | |
| 746 | + 'server_error' => __( 'Server Error', 'elementor' ), | |
| 747 | + 'server_connection_lost' => __( 'Connection Lost', 'elementor' ), | |
| 748 | + 'unknown_error' => __( 'Unknown Error', 'elementor' ), | |
| 749 | + | |
| 750 | + // Context Menu | |
| 751 | + 'duplicate' => __( 'Duplicate', 'elementor' ), | |
| 752 | + 'copy' => __( 'Copy', 'elementor' ), | |
| 753 | + 'paste' => __( 'Paste', 'elementor' ), | |
| 754 | + 'copy_style' => __( 'Copy Style', 'elementor' ), | |
| 755 | + 'paste_style' => __( 'Paste Style', 'elementor' ), | |
| 756 | + 'reset_style' => __( 'Reset Style', 'elementor' ), | |
| 757 | + 'save_as_global' => __( 'Save as a Global', 'elementor' ), | |
| 758 | + 'save_as_block' => __( 'Save as Template', 'elementor' ), | |
| 759 | + 'new_column' => __( 'Add New Column', 'elementor' ), | |
| 760 | + 'copy_all_content' => __( 'Copy All Content', 'elementor' ), | |
| 761 | + 'delete_all_content' => __( 'Delete All Content', 'elementor' ), | |
| 762 | + 'navigator' => __( 'Navigator', 'elementor' ), | |
| 763 | + | |
| 764 | + // Right Click Introduction | |
| 765 | + 'meet_right_click_header' => __( 'Meet Right Click', 'elementor' ), | |
| 766 | + 'meet_right_click_message' => __( 'Now you can access all editing actions using right click.', 'elementor' ), | |
| 767 | + | |
| 768 | + // Hotkeys screen | |
| 769 | + 'keyboard_shortcuts' => __( 'Keyboard Shortcuts', 'elementor' ), | |
| 770 | + | |
| 771 | + // Deprecated Control | |
| 772 | + 'deprecated_notice' => __( 'The <strong>%1$s</strong> widget has been deprecated since %2$s %3$s.', 'elementor' ), | |
| 773 | + 'deprecated_notice_replacement' => __( 'It has been replaced by <strong>%1$s</strong>.', 'elementor' ), | |
| 774 | + 'deprecated_notice_last' => __( 'Note that %1$s will be completely removed once %2$s %3$s is released.', 'elementor' ), | |
| 775 | + | |
| 776 | + //Preview Debug | |
| 777 | + 'preview_debug_link_text' => __( 'Click here for preview debug', 'elementor' ), | |
| 778 | + | |
| 779 | + 'icon_library' => __( 'Icon Library', 'elementor' ), | |
| 780 | + 'my_libraries' => __( 'My Libraries', 'elementor' ), | |
| 781 | + 'upload' => __( 'Upload', 'elementor' ), | |
| 782 | + 'icons_promotion' => __( 'Become a Pro user to upload unlimited font icon folders to your website.', 'elementor' ), | |
| 783 | + 'go_pro' => __( 'Go Pro', 'elementor' ), | |
| 784 | + 'custom_positioning' => __( 'Custom Positioning', 'elementor' ), | |
| 785 | + | |
| 786 | + 'element_promotion_dialog_header' => __( '%s Widget', 'elementor' ), | |
| 787 | + 'element_promotion_dialog_message' => __( 'Use %s widget and dozens more pro features to extend your toolbox and build sites faster and better.', 'elementor' ), | |
| 788 | + 'see_it_in_action' => __( 'See it in Action', 'elementor' ), | |
| 789 | + 'dynamic_content' => __( 'Dynamic Content', 'elementor' ), | |
| 790 | + 'dynamic_promotion_message' => __( 'Create more personalized and dynamic sites by populating data from various sources with dozens of dynamic tags to choose from.', 'elementor' ), | |
| 791 | + | |
| 792 | + // TODO: Remove. | |
| 793 | + 'autosave' => __( 'Autosave', 'elementor' ), | |
| 794 | + 'elementor_docs' => __( 'Documentation', 'elementor' ), | |
| 795 | + 'reload_page' => __( 'Reload Page', 'elementor' ), | |
| 796 | + 'session_expired_header' => __( 'Timeout', 'elementor' ), | |
| 797 | + 'session_expired_message' => __( 'Your session has expired. Please reload the page to continue editing.', 'elementor' ), | |
| 798 | + 'soon' => __( 'Soon', 'elementor' ), | |
| 799 | + 'unknown_value' => __( 'Unknown Value', 'elementor' ), | |
| 800 | + ], | |
| 801 | + ]; | |
| 802 | + | |
| 803 | + if ( ! Utils::has_pro() && current_user_can( 'manage_options' ) ) { | |
| 804 | + $config['promotionWidgets'] = Api::get_promotion_widgets(); | |
| 805 | + } | |
| 806 | + | |
| 807 | + $this->bc_move_document_filters(); | |
| 808 | + | |
| 359 | 809 | /** |
| 810 | + * Localize editor settings. | |
| 811 | + * | |
| 812 | + * Filters the editor localized settings. | |
| 813 | + * | |
| 814 | + * @since 1.0.0 | |
| 815 | + * | |
| 816 | + * @param array $config Editor configuration. | |
| 817 | + * @param int $post_id The ID of the current post being edited. | |
| 818 | + */ | |
| 819 | + $config = apply_filters( 'elementor/editor/localize_settings', $config ); | |
| 820 | + | |
| 821 | + Utils::print_js_config( 'elementor-editor', 'ElementorConfig', $config ); | |
| 822 | + | |
| 823 | + wp_enqueue_script( 'elementor-editor' ); | |
| 824 | + | |
| 825 | + $plugin->controls_manager->enqueue_control_scripts(); | |
| 826 | + | |
| 827 | + /** | |
| 360 | 828 | * After editor enqueue scripts. |
| 361 | 829 | * |
| 362 | 830 | * Fires after Elementor editor scripts are enqueued. |
| 363 | 831 | * |
| @@ -383,23 +851,90 @@ | ||
| 383 | 851 | * @since 1.0.0 |
| 384 | 852 | */ |
| 385 | 853 | do_action( 'elementor/editor/before_enqueue_styles' ); |
| 386 | 854 | |
| 387 | - $this->get_loader()->register_styles(); | |
| 388 | - $this->get_loader()->enqueue_styles(); | |
| 855 | + $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 389 | 856 | |
| 390 | - $this->enqueue_theme_ui_styles(); | |
| 857 | + $direction_suffix = is_rtl() ? '-rtl' : ''; | |
| 391 | 858 | |
| 392 | - $breakpoints = Plugin::$instance->breakpoints->get_breakpoints(); | |
| 859 | + wp_register_style( | |
| 860 | + 'font-awesome', | |
| 861 | + ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome' . $suffix . '.css', | |
| 862 | + [], | |
| 863 | + '4.7.0' | |
| 864 | + ); | |
| 393 | 865 | |
| 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; }' | |
| 866 | + wp_register_style( | |
| 867 | + 'elementor-select2', | |
| 868 | + ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2' . $suffix . '.css', | |
| 869 | + [], | |
| 870 | + '4.0.6-rc.1' | |
| 871 | + ); | |
| 872 | + | |
| 873 | + wp_register_style( | |
| 874 | + 'google-font-roboto', | |
| 875 | + 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700', | |
| 876 | + [], | |
| 877 | + ELEMENTOR_VERSION | |
| 878 | + ); | |
| 879 | + | |
| 880 | + wp_register_style( | |
| 881 | + 'flatpickr', | |
| 882 | + ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.css', | |
| 883 | + [], | |
| 884 | + '1.12.0' | |
| 885 | + ); | |
| 886 | + | |
| 887 | + wp_register_style( | |
| 888 | + 'pickr', | |
| 889 | + ELEMENTOR_ASSETS_URL . 'lib/pickr/themes/monolith.min.css', | |
| 890 | + [], | |
| 891 | + '1.5.0' | |
| 892 | + ); | |
| 893 | + | |
| 894 | + wp_register_style( | |
| 895 | + 'elementor-editor', | |
| 896 | + ELEMENTOR_ASSETS_URL . 'css/editor' . $direction_suffix . $suffix . '.css', | |
| 897 | + [ | |
| 898 | + 'elementor-common', | |
| 899 | + 'elementor-select2', | |
| 900 | + 'elementor-icons', | |
| 901 | + 'wp-auth-check', | |
| 902 | + 'google-font-roboto', | |
| 903 | + 'flatpickr', | |
| 904 | + 'pickr', | |
| 905 | + ], | |
| 906 | + ELEMENTOR_VERSION | |
| 907 | + ); | |
| 908 | + | |
| 909 | + wp_enqueue_style( 'elementor-editor' ); | |
| 910 | + | |
| 911 | + $ui_theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); | |
| 912 | + | |
| 913 | + if ( 'light' !== $ui_theme ) { | |
| 914 | + $ui_theme_media_queries = 'all'; | |
| 915 | + | |
| 916 | + if ( 'auto' === $ui_theme ) { | |
| 917 | + $ui_theme_media_queries = '(prefers-color-scheme: dark)'; | |
| 918 | + } | |
| 919 | + | |
| 920 | + wp_enqueue_style( | |
| 921 | + 'elementor-editor-dark-mode', | |
| 922 | + ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css', | |
| 923 | + [ | |
| 924 | + 'elementor-editor', | |
| 925 | + ], | |
| 926 | + ELEMENTOR_VERSION, | |
| 927 | + $ui_theme_media_queries | |
| 399 | 928 | ); |
| 400 | 929 | } |
| 401 | 930 | |
| 931 | + if ( Responsive::has_custom_breakpoints() ) { | |
| 932 | + $breakpoints = Responsive::get_breakpoints(); | |
| 933 | + | |
| 934 | + wp_add_inline_style( 'elementor-editor', '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . $breakpoints['md'] . 'px; }' ); | |
| 935 | + } | |
| 936 | + | |
| 402 | 937 | /** |
| 403 | 938 | * After editor enqueue styles. |
| 404 | 939 | * |
| 405 | 940 | * Fires after Elementor editor styles are enqueued. |
| @@ -408,44 +943,51 @@ | ||
| 408 | 943 | */ |
| 409 | 944 | do_action( 'elementor/editor/after_enqueue_styles' ); |
| 410 | 945 | } |
| 411 | 946 | |
| 412 | - private function enqueue_theme_ui_styles() { | |
| 413 | - $ui_theme_selected = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); | |
| 947 | + /** | |
| 948 | + * Get WordPress editor config. | |
| 949 | + * | |
| 950 | + * Config the default WordPress editor with custom settings for Elementor use. | |
| 951 | + * | |
| 952 | + * @since 1.9.0 | |
| 953 | + * @access private | |
| 954 | + */ | |
| 955 | + private function get_wp_editor_config() { | |
| 956 | + // Remove all TinyMCE plugins. | |
| 957 | + remove_all_filters( 'mce_buttons', 10 ); | |
| 958 | + remove_all_filters( 'mce_external_plugins', 10 ); | |
| 414 | 959 | |
| 415 | - $ui_themes = [ | |
| 416 | - 'light', | |
| 417 | - 'dark', | |
| 418 | - ]; | |
| 960 | + if ( ! class_exists( '\_WP_Editors', false ) ) { | |
| 961 | + require ABSPATH . WPINC . '/class-wp-editor.php'; | |
| 962 | + } | |
| 419 | 963 | |
| 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'; | |
| 964 | + // WordPress 4.8 and higher | |
| 965 | + if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) { | |
| 966 | + \_WP_Editors::print_default_editor_scripts(); | |
| 967 | + \_WP_Editors::print_tinymce_scripts(); | |
| 968 | + } | |
| 969 | + ob_start(); | |
| 426 | 970 | |
| 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 | - } | |
| 971 | + wp_editor( | |
| 972 | + '%%EDITORCONTENT%%', | |
| 973 | + 'elementorwpeditor', | |
| 974 | + [ | |
| 975 | + 'editor_class' => 'elementor-wp-editor', | |
| 976 | + 'editor_height' => 250, | |
| 977 | + 'drag_drop_upload' => true, | |
| 978 | + ] | |
| 979 | + ); | |
| 433 | 980 | |
| 434 | - $this->enqueue_theme_ui( 'light', $ui_light_theme_media_queries ); | |
| 435 | - $this->enqueue_theme_ui( 'dark', $ui_dark_theme_media_queries ); | |
| 436 | - } | |
| 981 | + $config = ob_get_clean(); | |
| 437 | 982 | |
| 438 | - private function enqueue_theme_ui( $ui_theme, $ui_theme_media_queries = 'all' ) { | |
| 439 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 983 | + // Don't call \_WP_Editors methods again | |
| 984 | + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 ); | |
| 985 | + remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 ); | |
| 440 | 986 | |
| 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 | - ); | |
| 987 | + \_WP_Editors::editor_js(); | |
| 988 | + | |
| 989 | + return $config; | |
| 448 | 990 | } |
| 449 | 991 | |
| 450 | 992 | /** |
| 451 | 993 | * Editor head trigger. |
| @@ -469,8 +1011,32 @@ | ||
| 469 | 1011 | do_action( 'elementor/editor/wp_head' ); |
| 470 | 1012 | } |
| 471 | 1013 | |
| 472 | 1014 | /** |
| 1015 | + * Add editor template. | |
| 1016 | + * | |
| 1017 | + * Registers new editor templates. | |
| 1018 | + * | |
| 1019 | + * @since 1.0.0 | |
| 1020 | + * @deprecated 2.3.0 Use `Plugin::$instance->common->add_template()` | |
| 1021 | + * @access public | |
| 1022 | + * | |
| 1023 | + * @param string $template Can be either a link to template file or template | |
| 1024 | + * HTML content. | |
| 1025 | + * @param string $type Optional. Whether to handle the template as path | |
| 1026 | + * or text. Default is `path`. | |
| 1027 | + */ | |
| 1028 | + public function add_editor_template( $template, $type = 'path' ) { | |
| 1029 | + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->add_template()' ); | |
| 1030 | + | |
| 1031 | + $common = Plugin::$instance->common; | |
| 1032 | + | |
| 1033 | + if ( $common ) { | |
| 1034 | + Plugin::$instance->common->add_template( $template, $type ); | |
| 1035 | + } | |
| 1036 | + } | |
| 1037 | + | |
| 1038 | + /** | |
| 473 | 1039 | * WP footer. |
| 474 | 1040 | * |
| 475 | 1041 | * Prints Elementor editor with all the editor templates, and render controls, |
| 476 | 1042 | * widgets and content elements. |
| @@ -486,11 +1052,13 @@ | ||
| 486 | 1052 | $plugin->controls_manager->render_controls(); |
| 487 | 1053 | $plugin->widgets_manager->render_widgets_content(); |
| 488 | 1054 | $plugin->elements_manager->render_elements_content(); |
| 489 | 1055 | |
| 1056 | + $plugin->schemes_manager->print_schemes_templates(); | |
| 1057 | + | |
| 490 | 1058 | $plugin->dynamic_tags->print_templates(); |
| 491 | 1059 | |
| 492 | - $this->get_loader()->register_additional_templates(); | |
| 1060 | + $this->init_editor_templates(); | |
| 493 | 1061 | |
| 494 | 1062 | /** |
| 495 | 1063 | * Elementor editor footer. |
| 496 | 1064 | * |
| @@ -526,12 +1094,11 @@ | ||
| 526 | 1094 | * @since 1.0.0 |
| 527 | 1095 | * @access public |
| 528 | 1096 | */ |
| 529 | 1097 | public function __construct() { |
| 530 | - Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() ); | |
| 1098 | + Plugin::$instance->data_manager->register_controller( Data\Globals\Controller::class ); | |
| 531 | 1099 | |
| 532 | 1100 | $this->notice_bar = new Notice_Bar(); |
| 533 | - $this->promotion = new Promotion(); | |
| 534 | 1101 | |
| 535 | 1102 | add_action( 'admin_action_elementor', [ $this, 'init' ] ); |
| 536 | 1103 | add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] ); |
| 537 | 1104 | |
| @@ -537,31 +1104,11 @@ | ||
| 537 | 1104 | |
| 538 | 1105 | // Handle autocomplete feature for URL control. |
| 539 | 1106 | add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] ); |
| 540 | 1107 | add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] ); |
| 541 | - | |
| 542 | - add_filter( 'replace_editor', [ $this, 'filter_replace_editor' ], 10, 2 ); | |
| 543 | 1108 | } |
| 544 | 1109 | |
| 545 | 1110 | /** |
| 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 | 1111 | * @since 2.2.0 |
| 565 | 1112 | * @access public |
| 566 | 1113 | */ |
| 567 | 1114 | public function filter_wp_link_query_args( $query ) { |
| @@ -577,11 +1124,9 @@ | ||
| 577 | 1124 | * @since 2.2.0 |
| 578 | 1125 | * @access public |
| 579 | 1126 | */ |
| 580 | 1127 | 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 | |
| 1128 | + if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { | |
| 584 | 1129 | $post_type_object = get_post_type_object( 'post' ); |
| 585 | 1130 | $post_label = $post_type_object->labels->singular_name; |
| 586 | 1131 | |
| 587 | 1132 | foreach ( $results as & $result ) { |
| @@ -593,71 +1138,146 @@ | ||
| 593 | 1138 | |
| 594 | 1139 | return $results; |
| 595 | 1140 | } |
| 596 | 1141 | |
| 597 | - public function set_post_id( $post_id ) { | |
| 598 | - $this->post_id = $post_id; | |
| 1142 | + /** | |
| 1143 | + * Create nonce. | |
| 1144 | + * | |
| 1145 | + * If the user has edit capabilities, it creates a cryptographic token to | |
| 1146 | + * give him access to Elementor editor. | |
| 1147 | + * | |
| 1148 | + * @since 1.8.1 | |
| 1149 | + * @since 1.8.7 The `$post_type` parameter was introduces. | |
| 1150 | + * @deprecated 2.3.0 Use `Plugin::$instance->common->get_component( 'ajax' )->create_nonce()` instead | |
| 1151 | + * @access public | |
| 1152 | + * | |
| 1153 | + * @param string $post_type The post type to check capabilities. | |
| 1154 | + * | |
| 1155 | + * @return null|string The nonce token, or `null` if the user has no edit | |
| 1156 | + * capabilities. | |
| 1157 | + */ | |
| 1158 | + public function create_nonce( $post_type ) { | |
| 1159 | + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->get_component( \'ajax\' )->create_nonce()' ); | |
| 1160 | + | |
| 1161 | + /** @var Ajax $ajax */ | |
| 1162 | + $ajax = Plugin::$instance->common->get_component( 'ajax' ); | |
| 1163 | + | |
| 1164 | + return $ajax->create_nonce(); | |
| 599 | 1165 | } |
| 600 | 1166 | |
| 601 | 1167 | /** |
| 602 | - * Get loader. | |
| 1168 | + * Verify nonce. | |
| 603 | 1169 | * |
| 604 | - * @return Editor_Loader_Interface | |
| 1170 | + * The user is given an amount of time to use the token, so therefore, since | |
| 1171 | + * the user ID and `$action` remain the same, the independent variable is | |
| 1172 | + * the time. | |
| 1173 | + * | |
| 1174 | + * @since 1.8.1 | |
| 1175 | + * @deprecated 2.3.0 | |
| 1176 | + * @access public | |
| 1177 | + * | |
| 1178 | + * @param string $nonce Nonce to verify. | |
| 1179 | + * | |
| 1180 | + * @return false|int If the nonce is invalid it returns `false`. If the | |
| 1181 | + * nonce is valid and generated between 0-12 hours ago it | |
| 1182 | + * returns `1`. If the nonce is valid and generated | |
| 1183 | + * between 12-24 hours ago it returns `2`. | |
| 605 | 1184 | */ |
| 606 | - private function get_loader() { | |
| 607 | - if ( ! $this->loader ) { | |
| 608 | - $this->loader = Editor_Loader_Factory::create(); | |
| 1185 | + public function verify_nonce( $nonce ) { | |
| 1186 | + _deprecated_function( __METHOD__, '2.3.0', 'wp_verify_nonce()' ); | |
| 609 | 1187 | |
| 610 | - $this->loader->init(); | |
| 611 | - } | |
| 612 | - | |
| 613 | - return $this->loader; | |
| 1188 | + return wp_verify_nonce( $nonce ); | |
| 614 | 1189 | } |
| 615 | 1190 | |
| 616 | 1191 | /** |
| 617 | - * Get elements presets. | |
| 1192 | + * Verify request nonce. | |
| 618 | 1193 | * |
| 619 | - * @return array | |
| 1194 | + * Whether the request nonce verified or not. | |
| 1195 | + * | |
| 1196 | + * @since 1.8.1 | |
| 1197 | + * @deprecated 2.3.0 Use `Plugin::$instance->common->get_component( 'ajax' )->verify_request_nonce()` instead | |
| 1198 | + * @access public | |
| 1199 | + * | |
| 1200 | + * @return bool True if request nonce verified, False otherwise. | |
| 620 | 1201 | */ |
| 621 | - public function get_elements_presets() { | |
| 622 | - $element_types = Plugin::$instance->elements_manager->get_element_types(); | |
| 623 | - $presets = []; | |
| 1202 | + public function verify_request_nonce() { | |
| 1203 | + _deprecated_function( __METHOD__, '2.3.0', 'Plugin::$instance->common->get_component( \'ajax\' )->verify_request_nonce()' ); | |
| 624 | 1204 | |
| 625 | - foreach ( $element_types as $el_type => $element ) { | |
| 626 | - $this->check_element_for_presets( $element, $el_type, $presets ); | |
| 627 | - } | |
| 1205 | + /** @var Ajax $ajax */ | |
| 1206 | + $ajax = Plugin::$instance->common->get_component( 'ajax' ); | |
| 628 | 1207 | |
| 629 | - return $presets; | |
| 1208 | + return $ajax->verify_request_nonce(); | |
| 630 | 1209 | } |
| 631 | 1210 | |
| 632 | 1211 | /** |
| 633 | - * @return void | |
| 1212 | + * Verify ajax nonce. | |
| 1213 | + * | |
| 1214 | + * Verify request nonce and send a JSON request, if not verified returns an | |
| 1215 | + * error. | |
| 1216 | + * | |
| 1217 | + * @since 1.9.0 | |
| 1218 | + * @deprecated 2.3.0 | |
| 1219 | + * @access public | |
| 634 | 1220 | */ |
| 635 | - private function check_element_for_presets( $element, $el_type, &$presets ) { | |
| 636 | - $element_presets = $element->get_panel_presets(); | |
| 1221 | + public function verify_ajax_nonce() { | |
| 1222 | + _deprecated_function( __METHOD__, '2.3.0' ); | |
| 637 | 1223 | |
| 638 | - if ( empty( $element_presets ) ) { | |
| 639 | - return; | |
| 640 | - } | |
| 1224 | + /** @var Ajax $ajax */ | |
| 1225 | + $ajax = Plugin::$instance->common->get_component( 'ajax' ); | |
| 641 | 1226 | |
| 642 | - foreach ( $element_presets as $key => $preset ) { | |
| 643 | - $this->maybe_add_preset( $el_type, $preset, $key, $presets ); | |
| 1227 | + if ( ! $ajax->verify_request_nonce() ) { | |
| 1228 | + wp_send_json_error( new \WP_Error( 'token_expired', 'Nonce token expired.' ) ); | |
| 644 | 1229 | } |
| 645 | 1230 | } |
| 646 | 1231 | |
| 647 | 1232 | /** |
| 648 | - * @return void | |
| 1233 | + * Init editor templates. | |
| 1234 | + * | |
| 1235 | + * Initialize default elementor templates used in the editor panel. | |
| 1236 | + * | |
| 1237 | + * @since 1.7.0 | |
| 1238 | + * @access private | |
| 649 | 1239 | */ |
| 650 | - private function maybe_add_preset( $el_type, $preset, $key, &$presets ) { | |
| 651 | - if ( $this->is_valid_preset( $el_type, $preset ) ) { | |
| 652 | - $presets[ $key ] = $preset; | |
| 1240 | + private function init_editor_templates() { | |
| 1241 | + $template_names = [ | |
| 1242 | + 'global', | |
| 1243 | + 'panel', | |
| 1244 | + 'panel-elements', | |
| 1245 | + 'repeater', | |
| 1246 | + 'templates', | |
| 1247 | + 'navigator', | |
| 1248 | + 'hotkeys', | |
| 1249 | + ]; | |
| 1250 | + | |
| 1251 | + foreach ( $template_names as $template_name ) { | |
| 1252 | + Plugin::$instance->common->add_template( ELEMENTOR_PATH . "includes/editor-templates/$template_name.php" ); | |
| 653 | 1253 | } |
| 654 | 1254 | } |
| 655 | 1255 | |
| 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']; | |
| 1256 | + private function bc_move_document_filters() { | |
| 1257 | + global $wp_filter; | |
| 1258 | + | |
| 1259 | + $old_tag = 'elementor/editor/localize_settings'; | |
| 1260 | + $new_tag = 'elementor/document/config'; | |
| 1261 | + | |
| 1262 | + if ( ! has_filter( $old_tag ) ) { | |
| 1263 | + return; | |
| 1264 | + } | |
| 1265 | + | |
| 1266 | + foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) { | |
| 1267 | + foreach ( $filters as $filter_id => $filter_args ) { | |
| 1268 | + if ( 2 === $filter_args['accepted_args'] ) { | |
| 1269 | + remove_filter( $old_tag, $filter_id, $priority ); | |
| 1270 | + | |
| 1271 | + add_filter( $new_tag, $filter_args['function'], $priority, 2 ); | |
| 1272 | + | |
| 1273 | + // TODO: Hard deprecation | |
| 1274 | + // _deprecated_hook( '`' . $old_tag . ` is no longer using post_id', '2.9.0', $new_tag' ); | |
| 1275 | + } | |
| 1276 | + } | |
| 1277 | + } | |
| 1278 | + } | |
| 1279 | + | |
| 1280 | + public function set_post_id( $post_id ) { | |
| 1281 | + $this->post_id = $post_id; | |
| 662 | 1282 | } |
| 663 | 1283 | } |