PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.1
Elementor Website Builder – more than just a page builder v4.0.1
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.0.1, at includes/plugin.php

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