forked from elementor/elementor-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
105 lines (88 loc) · 2.5 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace ElementorBeta;
use ElementorBeta\Core\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Bootstrap {
const ELEMENTOR_PLUGIN_NAME = 'elementor/elementor.php';
const ELEMENTOR_PRO_PLUGIN_NAME = 'elementor-pro/elementor-pro.php';
/**
* Bootstrap constructor.
*/
public function __construct() {
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
}
/**
* Plugins loaded.
*/
public function plugins_loaded() {
load_plugin_textdomain( 'elementor-beta' );
if ( ! $this->is_elementor_class_exists() ) {
add_action( 'admin_notices', [ $this, 'notice_elementor_class_not_exists' ] );
return;
}
// initiate the plugin.
Plugin::instance();
}
/**
* Notice to admin that elementor class is not exists.
*/
public function notice_elementor_class_not_exists() {
if ( $this->is_install_screen() ) {
return;
}
if ( ! $this->is_elementor_installed() && current_user_can( 'install_plugins' ) ) {
require __DIR__ . '/views/admin-notices/elementor-not-installed.php';
} elseif ( ! $this->is_elementor_active() && current_user_can( 'activate_plugin', self::ELEMENTOR_PLUGIN_NAME ) ) {
require __DIR__ . '/views/admin-notices/elementor-not-active.php';
}
}
/**
* Get all the plugins.
*
* This method is mostly for unit tests (mock this method to demonstrate a case that elementor is not installed).
*
* @return array[]
*/
protected function get_plugins() {
return get_plugins();
}
/**
* Checks if elementor is active.
*
* This method is protected and not private mostly for unit tests (mock this method to demonstrate a case that elementor is not active).
*
* @return bool
*/
protected function is_elementor_active() {
return is_plugin_active( self::ELEMENTOR_PLUGIN_NAME );
}
/**
* Checks if elementor class exists.
* this is an early check before it can check if the plugin installed or active.
*
* @return bool
*/
private function is_elementor_class_exists() {
return class_exists( 'Elementor\\Plugin' );
}
/**
* Checks if elementor is installed.
*
* @return bool
*/
private function is_elementor_installed() {
$installed_plugins = $this->get_plugins();
return isset( $installed_plugins[ self::ELEMENTOR_PLUGIN_NAME ] );
}
/**
* Checks if is in install page.
*
* @return bool
*/
private function is_install_screen() {
$screen = get_current_screen();
return isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id;
}
}