PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta1
Elementor Website Builder – more than just a page builder v4.3.0-beta1
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 4.3.0-beta1, at core/editor/editor.php

795 lines 20.0 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\Core\Breakpoints\Manager as Breakpoints_Manager;
5 use Elementor\Core\Common\Modules\Ajax\Module;
6 use Elementor\Core\Debug\Loading_Inspection_Manager;
7 use Elementor\Core\Editor\Loader\Editor_Loader;
8 use Elementor\Core\Utils\Assets_Config_Provider;
9 use Elementor\Core\Utils\Collection;
10 use Elementor\Core\Settings\Manager as SettingsManager;
11 use Elementor\Plugin;
12 use Elementor\TemplateLibrary\Source_Local;
13 use Elementor\Utils;
14 use Elementor\Core\Editor\Data;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 /**
21 * Elementor editor.
22 *
23 * Elementor editor handler class is responsible for initializing Elementor
24 * editor and register all the actions needed to display the editor.
25 *
26 * @since 1.0.0
27 */
28 class Editor {
29
30 /**
31 * User capability required to access Elementor editor.
32 */
33 const EDITING_CAPABILITY = 'edit_posts';
34
35 /**
36 * Post ID.
37 *
38 * Holds the ID of the current post being edited.
39 *
40 * @since 1.0.0
41 * @access private
42 *
43 * @var int Post ID.
44 */
45 private $post_id;
46
47 /**
48 * Whether the edit mode is active.
49 *
50 * Used to determine whether we are in edit mode.
51 *
52 * @since 1.0.0
53 * @access private
54 *
55 * @var bool Whether the edit mode is active.
56 */
57 private $is_edit_mode;
58
59 /**
60 * @var Notice_Bar
61 */
62 public $notice_bar;
63
64 /**
65 * @var Promotion
66 */
67 public $promotion;
68
69 /**
70 * @var Editor_Loader
71 */
72 private $loader;
73
74 /**
75 * Init.
76 *
77 * Initialize Elementor editor. Registers all needed actions to run Elementor,
78 * removes conflicting actions etc.
79 *
80 * Fired by `admin_action_elementor` action.
81 *
82 * @since 1.0.0
83 * @access public
84 *
85 * @param bool $to_die Optional. Whether to die at the end. Default is `true`.
86 */
87 public function init( $to_die = true ) {
88 if ( empty( $_REQUEST['post'] ) ) {
89 return;
90 }
91
92 $this->set_post_id( absint( $_REQUEST['post'] ) );
93
94 if ( ! $this->is_edit_mode( $this->post_id ) ) {
95 return;
96 }
97
98 // BC: From 2.9.0, the editor shouldn't handle the global post / current document.
99 // Use requested id and not the global in order to avoid conflicts with plugins that changes the global post.
100 query_posts( [
101 'p' => $this->post_id,
102 'post_type' => get_post_type( $this->post_id ),
103 ] );
104
105 Plugin::$instance->db->switch_to_post( $this->post_id );
106
107 $document = Plugin::$instance->documents->get( $this->post_id );
108
109 Plugin::$instance->documents->switch_to_document( $document );
110
111 // Change mode to Builder
112 $document->set_is_built_with_elementor( true );
113
114 // End BC.
115
116 Loading_Inspection_Manager::instance()->register_inspections();
117
118 // Send MIME Type header like WP admin-header.
119 @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
120
121 self::send_document_isolation_policy_header();
122
123 add_filter( 'show_admin_bar', '__return_false' );
124
125 // Remove all WordPress actions
126 remove_all_actions( 'wp_head' );
127 remove_all_actions( 'wp_print_styles' );
128 remove_all_actions( 'wp_print_head_scripts' );
129 remove_all_actions( 'wp_footer' );
130
131 // Handle `wp_head`
132 add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
133 add_action( 'wp_head', 'wp_print_styles', 8 );
134 add_action( 'wp_head', 'wp_print_head_scripts', 9 );
135 add_action( 'wp_head', 'wp_site_icon' );
136 add_action( 'wp_head', [ $this, 'editor_head_trigger' ], 30 );
137
138 // Handle `wp_footer`
139 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
140 add_action( 'wp_footer', 'wp_auth_check_html', 30 );
141 add_action( 'wp_footer', [ $this, 'wp_footer' ] );
142
143 // Handle `wp_enqueue_scripts`
144 remove_all_actions( 'wp_enqueue_scripts' );
145
146 // Also remove all scripts hooked into after_wp_tiny_mce.
147 remove_all_actions( 'after_wp_tiny_mce' );
148
149 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 999999 );
150 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], 999999 );
151
152 // Setup default heartbeat options
153 add_filter( 'heartbeat_settings', function( $settings ) {
154 $settings['interval'] = 15;
155 return $settings;
156 } );
157
158 // Tell to WP Cache plugins do not cache this request.
159 Utils::do_not_cache();
160
161 do_action( 'elementor/editor/init' );
162
163 $this->get_loader()->print_root_template();
164
165 // From the action it's an empty string, from tests its `false`
166 if ( false !== $to_die ) {
167 die;
168 }
169 }
170
171 /**
172 * Retrieve post ID.
173 *
174 * Get the ID of the current post.
175 *
176 * @since 1.8.0
177 * @access public
178 *
179 * @return int Post ID.
180 */
181 public function get_post_id() {
182 return $this->post_id;
183 }
184
185 /**
186 * Redirect to new URL.
187 *
188 * Used as a fallback function for the old URL structure of Elementor page
189 * edit URL.
190 *
191 * Fired by `template_redirect` action.
192 *
193 * @since 1.6.0
194 * @access public
195 */
196 public function redirect_to_new_url() {
197 if ( ! isset( $_GET['elementor'] ) ) {
198 return;
199 }
200
201 $document = Plugin::$instance->documents->get( get_the_ID() );
202
203 if ( ! $document ) {
204 wp_die( esc_html__( 'Document not found.', 'elementor' ) );
205 }
206
207 if ( ! $document->is_editable_by_current_user() || ! $document->is_built_with_elementor() ) {
208 return;
209 }
210
211 wp_safe_redirect( $document->get_edit_url() );
212 die;
213 }
214
215 /**
216 * Whether the current request targets the Elementor editor.
217 *
218 * Unlike `is_edit_mode()`, this is not affected by temporary `set_edit_mode()` overrides.
219 *
220 * @since 4.1.0
221 * @access public
222 *
223 * @return bool Whether the current request targets the Elementor editor.
224 */
225 public function is_editor_request() {
226 $common = Plugin::$instance->common;
227
228 if ( $common ) {
229 /** @var Module ajax */
230 $ajax_data = $common->get_component( 'ajax' )->get_current_action_data();
231
232 if ( ! empty( $ajax_data ) && 'get_document_config' === $ajax_data['action'] ) {
233 return true;
234 }
235 }
236
237 if ( $this->is_editor_admin_screen() ) {
238 return true;
239 }
240
241 return $this->is_editor_ajax_request();
242 }
243
244 private function is_editor_admin_screen(): bool {
245 if ( ! function_exists( 'get_current_screen' ) ) {
246 return false;
247 }
248
249 $screen = get_current_screen();
250
251 if ( ! $screen ) {
252 return false;
253 }
254
255 return isset( $_GET['action'] ) && 'elementor' === $_GET['action'] && in_array( $screen->base, [ 'post', 'toplevel_page_elementor' ], true );
256 }
257
258 private function is_editor_ajax_request(): bool {
259 $actions = apply_filters( 'elementor/editor/ajax_actions', [
260 'elementor',
261
262 // Templates
263 'elementor_get_templates',
264 'elementor_save_template',
265 'elementor_get_template',
266 'elementor_delete_template',
267 'elementor_import_template',
268 'elementor_library_direct_actions',
269 ] );
270
271 return isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions, true );
272 }
273
274 /**
275 * Whether the edit mode is active.
276 *
277 * Used to determine whether we are in the edit mode.
278 *
279 * @since 1.0.0
280 * @access public
281 *
282 * @param int $post_id Optional. Post ID. Default is `null`, the current
283 * post ID.
284 *
285 * @return bool Whether the edit mode is active.
286 */
287 public function is_edit_mode( $post_id = null ) {
288 if ( null !== $this->is_edit_mode ) {
289 return $this->is_edit_mode;
290 }
291
292 if ( empty( $post_id ) ) {
293 $post_id = $this->post_id;
294 }
295
296 $document = Plugin::$instance->documents->get( $post_id );
297
298 if ( ! $document || ! $document->is_editable_by_current_user() ) {
299 return false;
300 }
301
302 /** @var Module ajax */
303 $ajax_data = Plugin::$instance->common->get_component( 'ajax' )->get_current_action_data();
304
305 if ( ! empty( $ajax_data ) && 'get_document_config' === $ajax_data['action'] ) {
306 return true;
307 }
308
309 // Ajax request as Editor mode
310 $actions = [
311 'elementor',
312
313 // Templates
314 'elementor_get_templates',
315 'elementor_save_template',
316 'elementor_get_template',
317 'elementor_delete_template',
318 'elementor_import_template',
319 'elementor_library_direct_actions',
320 ];
321
322 if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions ) ) {
323 return true;
324 }
325
326 return false;
327 }
328
329 /**
330 * Lock post.
331 *
332 * Mark the post as currently being edited by the current user.
333 *
334 * @since 1.0.0
335 * @access public
336 *
337 * @param int $post_id The ID of the post being edited.
338 */
339 public function lock_post( $post_id ) {
340 if ( ! function_exists( 'wp_set_post_lock' ) ) {
341 require_once ABSPATH . 'wp-admin/includes/post.php';
342 }
343
344 wp_set_post_lock( $post_id );
345 }
346
347 /**
348 * Get locked user.
349 *
350 * Check what user is currently editing the post.
351 *
352 * @since 1.0.0
353 * @access public
354 *
355 * @param int $post_id The ID of the post being edited.
356 *
357 * @return \WP_User|false User information or false if the post is not locked.
358 */
359 public function get_locked_user( $post_id ) {
360 if ( ! function_exists( 'wp_check_post_lock' ) ) {
361 require_once ABSPATH . 'wp-admin/includes/post.php';
362 }
363
364 $locked_user = wp_check_post_lock( $post_id );
365 if ( ! $locked_user ) {
366 return false;
367 }
368
369 return get_user_by( 'id', $locked_user );
370 }
371
372 /**
373 * NOTICE: This method not in use, it's here for backward compatibility.
374 *
375 * Print Editor Template.
376 *
377 * Include the wrapper template of the editor.
378 *
379 * @since 2.2.0
380 * @access public
381 */
382 public function print_editor_template() {
383 include ELEMENTOR_PATH . 'includes/editor-templates/editor-wrapper.php';
384 }
385
386 /**
387 * Enqueue scripts.
388 *
389 * Registers all the editor scripts and enqueues them.
390 *
391 * @since 1.0.0
392 * @access public
393 */
394 public function enqueue_scripts() {
395 remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 );
396
397 global $wp_styles, $wp_scripts;
398
399 // Reset global variable
400 $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
401 $wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
402
403 $this->get_loader()->register_scripts();
404
405 /**
406 * Before editor enqueue scripts.
407 *
408 * Fires before Elementor editor scripts are enqueued.
409 *
410 * @since 1.0.0
411 */
412 do_action( 'elementor/editor/before_enqueue_scripts' );
413
414 // Tweak for WP Admin menu icons
415 wp_print_styles( 'editor-buttons' );
416
417 $this->get_loader()->enqueue_scripts();
418
419 Plugin::$instance->controls_manager->enqueue_control_scripts();
420
421 /**
422 * After editor enqueue scripts.
423 *
424 * Fires after Elementor editor scripts are enqueued.
425 *
426 * @since 1.0.0
427 */
428 do_action( 'elementor/editor/after_enqueue_scripts' );
429 }
430
431 /**
432 * Enqueue styles.
433 *
434 * Registers all the editor styles and enqueues them.
435 *
436 * @since 1.0.0
437 * @access public
438 */
439 public function enqueue_styles() {
440 /**
441 * Before editor enqueue styles.
442 *
443 * Fires before Elementor editor styles are enqueued.
444 *
445 * @since 1.0.0
446 */
447 do_action( 'elementor/editor/before_enqueue_styles' );
448
449 $this->get_loader()->register_styles();
450 $this->get_loader()->enqueue_styles();
451
452 $this->enqueue_theme_ui_styles();
453
454 $breakpoints = Plugin::$instance->breakpoints->get_breakpoints();
455
456 // The two breakpoints under 'tablet' need to be checked for values.
457 if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) {
458 wp_add_inline_style(
459 'elementor-editor',
460 '.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . Plugin::$instance->breakpoints->get_device_min_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_TABLET ) . 'px; }'
461 );
462 }
463
464 /**
465 * After editor enqueue styles.
466 *
467 * Fires after Elementor editor styles are enqueued.
468 *
469 * @since 1.0.0
470 */
471 do_action( 'elementor/editor/after_enqueue_styles' );
472 }
473
474 private function enqueue_theme_ui_styles() {
475 $ui_theme_selected = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' );
476
477 $ui_themes = [
478 'light',
479 'dark',
480 ];
481
482 if ( 'auto' === $ui_theme_selected || ! in_array( $ui_theme_selected, $ui_themes, true ) ) {
483 $ui_light_theme_media_queries = '(prefers-color-scheme: light)';
484 $ui_dark_theme_media_queries = '(prefers-color-scheme: dark)';
485 } else {
486 $ui_light_theme_media_queries = 'none';
487 $ui_dark_theme_media_queries = 'none';
488
489 if ( 'light' === $ui_theme_selected ) {
490 $ui_light_theme_media_queries = 'all';
491 } elseif ( 'dark' === $ui_theme_selected ) {
492 $ui_dark_theme_media_queries = 'all';
493 }
494 }
495
496 $this->enqueue_theme_ui( 'light', $ui_light_theme_media_queries );
497 $this->enqueue_theme_ui( 'dark', $ui_dark_theme_media_queries );
498 }
499
500 private function enqueue_theme_ui( $ui_theme, $ui_theme_media_queries = 'all' ) {
501 $suffix = Utils::is_script_debug() ? '' : '.min';
502
503 wp_enqueue_style(
504 'e-theme-ui-' . $ui_theme,
505 ELEMENTOR_ASSETS_URL . 'css/theme-' . $ui_theme . $suffix . '.css',
506 [],
507 ELEMENTOR_VERSION,
508 $ui_theme_media_queries
509 );
510 }
511
512 /**
513 * Editor head trigger.
514 *
515 * Fires the 'elementor/editor/wp_head' action in the head tag in Elementor
516 * editor.
517 *
518 * @since 1.0.0
519 * @access public
520 */
521 public function editor_head_trigger() {
522 /**
523 * Elementor editor head.
524 *
525 * Fires on Elementor editor head tag.
526 *
527 * Used to prints scripts or any other data in the head tag.
528 *
529 * @since 1.0.0
530 */
531 do_action( 'elementor/editor/wp_head' );
532 }
533
534 /**
535 * WP footer.
536 *
537 * Prints Elementor editor with all the editor templates, and render controls,
538 * widgets and content elements.
539 *
540 * Fired by `wp_footer` action.
541 *
542 * @since 1.0.0
543 * @access public
544 */
545 public function wp_footer() {
546 $plugin = Plugin::$instance;
547
548 $plugin->controls_manager->render_controls();
549 $plugin->widgets_manager->render_widgets_content();
550 $plugin->elements_manager->render_elements_content();
551
552 $plugin->dynamic_tags->print_templates();
553
554 $this->get_loader()->register_additional_templates();
555
556 /**
557 * Elementor editor footer.
558 *
559 * Fires on Elementor editor before closing the body tag.
560 *
561 * Used to prints scripts or any other HTML before closing the body tag.
562 *
563 * @since 1.0.0
564 */
565 do_action( 'elementor/editor/footer' );
566 }
567
568 /**
569 * Set edit mode.
570 *
571 * Used to update the edit mode.
572 *
573 * @since 1.0.0
574 * @access public
575 *
576 * @param bool $edit_mode Whether the edit mode is active.
577 */
578 public function set_edit_mode( $edit_mode ) {
579 $this->is_edit_mode = $edit_mode;
580 }
581
582 /**
583 * Editor constructor.
584 *
585 * Initializing Elementor editor and redirect from old URL structure of
586 * Elementor editor.
587 *
588 * @since 1.0.0
589 * @access public
590 */
591 public function __construct() {
592 Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() );
593
594 $this->notice_bar = new Notice_Bar();
595 $this->promotion = new Promotion();
596
597 add_action( 'admin_action_elementor', [ $this, 'init' ] );
598 add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] );
599
600 // Handle autocomplete feature for URL control.
601 add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] );
602 add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] );
603
604 add_filter( 'replace_editor', [ $this, 'filter_replace_editor' ], 10, 2 );
605 }
606
607 /**
608 * Whether the Document-Isolation-Policy header should be sent on the
609 * Elementor editor screen and the editor preview iframe.
610 *
611 * DIP places the document in its own agent cluster, which is the prerequisite
612 * for cross-origin isolation features such as SharedArrayBuffer (required by
613 * WordPress core's client-side media processing introduced in WP 7.1).
614 *
615 * Both the editor parent document and the preview iframe must send the same
616 * DIP header so they join the same agent cluster and synchronous DOM access
617 * between them (e.g. `iframe.contentWindow.elementorFrontend`) keeps working.
618 *
619 * The header is only honored by browsers on a secure context (HTTPS or
620 * localhost) so the helper short-circuits on insecure origins to avoid
621 * sending a header that the browser will ignore.
622 *
623 * @since 4.1.0
624 *
625 * @return bool
626 */
627 public static function should_use_document_isolation_policy() {
628 if ( ! is_ssl() ) {
629 $raw_host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
630 $host = strtolower( (string) strtok( $raw_host, ':' ) );
631
632 if ( 'localhost' !== $host && ! str_ends_with( $host, '.localhost' ) ) {
633 return false;
634 }
635 }
636
637 /**
638 * Filters whether Elementor sends the Document-Isolation-Policy header
639 * on the editor screen and preview iframe.
640 *
641 * @since 4.1.0
642 *
643 * @param bool $enabled Whether DIP is enabled. Defaults to true on a secure context.
644 */
645 return (bool) apply_filters( 'elementor/editor/use_document_isolation_policy', true );
646 }
647
648 /**
649 * Send the Document-Isolation-Policy header for the current response.
650 *
651 * Safe to call from both the Elementor editor screen handler and the
652 * preview iframe handler. No-op when {@see self::should_use_document_isolation_policy()}
653 * returns false.
654 *
655 * @since 4.1.0
656 */
657 public static function send_document_isolation_policy_header() {
658 if ( ! self::should_use_document_isolation_policy() || headers_sent() ) {
659 return;
660 }
661
662 header( 'Document-Isolation-Policy: isolate-and-credentialless' );
663 }
664
665 /**
666 * Signals to WordPress that Elementor is replacing the block editor on its own editor page,
667 * so that block-editor-specific behaviour (e.g. WP 7.0 COOP/COEP isolation headers) is not
668 * applied when the Elementor editor is active.
669 *
670 * @param bool $replace Whether the editor is being replaced.
671 * @param \WP_Post $post The post being edited.
672 *
673 * @return bool
674 */
675 public function filter_replace_editor( $replace, $post ) {
676 if ( isset( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
677 return true;
678 }
679
680 return $replace;
681 }
682
683 /**
684 * @since 2.2.0
685 * @access public
686 */
687 public function filter_wp_link_query_args( $query ) {
688 $library_cpt_key = array_search( Source_Local::CPT, $query['post_type'], true );
689 if ( false !== $library_cpt_key ) {
690 unset( $query['post_type'][ $library_cpt_key ] );
691 }
692
693 return $query;
694 }
695
696 /**
697 * @since 2.2.0
698 * @access public
699 */
700 public function filter_wp_link_query( $results ) {
701
702 // PHPCS - The user data is not used.
703 if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
704 $post_type_object = get_post_type_object( 'post' );
705 $post_label = $post_type_object->labels->singular_name;
706
707 foreach ( $results as & $result ) {
708 if ( 'post' === get_post_type( $result['ID'] ) ) {
709 $result['info'] = $post_label;
710 }
711 }
712 }
713
714 return $results;
715 }
716
717 public function set_post_id( $post_id ) {
718 $this->post_id = $post_id;
719 }
720
721 /**
722 * Get loader.
723 *
724 * @return Editor_Loader
725 */
726 private function get_loader() {
727 if ( ! $this->loader ) {
728 $this->loader = new Editor_Loader(
729 new Collection( [
730 'assets_url' => ELEMENTOR_ASSETS_URL,
731 'min_suffix' => ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min',
732 'direction_suffix' => is_rtl() ? '-rtl' : '',
733 ] ),
734 ( new Assets_Config_Provider() )->set_path_resolver(
735 function ( $name ) {
736 return ELEMENTOR_ASSETS_PATH . "js/packages/{$name}/{$name}.asset.php";
737 }
738 )
739 );
740
741 $this->loader->init();
742 }
743
744 return $this->loader;
745 }
746
747 /**
748 * Get elements presets.
749 *
750 * @return array
751 */
752 public function get_elements_presets() {
753 $element_types = Plugin::$instance->elements_manager->get_element_types();
754 $presets = [];
755
756 foreach ( $element_types as $el_type => $element ) {
757 $this->check_element_for_presets( $element, $el_type, $presets );
758 }
759
760 return $presets;
761 }
762
763 /**
764 * @return void
765 */
766 private function check_element_for_presets( $element, $el_type, &$presets ) {
767 $element_presets = $element->get_panel_presets();
768
769 if ( empty( $element_presets ) ) {
770 return;
771 }
772
773 foreach ( $element_presets as $key => $preset ) {
774 $this->maybe_add_preset( $el_type, $preset, $key, $presets );
775 }
776 }
777
778 /**
779 * @return void
780 */
781 private function maybe_add_preset( $el_type, $preset, $key, &$presets ) {
782 if ( $this->is_valid_preset( $el_type, $preset ) ) {
783 $presets[ $key ] = $preset;
784 }
785 }
786
787 /**
788 * @return boolean
789 */
790 private function is_valid_preset( $el_type, $preset ) {
791 return isset( $preset['replacements']['custom']['originalWidget'] )
792 && $el_type === $preset['replacements']['custom']['originalWidget'];
793 }
794 }
795