PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0-dev2
Elementor Website Builder – more than just a page builder v4.2.0-dev2
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 / includes / plugin.php

plugin.php in Elementor Website Builder – more than just a page builder 4.2.0-dev2, at includes/plugin.php

880 lines 16.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor;
4
5 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
6 use Elementor\Core\Wp_Api;
7 use Elementor\Core\Admin\Admin;
8 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
9 use Elementor\Core\Common\App as CommonApp;
10 use Elementor\Core\Debug\Inspector;
11 use Elementor\Core\Documents_Manager;
12 use Elementor\Core\Experiments\Manager as Experiments_Manager;
13 use Elementor\Core\Kits\Manager as Kits_Manager;
14 use Elementor\Core\Editor\Editor;
15 use Elementor\Core\Files\Manager as Files_Manager;
16 use Elementor\Core\Files\Assets\Manager as Assets_Manager;
17 use Elementor\Core\Modules_Manager;
18 use Elementor\Core\Settings\Manager as Settings_Manager;
19 use Elementor\Core\Settings\Page\Manager as Page_Settings_Manager;
20 use Elementor\Modules\History\Revisions_Manager;
21 use Elementor\Core\DynamicTags\Manager as Dynamic_Tags_Manager;
22 use Elementor\Core\Logger\Manager as Log_Manager;
23 use Elementor\Core\Page_Assets\Loader as Assets_Loader;
24 use Elementor\Modules\System_Info\Module as System_Info_Module;
25 use Elementor\Data\Manager as Data_Manager;
26 use Elementor\Data\V2\Manager as Data_Manager_V2;
27 use Elementor\Core\Files\Uploads_Manager;
28 use WP_REST_Request;
29
30 if ( ! defined( 'ABSPATH' ) ) {
31 exit;
32 }
33
34 /**
35 * Elementor plugin.
36 *
37 * The main plugin handler class is responsible for initializing Elementor. The
38 * class registers and all the components required to run the plugin.
39 *
40 * @since 1.0.0
41 */
42 class Plugin {
43
44 const ELEMENTOR_DEFAULT_POST_TYPES = [ 'page', 'post' ];
45
46 private const SANITIZABLE_META_KEYS = [
47 '_elementor_data',
48 '_elementor_page_settings',
49 '_elementor_global_class_data',
50 ];
51
52 /**
53 * Instance.
54 *
55 * Holds the plugin instance.
56 *
57 * @since 1.0.0
58 * @access public
59 * @static
60 *
61 * @var Plugin
62 */
63 public static $instance = null;
64
65 /**
66 * Database.
67 *
68 * Holds the plugin database handler which is responsible for communicating
69 * with the database.
70 *
71 * @since 1.0.0
72 * @access public
73 *
74 * @var DB
75 */
76 public $db;
77
78 /**
79 * Controls manager.
80 *
81 * Holds the plugin controls manager handler is responsible for registering
82 * and initializing controls.
83 *
84 * @since 1.0.0
85 * @access public
86 *
87 * @var Controls_Manager
88 */
89 public $controls_manager;
90
91 /**
92 * Documents manager.
93 *
94 * Holds the documents manager.
95 *
96 * @since 2.0.0
97 * @access public
98 *
99 * @var Documents_Manager
100 */
101 public $documents;
102
103 /**
104 * Elements manager.
105 *
106 * Holds the plugin elements manager.
107 *
108 * @since 1.0.0
109 * @access public
110 *
111 * @var Elements_Manager
112 */
113 public $elements_manager;
114
115 /**
116 * Widgets manager.
117 *
118 * Holds the plugin widgets manager which is responsible for registering and
119 * initializing widgets.
120 *
121 * @since 1.0.0
122 * @access public
123 *
124 * @var Widgets_Manager
125 */
126 public $widgets_manager;
127
128 /**
129 * Revisions manager.
130 *
131 * Holds the plugin revisions manager which handles history and revisions
132 * functionality.
133 *
134 * @since 1.0.0
135 * @access public
136 *
137 * @var Revisions_Manager
138 */
139 public $revisions_manager;
140
141 /**
142 * Images manager.
143 *
144 * Holds the plugin images manager which is responsible for retrieving image
145 * details.
146 *
147 * @since 2.9.0
148 * @access public
149 *
150 * @var Images_Manager
151 */
152 public $images_manager;
153
154 /**
155 * Maintenance mode.
156 *
157 * Holds the maintenance mode manager responsible for the "Maintenance Mode"
158 * and the "Coming Soon" features.
159 *
160 * @since 1.0.0
161 * @access public
162 *
163 * @var Maintenance_Mode
164 */
165 public $maintenance_mode;
166
167 /**
168 * Page settings manager.
169 *
170 * Holds the page settings manager.
171 *
172 * @since 1.0.0
173 * @access public
174 *
175 * @var Page_Settings_Manager
176 */
177 public $page_settings_manager;
178
179 /**
180 * Dynamic tags manager.
181 *
182 * Holds the dynamic tags manager.
183 *
184 * @since 1.0.0
185 * @access public
186 *
187 * @var Dynamic_Tags_Manager
188 */
189 public $dynamic_tags;
190
191 /**
192 * Settings.
193 *
194 * Holds the plugin settings.
195 *
196 * @since 1.0.0
197 * @access public
198 *
199 * @var Settings
200 */
201 public $settings;
202
203 /**
204 * Role Manager.
205 *
206 * Holds the plugin role manager.
207 *
208 * @since 2.0.0
209 * @access public
210 *
211 * @var Core\RoleManager\Role_Manager
212 */
213 public $role_manager;
214
215 /**
216 * Admin.
217 *
218 * Holds the plugin admin.
219 *
220 * @since 1.0.0
221 * @access public
222 *
223 * @var Admin
224 */
225 public $admin;
226
227 /**
228 * Tools.
229 *
230 * Holds the plugin tools.
231 *
232 * @since 1.0.0
233 * @access public
234 *
235 * @var Tools
236 */
237 public $tools;
238
239 /**
240 * Preview.
241 *
242 * Holds the plugin preview.
243 *
244 * @since 1.0.0
245 * @access public
246 *
247 * @var Preview
248 */
249 public $preview;
250
251 /**
252 * Editor.
253 *
254 * Holds the plugin editor.
255 *
256 * @since 1.0.0
257 * @access public
258 *
259 * @var Editor
260 */
261 public $editor;
262
263 /**
264 * Frontend.
265 *
266 * Holds the plugin frontend.
267 *
268 * @since 1.0.0
269 * @access public
270 *
271 * @var Frontend
272 */
273 public $frontend;
274
275 /**
276 * Heartbeat.
277 *
278 * Holds the plugin heartbeat.
279 *
280 * @since 1.0.0
281 * @access public
282 *
283 * @var Heartbeat
284 */
285 public $heartbeat;
286
287 /**
288 * System info.
289 *
290 * Holds the system info data.
291 *
292 * @since 1.0.0
293 * @access public
294 *
295 * @var System_Info_Module
296 */
297 public $system_info;
298
299 /**
300 * Template library manager.
301 *
302 * Holds the template library manager.
303 *
304 * @since 1.0.0
305 * @access public
306 *
307 * @var TemplateLibrary\Manager
308 */
309 public $templates_manager;
310
311 /**
312 * Skins manager.
313 *
314 * Holds the skins manager.
315 *
316 * @since 1.0.0
317 * @access public
318 *
319 * @var Skins_Manager
320 */
321 public $skins_manager;
322
323 /**
324 * Files manager.
325 *
326 * Holds the plugin files manager.
327 *
328 * @since 2.1.0
329 * @access public
330 *
331 * @var Files_Manager
332 */
333 public $files_manager;
334
335 /**
336 * Assets manager.
337 *
338 * Holds the plugin assets manager.
339 *
340 * @since 2.6.0
341 * @access public
342 *
343 * @var Assets_Manager
344 */
345 public $assets_manager;
346
347 /**
348 * Icons Manager.
349 *
350 * Holds the plugin icons manager.
351 *
352 * @access public
353 *
354 * @var Icons_Manager
355 */
356 public $icons_manager;
357
358 /**
359 * WordPress widgets manager.
360 *
361 * Holds the WordPress widgets manager.
362 *
363 * @since 1.0.0
364 * @access public
365 *
366 * @var WordPress_Widgets_Manager
367 */
368 public $wordpress_widgets_manager;
369
370 /**
371 * Modules manager.
372 *
373 * Holds the plugin modules manager.
374 *
375 * @since 1.0.0
376 * @access public
377 *
378 * @var Modules_Manager
379 */
380 public $modules_manager;
381
382 /**
383 * Beta testers.
384 *
385 * Holds the plugin beta testers.
386 *
387 * @since 1.0.0
388 * @access public
389 *
390 * @var Beta_Testers
391 */
392 public $beta_testers;
393
394 /**
395 * Inspector.
396 *
397 * Holds the plugin inspector data.
398 *
399 * @since 2.1.2
400 * @access public
401 *
402 * @var Inspector
403 */
404 public $inspector;
405
406 /**
407 * @var Admin_Menu_Manager
408 */
409 public $admin_menu_manager;
410
411 /**
412 * Common functionality.
413 *
414 * Holds the plugin common functionality.
415 *
416 * @since 2.3.0
417 * @access public
418 *
419 * @var CommonApp
420 */
421 public $common;
422
423 /**
424 * Log manager.
425 *
426 * Holds the plugin log manager.
427 *
428 * @access public
429 *
430 * @var Log_Manager
431 */
432 public $logger;
433
434 /**
435 * Upgrade manager.
436 *
437 * Holds the plugin upgrade manager.
438 *
439 * @access public
440 *
441 * @var Core\Upgrade\Manager
442 */
443 public $upgrade;
444
445 /**
446 * Tasks manager.
447 *
448 * Holds the plugin tasks manager.
449 *
450 * @var Core\Upgrade\Custom_Tasks_Manager
451 */
452 public $custom_tasks;
453
454 /**
455 * Kits manager.
456 *
457 * Holds the plugin kits manager.
458 *
459 * @access public
460 *
461 * @var Core\Kits\Manager
462 */
463 public $kits_manager;
464
465 /**
466 * @var \Elementor\Data\V2\Manager
467 */
468 public $data_manager_v2;
469
470 /**
471 * Legacy mode.
472 *
473 * Holds the plugin legacy mode data.
474 *
475 * @access public
476 *
477 * @var array
478 */
479 public $legacy_mode;
480
481 /**
482 * App.
483 *
484 * Holds the plugin app data.
485 *
486 * @since 3.0.0
487 * @access public
488 *
489 * @var App\App
490 */
491 public $app;
492
493 /**
494 * WordPress API.
495 *
496 * Holds the methods that interact with WordPress Core API.
497 *
498 * @since 3.0.0
499 * @access public
500 *
501 * @var Wp_Api
502 */
503 public $wp;
504
505 /**
506 * Experiments manager.
507 *
508 * Holds the plugin experiments manager.
509 *
510 * @since 3.1.0
511 * @access public
512 *
513 * @var Experiments_Manager
514 */
515 public $experiments;
516
517 /**
518 * Uploads manager.
519 *
520 * Holds the plugin uploads manager responsible for handling file uploads
521 * that are not done with WordPress Media.
522 *
523 * @since 3.3.0
524 * @access public
525 *
526 * @var Uploads_Manager
527 */
528 public $uploads_manager;
529
530 /**
531 * Breakpoints manager.
532 *
533 * Holds the plugin breakpoints manager.
534 *
535 * @since 3.2.0
536 * @access public
537 *
538 * @var Breakpoints_Manager
539 */
540 public $breakpoints;
541
542 /**
543 * Assets loader.
544 *
545 * Holds the plugin assets loader responsible for conditionally enqueuing
546 * styles and script assets that were pre-enabled.
547 *
548 * @since 3.3.0
549 * @access public
550 *
551 * @var Assets_Loader
552 */
553 public $assets_loader;
554
555 /**
556 * Clone.
557 *
558 * Disable class cloning and throw an error on object clone.
559 *
560 * The whole idea of the singleton design pattern is that there is a single
561 * object. Therefore, we don't want the object to be cloned.
562 *
563 * @access public
564 * @since 1.0.0
565 */
566 public function __clone() {
567 _doing_it_wrong(
568 __FUNCTION__,
569 sprintf( 'Cloning instances of the singleton "%s" class is forbidden.', get_class( $this ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
570 '1.0.0'
571 );
572 }
573
574 /**
575 * Wakeup.
576 *
577 * Disable unserializing of the class.
578 *
579 * @access public
580 * @since 1.0.0
581 */
582 public function __wakeup() {
583 _doing_it_wrong(
584 __FUNCTION__,
585 sprintf( 'Unserializing instances of the singleton "%s" class is forbidden.', get_class( $this ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
586 '1.0.0'
587 );
588 }
589
590 /**
591 * Instance.
592 *
593 * Ensures only one instance of the plugin class is loaded or can be loaded.
594 *
595 * @since 1.0.0
596 * @access public
597 * @static
598 *
599 * @return Plugin An instance of the class.
600 */
601 public static function instance() {
602 if ( is_null( self::$instance ) ) {
603 self::$instance = new self();
604
605 /**
606 * Elementor loaded.
607 *
608 * Fires when Elementor was fully loaded and instantiated.
609 *
610 * @since 1.0.0
611 */
612 do_action( 'elementor/loaded' );
613 }
614
615 return self::$instance;
616 }
617
618 /**
619 * Init.
620 *
621 * Initialize Elementor Plugin. Register Elementor support for all the
622 * supported post types and initialize Elementor components.
623 *
624 * @since 1.0.0
625 * @access public
626 */
627 public function init() {
628 $this->add_cpt_support();
629
630 $this->init_components();
631
632 /**
633 * Elementor init.
634 *
635 * Fires when Elementor components are initialized.
636 *
637 * After Elementor finished loading but before any headers are sent.
638 *
639 * @since 1.0.0
640 */
641 do_action( 'elementor/init' );
642 }
643
644 /**
645 * Get install time.
646 *
647 * Retrieve the time when Elementor was installed.
648 *
649 * @since 2.6.0
650 * @access public
651 * @static
652 *
653 * @return int Unix timestamp when Elementor was installed.
654 */
655 public function get_install_time() {
656 $installed_time = get_option( '_elementor_installed_time' );
657
658 if ( ! $installed_time ) {
659 $installed_time = time();
660
661 update_option( '_elementor_installed_time', $installed_time );
662 }
663
664 return $installed_time;
665 }
666
667 /**
668 * @since 2.3.0
669 * @access public
670 */
671 public function on_rest_api_init() {
672 // On admin/frontend sometimes the rest API is initialized after the common is initialized.
673 if ( ! $this->common ) {
674 $this->init_common();
675 }
676 }
677
678 /**
679 * Init components.
680 *
681 * Initialize Elementor components. Register actions, run setting manager,
682 * initialize all the components that run elementor, and if in admin page
683 * initialize admin components.
684 *
685 * @since 1.0.0
686 * @access private
687 */
688 private function init_components() {
689 $this->experiments = new Experiments_Manager();
690 $this->breakpoints = new Breakpoints_Manager();
691 $this->inspector = new Inspector();
692
693 Settings_Manager::run();
694
695 $this->db = new DB();
696 $this->controls_manager = new Controls_Manager();
697 $this->documents = new Documents_Manager();
698 $this->kits_manager = new Kits_Manager();
699 $this->elements_manager = new Elements_Manager();
700 $this->widgets_manager = new Widgets_Manager();
701 $this->skins_manager = new Skins_Manager();
702 $this->files_manager = new Files_Manager();
703 $this->assets_manager = new Assets_Manager();
704 $this->icons_manager = new Icons_Manager();
705 $this->settings = new Settings();
706 $this->tools = new Tools();
707 $this->editor = new Editor();
708 $this->preview = new Preview();
709 $this->frontend = new Frontend();
710 $this->maintenance_mode = new Maintenance_Mode();
711 $this->dynamic_tags = new Dynamic_Tags_Manager();
712 $this->modules_manager = new Modules_Manager();
713 $this->templates_manager = new TemplateLibrary\Manager();
714 $this->role_manager = new Core\RoleManager\Role_Manager();
715 $this->system_info = new System_Info_Module();
716 $this->revisions_manager = new Revisions_Manager();
717 $this->images_manager = new Images_Manager();
718 $this->wp = new Wp_Api();
719 $this->assets_loader = new Assets_Loader();
720 $this->uploads_manager = new Uploads_Manager();
721
722 $this->admin_menu_manager = new Admin_Menu_Manager();
723 $this->admin_menu_manager->register_actions();
724
725 User::init();
726 User_Data::init();
727 Api::init();
728 Tracker::init();
729
730 $this->upgrade = new Core\Upgrade\Manager();
731 $this->custom_tasks = new Core\Upgrade\Custom_Tasks_Manager();
732
733 $this->app = new App\App();
734
735 if ( is_admin() ) {
736 $this->heartbeat = new Heartbeat();
737 $this->wordpress_widgets_manager = new WordPress_Widgets_Manager();
738 $this->admin = new Admin();
739 $this->beta_testers = new Beta_Testers();
740 }
741 }
742
743 /**
744 * @since 2.3.0
745 * @access public
746 */
747 public function init_common() {
748 $this->common = new CommonApp();
749
750 $this->common->init_components();
751 }
752
753 /**
754 * Add custom post type support.
755 *
756 * Register Elementor support for all the supported post types defined by
757 * the user in the admin screen and saved as `elementor_cpt_support` option
758 * in WordPress `$wpdb->options` table.
759 *
760 * If no custom post type selected, usually in new installs, this method
761 * will return the two default post types: `page` and `post`.
762 *
763 * @since 1.0.0
764 * @access private
765 */
766 private function add_cpt_support() {
767 $cpt_support = get_option( 'elementor_cpt_support', self::ELEMENTOR_DEFAULT_POST_TYPES );
768
769 foreach ( $cpt_support as $cpt_slug ) {
770 add_post_type_support( $cpt_slug, 'elementor' );
771 }
772 }
773
774 /**
775 * Register autoloader.
776 *
777 * Elementor autoloader loads all the classes needed to run the plugin.
778 *
779 * @since 1.6.0
780 * @access private
781 */
782 private function register_autoloader() {
783 require_once ELEMENTOR_PATH . '/includes/autoloader.php';
784
785 Autoloader::run();
786 }
787
788 /**
789 * Magic getter for accessing certain properties.
790 *
791 * @since 3.1.0
792 * @access public
793 *
794 * @param string $property The property name.
795 * @return mixed The property value or null if not found.
796 * @throws \Exception If trying to access a private property.
797 */
798 public function __get( $property ) {
799 if ( 'posts_css_manager' === $property ) {
800 self::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_argument( 'Plugin::$instance->posts_css_manager', '2.7.0', 'Plugin::$instance->files_manager' );
801
802 return $this->files_manager;
803 }
804
805 if ( 'data_manager' === $property ) {
806 return Data_Manager::instance();
807 }
808
809 if ( property_exists( $this, $property ) ) {
810 throw new \Exception( 'Cannot access private property.' );
811 }
812
813 return null;
814 }
815
816 /**
817 * Plugin constructor.
818 *
819 * Initializing Elementor plugin.
820 *
821 * @since 1.0.0
822 * @access private
823 */
824 private function __construct() {
825 $this->register_autoloader();
826
827 $this->logger = Log_Manager::instance();
828 $this->data_manager_v2 = Data_Manager_V2::instance();
829
830 Maintenance::init();
831 Compatibility::register_actions();
832
833 add_action( 'init', [ $this, 'init' ], 0 );
834 add_action( 'rest_api_init', [ $this, 'on_rest_api_init' ], 9 );
835 add_filter( 'rest_pre_insert_post', [ $this, 'sanitize_post_data' ], 10, 2 );
836 }
837
838 final public static function get_title() {
839 return esc_html__( 'Elementor', 'elementor' );
840 }
841
842 public function sanitize_post_data( $post, WP_REST_Request $request ) {
843 if ( current_user_can( 'unfiltered_html' ) ) {
844 return $post;
845 }
846
847 $meta = $request->get_param( 'meta' );
848 if ( empty( $meta ) || ! is_array( $meta ) ) {
849 return $post;
850 }
851
852 foreach ( self::SANITIZABLE_META_KEYS as $meta_key ) {
853 $elementor_data = $meta[ $meta_key ] ?? null;
854 if ( is_null( $elementor_data ) ) {
855 continue;
856 }
857 if ( is_string( $elementor_data ) ) {
858 $elementor_data = json_decode( $elementor_data, true );
859 }
860 if ( empty( $elementor_data ) ) {
861 continue;
862 }
863
864 $elementor_data = map_deep($elementor_data, function ( $value ) {
865 return is_bool( $value ) || is_null( $value ) ? $value : wp_kses_post( $value );
866 });
867
868 $meta[ $meta_key ] = wp_json_encode( $elementor_data );
869 }
870
871 $request->set_param( 'meta', $meta );
872 return $post;
873 }
874 }
875
876 if ( ! defined( 'ELEMENTOR_TESTS' ) ) {
877 // In tests we run the instance manually.
878 Plugin::instance();
879 }
880