Completed
Pull Request — dev/2.1.0 (#102)
by Maria Daniel Deepak
06:54
created

EmailLog   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 220
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 50%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
dl 0
loc 220
ccs 23
cts 46
cp 0.5
rs 10
c 4
b 0
f 0
wmc 16
lcom 2
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A set_licenser() 0 5 2
A get_licenser() 0 3 1
A add_loadie() 0 13 3
B load() 0 29 3
A get_version() 0 3 1
A get_plugin_path() 0 3 1
A get_plugin_file() 0 3 1
A get_store_url() 0 3 1
A remove_email_log_menu_by_user_role() 0 5 2
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
	 * Email Log Plugins Setting.
69
	 *
70
	 * @since 2.1.0
71
	 * @var \EmailLog\Core\UI\Setting\Setting
72
	 */
73
	public $setting;
74
75
	/**
76
	 * Add-on Licenser.
77
	 *
78
	 * @since 2.0
79
	 * @var \EmailLog\Addon\License\Licenser
80
	 */
81
	private $licenser;
82
83
	/**
84
	 * List of loadies.
85
	 *
86
	 * @var Loadie[]
87
	 */
88
	private $loadies = array();
89
90
	/**
91
	 * Initialize the plugin.
92
	 *
93
	 * @param string             $file          Plugin file.
94
	 * @param EmailLogAutoloader $loader        EmailLog Autoloader.
95
	 * @param TableManager       $table_manager Table Manager.
96
	 */
97 1
	public function __construct( $file, $loader, $table_manager ) {
98 1
		$this->plugin_file = $file;
99 1
		$this->loader = $loader;
100 1
		$this->table_manager = $table_manager;
101
102 1
		$this->add_loadie( $table_manager );
103
104 1
		$this->translations_path = dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' ;
105 1
	}
106
107
	/**
108
	 * Set Licenser.
109
	 *
110
	 * @param \EmailLog\Addon\License\Licenser $licenser Add-on Licenser.
111
	 */
112
	public function set_licenser( $licenser ) {
113
		if ( $this->add_loadie( $licenser ) ) {
114
			$this->licenser = $licenser;
115
		}
116
	}
117
118
	/**
119
	 * Get Licenser.
120
	 *
121
	 * @return \EmailLog\Addon\License\Licenser
122
	 */
123
	public function get_licenser() {
124
		return $this->licenser;
125
	}
126
127
	/**
128
	 * Add an Email Log Loadie.
129
	 * The `load()` method of the Loadies will be called when Email Log is loaded.
130
	 *
131
	 * @param \EmailLog\Core\Loadie $loadie Loadie to be loaded.
132
	 *
133
	 * @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise.
134
	 */
135 1
	public function add_loadie( $loadie ) {
136 1
		if ( $this->loaded ) {
137
			return false;
138
		}
139
140 1
		if ( ! $loadie instanceof Loadie ) {
141
			return false;
142
		}
143
144 1
		$this->loadies[] = $loadie;
145
146 1
		return true;
147
	}
148
149
	/**
150
	 * Load the plugin.
151
	 */
152 1
	public function load() {
153 1
		if ( $this->loaded ) {
154
			return;
155
		}
156
157 1
		load_plugin_textdomain( 'email-log', false, $this->translations_path );
158
159 1
		$this->table_manager->load();
160
161 1
		foreach ( $this->loadies as $loadie ) {
162 1
			$loadie->load();
163 1
		}
164
165 1
		$this->loaded = true;
166
167
		/**
168
		 * Email Log plugin loaded.
169
		 *
170
		 * @since 2.0
171
		 */
172 1
		do_action( 'el_loaded' );
173
174
		/**
175
		 * Shows the Email Log only to allowed User roles set in the Plugin's settings page.
176
		 *
177
		 * @since 2.1.0
178
		 */
179 1
		add_action( 'admin_init', array( $this, 'remove_email_log_menu_by_user_role' ) );
180 1
	}
181
182
	/**
183
	 * Return Email Log version.
184
	 *
185
	 * @return string Email Log Version.
186
	 */
187
	public function get_version() {
188
		return self::VERSION;
189
	}
190
191
	/**
192
	 * Return the Email Log plugin directory path.
193
	 *
194
	 * @return string Plugin directory path.
195
	 */
196
	public function get_plugin_path() {
197
		return plugin_dir_path( $this->plugin_file );
198
	}
199
200
	/**
201
	 * Return the Email Log plugin file.
202
	 *
203
	 * @since 2.0.0
204
	 *
205
	 * @return string Plugin directory path.
206
	 */
207
	public function get_plugin_file() {
208
		return $this->plugin_file;
209
	}
210
211
	/**
212
	 * Get Email Log Store URL.
213
	 *
214
	 * @since 2.0.0
215
	 *
216
	 * @return string Store URL
217
	 */
218
	public function get_store_url() {
219
		return self::STORE_URL;
220
	}
221
222
	/**
223
	 * Shows the Email Log only to allowed User roles set in the Plugin's settings page.
224
	 */
225
	public function remove_email_log_menu_by_user_role() {
226
		if ( ! \EmailLog\Util\can_current_user_email_log() ) {
227
			remove_menu_page( 'email-log' );
228
		}
229
	}
230
}
231