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