Completed
Pull Request — master (#65)
by Maria Daniel Deepak
22:48 queued 07:49
created

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