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

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