PluginProbe
Elementor Website Builder – more than just a page builder / 3.11.5
Elementor Website Builder – more than just a page builder v3.11.5
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / editor / editor.php

editor.php in Elementor Website Builder – more than just a page builder 3.11.5, at core/editor/editor.php

813 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Editor;
3
4 use Elementor\Api;
5 use Elementor\Core\Breakpoints\Breakpoint;
6 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
7 use Elementor\Core\Common\Modules\Ajax\Module;
8 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
9 use Elementor\Core\Debug\Loading_Inspection_Manager;
10 use Elementor\Core\Editor\Config_Providers\Config_Provider_Factory;
11 use Elementor\Core\Experiments\Manager as Experiments_Manager;
12 use Elementor\Core\Files\Uploads_Manager;
13 use Elementor\Core\Schemes\Manager as Schemes_Manager;
14 use Elementor\Core\Settings\Manager as SettingsManager;
15 use Elementor\Icons_Manager;
16 use Elementor\Plugin;
17 use Elementor\Settings;
18 use Elementor\Shapes;
19 use Elementor\TemplateLibrary\Source_Local;
20 use Elementor\Tools;
21 use Elementor\User;
22 use Elementor\Utils;
23 use Elementor\Core\Editor\Data;
24
25 if ( ! defined( 'ABSPATH' ) ) {
26 exit; // Exit if accessed directly.
27 }
28
29 /**
30 * Elementor editor.
31 *
32 * Elementor editor handler class is responsible for initializing Elementor
33 * editor and register all the actions needed to display the editor.
34 *
35 * @since 1.0.0
36 */
37 class Editor {
38
39 /**
40 * User capability required to access Elementor editor.
41 */
42 const EDITING_CAPABILITY = 'edit_posts';
43
44 const EDITOR_V2_EXPERIMENT_NAME = 'editor_v2';
45
46 /**
47 * Post ID.
48 *
49 * Holds the ID of the current post being edited.
50 *
51 * @since 1.0.0
52 * @access private
53 *
54 * @var int Post ID.
55 */
56 private $post_id;
57
58 /**
59 * Whether the edit mode is active.
60 *
61 * Used to determine whether we are in edit mode.
62 *
63 * @since 1.0.0
64 * @access private
65 *
66 * @var bool Whether the edit mode is active.
67 */
68 private $is_edit_mode;
69
70 /**
71 * @var Notice_Bar
72 */
73 public $notice_bar;
74
75 /**
76 * @var Promotion
77 */
78 public $promotion;
79
80 /**
81 * @var Editor_Loader
82 */
83 private $loader;
84
85 /**
86 * Init.
87 *
88 * Initialize Elementor editor. Registers all needed actions to run Elementor,
89 * removes conflicting actions etc.
90 *
91 * Fired by `admin_action_elementor` action.
92 *
93 * @since 1.0.0
94 * @access public
95 *
96 * @param bool $die Optional. Whether to die at the end. Default is `true`.
97 */
98 public function init( $die = true ) {
99 if ( empty( $_REQUEST['post'] ) ) {
100 return;
101 }
102
103 $this->set_post_id( absint( $_REQUEST['post'] ) );
104
105 if ( ! $this->is_edit_mode( $this->post_id ) ) {
106 return;
107 }
108
109 // BC: From 2.9.0, the editor shouldn't handle the global post / current document.
110 // Use requested id and not the global in order to avoid conflicts with plugins that changes the global post.
111 query_posts( [
112 'p' => $this->post_id,
113 'post_type' => get_post_type( $this->post_id ),
114 ] );
115
116 Plugin::$instance->db->switch_to_post( $this->post_id );
117
118 $document = Plugin::$instance->documents->get( $this->post_id );
119
120 Plugin::$instance->documents->switch_to_document( $document );
121
122 // Change mode to Builder
123 $document->set_is_built_with_elementor( true );
124
125 // End BC.
126
127 Loading_Inspection_Manager::instance()->register_inspections();
128
129 // Send MIME Type header like WP admin-header.
130 @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
131
132 add_filter( 'show_admin_bar', '__return_false' );
133
134 // Remove all WordPress actions
135 remove_all_actions( 'wp_head' );
136 remove_all_actions( 'wp_print_styles' );
137 remove_all_actions( 'wp_print_head_scripts' );
138 remove_all_actions( 'wp_footer' );
139
140 // Handle `wp_head`
141 add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
142 add_action( 'wp_head', 'wp_print_styles', 8 );
143 add_action( 'wp_head', 'wp_print_head_scripts', 9 );
144 add_action( 'wp_head', 'wp_site_icon' );
145 add_action( 'wp_head', [ $this, 'editor_head_trigger' ], 30 );
146
147 // Handle `wp_footer`
148 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
149 add_action( 'wp_footer', 'wp_auth_check_html', 30 );
150 add_action( 'wp_footer', [ $this, 'wp_footer' ] );
151
152 // Handle `wp_enqueue_scripts`
153 remove_all_actions( 'wp_enqueue_scripts' );
154
155 // Also remove all scripts hooked into after_wp_tiny_mce.
156 remove_all_actions( 'after_wp_tiny_mce' );
157
158 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 999999 );
159 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], 999999 );
160
161 // Setup default heartbeat options
162 add_filter( 'heartbeat_settings', function( $settings ) {
163 $settings['interval'] = 15;
164 return $settings;
165 } );
166
167 // Tell to WP Cache plugins do not cache this request.
168 Utils::do_not_cache();
169
170 do_action( 'elementor/editor/init' );
171
172 $this->get_loader()->print_root_template();
173
174 // From the action it's an empty string, from tests its `false`
175 if ( false !== $die ) {
176 die;
177 }
178 }
179
180 /**
181 * Retrieve post ID.
182 *
183 * Get the ID of the current post.
184 *
185 * @since 1.8.0
186 * @access public
187 *
188 * @return int Post ID.
189 */
190 public function get_post_id() {
191 return $this->post_id;
192 }
193
194 /**
195 * Redirect to new URL.
196 *
197 * Used as a fallback function for the old URL structure of Elementor page
198 * edit URL.
199 *
200 * Fired by `template_redirect` action.
201 *
202 * @since 1.6.0
203 * @access public
204 */
205 public function redirect_to_new_url() {
206 if ( ! isset( $_GET['elementor'] ) ) {
207 return;
208 }
209
210 $document = Plugin::$instance->documents->get( get_the_ID() );
211
212 if ( ! $document ) {
213 wp_die( esc_html__( 'Document not found.', 'elementor' ) );
214 }
215
216 if ( ! $document->is_editable_by_current_user() || ! $document->is_built_with_elementor() ) {
217 return;
218 }
219
220 wp_safe_redirect( $document->get_edit_url() );
221 die;
222 }
223
224 /**
225 * Whether the edit mode is active.
226 *
227 * Used to determine whether we are in the edit mode.
228 *
229 * @since 1.0.0
230 * @access public
231 *
232 * @param int $post_id Optional. Post ID. Default is `null`, the current
233 * post ID.
234 *
235 * @return bool Whether the edit mode is active.
236 */
237 public function is_edit_mode( $post_id = null ) {
238 if ( null !== $this->is_edit_mode ) {
239 return $this->is_edit_mode;
240 }
241
242 if ( empty( $post_id ) ) {
243 $post_id = $this->post_id;
244 }
245
246 $document = Plugin::$instance->documents->get( $post_id );
247
248 if ( ! $document || ! $document->is_editable_by_current_user() ) {
249 return false;
250 }
251
252 /** @var Module ajax */
253 $ajax_data = Plugin::$instance->common->get_component( 'ajax' )->get_current_action_data();
254
255 if ( ! empty( $ajax_data ) && 'get_document_config' === $ajax_data['action'] ) {
256 return true;
257 }
258
259 // Ajax request as Editor mode
260 $actions = [
261 'elementor',
262
263 // Templates
264 'elementor_get_templates',
265 'elementor_save_template',
266 'elementor_get_template',
267 'elementor_delete_template',
268 'elementor_import_template',
269 'elementor_library_direct_actions',
270 ];
271
272 if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions ) ) {
273 return true;
274 }
275
276 return false;
277 }
278
279 /**
280 * Lock post.
281 *
282 * Mark the post as currently being edited by the current user.
283 *
284 * @since 1.0.0
285 * @access public
286 *
287 * @param int $post_id The ID of the post being edited.
288 */
289 public function lock_post( $post_id ) {
290 if ( ! function_exists( 'wp_set_post_lock' ) ) {
291 require_once ABSPATH . 'wp-admin/includes/post.php';
292 }
293
294 wp_set_post_lock( $post_id );
295 }
296
297 /**
298 * Get locked user.
299 *
300 * Check what user is currently editing the post.
301 *
302 * @since 1.0.0
303 * @access public
304 *
305 * @param int $post_id The ID of the post being edited.
306 *
307 * @return \WP_User|false User information or false if the post is not locked.
308 */
309 public function get_locked_user( $post_id ) {
310 if ( ! function_exists( 'wp_check_post_lock' ) ) {
311 require_once ABSPATH . 'wp-admin/includes/post.php';
312 }
313
314 $locked_user = wp_check_post_lock( $post_id );
315 if ( ! $locked_user ) {
316 return false;
317 }
318
319 return get_user_by( 'id', $locked_user );
320 }
321
322 /**
323 * NOTICE: This method not in use, it's here for backward compatibility.
324 *
325 * Print Editor Template.
326 *
327 * Include the wrapper template of the editor.
328 *
329 * @since 2.2.0
330 * @access public
331 */
332 public function print_editor_template() {
333 include ELEMENTOR_PATH . 'includes/editor-templates/editor-wrapper.php';
334 }
335
336 /**
337 * Enqueue scripts.
338 *
339 * Registers all the editor scripts and enqueues them.
340 *
341 * @since 1.0.0
342 * @access public
343 */
344 public function enqueue_scripts() {
345 remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 );
346
347 global $wp_styles, $wp_scripts;
348
349 $plugin = Plugin::$instance;
350
351 // Reset global variable
352 $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
353 $wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
354
355 $suffix = ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min';
356
357 $this->get_loader()->register_scripts();
358
359 /**
360 * Before editor enqueue scripts.
361 *
362 * Fires before Elementor editor scripts are enqueued.
363 *
364 * @since 1.0.0
365 */
366 do_action( 'elementor/editor/before_enqueue_scripts' );
367
368 // Tweak for WP Admin menu icons
369 wp_print_styles( 'editor-buttons' );
370
371 $settings = SettingsManager::get_settings_managers_config();
372 // Moved to document since 2.9.0.
373 unset( $settings['page'] );
374
375 $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post_id );
376 $kits_manager = Plugin::$instance->kits_manager;
377
378 $page_title_selector = $kits_manager->get_current_settings( 'page_title_selector' );
379
380 $page_title_selector .= ', .elementor-page-title .elementor-heading-title';
381
382 $config = [
383 'initial_document' => $document->get_config(),
384 'version' => ELEMENTOR_VERSION,
385 'home_url' => home_url(),
386 'admin_settings_url' => admin_url( 'admin.php?page=' . Settings::PAGE_ID ),
387 'admin_tools_url' => admin_url( 'admin.php?page=' . Tools::PAGE_ID ),
388 'autosave_interval' => AUTOSAVE_INTERVAL,
389 'tabs' => $plugin->controls_manager->get_tabs(),
390 'controls' => $plugin->controls_manager->get_controls_data(),
391 'elements' => $plugin->elements_manager->get_element_types_config(),
392 'schemes' => [
393 'items' => $plugin->schemes_manager->get_registered_schemes_data(),
394 'enabled_schemes' => Schemes_Manager::get_enabled_schemes(),
395 ],
396 'globals' => [
397 'defaults_enabled' => [
398 'colors' => $kits_manager->is_custom_colors_enabled(),
399 'typography' => $kits_manager->is_custom_typography_enabled(),
400 ],
401 ],
402 'icons' => [
403 'libraries' => Icons_Manager::get_icon_manager_tabs_config(),
404 'goProURL' => 'https://go.elementor.com/go-pro-icon-library/',
405 ],
406 'fa4_to_fa5_mapping_url' => ELEMENTOR_ASSETS_URL . 'lib/font-awesome/migration/mapping.js',
407 'default_schemes' => $plugin->schemes_manager->get_schemes_defaults(),
408 'settings' => $settings,
409 'system_schemes' => $plugin->schemes_manager->get_system_schemes(),
410 'wp_editor' => $this->get_wp_editor_config(),
411 'settings_page_link' => Settings::get_url(),
412 'tools_page_link' => Tools::get_url(),
413 'tools_page_nonce' => wp_create_nonce( 'tools-page-from-editor' ),
414 'elementor_site' => 'https://go.elementor.com/about-elementor/',
415 'docs_elementor_site' => 'https://go.elementor.com/docs/',
416 'help_the_content_url' => 'https://go.elementor.com/the-content-missing/',
417 'help_flexbox_bc_url' => 'https://go.elementor.com/flexbox-layout-bc/',
418 'elementPromotionURL' => 'https://go.elementor.com/go-pro-%s',
419 'dynamicPromotionURL' => 'https://go.elementor.com/go-pro-dynamic-tag',
420 'additional_shapes' => Shapes::get_additional_shapes_for_config(),
421 'user' => [
422 'restrictions' => $plugin->role_manager->get_user_restrictions_array(),
423 'is_administrator' => current_user_can( 'manage_options' ),
424 'introduction' => User::get_introduction_meta(),
425 'locale' => get_user_locale(),
426 ],
427 'preview' => [
428 'help_preview_error_url' => 'https://go.elementor.com/preview-not-loaded/',
429 'help_preview_http_error_url' => 'https://go.elementor.com/preview-not-loaded/#permissions',
430 'help_preview_http_error_500_url' => 'https://go.elementor.com/500-error/',
431 'debug_data' => Loading_Inspection_Manager::instance()->run_inspections(),
432 ],
433 'locale' => get_locale(),
434 'rich_editing_enabled' => filter_var( get_user_meta( get_current_user_id(), 'rich_editing', true ), FILTER_VALIDATE_BOOLEAN ),
435 'page_title_selector' => $page_title_selector,
436 'tinymceHasCustomConfig' => class_exists( 'Tinymce_Advanced' ) || class_exists( 'Advanced_Editor_Tools' ),
437 'inlineEditing' => Plugin::$instance->widgets_manager->get_inline_editing_config(),
438 'dynamicTags' => Plugin::$instance->dynamic_tags->get_config(),
439 'ui' => [
440 'darkModeStylesheetURL' => ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css',
441 'defaultGenericFonts' => $kits_manager->get_current_settings( 'default_generic_fonts' ),
442 ],
443 // Empty array for BC to avoid errors.
444 'i18n' => [],
445 // 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0
446 'responsive' => [
447 'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(),
448 'icons_map' => Plugin::$instance->breakpoints->get_responsive_icons_classes_map(),
449 ],
450 'promotion' => [
451 'elements' => $this->promotion->get_elements_promotion(),
452 ],
453 ];
454
455 if ( ! Utils::has_pro() && current_user_can( 'manage_options' ) ) {
456 $config['promotionWidgets'] = Api::get_promotion_widgets();
457 }
458
459 $this->bc_move_document_filters();
460
461 /**
462 * Localize editor settings.
463 *
464 * Filters the editor localized settings.
465 *
466 * @since 1.0.0
467 *
468 * @param array $config Editor configuration.
469 * @param int $post_id The ID of the current post being edited.
470 */
471 $config = apply_filters( 'elementor/editor/localize_settings', $config );
472
473 Utils::print_js_config( 'elementor-editor', 'ElementorConfig', $config );
474
475 $this->get_loader()->enqueue_scripts();
476 $this->get_loader()->load_scripts_translations();
477
478 $plugin->controls_manager->enqueue_control_scripts();
479
480 /**
481 * After editor enqueue scripts.
482 *
483 * Fires after Elementor editor scripts are enqueued.
484 *
485 * @since 1.0.0
486 */
487 do_action( 'elementor/editor/after_enqueue_scripts' );
488 }
489
490 /**
491 * Enqueue styles.
492 *
493 * Registers all the editor styles and enqueues them.
494 *
495 * @since 1.0.0
496 * @access public
497 */
498 public function enqueue_styles() {
499 /**
500 * Before editor enqueue styles.
501 *
502 * Fires before Elementor editor styles are enqueued.
503 *
504 * @since 1.0.0
505 */
506 do_action( 'elementor/editor/before_enqueue_styles' );
507
508 $suffix = Utils::is_script_debug() ? '' : '.min';
509
510 $this->get_loader()->register_styles();
511 $this->get_loader()->enqueue_styles();
512
513 $ui_theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' );
514
515 if ( 'light' !== $ui_theme ) {
516 $ui_theme_media_queries = 'all';
517
518 if ( 'auto' === $ui_theme ) {
519 $ui_theme_media_queries = '(prefers-color-scheme: dark)';
520 }
521
522 wp_enqueue_style(
523 'elementor-editor-dark-mode',
524 ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css',
525 [
526 'elementor-editor',
527 ],
528 ELEMENTOR_VERSION,
529 $ui_theme_media_queries
530 );
531 }
532
533 $breakpoints = Plugin::$instance->breakpoints->get_breakpoints();
534
535 // The two breakpoints under 'tablet' need to be checked for values.
536 if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) {
537 wp_add_inline_style(
538 'elementor-editor',
539 '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . Plugin::$instance->breakpoints->get_device_min_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_TABLET ) . 'px; }'
540 );
541 }
542
543 /**
544 * After editor enqueue styles.
545 *
546 * Fires after Elementor editor styles are enqueued.
547 *
548 * @since 1.0.0
549 */
550 do_action( 'elementor/editor/after_enqueue_styles' );
551 }
552
553 /**
554 * Get WordPress editor config.
555 *
556 * Config the default WordPress editor with custom settings for Elementor use.
557 *
558 * @since 1.9.0
559 * @access private
560 */
561 private function get_wp_editor_config() {
562 // Remove all TinyMCE plugins.
563 remove_all_filters( 'mce_buttons', 10 );
564 remove_all_filters( 'mce_external_plugins', 10 );
565
566 if ( ! class_exists( '\_WP_Editors', false ) ) {
567 require ABSPATH . WPINC . '/class-wp-editor.php';
568 }
569
570 // WordPress 4.8 and higher
571 if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) {
572 \_WP_Editors::print_default_editor_scripts();
573 \_WP_Editors::print_tinymce_scripts();
574 }
575 ob_start();
576
577 wp_editor(
578 '%%EDITORCONTENT%%',
579 'elementorwpeditor',
580 [
581 'editor_class' => 'elementor-wp-editor',
582 'editor_height' => 250,
583 'drag_drop_upload' => true,
584 ]
585 );
586
587 $config = ob_get_clean();
588
589 // Don't call \_WP_Editors methods again
590 remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 );
591 remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 );
592
593 \_WP_Editors::editor_js();
594
595 return $config;
596 }
597
598 /**
599 * Editor head trigger.
600 *
601 * Fires the 'elementor/editor/wp_head' action in the head tag in Elementor
602 * editor.
603 *
604 * @since 1.0.0
605 * @access public
606 */
607 public function editor_head_trigger() {
608 /**
609 * Elementor editor head.
610 *
611 * Fires on Elementor editor head tag.
612 *
613 * Used to prints scripts or any other data in the head tag.
614 *
615 * @since 1.0.0
616 */
617 do_action( 'elementor/editor/wp_head' );
618 }
619
620 /**
621 * WP footer.
622 *
623 * Prints Elementor editor with all the editor templates, and render controls,
624 * widgets and content elements.
625 *
626 * Fired by `wp_footer` action.
627 *
628 * @since 1.0.0
629 * @access public
630 */
631 public function wp_footer() {
632 $plugin = Plugin::$instance;
633
634 $plugin->controls_manager->render_controls();
635 $plugin->widgets_manager->render_widgets_content();
636 $plugin->elements_manager->render_elements_content();
637
638 $plugin->schemes_manager->print_schemes_templates();
639
640 $plugin->dynamic_tags->print_templates();
641
642 $this->init_editor_templates();
643
644 /**
645 * Elementor editor footer.
646 *
647 * Fires on Elementor editor before closing the body tag.
648 *
649 * Used to prints scripts or any other HTML before closing the body tag.
650 *
651 * @since 1.0.0
652 */
653 do_action( 'elementor/editor/footer' );
654 }
655
656 /**
657 * Set edit mode.
658 *
659 * Used to update the edit mode.
660 *
661 * @since 1.0.0
662 * @access public
663 *
664 * @param bool $edit_mode Whether the edit mode is active.
665 */
666 public function set_edit_mode( $edit_mode ) {
667 $this->is_edit_mode = $edit_mode;
668 }
669
670 /**
671 * Editor constructor.
672 *
673 * Initializing Elementor editor and redirect from old URL structure of
674 * Elementor editor.
675 *
676 * @since 1.0.0
677 * @access public
678 */
679 public function __construct() {
680 Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() );
681
682 $this->notice_bar = new Notice_Bar();
683 $this->promotion = new Promotion();
684
685 add_action( 'admin_action_elementor', [ $this, 'init' ] );
686 add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] );
687
688 $this->register_editor_v2_experiment();
689
690 // Handle autocomplete feature for URL control.
691 add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] );
692 add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] );
693 }
694
695 /**
696 * @since 2.2.0
697 * @access public
698 */
699 public function filter_wp_link_query_args( $query ) {
700 $library_cpt_key = array_search( Source_Local::CPT, $query['post_type'], true );
701 if ( false !== $library_cpt_key ) {
702 unset( $query['post_type'][ $library_cpt_key ] );
703 }
704
705 return $query;
706 }
707
708 /**
709 * @since 2.2.0
710 * @access public
711 */
712 public function filter_wp_link_query( $results ) {
713
714 // PHPCS - The user data is not used.
715 if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
716 $post_type_object = get_post_type_object( 'post' );
717 $post_label = $post_type_object->labels->singular_name;
718
719 foreach ( $results as & $result ) {
720 if ( 'post' === get_post_type( $result['ID'] ) ) {
721 $result['info'] = $post_label;
722 }
723 }
724 }
725
726 return $results;
727 }
728
729 /**
730 * Init editor templates.
731 *
732 * Initialize default elementor templates used in the editor panel.
733 *
734 * @since 1.7.0
735 * @access private
736 */
737 private function init_editor_templates() {
738 $template_names = [
739 'global',
740 'panel',
741 'panel-elements',
742 'repeater',
743 'templates',
744 'navigator',
745 'hotkeys',
746 'responsive-bar',
747 ];
748
749 foreach ( $template_names as $template_name ) {
750 Plugin::$instance->common->add_template( ELEMENTOR_PATH . "includes/editor-templates/$template_name.php" );
751 }
752 }
753
754 private function bc_move_document_filters() {
755 global $wp_filter;
756
757 $old_tag = 'elementor/editor/localize_settings';
758 $new_tag = 'elementor/document/config';
759
760 if ( ! has_filter( $old_tag ) ) {
761 return;
762 }
763
764 foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) {
765 foreach ( $filters as $filter_id => $filter_args ) {
766 if ( 2 === $filter_args['accepted_args'] ) {
767 remove_filter( $old_tag, $filter_id, $priority );
768
769 add_filter( $new_tag, $filter_args['function'], $priority, 2 );
770
771 // TODO: Hard deprecation
772 // _deprecated_hook( '`' . $old_tag . ` is no longer using post_id', '2.9.0', $new_tag' );
773 }
774 }
775 }
776 }
777
778 public function set_post_id( $post_id ) {
779 $this->post_id = $post_id;
780 }
781
782 /**
783 * Get loader.
784 *
785 * @return Editor_Loader
786 */
787 private function get_loader() {
788 if ( ! $this->loader ) {
789 $this->loader = new Editor_Loader( Config_Provider_Factory::create() );
790 $this->loader->register_hooks();
791 }
792
793 return $this->loader;
794 }
795
796 /**
797 * Adding Editor V2 experiment.
798 *
799 * @return void
800 * @throws \Exception
801 */
802 private function register_editor_v2_experiment() {
803 Plugin::$instance->experiments->add_feature( [
804 'name' => static::EDITOR_V2_EXPERIMENT_NAME,
805 'title' => esc_html__( 'Editor V2', 'elementor' ),
806 'description' => esc_html__( 'Enable the new editor.', 'elementor' ),
807 'hidden' => true,
808 'default' => Experiments_Manager::STATE_INACTIVE,
809 'status' => Experiments_Manager::RELEASE_STATUS_ALPHA,
810 ] );
811 }
812 }
813