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

769 lines 14.2 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\Wp_Api;
5 use Elementor\Core\Admin\Admin;
6 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
7 use Elementor\Core\Common\App as CommonApp;
8 use Elementor\Core\Debug\Inspector;
9 use Elementor\Core\Documents_Manager;
10 use Elementor\Core\Experiments\Manager as Experiments_Manager;
11 use Elementor\Core\Kits\Manager as Kits_Manager;
12 use Elementor\Core\Editor\Editor;
13 use Elementor\Core\Files\Manager as Files_Manager;
14 use Elementor\Core\Files\Assets\Manager as Assets_Manager;
15 use Elementor\Core\Modules_Manager;
16 use Elementor\Core\Schemes\Manager as Schemes_Manager;
17 use Elementor\Core\Settings\Manager as Settings_Manager;
18 use Elementor\Core\Settings\Page\Manager as Page_Settings_Manager;
19 use Elementor\Core\Upgrade\Elementor_3_Re_Migrate_Globals;
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\Modules\System_Info\Module as System_Info_Module;
24 use Elementor\Data\Manager as Data_Manager;
25 use Elementor\Core\Common\Modules\DevTools\Module as Dev_Tools;
26
27 if ( ! defined( 'ABSPATH' ) ) {
28 exit;
29 }
30
31 /**
32 * Elementor plugin.
33 *
34 * The main plugin handler class is responsible for initializing Elementor. The
35 * class registers and all the components required to run the plugin.
36 *
37 * @since 1.0.0
38 */
39 class Plugin {
40
41 /**
42 * Instance.
43 *
44 * Holds the plugin instance.
45 *
46 * @since 1.0.0
47 * @access public
48 * @static
49 *
50 * @var Plugin
51 */
52 public static $instance = null;
53
54 /**
55 * Database.
56 *
57 * Holds the plugin database.
58 *
59 * @since 1.0.0
60 * @access public
61 *
62 * @var DB
63 */
64 public $db;
65
66 /**
67 * Ajax Manager.
68 *
69 * Holds the plugin ajax manager.
70 *
71 * @since 1.9.0
72 * @deprecated 2.3.0 Use `Plugin::$instance->common->get_component( 'ajax' )` instead
73 * @access public
74 *
75 * @var Ajax
76 */
77 public $ajax;
78
79 /**
80 * Controls manager.
81 *
82 * Holds the plugin controls manager.
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 * Schemes manager.
105 *
106 * Holds the plugin schemes manager.
107 *
108 * @since 1.0.0
109 * @access public
110 *
111 * @var Schemes_Manager
112 */
113 public $schemes_manager;
114
115 /**
116 * Elements manager.
117 *
118 * Holds the plugin elements manager.
119 *
120 * @since 1.0.0
121 * @access public
122 *
123 * @var Elements_Manager
124 */
125 public $elements_manager;
126
127 /**
128 * Widgets manager.
129 *
130 * Holds the plugin widgets manager.
131 *
132 * @since 1.0.0
133 * @access public
134 *
135 * @var Widgets_Manager
136 */
137 public $widgets_manager;
138
139 /**
140 * Revisions manager.
141 *
142 * Holds the plugin revisions manager.
143 *
144 * @since 1.0.0
145 * @access public
146 *
147 * @var Revisions_Manager
148 */
149 public $revisions_manager;
150
151 /**
152 * Images manager.
153 *
154 * Holds the plugin images manager.
155 *
156 * @since 2.9.0
157 * @access public
158 *
159 * @var Images_Manager
160 */
161 public $images_manager;
162
163 /**
164 * Maintenance mode.
165 *
166 * Holds the plugin maintenance mode.
167 *
168 * @since 1.0.0
169 * @access public
170 *
171 * @var Maintenance_Mode
172 */
173 public $maintenance_mode;
174
175 /**
176 * Page settings manager.
177 *
178 * Holds the page settings manager.
179 *
180 * @since 1.0.0
181 * @access public
182 *
183 * @var Page_Settings_Manager
184 */
185 public $page_settings_manager;
186
187 /**
188 * Dynamic tags manager.
189 *
190 * Holds the dynamic tags manager.
191 *
192 * @since 1.0.0
193 * @access public
194 *
195 * @var Dynamic_Tags_Manager
196 */
197 public $dynamic_tags;
198
199 /**
200 * Settings.
201 *
202 * Holds the plugin settings.
203 *
204 * @since 1.0.0
205 * @access public
206 *
207 * @var Settings
208 */
209 public $settings;
210
211 /**
212 * Role Manager.
213 *
214 * Holds the plugin Role Manager
215 *
216 * @since 2.0.0
217 * @access public
218 *
219 * @var \Elementor\Core\RoleManager\Role_Manager
220 */
221 public $role_manager;
222
223 /**
224 * Admin.
225 *
226 * Holds the plugin admin.
227 *
228 * @since 1.0.0
229 * @access public
230 *
231 * @var Admin
232 */
233 public $admin;
234
235 /**
236 * Tools.
237 *
238 * Holds the plugin tools.
239 *
240 * @since 1.0.0
241 * @access public
242 *
243 * @var Tools
244 */
245 public $tools;
246
247 /**
248 * Preview.
249 *
250 * Holds the plugin preview.
251 *
252 * @since 1.0.0
253 * @access public
254 *
255 * @var Preview
256 */
257 public $preview;
258
259 /**
260 * Editor.
261 *
262 * Holds the plugin editor.
263 *
264 * @since 1.0.0
265 * @access public
266 *
267 * @var Editor
268 */
269 public $editor;
270
271 /**
272 * Frontend.
273 *
274 * Holds the plugin frontend.
275 *
276 * @since 1.0.0
277 * @access public
278 *
279 * @var Frontend
280 */
281 public $frontend;
282
283 /**
284 * Heartbeat.
285 *
286 * Holds the plugin heartbeat.
287 *
288 * @since 1.0.0
289 * @access public
290 *
291 * @var Heartbeat
292 */
293 public $heartbeat;
294
295 /**
296 * System info.
297 *
298 * Holds the system info data.
299 *
300 * @since 1.0.0
301 * @access public
302 *
303 * @var System_Info\Main
304 */
305 public $system_info;
306
307 /**
308 * Template library manager.
309 *
310 * Holds the template library manager.
311 *
312 * @since 1.0.0
313 * @access public
314 *
315 * @var TemplateLibrary\Manager
316 */
317 public $templates_manager;
318
319 /**
320 * Skins manager.
321 *
322 * Holds the skins manager.
323 *
324 * @since 1.0.0
325 * @access public
326 *
327 * @var Skins_Manager
328 */
329 public $skins_manager;
330
331 /**
332 * Files Manager.
333 *
334 * Holds the files manager.
335 *
336 * @since 2.1.0
337 * @access public
338 *
339 * @var Files_Manager
340 */
341 public $files_manager;
342
343 /**
344 * Assets Manager.
345 *
346 * Holds the Assets manager.
347 *
348 * @since 2.6.0
349 * @access public
350 *
351 * @var Assets_Manager
352 */
353 public $assets_manager;
354
355 /**
356 * Files Manager.
357 *
358 * Holds the files manager.
359 *
360 * @since 1.0.0
361 * @access public
362 * @deprecated 2.1.0 Use `Plugin::$files_manager` instead
363 *
364 * @var Files_Manager
365 */
366 private $posts_css_manager;
367
368 /**
369 * WordPress widgets manager.
370 *
371 * Holds the WordPress widgets manager.
372 *
373 * @since 1.0.0
374 * @access public
375 *
376 * @var WordPress_Widgets_Manager
377 */
378 public $wordpress_widgets_manager;
379
380 /**
381 * Modules manager.
382 *
383 * Holds the modules manager.
384 *
385 * @since 1.0.0
386 * @access public
387 *
388 * @var Modules_Manager
389 */
390 public $modules_manager;
391
392 /**
393 * Beta testers.
394 *
395 * Holds the plugin beta testers.
396 *
397 * @since 1.0.0
398 * @access public
399 *
400 * @var Beta_Testers
401 */
402 public $beta_testers;
403
404 /**
405 * @var Inspector
406 * @deprecated 2.1.2 Use $inspector.
407 */
408 public $debugger;
409
410 /**
411 * @var Inspector
412 */
413 public $inspector;
414
415 /**
416 * @var CommonApp
417 */
418 public $common;
419
420 /**
421 * @var Log_Manager
422 */
423 public $logger;
424
425 /**
426 * @var Dev_Tools
427 */
428 private $dev_tools;
429
430 /**
431 * @var Core\Upgrade\Manager
432 */
433 public $upgrade;
434
435 /**
436 * @var Core\Kits\Manager
437 */
438 public $kits_manager;
439
440 /**
441 * @var \Core\Data\Manager
442 */
443 public $data_manager;
444
445 public $legacy_mode;
446
447 /**
448 * @var Core\App\App
449 */
450 public $app;
451
452 /**
453 * @var Wp_Api
454 */
455 public $wp;
456
457 /**
458 * @var Experiments_Manager
459 */
460 public $experiments;
461
462 /**
463 * Clone.
464 *
465 * Disable class cloning and throw an error on object clone.
466 *
467 * The whole idea of the singleton design pattern is that there is a single
468 * object. Therefore, we don't want the object to be cloned.
469 *
470 * @access public
471 * @since 1.0.0
472 */
473 public function __clone() {
474 // Cloning instances of the class is forbidden.
475 _doing_it_wrong( __FUNCTION__, esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
476 }
477
478 /**
479 * Wakeup.
480 *
481 * Disable unserializing of the class.
482 *
483 * @access public
484 * @since 1.0.0
485 */
486 public function __wakeup() {
487 // Unserializing instances of the class is forbidden.
488 _doing_it_wrong( __FUNCTION__, esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
489 }
490
491 /**
492 * Instance.
493 *
494 * Ensures only one instance of the plugin class is loaded or can be loaded.
495 *
496 * @since 1.0.0
497 * @access public
498 * @static
499 *
500 * @return Plugin An instance of the class.
501 */
502 public static function instance() {
503 if ( is_null( self::$instance ) ) {
504 self::$instance = new self();
505
506 /**
507 * Elementor loaded.
508 *
509 * Fires when Elementor was fully loaded and instantiated.
510 *
511 * @since 1.0.0
512 */
513 do_action( 'elementor/loaded' );
514 }
515
516 return self::$instance;
517 }
518
519 /**
520 * Init.
521 *
522 * Initialize Elementor Plugin. Register Elementor support for all the
523 * supported post types and initialize Elementor components.
524 *
525 * @since 1.0.0
526 * @access public
527 */
528 public function init() {
529 $this->add_cpt_support();
530
531 $this->init_components();
532
533 /**
534 * Elementor init.
535 *
536 * Fires on Elementor init, after Elementor has finished loading but
537 * before any headers are sent.
538 *
539 * @since 1.0.0
540 */
541 do_action( 'elementor/init' );
542 }
543
544 /**
545 * Get install time.
546 *
547 * Retrieve the time when Elementor was installed.
548 *
549 * @since 2.6.0
550 * @access public
551 * @static
552 *
553 * @return int Unix timestamp when Elementor was installed.
554 */
555 public function get_install_time() {
556 $installed_time = get_option( '_elementor_installed_time' );
557
558 if ( ! $installed_time ) {
559 $installed_time = time();
560
561 update_option( '_elementor_installed_time', $installed_time );
562 }
563
564 return $installed_time;
565 }
566
567 /**
568 * @since 2.3.0
569 * @access public
570 */
571 public function on_rest_api_init() {
572 // On admin/frontend sometimes the rest API is initialized after the common is initialized.
573 if ( ! $this->common ) {
574 $this->init_common();
575 }
576 }
577
578 /**
579 * Init components.
580 *
581 * Initialize Elementor components. Register actions, run setting manager,
582 * initialize all the components that run elementor, and if in admin page
583 * initialize admin components.
584 *
585 * @since 1.0.0
586 * @access private
587 */
588 private function init_components() {
589 $this->experiments = new Experiments_Manager();
590 $this->inspector = new Inspector();
591 $this->debugger = $this->inspector;
592
593 Settings_Manager::run();
594
595 $this->db = new DB();
596 $this->controls_manager = new Controls_Manager();
597 $this->documents = new Documents_Manager();
598 $this->kits_manager = new Kits_Manager();
599 $this->schemes_manager = new Schemes_Manager();
600 $this->elements_manager = new Elements_Manager();
601 $this->widgets_manager = new Widgets_Manager();
602 $this->skins_manager = new Skins_Manager();
603 $this->files_manager = new Files_Manager();
604 $this->assets_manager = new Assets_Manager();
605 $this->icons_manager = new Icons_Manager();
606 $this->settings = new Settings();
607 $this->tools = new Tools();
608 $this->editor = new Editor();
609 $this->preview = new Preview();
610 $this->frontend = new Frontend();
611 $this->maintenance_mode = new Maintenance_Mode();
612 $this->dynamic_tags = new Dynamic_Tags_Manager();
613 $this->modules_manager = new Modules_Manager();
614 $this->templates_manager = new TemplateLibrary\Manager();
615 $this->role_manager = new Core\RoleManager\Role_Manager();
616 $this->system_info = new System_Info_Module();
617 $this->revisions_manager = new Revisions_Manager();
618 $this->images_manager = new Images_Manager();
619 $this->wp = new Wp_Api();
620
621 User::init();
622 Api::init();
623 Tracker::init();
624
625 $this->upgrade = new Core\Upgrade\Manager();
626
627 $this->app = new Core\App\App();
628
629 if ( is_admin() ) {
630 $this->heartbeat = new Heartbeat();
631 $this->wordpress_widgets_manager = new WordPress_Widgets_Manager();
632 $this->admin = new Admin();
633 $this->beta_testers = new Beta_Testers();
634 new Elementor_3_Re_Migrate_Globals();
635 }
636 }
637
638 /**
639 * @since 2.3.0
640 * @access public
641 */
642 public function init_common() {
643 $this->common = new CommonApp();
644
645 $this->common->init_components();
646
647 $this->ajax = $this->common->get_component( 'ajax' );
648 }
649
650 /**
651 * Get Legacy Mode
652 *
653 * @since 3.0.0
654 * @deprecated 3.1.0 Use `Plugin::$instance->experiments->is_feature_active()` instead
655 *
656 * @param string $mode_name Optional. Default is null
657 *
658 * @return bool|bool[]
659 */
660 public function get_legacy_mode( $mode_name = null ) {
661 self::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation
662 ->deprecated_function( __METHOD__, '3.1.0', 'Plugin::$instance->experiments->is_feature_active()' );
663
664 $legacy_mode = [
665 'elementWrappers' => ! self::$instance->experiments->is_feature_active( 'e_dom_optimization' ),
666 ];
667
668 if ( ! $mode_name ) {
669 return $legacy_mode;
670 }
671
672 if ( isset( $legacy_mode[ $mode_name ] ) ) {
673 return $legacy_mode[ $mode_name ];
674 }
675
676 // If there is no legacy mode with the given mode name;
677 return false;
678 }
679
680 /**
681 * Add custom post type support.
682 *
683 * Register Elementor support for all the supported post types defined by
684 * the user in the admin screen and saved as `elementor_cpt_support` option
685 * in WordPress `$wpdb->options` table.
686 *
687 * If no custom post type selected, usually in new installs, this method
688 * will return the two default post types: `page` and `post`.
689 *
690 * @since 1.0.0
691 * @access private
692 */
693 private function add_cpt_support() {
694 $cpt_support = get_option( 'elementor_cpt_support', [ 'page', 'post' ] );
695
696 foreach ( $cpt_support as $cpt_slug ) {
697 add_post_type_support( $cpt_slug, 'elementor' );
698 }
699 }
700
701 /**
702 * Register autoloader.
703 *
704 * Elementor autoloader loads all the classes needed to run the plugin.
705 *
706 * @since 1.6.0
707 * @access private
708 */
709 private function register_autoloader() {
710 require_once ELEMENTOR_PATH . '/includes/autoloader.php';
711
712 Autoloader::run();
713 }
714
715 /**
716 * Plugin Magic Getter
717 *
718 * @since 3.1.0
719 * @access public
720 *
721 * @param $property
722 * @return mixed
723 * @throws \Exception
724 */
725 public function __get( $property ) {
726 if ( 'posts_css_manager' === $property ) {
727 self::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_argument( 'Plugin::$instance->posts_css_manager', '2.7.0', 'Plugin::$instance->files_manager' );
728
729 return $this->files_manager;
730 }
731
732 if ( property_exists( $this, $property ) ) {
733 throw new \Exception( 'Cannot access private property' );
734 }
735
736 return null;
737 }
738
739 /**
740 * Plugin constructor.
741 *
742 * Initializing Elementor plugin.
743 *
744 * @since 1.0.0
745 * @access private
746 */
747 private function __construct() {
748 $this->register_autoloader();
749
750 $this->logger = Log_Manager::instance();
751 $this->data_manager = Data_Manager::instance();
752
753 Maintenance::init();
754 Compatibility::register_actions();
755
756 add_action( 'init', [ $this, 'init' ], 0 );
757 add_action( 'rest_api_init', [ $this, 'on_rest_api_init' ] );
758 }
759
760 final public static function get_title() {
761 return __( 'Elementor', 'elementor' );
762 }
763 }
764
765 if ( ! defined( 'ELEMENTOR_TESTS' ) ) {
766 // In tests we run the instance manually.
767 Plugin::instance();
768 }
769