Completed
Push — dev/2.1.0 ( 60662d...15fd75 )
by Sudar
01:42
created

EmailLog::get_plugin_file()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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.2';
20
21
	/**
22
	 * Email Log Store URL.
23
	 */
24
	const STORE_URL = 'https://wpemaillog.com';
25
26
	/**
27
	 * Flag to track if the plugin is loaded.
28
	 *
29
	 * @since 2.0
30
	 * @access private
31
	 * @var bool
32
	 */
33
	private $loaded = false;
34
35
	/**
36
	 * Plugin file path.
37
	 *
38
	 * @since 2.0
39
	 * @access private
40
	 * @var string
41
	 */
42
	private $plugin_file;
43
44
	/**
45
	 * Filesystem directory path where translations are stored.
46
	 *
47
	 * @since 2.0
48
	 * @var string
49
	 */
50
	public $translations_path;
51
52
	/**
53
	 * Auto loader.
54
	 *
55
	 * @var \EmailLog\EmailLogAutoloader
56
	 */
57
	public $loader;
58
59
	/**
60
	 * Database Table Manager.
61
	 *
62
	 * @since 2.0
63
	 * @var \EmailLog\Core\DB\TableManager
64
	 */
65
	public $table_manager;
66
67
	/**
68
	 * Add-on Licenser.
69
	 * For non-admin requests it will not be set.
70
	 *
71
	 * @since 2.0
72
	 * @var \EmailLog\Addon\License\Licenser
73
	 */
74
	private $licenser = null;
75
76
	/**
77
	 * List of loadies.
78
	 *
79
	 * @var Loadie[]
80
	 */
81
	private $loadies = array();
82
83
	/**
84
	 * Initialize the plugin.
85
	 *
86
	 * @param string             $file          Plugin file.
87
	 * @param EmailLogAutoloader $loader        EmailLog Autoloader.
88
	 * @param TableManager       $table_manager Table Manager.
89
	 */
90 1
	public function __construct( $file, $loader, $table_manager ) {
91 1
		$this->plugin_file = $file;
92 1
		$this->loader = $loader;
93 1
		$this->table_manager = $table_manager;
94
95 1
		$this->add_loadie( $table_manager );
96
97 1
		$this->translations_path = dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' ;
98 1
	}
99
100
	/**
101
	 * Set Licenser.
102
	 *
103
	 * @param \EmailLog\Addon\License\Licenser $licenser Add-on Licenser.
104
	 */
105
	public function set_licenser( $licenser ) {
106
		if ( $this->add_loadie( $licenser ) ) {
107
			$this->licenser = $licenser;
108
		}
109
	}
110
111
	/**
112
	 * Get Licenser.
113
	 *
114
	 * @return null|\EmailLog\Addon\License\Licenser
115
	 */
116
	public function get_licenser() {
117
		return $this->licenser;
118
	}
119
120
	/**
121
	 * Add an Email Log Loadie.
122
	 * The `load()` method of the Loadies will be called when Email Log is loaded.
123
	 *
124
	 * @param \EmailLog\Core\Loadie $loadie Loadie to be loaded.
125
	 *
126
	 * @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise.
127
	 */
128 1
	public function add_loadie( $loadie ) {
129 1
		if ( $this->loaded ) {
130
			return false;
131
		}
132
133 1
		if ( ! $loadie instanceof Loadie ) {
134
			return false;
135
		}
136
137 1
		$this->loadies[] = $loadie;
138
139 1
		return true;
140
	}
141
142
	/**
143
	 * Load the plugin.
144
	 */
145 1
	public function load() {
146 1
		if ( $this->loaded ) {
147
			return;
148
		}
149
150 1
		load_plugin_textdomain( 'email-log', false, $this->translations_path );
151
152 1
		$this->table_manager->load();
153
154 1
		foreach ( $this->loadies as $loadie ) {
155 1
			$loadie->load();
156 1
		}
157
158 1
		$this->loaded = true;
159
160
		/**
161
		 * Email Log plugin loaded.
162
		 *
163
		 * @since 2.0
164
		 */
165 1
		do_action( 'el_loaded' );
166 1
	}
167
168
	/**
169
	 * Return Email Log version.
170
	 *
171
	 * @return string Email Log Version.
172
	 */
173
	public function get_version() {
174
		return self::VERSION;
175
	}
176
177
	/**
178
	 * Return the Email Log plugin directory path.
179
	 *
180
	 * @return string Plugin directory path.
181
	 */
182
	public function get_plugin_path() {
183
		return plugin_dir_path( $this->plugin_file );
184
	}
185
186
	/**
187
	 * Return the Email Log plugin file.
188
	 *
189
	 * @since 2.0.0
190
	 *
191
	 * @return string Plugin directory path.
192
	 */
193
	public function get_plugin_file() {
194
		return $this->plugin_file;
195
	}
196
197
	/**
198
	 * Get Email Log Store URL.
199
	 *
200
	 * @since 2.0.0
201
	 *
202
	 * @return string Store URL
203
	 */
204
	public function get_store_url() {
205
		return self::STORE_URL;
206
	}
207
}
208