plugin.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <?php
  2. namespace Elementor;
  3. use Elementor\Core\Ajax_Manager;
  4. use Elementor\Core\Debug\Inspector;
  5. use Elementor\Core\Documents_Manager;
  6. use Elementor\Core\Files\Manager as Files_Manager;
  7. use Elementor\Core\Modules_Manager;
  8. use Elementor\Debug\Debug;
  9. use Elementor\Core\Settings\Manager as Settings_Manager;
  10. use Elementor\Core\Settings\Page\Manager as Page_Settings_Manager;
  11. use Elementor\Modules\History\Revisions_Manager;
  12. use Elementor\Core\DynamicTags\Manager as Dynamic_Tags_Manager;
  13. if ( ! defined( 'ABSPATH' ) ) {
  14. exit;
  15. }
  16. /**
  17. * Elementor plugin.
  18. *
  19. * The main plugin handler class is responsible for initializing Elementor. The
  20. * class registers and all the components required to run the plugin.
  21. *
  22. * @since 1.0.0
  23. */
  24. class Plugin {
  25. /**
  26. * Instance.
  27. *
  28. * Holds the plugin instance.
  29. *
  30. * @since 1.0.0
  31. * @access public
  32. * @static
  33. *
  34. * @var Plugin
  35. */
  36. public static $instance = null;
  37. /**
  38. * Database.
  39. *
  40. * Holds the plugin database.
  41. *
  42. * @since 1.0.0
  43. * @access public
  44. *
  45. * @var DB
  46. */
  47. public $db;
  48. /**
  49. * Ajax Manager.
  50. *
  51. * Holds the plugin ajax manager.
  52. *
  53. * @since 1.9.0
  54. * @access public
  55. *
  56. * @var Ajax_Manager
  57. */
  58. public $ajax;
  59. /**
  60. * Controls manager.
  61. *
  62. * Holds the plugin controls manager.
  63. *
  64. * @since 1.0.0
  65. * @access public
  66. *
  67. * @var Controls_Manager
  68. */
  69. public $controls_manager;
  70. /**
  71. * Debug.
  72. *
  73. * Holds the plugin debug.
  74. *
  75. * @since 1.0.0
  76. * @access public
  77. *
  78. * @var Debug
  79. */
  80. public $debug;
  81. /**
  82. * Documents manager.
  83. *
  84. * Holds the documents manager.
  85. *
  86. * @since 2.0.0
  87. * @access public
  88. *
  89. * @var Documents_Manager
  90. */
  91. public $documents;
  92. /**
  93. * Schemes manager.
  94. *
  95. * Holds the plugin schemes manager.
  96. *
  97. * @since 1.0.0
  98. * @access public
  99. *
  100. * @var Schemes_Manager
  101. */
  102. public $schemes_manager;
  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. * Widgets manager.
  116. *
  117. * Holds the plugin widgets manager.
  118. *
  119. * @since 1.0.0
  120. * @access public
  121. *
  122. * @var Widgets_Manager
  123. */
  124. public $widgets_manager;
  125. /**
  126. * Revisions manager.
  127. *
  128. * Holds the plugin revisions manager.
  129. *
  130. * @since 1.0.0
  131. * @access public
  132. *
  133. * @var Revisions_Manager
  134. */
  135. public $revisions_manager;
  136. /**
  137. * Maintenance mode.
  138. *
  139. * Holds the plugin maintenance mode.
  140. *
  141. * @since 1.0.0
  142. * @access public
  143. *
  144. * @var Maintenance_Mode
  145. */
  146. public $maintenance_mode;
  147. /**
  148. * Page settings manager.
  149. *
  150. * Holds the page settings manager.
  151. *
  152. * @since 1.0.0
  153. * @access public
  154. *
  155. * @var Page_Settings_Manager
  156. */
  157. public $page_settings_manager;
  158. /**
  159. * Dynamic tags manager.
  160. *
  161. * Holds the dynamic tags manager.
  162. *
  163. * @since 1.0.0
  164. * @access public
  165. *
  166. * @var Dynamic_Tags_Manager
  167. */
  168. public $dynamic_tags;
  169. /**
  170. * Settings.
  171. *
  172. * Holds the plugin settings.
  173. *
  174. * @since 1.0.0
  175. * @access public
  176. *
  177. * @var Settings
  178. */
  179. public $settings;
  180. /**
  181. * Role Manager.
  182. *
  183. * Holds the plugin Role Manager
  184. *
  185. * @since 2.0.0
  186. * @access public
  187. *
  188. * @var \Elementor\Core\RoleManager\Role_Manager
  189. */
  190. public $role_manager;
  191. /**
  192. * Admin.
  193. *
  194. * Holds the plugin admin.
  195. *
  196. * @since 1.0.0
  197. * @access public
  198. *
  199. * @var Admin
  200. */
  201. public $admin;
  202. /**
  203. * Tools.
  204. *
  205. * Holds the plugin tools.
  206. *
  207. * @since 1.0.0
  208. * @access public
  209. *
  210. * @var Tools
  211. */
  212. public $tools;
  213. /**
  214. * Preview.
  215. *
  216. * Holds the plugin preview.
  217. *
  218. * @since 1.0.0
  219. * @access public
  220. *
  221. * @var Preview
  222. */
  223. public $preview;
  224. /**
  225. * Editor.
  226. *
  227. * Holds the plugin editor.
  228. *
  229. * @since 1.0.0
  230. * @access public
  231. *
  232. * @var Editor
  233. */
  234. public $editor;
  235. /**
  236. * Frontend.
  237. *
  238. * Holds the plugin frontend.
  239. *
  240. * @since 1.0.0
  241. * @access public
  242. *
  243. * @var Frontend
  244. */
  245. public $frontend;
  246. /**
  247. * Heartbeat.
  248. *
  249. * Holds the plugin heartbeat.
  250. *
  251. * @since 1.0.0
  252. * @access public
  253. *
  254. * @var Heartbeat
  255. */
  256. public $heartbeat;
  257. /**
  258. * System info.
  259. *
  260. * Holds the system info data.
  261. *
  262. * @since 1.0.0
  263. * @access public
  264. *
  265. * @var System_Info\Main
  266. */
  267. public $system_info;
  268. /**
  269. * Template library manager.
  270. *
  271. * Holds the template library manager.
  272. *
  273. * @since 1.0.0
  274. * @access public
  275. *
  276. * @var TemplateLibrary\Manager
  277. */
  278. public $templates_manager;
  279. /**
  280. * Skins manager.
  281. *
  282. * Holds the skins manager.
  283. *
  284. * @since 1.0.0
  285. * @access public
  286. *
  287. * @var Skins_Manager
  288. */
  289. public $skins_manager;
  290. /**
  291. * Files Manager.
  292. *
  293. * Holds the files manager.
  294. *
  295. * @since 2.1.0
  296. * @access public
  297. *
  298. * @var Files_Manager
  299. */
  300. public $files_manager;
  301. /**
  302. * Files Manager.
  303. *
  304. * Holds the files manager.
  305. *
  306. * @since 1.0.0
  307. * @access public
  308. * @deprecated 2.1.0 Use `Plugin::$files_manager` instead
  309. *
  310. * @var Files_Manager
  311. */
  312. public $posts_css_manager;
  313. /**
  314. * WordPress widgets manager.
  315. *
  316. * Holds the WordPress widgets manager.
  317. *
  318. * @since 1.0.0
  319. * @access public
  320. *
  321. * @var WordPress_Widgets_Manager
  322. */
  323. public $wordpress_widgets_manager;
  324. /**
  325. * Modules manager.
  326. *
  327. * Holds the modules manager.
  328. *
  329. * @since 1.0.0
  330. * @access public
  331. *
  332. * @var Modules_Manager
  333. */
  334. public $modules_manager;
  335. /**
  336. * Beta testers.
  337. *
  338. * Holds the plugin beta testers.
  339. *
  340. * @since 1.0.0
  341. * @access public
  342. *
  343. * @var Beta_Testers
  344. */
  345. public $beta_testers;
  346. /**
  347. * @var Inspector
  348. * @deprecated 2.1.2 Use $inspector.
  349. */
  350. public $debugger;
  351. /**
  352. * @var Inspector
  353. */
  354. public $inspector;
  355. /**
  356. * Clone.
  357. *
  358. * Disable class cloning and throw an error on object clone.
  359. *
  360. * The whole idea of the singleton design pattern is that there is a single
  361. * object. Therefore, we don't want the object to be cloned.
  362. *
  363. * @access public
  364. * @since 1.0.0
  365. */
  366. public function __clone() {
  367. // Cloning instances of the class is forbidden.
  368. _doing_it_wrong( __FUNCTION__, esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
  369. }
  370. /**
  371. * Wakeup.
  372. *
  373. * Disable unserializing of the class.
  374. *
  375. * @access public
  376. * @since 1.0.0
  377. */
  378. public function __wakeup() {
  379. // Unserializing instances of the class is forbidden.
  380. _doing_it_wrong( __FUNCTION__, esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
  381. }
  382. /**
  383. * Instance.
  384. *
  385. * Ensures only one instance of the plugin class is loaded or can be loaded.
  386. *
  387. * @since 1.0.0
  388. * @access public
  389. * @static
  390. *
  391. * @return Plugin An instance of the class.
  392. */
  393. public static function instance() {
  394. if ( is_null( self::$instance ) ) {
  395. self::$instance = new self();
  396. /**
  397. * Elementor loaded.
  398. *
  399. * Fires when Elementor was fully loaded and instantiated.
  400. *
  401. * @since 1.0.0
  402. */
  403. do_action( 'elementor/loaded' );
  404. }
  405. return self::$instance;
  406. }
  407. /**
  408. * Init.
  409. *
  410. * Initialize Elementor Plugin. Register Elementor support for all the
  411. * supported post types and initialize Elementor components.
  412. *
  413. * @since 1.0.0
  414. * @access public
  415. */
  416. public function init() {
  417. $this->add_cpt_support();
  418. $this->init_components();
  419. /**
  420. * Elementor init.
  421. *
  422. * Fires on Elementor init, after Elementor has finished loading but
  423. * before any headers are sent.
  424. *
  425. * @since 1.0.0
  426. */
  427. do_action( 'elementor/init' );
  428. }
  429. /**
  430. * Init components.
  431. *
  432. * Initialize Elementor components. Register actions, run setting manager,
  433. * initialize all the components that run elementor, and if in admin page
  434. * initialize admin components.
  435. *
  436. * @since 1.0.0
  437. * @access private
  438. */
  439. private function init_components() {
  440. $this->inspector = new Inspector();
  441. $this->debugger = $this->inspector;
  442. // Allow all components to use AJAX.
  443. $this->ajax = new Ajax_Manager();
  444. Settings_Manager::run();
  445. $this->db = new DB();
  446. $this->controls_manager = new Controls_Manager();
  447. $this->documents = new Documents_Manager();
  448. $this->schemes_manager = new Schemes_Manager();
  449. $this->elements_manager = new Elements_Manager();
  450. $this->widgets_manager = new Widgets_Manager();
  451. $this->skins_manager = new Skins_Manager();
  452. $this->files_manager = new Files_Manager();
  453. /*
  454. * @TODO: Remove deprecated alias
  455. */
  456. $this->posts_css_manager = $this->files_manager;
  457. $this->settings = new Settings();
  458. $this->editor = new Editor();
  459. $this->preview = new Preview();
  460. $this->frontend = new Frontend();
  461. $this->debug = new Debug();
  462. $this->templates_manager = new TemplateLibrary\Manager();
  463. $this->maintenance_mode = new Maintenance_Mode();
  464. $this->dynamic_tags = new Dynamic_Tags_Manager();
  465. $this->modules_manager = new Modules_Manager();
  466. $this->role_manager = new Core\RoleManager\Role_Manager();
  467. Upgrades::add_actions();
  468. Api::init();
  469. Tracker::init();
  470. if ( is_admin() ) {
  471. $this->revisions_manager = new Revisions_Manager();
  472. $this->heartbeat = new Heartbeat();
  473. $this->wordpress_widgets_manager = new WordPress_Widgets_Manager();
  474. $this->system_info = new System_Info\Main();
  475. $this->admin = new Core\Admin\Admin();
  476. $this->tools = new Tools();
  477. $this->beta_testers = new Beta_Testers();
  478. if ( Utils::is_ajax() ) {
  479. new Images_Manager();
  480. }
  481. }
  482. }
  483. /**
  484. * Add custom post type support.
  485. *
  486. * Register Elementor support for all the supported post types defined by
  487. * the user in the admin screen and saved as `elementor_cpt_support` option
  488. * in WordPress `$wpdb->options` table.
  489. *
  490. * If no custom post type selected, usually in new installs, this method
  491. * will return the two default post types: `page` and `post`.
  492. *
  493. * @since 1.0.0
  494. * @access private
  495. */
  496. private function add_cpt_support() {
  497. $cpt_support = get_option( 'elementor_cpt_support', [ 'page', 'post' ] );
  498. foreach ( $cpt_support as $cpt_slug ) {
  499. add_post_type_support( $cpt_slug, 'elementor' );
  500. }
  501. }
  502. /**
  503. * Register autoloader.
  504. *
  505. * Elementor autoloader loads all the classes needed to run the plugin.
  506. *
  507. * @since 1.6.0
  508. * @access private
  509. */
  510. private function register_autoloader() {
  511. require ELEMENTOR_PATH . '/includes/autoloader.php';
  512. Autoloader::run();
  513. }
  514. /**
  515. * Plugin constructor.
  516. *
  517. * Initializing Elementor plugin.
  518. *
  519. * @since 1.0.0
  520. * @access private
  521. */
  522. private function __construct() {
  523. $this->register_autoloader();
  524. Maintenance::init();
  525. Compatibility::register_actions();
  526. add_action( 'init', [ $this, 'init' ], 0 );
  527. }
  528. }
  529. if ( ! defined( 'ELEMENTOR_TESTS' ) ) {
  530. // In tests we run the instance manually.
  531. Plugin::instance();
  532. }