1
|
|
|
<?php namespace EmailLog\Core; |
2
|
|
|
|
3
|
|
|
use EmailLog\Core\DB\TableManager; |
4
|
|
|
use EmailLog\EmailLogAutoloader; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* The main plugin class. |
8
|
|
|
* |
9
|
|
|
* @since Genesis |
10
|
|
|
*/ |
11
|
|
|
class EmailLog { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Plugin Version number. |
15
|
|
|
* |
16
|
|
|
* @since Genesis |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
const VERSION = '2.0.0'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Flag to track if the plugin is loaded. |
23
|
|
|
* |
24
|
|
|
* @since 2.0 |
25
|
|
|
* @access private |
26
|
|
|
* @var bool |
27
|
|
|
*/ |
28
|
|
|
private $loaded = false; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Plugin file path. |
32
|
|
|
* |
33
|
|
|
* @since 2.0 |
34
|
|
|
* @access private |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $plugin_file; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Filesystem directory path where translations are stored. |
41
|
|
|
* |
42
|
|
|
* @since 2.0 |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
public $translations_path; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Auto loader. |
49
|
|
|
* |
50
|
|
|
* @var \EmailLog\EmailLogAutoloader |
51
|
|
|
*/ |
52
|
|
|
public $loader; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Database Table Manager. |
56
|
|
|
* |
57
|
|
|
* @since 2.0 |
58
|
|
|
* @var \EmailLog\Core\DB\TableManager |
59
|
|
|
*/ |
60
|
|
|
public $table_manager; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* List of loadies. |
64
|
|
|
* |
65
|
|
|
* @var Loadie[] |
66
|
|
|
*/ |
67
|
|
|
private $loadies = array(); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Initialize the plugin. |
71
|
|
|
* |
72
|
|
|
* @param string $file Plugin file. |
73
|
|
|
* @param EmailLogAutoloader $loader EmailLog Autoloader. |
74
|
2 |
|
* @param TableManager $table_manager Table Manager. |
75
|
2 |
|
*/ |
76
|
2 |
|
public function __construct( $file, $loader, $table_manager ) { |
77
|
2 |
|
$this->plugin_file = $file; |
78
|
|
|
$this->loader = $loader; |
79
|
|
|
$this->table_manager = $table_manager; |
80
|
|
|
|
81
|
|
|
$this->add_loadie( $table_manager ); |
82
|
2 |
|
|
83
|
2 |
|
$this->translations_path = dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' ; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
2 |
|
* Add an Email Log Loadie. |
88
|
|
|
* The `load()` method of the Loadies will be called when Email Log is loaded. |
89
|
2 |
|
* |
90
|
2 |
|
* @param \EmailLog\Core\Loadie $loadie Loadie to be loaded. |
91
|
2 |
|
* |
92
|
|
|
* @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise. |
93
|
2 |
|
*/ |
94
|
2 |
|
public function add_loadie( $loadie ) { |
95
|
|
|
if ( $this->loaded ) { |
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ( ! $loadie instanceof Loadie ) { |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->loadies[] = $loadie; |
104
|
|
|
|
105
|
|
|
return true; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Load the plugin. |
110
|
|
|
*/ |
111
|
|
|
public function load() { |
112
|
|
|
if ( $this->loaded ) { |
113
|
|
|
return; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
load_plugin_textdomain( 'email-log', false, $this->translations_path ); |
117
|
|
|
|
118
|
|
|
$this->table_manager->load(); |
119
|
|
|
|
120
|
|
|
foreach ( $this->loadies as $loadie ) { |
121
|
|
|
$loadie->load(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$this->loaded = true; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Email Log plugin loaded. |
128
|
|
|
* |
129
|
|
|
* @since 2.0 |
130
|
|
|
*/ |
131
|
|
|
do_action( 'el_loaded' ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Return Email Log version. |
136
|
|
|
* |
137
|
|
|
* @return string Email Log Version. |
138
|
|
|
*/ |
139
|
|
|
public function get_version() { |
140
|
|
|
return self::VERSION; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Return the Email Log plugin directory path. |
145
|
|
|
* |
146
|
|
|
* @return string Plugin directory path. |
147
|
|
|
*/ |
148
|
|
|
public function get_plugin_path() { |
149
|
|
|
return plugin_dir_path( $this->plugin_file ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Return the Email Log plugin file. |
154
|
|
|
* |
155
|
|
|
* @since 2.0.0 |
156
|
|
|
* |
157
|
|
|
* @return string Plugin directory path. |
158
|
|
|
*/ |
159
|
|
|
public function get_plugin_file() { |
160
|
|
|
return $this->plugin_file; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|