Completed
Branch BUG/11211/html-entities-being-... (7e723d)
by
unknown
41:55 queued 30:51
created
core/domain/DomainBase.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@
 block discarded – undo
121 121
 
122 122
 
123 123
     /**
124
-     * @return Version
124
+     * @return string
125 125
      */
126 126
     public function versionValueObject()
127 127
     {
Please login to merge, or discard this patch.
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -21,112 +21,112 @@
 block discarded – undo
21 21
 abstract class DomainBase implements DomainInterface
22 22
 {
23 23
 
24
-    /**
25
-     * Equivalent to `__FILE__` for main plugin file.
26
-     *
27
-     * @var FilePath
28
-     */
29
-    private $plugin_file;
30
-
31
-    /**
32
-     * String indicating version for plugin
33
-     *
34
-     * @var string
35
-     */
36
-    private $version;
37
-
38
-    /**
39
-     * @var string $plugin_basename
40
-     */
41
-    private $plugin_basename;
42
-
43
-    /**
44
-     * @var string $plugin_path
45
-     */
46
-    private $plugin_path;
47
-
48
-    /**
49
-     * @var string $plugin_url
50
-     */
51
-    private $plugin_url;
52
-
53
-
54
-
55
-    /**
56
-     * Initializes internal properties.
57
-     *
58
-     * @param FilePath $plugin_file
59
-     * @param Version  $version
60
-     * @throws InvalidArgumentException
61
-     * @throws DomainException
62
-     */
63
-    public function __construct(FilePath $plugin_file, Version $version)
64
-    {
65
-        $this->plugin_file = $plugin_file;
66
-        $this->version = $version;
67
-        $this->plugin_basename = plugin_basename($this->pluginFile());
68
-        $this->plugin_path = plugin_dir_path($this->pluginFile());
69
-        $this->plugin_url = plugin_dir_url($this->pluginFile());
70
-    }
71
-
72
-
73
-    /**
74
-     * @return string
75
-     */
76
-    public function pluginFile()
77
-    {
78
-        return (string) $this->plugin_file;
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * @return string
85
-     */
86
-    public function pluginBasename()
87
-    {
88
-        return $this->plugin_basename;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * @return string
95
-     */
96
-    public function pluginPath()
97
-    {
98
-        return $this->plugin_path;
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     * @return string
105
-     */
106
-    public function pluginUrl()
107
-    {
108
-        return $this->plugin_url;
109
-    }
110
-
111
-
112
-
113
-    /**
114
-     * @return string
115
-     */
116
-    public function version()
117
-    {
118
-        return (string) $this->version;
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * @return Version
125
-     */
126
-    public function versionValueObject()
127
-    {
128
-        return $this->version;
129
-    }
24
+	/**
25
+	 * Equivalent to `__FILE__` for main plugin file.
26
+	 *
27
+	 * @var FilePath
28
+	 */
29
+	private $plugin_file;
30
+
31
+	/**
32
+	 * String indicating version for plugin
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private $version;
37
+
38
+	/**
39
+	 * @var string $plugin_basename
40
+	 */
41
+	private $plugin_basename;
42
+
43
+	/**
44
+	 * @var string $plugin_path
45
+	 */
46
+	private $plugin_path;
47
+
48
+	/**
49
+	 * @var string $plugin_url
50
+	 */
51
+	private $plugin_url;
52
+
53
+
54
+
55
+	/**
56
+	 * Initializes internal properties.
57
+	 *
58
+	 * @param FilePath $plugin_file
59
+	 * @param Version  $version
60
+	 * @throws InvalidArgumentException
61
+	 * @throws DomainException
62
+	 */
63
+	public function __construct(FilePath $plugin_file, Version $version)
64
+	{
65
+		$this->plugin_file = $plugin_file;
66
+		$this->version = $version;
67
+		$this->plugin_basename = plugin_basename($this->pluginFile());
68
+		$this->plugin_path = plugin_dir_path($this->pluginFile());
69
+		$this->plugin_url = plugin_dir_url($this->pluginFile());
70
+	}
71
+
72
+
73
+	/**
74
+	 * @return string
75
+	 */
76
+	public function pluginFile()
77
+	{
78
+		return (string) $this->plugin_file;
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * @return string
85
+	 */
86
+	public function pluginBasename()
87
+	{
88
+		return $this->plugin_basename;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function pluginPath()
97
+	{
98
+		return $this->plugin_path;
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 * @return string
105
+	 */
106
+	public function pluginUrl()
107
+	{
108
+		return $this->plugin_url;
109
+	}
110
+
111
+
112
+
113
+	/**
114
+	 * @return string
115
+	 */
116
+	public function version()
117
+	{
118
+		return (string) $this->version;
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * @return Version
125
+	 */
126
+	public function versionValueObject()
127
+	{
128
+		return $this->version;
129
+	}
130 130
 
131 131
 
132 132
 }
Please login to merge, or discard this patch.
core/domain/values/Version.php 2 patches
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -20,297 +20,297 @@
 block discarded – undo
20 20
 class Version
21 21
 {
22 22
 
23
-    const RELEASE_TYPE_RC    = 'rc';
24
-
25
-    const RELEASE_TYPE_BETA  = 'beta';
26
-
27
-    const RELEASE_TYPE_DECAF = 'decaf';
28
-
29
-    const RELEASE_TYPE_PROD  = 'p';
30
-
31
-    /**
32
-     * @var int $major
33
-     */
34
-    private $major;
35
-
36
-    /**
37
-     * @var int $minor
38
-     */
39
-    private $minor;
40
-
41
-    /**
42
-     * @var int $patch
43
-     */
44
-    private $patch;
45
-
46
-    /**
47
-     * @var string $release
48
-     */
49
-    private $release;
50
-
51
-    /**
52
-     * @var int $build
53
-     */
54
-    private $build;
55
-
56
-
57
-    /**
58
-     * Version constructor.
59
-     *
60
-     * @param int    $major
61
-     * @param int    $minor
62
-     * @param int    $patch
63
-     * @param string $release
64
-     * @param int    $build
65
-     * @throws InvalidDataTypeException
66
-     * @throws InvalidArgumentException
67
-     */
68
-    public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0)
69
-    {
70
-        $this->setMajor($major);
71
-        $this->setMinor($minor);
72
-        $this->setPatch($patch);
73
-        $this->setRelease($release);
74
-        $this->setBuild($build);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param string $version_string
80
-     * @return Version
81
-     * @throws InvalidArgumentException
82
-     */
83
-    public static function fromString($version_string)
84
-    {
85
-        // compare incoming version string against the lowest possible valid version
86
-        if (version_compare($version_string, '0.0.1.dev.001', '<')) {
87
-            throw new InvalidArgumentException(
88
-                sprintf(
89
-                    esc_html__('"%1$s" is not a valid version string', 'event_espresso'),
90
-                    $version_string
91
-                )
92
-            );
93
-        }
94
-        // break apart incoming version string
95
-        $version_parts = explode('.', $version_string);
96
-        // verify that version string at least contains {major}.{minor}.{patch}
97
-        if (count($version_parts) < 3) {
98
-            throw new InvalidArgumentException(
99
-                sprintf(
100
-                    esc_html__(
101
-                        'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid',
102
-                        'event_espresso'
103
-                    ),
104
-                    $version_string
105
-                )
106
-            );
107
-        }
108
-        // add defaults for missing pieces
109
-        $version_parts += array(0,0,0,'p',0);
110
-        // reassign to individual variables
111
-        list($major, $minor, $patch, $release, $build) = $version_parts;
112
-        return new Version(
113
-            (int) $major,
114
-            (int) $minor,
115
-            (int) $patch,
116
-            $release,
117
-            (int) $build
118
-        );
119
-    }
120
-
121
-
122
-    /**
123
-     * @return int
124
-     */
125
-    public function major()
126
-    {
127
-        return $this->major;
128
-    }
129
-
130
-
131
-    /**
132
-     * @param int|string $major
133
-     * @throws InvalidDataTypeException
134
-     */
135
-    private function setMajor($major)
136
-    {
137
-        if (! is_int($major)) {
138
-            throw new InvalidDataTypeException(
139
-                '$major',
140
-                $major,
141
-                'integer'
142
-            );
143
-        }
144
-        $this->major = absint($major);
145
-    }
146
-
147
-
148
-    /**
149
-     * @return int
150
-     */
151
-    public function minor()
152
-    {
153
-        return $this->minor;
154
-    }
155
-
156
-
157
-    /**
158
-     * @param int|string $minor
159
-     * @throws InvalidDataTypeException
160
-     */
161
-    private function setMinor($minor)
162
-    {
163
-        if (! is_int($minor)) {
164
-            throw new InvalidDataTypeException(
165
-                '$minor',
166
-                $minor,
167
-                'integer'
168
-            );
169
-        }
170
-        $this->minor = absint($minor);
171
-    }
172
-
173
-
174
-    /**
175
-     * @return int
176
-     */
177
-    public function patch()
178
-    {
179
-        return $this->patch;
180
-    }
181
-
182
-
183
-    /**
184
-     * @param int|string $patch
185
-     * @throws InvalidDataTypeException
186
-     */
187
-    private function setPatch($patch)
188
-    {
189
-        if (! is_int($patch)) {
190
-            throw new InvalidDataTypeException(
191
-                '$patch',
192
-                $patch,
193
-                'integer'
194
-            );
195
-        }
196
-        $this->patch = absint($patch);
197
-    }
198
-
199
-
200
-    /**
201
-     * @return string
202
-     */
203
-    public function release()
204
-    {
205
-        return $this->release;
206
-    }
207
-
208
-
209
-    /**
210
-     * @param string $release
211
-     * @throws InvalidArgumentException
212
-     */
213
-    private function setRelease($release)
214
-    {
215
-        $valid_release_types = array(
216
-            Version::RELEASE_TYPE_RC,
217
-            Version::RELEASE_TYPE_BETA,
218
-            Version::RELEASE_TYPE_DECAF,
219
-            Version::RELEASE_TYPE_PROD,
220
-        );
221
-        if (! in_array($release, $valid_release_types, true)) {
222
-            throw new InvalidArgumentException(
223
-                sprintf(
224
-                    esc_html__(
225
-                        '"%1$s" is not a valid release type. Please use one of the following values: %2$s',
226
-                        'event_espresso'
227
-                    ),
228
-                    $release,
229
-                    implode(', ', $valid_release_types)
230
-                )
231
-            );
232
-        }
233
-        $this->release = $release;
234
-    }
235
-
236
-
237
-    /**
238
-     * @return int
239
-     */
240
-    public function build()
241
-    {
242
-        return $this->build;
243
-    }
244
-
245
-
246
-    /**
247
-     * @param int|string $build
248
-     * @throws InvalidDataTypeException
249
-     */
250
-    private function setBuild($build)
251
-    {
252
-        if (! is_int($build)) {
253
-            throw new InvalidDataTypeException(
254
-                '$build',
255
-                $build,
256
-                'integer'
257
-            );
258
-        }
259
-        $this->build = absint($build);
260
-    }
261
-
262
-
263
-    /**
264
-     * @param Version $other_version
265
-     * @return int
266
-     */
267
-    public function compare(Version $other_version)
268
-    {
269
-        return version_compare((string) $this, (string) $other_version);
270
-    }
271
-
272
-
273
-    /**
274
-     * @param Version $other_version
275
-     * @return bool
276
-     */
277
-    public function equals(Version $other_version)
278
-    {
279
-        return version_compare((string) $this, (string) $other_version, '==');
280
-    }
281
-
282
-
283
-    /**
284
-     * @param Version $other_version
285
-     * @return bool
286
-     */
287
-    public function newerThan(Version $other_version)
288
-    {
289
-        return version_compare((string) $this, (string) $other_version, '>');
290
-    }
291
-
292
-
293
-    /**
294
-     * @param Version $other_version
295
-     * @return bool
296
-     */
297
-    public function olderThan(Version $other_version)
298
-    {
299
-        return version_compare((string) $this, (string) $other_version, '<');
300
-    }
301
-
302
-
303
-    /**
304
-     * @return string
305
-     */
306
-    public function __toString()
307
-    {
308
-        $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}";
309
-        if($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) {
310
-            $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT);
311
-        }
312
-        return $version_string;
313
-    }
23
+	const RELEASE_TYPE_RC    = 'rc';
24
+
25
+	const RELEASE_TYPE_BETA  = 'beta';
26
+
27
+	const RELEASE_TYPE_DECAF = 'decaf';
28
+
29
+	const RELEASE_TYPE_PROD  = 'p';
30
+
31
+	/**
32
+	 * @var int $major
33
+	 */
34
+	private $major;
35
+
36
+	/**
37
+	 * @var int $minor
38
+	 */
39
+	private $minor;
40
+
41
+	/**
42
+	 * @var int $patch
43
+	 */
44
+	private $patch;
45
+
46
+	/**
47
+	 * @var string $release
48
+	 */
49
+	private $release;
50
+
51
+	/**
52
+	 * @var int $build
53
+	 */
54
+	private $build;
55
+
56
+
57
+	/**
58
+	 * Version constructor.
59
+	 *
60
+	 * @param int    $major
61
+	 * @param int    $minor
62
+	 * @param int    $patch
63
+	 * @param string $release
64
+	 * @param int    $build
65
+	 * @throws InvalidDataTypeException
66
+	 * @throws InvalidArgumentException
67
+	 */
68
+	public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0)
69
+	{
70
+		$this->setMajor($major);
71
+		$this->setMinor($minor);
72
+		$this->setPatch($patch);
73
+		$this->setRelease($release);
74
+		$this->setBuild($build);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param string $version_string
80
+	 * @return Version
81
+	 * @throws InvalidArgumentException
82
+	 */
83
+	public static function fromString($version_string)
84
+	{
85
+		// compare incoming version string against the lowest possible valid version
86
+		if (version_compare($version_string, '0.0.1.dev.001', '<')) {
87
+			throw new InvalidArgumentException(
88
+				sprintf(
89
+					esc_html__('"%1$s" is not a valid version string', 'event_espresso'),
90
+					$version_string
91
+				)
92
+			);
93
+		}
94
+		// break apart incoming version string
95
+		$version_parts = explode('.', $version_string);
96
+		// verify that version string at least contains {major}.{minor}.{patch}
97
+		if (count($version_parts) < 3) {
98
+			throw new InvalidArgumentException(
99
+				sprintf(
100
+					esc_html__(
101
+						'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid',
102
+						'event_espresso'
103
+					),
104
+					$version_string
105
+				)
106
+			);
107
+		}
108
+		// add defaults for missing pieces
109
+		$version_parts += array(0,0,0,'p',0);
110
+		// reassign to individual variables
111
+		list($major, $minor, $patch, $release, $build) = $version_parts;
112
+		return new Version(
113
+			(int) $major,
114
+			(int) $minor,
115
+			(int) $patch,
116
+			$release,
117
+			(int) $build
118
+		);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return int
124
+	 */
125
+	public function major()
126
+	{
127
+		return $this->major;
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param int|string $major
133
+	 * @throws InvalidDataTypeException
134
+	 */
135
+	private function setMajor($major)
136
+	{
137
+		if (! is_int($major)) {
138
+			throw new InvalidDataTypeException(
139
+				'$major',
140
+				$major,
141
+				'integer'
142
+			);
143
+		}
144
+		$this->major = absint($major);
145
+	}
146
+
147
+
148
+	/**
149
+	 * @return int
150
+	 */
151
+	public function minor()
152
+	{
153
+		return $this->minor;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param int|string $minor
159
+	 * @throws InvalidDataTypeException
160
+	 */
161
+	private function setMinor($minor)
162
+	{
163
+		if (! is_int($minor)) {
164
+			throw new InvalidDataTypeException(
165
+				'$minor',
166
+				$minor,
167
+				'integer'
168
+			);
169
+		}
170
+		$this->minor = absint($minor);
171
+	}
172
+
173
+
174
+	/**
175
+	 * @return int
176
+	 */
177
+	public function patch()
178
+	{
179
+		return $this->patch;
180
+	}
181
+
182
+
183
+	/**
184
+	 * @param int|string $patch
185
+	 * @throws InvalidDataTypeException
186
+	 */
187
+	private function setPatch($patch)
188
+	{
189
+		if (! is_int($patch)) {
190
+			throw new InvalidDataTypeException(
191
+				'$patch',
192
+				$patch,
193
+				'integer'
194
+			);
195
+		}
196
+		$this->patch = absint($patch);
197
+	}
198
+
199
+
200
+	/**
201
+	 * @return string
202
+	 */
203
+	public function release()
204
+	{
205
+		return $this->release;
206
+	}
207
+
208
+
209
+	/**
210
+	 * @param string $release
211
+	 * @throws InvalidArgumentException
212
+	 */
213
+	private function setRelease($release)
214
+	{
215
+		$valid_release_types = array(
216
+			Version::RELEASE_TYPE_RC,
217
+			Version::RELEASE_TYPE_BETA,
218
+			Version::RELEASE_TYPE_DECAF,
219
+			Version::RELEASE_TYPE_PROD,
220
+		);
221
+		if (! in_array($release, $valid_release_types, true)) {
222
+			throw new InvalidArgumentException(
223
+				sprintf(
224
+					esc_html__(
225
+						'"%1$s" is not a valid release type. Please use one of the following values: %2$s',
226
+						'event_espresso'
227
+					),
228
+					$release,
229
+					implode(', ', $valid_release_types)
230
+				)
231
+			);
232
+		}
233
+		$this->release = $release;
234
+	}
235
+
236
+
237
+	/**
238
+	 * @return int
239
+	 */
240
+	public function build()
241
+	{
242
+		return $this->build;
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param int|string $build
248
+	 * @throws InvalidDataTypeException
249
+	 */
250
+	private function setBuild($build)
251
+	{
252
+		if (! is_int($build)) {
253
+			throw new InvalidDataTypeException(
254
+				'$build',
255
+				$build,
256
+				'integer'
257
+			);
258
+		}
259
+		$this->build = absint($build);
260
+	}
261
+
262
+
263
+	/**
264
+	 * @param Version $other_version
265
+	 * @return int
266
+	 */
267
+	public function compare(Version $other_version)
268
+	{
269
+		return version_compare((string) $this, (string) $other_version);
270
+	}
271
+
272
+
273
+	/**
274
+	 * @param Version $other_version
275
+	 * @return bool
276
+	 */
277
+	public function equals(Version $other_version)
278
+	{
279
+		return version_compare((string) $this, (string) $other_version, '==');
280
+	}
281
+
282
+
283
+	/**
284
+	 * @param Version $other_version
285
+	 * @return bool
286
+	 */
287
+	public function newerThan(Version $other_version)
288
+	{
289
+		return version_compare((string) $this, (string) $other_version, '>');
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param Version $other_version
295
+	 * @return bool
296
+	 */
297
+	public function olderThan(Version $other_version)
298
+	{
299
+		return version_compare((string) $this, (string) $other_version, '<');
300
+	}
301
+
302
+
303
+	/**
304
+	 * @return string
305
+	 */
306
+	public function __toString()
307
+	{
308
+		$version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}";
309
+		if($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) {
310
+			$version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT);
311
+		}
312
+		return $version_string;
313
+	}
314 314
 
315 315
 
316 316
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
             );
107 107
         }
108 108
         // add defaults for missing pieces
109
-        $version_parts += array(0,0,0,'p',0);
109
+        $version_parts += array(0, 0, 0, 'p', 0);
110 110
         // reassign to individual variables
111 111
         list($major, $minor, $patch, $release, $build) = $version_parts;
112 112
         return new Version(
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     private function setMajor($major)
136 136
     {
137
-        if (! is_int($major)) {
137
+        if ( ! is_int($major)) {
138 138
             throw new InvalidDataTypeException(
139 139
                 '$major',
140 140
                 $major,
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
      */
161 161
     private function setMinor($minor)
162 162
     {
163
-        if (! is_int($minor)) {
163
+        if ( ! is_int($minor)) {
164 164
             throw new InvalidDataTypeException(
165 165
                 '$minor',
166 166
                 $minor,
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     private function setPatch($patch)
188 188
     {
189
-        if (! is_int($patch)) {
189
+        if ( ! is_int($patch)) {
190 190
             throw new InvalidDataTypeException(
191 191
                 '$patch',
192 192
                 $patch,
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
             Version::RELEASE_TYPE_DECAF,
219 219
             Version::RELEASE_TYPE_PROD,
220 220
         );
221
-        if (! in_array($release, $valid_release_types, true)) {
221
+        if ( ! in_array($release, $valid_release_types, true)) {
222 222
             throw new InvalidArgumentException(
223 223
                 sprintf(
224 224
                     esc_html__(
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      */
250 250
     private function setBuild($build)
251 251
     {
252
-        if (! is_int($build)) {
252
+        if ( ! is_int($build)) {
253 253
             throw new InvalidDataTypeException(
254 254
                 '$build',
255 255
                 $build,
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
     public function __toString()
307 307
     {
308 308
         $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}";
309
-        if($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) {
310
-            $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT);
309
+        if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) {
310
+            $version_string .= '.'.str_pad($this->build, 3, '0', STR_PAD_LEFT);
311 311
         }
312 312
         return $version_string;
313 313
     }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Payment_Method.lib.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -22,174 +22,174 @@
 block discarded – undo
22 22
 class EE_Register_Payment_Method implements EEI_Plugin_API
23 23
 {
24 24
 
25
-    /**
26
-     * Holds values for registered payment methods
27
-     *
28
-     * @var array
29
-     */
30
-    protected static $_settings = array();
31
-
32
-
33
-
34
-    /**
35
-     * Method for registering new EE_PMT_Base children
36
-     *
37
-     * @since    4.5.0
38
-     * @param string  $payment_method_id    a unique identifier for this set of modules Required.
39
-     * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
40
-     * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
41
-     *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
42
-     *                                      the files EE_PMT_Payomatic.pm.php)
43
-     *                                      }
44
-     * @throws EE_Error
45
-     * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
46
-     *                                      children, or to the EED_Module files themselves
47
-     * @return void
48
-     * @throws InvalidDataTypeException
49
-     * @throws DomainException
50
-     * @throws InvalidArgumentException
51
-     * @throws InvalidInterfaceException
52
-     * @throws InvalidDataTypeException
53
-     */
54
-    public static function register($payment_method_id = null, $setup_args = array())
55
-    {
56
-        //required fields MUST be present, so let's make sure they are.
57
-        if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
58
-            throw new EE_Error(
59
-                esc_html__(
60
-                    'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
61
-                    'event_espresso'
62
-                )
63
-            );
64
-        }
65
-        //make sure we don't register twice
66
-        if (isset(self::$_settings[$payment_method_id])) {
67
-            return;
68
-        }
69
-        //make sure this was called in the right place!
70
-        if (
71
-            ! did_action('AHEE__EE_System__load_espresso_addons')
72
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
73
-        ) {
74
-            EE_Error::doing_it_wrong(
75
-                __METHOD__,
76
-                esc_html__(
77
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
78
-                    'event_espresso'
79
-                ),
80
-                '4.3.0'
81
-            );
82
-        }
83
-        //setup $_settings array from incoming values.
84
-        self::$_settings[$payment_method_id] = array(
85
-            // array of full server paths to any EE_PMT_Base children used
86
-            'payment_method_paths' => isset($setup_args['payment_method_paths'])
87
-                ? (array)$setup_args['payment_method_paths']
88
-                : array(),
89
-        );
90
-        // add to list of modules to be registered
91
-        add_filter(
92
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
93
-            array('EE_Register_Payment_Method', 'add_payment_methods')
94
-        );
95
-        // If EE_Payment_Method_Manager::register_payment_methods has already been called,
96
-        // then we need to add our caps for this payment method manually
97
-        if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
98
-            $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
99
-            // register payment methods directly
100
-            foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) {
101
-                $payment_method_manager->register_payment_method($payment_method_path);
102
-            }
103
-            $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
104
-            $capabilities->addCaps(
105
-                self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id])
106
-            );
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Filters the list of payment methods to add ours.
114
-     * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
115
-     *
116
-     * @param array $payment_method_folders array of paths to all payment methods that require registering
117
-     * @return array
118
-     */
119
-    public static function add_payment_methods($payment_method_folders)
120
-    {
121
-        foreach (self::$_settings as $settings) {
122
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
123
-                $payment_method_folders[] = $payment_method_path;
124
-            }
125
-        }
126
-        return $payment_method_folders;
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * This deregisters a module that was previously registered with a specific $module_id.
133
-     *
134
-     * @since    4.3.0
135
-     *
136
-     * @param string $module_id the name for the module that was previously registered
137
-     * @return void
138
-     * @throws DomainException
139
-     * @throws EE_Error
140
-     * @throws InvalidArgumentException
141
-     * @throws InvalidInterfaceException
142
-     * @throws InvalidDataTypeException
143
-     */
144
-    public static function deregister($module_id = null)
145
-    {
146
-        if (isset(self::$_settings[$module_id])) {
147
-
148
-            //set action for just this module id to delay deregistration until core is loaded and ready.
149
-            $module_settings = self::$_settings[$module_id];
150
-            unset(self::$_settings[$module_id]);
151
-            add_action(
152
-                'AHEE__EE_System__core_loaded_and_ready',
153
-                function () use ($module_settings) {
154
-                    $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
155
-                    $capabilities->removeCaps(
156
-                        EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
157
-                    );
158
-                }
159
-            );
160
-        }
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * returns an array of the caps that get added when a Payment Method is registered
167
-     *
168
-     * @param array $settings
169
-     * @return array
170
-     * @throws DomainException
171
-     * @throws EE_Error
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidInterfaceException
174
-     * @throws InvalidDataTypeException
175
-     * @access private  Developers do NOT use this method.  It's only public for PHP5.3 closure support (see deregister)
176
-     *                  When we drop support for PHP5.3 this will be made private again.  You have been warned.
177
-     *
178
-     */
179
-    public static function getPaymentMethodCapabilities(array $settings)
180
-    {
181
-        $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
182
-        $payment_method_caps = array('administrator' => array());
183
-        if (isset($settings['payment_method_paths'])) {
184
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
185
-                $payment_method_caps = $payment_method_manager->addPaymentMethodCap(
186
-                    strtolower(basename($payment_method_path)),
187
-                    $payment_method_caps
188
-                );
189
-            }
190
-        }
191
-        return $payment_method_caps;
192
-    }
25
+	/**
26
+	 * Holds values for registered payment methods
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected static $_settings = array();
31
+
32
+
33
+
34
+	/**
35
+	 * Method for registering new EE_PMT_Base children
36
+	 *
37
+	 * @since    4.5.0
38
+	 * @param string  $payment_method_id    a unique identifier for this set of modules Required.
39
+	 * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
40
+	 * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
41
+	 *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
42
+	 *                                      the files EE_PMT_Payomatic.pm.php)
43
+	 *                                      }
44
+	 * @throws EE_Error
45
+	 * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
46
+	 *                                      children, or to the EED_Module files themselves
47
+	 * @return void
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws DomainException
50
+	 * @throws InvalidArgumentException
51
+	 * @throws InvalidInterfaceException
52
+	 * @throws InvalidDataTypeException
53
+	 */
54
+	public static function register($payment_method_id = null, $setup_args = array())
55
+	{
56
+		//required fields MUST be present, so let's make sure they are.
57
+		if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
58
+			throw new EE_Error(
59
+				esc_html__(
60
+					'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
61
+					'event_espresso'
62
+				)
63
+			);
64
+		}
65
+		//make sure we don't register twice
66
+		if (isset(self::$_settings[$payment_method_id])) {
67
+			return;
68
+		}
69
+		//make sure this was called in the right place!
70
+		if (
71
+			! did_action('AHEE__EE_System__load_espresso_addons')
72
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
73
+		) {
74
+			EE_Error::doing_it_wrong(
75
+				__METHOD__,
76
+				esc_html__(
77
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
78
+					'event_espresso'
79
+				),
80
+				'4.3.0'
81
+			);
82
+		}
83
+		//setup $_settings array from incoming values.
84
+		self::$_settings[$payment_method_id] = array(
85
+			// array of full server paths to any EE_PMT_Base children used
86
+			'payment_method_paths' => isset($setup_args['payment_method_paths'])
87
+				? (array)$setup_args['payment_method_paths']
88
+				: array(),
89
+		);
90
+		// add to list of modules to be registered
91
+		add_filter(
92
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
93
+			array('EE_Register_Payment_Method', 'add_payment_methods')
94
+		);
95
+		// If EE_Payment_Method_Manager::register_payment_methods has already been called,
96
+		// then we need to add our caps for this payment method manually
97
+		if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
98
+			$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
99
+			// register payment methods directly
100
+			foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) {
101
+				$payment_method_manager->register_payment_method($payment_method_path);
102
+			}
103
+			$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
104
+			$capabilities->addCaps(
105
+				self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id])
106
+			);
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Filters the list of payment methods to add ours.
114
+	 * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
115
+	 *
116
+	 * @param array $payment_method_folders array of paths to all payment methods that require registering
117
+	 * @return array
118
+	 */
119
+	public static function add_payment_methods($payment_method_folders)
120
+	{
121
+		foreach (self::$_settings as $settings) {
122
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
123
+				$payment_method_folders[] = $payment_method_path;
124
+			}
125
+		}
126
+		return $payment_method_folders;
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * This deregisters a module that was previously registered with a specific $module_id.
133
+	 *
134
+	 * @since    4.3.0
135
+	 *
136
+	 * @param string $module_id the name for the module that was previously registered
137
+	 * @return void
138
+	 * @throws DomainException
139
+	 * @throws EE_Error
140
+	 * @throws InvalidArgumentException
141
+	 * @throws InvalidInterfaceException
142
+	 * @throws InvalidDataTypeException
143
+	 */
144
+	public static function deregister($module_id = null)
145
+	{
146
+		if (isset(self::$_settings[$module_id])) {
147
+
148
+			//set action for just this module id to delay deregistration until core is loaded and ready.
149
+			$module_settings = self::$_settings[$module_id];
150
+			unset(self::$_settings[$module_id]);
151
+			add_action(
152
+				'AHEE__EE_System__core_loaded_and_ready',
153
+				function () use ($module_settings) {
154
+					$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
155
+					$capabilities->removeCaps(
156
+						EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
157
+					);
158
+				}
159
+			);
160
+		}
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * returns an array of the caps that get added when a Payment Method is registered
167
+	 *
168
+	 * @param array $settings
169
+	 * @return array
170
+	 * @throws DomainException
171
+	 * @throws EE_Error
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidInterfaceException
174
+	 * @throws InvalidDataTypeException
175
+	 * @access private  Developers do NOT use this method.  It's only public for PHP5.3 closure support (see deregister)
176
+	 *                  When we drop support for PHP5.3 this will be made private again.  You have been warned.
177
+	 *
178
+	 */
179
+	public static function getPaymentMethodCapabilities(array $settings)
180
+	{
181
+		$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
182
+		$payment_method_caps = array('administrator' => array());
183
+		if (isset($settings['payment_method_paths'])) {
184
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
185
+				$payment_method_caps = $payment_method_manager->addPaymentMethodCap(
186
+					strtolower(basename($payment_method_path)),
187
+					$payment_method_caps
188
+				);
189
+			}
190
+		}
191
+		return $payment_method_caps;
192
+	}
193 193
 
194 194
 }
195 195
 // End of file EE_Register_Payment_Method.lib.php
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         self::$_settings[$payment_method_id] = array(
85 85
             // array of full server paths to any EE_PMT_Base children used
86 86
             'payment_method_paths' => isset($setup_args['payment_method_paths'])
87
-                ? (array)$setup_args['payment_method_paths']
87
+                ? (array) $setup_args['payment_method_paths']
88 88
                 : array(),
89 89
         );
90 90
         // add to list of modules to be registered
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             unset(self::$_settings[$module_id]);
151 151
             add_action(
152 152
                 'AHEE__EE_System__core_loaded_and_ready',
153
-                function () use ($module_settings) {
153
+                function() use ($module_settings) {
154 154
                     $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
155 155
                     $capabilities->removeCaps(
156 156
                         EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
Please login to merge, or discard this patch.
core/EE_Addon.core.php 2 patches
Indentation   +814 added lines, -814 removed lines patch added patch discarded remove patch
@@ -18,786 +18,786 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * prefix to be added onto an addon's plugin slug to make a wp option name
23
-     * which will be used to store the plugin's activation history
24
-     */
25
-    const ee_addon_version_history_option_prefix = 'ee_version_history_';
26
-
27
-    /**
28
-     * @var $_version
29
-     * @type string
30
-     */
31
-    protected $_version = '';
32
-
33
-    /**
34
-     * @var $_min_core_version
35
-     * @type string
36
-     */
37
-    protected $_min_core_version = '';
38
-
39
-    /**
40
-     * derived from plugin 'main_file_path using plugin_basename()
41
-     *
42
-     * @type string $_plugin_basename
43
-     */
44
-    protected $_plugin_basename = '';
45
-
46
-    /**
47
-     * A non-internationalized name to identify this addon for use in URLs, etc
48
-     *
49
-     * @type string $_plugin_slug
50
-     */
51
-    protected $_plugin_slug = '';
52
-
53
-    /**
54
-     * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
55
-     *
56
-     * @type string _addon_name
57
-     */
58
-    protected $_addon_name = '';
59
-
60
-    /**
61
-     * one of the EE_System::req_type_* constants
62
-     *
63
-     * @type int $_req_type
64
-     */
65
-    protected $_req_type;
66
-
67
-    /**
68
-     * page slug to be used when generating the "Settings" link on the WP plugin page
69
-     *
70
-     * @type string $_plugin_action_slug
71
-     */
72
-    protected $_plugin_action_slug = '';
73
-
74
-    /**
75
-     * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
76
-     * that can be used for adding upgrading/marketing info
77
-     *
78
-     * @type array $_plugins_page_row
79
-     */
80
-    protected $_plugins_page_row = array();
81
-
82
-
83
-
84
-    /**
85
-     *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
-     *
87
-     * @type string
88
-     */
89
-    protected $_main_plugin_file;
90
-
91
-
92
-    /**
93
-     * @var EE_Dependency_Map $dependency_map
94
-     */
95
-    private $dependency_map;
96
-
97
-
98
-    /**
99
-     * @var DomainInterface $domain
100
-     */
101
-    private $domain;
102
-
103
-
104
-    /**
105
-     * @param EE_Dependency_Map $dependency_map [optional]
106
-     * @param DomainInterface   $domain         [optional]
107
-     */
108
-    public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
109
-    {
110
-        if($dependency_map instanceof EE_Dependency_Map) {
111
-            $this->setDependencyMap($dependency_map);
112
-        }
113
-        if ($domain instanceof DomainInterface) {
114
-            $this->setDomain($domain);
115
-        }
116
-        add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
117
-    }
118
-
119
-
120
-    /**
121
-     * @param EE_Dependency_Map $dependency_map
122
-     */
123
-    public function setDependencyMap($dependency_map)
124
-    {
125
-        $this->dependency_map = $dependency_map;
126
-    }
127
-
128
-
129
-    /**
130
-     * @return EE_Dependency_Map
131
-     */
132
-    public function dependencyMap()
133
-    {
134
-        return $this->dependency_map;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param DomainInterface $domain
140
-     */
141
-    public function setDomain(DomainInterface $domain)
142
-    {
143
-        $this->domain = $domain;
144
-    }
145
-
146
-    /**
147
-     * @return DomainInterface
148
-     */
149
-    public function domain()
150
-    {
151
-        return $this->domain;
152
-    }
153
-
154
-
155
-    /**
156
-     * @param mixed $version
157
-     */
158
-    public function set_version($version = null)
159
-    {
160
-        $this->_version = $version;
161
-    }
162
-
163
-
164
-    /**
165
-     * get__version
166
-     *
167
-     * @return string
168
-     */
169
-    public function version()
170
-    {
171
-        return $this->_version;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param mixed $min_core_version
177
-     */
178
-    public function set_min_core_version($min_core_version = null)
179
-    {
180
-        $this->_min_core_version = $min_core_version;
181
-    }
182
-
183
-
184
-    /**
185
-     * get__min_core_version
186
-     *
187
-     * @return string
188
-     */
189
-    public function min_core_version()
190
-    {
191
-        return $this->_min_core_version;
192
-    }
193
-
194
-
195
-    /**
196
-     * Sets addon_name
197
-     *
198
-     * @param string $addon_name
199
-     * @return boolean
200
-     */
201
-    public function set_name($addon_name)
202
-    {
203
-        return $this->_addon_name = $addon_name;
204
-    }
205
-
206
-
207
-    /**
208
-     * Gets addon_name
209
-     *
210
-     * @return string
211
-     */
212
-    public function name()
213
-    {
214
-        return $this->_addon_name;
215
-    }
216
-
217
-
218
-    /**
219
-     * @return string
220
-     */
221
-    public function plugin_basename()
222
-    {
223
-
224
-        return $this->_plugin_basename;
225
-    }
226
-
227
-
228
-    /**
229
-     * @param string $plugin_basename
230
-     */
231
-    public function set_plugin_basename($plugin_basename)
232
-    {
233
-
234
-        $this->_plugin_basename = $plugin_basename;
235
-    }
236
-
237
-
238
-    /**
239
-     * @return string
240
-     */
241
-    public function plugin_slug()
242
-    {
243
-
244
-        return $this->_plugin_slug;
245
-    }
246
-
247
-
248
-    /**
249
-     * @param string $plugin_slug
250
-     */
251
-    public function set_plugin_slug($plugin_slug)
252
-    {
253
-
254
-        $this->_plugin_slug = $plugin_slug;
255
-    }
256
-
257
-
258
-    /**
259
-     * @return string
260
-     */
261
-    public function plugin_action_slug()
262
-    {
263
-
264
-        return $this->_plugin_action_slug;
265
-    }
266
-
267
-
268
-    /**
269
-     * @param string $plugin_action_slug
270
-     */
271
-    public function set_plugin_action_slug($plugin_action_slug)
272
-    {
273
-
274
-        $this->_plugin_action_slug = $plugin_action_slug;
275
-    }
276
-
277
-
278
-    /**
279
-     * @return array
280
-     */
281
-    public function get_plugins_page_row()
282
-    {
283
-
284
-        return $this->_plugins_page_row;
285
-    }
286
-
287
-
288
-    /**
289
-     * @param array $plugins_page_row
290
-     */
291
-    public function set_plugins_page_row($plugins_page_row = array())
292
-    {
293
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
294
-        if (! is_array($plugins_page_row)
295
-            && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
296
-        ) {
297
-            $plugins_page_row = array();
298
-        }
299
-        $this->_plugins_page_row = (array) $plugins_page_row;
300
-    }
301
-
302
-
303
-    /**
304
-     * Called when EE core detects this addon has been activated for the first time.
305
-     * If the site isn't in maintenance mode, should setup the addon's database
306
-     *
307
-     * @return void
308
-     */
309
-    public function new_install()
310
-    {
311
-        $classname = get_class($this);
312
-        do_action("AHEE__{$classname}__new_install");
313
-        do_action('AHEE__EE_Addon__new_install', $this);
314
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
315
-        add_action(
316
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
317
-            array($this, 'initialize_db_if_no_migrations_required')
318
-        );
319
-    }
320
-
321
-
322
-    /**
323
-     * Called when EE core detects this addon has been reactivated. When this happens,
324
-     * it's good to just check that your data is still intact
325
-     *
326
-     * @return void
327
-     */
328
-    public function reactivation()
329
-    {
330
-        $classname = get_class($this);
331
-        do_action("AHEE__{$classname}__reactivation");
332
-        do_action('AHEE__EE_Addon__reactivation', $this);
333
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
334
-        add_action(
335
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
336
-            array($this, 'initialize_db_if_no_migrations_required')
337
-        );
338
-    }
339
-
340
-
341
-    /**
342
-     * Called when the registered deactivation hook for this addon fires.
343
-     * @throws EE_Error
344
-     */
345
-    public function deactivation()
346
-    {
347
-        $classname = get_class($this);
348
-        do_action("AHEE__{$classname}__deactivation");
349
-        do_action('AHEE__EE_Addon__deactivation', $this);
350
-        //check if the site no longer needs to be in maintenance mode
351
-        EE_Register_Addon::deregister($this->name());
352
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
353
-    }
354
-
355
-
356
-    /**
357
-     * Takes care of double-checking that we're not in maintenance mode, and then
358
-     * initializing this addon's necessary initial data. This is called by default on new activations
359
-     * and reactivations.
360
-     *
361
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
362
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
363
-     * @return void
364
-     * @throws \EE_Error
365
-     */
366
-    public function initialize_db_if_no_migrations_required($verify_schema = true)
367
-    {
368
-        if ($verify_schema === '') {
369
-            //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
370
-            //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
371
-            //calls them with an argument of an empty string (ie ""), which evaluates to false
372
-            //so we need to treat the empty string as if nothing had been passed, and should instead use the default
373
-            $verify_schema = true;
374
-        }
375
-        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
376
-            if ($verify_schema) {
377
-                $this->initialize_db();
378
-            }
379
-            $this->initialize_default_data();
380
-            //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
381
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to(
382
-                array(
383
-                    'slug'    => $this->name(),
384
-                    'version' => $this->version(),
385
-                )
386
-            );
387
-            /* make sure core's data is a-ok
21
+	/**
22
+	 * prefix to be added onto an addon's plugin slug to make a wp option name
23
+	 * which will be used to store the plugin's activation history
24
+	 */
25
+	const ee_addon_version_history_option_prefix = 'ee_version_history_';
26
+
27
+	/**
28
+	 * @var $_version
29
+	 * @type string
30
+	 */
31
+	protected $_version = '';
32
+
33
+	/**
34
+	 * @var $_min_core_version
35
+	 * @type string
36
+	 */
37
+	protected $_min_core_version = '';
38
+
39
+	/**
40
+	 * derived from plugin 'main_file_path using plugin_basename()
41
+	 *
42
+	 * @type string $_plugin_basename
43
+	 */
44
+	protected $_plugin_basename = '';
45
+
46
+	/**
47
+	 * A non-internationalized name to identify this addon for use in URLs, etc
48
+	 *
49
+	 * @type string $_plugin_slug
50
+	 */
51
+	protected $_plugin_slug = '';
52
+
53
+	/**
54
+	 * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
55
+	 *
56
+	 * @type string _addon_name
57
+	 */
58
+	protected $_addon_name = '';
59
+
60
+	/**
61
+	 * one of the EE_System::req_type_* constants
62
+	 *
63
+	 * @type int $_req_type
64
+	 */
65
+	protected $_req_type;
66
+
67
+	/**
68
+	 * page slug to be used when generating the "Settings" link on the WP plugin page
69
+	 *
70
+	 * @type string $_plugin_action_slug
71
+	 */
72
+	protected $_plugin_action_slug = '';
73
+
74
+	/**
75
+	 * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
76
+	 * that can be used for adding upgrading/marketing info
77
+	 *
78
+	 * @type array $_plugins_page_row
79
+	 */
80
+	protected $_plugins_page_row = array();
81
+
82
+
83
+
84
+	/**
85
+	 *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
86
+	 *
87
+	 * @type string
88
+	 */
89
+	protected $_main_plugin_file;
90
+
91
+
92
+	/**
93
+	 * @var EE_Dependency_Map $dependency_map
94
+	 */
95
+	private $dependency_map;
96
+
97
+
98
+	/**
99
+	 * @var DomainInterface $domain
100
+	 */
101
+	private $domain;
102
+
103
+
104
+	/**
105
+	 * @param EE_Dependency_Map $dependency_map [optional]
106
+	 * @param DomainInterface   $domain         [optional]
107
+	 */
108
+	public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
109
+	{
110
+		if($dependency_map instanceof EE_Dependency_Map) {
111
+			$this->setDependencyMap($dependency_map);
112
+		}
113
+		if ($domain instanceof DomainInterface) {
114
+			$this->setDomain($domain);
115
+		}
116
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
117
+	}
118
+
119
+
120
+	/**
121
+	 * @param EE_Dependency_Map $dependency_map
122
+	 */
123
+	public function setDependencyMap($dependency_map)
124
+	{
125
+		$this->dependency_map = $dependency_map;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return EE_Dependency_Map
131
+	 */
132
+	public function dependencyMap()
133
+	{
134
+		return $this->dependency_map;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param DomainInterface $domain
140
+	 */
141
+	public function setDomain(DomainInterface $domain)
142
+	{
143
+		$this->domain = $domain;
144
+	}
145
+
146
+	/**
147
+	 * @return DomainInterface
148
+	 */
149
+	public function domain()
150
+	{
151
+		return $this->domain;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param mixed $version
157
+	 */
158
+	public function set_version($version = null)
159
+	{
160
+		$this->_version = $version;
161
+	}
162
+
163
+
164
+	/**
165
+	 * get__version
166
+	 *
167
+	 * @return string
168
+	 */
169
+	public function version()
170
+	{
171
+		return $this->_version;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param mixed $min_core_version
177
+	 */
178
+	public function set_min_core_version($min_core_version = null)
179
+	{
180
+		$this->_min_core_version = $min_core_version;
181
+	}
182
+
183
+
184
+	/**
185
+	 * get__min_core_version
186
+	 *
187
+	 * @return string
188
+	 */
189
+	public function min_core_version()
190
+	{
191
+		return $this->_min_core_version;
192
+	}
193
+
194
+
195
+	/**
196
+	 * Sets addon_name
197
+	 *
198
+	 * @param string $addon_name
199
+	 * @return boolean
200
+	 */
201
+	public function set_name($addon_name)
202
+	{
203
+		return $this->_addon_name = $addon_name;
204
+	}
205
+
206
+
207
+	/**
208
+	 * Gets addon_name
209
+	 *
210
+	 * @return string
211
+	 */
212
+	public function name()
213
+	{
214
+		return $this->_addon_name;
215
+	}
216
+
217
+
218
+	/**
219
+	 * @return string
220
+	 */
221
+	public function plugin_basename()
222
+	{
223
+
224
+		return $this->_plugin_basename;
225
+	}
226
+
227
+
228
+	/**
229
+	 * @param string $plugin_basename
230
+	 */
231
+	public function set_plugin_basename($plugin_basename)
232
+	{
233
+
234
+		$this->_plugin_basename = $plugin_basename;
235
+	}
236
+
237
+
238
+	/**
239
+	 * @return string
240
+	 */
241
+	public function plugin_slug()
242
+	{
243
+
244
+		return $this->_plugin_slug;
245
+	}
246
+
247
+
248
+	/**
249
+	 * @param string $plugin_slug
250
+	 */
251
+	public function set_plugin_slug($plugin_slug)
252
+	{
253
+
254
+		$this->_plugin_slug = $plugin_slug;
255
+	}
256
+
257
+
258
+	/**
259
+	 * @return string
260
+	 */
261
+	public function plugin_action_slug()
262
+	{
263
+
264
+		return $this->_plugin_action_slug;
265
+	}
266
+
267
+
268
+	/**
269
+	 * @param string $plugin_action_slug
270
+	 */
271
+	public function set_plugin_action_slug($plugin_action_slug)
272
+	{
273
+
274
+		$this->_plugin_action_slug = $plugin_action_slug;
275
+	}
276
+
277
+
278
+	/**
279
+	 * @return array
280
+	 */
281
+	public function get_plugins_page_row()
282
+	{
283
+
284
+		return $this->_plugins_page_row;
285
+	}
286
+
287
+
288
+	/**
289
+	 * @param array $plugins_page_row
290
+	 */
291
+	public function set_plugins_page_row($plugins_page_row = array())
292
+	{
293
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
294
+		if (! is_array($plugins_page_row)
295
+			&& strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
296
+		) {
297
+			$plugins_page_row = array();
298
+		}
299
+		$this->_plugins_page_row = (array) $plugins_page_row;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Called when EE core detects this addon has been activated for the first time.
305
+	 * If the site isn't in maintenance mode, should setup the addon's database
306
+	 *
307
+	 * @return void
308
+	 */
309
+	public function new_install()
310
+	{
311
+		$classname = get_class($this);
312
+		do_action("AHEE__{$classname}__new_install");
313
+		do_action('AHEE__EE_Addon__new_install', $this);
314
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
315
+		add_action(
316
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
317
+			array($this, 'initialize_db_if_no_migrations_required')
318
+		);
319
+	}
320
+
321
+
322
+	/**
323
+	 * Called when EE core detects this addon has been reactivated. When this happens,
324
+	 * it's good to just check that your data is still intact
325
+	 *
326
+	 * @return void
327
+	 */
328
+	public function reactivation()
329
+	{
330
+		$classname = get_class($this);
331
+		do_action("AHEE__{$classname}__reactivation");
332
+		do_action('AHEE__EE_Addon__reactivation', $this);
333
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
334
+		add_action(
335
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
336
+			array($this, 'initialize_db_if_no_migrations_required')
337
+		);
338
+	}
339
+
340
+
341
+	/**
342
+	 * Called when the registered deactivation hook for this addon fires.
343
+	 * @throws EE_Error
344
+	 */
345
+	public function deactivation()
346
+	{
347
+		$classname = get_class($this);
348
+		do_action("AHEE__{$classname}__deactivation");
349
+		do_action('AHEE__EE_Addon__deactivation', $this);
350
+		//check if the site no longer needs to be in maintenance mode
351
+		EE_Register_Addon::deregister($this->name());
352
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
353
+	}
354
+
355
+
356
+	/**
357
+	 * Takes care of double-checking that we're not in maintenance mode, and then
358
+	 * initializing this addon's necessary initial data. This is called by default on new activations
359
+	 * and reactivations.
360
+	 *
361
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
362
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
363
+	 * @return void
364
+	 * @throws \EE_Error
365
+	 */
366
+	public function initialize_db_if_no_migrations_required($verify_schema = true)
367
+	{
368
+		if ($verify_schema === '') {
369
+			//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
370
+			//(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
371
+			//calls them with an argument of an empty string (ie ""), which evaluates to false
372
+			//so we need to treat the empty string as if nothing had been passed, and should instead use the default
373
+			$verify_schema = true;
374
+		}
375
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
376
+			if ($verify_schema) {
377
+				$this->initialize_db();
378
+			}
379
+			$this->initialize_default_data();
380
+			//@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
381
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
382
+				array(
383
+					'slug'    => $this->name(),
384
+					'version' => $this->version(),
385
+				)
386
+			);
387
+			/* make sure core's data is a-ok
388 388
              * (at the time of writing, we especially want to verify all the caps are present
389 389
              * because payment method type capabilities are added dynamically, and it's
390 390
              * possible this addon added a payment method. But it's also possible
391 391
              * other data needs to be verified)
392 392
              */
393
-            EEH_Activation::initialize_db_content();
394
-            update_option('ee_flush_rewrite_rules', true);
395
-            //in case there are lots of addons being activated at once, let's force garbage collection
396
-            //to help avoid memory limit errors
397
-            //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
398
-            gc_collect_cycles();
399
-        } else {
400
-            //ask the data migration manager to init this addon's data
401
-            //when migrations are finished because we can't do it now
402
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
403
-        }
404
-    }
405
-
406
-
407
-    /**
408
-     * Used to setup this addon's database tables, but not necessarily any default
409
-     * data in them. The default is to actually use the most up-to-date data migration script
410
-     * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
411
-     * methods to setup the db.
412
-     */
413
-    public function initialize_db()
414
-    {
415
-        //find the migration script that sets the database to be compatible with the code
416
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
417
-        if ($current_dms_name) {
418
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
419
-            $current_data_migration_script->set_migrating(false);
420
-            $current_data_migration_script->schema_changes_before_migration();
421
-            $current_data_migration_script->schema_changes_after_migration();
422
-            if ($current_data_migration_script->get_errors()) {
423
-                foreach ($current_data_migration_script->get_errors() as $error) {
424
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
425
-                }
426
-            }
427
-        }
428
-        //if not DMS was found that should be ok. This addon just doesn't require any database changes
429
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
430
-            array(
431
-                'slug'    => $this->name(),
432
-                'version' => $this->version(),
433
-            )
434
-        );
435
-    }
436
-
437
-
438
-    /**
439
-     * If you want to setup default data for the addon, override this method, and call
440
-     * parent::initialize_default_data() from within it. This is normally called
441
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
442
-     * and should verify default data is present (but this is also called
443
-     * on reactivations and just after migrations, so please verify you actually want
444
-     * to ADD default data, because it may already be present).
445
-     * However, please call this parent (currently it just fires a hook which other
446
-     * addons may be depending on)
447
-     */
448
-    public function initialize_default_data()
449
-    {
450
-        /**
451
-         * Called when an addon is ensuring its default data is set (possibly called
452
-         * on a reactivation, so first check for the absence of other data before setting
453
-         * default data)
454
-         *
455
-         * @param EE_Addon $addon the addon that called this
456
-         */
457
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
458
-        //override to insert default data. It is safe to use the models here
459
-        //because the site should not be in maintenance mode
460
-    }
461
-
462
-
463
-    /**
464
-     * EE Core detected that this addon has been upgraded. We should check if there
465
-     * are any new migration scripts, and if so put the site into maintenance mode until
466
-     * they're ran
467
-     *
468
-     * @return void
469
-     */
470
-    public function upgrade()
471
-    {
472
-        $classname = get_class($this);
473
-        do_action("AHEE__{$classname}__upgrade");
474
-        do_action('AHEE__EE_Addon__upgrade', $this);
475
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
476
-        //also it's possible there is new default data that needs to be added
477
-        add_action(
478
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
479
-            array($this, 'initialize_db_if_no_migrations_required')
480
-        );
481
-    }
482
-
483
-
484
-    /**
485
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
486
-     */
487
-    public function downgrade()
488
-    {
489
-        $classname = get_class($this);
490
-        do_action("AHEE__{$classname}__downgrade");
491
-        do_action('AHEE__EE_Addon__downgrade', $this);
492
-        //it's possible there's old default data that needs to be double-checked
493
-        add_action(
494
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
495
-            array($this, 'initialize_db_if_no_migrations_required')
496
-        );
497
-    }
498
-
499
-
500
-    /**
501
-     * set_db_update_option_name
502
-     * Until we do something better, we'll just check for migration scripts upon
503
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
504
-     *
505
-     * @return bool
506
-     */
507
-    public function set_db_update_option_name()
508
-    {
509
-        EE_Error::doing_it_wrong(
510
-            __FUNCTION__,
511
-            esc_html__(
512
-                'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
513
-                'event_espresso'
514
-            ),
515
-            '4.3.0.alpha.016'
516
-        );
517
-        //let's just handle this on the next request, ok? right now we're just not really ready
518
-        return $this->set_activation_indicator_option();
519
-    }
520
-
521
-
522
-    /**
523
-     * Returns the name of the activation indicator option
524
-     * (an option which is set temporarily to indicate that this addon was just activated)
525
-     *
526
-     * @deprecated since version 4.3.0.alpha.016
527
-     * @return string
528
-     */
529
-    public function get_db_update_option_name()
530
-    {
531
-        EE_Error::doing_it_wrong(
532
-            __FUNCTION__,
533
-            esc_html__(
534
-                'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
535
-                'event_espresso'
536
-            ),
537
-            '4.3.0.alpha.016'
538
-        );
539
-        return $this->get_activation_indicator_option_name();
540
-    }
541
-
542
-
543
-    /**
544
-     * When the addon is activated, this should be called to set a wordpress option that
545
-     * indicates it was activated. This is especially useful for detecting reactivations.
546
-     *
547
-     * @return bool
548
-     */
549
-    public function set_activation_indicator_option()
550
-    {
551
-        // let's just handle this on the next request, ok? right now we're just not really ready
552
-        return update_option($this->get_activation_indicator_option_name(), true);
553
-    }
554
-
555
-
556
-    /**
557
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
558
-     *
559
-     * @return string
560
-     */
561
-    public function get_activation_indicator_option_name()
562
-    {
563
-        return 'ee_activation_' . $this->name();
564
-    }
565
-
566
-
567
-    /**
568
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
569
-     *
570
-     * @param int $req_type
571
-     */
572
-    public function set_req_type($req_type)
573
-    {
574
-        $this->_req_type = $req_type;
575
-    }
576
-
577
-
578
-    /**
579
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
580
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
581
-     * EE_System when it is checking for new install or upgrades of addons
582
-     */
583
-    public function detect_req_type()
584
-    {
585
-        if (! $this->_req_type) {
586
-            $this->detect_activation_or_upgrade();
587
-        }
588
-        return $this->_req_type;
589
-    }
590
-
591
-
592
-    /**
593
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
594
-     * Should only be called once per request
595
-     *
596
-     * @return void
597
-     */
598
-    public function detect_activation_or_upgrade()
599
-    {
600
-        $activation_history_for_addon = $this->get_activation_history();
393
+			EEH_Activation::initialize_db_content();
394
+			update_option('ee_flush_rewrite_rules', true);
395
+			//in case there are lots of addons being activated at once, let's force garbage collection
396
+			//to help avoid memory limit errors
397
+			//EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
398
+			gc_collect_cycles();
399
+		} else {
400
+			//ask the data migration manager to init this addon's data
401
+			//when migrations are finished because we can't do it now
402
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
403
+		}
404
+	}
405
+
406
+
407
+	/**
408
+	 * Used to setup this addon's database tables, but not necessarily any default
409
+	 * data in them. The default is to actually use the most up-to-date data migration script
410
+	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
411
+	 * methods to setup the db.
412
+	 */
413
+	public function initialize_db()
414
+	{
415
+		//find the migration script that sets the database to be compatible with the code
416
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
417
+		if ($current_dms_name) {
418
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
419
+			$current_data_migration_script->set_migrating(false);
420
+			$current_data_migration_script->schema_changes_before_migration();
421
+			$current_data_migration_script->schema_changes_after_migration();
422
+			if ($current_data_migration_script->get_errors()) {
423
+				foreach ($current_data_migration_script->get_errors() as $error) {
424
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
425
+				}
426
+			}
427
+		}
428
+		//if not DMS was found that should be ok. This addon just doesn't require any database changes
429
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
430
+			array(
431
+				'slug'    => $this->name(),
432
+				'version' => $this->version(),
433
+			)
434
+		);
435
+	}
436
+
437
+
438
+	/**
439
+	 * If you want to setup default data for the addon, override this method, and call
440
+	 * parent::initialize_default_data() from within it. This is normally called
441
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
442
+	 * and should verify default data is present (but this is also called
443
+	 * on reactivations and just after migrations, so please verify you actually want
444
+	 * to ADD default data, because it may already be present).
445
+	 * However, please call this parent (currently it just fires a hook which other
446
+	 * addons may be depending on)
447
+	 */
448
+	public function initialize_default_data()
449
+	{
450
+		/**
451
+		 * Called when an addon is ensuring its default data is set (possibly called
452
+		 * on a reactivation, so first check for the absence of other data before setting
453
+		 * default data)
454
+		 *
455
+		 * @param EE_Addon $addon the addon that called this
456
+		 */
457
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
458
+		//override to insert default data. It is safe to use the models here
459
+		//because the site should not be in maintenance mode
460
+	}
461
+
462
+
463
+	/**
464
+	 * EE Core detected that this addon has been upgraded. We should check if there
465
+	 * are any new migration scripts, and if so put the site into maintenance mode until
466
+	 * they're ran
467
+	 *
468
+	 * @return void
469
+	 */
470
+	public function upgrade()
471
+	{
472
+		$classname = get_class($this);
473
+		do_action("AHEE__{$classname}__upgrade");
474
+		do_action('AHEE__EE_Addon__upgrade', $this);
475
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
476
+		//also it's possible there is new default data that needs to be added
477
+		add_action(
478
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
479
+			array($this, 'initialize_db_if_no_migrations_required')
480
+		);
481
+	}
482
+
483
+
484
+	/**
485
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
486
+	 */
487
+	public function downgrade()
488
+	{
489
+		$classname = get_class($this);
490
+		do_action("AHEE__{$classname}__downgrade");
491
+		do_action('AHEE__EE_Addon__downgrade', $this);
492
+		//it's possible there's old default data that needs to be double-checked
493
+		add_action(
494
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
495
+			array($this, 'initialize_db_if_no_migrations_required')
496
+		);
497
+	}
498
+
499
+
500
+	/**
501
+	 * set_db_update_option_name
502
+	 * Until we do something better, we'll just check for migration scripts upon
503
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
504
+	 *
505
+	 * @return bool
506
+	 */
507
+	public function set_db_update_option_name()
508
+	{
509
+		EE_Error::doing_it_wrong(
510
+			__FUNCTION__,
511
+			esc_html__(
512
+				'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
513
+				'event_espresso'
514
+			),
515
+			'4.3.0.alpha.016'
516
+		);
517
+		//let's just handle this on the next request, ok? right now we're just not really ready
518
+		return $this->set_activation_indicator_option();
519
+	}
520
+
521
+
522
+	/**
523
+	 * Returns the name of the activation indicator option
524
+	 * (an option which is set temporarily to indicate that this addon was just activated)
525
+	 *
526
+	 * @deprecated since version 4.3.0.alpha.016
527
+	 * @return string
528
+	 */
529
+	public function get_db_update_option_name()
530
+	{
531
+		EE_Error::doing_it_wrong(
532
+			__FUNCTION__,
533
+			esc_html__(
534
+				'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
535
+				'event_espresso'
536
+			),
537
+			'4.3.0.alpha.016'
538
+		);
539
+		return $this->get_activation_indicator_option_name();
540
+	}
541
+
542
+
543
+	/**
544
+	 * When the addon is activated, this should be called to set a wordpress option that
545
+	 * indicates it was activated. This is especially useful for detecting reactivations.
546
+	 *
547
+	 * @return bool
548
+	 */
549
+	public function set_activation_indicator_option()
550
+	{
551
+		// let's just handle this on the next request, ok? right now we're just not really ready
552
+		return update_option($this->get_activation_indicator_option_name(), true);
553
+	}
554
+
555
+
556
+	/**
557
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
558
+	 *
559
+	 * @return string
560
+	 */
561
+	public function get_activation_indicator_option_name()
562
+	{
563
+		return 'ee_activation_' . $this->name();
564
+	}
565
+
566
+
567
+	/**
568
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
569
+	 *
570
+	 * @param int $req_type
571
+	 */
572
+	public function set_req_type($req_type)
573
+	{
574
+		$this->_req_type = $req_type;
575
+	}
576
+
577
+
578
+	/**
579
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
580
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
581
+	 * EE_System when it is checking for new install or upgrades of addons
582
+	 */
583
+	public function detect_req_type()
584
+	{
585
+		if (! $this->_req_type) {
586
+			$this->detect_activation_or_upgrade();
587
+		}
588
+		return $this->_req_type;
589
+	}
590
+
591
+
592
+	/**
593
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
594
+	 * Should only be called once per request
595
+	 *
596
+	 * @return void
597
+	 */
598
+	public function detect_activation_or_upgrade()
599
+	{
600
+		$activation_history_for_addon = $this->get_activation_history();
601 601
 //		d($activation_history_for_addon);
602
-        $request_type = EE_System::detect_req_type_given_activation_history(
603
-            $activation_history_for_addon,
604
-            $this->get_activation_indicator_option_name(),
605
-            $this->version()
606
-        );
607
-        $this->set_req_type($request_type);
608
-        $classname = get_class($this);
609
-        switch ($request_type) {
610
-            case EE_System::req_type_new_activation:
611
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
612
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
613
-                $this->new_install();
614
-                $this->update_list_of_installed_versions($activation_history_for_addon);
615
-                break;
616
-            case EE_System::req_type_reactivation:
617
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
618
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
619
-                $this->reactivation();
620
-                $this->update_list_of_installed_versions($activation_history_for_addon);
621
-                break;
622
-            case EE_System::req_type_upgrade:
623
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
624
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
625
-                $this->upgrade();
626
-                $this->update_list_of_installed_versions($activation_history_for_addon);
627
-                break;
628
-            case EE_System::req_type_downgrade:
629
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
630
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
631
-                $this->downgrade();
632
-                $this->update_list_of_installed_versions($activation_history_for_addon);
633
-                break;
634
-            case EE_System::req_type_normal:
635
-            default:
602
+		$request_type = EE_System::detect_req_type_given_activation_history(
603
+			$activation_history_for_addon,
604
+			$this->get_activation_indicator_option_name(),
605
+			$this->version()
606
+		);
607
+		$this->set_req_type($request_type);
608
+		$classname = get_class($this);
609
+		switch ($request_type) {
610
+			case EE_System::req_type_new_activation:
611
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
612
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
613
+				$this->new_install();
614
+				$this->update_list_of_installed_versions($activation_history_for_addon);
615
+				break;
616
+			case EE_System::req_type_reactivation:
617
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
618
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
619
+				$this->reactivation();
620
+				$this->update_list_of_installed_versions($activation_history_for_addon);
621
+				break;
622
+			case EE_System::req_type_upgrade:
623
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
624
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
625
+				$this->upgrade();
626
+				$this->update_list_of_installed_versions($activation_history_for_addon);
627
+				break;
628
+			case EE_System::req_type_downgrade:
629
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
630
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
631
+				$this->downgrade();
632
+				$this->update_list_of_installed_versions($activation_history_for_addon);
633
+				break;
634
+			case EE_System::req_type_normal:
635
+			default:
636 636
 //				$this->_maybe_redirect_to_ee_about();
637
-                break;
638
-        }
639
-
640
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
641
-    }
642
-
643
-    /**
644
-     * Updates the version history for this addon
645
-     *
646
-     * @param array  $version_history
647
-     * @param string $current_version_to_add
648
-     * @return boolean success
649
-     */
650
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
651
-    {
652
-        if (! $version_history) {
653
-            $version_history = $this->get_activation_history();
654
-        }
655
-        if ($current_version_to_add === null) {
656
-            $current_version_to_add = $this->version();
657
-        }
658
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
659
-        // resave
637
+				break;
638
+		}
639
+
640
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
641
+	}
642
+
643
+	/**
644
+	 * Updates the version history for this addon
645
+	 *
646
+	 * @param array  $version_history
647
+	 * @param string $current_version_to_add
648
+	 * @return boolean success
649
+	 */
650
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
651
+	{
652
+		if (! $version_history) {
653
+			$version_history = $this->get_activation_history();
654
+		}
655
+		if ($current_version_to_add === null) {
656
+			$current_version_to_add = $this->version();
657
+		}
658
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
659
+		// resave
660 660
 //		echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history);
661
-        return update_option($this->get_activation_history_option_name(), $version_history);
662
-    }
663
-
664
-    /**
665
-     * Gets the name of the wp option that stores the activation history
666
-     * of this addon
667
-     *
668
-     * @return string
669
-     */
670
-    public function get_activation_history_option_name()
671
-    {
672
-        return self::ee_addon_version_history_option_prefix . $this->name();
673
-    }
674
-
675
-
676
-    /**
677
-     * Gets the wp option which stores the activation history for this addon
678
-     *
679
-     * @return array
680
-     */
681
-    public function get_activation_history()
682
-    {
683
-        return get_option($this->get_activation_history_option_name(), null);
684
-    }
685
-
686
-
687
-    /**
688
-     * @param string $config_section
689
-     */
690
-    public function set_config_section($config_section = '')
691
-    {
692
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
693
-    }
694
-
695
-    /**
696
-     * Sets the filepath to the main plugin file
697
-     *
698
-     * @param string $filepath
699
-     */
700
-    public function set_main_plugin_file($filepath)
701
-    {
702
-        $this->_main_plugin_file = $filepath;
703
-    }
704
-
705
-    /**
706
-     * gets the filepath to teh main file
707
-     *
708
-     * @return string
709
-     */
710
-    public function get_main_plugin_file()
711
-    {
712
-        return $this->_main_plugin_file;
713
-    }
714
-
715
-    /**
716
-     * Gets the filename (no path) of the main file (the main file loaded
717
-     * by WP)
718
-     *
719
-     * @return string
720
-     */
721
-    public function get_main_plugin_file_basename()
722
-    {
723
-        return plugin_basename($this->get_main_plugin_file());
724
-    }
725
-
726
-    /**
727
-     * Gets the folder name which contains the main plugin file
728
-     *
729
-     * @return string
730
-     */
731
-    public function get_main_plugin_file_dirname()
732
-    {
733
-        return dirname($this->get_main_plugin_file());
734
-    }
735
-
736
-
737
-    /**
738
-     * sets hooks used in the admin
739
-     *
740
-     * @return void
741
-     */
742
-    public function admin_init()
743
-    {
744
-        // is admin and not in M-Mode ?
745
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
746
-            add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
747
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
748
-        }
749
-    }
750
-
751
-
752
-    /**
753
-     * plugin_actions
754
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
755
-     *
756
-     * @param $links
757
-     * @param $file
758
-     * @return array
759
-     */
760
-    public function plugin_action_links($links, $file)
761
-    {
762
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
763
-            // before other links
764
-            array_unshift(
765
-                $links,
766
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
767
-                . esc_html__('Settings', 'event_espresso')
768
-                . '</a>'
769
-            );
770
-        }
771
-        return $links;
772
-    }
773
-
774
-
775
-    /**
776
-     * after_plugin_row
777
-     * Add additional content to the plugins page plugin row
778
-     * Inserts another row
779
-     *
780
-     * @param $plugin_file
781
-     * @param $plugin_data
782
-     * @param $status
783
-     * @return void
784
-     */
785
-    public function after_plugin_row($plugin_file, $plugin_data, $status)
786
-    {
787
-        $after_plugin_row = '';
788
-        $plugins_page_row = $this->get_plugins_page_row();
789
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
790
-            $class            = $status ? 'active' : 'inactive';
791
-            $link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
792
-            $link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
793
-            $description      = isset($plugins_page_row['description'])
794
-                ? $plugins_page_row['description']
795
-                : '';
796
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
797
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
798
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
799
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
800
-                $after_plugin_row .= '<style>
661
+		return update_option($this->get_activation_history_option_name(), $version_history);
662
+	}
663
+
664
+	/**
665
+	 * Gets the name of the wp option that stores the activation history
666
+	 * of this addon
667
+	 *
668
+	 * @return string
669
+	 */
670
+	public function get_activation_history_option_name()
671
+	{
672
+		return self::ee_addon_version_history_option_prefix . $this->name();
673
+	}
674
+
675
+
676
+	/**
677
+	 * Gets the wp option which stores the activation history for this addon
678
+	 *
679
+	 * @return array
680
+	 */
681
+	public function get_activation_history()
682
+	{
683
+		return get_option($this->get_activation_history_option_name(), null);
684
+	}
685
+
686
+
687
+	/**
688
+	 * @param string $config_section
689
+	 */
690
+	public function set_config_section($config_section = '')
691
+	{
692
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
693
+	}
694
+
695
+	/**
696
+	 * Sets the filepath to the main plugin file
697
+	 *
698
+	 * @param string $filepath
699
+	 */
700
+	public function set_main_plugin_file($filepath)
701
+	{
702
+		$this->_main_plugin_file = $filepath;
703
+	}
704
+
705
+	/**
706
+	 * gets the filepath to teh main file
707
+	 *
708
+	 * @return string
709
+	 */
710
+	public function get_main_plugin_file()
711
+	{
712
+		return $this->_main_plugin_file;
713
+	}
714
+
715
+	/**
716
+	 * Gets the filename (no path) of the main file (the main file loaded
717
+	 * by WP)
718
+	 *
719
+	 * @return string
720
+	 */
721
+	public function get_main_plugin_file_basename()
722
+	{
723
+		return plugin_basename($this->get_main_plugin_file());
724
+	}
725
+
726
+	/**
727
+	 * Gets the folder name which contains the main plugin file
728
+	 *
729
+	 * @return string
730
+	 */
731
+	public function get_main_plugin_file_dirname()
732
+	{
733
+		return dirname($this->get_main_plugin_file());
734
+	}
735
+
736
+
737
+	/**
738
+	 * sets hooks used in the admin
739
+	 *
740
+	 * @return void
741
+	 */
742
+	public function admin_init()
743
+	{
744
+		// is admin and not in M-Mode ?
745
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
746
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
747
+			add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
748
+		}
749
+	}
750
+
751
+
752
+	/**
753
+	 * plugin_actions
754
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
755
+	 *
756
+	 * @param $links
757
+	 * @param $file
758
+	 * @return array
759
+	 */
760
+	public function plugin_action_links($links, $file)
761
+	{
762
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
763
+			// before other links
764
+			array_unshift(
765
+				$links,
766
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
767
+				. esc_html__('Settings', 'event_espresso')
768
+				. '</a>'
769
+			);
770
+		}
771
+		return $links;
772
+	}
773
+
774
+
775
+	/**
776
+	 * after_plugin_row
777
+	 * Add additional content to the plugins page plugin row
778
+	 * Inserts another row
779
+	 *
780
+	 * @param $plugin_file
781
+	 * @param $plugin_data
782
+	 * @param $status
783
+	 * @return void
784
+	 */
785
+	public function after_plugin_row($plugin_file, $plugin_data, $status)
786
+	{
787
+		$after_plugin_row = '';
788
+		$plugins_page_row = $this->get_plugins_page_row();
789
+		if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
790
+			$class            = $status ? 'active' : 'inactive';
791
+			$link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
792
+			$link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
793
+			$description      = isset($plugins_page_row['description'])
794
+				? $plugins_page_row['description']
795
+				: '';
796
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
797
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
798
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
799
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
800
+				$after_plugin_row .= '<style>
801 801
 .ee-button,
802 802
 .ee-button:active,
803 803
 .ee-button:visited {
@@ -834,49 +834,49 @@  discard block
 block discarded – undo
834 834
 }
835 835
 .ee-button:active { top:0; }
836 836
 </style>';
837
-                $after_plugin_row .= '
837
+				$after_plugin_row .= '
838 838
 <p class="ee-addon-upsell-info-dv">
839 839
 	<a class="ee-button" href="' . $link_url . '">'
840
-                . $link_text
841
-                . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
842
-                . '</a>
840
+				. $link_text
841
+				. ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
842
+				. '</a>
843 843
 </p>';
844
-                $after_plugin_row .= '</td>';
845
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
846
-                $after_plugin_row .= $description;
847
-                $after_plugin_row .= '</td>';
848
-                $after_plugin_row .= '</tr>';
849
-            } else {
850
-                $after_plugin_row .= $description;
851
-            }
852
-        }
853
-
854
-        echo $after_plugin_row;
855
-    }
856
-
857
-
858
-    /**
859
-     * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
860
-     * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
861
-     * for back compat reasons.
862
-     *
863
-     * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
864
-     *
865
-     * It is recommended, if client code is `de-registering` an add-on, then do it on the
866
-     * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
867
-     * callback does not get run/set in that request.
868
-     *
869
-     * Also, keep in mind that if a registered add-on happens to be deactivated via
870
-     * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
871
-     * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
872
-     * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
873
-     * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
874
-     * to call `parent::deactivation`.
875
-     *
876
-     * @since 4.9.26
877
-     */
878
-    public function after_registration()
879
-    {
880
-        // cricket chirp... cricket chirp...
881
-    }
844
+				$after_plugin_row .= '</td>';
845
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
846
+				$after_plugin_row .= $description;
847
+				$after_plugin_row .= '</td>';
848
+				$after_plugin_row .= '</tr>';
849
+			} else {
850
+				$after_plugin_row .= $description;
851
+			}
852
+		}
853
+
854
+		echo $after_plugin_row;
855
+	}
856
+
857
+
858
+	/**
859
+	 * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
860
+	 * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
861
+	 * for back compat reasons.
862
+	 *
863
+	 * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
864
+	 *
865
+	 * It is recommended, if client code is `de-registering` an add-on, then do it on the
866
+	 * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
867
+	 * callback does not get run/set in that request.
868
+	 *
869
+	 * Also, keep in mind that if a registered add-on happens to be deactivated via
870
+	 * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
871
+	 * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
872
+	 * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
873
+	 * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
874
+	 * to call `parent::deactivation`.
875
+	 *
876
+	 * @since 4.9.26
877
+	 */
878
+	public function after_registration()
879
+	{
880
+		// cricket chirp... cricket chirp...
881
+	}
882 882
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
109 109
     {
110
-        if($dependency_map instanceof EE_Dependency_Map) {
110
+        if ($dependency_map instanceof EE_Dependency_Map) {
111 111
             $this->setDependencyMap($dependency_map);
112 112
         }
113 113
         if ($domain instanceof DomainInterface) {
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
     public function set_plugins_page_row($plugins_page_row = array())
292 292
     {
293 293
         // sigh.... check for example content that I stupidly merged to master and remove it if found
294
-        if (! is_array($plugins_page_row)
294
+        if ( ! is_array($plugins_page_row)
295 295
             && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
296 296
         ) {
297 297
             $plugins_page_row = array();
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
      */
561 561
     public function get_activation_indicator_option_name()
562 562
     {
563
-        return 'ee_activation_' . $this->name();
563
+        return 'ee_activation_'.$this->name();
564 564
     }
565 565
 
566 566
 
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
      */
583 583
     public function detect_req_type()
584 584
     {
585
-        if (! $this->_req_type) {
585
+        if ( ! $this->_req_type) {
586 586
             $this->detect_activation_or_upgrade();
587 587
         }
588 588
         return $this->_req_type;
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
      */
650 650
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
651 651
     {
652
-        if (! $version_history) {
652
+        if ( ! $version_history) {
653 653
             $version_history = $this->get_activation_history();
654 654
         }
655 655
         if ($current_version_to_add === null) {
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
      */
670 670
     public function get_activation_history_option_name()
671 671
     {
672
-        return self::ee_addon_version_history_option_prefix . $this->name();
672
+        return self::ee_addon_version_history_option_prefix.$this->name();
673 673
     }
674 674
 
675 675
 
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
         // is admin and not in M-Mode ?
745 745
         if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
746 746
             add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
747
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
747
+            add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
748 748
         }
749 749
     }
750 750
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
             // before other links
764 764
             array_unshift(
765 765
                 $links,
766
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
766
+                '<a href="admin.php?page='.$this->plugin_action_slug().'">'
767 767
                 . esc_html__('Settings', 'event_espresso')
768 768
                 . '</a>'
769 769
             );
@@ -786,15 +786,15 @@  discard block
 block discarded – undo
786 786
     {
787 787
         $after_plugin_row = '';
788 788
         $plugins_page_row = $this->get_plugins_page_row();
789
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
789
+        if ( ! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
790 790
             $class            = $status ? 'active' : 'inactive';
791 791
             $link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
792 792
             $link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
793 793
             $description      = isset($plugins_page_row['description'])
794 794
                 ? $plugins_page_row['description']
795 795
                 : '';
796
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
797
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
796
+            if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) {
797
+                $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">';
798 798
                 $after_plugin_row .= '<th class="check-column" scope="row"></th>';
799 799
                 $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
800 800
                 $after_plugin_row .= '<style>
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
 </style>';
837 837
                 $after_plugin_row .= '
838 838
 <p class="ee-addon-upsell-info-dv">
839
-	<a class="ee-button" href="' . $link_url . '">'
839
+	<a class="ee-button" href="' . $link_url.'">'
840 840
                 . $link_text
841 841
                 . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
842 842
                 . '</a>
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1076 added lines, -1076 removed lines patch added patch discarded remove patch
@@ -24,1137 +24,1137 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * possibly truncated version of the EE core version string
29
-     *
30
-     * @var string
31
-     */
32
-    protected static $_core_version = '';
27
+	/**
28
+	 * possibly truncated version of the EE core version string
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected static $_core_version = '';
33 33
 
34
-    /**
35
-     * Holds values for registered addons
36
-     *
37
-     * @var array
38
-     */
39
-    protected static $_settings = array();
34
+	/**
35
+	 * Holds values for registered addons
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected static $_settings = array();
40 40
 
41
-    /**
42
-     * @var  array $_incompatible_addons keys are addon SLUGS
43
-     * (first argument passed to EE_Register_Addon::register()), keys are
44
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
-     * Generally this should be used sparingly, as we don't want to muddle up
46
-     * EE core with knowledge of ALL the addons out there.
47
-     * If you want NO versions of an addon to run with a certain version of core,
48
-     * it's usually best to define the addon's "min_core_version" as part of its call
49
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
50
-     * minimum plugin version.
51
-     * @access    protected
52
-     */
53
-    protected static $_incompatible_addons = array(
54
-        'Multi_Event_Registration' => '2.0.11.rc.002',
55
-        'Promotions'               => '1.0.0.rc.084',
56
-    );
41
+	/**
42
+	 * @var  array $_incompatible_addons keys are addon SLUGS
43
+	 * (first argument passed to EE_Register_Addon::register()), keys are
44
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
+	 * Generally this should be used sparingly, as we don't want to muddle up
46
+	 * EE core with knowledge of ALL the addons out there.
47
+	 * If you want NO versions of an addon to run with a certain version of core,
48
+	 * it's usually best to define the addon's "min_core_version" as part of its call
49
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
50
+	 * minimum plugin version.
51
+	 * @access    protected
52
+	 */
53
+	protected static $_incompatible_addons = array(
54
+		'Multi_Event_Registration' => '2.0.11.rc.002',
55
+		'Promotions'               => '1.0.0.rc.084',
56
+	);
57 57
 
58 58
 
59
-    /**
60
-     * We should always be comparing core to a version like '4.3.0.rc.000',
61
-     * not just '4.3.0'.
62
-     * So if the addon developer doesn't provide that full version string,
63
-     * fill in the blanks for them
64
-     *
65
-     * @param string $min_core_version
66
-     * @return string always like '4.3.0.rc.000'
67
-     */
68
-    protected static function _effective_version($min_core_version)
69
-    {
70
-        // versions: 4 . 3 . 1 . p . 123
71
-        // offsets:    0 . 1 . 2 . 3 . 4
72
-        $version_parts = explode('.', $min_core_version);
73
-        //check they specified the micro version (after 2nd period)
74
-        if (! isset($version_parts[2])) {
75
-            $version_parts[2] = '0';
76
-        }
77
-        //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
78
-        //soon we can assume that's 'rc', but this current version is 'alpha'
79
-        if (! isset($version_parts[3])) {
80
-            $version_parts[3] = 'dev';
81
-        }
82
-        if (! isset($version_parts[4])) {
83
-            $version_parts[4] = '000';
84
-        }
85
-        return implode('.', $version_parts);
86
-    }
59
+	/**
60
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
61
+	 * not just '4.3.0'.
62
+	 * So if the addon developer doesn't provide that full version string,
63
+	 * fill in the blanks for them
64
+	 *
65
+	 * @param string $min_core_version
66
+	 * @return string always like '4.3.0.rc.000'
67
+	 */
68
+	protected static function _effective_version($min_core_version)
69
+	{
70
+		// versions: 4 . 3 . 1 . p . 123
71
+		// offsets:    0 . 1 . 2 . 3 . 4
72
+		$version_parts = explode('.', $min_core_version);
73
+		//check they specified the micro version (after 2nd period)
74
+		if (! isset($version_parts[2])) {
75
+			$version_parts[2] = '0';
76
+		}
77
+		//if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
78
+		//soon we can assume that's 'rc', but this current version is 'alpha'
79
+		if (! isset($version_parts[3])) {
80
+			$version_parts[3] = 'dev';
81
+		}
82
+		if (! isset($version_parts[4])) {
83
+			$version_parts[4] = '000';
84
+		}
85
+		return implode('.', $version_parts);
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * Returns whether or not the min core version requirement of the addon is met
91
-     *
92
-     * @param string $min_core_version    the minimum core version required by the addon
93
-     * @param string $actual_core_version the actual core version, optional
94
-     * @return boolean
95
-     */
96
-    public static function _meets_min_core_version_requirement(
97
-        $min_core_version,
98
-        $actual_core_version = EVENT_ESPRESSO_VERSION
99
-    ) {
100
-        return version_compare(
101
-            self::_effective_version($actual_core_version),
102
-            self::_effective_version($min_core_version),
103
-            '>='
104
-        );
105
-    }
89
+	/**
90
+	 * Returns whether or not the min core version requirement of the addon is met
91
+	 *
92
+	 * @param string $min_core_version    the minimum core version required by the addon
93
+	 * @param string $actual_core_version the actual core version, optional
94
+	 * @return boolean
95
+	 */
96
+	public static function _meets_min_core_version_requirement(
97
+		$min_core_version,
98
+		$actual_core_version = EVENT_ESPRESSO_VERSION
99
+	) {
100
+		return version_compare(
101
+			self::_effective_version($actual_core_version),
102
+			self::_effective_version($min_core_version),
103
+			'>='
104
+		);
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * Method for registering new EE_Addons.
110
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
111
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
112
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
113
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
114
-     * 'activate_plugin', it registers the addon still, but its components are not registered
115
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
116
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
117
-     * (so that we can detect that the addon has activated on the subsequent request)
118
-     *
119
-     * @since    4.3.0
120
-     * @param string                  $addon_name                       the EE_Addon's name. Required.
121
-     * @param  array                  $setup_args                       {
122
-     *                                                                  An array of arguments provided for registering the
123
-     *                                                                  message type.
124
-     * @type  string                  $class_name                       the addon's main file name.
125
-     *                                                                  If left blank, generated from the addon name,
126
-     *                                                                  changes something like "calendar" to "EE_Calendar"
127
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
128
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
129
-     * @type string                   $version                          the "software" version for the addon. eg
130
-     *                                                                  "1.0.0.p" for a first stable release, or
131
-     *                                                                  "1.0.0.rc.043" for a version in progress
132
-     * @type string                   $main_file_path                   the full server path to the main file
133
-     *                                                                  loaded directly by WP
134
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
135
-     *                                                                  for the addon's Domain class
136
-     *                                                                  (see EventEspresso\core\domain\Domain)
137
-     * @type string                   $admin_path                       full server path to the folder where the
138
-     *                                                                  addon\'s admin files reside
139
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
140
-     *                                                                  first invoked, can be used for hooking into
141
-     *                                                                  any admin page
142
-     * @type string                   $config_section                   the section name for this addon's
143
-     *                                                                  configuration settings section
144
-     *                                                                  (defaults to "addons")
145
-     * @type string                   $config_class                     the class name for this addon's
146
-     *                                                                  configuration settings object
147
-     * @type string                   $config_name                      the class name for this addon's
148
-     *                                                                  configuration settings object
149
-     * @type string                   $autoloader_paths                 an array of class names and the full server
150
-     *                                                                  paths to those files. Required.
151
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
152
-     *                                                                  folders containing classes that might be
153
-     *                                                                  invoked by the addon
154
-     * @type string                   $dms_paths                        an array of full server paths to folders that
155
-     *                                                                  contain data migration scripts. Required.
156
-     * @type string                   $module_paths                     an array of full server paths to any
157
-     *                                                                  EED_Modules used by the addon
158
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
159
-     *                                                                  that contain EES_Shortcodes
160
-     * @type string                   $widget_paths                     an array of full server paths to folders
161
-     *                                                                  that contain WP_Widgets
162
-     * @type string                   $pue_options
163
-     * @type array                    $capabilities                     an array indexed by role name
164
-     *                                                                  (i.e administrator,author ) and the values
165
-     *                                                                  are an array of caps to add to the role.
166
-     *                                                                  'administrator' => array(
167
-     *                                                                  'read_addon',
168
-     *                                                                  'edit_addon',
169
-     *                                                                  etc.
170
-     *                                                                  ).
171
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
172
-     *                                                                  for any addons that need to register any
173
-     *                                                                  special meta mapped capabilities.  Should
174
-     *                                                                  be indexed where the key is the
175
-     *                                                                  EE_Meta_Capability_Map class name and the
176
-     *                                                                  values are the arguments sent to the class.
177
-     * @type array                    $model_paths                      array of folders containing DB models
178
-     * @see      EE_Register_Model
179
-     * @type array                    $class_paths                      array of folders containing DB classes
180
-     * @see      EE_Register_Model
181
-     * @type array                    $model_extension_paths            array of folders containing DB model
182
-     *                                                                  extensions
183
-     * @see      EE_Register_Model_Extension
184
-     * @type array                    $class_extension_paths            array of folders containing DB class
185
-     *                                                                  extensions
186
-     * @see      EE_Register_Model_Extension
187
-     * @type array message_types {
188
-     *                                                                  An array of message types with the key as
189
-     *                                                                  the message type name and the values as
190
-     *                                                                  below:
191
-     * @type string                   $mtfilename                       The filename of the message type being
192
-     *                                                                  registered. This will be the main
193
-     *                                                                  EE_{Message Type Name}_message_type class.
194
-     *                                                                  (eg. EE_Declined_Registration_message_type.class.php)
195
-     *                                                                  Required.
196
-     * @type array                    $autoloadpaths                    An array of paths to add to the messages
197
-     *                                                                  autoloader for the new message type.
198
-     *                                                                  Required.
199
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
200
-     *                                                                  type should activate with. Each value in
201
-     *                                                                  the
202
-     *                                                                  array
203
-     *                                                                  should match the name property of a
204
-     *                                                                  EE_messenger. Optional.
205
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
206
-     *                                                                  type should validate with. Each value in
207
-     *                                                                  the
208
-     *                                                                  array
209
-     *                                                                  should match the name property of an
210
-     *                                                                  EE_messenger.
211
-     *                                                                  Optional.
212
-     *                                                                  }
213
-     * @type array                    $custom_post_types
214
-     * @type array                    $custom_taxonomies
215
-     * @type array                    $payment_method_paths             each element is the folder containing the
216
-     *                                                                  EE_PMT_Base child class
217
-     *                                                                  (eg,
218
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
219
-     *                                                                  which contains the files
220
-     *                                                                  EE_PMT_Payomatic.pm.php)
221
-     * @type array                    $default_terms
222
-     * @type array                    $namespace                        {
223
-     *                                                                  An array with two items for registering the
224
-     *                                                                  addon's namespace. (If, for some reason, you
225
-     *                                                                  require additional namespaces,
226
-     *                                                                  use EventEspresso\core\Psr4Autoloader::addNamespace()
227
-     *                                                                  directly)
228
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
229
-     * @type string                   $FQNS                             the namespace prefix
230
-     * @type string                   $DIR                              a base directory for class files in the
231
-     *                                                                  namespace.
232
-     *                                                                  }
233
-     *                                                                  }
234
-     * @return void
235
-     * @throws DomainException
236
-     * @throws EE_Error
237
-     * @throws InvalidArgumentException
238
-     * @throws ReflectionException
239
-     * @throws InvalidDataTypeException
240
-     * @throws InvalidInterfaceException
241
-     */
242
-    public static function register($addon_name = '', $setup_args = array())
243
-    {
244
-        // required fields MUST be present, so let's make sure they are.
245
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
246
-        // get class name for addon
247
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
248
-        //setup $_settings array from incoming values.
249
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
250
-        // setup PUE
251
-        EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
252
-        // does this addon work with this version of core or WordPress ?
253
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
254
-            return;
255
-        }
256
-        // register namespaces
257
-        EE_Register_Addon::_setup_namespaces($addon_settings);
258
-        // check if this is an activation request
259
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
260
-            // dont bother setting up the rest of the addon atm
261
-            return;
262
-        }
263
-        // we need cars
264
-        EE_Register_Addon::_setup_autoloaders($addon_name);
265
-        // register new models and extensions
266
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
267
-        // setup DMS
268
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
269
-        // if config_class is present let's register config.
270
-        EE_Register_Addon::_register_config($addon_name);
271
-        // register admin pages
272
-        EE_Register_Addon::_register_admin_pages($addon_name);
273
-        // add to list of modules to be registered
274
-        EE_Register_Addon::_register_modules($addon_name);
275
-        // add to list of shortcodes to be registered
276
-        EE_Register_Addon::_register_shortcodes($addon_name);
277
-        // add to list of widgets to be registered
278
-        EE_Register_Addon::_register_widgets($addon_name);
279
-        // register capability related stuff.
280
-        EE_Register_Addon::_register_capabilities($addon_name);
281
-        // any message type to register?
282
-        EE_Register_Addon::_register_message_types($addon_name);
283
-        // any custom post type/ custom capabilities or default terms to register
284
-        EE_Register_Addon::_register_custom_post_types($addon_name);
285
-        // and any payment methods
286
-        EE_Register_Addon::_register_payment_methods($addon_name);
287
-        // load and instantiate main addon class
288
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
289
-        //delay calling after_registration hook on each addon until after all add-ons have been registered.
290
-        add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
291
-    }
108
+	/**
109
+	 * Method for registering new EE_Addons.
110
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
111
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
112
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
113
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
114
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
115
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
116
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
117
+	 * (so that we can detect that the addon has activated on the subsequent request)
118
+	 *
119
+	 * @since    4.3.0
120
+	 * @param string                  $addon_name                       the EE_Addon's name. Required.
121
+	 * @param  array                  $setup_args                       {
122
+	 *                                                                  An array of arguments provided for registering the
123
+	 *                                                                  message type.
124
+	 * @type  string                  $class_name                       the addon's main file name.
125
+	 *                                                                  If left blank, generated from the addon name,
126
+	 *                                                                  changes something like "calendar" to "EE_Calendar"
127
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
128
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
129
+	 * @type string                   $version                          the "software" version for the addon. eg
130
+	 *                                                                  "1.0.0.p" for a first stable release, or
131
+	 *                                                                  "1.0.0.rc.043" for a version in progress
132
+	 * @type string                   $main_file_path                   the full server path to the main file
133
+	 *                                                                  loaded directly by WP
134
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
135
+	 *                                                                  for the addon's Domain class
136
+	 *                                                                  (see EventEspresso\core\domain\Domain)
137
+	 * @type string                   $admin_path                       full server path to the folder where the
138
+	 *                                                                  addon\'s admin files reside
139
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
140
+	 *                                                                  first invoked, can be used for hooking into
141
+	 *                                                                  any admin page
142
+	 * @type string                   $config_section                   the section name for this addon's
143
+	 *                                                                  configuration settings section
144
+	 *                                                                  (defaults to "addons")
145
+	 * @type string                   $config_class                     the class name for this addon's
146
+	 *                                                                  configuration settings object
147
+	 * @type string                   $config_name                      the class name for this addon's
148
+	 *                                                                  configuration settings object
149
+	 * @type string                   $autoloader_paths                 an array of class names and the full server
150
+	 *                                                                  paths to those files. Required.
151
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
152
+	 *                                                                  folders containing classes that might be
153
+	 *                                                                  invoked by the addon
154
+	 * @type string                   $dms_paths                        an array of full server paths to folders that
155
+	 *                                                                  contain data migration scripts. Required.
156
+	 * @type string                   $module_paths                     an array of full server paths to any
157
+	 *                                                                  EED_Modules used by the addon
158
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
159
+	 *                                                                  that contain EES_Shortcodes
160
+	 * @type string                   $widget_paths                     an array of full server paths to folders
161
+	 *                                                                  that contain WP_Widgets
162
+	 * @type string                   $pue_options
163
+	 * @type array                    $capabilities                     an array indexed by role name
164
+	 *                                                                  (i.e administrator,author ) and the values
165
+	 *                                                                  are an array of caps to add to the role.
166
+	 *                                                                  'administrator' => array(
167
+	 *                                                                  'read_addon',
168
+	 *                                                                  'edit_addon',
169
+	 *                                                                  etc.
170
+	 *                                                                  ).
171
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
172
+	 *                                                                  for any addons that need to register any
173
+	 *                                                                  special meta mapped capabilities.  Should
174
+	 *                                                                  be indexed where the key is the
175
+	 *                                                                  EE_Meta_Capability_Map class name and the
176
+	 *                                                                  values are the arguments sent to the class.
177
+	 * @type array                    $model_paths                      array of folders containing DB models
178
+	 * @see      EE_Register_Model
179
+	 * @type array                    $class_paths                      array of folders containing DB classes
180
+	 * @see      EE_Register_Model
181
+	 * @type array                    $model_extension_paths            array of folders containing DB model
182
+	 *                                                                  extensions
183
+	 * @see      EE_Register_Model_Extension
184
+	 * @type array                    $class_extension_paths            array of folders containing DB class
185
+	 *                                                                  extensions
186
+	 * @see      EE_Register_Model_Extension
187
+	 * @type array message_types {
188
+	 *                                                                  An array of message types with the key as
189
+	 *                                                                  the message type name and the values as
190
+	 *                                                                  below:
191
+	 * @type string                   $mtfilename                       The filename of the message type being
192
+	 *                                                                  registered. This will be the main
193
+	 *                                                                  EE_{Message Type Name}_message_type class.
194
+	 *                                                                  (eg. EE_Declined_Registration_message_type.class.php)
195
+	 *                                                                  Required.
196
+	 * @type array                    $autoloadpaths                    An array of paths to add to the messages
197
+	 *                                                                  autoloader for the new message type.
198
+	 *                                                                  Required.
199
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
200
+	 *                                                                  type should activate with. Each value in
201
+	 *                                                                  the
202
+	 *                                                                  array
203
+	 *                                                                  should match the name property of a
204
+	 *                                                                  EE_messenger. Optional.
205
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
206
+	 *                                                                  type should validate with. Each value in
207
+	 *                                                                  the
208
+	 *                                                                  array
209
+	 *                                                                  should match the name property of an
210
+	 *                                                                  EE_messenger.
211
+	 *                                                                  Optional.
212
+	 *                                                                  }
213
+	 * @type array                    $custom_post_types
214
+	 * @type array                    $custom_taxonomies
215
+	 * @type array                    $payment_method_paths             each element is the folder containing the
216
+	 *                                                                  EE_PMT_Base child class
217
+	 *                                                                  (eg,
218
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
219
+	 *                                                                  which contains the files
220
+	 *                                                                  EE_PMT_Payomatic.pm.php)
221
+	 * @type array                    $default_terms
222
+	 * @type array                    $namespace                        {
223
+	 *                                                                  An array with two items for registering the
224
+	 *                                                                  addon's namespace. (If, for some reason, you
225
+	 *                                                                  require additional namespaces,
226
+	 *                                                                  use EventEspresso\core\Psr4Autoloader::addNamespace()
227
+	 *                                                                  directly)
228
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
229
+	 * @type string                   $FQNS                             the namespace prefix
230
+	 * @type string                   $DIR                              a base directory for class files in the
231
+	 *                                                                  namespace.
232
+	 *                                                                  }
233
+	 *                                                                  }
234
+	 * @return void
235
+	 * @throws DomainException
236
+	 * @throws EE_Error
237
+	 * @throws InvalidArgumentException
238
+	 * @throws ReflectionException
239
+	 * @throws InvalidDataTypeException
240
+	 * @throws InvalidInterfaceException
241
+	 */
242
+	public static function register($addon_name = '', $setup_args = array())
243
+	{
244
+		// required fields MUST be present, so let's make sure they are.
245
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
246
+		// get class name for addon
247
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
248
+		//setup $_settings array from incoming values.
249
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
250
+		// setup PUE
251
+		EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
252
+		// does this addon work with this version of core or WordPress ?
253
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
254
+			return;
255
+		}
256
+		// register namespaces
257
+		EE_Register_Addon::_setup_namespaces($addon_settings);
258
+		// check if this is an activation request
259
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
260
+			// dont bother setting up the rest of the addon atm
261
+			return;
262
+		}
263
+		// we need cars
264
+		EE_Register_Addon::_setup_autoloaders($addon_name);
265
+		// register new models and extensions
266
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
267
+		// setup DMS
268
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
269
+		// if config_class is present let's register config.
270
+		EE_Register_Addon::_register_config($addon_name);
271
+		// register admin pages
272
+		EE_Register_Addon::_register_admin_pages($addon_name);
273
+		// add to list of modules to be registered
274
+		EE_Register_Addon::_register_modules($addon_name);
275
+		// add to list of shortcodes to be registered
276
+		EE_Register_Addon::_register_shortcodes($addon_name);
277
+		// add to list of widgets to be registered
278
+		EE_Register_Addon::_register_widgets($addon_name);
279
+		// register capability related stuff.
280
+		EE_Register_Addon::_register_capabilities($addon_name);
281
+		// any message type to register?
282
+		EE_Register_Addon::_register_message_types($addon_name);
283
+		// any custom post type/ custom capabilities or default terms to register
284
+		EE_Register_Addon::_register_custom_post_types($addon_name);
285
+		// and any payment methods
286
+		EE_Register_Addon::_register_payment_methods($addon_name);
287
+		// load and instantiate main addon class
288
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
289
+		//delay calling after_registration hook on each addon until after all add-ons have been registered.
290
+		add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
291
+	}
292 292
 
293 293
 
294
-    /**
295
-     * @param string $addon_name
296
-     * @param array  $setup_args
297
-     * @return void
298
-     * @throws EE_Error
299
-     */
300
-    private static function _verify_parameters($addon_name, array $setup_args)
301
-    {
302
-        // required fields MUST be present, so let's make sure they are.
303
-        if (empty($addon_name) || ! is_array($setup_args)) {
304
-            throw new EE_Error(
305
-                __(
306
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
307
-                    'event_espresso'
308
-                )
309
-            );
310
-        }
311
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
312
-            throw new EE_Error(
313
-                sprintf(
314
-                    __(
315
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
316
-                        'event_espresso'
317
-                    ),
318
-                    implode(',', array_keys($setup_args))
319
-                )
320
-            );
321
-        }
322
-        // check that addon has not already been registered with that name
323
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
324
-            throw new EE_Error(
325
-                sprintf(
326
-                    __(
327
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
328
-                        'event_espresso'
329
-                    ),
330
-                    $addon_name
331
-                )
332
-            );
333
-        }
334
-    }
294
+	/**
295
+	 * @param string $addon_name
296
+	 * @param array  $setup_args
297
+	 * @return void
298
+	 * @throws EE_Error
299
+	 */
300
+	private static function _verify_parameters($addon_name, array $setup_args)
301
+	{
302
+		// required fields MUST be present, so let's make sure they are.
303
+		if (empty($addon_name) || ! is_array($setup_args)) {
304
+			throw new EE_Error(
305
+				__(
306
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
307
+					'event_espresso'
308
+				)
309
+			);
310
+		}
311
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
312
+			throw new EE_Error(
313
+				sprintf(
314
+					__(
315
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
316
+						'event_espresso'
317
+					),
318
+					implode(',', array_keys($setup_args))
319
+				)
320
+			);
321
+		}
322
+		// check that addon has not already been registered with that name
323
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
324
+			throw new EE_Error(
325
+				sprintf(
326
+					__(
327
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
328
+						'event_espresso'
329
+					),
330
+					$addon_name
331
+				)
332
+			);
333
+		}
334
+	}
335 335
 
336 336
 
337
-    /**
338
-     * @param string $addon_name
339
-     * @param array  $setup_args
340
-     * @return string
341
-     */
342
-    private static function _parse_class_name($addon_name, array $setup_args)
343
-    {
344
-        if (empty($setup_args['class_name'])) {
345
-            // generate one by first separating name with spaces
346
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
347
-            //capitalize, then replace spaces with underscores
348
-            $class_name = str_replace(' ', '_', ucwords($class_name));
349
-        } else {
350
-            $class_name = $setup_args['class_name'];
351
-        }
352
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
353
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
354
-            ? $class_name
355
-            : 'EE_' . $class_name;
356
-    }
337
+	/**
338
+	 * @param string $addon_name
339
+	 * @param array  $setup_args
340
+	 * @return string
341
+	 */
342
+	private static function _parse_class_name($addon_name, array $setup_args)
343
+	{
344
+		if (empty($setup_args['class_name'])) {
345
+			// generate one by first separating name with spaces
346
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
347
+			//capitalize, then replace spaces with underscores
348
+			$class_name = str_replace(' ', '_', ucwords($class_name));
349
+		} else {
350
+			$class_name = $setup_args['class_name'];
351
+		}
352
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
353
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
354
+			? $class_name
355
+			: 'EE_' . $class_name;
356
+	}
357 357
 
358 358
 
359
-    /**
360
-     * @param string $class_name
361
-     * @param array  $setup_args
362
-     * @return array
363
-     */
364
-    private static function _get_addon_settings($class_name, array $setup_args)
365
-    {
366
-        //setup $_settings array from incoming values.
367
-        $addon_settings = array(
368
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
369
-            'class_name'            => $class_name,
370
-            // the addon slug for use in URLs, etc
371
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
372
-                ? (string) $setup_args['plugin_slug']
373
-                : '',
374
-            // page slug to be used when generating the "Settings" link on the WP plugin page
375
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
376
-                ? (string) $setup_args['plugin_action_slug']
377
-                : '',
378
-            // the "software" version for the addon
379
-            'version'               => isset($setup_args['version'])
380
-                ? (string) $setup_args['version']
381
-                : '',
382
-            // the minimum version of EE Core that the addon will work with
383
-            'min_core_version'      => isset($setup_args['min_core_version'])
384
-                ? (string) $setup_args['min_core_version']
385
-                : '',
386
-            // the minimum version of WordPress that the addon will work with
387
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
388
-                ? (string) $setup_args['min_wp_version']
389
-                : EE_MIN_WP_VER_REQUIRED,
390
-            // full server path to main file (file loaded directly by WP)
391
-            'main_file_path'        => isset($setup_args['main_file_path'])
392
-                ? (string) $setup_args['main_file_path']
393
-                : '',
394
-            // Fully Qualified Class Name for the addon's Domain class
395
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
396
-                ? (string) $setup_args['domain_fqcn']
397
-                : '',
398
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
399
-            'admin_path'            => isset($setup_args['admin_path'])
400
-                ? (string) $setup_args['admin_path'] : '',
401
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
402
-            'admin_callback'        => isset($setup_args['admin_callback'])
403
-                ? (string) $setup_args['admin_callback']
404
-                : '',
405
-            // the section name for this addon's configuration settings section (defaults to "addons")
406
-            'config_section'        => isset($setup_args['config_section'])
407
-                ? (string) $setup_args['config_section']
408
-                : 'addons',
409
-            // the class name for this addon's configuration settings object
410
-            'config_class'          => isset($setup_args['config_class'])
411
-                ? (string) $setup_args['config_class'] : '',
412
-            //the name given to the config for this addons' configuration settings object (optional)
413
-            'config_name'           => isset($setup_args['config_name'])
414
-                ? (string) $setup_args['config_name'] : '',
415
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
416
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
417
-                ? (array) $setup_args['autoloader_paths']
418
-                : array(),
419
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
420
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
421
-                ? (array) $setup_args['autoloader_folders']
422
-                : array(),
423
-            // array of full server paths to any EE_DMS data migration scripts used by the addon
424
-            'dms_paths'             => isset($setup_args['dms_paths'])
425
-                ? (array) $setup_args['dms_paths']
426
-                : array(),
427
-            // array of full server paths to any EED_Modules used by the addon
428
-            'module_paths'          => isset($setup_args['module_paths'])
429
-                ? (array) $setup_args['module_paths']
430
-                : array(),
431
-            // array of full server paths to any EES_Shortcodes used by the addon
432
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
433
-                ? (array) $setup_args['shortcode_paths']
434
-                : array(),
435
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
436
-                ? (array) $setup_args['shortcode_fqcns']
437
-                : array(),
438
-            // array of full server paths to any WP_Widgets used by the addon
439
-            'widget_paths'          => isset($setup_args['widget_paths'])
440
-                ? (array) $setup_args['widget_paths']
441
-                : array(),
442
-            // array of PUE options used by the addon
443
-            'pue_options'           => isset($setup_args['pue_options'])
444
-                ? (array) $setup_args['pue_options']
445
-                : array(),
446
-            'message_types'         => isset($setup_args['message_types'])
447
-                ? (array) $setup_args['message_types']
448
-                : array(),
449
-            'capabilities'          => isset($setup_args['capabilities'])
450
-                ? (array) $setup_args['capabilities']
451
-                : array(),
452
-            'capability_maps'       => isset($setup_args['capability_maps'])
453
-                ? (array) $setup_args['capability_maps']
454
-                : array(),
455
-            'model_paths'           => isset($setup_args['model_paths'])
456
-                ? (array) $setup_args['model_paths']
457
-                : array(),
458
-            'class_paths'           => isset($setup_args['class_paths'])
459
-                ? (array) $setup_args['class_paths']
460
-                : array(),
461
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
462
-                ? (array) $setup_args['model_extension_paths']
463
-                : array(),
464
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
465
-                ? (array) $setup_args['class_extension_paths']
466
-                : array(),
467
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
468
-                ? (array) $setup_args['custom_post_types']
469
-                : array(),
470
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
471
-                ? (array) $setup_args['custom_taxonomies']
472
-                : array(),
473
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
474
-                ? (array) $setup_args['payment_method_paths']
475
-                : array(),
476
-            'default_terms'         => isset($setup_args['default_terms'])
477
-                ? (array) $setup_args['default_terms']
478
-                : array(),
479
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
480
-            // that can be used for adding upgrading/marketing info
481
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
482
-                ? $setup_args['plugins_page_row']
483
-                : '',
484
-            'namespace'             => isset(
485
-                $setup_args['namespace']['FQNS'],
486
-                $setup_args['namespace']['DIR']
487
-            )
488
-                ? (array) $setup_args['namespace']
489
-                : array(),
490
-        );
491
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
492
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
493
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
494
-                                                && ! empty($addon_settings['admin_path'])
495
-            ? $addon_settings['plugin_slug']
496
-            : $addon_settings['plugin_action_slug'];
497
-        // full server path to main file (file loaded directly by WP)
498
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
499
-        return $addon_settings;
500
-    }
359
+	/**
360
+	 * @param string $class_name
361
+	 * @param array  $setup_args
362
+	 * @return array
363
+	 */
364
+	private static function _get_addon_settings($class_name, array $setup_args)
365
+	{
366
+		//setup $_settings array from incoming values.
367
+		$addon_settings = array(
368
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
369
+			'class_name'            => $class_name,
370
+			// the addon slug for use in URLs, etc
371
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
372
+				? (string) $setup_args['plugin_slug']
373
+				: '',
374
+			// page slug to be used when generating the "Settings" link on the WP plugin page
375
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
376
+				? (string) $setup_args['plugin_action_slug']
377
+				: '',
378
+			// the "software" version for the addon
379
+			'version'               => isset($setup_args['version'])
380
+				? (string) $setup_args['version']
381
+				: '',
382
+			// the minimum version of EE Core that the addon will work with
383
+			'min_core_version'      => isset($setup_args['min_core_version'])
384
+				? (string) $setup_args['min_core_version']
385
+				: '',
386
+			// the minimum version of WordPress that the addon will work with
387
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
388
+				? (string) $setup_args['min_wp_version']
389
+				: EE_MIN_WP_VER_REQUIRED,
390
+			// full server path to main file (file loaded directly by WP)
391
+			'main_file_path'        => isset($setup_args['main_file_path'])
392
+				? (string) $setup_args['main_file_path']
393
+				: '',
394
+			// Fully Qualified Class Name for the addon's Domain class
395
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
396
+				? (string) $setup_args['domain_fqcn']
397
+				: '',
398
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
399
+			'admin_path'            => isset($setup_args['admin_path'])
400
+				? (string) $setup_args['admin_path'] : '',
401
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
402
+			'admin_callback'        => isset($setup_args['admin_callback'])
403
+				? (string) $setup_args['admin_callback']
404
+				: '',
405
+			// the section name for this addon's configuration settings section (defaults to "addons")
406
+			'config_section'        => isset($setup_args['config_section'])
407
+				? (string) $setup_args['config_section']
408
+				: 'addons',
409
+			// the class name for this addon's configuration settings object
410
+			'config_class'          => isset($setup_args['config_class'])
411
+				? (string) $setup_args['config_class'] : '',
412
+			//the name given to the config for this addons' configuration settings object (optional)
413
+			'config_name'           => isset($setup_args['config_name'])
414
+				? (string) $setup_args['config_name'] : '',
415
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
416
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
417
+				? (array) $setup_args['autoloader_paths']
418
+				: array(),
419
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
420
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
421
+				? (array) $setup_args['autoloader_folders']
422
+				: array(),
423
+			// array of full server paths to any EE_DMS data migration scripts used by the addon
424
+			'dms_paths'             => isset($setup_args['dms_paths'])
425
+				? (array) $setup_args['dms_paths']
426
+				: array(),
427
+			// array of full server paths to any EED_Modules used by the addon
428
+			'module_paths'          => isset($setup_args['module_paths'])
429
+				? (array) $setup_args['module_paths']
430
+				: array(),
431
+			// array of full server paths to any EES_Shortcodes used by the addon
432
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
433
+				? (array) $setup_args['shortcode_paths']
434
+				: array(),
435
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
436
+				? (array) $setup_args['shortcode_fqcns']
437
+				: array(),
438
+			// array of full server paths to any WP_Widgets used by the addon
439
+			'widget_paths'          => isset($setup_args['widget_paths'])
440
+				? (array) $setup_args['widget_paths']
441
+				: array(),
442
+			// array of PUE options used by the addon
443
+			'pue_options'           => isset($setup_args['pue_options'])
444
+				? (array) $setup_args['pue_options']
445
+				: array(),
446
+			'message_types'         => isset($setup_args['message_types'])
447
+				? (array) $setup_args['message_types']
448
+				: array(),
449
+			'capabilities'          => isset($setup_args['capabilities'])
450
+				? (array) $setup_args['capabilities']
451
+				: array(),
452
+			'capability_maps'       => isset($setup_args['capability_maps'])
453
+				? (array) $setup_args['capability_maps']
454
+				: array(),
455
+			'model_paths'           => isset($setup_args['model_paths'])
456
+				? (array) $setup_args['model_paths']
457
+				: array(),
458
+			'class_paths'           => isset($setup_args['class_paths'])
459
+				? (array) $setup_args['class_paths']
460
+				: array(),
461
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
462
+				? (array) $setup_args['model_extension_paths']
463
+				: array(),
464
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
465
+				? (array) $setup_args['class_extension_paths']
466
+				: array(),
467
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
468
+				? (array) $setup_args['custom_post_types']
469
+				: array(),
470
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
471
+				? (array) $setup_args['custom_taxonomies']
472
+				: array(),
473
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
474
+				? (array) $setup_args['payment_method_paths']
475
+				: array(),
476
+			'default_terms'         => isset($setup_args['default_terms'])
477
+				? (array) $setup_args['default_terms']
478
+				: array(),
479
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
480
+			// that can be used for adding upgrading/marketing info
481
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
482
+				? $setup_args['plugins_page_row']
483
+				: '',
484
+			'namespace'             => isset(
485
+				$setup_args['namespace']['FQNS'],
486
+				$setup_args['namespace']['DIR']
487
+			)
488
+				? (array) $setup_args['namespace']
489
+				: array(),
490
+		);
491
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
492
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
493
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
494
+												&& ! empty($addon_settings['admin_path'])
495
+			? $addon_settings['plugin_slug']
496
+			: $addon_settings['plugin_action_slug'];
497
+		// full server path to main file (file loaded directly by WP)
498
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
499
+		return $addon_settings;
500
+	}
501 501
 
502 502
 
503
-    /**
504
-     * @param string $addon_name
505
-     * @param array  $addon_settings
506
-     * @return boolean
507
-     */
508
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
509
-    {
510
-        global $wp_version;
511
-        $incompatibility_message = '';
512
-        //check whether this addon version is compatible with EE core
513
-        if (
514
-            isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
515
-            && ! self::_meets_min_core_version_requirement(
516
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
517
-                $addon_settings['version']
518
-            )
519
-        ) {
520
-            $incompatibility_message = sprintf(
521
-                __(
522
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
523
-                ),
524
-                $addon_name,
525
-                '<br />',
526
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
527
-                '<span style="font-weight: bold; color: #D54E21;">',
528
-                '</span><br />'
529
-            );
530
-        } elseif (
531
-        ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
532
-        ) {
533
-            $incompatibility_message = sprintf(
534
-                __(
535
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
536
-                    'event_espresso'
537
-                ),
538
-                $addon_name,
539
-                self::_effective_version($addon_settings['min_core_version']),
540
-                self::_effective_version(espresso_version()),
541
-                '<br />',
542
-                '<span style="font-weight: bold; color: #D54E21;">',
543
-                '</span><br />'
544
-            );
545
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
546
-            $incompatibility_message = sprintf(
547
-                __(
548
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
549
-                    'event_espresso'
550
-                ),
551
-                $addon_name,
552
-                $addon_settings['min_wp_version'],
553
-                '<br />',
554
-                '<span style="font-weight: bold; color: #D54E21;">',
555
-                '</span><br />'
556
-            );
557
-        }
558
-        if (! empty($incompatibility_message)) {
559
-            // remove 'activate' from the REQUEST
560
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
561
-            unset($_GET['activate'], $_REQUEST['activate']);
562
-            if (current_user_can('activate_plugins')) {
563
-                // show an error message indicating the plugin didn't activate properly
564
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
565
-            }
566
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
567
-            return false;
568
-        }
569
-        // addon IS compatible
570
-        return true;
571
-    }
503
+	/**
504
+	 * @param string $addon_name
505
+	 * @param array  $addon_settings
506
+	 * @return boolean
507
+	 */
508
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
509
+	{
510
+		global $wp_version;
511
+		$incompatibility_message = '';
512
+		//check whether this addon version is compatible with EE core
513
+		if (
514
+			isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
515
+			&& ! self::_meets_min_core_version_requirement(
516
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
517
+				$addon_settings['version']
518
+			)
519
+		) {
520
+			$incompatibility_message = sprintf(
521
+				__(
522
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
523
+				),
524
+				$addon_name,
525
+				'<br />',
526
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
527
+				'<span style="font-weight: bold; color: #D54E21;">',
528
+				'</span><br />'
529
+			);
530
+		} elseif (
531
+		! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
532
+		) {
533
+			$incompatibility_message = sprintf(
534
+				__(
535
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
536
+					'event_espresso'
537
+				),
538
+				$addon_name,
539
+				self::_effective_version($addon_settings['min_core_version']),
540
+				self::_effective_version(espresso_version()),
541
+				'<br />',
542
+				'<span style="font-weight: bold; color: #D54E21;">',
543
+				'</span><br />'
544
+			);
545
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
546
+			$incompatibility_message = sprintf(
547
+				__(
548
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
549
+					'event_espresso'
550
+				),
551
+				$addon_name,
552
+				$addon_settings['min_wp_version'],
553
+				'<br />',
554
+				'<span style="font-weight: bold; color: #D54E21;">',
555
+				'</span><br />'
556
+			);
557
+		}
558
+		if (! empty($incompatibility_message)) {
559
+			// remove 'activate' from the REQUEST
560
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
561
+			unset($_GET['activate'], $_REQUEST['activate']);
562
+			if (current_user_can('activate_plugins')) {
563
+				// show an error message indicating the plugin didn't activate properly
564
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
565
+			}
566
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
567
+			return false;
568
+		}
569
+		// addon IS compatible
570
+		return true;
571
+	}
572 572
 
573 573
 
574
-    /**
575
-     * if plugin update engine is being used for auto-updates,
576
-     * then let's set that up now before going any further so that ALL addons can be updated
577
-     * (not needed if PUE is not being used)
578
-     *
579
-     * @param string $addon_name
580
-     * @param string $class_name
581
-     * @param array  $setup_args
582
-     * @return void
583
-     */
584
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
585
-    {
586
-        if (! empty($setup_args['pue_options'])) {
587
-            self::$_settings[ $addon_name ]['pue_options'] = array(
588
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
589
-                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
590
-                    : 'espresso_' . strtolower($class_name),
591
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
592
-                    ? (string) $setup_args['pue_options']['plugin_basename']
593
-                    : plugin_basename($setup_args['main_file_path']),
594
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
595
-                    ? (string) $setup_args['pue_options']['checkPeriod']
596
-                    : '24',
597
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
598
-                    ? (string) $setup_args['pue_options']['use_wp_update']
599
-                    : false,
600
-            );
601
-            add_action(
602
-                'AHEE__EE_System__brew_espresso__after_pue_init',
603
-                array('EE_Register_Addon', 'load_pue_update')
604
-            );
605
-        }
606
-    }
574
+	/**
575
+	 * if plugin update engine is being used for auto-updates,
576
+	 * then let's set that up now before going any further so that ALL addons can be updated
577
+	 * (not needed if PUE is not being used)
578
+	 *
579
+	 * @param string $addon_name
580
+	 * @param string $class_name
581
+	 * @param array  $setup_args
582
+	 * @return void
583
+	 */
584
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
585
+	{
586
+		if (! empty($setup_args['pue_options'])) {
587
+			self::$_settings[ $addon_name ]['pue_options'] = array(
588
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
589
+					? (string) $setup_args['pue_options']['pue_plugin_slug']
590
+					: 'espresso_' . strtolower($class_name),
591
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
592
+					? (string) $setup_args['pue_options']['plugin_basename']
593
+					: plugin_basename($setup_args['main_file_path']),
594
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
595
+					? (string) $setup_args['pue_options']['checkPeriod']
596
+					: '24',
597
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
598
+					? (string) $setup_args['pue_options']['use_wp_update']
599
+					: false,
600
+			);
601
+			add_action(
602
+				'AHEE__EE_System__brew_espresso__after_pue_init',
603
+				array('EE_Register_Addon', 'load_pue_update')
604
+			);
605
+		}
606
+	}
607 607
 
608 608
 
609
-    /**
610
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
611
-     *
612
-     * @param array $addon_settings
613
-     * @return void
614
-     */
615
-    private static function _setup_namespaces(array $addon_settings)
616
-    {
617
-        //
618
-        if (
619
-        isset(
620
-            $addon_settings['namespace']['FQNS'],
621
-            $addon_settings['namespace']['DIR']
622
-        )
623
-        ) {
624
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
625
-                $addon_settings['namespace']['FQNS'],
626
-                $addon_settings['namespace']['DIR']
627
-            );
628
-        }
629
-    }
609
+	/**
610
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
611
+	 *
612
+	 * @param array $addon_settings
613
+	 * @return void
614
+	 */
615
+	private static function _setup_namespaces(array $addon_settings)
616
+	{
617
+		//
618
+		if (
619
+		isset(
620
+			$addon_settings['namespace']['FQNS'],
621
+			$addon_settings['namespace']['DIR']
622
+		)
623
+		) {
624
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
625
+				$addon_settings['namespace']['FQNS'],
626
+				$addon_settings['namespace']['DIR']
627
+			);
628
+		}
629
+	}
630 630
 
631 631
 
632
-    /**
633
-     * @param string $addon_name
634
-     * @param array  $addon_settings
635
-     * @return bool
636
-     * @throws EE_Error
637
-     * @throws InvalidArgumentException
638
-     * @throws ReflectionException
639
-     * @throws InvalidDataTypeException
640
-     * @throws InvalidInterfaceException
641
-     */
642
-    private static function _addon_activation($addon_name, array $addon_settings)
643
-    {
644
-        // this is an activation request
645
-        if (did_action('activate_plugin')) {
646
-            //to find if THIS is the addon that was activated, just check if we have already registered it or not
647
-            //(as the newly-activated addon wasn't around the first time addons were registered).
648
-            //Note: the presence of pue_options in the addon registration options will initialize the $_settings
649
-            //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
650
-            if (! isset(self::$_settings[ $addon_name ])
651
-                || (isset(self::$_settings[ $addon_name ])
652
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
653
-                )
654
-            ) {
655
-                self::$_settings[ $addon_name ] = $addon_settings;
656
-                $addon                          = self::_load_and_init_addon_class($addon_name);
657
-                $addon->set_activation_indicator_option();
658
-                // dont bother setting up the rest of the addon.
659
-                // we know it was just activated and the request will end soon
660
-            }
661
-            return true;
662
-        }
663
-        // make sure this was called in the right place!
664
-        if (
665
-            ! did_action('AHEE__EE_System__load_espresso_addons')
666
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
667
-        ) {
668
-            EE_Error::doing_it_wrong(
669
-                __METHOD__,
670
-                sprintf(
671
-                    __(
672
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
673
-                        'event_espresso'
674
-                    ),
675
-                    $addon_name
676
-                ),
677
-                '4.3.0'
678
-            );
679
-        }
680
-        // make sure addon settings are set correctly without overwriting anything existing
681
-        if (isset(self::$_settings[ $addon_name ])) {
682
-            self::$_settings[ $addon_name ] += $addon_settings;
683
-        } else {
684
-            self::$_settings[ $addon_name ] = $addon_settings;
685
-        }
686
-        return false;
687
-    }
632
+	/**
633
+	 * @param string $addon_name
634
+	 * @param array  $addon_settings
635
+	 * @return bool
636
+	 * @throws EE_Error
637
+	 * @throws InvalidArgumentException
638
+	 * @throws ReflectionException
639
+	 * @throws InvalidDataTypeException
640
+	 * @throws InvalidInterfaceException
641
+	 */
642
+	private static function _addon_activation($addon_name, array $addon_settings)
643
+	{
644
+		// this is an activation request
645
+		if (did_action('activate_plugin')) {
646
+			//to find if THIS is the addon that was activated, just check if we have already registered it or not
647
+			//(as the newly-activated addon wasn't around the first time addons were registered).
648
+			//Note: the presence of pue_options in the addon registration options will initialize the $_settings
649
+			//property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
650
+			if (! isset(self::$_settings[ $addon_name ])
651
+				|| (isset(self::$_settings[ $addon_name ])
652
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
653
+				)
654
+			) {
655
+				self::$_settings[ $addon_name ] = $addon_settings;
656
+				$addon                          = self::_load_and_init_addon_class($addon_name);
657
+				$addon->set_activation_indicator_option();
658
+				// dont bother setting up the rest of the addon.
659
+				// we know it was just activated and the request will end soon
660
+			}
661
+			return true;
662
+		}
663
+		// make sure this was called in the right place!
664
+		if (
665
+			! did_action('AHEE__EE_System__load_espresso_addons')
666
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
667
+		) {
668
+			EE_Error::doing_it_wrong(
669
+				__METHOD__,
670
+				sprintf(
671
+					__(
672
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
673
+						'event_espresso'
674
+					),
675
+					$addon_name
676
+				),
677
+				'4.3.0'
678
+			);
679
+		}
680
+		// make sure addon settings are set correctly without overwriting anything existing
681
+		if (isset(self::$_settings[ $addon_name ])) {
682
+			self::$_settings[ $addon_name ] += $addon_settings;
683
+		} else {
684
+			self::$_settings[ $addon_name ] = $addon_settings;
685
+		}
686
+		return false;
687
+	}
688 688
 
689 689
 
690
-    /**
691
-     * @param string $addon_name
692
-     * @return void
693
-     * @throws EE_Error
694
-     */
695
-    private static function _setup_autoloaders($addon_name)
696
-    {
697
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
698
-            // setup autoloader for single file
699
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
700
-        }
701
-        // setup autoloaders for folders
702
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
703
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
704
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
705
-            }
706
-        }
707
-    }
690
+	/**
691
+	 * @param string $addon_name
692
+	 * @return void
693
+	 * @throws EE_Error
694
+	 */
695
+	private static function _setup_autoloaders($addon_name)
696
+	{
697
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
698
+			// setup autoloader for single file
699
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
700
+		}
701
+		// setup autoloaders for folders
702
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
703
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
704
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
705
+			}
706
+		}
707
+	}
708 708
 
709 709
 
710
-    /**
711
-     * register new models and extensions
712
-     *
713
-     * @param string $addon_name
714
-     * @return void
715
-     * @throws EE_Error
716
-     */
717
-    private static function _register_models_and_extensions($addon_name)
718
-    {
719
-        // register new models
720
-        if (
721
-            ! empty(self::$_settings[ $addon_name ]['model_paths'])
722
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
723
-        ) {
724
-            EE_Register_Model::register(
725
-                $addon_name,
726
-                array(
727
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
728
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
729
-                )
730
-            );
731
-        }
732
-        // register model extensions
733
-        if (
734
-            ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
735
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
736
-        ) {
737
-            EE_Register_Model_Extensions::register(
738
-                $addon_name,
739
-                array(
740
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
741
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
742
-                )
743
-            );
744
-        }
745
-    }
710
+	/**
711
+	 * register new models and extensions
712
+	 *
713
+	 * @param string $addon_name
714
+	 * @return void
715
+	 * @throws EE_Error
716
+	 */
717
+	private static function _register_models_and_extensions($addon_name)
718
+	{
719
+		// register new models
720
+		if (
721
+			! empty(self::$_settings[ $addon_name ]['model_paths'])
722
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
723
+		) {
724
+			EE_Register_Model::register(
725
+				$addon_name,
726
+				array(
727
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
728
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
729
+				)
730
+			);
731
+		}
732
+		// register model extensions
733
+		if (
734
+			! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
735
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
736
+		) {
737
+			EE_Register_Model_Extensions::register(
738
+				$addon_name,
739
+				array(
740
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
741
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
742
+				)
743
+			);
744
+		}
745
+	}
746 746
 
747 747
 
748
-    /**
749
-     * @param string $addon_name
750
-     * @return void
751
-     * @throws EE_Error
752
-     */
753
-    private static function _register_data_migration_scripts($addon_name)
754
-    {
755
-        // setup DMS
756
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
757
-            EE_Register_Data_Migration_Scripts::register(
758
-                $addon_name,
759
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
760
-            );
761
-        }
762
-    }
748
+	/**
749
+	 * @param string $addon_name
750
+	 * @return void
751
+	 * @throws EE_Error
752
+	 */
753
+	private static function _register_data_migration_scripts($addon_name)
754
+	{
755
+		// setup DMS
756
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
757
+			EE_Register_Data_Migration_Scripts::register(
758
+				$addon_name,
759
+				array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
760
+			);
761
+		}
762
+	}
763 763
 
764 764
 
765
-    /**
766
-     * @param string $addon_name
767
-     * @return void
768
-     * @throws EE_Error
769
-     */
770
-    private static function _register_config($addon_name)
771
-    {
772
-        // if config_class is present let's register config.
773
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
774
-            EE_Register_Config::register(
775
-                self::$_settings[ $addon_name ]['config_class'],
776
-                array(
777
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
778
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
779
-                )
780
-            );
781
-        }
782
-    }
765
+	/**
766
+	 * @param string $addon_name
767
+	 * @return void
768
+	 * @throws EE_Error
769
+	 */
770
+	private static function _register_config($addon_name)
771
+	{
772
+		// if config_class is present let's register config.
773
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
774
+			EE_Register_Config::register(
775
+				self::$_settings[ $addon_name ]['config_class'],
776
+				array(
777
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
778
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
779
+				)
780
+			);
781
+		}
782
+	}
783 783
 
784 784
 
785
-    /**
786
-     * @param string $addon_name
787
-     * @return void
788
-     * @throws EE_Error
789
-     */
790
-    private static function _register_admin_pages($addon_name)
791
-    {
792
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
793
-            EE_Register_Admin_Page::register(
794
-                $addon_name,
795
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
796
-            );
797
-        }
798
-    }
785
+	/**
786
+	 * @param string $addon_name
787
+	 * @return void
788
+	 * @throws EE_Error
789
+	 */
790
+	private static function _register_admin_pages($addon_name)
791
+	{
792
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
793
+			EE_Register_Admin_Page::register(
794
+				$addon_name,
795
+				array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
796
+			);
797
+		}
798
+	}
799 799
 
800 800
 
801
-    /**
802
-     * @param string $addon_name
803
-     * @return void
804
-     * @throws EE_Error
805
-     */
806
-    private static function _register_modules($addon_name)
807
-    {
808
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
809
-            EE_Register_Module::register(
810
-                $addon_name,
811
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
812
-            );
813
-        }
814
-    }
801
+	/**
802
+	 * @param string $addon_name
803
+	 * @return void
804
+	 * @throws EE_Error
805
+	 */
806
+	private static function _register_modules($addon_name)
807
+	{
808
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
809
+			EE_Register_Module::register(
810
+				$addon_name,
811
+				array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
812
+			);
813
+		}
814
+	}
815 815
 
816 816
 
817
-    /**
818
-     * @param string $addon_name
819
-     * @return void
820
-     * @throws EE_Error
821
-     */
822
-    private static function _register_shortcodes($addon_name)
823
-    {
824
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
825
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
826
-        ) {
827
-            EE_Register_Shortcode::register(
828
-                $addon_name,
829
-                array(
830
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
831
-                        ? self::$_settings[ $addon_name ]['shortcode_paths']
832
-                        : array(),
833
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
834
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns']
835
-                        : array(),
836
-                )
837
-            );
838
-        }
839
-    }
817
+	/**
818
+	 * @param string $addon_name
819
+	 * @return void
820
+	 * @throws EE_Error
821
+	 */
822
+	private static function _register_shortcodes($addon_name)
823
+	{
824
+		if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
825
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
826
+		) {
827
+			EE_Register_Shortcode::register(
828
+				$addon_name,
829
+				array(
830
+					'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
831
+						? self::$_settings[ $addon_name ]['shortcode_paths']
832
+						: array(),
833
+					'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
834
+						? self::$_settings[ $addon_name ]['shortcode_fqcns']
835
+						: array(),
836
+				)
837
+			);
838
+		}
839
+	}
840 840
 
841 841
 
842
-    /**
843
-     * @param string $addon_name
844
-     * @return void
845
-     * @throws EE_Error
846
-     */
847
-    private static function _register_widgets($addon_name)
848
-    {
849
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
850
-            EE_Register_Widget::register(
851
-                $addon_name,
852
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
853
-            );
854
-        }
855
-    }
842
+	/**
843
+	 * @param string $addon_name
844
+	 * @return void
845
+	 * @throws EE_Error
846
+	 */
847
+	private static function _register_widgets($addon_name)
848
+	{
849
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
850
+			EE_Register_Widget::register(
851
+				$addon_name,
852
+				array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
853
+			);
854
+		}
855
+	}
856 856
 
857 857
 
858
-    /**
859
-     * @param string $addon_name
860
-     * @return void
861
-     * @throws EE_Error
862
-     */
863
-    private static function _register_capabilities($addon_name)
864
-    {
865
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
866
-            EE_Register_Capabilities::register(
867
-                $addon_name,
868
-                array(
869
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
870
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
871
-                )
872
-            );
873
-        }
874
-    }
858
+	/**
859
+	 * @param string $addon_name
860
+	 * @return void
861
+	 * @throws EE_Error
862
+	 */
863
+	private static function _register_capabilities($addon_name)
864
+	{
865
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
866
+			EE_Register_Capabilities::register(
867
+				$addon_name,
868
+				array(
869
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
870
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
871
+				)
872
+			);
873
+		}
874
+	}
875 875
 
876 876
 
877
-    /**
878
-     * @param string $addon_name
879
-     * @return void
880
-     * @throws EE_Error
881
-     */
882
-    private static function _register_message_types($addon_name)
883
-    {
884
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
885
-            add_action(
886
-                'EE_Brewing_Regular___messages_caf',
887
-                array('EE_Register_Addon', 'register_message_types')
888
-            );
889
-        }
890
-    }
877
+	/**
878
+	 * @param string $addon_name
879
+	 * @return void
880
+	 * @throws EE_Error
881
+	 */
882
+	private static function _register_message_types($addon_name)
883
+	{
884
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
885
+			add_action(
886
+				'EE_Brewing_Regular___messages_caf',
887
+				array('EE_Register_Addon', 'register_message_types')
888
+			);
889
+		}
890
+	}
891 891
 
892 892
 
893
-    /**
894
-     * @param string $addon_name
895
-     * @return void
896
-     * @throws EE_Error
897
-     */
898
-    private static function _register_custom_post_types($addon_name)
899
-    {
900
-        if (
901
-            ! empty(self::$_settings[ $addon_name ]['custom_post_types'])
902
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
903
-        ) {
904
-            EE_Register_CPT::register(
905
-                $addon_name,
906
-                array(
907
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
908
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
909
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
910
-                )
911
-            );
912
-        }
913
-    }
893
+	/**
894
+	 * @param string $addon_name
895
+	 * @return void
896
+	 * @throws EE_Error
897
+	 */
898
+	private static function _register_custom_post_types($addon_name)
899
+	{
900
+		if (
901
+			! empty(self::$_settings[ $addon_name ]['custom_post_types'])
902
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
903
+		) {
904
+			EE_Register_CPT::register(
905
+				$addon_name,
906
+				array(
907
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
908
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
909
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
910
+				)
911
+			);
912
+		}
913
+	}
914 914
 
915 915
 
916
-    /**
917
-     * @param string $addon_name
918
-     * @return void
919
-     * @throws InvalidArgumentException
920
-     * @throws InvalidInterfaceException
921
-     * @throws InvalidDataTypeException
922
-     * @throws DomainException
923
-     * @throws EE_Error
924
-     */
925
-    private static function _register_payment_methods($addon_name)
926
-    {
927
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
928
-            EE_Register_Payment_Method::register(
929
-                $addon_name,
930
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
931
-            );
932
-        }
933
-    }
916
+	/**
917
+	 * @param string $addon_name
918
+	 * @return void
919
+	 * @throws InvalidArgumentException
920
+	 * @throws InvalidInterfaceException
921
+	 * @throws InvalidDataTypeException
922
+	 * @throws DomainException
923
+	 * @throws EE_Error
924
+	 */
925
+	private static function _register_payment_methods($addon_name)
926
+	{
927
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
928
+			EE_Register_Payment_Method::register(
929
+				$addon_name,
930
+				array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
931
+			);
932
+		}
933
+	}
934 934
 
935 935
 
936
-    /**
937
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
938
-     *
939
-     * @param string $addon_name
940
-     * @return EE_Addon
941
-     * @throws InvalidArgumentException
942
-     * @throws InvalidInterfaceException
943
-     * @throws InvalidDataTypeException
944
-     * @throws ReflectionException
945
-     * @throws EE_Error
946
-     */
947
-    private static function _load_and_init_addon_class($addon_name)
948
-    {
949
-        $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
950
-        $addon = $loader->getShared(
951
-            self::$_settings[ $addon_name ]['class_name'],
952
-            array('EE_Registry::create(addon)' => true)
953
-        );
954
-        // setter inject dep map if required
955
-        if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){
956
-            $addon->setDependencyMap($loader->getShared('EE_Dependency_Map'));
957
-        }
958
-        // setter inject domain if required
959
-        if(
960
-            $addon instanceof RequiresDomainInterface
961
-            && self::$_settings[ $addon_name ]['domain_fqcn'] !== ''
962
-            && $addon->domain() === null
963
-        ){
964
-            $addon->setDomain(
965
-                $loader->getShared(
966
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
967
-                    array(
968
-                        self::$_settings[ $addon_name ]['main_file_path'],
969
-                        self::$_settings[ $addon_name ]['version']
970
-                    )
971
-                )
972
-            );
973
-        }
936
+	/**
937
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
938
+	 *
939
+	 * @param string $addon_name
940
+	 * @return EE_Addon
941
+	 * @throws InvalidArgumentException
942
+	 * @throws InvalidInterfaceException
943
+	 * @throws InvalidDataTypeException
944
+	 * @throws ReflectionException
945
+	 * @throws EE_Error
946
+	 */
947
+	private static function _load_and_init_addon_class($addon_name)
948
+	{
949
+		$loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
950
+		$addon = $loader->getShared(
951
+			self::$_settings[ $addon_name ]['class_name'],
952
+			array('EE_Registry::create(addon)' => true)
953
+		);
954
+		// setter inject dep map if required
955
+		if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){
956
+			$addon->setDependencyMap($loader->getShared('EE_Dependency_Map'));
957
+		}
958
+		// setter inject domain if required
959
+		if(
960
+			$addon instanceof RequiresDomainInterface
961
+			&& self::$_settings[ $addon_name ]['domain_fqcn'] !== ''
962
+			&& $addon->domain() === null
963
+		){
964
+			$addon->setDomain(
965
+				$loader->getShared(
966
+					self::$_settings[ $addon_name ]['domain_fqcn'],
967
+					array(
968
+						self::$_settings[ $addon_name ]['main_file_path'],
969
+						self::$_settings[ $addon_name ]['version']
970
+					)
971
+				)
972
+			);
973
+		}
974 974
 
975
-        $addon->set_name($addon_name);
976
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
977
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
978
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
979
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
980
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
981
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
982
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
983
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
984
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
985
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
986
-        //unfortunately this can't be hooked in upon construction, because we don't have
987
-        //the plugin mainfile's path upon construction.
988
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
989
-        // call any additional admin_callback functions during load_admin_controller hook
990
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
991
-            add_action(
992
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
993
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
994
-            );
995
-        }
996
-        return $addon;
997
-    }
975
+		$addon->set_name($addon_name);
976
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
977
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
978
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
979
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
980
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
981
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
982
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
983
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
984
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
985
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
986
+		//unfortunately this can't be hooked in upon construction, because we don't have
987
+		//the plugin mainfile's path upon construction.
988
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
989
+		// call any additional admin_callback functions during load_admin_controller hook
990
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
991
+			add_action(
992
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
993
+				array($addon, self::$_settings[ $addon_name ]['admin_callback'])
994
+			);
995
+		}
996
+		return $addon;
997
+	}
998 998
 
999 999
 
1000
-    /**
1001
-     *    load_pue_update - Update notifications
1002
-     *
1003
-     * @return void
1004
-     * @throws InvalidArgumentException
1005
-     * @throws InvalidDataTypeException
1006
-     * @throws InvalidInterfaceException
1007
-     */
1008
-    public static function load_pue_update()
1009
-    {
1010
-        // load PUE client
1011
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
1012
-        // cycle thru settings
1013
-        foreach (self::$_settings as $settings) {
1014
-            if (! empty($settings['pue_options'])) {
1015
-                // initiate the class and start the plugin update engine!
1016
-                new PluginUpdateEngineChecker(
1017
-                // host file URL
1018
-                    'https://eventespresso.com',
1019
-                    // plugin slug(s)
1020
-                    array(
1021
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1022
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1023
-                    ),
1024
-                    // options
1025
-                    array(
1026
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1027
-                        'lang_domain'       => 'event_espresso',
1028
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1029
-                        'option_key'        => 'site_license_key',
1030
-                        'options_page_slug' => 'event_espresso',
1031
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1032
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1033
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1034
-                    )
1035
-                );
1036
-            }
1037
-        }
1038
-    }
1000
+	/**
1001
+	 *    load_pue_update - Update notifications
1002
+	 *
1003
+	 * @return void
1004
+	 * @throws InvalidArgumentException
1005
+	 * @throws InvalidDataTypeException
1006
+	 * @throws InvalidInterfaceException
1007
+	 */
1008
+	public static function load_pue_update()
1009
+	{
1010
+		// load PUE client
1011
+		require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
1012
+		// cycle thru settings
1013
+		foreach (self::$_settings as $settings) {
1014
+			if (! empty($settings['pue_options'])) {
1015
+				// initiate the class and start the plugin update engine!
1016
+				new PluginUpdateEngineChecker(
1017
+				// host file URL
1018
+					'https://eventespresso.com',
1019
+					// plugin slug(s)
1020
+					array(
1021
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1022
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1023
+					),
1024
+					// options
1025
+					array(
1026
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1027
+						'lang_domain'       => 'event_espresso',
1028
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1029
+						'option_key'        => 'site_license_key',
1030
+						'options_page_slug' => 'event_espresso',
1031
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1032
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1033
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1034
+					)
1035
+				);
1036
+			}
1037
+		}
1038
+	}
1039 1039
 
1040 1040
 
1041
-    /**
1042
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1043
-     *
1044
-     * @since 4.4.0
1045
-     * @return void
1046
-     * @throws EE_Error
1047
-     */
1048
-    public static function register_message_types()
1049
-    {
1050
-        foreach (self::$_settings as $addon_name => $settings) {
1051
-            if (! empty($settings['message_types'])) {
1052
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1053
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1054
-                }
1055
-            }
1056
-        }
1057
-    }
1041
+	/**
1042
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1043
+	 *
1044
+	 * @since 4.4.0
1045
+	 * @return void
1046
+	 * @throws EE_Error
1047
+	 */
1048
+	public static function register_message_types()
1049
+	{
1050
+		foreach (self::$_settings as $addon_name => $settings) {
1051
+			if (! empty($settings['message_types'])) {
1052
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1053
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1054
+				}
1055
+			}
1056
+		}
1057
+	}
1058 1058
 
1059 1059
 
1060
-    /**
1061
-     * This deregisters an addon that was previously registered with a specific addon_name.
1062
-     *
1063
-     * @since    4.3.0
1064
-     * @param string $addon_name the name for the addon that was previously registered
1065
-     * @throws DomainException
1066
-     * @throws EE_Error
1067
-     * @throws InvalidArgumentException
1068
-     * @throws InvalidDataTypeException
1069
-     * @throws InvalidInterfaceException
1070
-     */
1071
-    public static function deregister($addon_name = null)
1072
-    {
1073
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1074
-            do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1075
-            $class_name = self::$_settings[ $addon_name ]['class_name'];
1076
-            if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1077
-                // setup DMS
1078
-                EE_Register_Data_Migration_Scripts::deregister($addon_name);
1079
-            }
1080
-            if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1081
-                // register admin page
1082
-                EE_Register_Admin_Page::deregister($addon_name);
1083
-            }
1084
-            if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1085
-                // add to list of modules to be registered
1086
-                EE_Register_Module::deregister($addon_name);
1087
-            }
1088
-            if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1089
-                || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1090
-            ) {
1091
-                // add to list of shortcodes to be registered
1092
-                EE_Register_Shortcode::deregister($addon_name);
1093
-            }
1094
-            if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1095
-                // if config_class present let's register config.
1096
-                EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1097
-            }
1098
-            if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1099
-                // add to list of widgets to be registered
1100
-                EE_Register_Widget::deregister($addon_name);
1101
-            }
1102
-            if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1103
-                || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1104
-            ) {
1105
-                // add to list of shortcodes to be registered
1106
-                EE_Register_Model::deregister($addon_name);
1107
-            }
1108
-            if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1109
-                || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1110
-            ) {
1111
-                // add to list of shortcodes to be registered
1112
-                EE_Register_Model_Extensions::deregister($addon_name);
1113
-            }
1114
-            if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1115
-                foreach (
1116
-                    (array) self::$_settings[ $addon_name ]['message_types'] as $message_type =>
1117
-                    $message_type_settings
1118
-                ) {
1119
-                    EE_Register_Message_Type::deregister($message_type);
1120
-                }
1121
-            }
1122
-            //deregister capabilities for addon
1123
-            if (
1124
-                ! empty(self::$_settings[ $addon_name ]['capabilities'])
1125
-                || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1126
-            ) {
1127
-                EE_Register_Capabilities::deregister($addon_name);
1128
-            }
1129
-            //deregister custom_post_types for addon
1130
-            if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1131
-                EE_Register_CPT::deregister($addon_name);
1132
-            }
1133
-            if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1134
-                EE_Register_Payment_Method::deregister($addon_name);
1135
-            }
1136
-            $addon = EE_Registry::instance()->getAddon($class_name);
1137
-            if ($addon instanceof EE_Addon) {
1138
-                remove_action(
1139
-                    'deactivate_' . $addon->get_main_plugin_file_basename(),
1140
-                    array($addon, 'deactivation')
1141
-                );
1142
-                remove_action(
1143
-                    'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1144
-                    array($addon, 'initialize_db_if_no_migrations_required')
1145
-                );
1146
-                //remove `after_registration` call
1147
-                remove_action(
1148
-                    'AHEE__EE_System__load_espresso_addons__complete',
1149
-                    array($addon, 'after_registration'),
1150
-                    999
1151
-                );
1152
-            }
1153
-            EE_Registry::instance()->removeAddon($class_name);
1154
-            unset(self::$_settings[ $addon_name ]);
1155
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1156
-        }
1157
-    }
1060
+	/**
1061
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1062
+	 *
1063
+	 * @since    4.3.0
1064
+	 * @param string $addon_name the name for the addon that was previously registered
1065
+	 * @throws DomainException
1066
+	 * @throws EE_Error
1067
+	 * @throws InvalidArgumentException
1068
+	 * @throws InvalidDataTypeException
1069
+	 * @throws InvalidInterfaceException
1070
+	 */
1071
+	public static function deregister($addon_name = null)
1072
+	{
1073
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1074
+			do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1075
+			$class_name = self::$_settings[ $addon_name ]['class_name'];
1076
+			if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1077
+				// setup DMS
1078
+				EE_Register_Data_Migration_Scripts::deregister($addon_name);
1079
+			}
1080
+			if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1081
+				// register admin page
1082
+				EE_Register_Admin_Page::deregister($addon_name);
1083
+			}
1084
+			if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1085
+				// add to list of modules to be registered
1086
+				EE_Register_Module::deregister($addon_name);
1087
+			}
1088
+			if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1089
+				|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1090
+			) {
1091
+				// add to list of shortcodes to be registered
1092
+				EE_Register_Shortcode::deregister($addon_name);
1093
+			}
1094
+			if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1095
+				// if config_class present let's register config.
1096
+				EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1097
+			}
1098
+			if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1099
+				// add to list of widgets to be registered
1100
+				EE_Register_Widget::deregister($addon_name);
1101
+			}
1102
+			if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1103
+				|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1104
+			) {
1105
+				// add to list of shortcodes to be registered
1106
+				EE_Register_Model::deregister($addon_name);
1107
+			}
1108
+			if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1109
+				|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1110
+			) {
1111
+				// add to list of shortcodes to be registered
1112
+				EE_Register_Model_Extensions::deregister($addon_name);
1113
+			}
1114
+			if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1115
+				foreach (
1116
+					(array) self::$_settings[ $addon_name ]['message_types'] as $message_type =>
1117
+					$message_type_settings
1118
+				) {
1119
+					EE_Register_Message_Type::deregister($message_type);
1120
+				}
1121
+			}
1122
+			//deregister capabilities for addon
1123
+			if (
1124
+				! empty(self::$_settings[ $addon_name ]['capabilities'])
1125
+				|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1126
+			) {
1127
+				EE_Register_Capabilities::deregister($addon_name);
1128
+			}
1129
+			//deregister custom_post_types for addon
1130
+			if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1131
+				EE_Register_CPT::deregister($addon_name);
1132
+			}
1133
+			if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1134
+				EE_Register_Payment_Method::deregister($addon_name);
1135
+			}
1136
+			$addon = EE_Registry::instance()->getAddon($class_name);
1137
+			if ($addon instanceof EE_Addon) {
1138
+				remove_action(
1139
+					'deactivate_' . $addon->get_main_plugin_file_basename(),
1140
+					array($addon, 'deactivation')
1141
+				);
1142
+				remove_action(
1143
+					'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1144
+					array($addon, 'initialize_db_if_no_migrations_required')
1145
+				);
1146
+				//remove `after_registration` call
1147
+				remove_action(
1148
+					'AHEE__EE_System__load_espresso_addons__complete',
1149
+					array($addon, 'after_registration'),
1150
+					999
1151
+				);
1152
+			}
1153
+			EE_Registry::instance()->removeAddon($class_name);
1154
+			unset(self::$_settings[ $addon_name ]);
1155
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1156
+		}
1157
+	}
1158 1158
 
1159 1159
 
1160 1160
 }
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
         // offsets:    0 . 1 . 2 . 3 . 4
72 72
         $version_parts = explode('.', $min_core_version);
73 73
         //check they specified the micro version (after 2nd period)
74
-        if (! isset($version_parts[2])) {
74
+        if ( ! isset($version_parts[2])) {
75 75
             $version_parts[2] = '0';
76 76
         }
77 77
         //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
78 78
         //soon we can assume that's 'rc', but this current version is 'alpha'
79
-        if (! isset($version_parts[3])) {
79
+        if ( ! isset($version_parts[3])) {
80 80
             $version_parts[3] = 'dev';
81 81
         }
82
-        if (! isset($version_parts[4])) {
82
+        if ( ! isset($version_parts[4])) {
83 83
             $version_parts[4] = '000';
84 84
         }
85 85
         return implode('.', $version_parts);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         // setup PUE
251 251
         EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
252 252
         // does this addon work with this version of core or WordPress ?
253
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
253
+        if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
254 254
             return;
255 255
         }
256 256
         // register namespaces
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
                 )
309 309
             );
310 310
         }
311
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
311
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
312 312
             throw new EE_Error(
313 313
                 sprintf(
314 314
                     __(
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
             );
321 321
         }
322 322
         // check that addon has not already been registered with that name
323
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
323
+        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
324 324
             throw new EE_Error(
325 325
                 sprintf(
326 326
                     __(
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
         // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
353 353
         return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
354 354
             ? $class_name
355
-            : 'EE_' . $class_name;
355
+            : 'EE_'.$class_name;
356 356
     }
357 357
 
358 358
 
@@ -511,9 +511,9 @@  discard block
 block discarded – undo
511 511
         $incompatibility_message = '';
512 512
         //check whether this addon version is compatible with EE core
513 513
         if (
514
-            isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
514
+            isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
515 515
             && ! self::_meets_min_core_version_requirement(
516
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
516
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
517 517
                 $addon_settings['version']
518 518
             )
519 519
         ) {
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
                 ),
524 524
                 $addon_name,
525 525
                 '<br />',
526
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
526
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
527 527
                 '<span style="font-weight: bold; color: #D54E21;">',
528 528
                 '</span><br />'
529 529
             );
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
                 '</span><br />'
556 556
             );
557 557
         }
558
-        if (! empty($incompatibility_message)) {
558
+        if ( ! empty($incompatibility_message)) {
559 559
             // remove 'activate' from the REQUEST
560 560
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
561 561
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -583,11 +583,11 @@  discard block
 block discarded – undo
583 583
      */
584 584
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
585 585
     {
586
-        if (! empty($setup_args['pue_options'])) {
587
-            self::$_settings[ $addon_name ]['pue_options'] = array(
586
+        if ( ! empty($setup_args['pue_options'])) {
587
+            self::$_settings[$addon_name]['pue_options'] = array(
588 588
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
589 589
                     ? (string) $setup_args['pue_options']['pue_plugin_slug']
590
-                    : 'espresso_' . strtolower($class_name),
590
+                    : 'espresso_'.strtolower($class_name),
591 591
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
592 592
                     ? (string) $setup_args['pue_options']['plugin_basename']
593 593
                     : plugin_basename($setup_args['main_file_path']),
@@ -647,12 +647,12 @@  discard block
 block discarded – undo
647 647
             //(as the newly-activated addon wasn't around the first time addons were registered).
648 648
             //Note: the presence of pue_options in the addon registration options will initialize the $_settings
649 649
             //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
650
-            if (! isset(self::$_settings[ $addon_name ])
651
-                || (isset(self::$_settings[ $addon_name ])
652
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
650
+            if ( ! isset(self::$_settings[$addon_name])
651
+                || (isset(self::$_settings[$addon_name])
652
+                    && ! isset(self::$_settings[$addon_name]['class_name'])
653 653
                 )
654 654
             ) {
655
-                self::$_settings[ $addon_name ] = $addon_settings;
655
+                self::$_settings[$addon_name] = $addon_settings;
656 656
                 $addon                          = self::_load_and_init_addon_class($addon_name);
657 657
                 $addon->set_activation_indicator_option();
658 658
                 // dont bother setting up the rest of the addon.
@@ -678,10 +678,10 @@  discard block
 block discarded – undo
678 678
             );
679 679
         }
680 680
         // make sure addon settings are set correctly without overwriting anything existing
681
-        if (isset(self::$_settings[ $addon_name ])) {
682
-            self::$_settings[ $addon_name ] += $addon_settings;
681
+        if (isset(self::$_settings[$addon_name])) {
682
+            self::$_settings[$addon_name] += $addon_settings;
683 683
         } else {
684
-            self::$_settings[ $addon_name ] = $addon_settings;
684
+            self::$_settings[$addon_name] = $addon_settings;
685 685
         }
686 686
         return false;
687 687
     }
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
      */
695 695
     private static function _setup_autoloaders($addon_name)
696 696
     {
697
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
697
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
698 698
             // setup autoloader for single file
699
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
699
+            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
700 700
         }
701 701
         // setup autoloaders for folders
702
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
703
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
702
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
703
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
704 704
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
705 705
             }
706 706
         }
@@ -718,27 +718,27 @@  discard block
 block discarded – undo
718 718
     {
719 719
         // register new models
720 720
         if (
721
-            ! empty(self::$_settings[ $addon_name ]['model_paths'])
722
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
721
+            ! empty(self::$_settings[$addon_name]['model_paths'])
722
+            || ! empty(self::$_settings[$addon_name]['class_paths'])
723 723
         ) {
724 724
             EE_Register_Model::register(
725 725
                 $addon_name,
726 726
                 array(
727
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
728
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
727
+                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
728
+                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
729 729
                 )
730 730
             );
731 731
         }
732 732
         // register model extensions
733 733
         if (
734
-            ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
735
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
734
+            ! empty(self::$_settings[$addon_name]['model_extension_paths'])
735
+            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
736 736
         ) {
737 737
             EE_Register_Model_Extensions::register(
738 738
                 $addon_name,
739 739
                 array(
740
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
741
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
740
+                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
741
+                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
742 742
                 )
743 743
             );
744 744
         }
@@ -753,10 +753,10 @@  discard block
 block discarded – undo
753 753
     private static function _register_data_migration_scripts($addon_name)
754 754
     {
755 755
         // setup DMS
756
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
756
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
757 757
             EE_Register_Data_Migration_Scripts::register(
758 758
                 $addon_name,
759
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
759
+                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
760 760
             );
761 761
         }
762 762
     }
@@ -770,12 +770,12 @@  discard block
 block discarded – undo
770 770
     private static function _register_config($addon_name)
771 771
     {
772 772
         // if config_class is present let's register config.
773
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
773
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
774 774
             EE_Register_Config::register(
775
-                self::$_settings[ $addon_name ]['config_class'],
775
+                self::$_settings[$addon_name]['config_class'],
776 776
                 array(
777
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
778
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
777
+                    'config_section' => self::$_settings[$addon_name]['config_section'],
778
+                    'config_name'    => self::$_settings[$addon_name]['config_name'],
779 779
                 )
780 780
             );
781 781
         }
@@ -789,10 +789,10 @@  discard block
 block discarded – undo
789 789
      */
790 790
     private static function _register_admin_pages($addon_name)
791 791
     {
792
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
792
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
793 793
             EE_Register_Admin_Page::register(
794 794
                 $addon_name,
795
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
795
+                array('page_path' => self::$_settings[$addon_name]['admin_path'])
796 796
             );
797 797
         }
798 798
     }
@@ -805,10 +805,10 @@  discard block
 block discarded – undo
805 805
      */
806 806
     private static function _register_modules($addon_name)
807 807
     {
808
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
808
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
809 809
             EE_Register_Module::register(
810 810
                 $addon_name,
811
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
811
+                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
812 812
             );
813 813
         }
814 814
     }
@@ -821,17 +821,17 @@  discard block
 block discarded – undo
821 821
      */
822 822
     private static function _register_shortcodes($addon_name)
823 823
     {
824
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
825
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
824
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
825
+            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
826 826
         ) {
827 827
             EE_Register_Shortcode::register(
828 828
                 $addon_name,
829 829
                 array(
830
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
831
-                        ? self::$_settings[ $addon_name ]['shortcode_paths']
830
+                    'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
831
+                        ? self::$_settings[$addon_name]['shortcode_paths']
832 832
                         : array(),
833
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
834
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns']
833
+                    'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
834
+                        ? self::$_settings[$addon_name]['shortcode_fqcns']
835 835
                         : array(),
836 836
                 )
837 837
             );
@@ -846,10 +846,10 @@  discard block
 block discarded – undo
846 846
      */
847 847
     private static function _register_widgets($addon_name)
848 848
     {
849
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
849
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
850 850
             EE_Register_Widget::register(
851 851
                 $addon_name,
852
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
852
+                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
853 853
             );
854 854
         }
855 855
     }
@@ -862,12 +862,12 @@  discard block
 block discarded – undo
862 862
      */
863 863
     private static function _register_capabilities($addon_name)
864 864
     {
865
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
865
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
866 866
             EE_Register_Capabilities::register(
867 867
                 $addon_name,
868 868
                 array(
869
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
870
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
869
+                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
870
+                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
871 871
                 )
872 872
             );
873 873
         }
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
      */
882 882
     private static function _register_message_types($addon_name)
883 883
     {
884
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
884
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
885 885
             add_action(
886 886
                 'EE_Brewing_Regular___messages_caf',
887 887
                 array('EE_Register_Addon', 'register_message_types')
@@ -898,15 +898,15 @@  discard block
 block discarded – undo
898 898
     private static function _register_custom_post_types($addon_name)
899 899
     {
900 900
         if (
901
-            ! empty(self::$_settings[ $addon_name ]['custom_post_types'])
902
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
901
+            ! empty(self::$_settings[$addon_name]['custom_post_types'])
902
+            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
903 903
         ) {
904 904
             EE_Register_CPT::register(
905 905
                 $addon_name,
906 906
                 array(
907
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
908
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
909
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
907
+                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
908
+                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
909
+                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
910 910
                 )
911 911
             );
912 912
         }
@@ -924,10 +924,10 @@  discard block
 block discarded – undo
924 924
      */
925 925
     private static function _register_payment_methods($addon_name)
926 926
     {
927
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
927
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
928 928
             EE_Register_Payment_Method::register(
929 929
                 $addon_name,
930
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
930
+                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
931 931
             );
932 932
         }
933 933
     }
@@ -948,49 +948,49 @@  discard block
 block discarded – undo
948 948
     {
949 949
         $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader();
950 950
         $addon = $loader->getShared(
951
-            self::$_settings[ $addon_name ]['class_name'],
951
+            self::$_settings[$addon_name]['class_name'],
952 952
             array('EE_Registry::create(addon)' => true)
953 953
         );
954 954
         // setter inject dep map if required
955
-        if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){
955
+        if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) {
956 956
             $addon->setDependencyMap($loader->getShared('EE_Dependency_Map'));
957 957
         }
958 958
         // setter inject domain if required
959
-        if(
959
+        if (
960 960
             $addon instanceof RequiresDomainInterface
961
-            && self::$_settings[ $addon_name ]['domain_fqcn'] !== ''
961
+            && self::$_settings[$addon_name]['domain_fqcn'] !== ''
962 962
             && $addon->domain() === null
963
-        ){
963
+        ) {
964 964
             $addon->setDomain(
965 965
                 $loader->getShared(
966
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
966
+                    self::$_settings[$addon_name]['domain_fqcn'],
967 967
                     array(
968
-                        self::$_settings[ $addon_name ]['main_file_path'],
969
-                        self::$_settings[ $addon_name ]['version']
968
+                        self::$_settings[$addon_name]['main_file_path'],
969
+                        self::$_settings[$addon_name]['version']
970 970
                     )
971 971
                 )
972 972
             );
973 973
         }
974 974
 
975 975
         $addon->set_name($addon_name);
976
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
977
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
978
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
979
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
980
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
981
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
982
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
983
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
984
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
985
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
976
+        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
977
+        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
978
+        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
979
+        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
980
+        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
981
+        $addon->set_version(self::$_settings[$addon_name]['version']);
982
+        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
983
+        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
984
+        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
985
+        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
986 986
         //unfortunately this can't be hooked in upon construction, because we don't have
987 987
         //the plugin mainfile's path upon construction.
988 988
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
989 989
         // call any additional admin_callback functions during load_admin_controller hook
990
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
990
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
991 991
             add_action(
992 992
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
993
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
993
+                array($addon, self::$_settings[$addon_name]['admin_callback'])
994 994
             );
995 995
         }
996 996
         return $addon;
@@ -1008,10 +1008,10 @@  discard block
 block discarded – undo
1008 1008
     public static function load_pue_update()
1009 1009
     {
1010 1010
         // load PUE client
1011
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
1011
+        require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php';
1012 1012
         // cycle thru settings
1013 1013
         foreach (self::$_settings as $settings) {
1014
-            if (! empty($settings['pue_options'])) {
1014
+            if ( ! empty($settings['pue_options'])) {
1015 1015
                 // initiate the class and start the plugin update engine!
1016 1016
                 new PluginUpdateEngineChecker(
1017 1017
                 // host file URL
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
                     // plugin slug(s)
1020 1020
                     array(
1021 1021
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1022
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1022
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
1023 1023
                     ),
1024 1024
                     // options
1025 1025
                     array(
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
     public static function register_message_types()
1049 1049
     {
1050 1050
         foreach (self::$_settings as $addon_name => $settings) {
1051
-            if (! empty($settings['message_types'])) {
1051
+            if ( ! empty($settings['message_types'])) {
1052 1052
                 foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1053 1053
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
1054 1054
                 }
@@ -1070,50 +1070,50 @@  discard block
 block discarded – undo
1070 1070
      */
1071 1071
     public static function deregister($addon_name = null)
1072 1072
     {
1073
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1073
+        if (isset(self::$_settings[$addon_name]['class_name'])) {
1074 1074
             do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1075
-            $class_name = self::$_settings[ $addon_name ]['class_name'];
1076
-            if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1075
+            $class_name = self::$_settings[$addon_name]['class_name'];
1076
+            if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1077 1077
                 // setup DMS
1078 1078
                 EE_Register_Data_Migration_Scripts::deregister($addon_name);
1079 1079
             }
1080
-            if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1080
+            if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1081 1081
                 // register admin page
1082 1082
                 EE_Register_Admin_Page::deregister($addon_name);
1083 1083
             }
1084
-            if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1084
+            if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1085 1085
                 // add to list of modules to be registered
1086 1086
                 EE_Register_Module::deregister($addon_name);
1087 1087
             }
1088
-            if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1089
-                || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1088
+            if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1089
+                || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1090 1090
             ) {
1091 1091
                 // add to list of shortcodes to be registered
1092 1092
                 EE_Register_Shortcode::deregister($addon_name);
1093 1093
             }
1094
-            if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1094
+            if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1095 1095
                 // if config_class present let's register config.
1096
-                EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1096
+                EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1097 1097
             }
1098
-            if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1098
+            if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1099 1099
                 // add to list of widgets to be registered
1100 1100
                 EE_Register_Widget::deregister($addon_name);
1101 1101
             }
1102
-            if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1103
-                || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1102
+            if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1103
+                || ! empty(self::$_settings[$addon_name]['class_paths'])
1104 1104
             ) {
1105 1105
                 // add to list of shortcodes to be registered
1106 1106
                 EE_Register_Model::deregister($addon_name);
1107 1107
             }
1108
-            if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1109
-                || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1108
+            if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1109
+                || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1110 1110
             ) {
1111 1111
                 // add to list of shortcodes to be registered
1112 1112
                 EE_Register_Model_Extensions::deregister($addon_name);
1113 1113
             }
1114
-            if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1114
+            if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1115 1115
                 foreach (
1116
-                    (array) self::$_settings[ $addon_name ]['message_types'] as $message_type =>
1116
+                    (array) self::$_settings[$addon_name]['message_types'] as $message_type =>
1117 1117
                     $message_type_settings
1118 1118
                 ) {
1119 1119
                     EE_Register_Message_Type::deregister($message_type);
@@ -1121,22 +1121,22 @@  discard block
 block discarded – undo
1121 1121
             }
1122 1122
             //deregister capabilities for addon
1123 1123
             if (
1124
-                ! empty(self::$_settings[ $addon_name ]['capabilities'])
1125
-                || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1124
+                ! empty(self::$_settings[$addon_name]['capabilities'])
1125
+                || ! empty(self::$_settings[$addon_name]['capability_maps'])
1126 1126
             ) {
1127 1127
                 EE_Register_Capabilities::deregister($addon_name);
1128 1128
             }
1129 1129
             //deregister custom_post_types for addon
1130
-            if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1130
+            if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1131 1131
                 EE_Register_CPT::deregister($addon_name);
1132 1132
             }
1133
-            if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1133
+            if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1134 1134
                 EE_Register_Payment_Method::deregister($addon_name);
1135 1135
             }
1136 1136
             $addon = EE_Registry::instance()->getAddon($class_name);
1137 1137
             if ($addon instanceof EE_Addon) {
1138 1138
                 remove_action(
1139
-                    'deactivate_' . $addon->get_main_plugin_file_basename(),
1139
+                    'deactivate_'.$addon->get_main_plugin_file_basename(),
1140 1140
                     array($addon, 'deactivation')
1141 1141
                 );
1142 1142
                 remove_action(
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
                 );
1152 1152
             }
1153 1153
             EE_Registry::instance()->removeAddon($class_name);
1154
-            unset(self::$_settings[ $addon_name ]);
1154
+            unset(self::$_settings[$addon_name]);
1155 1155
             do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1156 1156
         }
1157 1157
     }
Please login to merge, or discard this patch.
core/domain/RequiresDomainInterface.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,16 +18,16 @@
 block discarded – undo
18 18
 interface RequiresDomainInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @param DomainInterface $domain
23
-     */
24
-    public function setDomain(DomainInterface $domain);
21
+	/**
22
+	 * @param DomainInterface $domain
23
+	 */
24
+	public function setDomain(DomainInterface $domain);
25 25
 
26 26
 
27
-    /**
28
-     * @return DomainInterface
29
-     */
30
-    public function domain();
27
+	/**
28
+	 * @return DomainInterface
29
+	 */
30
+	public function domain();
31 31
 
32 32
 }
33 33
 // Location: RequiresDomainInterface.php
Please login to merge, or discard this patch.
core/EE_Session.core.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      *
485 485
      * @access    public
486 486
      * @param    array $data
487
-     * @return    TRUE on success, FALSE on fail
487
+     * @return    boolean on success, FALSE on fail
488 488
      */
489 489
     public function set_session_data($data)
490 490
     {
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
     /**
512 512
      * @initiate session
513 513
      * @access   private
514
-     * @return TRUE on success, FALSE on fail
514
+     * @return boolean on success, FALSE on fail
515 515
      * @throws EE_Error
516 516
      * @throws InvalidArgumentException
517 517
      * @throws InvalidDataTypeException
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
      * @update session data  prior to saving to the db
747 747
      * @access public
748 748
      * @param bool $new_session
749
-     * @return TRUE on success, FALSE on fail
749
+     * @return boolean on success, FALSE on fail
750 750
      * @throws EE_Error
751 751
      * @throws InvalidArgumentException
752 752
      * @throws InvalidDataTypeException
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
      * _save_session_to_db
848 848
      *
849 849
      * @param bool $clear_session
850
-     * @return string
850
+     * @return boolean
851 851
      * @throws EE_Error
852 852
      * @throws InvalidArgumentException
853 853
      * @throws InvalidDataTypeException
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
      * @access public
1009 1009
      * @param array|mixed $data_to_reset
1010 1010
      * @param bool        $show_all_notices
1011
-     * @return TRUE on success, FALSE on fail
1011
+     * @return boolean on success, FALSE on fail
1012 1012
      */
1013 1013
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1014 1014
     {
Please login to merge, or discard this patch.
Indentation   +1204 added lines, -1204 removed lines patch added patch discarded remove patch
@@ -20,1210 +20,1210 @@  discard block
 block discarded – undo
20 20
 class EE_Session implements SessionIdentifierInterface
21 21
 {
22 22
 
23
-    const session_id_prefix    = 'ee_ssn_';
24
-
25
-    const hash_check_prefix    = 'ee_shc_';
26
-
27
-    const OPTION_NAME_SETTINGS = 'ee_session_settings';
28
-
29
-    /**
30
-     * instance of the EE_Session object
31
-     *
32
-     * @var EE_Session
33
-     */
34
-    private static $_instance;
35
-
36
-    /**
37
-     * @var CacheStorageInterface $cache_storage
38
-     */
39
-    protected $cache_storage;
40
-
41
-    /**
42
-     * EE_Encryption object
43
-     *
44
-     * @var EE_Encryption
45
-     */
46
-    protected $encryption;
47
-
48
-    /**
49
-     * the session id
50
-     *
51
-     * @var string
52
-     */
53
-    private $_sid;
54
-
55
-    /**
56
-     * session id salt
57
-     *
58
-     * @var string
59
-     */
60
-    private $_sid_salt;
61
-
62
-    /**
63
-     * session data
64
-     *
65
-     * @var array
66
-     */
67
-    private $_session_data = array();
68
-
69
-    /**
70
-     * how long an EE session lasts
71
-     * default session lifespan of 2 hours (for not so instant IPNs)
72
-     *
73
-     * @var int
74
-     */
75
-    private $_lifespan;
76
-
77
-    /**
78
-     * session expiration time as Unix timestamp in GMT
79
-     *
80
-     * @var int
81
-     */
82
-    private $_expiration;
83
-
84
-    /**
85
-     * whether or not session has expired at some point
86
-     *
87
-     * @var boolean
88
-     */
89
-    private $_expired = false;
90
-
91
-    /**
92
-     * current time as Unix timestamp in GMT
93
-     *
94
-     * @var int
95
-     */
96
-    private $_time;
97
-
98
-    /**
99
-     * whether to encrypt session data
100
-     *
101
-     * @var bool
102
-     */
103
-    private $_use_encryption;
104
-
105
-    /**
106
-     * well... according to the server...
107
-     *
108
-     * @var null
109
-     */
110
-    private $_user_agent;
111
-
112
-    /**
113
-     * do you really trust the server ?
114
-     *
115
-     * @var null
116
-     */
117
-    private $_ip_address;
118
-
119
-    /**
120
-     * current WP user_id
121
-     *
122
-     * @var null
123
-     */
124
-    private $_wp_user_id;
125
-
126
-    /**
127
-     * array for defining default session vars
128
-     *
129
-     * @var array
130
-     */
131
-    private $_default_session_vars = array(
132
-        'id'            => null,
133
-        'user_id'       => null,
134
-        'ip_address'    => null,
135
-        'user_agent'    => null,
136
-        'init_access'   => null,
137
-        'last_access'   => null,
138
-        'expiration'    => null,
139
-        'pages_visited' => array(),
140
-    );
141
-
142
-    /**
143
-     * timestamp for when last garbage collection cycle was performed
144
-     *
145
-     * @var int $_last_gc
146
-     */
147
-    private $_last_gc;
148
-
149
-
150
-
151
-    /**
152
-     * @singleton method used to instantiate class object
153
-     * @param CacheStorageInterface $cache_storage
154
-     * @param EE_Encryption         $encryption
155
-     * @return EE_Session
156
-     * @throws InvalidArgumentException
157
-     * @throws InvalidDataTypeException
158
-     * @throws InvalidInterfaceException
159
-     */
160
-    public static function instance(
161
-        CacheStorageInterface $cache_storage = null,
162
-        EE_Encryption $encryption = null
163
-    ) {
164
-        // check if class object is instantiated
165
-        // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
166
-        // add_filter( 'FHEE_load_EE_Session', '__return_false' );
167
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
168
-            self::$_instance = new self($cache_storage, $encryption);
169
-        }
170
-        return self::$_instance;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * protected constructor to prevent direct creation
177
-     *
178
-     * @param CacheStorageInterface $cache_storage
179
-     * @param EE_Encryption         $encryption
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     */
184
-    protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null)
185
-    {
186
-
187
-        // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
188
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
189
-            return;
190
-        }
191
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
192
-        if (! defined('ESPRESSO_SESSION')) {
193
-            define('ESPRESSO_SESSION', true);
194
-        }
195
-        // default session lifespan in seconds
196
-        $this->_lifespan = apply_filters(
197
-                               'FHEE__EE_Session__construct___lifespan',
198
-                               60 * MINUTE_IN_SECONDS
199
-                           ) + 1;
200
-        /*
23
+	const session_id_prefix    = 'ee_ssn_';
24
+
25
+	const hash_check_prefix    = 'ee_shc_';
26
+
27
+	const OPTION_NAME_SETTINGS = 'ee_session_settings';
28
+
29
+	/**
30
+	 * instance of the EE_Session object
31
+	 *
32
+	 * @var EE_Session
33
+	 */
34
+	private static $_instance;
35
+
36
+	/**
37
+	 * @var CacheStorageInterface $cache_storage
38
+	 */
39
+	protected $cache_storage;
40
+
41
+	/**
42
+	 * EE_Encryption object
43
+	 *
44
+	 * @var EE_Encryption
45
+	 */
46
+	protected $encryption;
47
+
48
+	/**
49
+	 * the session id
50
+	 *
51
+	 * @var string
52
+	 */
53
+	private $_sid;
54
+
55
+	/**
56
+	 * session id salt
57
+	 *
58
+	 * @var string
59
+	 */
60
+	private $_sid_salt;
61
+
62
+	/**
63
+	 * session data
64
+	 *
65
+	 * @var array
66
+	 */
67
+	private $_session_data = array();
68
+
69
+	/**
70
+	 * how long an EE session lasts
71
+	 * default session lifespan of 2 hours (for not so instant IPNs)
72
+	 *
73
+	 * @var int
74
+	 */
75
+	private $_lifespan;
76
+
77
+	/**
78
+	 * session expiration time as Unix timestamp in GMT
79
+	 *
80
+	 * @var int
81
+	 */
82
+	private $_expiration;
83
+
84
+	/**
85
+	 * whether or not session has expired at some point
86
+	 *
87
+	 * @var boolean
88
+	 */
89
+	private $_expired = false;
90
+
91
+	/**
92
+	 * current time as Unix timestamp in GMT
93
+	 *
94
+	 * @var int
95
+	 */
96
+	private $_time;
97
+
98
+	/**
99
+	 * whether to encrypt session data
100
+	 *
101
+	 * @var bool
102
+	 */
103
+	private $_use_encryption;
104
+
105
+	/**
106
+	 * well... according to the server...
107
+	 *
108
+	 * @var null
109
+	 */
110
+	private $_user_agent;
111
+
112
+	/**
113
+	 * do you really trust the server ?
114
+	 *
115
+	 * @var null
116
+	 */
117
+	private $_ip_address;
118
+
119
+	/**
120
+	 * current WP user_id
121
+	 *
122
+	 * @var null
123
+	 */
124
+	private $_wp_user_id;
125
+
126
+	/**
127
+	 * array for defining default session vars
128
+	 *
129
+	 * @var array
130
+	 */
131
+	private $_default_session_vars = array(
132
+		'id'            => null,
133
+		'user_id'       => null,
134
+		'ip_address'    => null,
135
+		'user_agent'    => null,
136
+		'init_access'   => null,
137
+		'last_access'   => null,
138
+		'expiration'    => null,
139
+		'pages_visited' => array(),
140
+	);
141
+
142
+	/**
143
+	 * timestamp for when last garbage collection cycle was performed
144
+	 *
145
+	 * @var int $_last_gc
146
+	 */
147
+	private $_last_gc;
148
+
149
+
150
+
151
+	/**
152
+	 * @singleton method used to instantiate class object
153
+	 * @param CacheStorageInterface $cache_storage
154
+	 * @param EE_Encryption         $encryption
155
+	 * @return EE_Session
156
+	 * @throws InvalidArgumentException
157
+	 * @throws InvalidDataTypeException
158
+	 * @throws InvalidInterfaceException
159
+	 */
160
+	public static function instance(
161
+		CacheStorageInterface $cache_storage = null,
162
+		EE_Encryption $encryption = null
163
+	) {
164
+		// check if class object is instantiated
165
+		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
166
+		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
167
+		if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
168
+			self::$_instance = new self($cache_storage, $encryption);
169
+		}
170
+		return self::$_instance;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * protected constructor to prevent direct creation
177
+	 *
178
+	 * @param CacheStorageInterface $cache_storage
179
+	 * @param EE_Encryption         $encryption
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 */
184
+	protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null)
185
+	{
186
+
187
+		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
188
+		if (! apply_filters('FHEE_load_EE_Session', true)) {
189
+			return;
190
+		}
191
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
192
+		if (! defined('ESPRESSO_SESSION')) {
193
+			define('ESPRESSO_SESSION', true);
194
+		}
195
+		// default session lifespan in seconds
196
+		$this->_lifespan = apply_filters(
197
+							   'FHEE__EE_Session__construct___lifespan',
198
+							   60 * MINUTE_IN_SECONDS
199
+						   ) + 1;
200
+		/*
201 201
          * do something like the following to adjust the session lifespan:
202 202
          * 		public static function session_lifespan() {
203 203
          * 			return 15 * MINUTE_IN_SECONDS;
204 204
          * 		}
205 205
          */
206
-        // retrieve session options from db
207
-        $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
208
-        if (! empty($session_settings)) {
209
-            // cycle though existing session options
210
-            foreach ($session_settings as $var_name => $session_setting) {
211
-                // set values for class properties
212
-                $var_name          = '_' . $var_name;
213
-                $this->{$var_name} = $session_setting;
214
-            }
215
-        }
216
-        $this->cache_storage = $cache_storage;
217
-        // are we using encryption?
218
-        $this->_use_encryption = $encryption instanceof EE_Encryption
219
-                                 && EE_Registry::instance()->CFG->admin->encode_session_data();
220
-        // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
221
-        // encrypt data via: $this->encryption->encrypt();
222
-        $this->encryption = $encryption;
223
-        // filter hook allows outside functions/classes/plugins to change default empty cart
224
-        $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
225
-        array_merge($this->_default_session_vars, $extra_default_session_vars);
226
-        // apply default session vars
227
-        $this->_set_defaults();
228
-        add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
229
-        // check request for 'clear_session' param
230
-        add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
231
-        // once everything is all said and done,
232
-        add_action('shutdown', array($this, 'update'), 100);
233
-        add_action('shutdown', array($this, 'garbageCollection'), 1000);
234
-        $this->configure_garbage_collection_filters();
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * @return void
241
-     * @throws EE_Error
242
-     * @throws InvalidArgumentException
243
-     * @throws InvalidDataTypeException
244
-     * @throws InvalidInterfaceException
245
-     * @throws InvalidSessionDataException
246
-     */
247
-    public function open_session()
248
-    {
249
-        // check for existing session and retrieve it from db
250
-        if (! $this->_espresso_session()) {
251
-            // or just start a new one
252
-            $this->_create_espresso_session();
253
-        }
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * @return bool
260
-     */
261
-    public function expired()
262
-    {
263
-        return $this->_expired;
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * @return void
270
-     */
271
-    public function reset_expired()
272
-    {
273
-        $this->_expired = false;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return int
279
-     */
280
-    public function expiration()
281
-    {
282
-        return $this->_expiration;
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * @return int
289
-     */
290
-    public function extension()
291
-    {
292
-        return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * @param int $time number of seconds to add to session expiration
299
-     */
300
-    public function extend_expiration($time = 0)
301
-    {
302
-        $time              = $time ? $time : $this->extension();
303
-        $this->_expiration += absint($time);
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * @return int
310
-     */
311
-    public function lifespan()
312
-    {
313
-        return $this->_lifespan;
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * This just sets some defaults for the _session data property
320
-     *
321
-     * @access private
322
-     * @return void
323
-     */
324
-    private function _set_defaults()
325
-    {
326
-        // set some defaults
327
-        foreach ($this->_default_session_vars as $key => $default_var) {
328
-            if (is_array($default_var)) {
329
-                $this->_session_data[ $key ] = array();
330
-            } else {
331
-                $this->_session_data[ $key ] = '';
332
-            }
333
-        }
334
-    }
206
+		// retrieve session options from db
207
+		$session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
208
+		if (! empty($session_settings)) {
209
+			// cycle though existing session options
210
+			foreach ($session_settings as $var_name => $session_setting) {
211
+				// set values for class properties
212
+				$var_name          = '_' . $var_name;
213
+				$this->{$var_name} = $session_setting;
214
+			}
215
+		}
216
+		$this->cache_storage = $cache_storage;
217
+		// are we using encryption?
218
+		$this->_use_encryption = $encryption instanceof EE_Encryption
219
+								 && EE_Registry::instance()->CFG->admin->encode_session_data();
220
+		// \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
221
+		// encrypt data via: $this->encryption->encrypt();
222
+		$this->encryption = $encryption;
223
+		// filter hook allows outside functions/classes/plugins to change default empty cart
224
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
225
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
226
+		// apply default session vars
227
+		$this->_set_defaults();
228
+		add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
229
+		// check request for 'clear_session' param
230
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
231
+		// once everything is all said and done,
232
+		add_action('shutdown', array($this, 'update'), 100);
233
+		add_action('shutdown', array($this, 'garbageCollection'), 1000);
234
+		$this->configure_garbage_collection_filters();
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * @return void
241
+	 * @throws EE_Error
242
+	 * @throws InvalidArgumentException
243
+	 * @throws InvalidDataTypeException
244
+	 * @throws InvalidInterfaceException
245
+	 * @throws InvalidSessionDataException
246
+	 */
247
+	public function open_session()
248
+	{
249
+		// check for existing session and retrieve it from db
250
+		if (! $this->_espresso_session()) {
251
+			// or just start a new one
252
+			$this->_create_espresso_session();
253
+		}
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * @return bool
260
+	 */
261
+	public function expired()
262
+	{
263
+		return $this->_expired;
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * @return void
270
+	 */
271
+	public function reset_expired()
272
+	{
273
+		$this->_expired = false;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return int
279
+	 */
280
+	public function expiration()
281
+	{
282
+		return $this->_expiration;
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * @return int
289
+	 */
290
+	public function extension()
291
+	{
292
+		return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * @param int $time number of seconds to add to session expiration
299
+	 */
300
+	public function extend_expiration($time = 0)
301
+	{
302
+		$time              = $time ? $time : $this->extension();
303
+		$this->_expiration += absint($time);
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * @return int
310
+	 */
311
+	public function lifespan()
312
+	{
313
+		return $this->_lifespan;
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * This just sets some defaults for the _session data property
320
+	 *
321
+	 * @access private
322
+	 * @return void
323
+	 */
324
+	private function _set_defaults()
325
+	{
326
+		// set some defaults
327
+		foreach ($this->_default_session_vars as $key => $default_var) {
328
+			if (is_array($default_var)) {
329
+				$this->_session_data[ $key ] = array();
330
+			} else {
331
+				$this->_session_data[ $key ] = '';
332
+			}
333
+		}
334
+	}
335 335
 
336 336
 
337
-
338
-    /**
339
-     * @retrieve  session data
340
-     * @access    public
341
-     * @return    string
342
-     */
343
-    public function id()
344
-    {
345
-        return $this->_sid;
346
-    }
337
+
338
+	/**
339
+	 * @retrieve  session data
340
+	 * @access    public
341
+	 * @return    string
342
+	 */
343
+	public function id()
344
+	{
345
+		return $this->_sid;
346
+	}
347 347
 
348 348
 
349 349
 
350
-    /**
351
-     * @param \EE_Cart $cart
352
-     * @return bool
353
-     */
354
-    public function set_cart(EE_Cart $cart)
355
-    {
356
-        $this->_session_data['cart'] = $cart;
357
-        return true;
358
-    }
350
+	/**
351
+	 * @param \EE_Cart $cart
352
+	 * @return bool
353
+	 */
354
+	public function set_cart(EE_Cart $cart)
355
+	{
356
+		$this->_session_data['cart'] = $cart;
357
+		return true;
358
+	}
359 359
 
360 360
 
361 361
 
362
-    /**
363
-     * reset_cart
364
-     */
365
-    public function reset_cart()
366
-    {
367
-        do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
368
-        $this->_session_data['cart'] = null;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @return \EE_Cart
375
-     */
376
-    public function cart()
377
-    {
378
-        return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
379
-            ? $this->_session_data['cart']
380
-            : null;
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * @param \EE_Checkout $checkout
387
-     * @return bool
388
-     */
389
-    public function set_checkout(EE_Checkout $checkout)
390
-    {
391
-        $this->_session_data['checkout'] = $checkout;
392
-        return true;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * reset_checkout
399
-     */
400
-    public function reset_checkout()
401
-    {
402
-        do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
403
-        $this->_session_data['checkout'] = null;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * @return \EE_Checkout
410
-     */
411
-    public function checkout()
412
-    {
413
-        return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
414
-            ? $this->_session_data['checkout']
415
-            : null;
416
-    }
417
-
418
-
419
-
420
-    /**
421
-     * @param \EE_Transaction $transaction
422
-     * @return bool
423
-     * @throws EE_Error
424
-     */
425
-    public function set_transaction(EE_Transaction $transaction)
426
-    {
427
-        // first remove the session from the transaction before we save the transaction in the session
428
-        $transaction->set_txn_session_data(null);
429
-        $this->_session_data['transaction'] = $transaction;
430
-        return true;
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * reset_transaction
437
-     */
438
-    public function reset_transaction()
439
-    {
440
-        do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
441
-        $this->_session_data['transaction'] = null;
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * @return \EE_Transaction
448
-     */
449
-    public function transaction()
450
-    {
451
-        return isset($this->_session_data['transaction'])
452
-               && $this->_session_data['transaction'] instanceof EE_Transaction
453
-            ? $this->_session_data['transaction']
454
-            : null;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * retrieve session data
461
-     *
462
-     * @access    public
463
-     * @param null $key
464
-     * @param bool $reset_cache
465
-     * @return    array
466
-     */
467
-    public function get_session_data($key = null, $reset_cache = false)
468
-    {
469
-        if ($reset_cache) {
470
-            $this->reset_cart();
471
-            $this->reset_checkout();
472
-            $this->reset_transaction();
473
-        }
474
-        if (! empty($key)) {
475
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
476
-        }
477
-        return $this->_session_data;
478
-    }
479
-
480
-
481
-
482
-    /**
483
-     * set session data
484
-     *
485
-     * @access    public
486
-     * @param    array $data
487
-     * @return    TRUE on success, FALSE on fail
488
-     */
489
-    public function set_session_data($data)
490
-    {
491
-
492
-        // nothing ??? bad data ??? go home!
493
-        if (empty($data) || ! is_array($data)) {
494
-            EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__,
495
-                __FUNCTION__, __LINE__);
496
-            return false;
497
-        }
498
-        foreach ($data as $key => $value) {
499
-            if (isset($this->_default_session_vars[ $key ])) {
500
-                EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
501
-                    'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
502
-                return false;
503
-            }
504
-            $this->_session_data[ $key ] = $value;
505
-        }
506
-        return true;
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * @initiate session
513
-     * @access   private
514
-     * @return TRUE on success, FALSE on fail
515
-     * @throws EE_Error
516
-     * @throws InvalidArgumentException
517
-     * @throws InvalidDataTypeException
518
-     * @throws InvalidInterfaceException
519
-     * @throws InvalidSessionDataException
520
-     */
521
-    private function _espresso_session()
522
-    {
523
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
-        // check that session has started
525
-        if (session_id() === '') {
526
-            //starts a new session if one doesn't already exist, or re-initiates an existing one
527
-            session_start();
528
-        }
529
-        // get our modified session ID
530
-        $this->_sid = $this->_generate_session_id();
531
-        // and the visitors IP
532
-        $this->_ip_address = $this->_visitor_ip();
533
-        // set the "user agent"
534
-        $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
535
-        // now let's retrieve what's in the db
536
-        $session_data = $this->_retrieve_session_data();
537
-        if (! empty($session_data)) {
538
-            // get the current time in UTC
539
-            $this->_time = $this->_time !== null ? $this->_time : time();
540
-            // and reset the session expiration
541
-            $this->_expiration = isset($session_data['expiration'])
542
-                ? $session_data['expiration']
543
-                : $this->_time + $this->_lifespan;
544
-        } else {
545
-            // set initial site access time and the session expiration
546
-            $this->_set_init_access_and_expiration();
547
-            // set referer
548
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
549
-                ? esc_attr($_SERVER['HTTP_REFERER'])
550
-                : '';
551
-            // no previous session = go back and create one (on top of the data above)
552
-            return false;
553
-        }
554
-        // now the user agent
555
-        if ($session_data['user_agent'] !== $this->_user_agent) {
556
-            return false;
557
-        }
558
-        // wait a minute... how old are you?
559
-        if ($this->_time > $this->_expiration) {
560
-            // yer too old fer me!
561
-            $this->_expired = true;
562
-            // wipe out everything that isn't a default session datum
563
-            $this->clear_session(__CLASS__, __FUNCTION__);
564
-        }
565
-        // make event espresso session data available to plugin
566
-        $this->_session_data = array_merge($this->_session_data, $session_data);
567
-        return true;
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * _get_session_data
574
-     * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
575
-     * databases
576
-     *
577
-     * @return array
578
-     * @throws EE_Error
579
-     * @throws InvalidArgumentException
580
-     * @throws InvalidSessionDataException
581
-     * @throws InvalidDataTypeException
582
-     * @throws InvalidInterfaceException
583
-     */
584
-    protected function _retrieve_session_data()
585
-    {
586
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
587
-        try {
588
-            // we're using WP's Transient API to store session data using the PHP session ID as the option name
589
-            $session_data = $this->cache_storage->get($ssn_key, false);
590
-            if (empty($session_data)) {
591
-                return array();
592
-            }
593
-            if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
594
-                $hash_check = $this->cache_storage->get(
595
-                    EE_Session::hash_check_prefix . $this->_sid,
596
-                    false
597
-                );
598
-                if ($hash_check && $hash_check !== md5($session_data)) {
599
-                    EE_Error::add_error(
600
-                        sprintf(
601
-                            __(
602
-                                'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
603
-                                'event_espresso'
604
-                            ),
605
-                            EE_Session::session_id_prefix . $this->_sid
606
-                        ),
607
-                        __FILE__, __FUNCTION__, __LINE__
608
-                    );
609
-                }
610
-            }
611
-        } catch (Exception $e) {
612
-            // let's just eat that error for now and attempt to correct any corrupted data
613
-            global $wpdb;
614
-            $row          = $wpdb->get_row(
615
-                $wpdb->prepare(
616
-                    "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
617
-                    '_transient_' . $ssn_key
618
-                )
619
-            );
620
-            $session_data = is_object($row) ? $row->option_value : null;
621
-            if ($session_data) {
622
-                $session_data = preg_replace_callback(
623
-                    '!s:(d+):"(.*?)";!',
624
-                    function ($match)
625
-                    {
626
-                        return $match[1] === strlen($match[2])
627
-                            ? $match[0]
628
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
629
-                    },
630
-                    $session_data
631
-                );
632
-            }
633
-            $session_data = maybe_unserialize($session_data);
634
-        }
635
-        // in case the data is encoded... try to decode it
636
-        $session_data = $this->encryption instanceof EE_Encryption
637
-            ? $this->encryption->base64_string_decode($session_data)
638
-            : $session_data;
639
-        if (! is_array($session_data)) {
640
-            try {
641
-                $session_data = maybe_unserialize($session_data);
642
-            } catch (Exception $e) {
643
-                $msg = esc_html__(
644
-                    'An error occurred while attempting to unserialize the session data.',
645
-                    'event_espresso'
646
-                );
647
-                $msg .= WP_DEBUG
648
-                    ? '<br><pre>'
649
-                      . print_r($session_data, true)
650
-                      . '</pre><br>'
651
-                      . $this->find_serialize_error($session_data)
652
-                    : '';
653
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
654
-                throw new InvalidSessionDataException($msg, 0, $e);
655
-            }
656
-        }
657
-        // just a check to make sure the session array is indeed an array
658
-        if (! is_array($session_data)) {
659
-            // no?!?! then something is wrong
660
-            $msg = esc_html__(
661
-                'The session data is missing, invalid, or corrupted.',
662
-                'event_espresso'
663
-            );
664
-            $msg .= WP_DEBUG
665
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
666
-                : '';
667
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
668
-            throw new InvalidSessionDataException($msg);
669
-        }
670
-        if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
671
-            $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
672
-                $session_data['transaction']
673
-            );
674
-        }
675
-        return $session_data;
676
-    }
677
-
678
-
679
-
680
-    /**
681
-     * _generate_session_id
682
-     * Retrieves the PHP session id either directly from the PHP session,
683
-     * or from the $_REQUEST array if it was passed in from an AJAX request.
684
-     * The session id is then salted and hashed (mmm sounds tasty)
685
-     * so that it can be safely used as a $_REQUEST param
686
-     *
687
-     * @return string
688
-     */
689
-    protected function _generate_session_id()
690
-    {
691
-        // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
692
-        if (isset($_REQUEST['EESID'])) {
693
-            $session_id = sanitize_text_field($_REQUEST['EESID']);
694
-        } else {
695
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
696
-        }
697
-        return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * _get_sid_salt
704
-     *
705
-     * @return string
706
-     */
707
-    protected function _get_sid_salt()
708
-    {
709
-        // was session id salt already saved to db ?
710
-        if (empty($this->_sid_salt)) {
711
-            // no?  then maybe use WP defined constant
712
-            if (defined('AUTH_SALT')) {
713
-                $this->_sid_salt = AUTH_SALT;
714
-            }
715
-            // if salt doesn't exist or is too short
716
-            if (strlen($this->_sid_salt) < 32) {
717
-                // create a new one
718
-                $this->_sid_salt = wp_generate_password(64);
719
-            }
720
-            // and save it as a permanent session setting
721
-            $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
722
-        }
723
-        return $this->_sid_salt;
724
-    }
725
-
726
-
727
-
728
-    /**
729
-     * _set_init_access_and_expiration
730
-     *
731
-     * @return void
732
-     */
733
-    protected function _set_init_access_and_expiration()
734
-    {
735
-        $this->_time       = time();
736
-        $this->_expiration = $this->_time + $this->_lifespan;
737
-        // set initial site access time
738
-        $this->_session_data['init_access'] = $this->_time;
739
-        // and the session expiration
740
-        $this->_session_data['expiration'] = $this->_expiration;
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     * @update session data  prior to saving to the db
747
-     * @access public
748
-     * @param bool $new_session
749
-     * @return TRUE on success, FALSE on fail
750
-     * @throws EE_Error
751
-     * @throws InvalidArgumentException
752
-     * @throws InvalidDataTypeException
753
-     * @throws InvalidInterfaceException
754
-     */
755
-    public function update($new_session = false)
756
-    {
757
-        $this->_session_data = $this->_session_data !== null
758
-                               && is_array($this->_session_data)
759
-                               && isset($this->_session_data['id'])
760
-            ? $this->_session_data
761
-            : array();
762
-        if (empty($this->_session_data)) {
763
-            $this->_set_defaults();
764
-        }
765
-        $session_data = array();
766
-        foreach ($this->_session_data as $key => $value) {
767
-
768
-            switch ($key) {
769
-
770
-                case 'id' :
771
-                    // session ID
772
-                    $session_data['id'] = $this->_sid;
773
-                    break;
774
-                case 'ip_address' :
775
-                    // visitor ip address
776
-                    $session_data['ip_address'] = $this->_visitor_ip();
777
-                    break;
778
-                case 'user_agent' :
779
-                    // visitor user_agent
780
-                    $session_data['user_agent'] = $this->_user_agent;
781
-                    break;
782
-                case 'init_access' :
783
-                    $session_data['init_access'] = absint($value);
784
-                    break;
785
-                case 'last_access' :
786
-                    // current access time
787
-                    $session_data['last_access'] = $this->_time;
788
-                    break;
789
-                case 'expiration' :
790
-                    // when the session expires
791
-                    $session_data['expiration'] = ! empty($this->_expiration)
792
-                        ? $this->_expiration
793
-                        : $session_data['init_access'] + $this->_lifespan;
794
-                    break;
795
-                case 'user_id' :
796
-                    // current user if logged in
797
-                    $session_data['user_id'] = $this->_wp_user_id();
798
-                    break;
799
-                case 'pages_visited' :
800
-                    $page_visit = $this->_get_page_visit();
801
-                    if ($page_visit) {
802
-                        // set pages visited where the first will be the http referrer
803
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
804
-                        // we'll only save the last 10 page visits.
805
-                        $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
806
-                    }
807
-                    break;
808
-                default :
809
-                    // carry any other data over
810
-                    $session_data[ $key ] = $this->_session_data[ $key ];
811
-            }
812
-        }
813
-        $this->_session_data = $session_data;
814
-        // creating a new session does not require saving to the db just yet
815
-        if (! $new_session) {
816
-            // ready? let's save
817
-            if ($this->_save_session_to_db()) {
818
-                return true;
819
-            }
820
-            return false;
821
-        }
822
-        // meh, why not?
823
-        return true;
824
-    }
825
-
826
-
827
-
828
-    /**
829
-     * @create session data array
830
-     * @access public
831
-     * @return bool
832
-     * @throws EE_Error
833
-     * @throws InvalidArgumentException
834
-     * @throws InvalidDataTypeException
835
-     * @throws InvalidInterfaceException
836
-     */
837
-    private function _create_espresso_session()
838
-    {
839
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
840
-        // use the update function for now with $new_session arg set to TRUE
841
-        return $this->update(true) ? true : false;
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * _save_session_to_db
848
-     *
849
-     * @param bool $clear_session
850
-     * @return string
851
-     * @throws EE_Error
852
-     * @throws InvalidArgumentException
853
-     * @throws InvalidDataTypeException
854
-     * @throws InvalidInterfaceException
855
-     */
856
-    private function _save_session_to_db($clear_session = false)
857
-    {
858
-        // unless we're deleting the session data, don't save anything if there isn't a cart
859
-        if (! $clear_session && ! $this->cart() instanceof EE_Cart) {
860
-            return false;
861
-        }
862
-        $transaction = $this->transaction();
863
-        if ($transaction instanceof EE_Transaction) {
864
-            if (! $transaction->ID()) {
865
-                $transaction->save();
866
-            }
867
-            $this->_session_data['transaction'] = $transaction->ID();
868
-        }
869
-        // then serialize all of our session data
870
-        $session_data = serialize($this->_session_data);
871
-        // do we need to also encode it to avoid corrupted data when saved to the db?
872
-        $session_data = $this->_use_encryption
873
-            ? $this->encryption->base64_string_encode($session_data)
874
-            : $session_data;
875
-        // maybe save hash check
876
-        if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
877
-            $this->cache_storage->add(
878
-                EE_Session::hash_check_prefix . $this->_sid,
879
-                md5($session_data),
880
-                $this->_lifespan
881
-            );
882
-        }
883
-        // we're using the Transient API for storing session data,
884
-        return $this->cache_storage->add(
885
-            EE_Session::session_id_prefix . $this->_sid,
886
-            $session_data,
887
-            $this->_lifespan
888
-        );
889
-    }
890
-
891
-
892
-
893
-    /**
894
-     * _visitor_ip
895
-     *    attempt to get IP address of current visitor from server
896
-     * plz see: http://stackoverflow.com/a/2031935/1475279
897
-     *
898
-     * @access public
899
-     * @return string
900
-     */
901
-    private function _visitor_ip()
902
-    {
903
-        $visitor_ip  = '0.0.0.0';
904
-        $server_keys = array(
905
-            'HTTP_CLIENT_IP',
906
-            'HTTP_X_FORWARDED_FOR',
907
-            'HTTP_X_FORWARDED',
908
-            'HTTP_X_CLUSTER_CLIENT_IP',
909
-            'HTTP_FORWARDED_FOR',
910
-            'HTTP_FORWARDED',
911
-            'REMOTE_ADDR',
912
-        );
913
-        foreach ($server_keys as $key) {
914
-            if (isset($_SERVER[ $key ])) {
915
-                foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
916
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
917
-                        $visitor_ip = $ip;
918
-                    }
919
-                }
920
-            }
921
-        }
922
-        return $visitor_ip;
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * @get    the full page request the visitor is accessing
929
-     * @access public
930
-     * @return string
931
-     */
932
-    public function _get_page_visit()
933
-    {
934
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
935
-        // check for request url
936
-        if (isset($_SERVER['REQUEST_URI'])) {
937
-            $http_host   = '';
938
-            $page_id     = '?';
939
-            $e_reg       = '';
940
-            $request_uri = esc_url($_SERVER['REQUEST_URI']);
941
-            $ru_bits     = explode('?', $request_uri);
942
-            $request_uri = $ru_bits[0];
943
-            // check for and grab host as well
944
-            if (isset($_SERVER['HTTP_HOST'])) {
945
-                $http_host = esc_url($_SERVER['HTTP_HOST']);
946
-            }
947
-            // check for page_id in SERVER REQUEST
948
-            if (isset($_REQUEST['page_id'])) {
949
-                // rebuild $e_reg without any of the extra parameters
950
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
951
-            }
952
-            // check for $e_reg in SERVER REQUEST
953
-            if (isset($_REQUEST['ee'])) {
954
-                // rebuild $e_reg without any of the extra parameters
955
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
956
-            }
957
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
958
-        }
959
-        return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
960
-    }
961
-
962
-
963
-
964
-    /**
965
-     * @the    current wp user id
966
-     * @access public
967
-     * @return int
968
-     */
969
-    public function _wp_user_id()
970
-    {
971
-        // if I need to explain the following lines of code, then you shouldn't be looking at this!
972
-        $this->_wp_user_id = get_current_user_id();
973
-        return $this->_wp_user_id;
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * Clear EE_Session data
980
-     *
981
-     * @access public
982
-     * @param string $class
983
-     * @param string $function
984
-     * @return void
985
-     * @throws EE_Error
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidDataTypeException
988
-     * @throws InvalidInterfaceException
989
-     */
990
-    public function clear_session($class = '', $function = '')
991
-    {
992
-        //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
993
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
994
-        $this->reset_cart();
995
-        $this->reset_checkout();
996
-        $this->reset_transaction();
997
-        // wipe out everything that isn't a default session datum
998
-        $this->reset_data(array_keys($this->_session_data));
999
-        // reset initial site access time and the session expiration
1000
-        $this->_set_init_access_and_expiration();
1001
-        $this->_save_session_to_db(true);
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * @resets all non-default session vars
1008
-     * @access public
1009
-     * @param array|mixed $data_to_reset
1010
-     * @param bool        $show_all_notices
1011
-     * @return TRUE on success, FALSE on fail
1012
-     */
1013
-    public function reset_data($data_to_reset = array(), $show_all_notices = false)
1014
-    {
1015
-        // if $data_to_reset is not in an array, then put it in one
1016
-        if (! is_array($data_to_reset)) {
1017
-            $data_to_reset = array($data_to_reset);
1018
-        }
1019
-        // nothing ??? go home!
1020
-        if (empty($data_to_reset)) {
1021
-            EE_Error::add_error(__('No session data could be reset, because no session var name was provided.',
1022
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1023
-            return false;
1024
-        }
1025
-        $return_value = true;
1026
-        // since $data_to_reset is an array, cycle through the values
1027
-        foreach ($data_to_reset as $reset) {
1028
-
1029
-            // first check to make sure it is a valid session var
1030
-            if (isset($this->_session_data[ $reset ])) {
1031
-                // then check to make sure it is not a default var
1032
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1033
-                    // remove session var
1034
-                    unset($this->_session_data[ $reset ]);
1035
-                    if ($show_all_notices) {
1036
-                        EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1037
-                            $reset), __FILE__, __FUNCTION__, __LINE__);
1038
-                    }
1039
-                } else {
1040
-                    // yeeeeeeeeerrrrrrrrrrr OUT !!!!
1041
-                    if ($show_all_notices) {
1042
-                        EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
1043
-                            'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1044
-                    }
1045
-                    $return_value = false;
1046
-                }
1047
-            } elseif ($show_all_notices) {
1048
-                // oops! that session var does not exist!
1049
-                EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.',
1050
-                    'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1051
-                $return_value = false;
1052
-            }
1053
-        } // end of foreach
1054
-        return $return_value;
1055
-    }
1056
-
1057
-
1058
-
1059
-    /**
1060
-     *   wp_loaded
1061
-     *
1062
-     * @access public
1063
-     * @throws EE_Error
1064
-     * @throws InvalidDataTypeException
1065
-     * @throws InvalidInterfaceException
1066
-     * @throws InvalidArgumentException
1067
-     */
1068
-    public function wp_loaded()
1069
-    {
1070
-        if (
1071
-            EE_Registry::instance()->REQ instanceof EE_Request_Handler
1072
-            && EE_Registry::instance()->REQ->is_set('clear_session')
1073
-        ) {
1074
-            $this->clear_session(__CLASS__, __FUNCTION__);
1075
-        }
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * Used to reset the entire object (for tests).
1082
-     *
1083
-     * @since 4.3.0
1084
-     * @throws EE_Error
1085
-     * @throws InvalidDataTypeException
1086
-     * @throws InvalidInterfaceException
1087
-     * @throws InvalidArgumentException
1088
-     */
1089
-    public function reset_instance()
1090
-    {
1091
-        $this->clear_session();
1092
-        self::$_instance = null;
1093
-    }
1094
-
1095
-
1096
-
1097
-    public function configure_garbage_collection_filters()
1098
-    {
1099
-        // run old filter we had for controlling session cleanup
1100
-        $expired_session_transient_delete_query_limit = absint(
1101
-            apply_filters(
1102
-                'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1103
-                50
1104
-            )
1105
-        );
1106
-        // is there a value? or one that is different than the default 50 records?
1107
-        if ($expired_session_transient_delete_query_limit === 0) {
1108
-            // hook into TransientCacheStorage in case Session cleanup was turned off
1109
-            add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1110
-        } elseif ($expired_session_transient_delete_query_limit !== 50) {
1111
-            // or use that for the new transient cleanup query limit
1112
-            add_filter(
1113
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1114
-                function () use ($expired_session_transient_delete_query_limit)
1115
-                {
1116
-                    return $expired_session_transient_delete_query_limit;
1117
-                }
1118
-            );
1119
-        }
1120
-    }
1121
-
1122
-
1123
-
1124
-    /**
1125
-     * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1126
-     * @param $data1
1127
-     * @return string
1128
-     */
1129
-    private function find_serialize_error($data1)
1130
-    {
1131
-        $error = '<pre>';
1132
-        $data2 = preg_replace_callback(
1133
-            '!s:(\d+):"(.*?)";!',
1134
-            function ($match)
1135
-            {
1136
-                return ($match[1] === strlen($match[2]))
1137
-                    ? $match[0]
1138
-                    : 's:'
1139
-                      . strlen($match[2])
1140
-                      . ':"'
1141
-                      . $match[2]
1142
-                      . '";';
1143
-            },
1144
-            $data1
1145
-        );
1146
-        $max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1147
-        $error .= $data1 . PHP_EOL;
1148
-        $error .= $data2 . PHP_EOL;
1149
-        for ($i = 0; $i < $max; $i++) {
1150
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1151
-                $error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1152
-                $error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1153
-                $error  .= "\t-> Line Number = $i" . PHP_EOL;
1154
-                $start  = ($i - 20);
1155
-                $start  = ($start < 0) ? 0 : $start;
1156
-                $length = 40;
1157
-                $point  = $max - $i;
1158
-                if ($point < 20) {
1159
-                    $rlength = 1;
1160
-                    $rpoint  = -$point;
1161
-                } else {
1162
-                    $rpoint  = $length - 20;
1163
-                    $rlength = 1;
1164
-                }
1165
-                $error .= "\t-> Section Data1  = ";
1166
-                $error .= substr_replace(
1167
-                    substr($data1, $start, $length),
1168
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1169
-                    $rpoint,
1170
-                    $rlength
1171
-                );
1172
-                $error .= PHP_EOL;
1173
-                $error .= "\t-> Section Data2  = ";
1174
-                $error .= substr_replace(
1175
-                    substr($data2, $start, $length),
1176
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1177
-                    $rpoint,
1178
-                    $rlength
1179
-                );
1180
-                $error .= PHP_EOL;
1181
-            }
1182
-        }
1183
-        $error .= '</pre>';
1184
-        return $error;
1185
-    }
1186
-
1187
-
1188
-    /**
1189
-     * Saves an  array of settings used for configuring aspects of session behaviour
1190
-     *
1191
-     * @param array $updated_settings
1192
-     */
1193
-    private function updateSessionSettings(array $updated_settings = array())
1194
-    {
1195
-        // add existing settings, but only if not included in incoming $updated_settings array
1196
-        $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1197
-        update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1198
-    }
1199
-
1200
-
1201
-    /**
1202
-     * garbage_collection
1203
-     */
1204
-    public function garbageCollection()
1205
-    {
1206
-        // only perform during regular requests if last garbage collection was over an hour ago
1207
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1208
-            $this->_last_gc = time();
1209
-            $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1210
-            /** @type WPDB $wpdb */
1211
-            global $wpdb;
1212
-            // filter the query limit. Set to 0 to turn off garbage collection
1213
-            $expired_session_transient_delete_query_limit = absint(
1214
-                apply_filters(
1215
-                    'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1216
-                    50
1217
-                )
1218
-            );
1219
-            // non-zero LIMIT means take out the trash
1220
-            if ($expired_session_transient_delete_query_limit) {
1221
-                $session_key    = str_replace('_', '\_', EE_Session::session_id_prefix);
1222
-                $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1223
-                // since transient expiration timestamps are set in the future, we can compare against NOW
1224
-                // but we only want to pick up any trash that's been around for more than a day
1225
-                $expiration = time() - DAY_IN_SECONDS;
1226
-                $SQL        = "
362
+	/**
363
+	 * reset_cart
364
+	 */
365
+	public function reset_cart()
366
+	{
367
+		do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
368
+		$this->_session_data['cart'] = null;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @return \EE_Cart
375
+	 */
376
+	public function cart()
377
+	{
378
+		return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
379
+			? $this->_session_data['cart']
380
+			: null;
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * @param \EE_Checkout $checkout
387
+	 * @return bool
388
+	 */
389
+	public function set_checkout(EE_Checkout $checkout)
390
+	{
391
+		$this->_session_data['checkout'] = $checkout;
392
+		return true;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * reset_checkout
399
+	 */
400
+	public function reset_checkout()
401
+	{
402
+		do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
403
+		$this->_session_data['checkout'] = null;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * @return \EE_Checkout
410
+	 */
411
+	public function checkout()
412
+	{
413
+		return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
414
+			? $this->_session_data['checkout']
415
+			: null;
416
+	}
417
+
418
+
419
+
420
+	/**
421
+	 * @param \EE_Transaction $transaction
422
+	 * @return bool
423
+	 * @throws EE_Error
424
+	 */
425
+	public function set_transaction(EE_Transaction $transaction)
426
+	{
427
+		// first remove the session from the transaction before we save the transaction in the session
428
+		$transaction->set_txn_session_data(null);
429
+		$this->_session_data['transaction'] = $transaction;
430
+		return true;
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * reset_transaction
437
+	 */
438
+	public function reset_transaction()
439
+	{
440
+		do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
441
+		$this->_session_data['transaction'] = null;
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * @return \EE_Transaction
448
+	 */
449
+	public function transaction()
450
+	{
451
+		return isset($this->_session_data['transaction'])
452
+			   && $this->_session_data['transaction'] instanceof EE_Transaction
453
+			? $this->_session_data['transaction']
454
+			: null;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * retrieve session data
461
+	 *
462
+	 * @access    public
463
+	 * @param null $key
464
+	 * @param bool $reset_cache
465
+	 * @return    array
466
+	 */
467
+	public function get_session_data($key = null, $reset_cache = false)
468
+	{
469
+		if ($reset_cache) {
470
+			$this->reset_cart();
471
+			$this->reset_checkout();
472
+			$this->reset_transaction();
473
+		}
474
+		if (! empty($key)) {
475
+			return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
476
+		}
477
+		return $this->_session_data;
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * set session data
484
+	 *
485
+	 * @access    public
486
+	 * @param    array $data
487
+	 * @return    TRUE on success, FALSE on fail
488
+	 */
489
+	public function set_session_data($data)
490
+	{
491
+
492
+		// nothing ??? bad data ??? go home!
493
+		if (empty($data) || ! is_array($data)) {
494
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__,
495
+				__FUNCTION__, __LINE__);
496
+			return false;
497
+		}
498
+		foreach ($data as $key => $value) {
499
+			if (isset($this->_default_session_vars[ $key ])) {
500
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
501
+					'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
502
+				return false;
503
+			}
504
+			$this->_session_data[ $key ] = $value;
505
+		}
506
+		return true;
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * @initiate session
513
+	 * @access   private
514
+	 * @return TRUE on success, FALSE on fail
515
+	 * @throws EE_Error
516
+	 * @throws InvalidArgumentException
517
+	 * @throws InvalidDataTypeException
518
+	 * @throws InvalidInterfaceException
519
+	 * @throws InvalidSessionDataException
520
+	 */
521
+	private function _espresso_session()
522
+	{
523
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
+		// check that session has started
525
+		if (session_id() === '') {
526
+			//starts a new session if one doesn't already exist, or re-initiates an existing one
527
+			session_start();
528
+		}
529
+		// get our modified session ID
530
+		$this->_sid = $this->_generate_session_id();
531
+		// and the visitors IP
532
+		$this->_ip_address = $this->_visitor_ip();
533
+		// set the "user agent"
534
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
535
+		// now let's retrieve what's in the db
536
+		$session_data = $this->_retrieve_session_data();
537
+		if (! empty($session_data)) {
538
+			// get the current time in UTC
539
+			$this->_time = $this->_time !== null ? $this->_time : time();
540
+			// and reset the session expiration
541
+			$this->_expiration = isset($session_data['expiration'])
542
+				? $session_data['expiration']
543
+				: $this->_time + $this->_lifespan;
544
+		} else {
545
+			// set initial site access time and the session expiration
546
+			$this->_set_init_access_and_expiration();
547
+			// set referer
548
+			$this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
549
+				? esc_attr($_SERVER['HTTP_REFERER'])
550
+				: '';
551
+			// no previous session = go back and create one (on top of the data above)
552
+			return false;
553
+		}
554
+		// now the user agent
555
+		if ($session_data['user_agent'] !== $this->_user_agent) {
556
+			return false;
557
+		}
558
+		// wait a minute... how old are you?
559
+		if ($this->_time > $this->_expiration) {
560
+			// yer too old fer me!
561
+			$this->_expired = true;
562
+			// wipe out everything that isn't a default session datum
563
+			$this->clear_session(__CLASS__, __FUNCTION__);
564
+		}
565
+		// make event espresso session data available to plugin
566
+		$this->_session_data = array_merge($this->_session_data, $session_data);
567
+		return true;
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * _get_session_data
574
+	 * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
575
+	 * databases
576
+	 *
577
+	 * @return array
578
+	 * @throws EE_Error
579
+	 * @throws InvalidArgumentException
580
+	 * @throws InvalidSessionDataException
581
+	 * @throws InvalidDataTypeException
582
+	 * @throws InvalidInterfaceException
583
+	 */
584
+	protected function _retrieve_session_data()
585
+	{
586
+		$ssn_key = EE_Session::session_id_prefix . $this->_sid;
587
+		try {
588
+			// we're using WP's Transient API to store session data using the PHP session ID as the option name
589
+			$session_data = $this->cache_storage->get($ssn_key, false);
590
+			if (empty($session_data)) {
591
+				return array();
592
+			}
593
+			if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
594
+				$hash_check = $this->cache_storage->get(
595
+					EE_Session::hash_check_prefix . $this->_sid,
596
+					false
597
+				);
598
+				if ($hash_check && $hash_check !== md5($session_data)) {
599
+					EE_Error::add_error(
600
+						sprintf(
601
+							__(
602
+								'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
603
+								'event_espresso'
604
+							),
605
+							EE_Session::session_id_prefix . $this->_sid
606
+						),
607
+						__FILE__, __FUNCTION__, __LINE__
608
+					);
609
+				}
610
+			}
611
+		} catch (Exception $e) {
612
+			// let's just eat that error for now and attempt to correct any corrupted data
613
+			global $wpdb;
614
+			$row          = $wpdb->get_row(
615
+				$wpdb->prepare(
616
+					"SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
617
+					'_transient_' . $ssn_key
618
+				)
619
+			);
620
+			$session_data = is_object($row) ? $row->option_value : null;
621
+			if ($session_data) {
622
+				$session_data = preg_replace_callback(
623
+					'!s:(d+):"(.*?)";!',
624
+					function ($match)
625
+					{
626
+						return $match[1] === strlen($match[2])
627
+							? $match[0]
628
+							: 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
629
+					},
630
+					$session_data
631
+				);
632
+			}
633
+			$session_data = maybe_unserialize($session_data);
634
+		}
635
+		// in case the data is encoded... try to decode it
636
+		$session_data = $this->encryption instanceof EE_Encryption
637
+			? $this->encryption->base64_string_decode($session_data)
638
+			: $session_data;
639
+		if (! is_array($session_data)) {
640
+			try {
641
+				$session_data = maybe_unserialize($session_data);
642
+			} catch (Exception $e) {
643
+				$msg = esc_html__(
644
+					'An error occurred while attempting to unserialize the session data.',
645
+					'event_espresso'
646
+				);
647
+				$msg .= WP_DEBUG
648
+					? '<br><pre>'
649
+					  . print_r($session_data, true)
650
+					  . '</pre><br>'
651
+					  . $this->find_serialize_error($session_data)
652
+					: '';
653
+				$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
654
+				throw new InvalidSessionDataException($msg, 0, $e);
655
+			}
656
+		}
657
+		// just a check to make sure the session array is indeed an array
658
+		if (! is_array($session_data)) {
659
+			// no?!?! then something is wrong
660
+			$msg = esc_html__(
661
+				'The session data is missing, invalid, or corrupted.',
662
+				'event_espresso'
663
+			);
664
+			$msg .= WP_DEBUG
665
+				? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
666
+				: '';
667
+			$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
668
+			throw new InvalidSessionDataException($msg);
669
+		}
670
+		if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
671
+			$session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
672
+				$session_data['transaction']
673
+			);
674
+		}
675
+		return $session_data;
676
+	}
677
+
678
+
679
+
680
+	/**
681
+	 * _generate_session_id
682
+	 * Retrieves the PHP session id either directly from the PHP session,
683
+	 * or from the $_REQUEST array if it was passed in from an AJAX request.
684
+	 * The session id is then salted and hashed (mmm sounds tasty)
685
+	 * so that it can be safely used as a $_REQUEST param
686
+	 *
687
+	 * @return string
688
+	 */
689
+	protected function _generate_session_id()
690
+	{
691
+		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
692
+		if (isset($_REQUEST['EESID'])) {
693
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
694
+		} else {
695
+			$session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
696
+		}
697
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * _get_sid_salt
704
+	 *
705
+	 * @return string
706
+	 */
707
+	protected function _get_sid_salt()
708
+	{
709
+		// was session id salt already saved to db ?
710
+		if (empty($this->_sid_salt)) {
711
+			// no?  then maybe use WP defined constant
712
+			if (defined('AUTH_SALT')) {
713
+				$this->_sid_salt = AUTH_SALT;
714
+			}
715
+			// if salt doesn't exist or is too short
716
+			if (strlen($this->_sid_salt) < 32) {
717
+				// create a new one
718
+				$this->_sid_salt = wp_generate_password(64);
719
+			}
720
+			// and save it as a permanent session setting
721
+			$this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
722
+		}
723
+		return $this->_sid_salt;
724
+	}
725
+
726
+
727
+
728
+	/**
729
+	 * _set_init_access_and_expiration
730
+	 *
731
+	 * @return void
732
+	 */
733
+	protected function _set_init_access_and_expiration()
734
+	{
735
+		$this->_time       = time();
736
+		$this->_expiration = $this->_time + $this->_lifespan;
737
+		// set initial site access time
738
+		$this->_session_data['init_access'] = $this->_time;
739
+		// and the session expiration
740
+		$this->_session_data['expiration'] = $this->_expiration;
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 * @update session data  prior to saving to the db
747
+	 * @access public
748
+	 * @param bool $new_session
749
+	 * @return TRUE on success, FALSE on fail
750
+	 * @throws EE_Error
751
+	 * @throws InvalidArgumentException
752
+	 * @throws InvalidDataTypeException
753
+	 * @throws InvalidInterfaceException
754
+	 */
755
+	public function update($new_session = false)
756
+	{
757
+		$this->_session_data = $this->_session_data !== null
758
+							   && is_array($this->_session_data)
759
+							   && isset($this->_session_data['id'])
760
+			? $this->_session_data
761
+			: array();
762
+		if (empty($this->_session_data)) {
763
+			$this->_set_defaults();
764
+		}
765
+		$session_data = array();
766
+		foreach ($this->_session_data as $key => $value) {
767
+
768
+			switch ($key) {
769
+
770
+				case 'id' :
771
+					// session ID
772
+					$session_data['id'] = $this->_sid;
773
+					break;
774
+				case 'ip_address' :
775
+					// visitor ip address
776
+					$session_data['ip_address'] = $this->_visitor_ip();
777
+					break;
778
+				case 'user_agent' :
779
+					// visitor user_agent
780
+					$session_data['user_agent'] = $this->_user_agent;
781
+					break;
782
+				case 'init_access' :
783
+					$session_data['init_access'] = absint($value);
784
+					break;
785
+				case 'last_access' :
786
+					// current access time
787
+					$session_data['last_access'] = $this->_time;
788
+					break;
789
+				case 'expiration' :
790
+					// when the session expires
791
+					$session_data['expiration'] = ! empty($this->_expiration)
792
+						? $this->_expiration
793
+						: $session_data['init_access'] + $this->_lifespan;
794
+					break;
795
+				case 'user_id' :
796
+					// current user if logged in
797
+					$session_data['user_id'] = $this->_wp_user_id();
798
+					break;
799
+				case 'pages_visited' :
800
+					$page_visit = $this->_get_page_visit();
801
+					if ($page_visit) {
802
+						// set pages visited where the first will be the http referrer
803
+						$this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
804
+						// we'll only save the last 10 page visits.
805
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
806
+					}
807
+					break;
808
+				default :
809
+					// carry any other data over
810
+					$session_data[ $key ] = $this->_session_data[ $key ];
811
+			}
812
+		}
813
+		$this->_session_data = $session_data;
814
+		// creating a new session does not require saving to the db just yet
815
+		if (! $new_session) {
816
+			// ready? let's save
817
+			if ($this->_save_session_to_db()) {
818
+				return true;
819
+			}
820
+			return false;
821
+		}
822
+		// meh, why not?
823
+		return true;
824
+	}
825
+
826
+
827
+
828
+	/**
829
+	 * @create session data array
830
+	 * @access public
831
+	 * @return bool
832
+	 * @throws EE_Error
833
+	 * @throws InvalidArgumentException
834
+	 * @throws InvalidDataTypeException
835
+	 * @throws InvalidInterfaceException
836
+	 */
837
+	private function _create_espresso_session()
838
+	{
839
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
840
+		// use the update function for now with $new_session arg set to TRUE
841
+		return $this->update(true) ? true : false;
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * _save_session_to_db
848
+	 *
849
+	 * @param bool $clear_session
850
+	 * @return string
851
+	 * @throws EE_Error
852
+	 * @throws InvalidArgumentException
853
+	 * @throws InvalidDataTypeException
854
+	 * @throws InvalidInterfaceException
855
+	 */
856
+	private function _save_session_to_db($clear_session = false)
857
+	{
858
+		// unless we're deleting the session data, don't save anything if there isn't a cart
859
+		if (! $clear_session && ! $this->cart() instanceof EE_Cart) {
860
+			return false;
861
+		}
862
+		$transaction = $this->transaction();
863
+		if ($transaction instanceof EE_Transaction) {
864
+			if (! $transaction->ID()) {
865
+				$transaction->save();
866
+			}
867
+			$this->_session_data['transaction'] = $transaction->ID();
868
+		}
869
+		// then serialize all of our session data
870
+		$session_data = serialize($this->_session_data);
871
+		// do we need to also encode it to avoid corrupted data when saved to the db?
872
+		$session_data = $this->_use_encryption
873
+			? $this->encryption->base64_string_encode($session_data)
874
+			: $session_data;
875
+		// maybe save hash check
876
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
877
+			$this->cache_storage->add(
878
+				EE_Session::hash_check_prefix . $this->_sid,
879
+				md5($session_data),
880
+				$this->_lifespan
881
+			);
882
+		}
883
+		// we're using the Transient API for storing session data,
884
+		return $this->cache_storage->add(
885
+			EE_Session::session_id_prefix . $this->_sid,
886
+			$session_data,
887
+			$this->_lifespan
888
+		);
889
+	}
890
+
891
+
892
+
893
+	/**
894
+	 * _visitor_ip
895
+	 *    attempt to get IP address of current visitor from server
896
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
897
+	 *
898
+	 * @access public
899
+	 * @return string
900
+	 */
901
+	private function _visitor_ip()
902
+	{
903
+		$visitor_ip  = '0.0.0.0';
904
+		$server_keys = array(
905
+			'HTTP_CLIENT_IP',
906
+			'HTTP_X_FORWARDED_FOR',
907
+			'HTTP_X_FORWARDED',
908
+			'HTTP_X_CLUSTER_CLIENT_IP',
909
+			'HTTP_FORWARDED_FOR',
910
+			'HTTP_FORWARDED',
911
+			'REMOTE_ADDR',
912
+		);
913
+		foreach ($server_keys as $key) {
914
+			if (isset($_SERVER[ $key ])) {
915
+				foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
916
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
917
+						$visitor_ip = $ip;
918
+					}
919
+				}
920
+			}
921
+		}
922
+		return $visitor_ip;
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * @get    the full page request the visitor is accessing
929
+	 * @access public
930
+	 * @return string
931
+	 */
932
+	public function _get_page_visit()
933
+	{
934
+		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
935
+		// check for request url
936
+		if (isset($_SERVER['REQUEST_URI'])) {
937
+			$http_host   = '';
938
+			$page_id     = '?';
939
+			$e_reg       = '';
940
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
941
+			$ru_bits     = explode('?', $request_uri);
942
+			$request_uri = $ru_bits[0];
943
+			// check for and grab host as well
944
+			if (isset($_SERVER['HTTP_HOST'])) {
945
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
946
+			}
947
+			// check for page_id in SERVER REQUEST
948
+			if (isset($_REQUEST['page_id'])) {
949
+				// rebuild $e_reg without any of the extra parameters
950
+				$page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
951
+			}
952
+			// check for $e_reg in SERVER REQUEST
953
+			if (isset($_REQUEST['ee'])) {
954
+				// rebuild $e_reg without any of the extra parameters
955
+				$e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
956
+			}
957
+			$page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
958
+		}
959
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
960
+	}
961
+
962
+
963
+
964
+	/**
965
+	 * @the    current wp user id
966
+	 * @access public
967
+	 * @return int
968
+	 */
969
+	public function _wp_user_id()
970
+	{
971
+		// if I need to explain the following lines of code, then you shouldn't be looking at this!
972
+		$this->_wp_user_id = get_current_user_id();
973
+		return $this->_wp_user_id;
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * Clear EE_Session data
980
+	 *
981
+	 * @access public
982
+	 * @param string $class
983
+	 * @param string $function
984
+	 * @return void
985
+	 * @throws EE_Error
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidDataTypeException
988
+	 * @throws InvalidInterfaceException
989
+	 */
990
+	public function clear_session($class = '', $function = '')
991
+	{
992
+		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
993
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
994
+		$this->reset_cart();
995
+		$this->reset_checkout();
996
+		$this->reset_transaction();
997
+		// wipe out everything that isn't a default session datum
998
+		$this->reset_data(array_keys($this->_session_data));
999
+		// reset initial site access time and the session expiration
1000
+		$this->_set_init_access_and_expiration();
1001
+		$this->_save_session_to_db(true);
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * @resets all non-default session vars
1008
+	 * @access public
1009
+	 * @param array|mixed $data_to_reset
1010
+	 * @param bool        $show_all_notices
1011
+	 * @return TRUE on success, FALSE on fail
1012
+	 */
1013
+	public function reset_data($data_to_reset = array(), $show_all_notices = false)
1014
+	{
1015
+		// if $data_to_reset is not in an array, then put it in one
1016
+		if (! is_array($data_to_reset)) {
1017
+			$data_to_reset = array($data_to_reset);
1018
+		}
1019
+		// nothing ??? go home!
1020
+		if (empty($data_to_reset)) {
1021
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.',
1022
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1023
+			return false;
1024
+		}
1025
+		$return_value = true;
1026
+		// since $data_to_reset is an array, cycle through the values
1027
+		foreach ($data_to_reset as $reset) {
1028
+
1029
+			// first check to make sure it is a valid session var
1030
+			if (isset($this->_session_data[ $reset ])) {
1031
+				// then check to make sure it is not a default var
1032
+				if (! array_key_exists($reset, $this->_default_session_vars)) {
1033
+					// remove session var
1034
+					unset($this->_session_data[ $reset ]);
1035
+					if ($show_all_notices) {
1036
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1037
+							$reset), __FILE__, __FUNCTION__, __LINE__);
1038
+					}
1039
+				} else {
1040
+					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
1041
+					if ($show_all_notices) {
1042
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
1043
+							'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1044
+					}
1045
+					$return_value = false;
1046
+				}
1047
+			} elseif ($show_all_notices) {
1048
+				// oops! that session var does not exist!
1049
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.',
1050
+					'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1051
+				$return_value = false;
1052
+			}
1053
+		} // end of foreach
1054
+		return $return_value;
1055
+	}
1056
+
1057
+
1058
+
1059
+	/**
1060
+	 *   wp_loaded
1061
+	 *
1062
+	 * @access public
1063
+	 * @throws EE_Error
1064
+	 * @throws InvalidDataTypeException
1065
+	 * @throws InvalidInterfaceException
1066
+	 * @throws InvalidArgumentException
1067
+	 */
1068
+	public function wp_loaded()
1069
+	{
1070
+		if (
1071
+			EE_Registry::instance()->REQ instanceof EE_Request_Handler
1072
+			&& EE_Registry::instance()->REQ->is_set('clear_session')
1073
+		) {
1074
+			$this->clear_session(__CLASS__, __FUNCTION__);
1075
+		}
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * Used to reset the entire object (for tests).
1082
+	 *
1083
+	 * @since 4.3.0
1084
+	 * @throws EE_Error
1085
+	 * @throws InvalidDataTypeException
1086
+	 * @throws InvalidInterfaceException
1087
+	 * @throws InvalidArgumentException
1088
+	 */
1089
+	public function reset_instance()
1090
+	{
1091
+		$this->clear_session();
1092
+		self::$_instance = null;
1093
+	}
1094
+
1095
+
1096
+
1097
+	public function configure_garbage_collection_filters()
1098
+	{
1099
+		// run old filter we had for controlling session cleanup
1100
+		$expired_session_transient_delete_query_limit = absint(
1101
+			apply_filters(
1102
+				'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1103
+				50
1104
+			)
1105
+		);
1106
+		// is there a value? or one that is different than the default 50 records?
1107
+		if ($expired_session_transient_delete_query_limit === 0) {
1108
+			// hook into TransientCacheStorage in case Session cleanup was turned off
1109
+			add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1110
+		} elseif ($expired_session_transient_delete_query_limit !== 50) {
1111
+			// or use that for the new transient cleanup query limit
1112
+			add_filter(
1113
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1114
+				function () use ($expired_session_transient_delete_query_limit)
1115
+				{
1116
+					return $expired_session_transient_delete_query_limit;
1117
+				}
1118
+			);
1119
+		}
1120
+	}
1121
+
1122
+
1123
+
1124
+	/**
1125
+	 * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1126
+	 * @param $data1
1127
+	 * @return string
1128
+	 */
1129
+	private function find_serialize_error($data1)
1130
+	{
1131
+		$error = '<pre>';
1132
+		$data2 = preg_replace_callback(
1133
+			'!s:(\d+):"(.*?)";!',
1134
+			function ($match)
1135
+			{
1136
+				return ($match[1] === strlen($match[2]))
1137
+					? $match[0]
1138
+					: 's:'
1139
+					  . strlen($match[2])
1140
+					  . ':"'
1141
+					  . $match[2]
1142
+					  . '";';
1143
+			},
1144
+			$data1
1145
+		);
1146
+		$max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1147
+		$error .= $data1 . PHP_EOL;
1148
+		$error .= $data2 . PHP_EOL;
1149
+		for ($i = 0; $i < $max; $i++) {
1150
+			if (@$data1[ $i ] !== @$data2[ $i ]) {
1151
+				$error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1152
+				$error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1153
+				$error  .= "\t-> Line Number = $i" . PHP_EOL;
1154
+				$start  = ($i - 20);
1155
+				$start  = ($start < 0) ? 0 : $start;
1156
+				$length = 40;
1157
+				$point  = $max - $i;
1158
+				if ($point < 20) {
1159
+					$rlength = 1;
1160
+					$rpoint  = -$point;
1161
+				} else {
1162
+					$rpoint  = $length - 20;
1163
+					$rlength = 1;
1164
+				}
1165
+				$error .= "\t-> Section Data1  = ";
1166
+				$error .= substr_replace(
1167
+					substr($data1, $start, $length),
1168
+					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1169
+					$rpoint,
1170
+					$rlength
1171
+				);
1172
+				$error .= PHP_EOL;
1173
+				$error .= "\t-> Section Data2  = ";
1174
+				$error .= substr_replace(
1175
+					substr($data2, $start, $length),
1176
+					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1177
+					$rpoint,
1178
+					$rlength
1179
+				);
1180
+				$error .= PHP_EOL;
1181
+			}
1182
+		}
1183
+		$error .= '</pre>';
1184
+		return $error;
1185
+	}
1186
+
1187
+
1188
+	/**
1189
+	 * Saves an  array of settings used for configuring aspects of session behaviour
1190
+	 *
1191
+	 * @param array $updated_settings
1192
+	 */
1193
+	private function updateSessionSettings(array $updated_settings = array())
1194
+	{
1195
+		// add existing settings, but only if not included in incoming $updated_settings array
1196
+		$updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1197
+		update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1198
+	}
1199
+
1200
+
1201
+	/**
1202
+	 * garbage_collection
1203
+	 */
1204
+	public function garbageCollection()
1205
+	{
1206
+		// only perform during regular requests if last garbage collection was over an hour ago
1207
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1208
+			$this->_last_gc = time();
1209
+			$this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1210
+			/** @type WPDB $wpdb */
1211
+			global $wpdb;
1212
+			// filter the query limit. Set to 0 to turn off garbage collection
1213
+			$expired_session_transient_delete_query_limit = absint(
1214
+				apply_filters(
1215
+					'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1216
+					50
1217
+				)
1218
+			);
1219
+			// non-zero LIMIT means take out the trash
1220
+			if ($expired_session_transient_delete_query_limit) {
1221
+				$session_key    = str_replace('_', '\_', EE_Session::session_id_prefix);
1222
+				$hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1223
+				// since transient expiration timestamps are set in the future, we can compare against NOW
1224
+				// but we only want to pick up any trash that's been around for more than a day
1225
+				$expiration = time() - DAY_IN_SECONDS;
1226
+				$SQL        = "
1227 1227
                     SELECT option_name
1228 1228
                     FROM {$wpdb->options}
1229 1229
                     WHERE
@@ -1232,19 +1232,19 @@  discard block
 block discarded – undo
1232 1232
                     AND option_value < {$expiration}
1233 1233
                     LIMIT {$expired_session_transient_delete_query_limit}
1234 1234
                 ";
1235
-                // produces something like:
1236
-                // SELECT option_name FROM wp_options
1237
-                // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1238
-                // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1239
-                // AND option_value < 1508368198 LIMIT 50
1240
-                $expired_sessions = $wpdb->get_col($SQL);
1241
-                // valid results?
1242
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1243
-                    $this->cache_storage->deleteMany($expired_sessions, true);
1244
-                }
1245
-            }
1246
-        }
1247
-    }
1235
+				// produces something like:
1236
+				// SELECT option_name FROM wp_options
1237
+				// WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1238
+				// OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1239
+				// AND option_value < 1508368198 LIMIT 50
1240
+				$expired_sessions = $wpdb->get_col($SQL);
1241
+				// valid results?
1242
+				if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1243
+					$this->cache_storage->deleteMany($expired_sessions, true);
1244
+				}
1245
+			}
1246
+		}
1247
+	}
1248 1248
 
1249 1249
 
1250 1250
 
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         // check if class object is instantiated
165 165
         // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
166 166
         // add_filter( 'FHEE_load_EE_Session', '__return_false' );
167
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
167
+        if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
168 168
             self::$_instance = new self($cache_storage, $encryption);
169 169
         }
170 170
         return self::$_instance;
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
     {
186 186
 
187 187
         // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
188
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
188
+        if ( ! apply_filters('FHEE_load_EE_Session', true)) {
189 189
             return;
190 190
         }
191 191
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
192
-        if (! defined('ESPRESSO_SESSION')) {
192
+        if ( ! defined('ESPRESSO_SESSION')) {
193 193
             define('ESPRESSO_SESSION', true);
194 194
         }
195 195
         // default session lifespan in seconds
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
          */
206 206
         // retrieve session options from db
207 207
         $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
208
-        if (! empty($session_settings)) {
208
+        if ( ! empty($session_settings)) {
209 209
             // cycle though existing session options
210 210
             foreach ($session_settings as $var_name => $session_setting) {
211 211
                 // set values for class properties
212
-                $var_name          = '_' . $var_name;
212
+                $var_name          = '_'.$var_name;
213 213
                 $this->{$var_name} = $session_setting;
214 214
             }
215 215
         }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function open_session()
248 248
     {
249 249
         // check for existing session and retrieve it from db
250
-        if (! $this->_espresso_session()) {
250
+        if ( ! $this->_espresso_session()) {
251 251
             // or just start a new one
252 252
             $this->_create_espresso_session();
253 253
         }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      */
300 300
     public function extend_expiration($time = 0)
301 301
     {
302
-        $time              = $time ? $time : $this->extension();
302
+        $time = $time ? $time : $this->extension();
303 303
         $this->_expiration += absint($time);
304 304
     }
305 305
 
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
         // set some defaults
327 327
         foreach ($this->_default_session_vars as $key => $default_var) {
328 328
             if (is_array($default_var)) {
329
-                $this->_session_data[ $key ] = array();
329
+                $this->_session_data[$key] = array();
330 330
             } else {
331
-                $this->_session_data[ $key ] = '';
331
+                $this->_session_data[$key] = '';
332 332
             }
333 333
         }
334 334
     }
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
             $this->reset_checkout();
472 472
             $this->reset_transaction();
473 473
         }
474
-        if (! empty($key)) {
475
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
474
+        if ( ! empty($key)) {
475
+            return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null;
476 476
         }
477 477
         return $this->_session_data;
478 478
     }
@@ -496,12 +496,12 @@  discard block
 block discarded – undo
496 496
             return false;
497 497
         }
498 498
         foreach ($data as $key => $value) {
499
-            if (isset($this->_default_session_vars[ $key ])) {
499
+            if (isset($this->_default_session_vars[$key])) {
500 500
                 EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
501 501
                     'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
502 502
                 return false;
503 503
             }
504
-            $this->_session_data[ $key ] = $value;
504
+            $this->_session_data[$key] = $value;
505 505
         }
506 506
         return true;
507 507
     }
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
         $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
535 535
         // now let's retrieve what's in the db
536 536
         $session_data = $this->_retrieve_session_data();
537
-        if (! empty($session_data)) {
537
+        if ( ! empty($session_data)) {
538 538
             // get the current time in UTC
539 539
             $this->_time = $this->_time !== null ? $this->_time : time();
540 540
             // and reset the session expiration
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
             // set initial site access time and the session expiration
546 546
             $this->_set_init_access_and_expiration();
547 547
             // set referer
548
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
548
+            $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
549 549
                 ? esc_attr($_SERVER['HTTP_REFERER'])
550 550
                 : '';
551 551
             // no previous session = go back and create one (on top of the data above)
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
      */
584 584
     protected function _retrieve_session_data()
585 585
     {
586
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
586
+        $ssn_key = EE_Session::session_id_prefix.$this->_sid;
587 587
         try {
588 588
             // we're using WP's Transient API to store session data using the PHP session ID as the option name
589 589
             $session_data = $this->cache_storage->get($ssn_key, false);
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
             }
593 593
             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
594 594
                 $hash_check = $this->cache_storage->get(
595
-                    EE_Session::hash_check_prefix . $this->_sid,
595
+                    EE_Session::hash_check_prefix.$this->_sid,
596 596
                     false
597 597
                 );
598 598
                 if ($hash_check && $hash_check !== md5($session_data)) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                                 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
603 603
                                 'event_espresso'
604 604
                             ),
605
-                            EE_Session::session_id_prefix . $this->_sid
605
+                            EE_Session::session_id_prefix.$this->_sid
606 606
                         ),
607 607
                         __FILE__, __FUNCTION__, __LINE__
608 608
                     );
@@ -611,21 +611,21 @@  discard block
 block discarded – undo
611 611
         } catch (Exception $e) {
612 612
             // let's just eat that error for now and attempt to correct any corrupted data
613 613
             global $wpdb;
614
-            $row          = $wpdb->get_row(
614
+            $row = $wpdb->get_row(
615 615
                 $wpdb->prepare(
616 616
                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
617
-                    '_transient_' . $ssn_key
617
+                    '_transient_'.$ssn_key
618 618
                 )
619 619
             );
620 620
             $session_data = is_object($row) ? $row->option_value : null;
621 621
             if ($session_data) {
622 622
                 $session_data = preg_replace_callback(
623 623
                     '!s:(d+):"(.*?)";!',
624
-                    function ($match)
624
+                    function($match)
625 625
                     {
626 626
                         return $match[1] === strlen($match[2])
627 627
                             ? $match[0]
628
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
628
+                            : 's:'.strlen($match[2]).':"'.$match[2].'";';
629 629
                     },
630 630
                     $session_data
631 631
                 );
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
         $session_data = $this->encryption instanceof EE_Encryption
637 637
             ? $this->encryption->base64_string_decode($session_data)
638 638
             : $session_data;
639
-        if (! is_array($session_data)) {
639
+        if ( ! is_array($session_data)) {
640 640
             try {
641 641
                 $session_data = maybe_unserialize($session_data);
642 642
             } catch (Exception $e) {
@@ -650,21 +650,21 @@  discard block
 block discarded – undo
650 650
                       . '</pre><br>'
651 651
                       . $this->find_serialize_error($session_data)
652 652
                     : '';
653
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
653
+                $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
654 654
                 throw new InvalidSessionDataException($msg, 0, $e);
655 655
             }
656 656
         }
657 657
         // just a check to make sure the session array is indeed an array
658
-        if (! is_array($session_data)) {
658
+        if ( ! is_array($session_data)) {
659 659
             // no?!?! then something is wrong
660 660
             $msg = esc_html__(
661 661
                 'The session data is missing, invalid, or corrupted.',
662 662
                 'event_espresso'
663 663
             );
664 664
             $msg .= WP_DEBUG
665
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
665
+                ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
666 666
                 : '';
667
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
667
+            $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
668 668
             throw new InvalidSessionDataException($msg);
669 669
         }
670 670
         if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
         if (isset($_REQUEST['EESID'])) {
693 693
             $session_id = sanitize_text_field($_REQUEST['EESID']);
694 694
         } else {
695
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
695
+            $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
696 696
         }
697 697
         return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
698 698
     }
@@ -800,19 +800,19 @@  discard block
 block discarded – undo
800 800
                     $page_visit = $this->_get_page_visit();
801 801
                     if ($page_visit) {
802 802
                         // set pages visited where the first will be the http referrer
803
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
803
+                        $this->_session_data['pages_visited'][$this->_time] = $page_visit;
804 804
                         // we'll only save the last 10 page visits.
805 805
                         $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
806 806
                     }
807 807
                     break;
808 808
                 default :
809 809
                     // carry any other data over
810
-                    $session_data[ $key ] = $this->_session_data[ $key ];
810
+                    $session_data[$key] = $this->_session_data[$key];
811 811
             }
812 812
         }
813 813
         $this->_session_data = $session_data;
814 814
         // creating a new session does not require saving to the db just yet
815
-        if (! $new_session) {
815
+        if ( ! $new_session) {
816 816
             // ready? let's save
817 817
             if ($this->_save_session_to_db()) {
818 818
                 return true;
@@ -856,12 +856,12 @@  discard block
 block discarded – undo
856 856
     private function _save_session_to_db($clear_session = false)
857 857
     {
858 858
         // unless we're deleting the session data, don't save anything if there isn't a cart
859
-        if (! $clear_session && ! $this->cart() instanceof EE_Cart) {
859
+        if ( ! $clear_session && ! $this->cart() instanceof EE_Cart) {
860 860
             return false;
861 861
         }
862 862
         $transaction = $this->transaction();
863 863
         if ($transaction instanceof EE_Transaction) {
864
-            if (! $transaction->ID()) {
864
+            if ( ! $transaction->ID()) {
865 865
                 $transaction->save();
866 866
             }
867 867
             $this->_session_data['transaction'] = $transaction->ID();
@@ -875,14 +875,14 @@  discard block
 block discarded – undo
875 875
         // maybe save hash check
876 876
         if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
877 877
             $this->cache_storage->add(
878
-                EE_Session::hash_check_prefix . $this->_sid,
878
+                EE_Session::hash_check_prefix.$this->_sid,
879 879
                 md5($session_data),
880 880
                 $this->_lifespan
881 881
             );
882 882
         }
883 883
         // we're using the Transient API for storing session data,
884 884
         return $this->cache_storage->add(
885
-            EE_Session::session_id_prefix . $this->_sid,
885
+            EE_Session::session_id_prefix.$this->_sid,
886 886
             $session_data,
887 887
             $this->_lifespan
888 888
         );
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
             'REMOTE_ADDR',
912 912
         );
913 913
         foreach ($server_keys as $key) {
914
-            if (isset($_SERVER[ $key ])) {
915
-                foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
914
+            if (isset($_SERVER[$key])) {
915
+                foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
916 916
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
917 917
                         $visitor_ip = $ip;
918 918
                     }
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
      */
932 932
     public function _get_page_visit()
933 933
     {
934
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
934
+        $page_visit = home_url('/').'wp-admin/admin-ajax.php';
935 935
         // check for request url
936 936
         if (isset($_SERVER['REQUEST_URI'])) {
937 937
             $http_host   = '';
@@ -947,14 +947,14 @@  discard block
 block discarded – undo
947 947
             // check for page_id in SERVER REQUEST
948 948
             if (isset($_REQUEST['page_id'])) {
949 949
                 // rebuild $e_reg without any of the extra parameters
950
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
950
+                $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
951 951
             }
952 952
             // check for $e_reg in SERVER REQUEST
953 953
             if (isset($_REQUEST['ee'])) {
954 954
                 // rebuild $e_reg without any of the extra parameters
955
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
955
+                $e_reg = 'ee='.esc_attr($_REQUEST['ee']);
956 956
             }
957
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
957
+            $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
958 958
         }
959 959
         return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
960 960
     }
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
     public function clear_session($class = '', $function = '')
991 991
     {
992 992
         //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
993
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
993
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
994 994
         $this->reset_cart();
995 995
         $this->reset_checkout();
996 996
         $this->reset_transaction();
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1014 1014
     {
1015 1015
         // if $data_to_reset is not in an array, then put it in one
1016
-        if (! is_array($data_to_reset)) {
1016
+        if ( ! is_array($data_to_reset)) {
1017 1017
             $data_to_reset = array($data_to_reset);
1018 1018
         }
1019 1019
         // nothing ??? go home!
@@ -1027,11 +1027,11 @@  discard block
 block discarded – undo
1027 1027
         foreach ($data_to_reset as $reset) {
1028 1028
 
1029 1029
             // first check to make sure it is a valid session var
1030
-            if (isset($this->_session_data[ $reset ])) {
1030
+            if (isset($this->_session_data[$reset])) {
1031 1031
                 // then check to make sure it is not a default var
1032
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1032
+                if ( ! array_key_exists($reset, $this->_default_session_vars)) {
1033 1033
                     // remove session var
1034
-                    unset($this->_session_data[ $reset ]);
1034
+                    unset($this->_session_data[$reset]);
1035 1035
                     if ($show_all_notices) {
1036 1036
                         EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1037 1037
                             $reset), __FILE__, __FUNCTION__, __LINE__);
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
             // or use that for the new transient cleanup query limit
1112 1112
             add_filter(
1113 1113
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1114
-                function () use ($expired_session_transient_delete_query_limit)
1114
+                function() use ($expired_session_transient_delete_query_limit)
1115 1115
                 {
1116 1116
                     return $expired_session_transient_delete_query_limit;
1117 1117
                 }
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
         $error = '<pre>';
1132 1132
         $data2 = preg_replace_callback(
1133 1133
             '!s:(\d+):"(.*?)";!',
1134
-            function ($match)
1134
+            function($match)
1135 1135
             {
1136 1136
                 return ($match[1] === strlen($match[2]))
1137 1137
                     ? $match[0]
@@ -1143,14 +1143,14 @@  discard block
 block discarded – undo
1143 1143
             },
1144 1144
             $data1
1145 1145
         );
1146
-        $max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1147
-        $error .= $data1 . PHP_EOL;
1148
-        $error .= $data2 . PHP_EOL;
1146
+        $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1147
+        $error .= $data1.PHP_EOL;
1148
+        $error .= $data2.PHP_EOL;
1149 1149
         for ($i = 0; $i < $max; $i++) {
1150
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1151
-                $error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1152
-                $error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1153
-                $error  .= "\t-> Line Number = $i" . PHP_EOL;
1150
+            if (@$data1[$i] !== @$data2[$i]) {
1151
+                $error  .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1152
+                $error  .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1153
+                $error  .= "\t-> Line Number = $i".PHP_EOL;
1154 1154
                 $start  = ($i - 20);
1155 1155
                 $start  = ($start < 0) ? 0 : $start;
1156 1156
                 $length = 40;
@@ -1165,7 +1165,7 @@  discard block
 block discarded – undo
1165 1165
                 $error .= "\t-> Section Data1  = ";
1166 1166
                 $error .= substr_replace(
1167 1167
                     substr($data1, $start, $length),
1168
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1168
+                    "<b style=\"color:green\">{$data1[$i]}</b>",
1169 1169
                     $rpoint,
1170 1170
                     $rlength
1171 1171
                 );
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
                 $error .= "\t-> Section Data2  = ";
1174 1174
                 $error .= substr_replace(
1175 1175
                     substr($data2, $start, $length),
1176
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1176
+                    "<b style=\"color:red\">{$data2[$i]}</b>",
1177 1177
                     $rpoint,
1178 1178
                     $rlength
1179 1179
                 );
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
     public function garbageCollection()
1205 1205
     {
1206 1206
         // only perform during regular requests if last garbage collection was over an hour ago
1207
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1207
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1208 1208
             $this->_last_gc = time();
1209 1209
             $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1210 1210
             /** @type WPDB $wpdb */
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
                 // AND option_value < 1508368198 LIMIT 50
1240 1240
                 $expired_sessions = $wpdb->get_col($SQL);
1241 1241
                 // valid results?
1242
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1242
+                if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1243 1243
                     $this->cache_storage->deleteMany($expired_sessions, true);
1244 1244
                 }
1245 1245
             }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Loader.core.php 2 patches
Indentation   +742 added lines, -742 removed lines patch added patch discarded remove patch
@@ -28,748 +28,748 @@
 block discarded – undo
28 28
 class EE_Admin_Page_Loader
29 29
 {
30 30
 
31
-    /**
32
-     * _installed_pages
33
-     * objects for page_init objects detected and loaded
34
-     *
35
-     * @access private
36
-     * @var \EE_Admin_Page_Init[]
37
-     */
38
-    private $_installed_pages = array();
39
-
40
-
41
-
42
-    /**
43
-     * this is used to hold the registry of menu slugs for all the installed admin pages
44
-     *
45
-     * @var array
46
-     */
47
-    private $_menu_slugs = array();
48
-
49
-
50
-    /**
51
-     * _caffeinated_extends
52
-     * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
53
-     * pieces needed to do so).  This property is defined in the _set_caffeinated method.
54
-     *
55
-     * @var array
56
-     */
57
-    private $_caffeinated_extends = array();
58
-
59
-
60
-
61
-    /**
62
-     * _current_caf_extend_slug
63
-     * This property is used for holding the page slug that is required for referencing the correct
64
-     * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
65
-     *
66
-     * @var array
67
-     */
68
-    private $_current_caf_extend_slug;
69
-
70
-
71
-
72
-    /**
73
-     * _caf_autoloader
74
-     * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the
75
-     * caffeinated/new directory.  This array is then used to setup a corresponding dynamic autoloader for these pages
76
-     * classes.
77
-     *
78
-     * @var array
79
-     */
80
-    //	private $_caf_autoloader = array();
81
-    /**
82
-     * _prepped_menu_maps
83
-     * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
84
-     *
85
-     * @since  4.4.0
86
-     * @var EE_Admin_Page_Menu_Map[]
87
-     */
88
-    private $_prepped_menu_maps = array();
89
-
90
-
91
-
92
-    /**
93
-     * _admin_menu_groups
94
-     * array that holds the group headings and details for
95
-     *
96
-     * @access private
97
-     * @var array
98
-     */
99
-    private $_admin_menu_groups = array();
100
-
101
-
102
-
103
-    /**
104
-     * This property will hold the hook file for setting up the filter that does all the connections between admin
105
-     * pages.
106
-     *
107
-     * @var string
108
-     */
109
-    public $hook_file;
110
-
111
-
112
-
113
-    /**
114
-     * constructor
115
-     *
116
-     * @access public
117
-     * @return \EE_Admin_Page_Loader
118
-     */
119
-    public function __construct()
120
-    {
121
-        //load menu_map classes
122
-        EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
123
-        //define the default "groups" for the admin_pages
124
-        $this->_set_menu_groups();
125
-        //let's set default autoloaders.  Note that this just sets autoloaders for root admin files.
126
-        //		spl_autoload_register( array( $this, 'init_autoloaders') );
127
-        //let's do a scan and see what installed pages we have
128
-        $this->_get_installed_pages();
129
-        //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
130
-        add_action('admin_menu', array($this, 'set_menus'));
131
-        add_action('network_admin_menu', array($this, 'set_network_menus'));
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
138
-     * files in the caffeinated folder.
139
-     *
140
-     * @access private
141
-     * @return void
142
-     */
143
-    private function _define_caffeinated_constants()
144
-    {
145
-        if (! defined('EE_CORE_CAF_ADMIN')) {
146
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
147
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
148
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
149
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
150
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
151
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * _set_menu_groups
159
-     * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    private function _set_menu_groups()
165
-    {
166
-
167
-        //set array of EE_Admin_Page_Menu_Group objects
168
-        $groups = array(
169
-            'main'       => new EE_Admin_Page_Menu_Group(
170
-                array(
171
-                    'menu_label'   => __('Main', 'event_espresso'),
172
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
173
-                    'menu_slug'    => 'main',
174
-                    'capability'   => 'ee_read_ee',
175
-                    'menu_order'   => 0,
176
-                    'parent_slug'  => 'espresso_events',
177
-                )
178
-            ),
179
-            'management' => new EE_Admin_Page_Menu_Group(
180
-                array(
181
-                    'menu_label'   => __('Management', 'event_espresso'),
182
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
183
-                    'menu_slug'    => 'management',
184
-                    'capability'   => 'ee_read_ee',
185
-                    'menu_order'   => 10,
186
-                    'parent_slug'  => 'espresso_events',
187
-                )
188
-            ),
189
-            'settings'   => new EE_Admin_Page_Menu_Group(
190
-                array(
191
-                    'menu_label'   => __('Settings', 'event_espresso'),
192
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
193
-                    'menu_slug'    => 'settings',
194
-                    'capability'   => 'ee_read_ee',
195
-                    'menu_order'   => 30,
196
-                    'parent_slug'  => 'espresso_events',
197
-                )
198
-            ),
199
-            'templates'  => new EE_Admin_Page_Menu_Group(
200
-                array(
201
-                    'menu_label'   => __('Templates', 'event_espresso'),
202
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
203
-                    'menu_slug'    => 'templates',
204
-                    'capability'   => 'ee_read_ee',
205
-                    'menu_order'   => 40,
206
-                    'parent_slug'  => 'espresso_events',
207
-                )
208
-            ),
209
-            'extras'     => new EE_Admin_Page_Menu_Group(
210
-                array(
211
-                    'menu_label'              => __('Extras', 'event_espresso'),
212
-                    'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
213
-                    'menu_slug'               => 'extras',
214
-                    'capability'              => 'ee_read_ee',
215
-                    'menu_order'              => 50,
216
-                    'parent_slug'             => 'espresso_events',
217
-                    'maintenance_mode_parent' => 'espresso_maintenance_settings',
218
-                )
219
-            ),
220
-            'tools'      => new EE_Admin_Page_Menu_Group(
221
-                array(
222
-                    'menu_label'   => __("Tools", "event_espresso"),
223
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
224
-                    'menu_slug'    => 'tools',
225
-                    'capability'   => 'ee_read_ee',
226
-                    'menu_order'   => 60,
227
-                    'parent_slug'  => 'espresso_events',
228
-                )
229
-            ),
230
-            'addons'     => new EE_Admin_Page_Menu_Group(
231
-                array(
232
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
233
-                    'menu_label'   => __('Add-ons', 'event_espresso'),
234
-                    'menu_slug'    => 'addons',
235
-                    'capability'   => 'ee_read_ee',
236
-                    'menu_order'   => 20,
237
-                    'parent_slug'  => 'espresso_events',
238
-                )
239
-            ),
240
-        );
241
-        $this->_admin_menu_groups = apply_filters(
242
-            'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
243
-            $groups
244
-        );
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
251
-     * slug.  The other utility with this function is it validates that all the groups are instances of
252
-     * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
253
-     *
254
-     * @since  4.4.0
255
-     * @throws \EE_Error
256
-     * @return EE_Admin_Page_Menu_Group[]
257
-     */
258
-    private function _rearrange_menu_groups()
259
-    {
260
-        $groups = array();
261
-        //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
262
-        usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
263
-        foreach ($this->_admin_menu_groups as $group) {
264
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
265
-                throw new EE_Error(
266
-                    sprintf(
267
-                        __(
268
-                            'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
269
-                            'event_espresso'
270
-                        ),
271
-                        print_r($group, true)
272
-                    )
273
-                );
274
-            }
275
-            $groups[$group->menu_slug] = $group;
276
-        }
277
-        return $groups;
278
-    }
279
-
280
-
281
-
282
-    /**
283
-     * _get_installed_pages
284
-     * This just gets the list of installed EE_Admin_pages.
285
-     *
286
-     * @access private
287
-     * @throws EE_Error
288
-     * @return void
289
-     */
290
-    private function _get_installed_pages()
291
-    {
292
-        $installed_refs = array();
293
-        $exclude        = array('assets', 'templates');
294
-        // grab everything in the  admin core directory
295
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
296
-        if ($admin_screens) {
297
-            foreach ($admin_screens as $admin_screen) {
298
-                // files and anything in the exclude array need not apply
299
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
300
-                    // these folders represent the different EE admin pages
301
-                    $installed_refs[basename($admin_screen)] = $admin_screen;
302
-                }
303
-            }
304
-        }
305
-        if (empty($installed_refs)) {
306
-            $error_msg[] = __(
307
-                'There are no EE_Admin pages detected, it looks like EE did not install properly',
308
-                'event_espresso'
309
-            );
310
-            $error_msg[] = $error_msg[0] . "\r\n" . sprintf(
311
-                    __(
312
-                        'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
313
-                        'event_espresso'
314
-                    ),
315
-                    EE_ADMIN_PAGES
316
-                );
317
-            throw new EE_Error(implode('||', $error_msg));
318
-        }
319
-        //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
320
-        $installed_refs = $this->_set_caffeinated($installed_refs);
321
-        //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
322
-        $installed_refs             = apply_filters(
323
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
324
-            $installed_refs
325
-        );
326
-        $this->_caffeinated_extends = apply_filters(
327
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
328
-            $this->_caffeinated_extends
329
-        );
330
-        //loop through admin pages and setup the $_installed_pages array.
331
-        $hooks_ref = array();
332
-        foreach ($installed_refs as $page => $path) {
333
-            // set autoloaders for our admin page classes based on included path information
334
-            EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
335
-            // build list of installed pages
336
-            $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
337
-            // verify returned object
338
-            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
339
-                if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
340
-                    continue;
341
-                }
342
-                //skip if in full maintenance mode and maintenance_mode_parent is set
343
-                $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
344
-                if (empty($maintenance_mode_parent)
345
-                    && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
346
-                ) {
347
-                    unset($installed_refs[$page]);
348
-                    continue;
349
-                }
350
-                $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug;
351
-                $this->_menu_slugs[$menu_slug] = $page;
352
-                //flag for register hooks on extended pages b/c extended pages use the default INIT.
353
-                $extend = false;
354
-                //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
355
-                if (isset($this->_caffeinated_extends[$page])) {
356
-                    $this->_current_caf_extend_slug = $page;
357
-                    $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name();
358
-                    $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path'];
359
-                    $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page'];
360
-                    add_filter(
361
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
362
-                        function($path_to_file) use ($caf_path) {
363
-                            return $caf_path;
364
-                        }
365
-                    );
366
-                    add_filter(
367
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
368
-                        function ($admin_page) use ($caf_admin_page)
369
-                        {
370
-                            return $caf_admin_page;
371
-                        }
372
-                    );
373
-                    $extend = true;
374
-                }
375
-                //let's do the registered hooks
376
-                $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
377
-                $hooks_ref      = array_merge($hooks_ref, $extended_hooks);
378
-            }
379
-        }
380
-        //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
381
-        //first make sure we've got unique values
382
-        $hooks_ref = array_unique($hooks_ref);
383
-        //now let's loop and require!
384
-        foreach ($hooks_ref as $path) {
385
-            require_once($path);
386
-        }
387
-        //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
388
-        global $ee_menu_slugs;
389
-        $ee_menu_slugs = $this->_menu_slugs;
390
-        //we need to loop again to run any early code
391
-        foreach ($installed_refs as $page => $path) {
392
-            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
393
-                $this->_installed_pages[$page]->do_initial_loads();
394
-            }
395
-        }
396
-        do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
397
-    }
398
-
399
-
400
-
401
-    /**
402
-     * get_admin_page_object
403
-     *
404
-     * @param string $page_slug
405
-     * @return EE_Admin_Page
406
-     */
407
-    public function get_admin_page_object($page_slug = '')
408
-    {
409
-        if (isset($this->_installed_pages[$page_slug])) {
410
-            return $this->_installed_pages[$page_slug]->loaded_page_object();
411
-        }
412
-        return null;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * _get_classname_for_admin_page
419
-     * generates an "Admin Page" class based on the directory  name
420
-     *
421
-     * @param $dir_name
422
-     * @return string
423
-     */
424
-    private function _get_classname_for_admin_page($dir_name = '')
425
-    {
426
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
427
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * _get_classname_for_admin_init_page
434
-     * generates an "Admin Page Init" class based on the directory  name
435
-     *
436
-     * @param $dir_name
437
-     * @return string
438
-     */
439
-    private function _get_classname_for_admin_init_page($dir_name = '')
440
-    {
441
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
442
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     * _load_admin_page
449
-     * Loads and instantiates page_init object for a single EE_admin page.
450
-     *
451
-     * @param  string $page page_reference
452
-     * @param string  $path
453
-     * @throws EE_Error
454
-     * @return object|bool  return page object if valid, bool false if not.
455
-     */
456
-    private function _load_admin_page($page = '', $path = '')
457
-    {
458
-        $class_name = $this->_get_classname_for_admin_init_page($page);
459
-        EE_Registry::instance()->load_file($path, $class_name, 'core');
460
-        if (! class_exists($class_name)) {
461
-            $inner_error_msg = '<br />' . sprintf(
462
-                    esc_html__(
463
-                        'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
464
-                        'event_espresso'
465
-                    ),
466
-                    '<strong>' . $class_name . '</strong>'
467
-                );
468
-            $error_msg[]     = sprintf(
469
-                __('Something went wrong with loading the %s admin page.', 'event_espresso'),
470
-                $page
471
-            );
472
-            $error_msg[]     = $error_msg[0]
473
-                               . "\r\n"
474
-                               . sprintf(
475
-                                   esc_html__(
476
-                                       'There is no Init class in place for the %s admin page.',
477
-                                       'event_espresso'
478
-                                   ),
479
-                                   $page
480
-                               )
481
-                               . $inner_error_msg;
482
-            throw new EE_Error(implode('||', $error_msg));
483
-        }
484
-        $a = new ReflectionClass($class_name);
485
-        return $a->newInstance();
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * set_menus
492
-     * This method sets up the menus for EE Admin Pages
493
-     *
494
-     * @access private
495
-     * @return void
496
-     */
497
-    public function set_menus()
498
-    {
499
-        //prep the menu pages (sort, group.)
500
-        $this->_prep_pages();
501
-        foreach ($this->_prepped_menu_maps as $menu_map) {
502
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
503
-                $menu_map->add_menu_page(false);
504
-            }
505
-        }
506
-    }
507
-
508
-
509
-    /**
510
-     * set_network_menus
511
-     * This method sets up the menus for network EE Admin Pages.
512
-     * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
513
-     * are only added to the menu map if they are intended for the admin menu
514
-     *
515
-     * @return void
516
-     */
517
-    public function set_network_menus()
518
-    {
519
-        $this->_prep_pages();
520
-        foreach ($this->_prepped_menu_maps as $menu_map) {
521
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
522
-                $menu_map->add_menu_page(true);
523
-            }
524
-        }
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * _prep_pages
531
-     * sets the _prepped_menu_maps property
532
-     *
533
-     * @access private
534
-     * @throws EE_Error
535
-     * @return void
536
-     */
537
-    private function _prep_pages()
538
-    {
539
-        $pages_array = array();
540
-        //rearrange _admin_menu_groups to be indexed by group slug.
541
-        $menu_groups = $this->_rearrange_menu_groups();
542
-        foreach ($this->_installed_pages as $page) {
543
-            if ($page instanceof EE_Admin_page_Init) {
544
-                $page_map = $page->get_menu_map();
545
-                //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
546
-                if (is_array($page_map) || empty($page_map)) {
547
-                      new PersistentAdminNotice(
548
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
549
-                        sprintf(
550
-                            __(
551
-                                'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
552
-                                'event_espresso'
553
-                            ),
554
-                            $page->label
555
-                        )
556
-                    );
557
-                    continue;
558
-                }
559
-                //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
560
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
561
-                    throw new EE_Error(
562
-                        sprintf(
563
-                            __(
564
-                                'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
565
-                                'event_espresso'
566
-                            ),
567
-                            $page->label,
568
-                            $page_map
569
-                        )
570
-                    );
571
-                }
572
-                //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
573
-                if (empty($page_map->maintenance_mode_parent)
574
-                    && EE_Maintenance_Mode::instance()->level()
575
-                       == EE_Maintenance_Mode::level_2_complete_maintenance) {
576
-                    continue;
577
-                }
578
-                //assign to group (remember $page_map has the admin page stored in it).
579
-                $pages_array[$page_map->menu_group][] = $page_map;
580
-            }
581
-        }
582
-        if (empty($pages_array)) {
583
-            throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
584
-        }
585
-        //let's sort the groups, make sure it's a valid group, add header (if to show).
586
-        foreach ($pages_array as $group => $menu_maps) {
587
-            //valid_group?
588
-            if (! array_key_exists($group, $menu_groups)) {
589
-                continue;
590
-            }
591
-            //sort pages.
592
-            usort($menu_maps, array($this, '_sort_menu_maps'));
593
-            //prepend header
594
-            array_unshift($menu_maps, $menu_groups[$group]);
595
-            //reset $pages_array with prepped data
596
-            $pages_array[$group] = $menu_maps;
597
-        }
598
-        //now let's setup the _prepped_menu_maps property
599
-        foreach ($menu_groups as $group => $group_objs) {
600
-            if (isset($pages_array[$group])) {
601
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]);
602
-            }
603
-        }/**/
604
-    }
605
-
606
-
607
-    /**
608
-     * This method is the "workhorse" for detecting and setting up caffeinated functionality.
609
-     * In this method there are three checks being done:
610
-     * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
611
-     * array) etc.  (new page sets are found in caffeinated/new/{page})
612
-     * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
613
-     * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
614
-     * Extend_Events_Admin_Page extends Events_Admin_Page.
615
-     * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
616
-     * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
617
-     * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
618
-     * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
619
-     * admin_pages)
620
-     *
621
-     * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
622
-     *                              loaded.
623
-     * @return array
624
-     */
625
-    private function _set_caffeinated($installed_refs)
626
-    {
627
-
628
-        //first let's check if there IS a caffeinated folder. If there is not then lets get out.
629
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
630
-            return $installed_refs;
631
-        }
632
-        $this->_define_caffeinated_constants();
633
-        $exclude = array('tickets');
634
-        //okay let's setup an "New" pages first (we'll return installed refs later)
635
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
636
-        if ($new_admin_screens) {
637
-            foreach ($new_admin_screens as $admin_screen) {
638
-                // files and anything in the exclude array need not apply
639
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
640
-                    // these folders represent the different NEW EE admin pages
641
-                    $installed_refs[basename($admin_screen)] = $admin_screen;
642
-                    // set autoloaders for our admin page classes based on included path information
643
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
644
-                    //					$this->_caf_autoloader[] = array(
645
-                    //						'dir' => 'new',
646
-                    //						'folder' => basename( $admin_screen )
647
-                    //					);
648
-                }
649
-            }
650
-        }
651
-        //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
652
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
653
-        if ($extends) {
654
-            foreach ($extends as $extend) {
655
-                if (is_dir($extend)) {
656
-                    $extend_ref = basename($extend);
657
-                    //now let's make sure there is a file that matches the expected format
658
-                    $filename                                              = str_replace(
659
-                        ' ',
660
-                        '_',
661
-                        ucwords(
662
-                            str_replace(
663
-                                '_',
664
-                                ' ',
665
-                                $extend_ref
666
-                            )
667
-                        )
668
-                    );
669
-                    $filename                                              = 'Extend_' . $filename . '_Admin_Page';
670
-                    $this->_caffeinated_extends[$extend_ref]['path']       = str_replace(
671
-                        array('\\', '/'),
672
-                        DS,
673
-                        EE_CORE_CAF_ADMIN
674
-                        . 'extend'
675
-                        . DS
676
-                        . $extend_ref
677
-                        . DS
678
-                        . $filename
679
-                        . '.core.php'
680
-                    );
681
-                    $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
682
-                    // set autoloaders for our admin page classes based on included path information
683
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
684
-                    //					$this->_caf_autoloader[] = array(
685
-                    //						'dir' => 'extend',
686
-                    //						'folder' => $extend_ref
687
-                    //					);
688
-                }
689
-            }
690
-        }
691
-        //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
692
-        $ee_admin_hooks = array();
693
-        $hooks          = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
694
-        if ($hooks) {
695
-            foreach ($hooks as $hook) {
696
-                if (is_readable($hook)) {
697
-                    require_once $hook;
698
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
699
-                    $classname = str_replace('.class.php', '', $classname);
700
-                    if (class_exists($classname)) {
701
-                        $a                = new ReflectionClass($classname);
702
-                        $ee_admin_hooks[] = $a->newInstance();
703
-                    }
704
-                }
705
-            }
706
-        }/**/
707
-        $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
708
-        return $installed_refs;
709
-    }
710
-
711
-
712
-
713
-
714
-
715
-    /**
716
-     * Initial autoloader registration
717
-     * This just sets up the autoloader for the root admin files
718
-     *
719
-     * @param  string $className incoming classname to check for autoload
720
-     * @return void
721
-     */
722
-    //	public function init_autoloaders( $className ) {
723
-    //		$dir_ref = array(
724
-    //			EE_ADMIN => array('core', 'class')
725
-    //		);
726
-    //		EEH_Autoloader::try_autoload($dir_ref, $className );
727
-    //	}
728
-    /**
729
-     * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the
730
-     * caffeinated folders.
731
-     *
732
-     * @access public
733
-     * @param  string $className in coming classname being called
734
-     * @return void
735
-     */
736
-    //	public function caffeinated_autoloaders( $className ) {
737
-    //		//let's setup an array of paths to check (for each subsystem)
738
-    //		$dir_ref = array();
739
-    //		foreach ( $this->_caf_autoloader as $pathinfo) {
740
-    //			$dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class');
741
-    //		}
742
-    //
743
-    //		EEH_Autoloader::try_autoload($dir_ref, $className );
744
-    //	}
745
-    /**
746
-     * Utility method for sorting the _menu_maps (callback for usort php function)
747
-     *
748
-     * @since  4.4.0
749
-     * @param  EE_Admin_Page_Menu_Map $a menu_map object
750
-     * @param  EE_Admin_Page_Menu_Map $b being compared to
751
-     * @return int    sort order
752
-     */
753
-    private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
754
-    {
755
-        if ($a->menu_order == $b->menu_order) {
756
-            return 0;
757
-        }
758
-        return ($a->menu_order < $b->menu_order) ? -1 : 1;
759
-    }
760
-
761
-
762
-
763
-    /**
764
-     * _default_header_link
765
-     * This is just a dummy method to use with header submenu items
766
-     *
767
-     * @return bool false
768
-     */
769
-    public function _default_header_link()
770
-    {
771
-        return false;
772
-    }
31
+	/**
32
+	 * _installed_pages
33
+	 * objects for page_init objects detected and loaded
34
+	 *
35
+	 * @access private
36
+	 * @var \EE_Admin_Page_Init[]
37
+	 */
38
+	private $_installed_pages = array();
39
+
40
+
41
+
42
+	/**
43
+	 * this is used to hold the registry of menu slugs for all the installed admin pages
44
+	 *
45
+	 * @var array
46
+	 */
47
+	private $_menu_slugs = array();
48
+
49
+
50
+	/**
51
+	 * _caffeinated_extends
52
+	 * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
53
+	 * pieces needed to do so).  This property is defined in the _set_caffeinated method.
54
+	 *
55
+	 * @var array
56
+	 */
57
+	private $_caffeinated_extends = array();
58
+
59
+
60
+
61
+	/**
62
+	 * _current_caf_extend_slug
63
+	 * This property is used for holding the page slug that is required for referencing the correct
64
+	 * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
65
+	 *
66
+	 * @var array
67
+	 */
68
+	private $_current_caf_extend_slug;
69
+
70
+
71
+
72
+	/**
73
+	 * _caf_autoloader
74
+	 * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the
75
+	 * caffeinated/new directory.  This array is then used to setup a corresponding dynamic autoloader for these pages
76
+	 * classes.
77
+	 *
78
+	 * @var array
79
+	 */
80
+	//	private $_caf_autoloader = array();
81
+	/**
82
+	 * _prepped_menu_maps
83
+	 * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
84
+	 *
85
+	 * @since  4.4.0
86
+	 * @var EE_Admin_Page_Menu_Map[]
87
+	 */
88
+	private $_prepped_menu_maps = array();
89
+
90
+
91
+
92
+	/**
93
+	 * _admin_menu_groups
94
+	 * array that holds the group headings and details for
95
+	 *
96
+	 * @access private
97
+	 * @var array
98
+	 */
99
+	private $_admin_menu_groups = array();
100
+
101
+
102
+
103
+	/**
104
+	 * This property will hold the hook file for setting up the filter that does all the connections between admin
105
+	 * pages.
106
+	 *
107
+	 * @var string
108
+	 */
109
+	public $hook_file;
110
+
111
+
112
+
113
+	/**
114
+	 * constructor
115
+	 *
116
+	 * @access public
117
+	 * @return \EE_Admin_Page_Loader
118
+	 */
119
+	public function __construct()
120
+	{
121
+		//load menu_map classes
122
+		EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
123
+		//define the default "groups" for the admin_pages
124
+		$this->_set_menu_groups();
125
+		//let's set default autoloaders.  Note that this just sets autoloaders for root admin files.
126
+		//		spl_autoload_register( array( $this, 'init_autoloaders') );
127
+		//let's do a scan and see what installed pages we have
128
+		$this->_get_installed_pages();
129
+		//set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
130
+		add_action('admin_menu', array($this, 'set_menus'));
131
+		add_action('network_admin_menu', array($this, 'set_network_menus'));
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
138
+	 * files in the caffeinated folder.
139
+	 *
140
+	 * @access private
141
+	 * @return void
142
+	 */
143
+	private function _define_caffeinated_constants()
144
+	{
145
+		if (! defined('EE_CORE_CAF_ADMIN')) {
146
+			define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
147
+			define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
148
+			define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
149
+			define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
150
+			define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
151
+			define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * _set_menu_groups
159
+	 * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	private function _set_menu_groups()
165
+	{
166
+
167
+		//set array of EE_Admin_Page_Menu_Group objects
168
+		$groups = array(
169
+			'main'       => new EE_Admin_Page_Menu_Group(
170
+				array(
171
+					'menu_label'   => __('Main', 'event_espresso'),
172
+					'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
173
+					'menu_slug'    => 'main',
174
+					'capability'   => 'ee_read_ee',
175
+					'menu_order'   => 0,
176
+					'parent_slug'  => 'espresso_events',
177
+				)
178
+			),
179
+			'management' => new EE_Admin_Page_Menu_Group(
180
+				array(
181
+					'menu_label'   => __('Management', 'event_espresso'),
182
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
183
+					'menu_slug'    => 'management',
184
+					'capability'   => 'ee_read_ee',
185
+					'menu_order'   => 10,
186
+					'parent_slug'  => 'espresso_events',
187
+				)
188
+			),
189
+			'settings'   => new EE_Admin_Page_Menu_Group(
190
+				array(
191
+					'menu_label'   => __('Settings', 'event_espresso'),
192
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
193
+					'menu_slug'    => 'settings',
194
+					'capability'   => 'ee_read_ee',
195
+					'menu_order'   => 30,
196
+					'parent_slug'  => 'espresso_events',
197
+				)
198
+			),
199
+			'templates'  => new EE_Admin_Page_Menu_Group(
200
+				array(
201
+					'menu_label'   => __('Templates', 'event_espresso'),
202
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
203
+					'menu_slug'    => 'templates',
204
+					'capability'   => 'ee_read_ee',
205
+					'menu_order'   => 40,
206
+					'parent_slug'  => 'espresso_events',
207
+				)
208
+			),
209
+			'extras'     => new EE_Admin_Page_Menu_Group(
210
+				array(
211
+					'menu_label'              => __('Extras', 'event_espresso'),
212
+					'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
213
+					'menu_slug'               => 'extras',
214
+					'capability'              => 'ee_read_ee',
215
+					'menu_order'              => 50,
216
+					'parent_slug'             => 'espresso_events',
217
+					'maintenance_mode_parent' => 'espresso_maintenance_settings',
218
+				)
219
+			),
220
+			'tools'      => new EE_Admin_Page_Menu_Group(
221
+				array(
222
+					'menu_label'   => __("Tools", "event_espresso"),
223
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
224
+					'menu_slug'    => 'tools',
225
+					'capability'   => 'ee_read_ee',
226
+					'menu_order'   => 60,
227
+					'parent_slug'  => 'espresso_events',
228
+				)
229
+			),
230
+			'addons'     => new EE_Admin_Page_Menu_Group(
231
+				array(
232
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
233
+					'menu_label'   => __('Add-ons', 'event_espresso'),
234
+					'menu_slug'    => 'addons',
235
+					'capability'   => 'ee_read_ee',
236
+					'menu_order'   => 20,
237
+					'parent_slug'  => 'espresso_events',
238
+				)
239
+			),
240
+		);
241
+		$this->_admin_menu_groups = apply_filters(
242
+			'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
243
+			$groups
244
+		);
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
251
+	 * slug.  The other utility with this function is it validates that all the groups are instances of
252
+	 * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
253
+	 *
254
+	 * @since  4.4.0
255
+	 * @throws \EE_Error
256
+	 * @return EE_Admin_Page_Menu_Group[]
257
+	 */
258
+	private function _rearrange_menu_groups()
259
+	{
260
+		$groups = array();
261
+		//first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
262
+		usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
263
+		foreach ($this->_admin_menu_groups as $group) {
264
+			if (! $group instanceof EE_Admin_Page_Menu_Group) {
265
+				throw new EE_Error(
266
+					sprintf(
267
+						__(
268
+							'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
269
+							'event_espresso'
270
+						),
271
+						print_r($group, true)
272
+					)
273
+				);
274
+			}
275
+			$groups[$group->menu_slug] = $group;
276
+		}
277
+		return $groups;
278
+	}
279
+
280
+
281
+
282
+	/**
283
+	 * _get_installed_pages
284
+	 * This just gets the list of installed EE_Admin_pages.
285
+	 *
286
+	 * @access private
287
+	 * @throws EE_Error
288
+	 * @return void
289
+	 */
290
+	private function _get_installed_pages()
291
+	{
292
+		$installed_refs = array();
293
+		$exclude        = array('assets', 'templates');
294
+		// grab everything in the  admin core directory
295
+		$admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
296
+		if ($admin_screens) {
297
+			foreach ($admin_screens as $admin_screen) {
298
+				// files and anything in the exclude array need not apply
299
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
300
+					// these folders represent the different EE admin pages
301
+					$installed_refs[basename($admin_screen)] = $admin_screen;
302
+				}
303
+			}
304
+		}
305
+		if (empty($installed_refs)) {
306
+			$error_msg[] = __(
307
+				'There are no EE_Admin pages detected, it looks like EE did not install properly',
308
+				'event_espresso'
309
+			);
310
+			$error_msg[] = $error_msg[0] . "\r\n" . sprintf(
311
+					__(
312
+						'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
313
+						'event_espresso'
314
+					),
315
+					EE_ADMIN_PAGES
316
+				);
317
+			throw new EE_Error(implode('||', $error_msg));
318
+		}
319
+		//this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
320
+		$installed_refs = $this->_set_caffeinated($installed_refs);
321
+		//allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
322
+		$installed_refs             = apply_filters(
323
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
324
+			$installed_refs
325
+		);
326
+		$this->_caffeinated_extends = apply_filters(
327
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
328
+			$this->_caffeinated_extends
329
+		);
330
+		//loop through admin pages and setup the $_installed_pages array.
331
+		$hooks_ref = array();
332
+		foreach ($installed_refs as $page => $path) {
333
+			// set autoloaders for our admin page classes based on included path information
334
+			EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
335
+			// build list of installed pages
336
+			$this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
337
+			// verify returned object
338
+			if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
339
+				if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
340
+					continue;
341
+				}
342
+				//skip if in full maintenance mode and maintenance_mode_parent is set
343
+				$maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
344
+				if (empty($maintenance_mode_parent)
345
+					&& EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
346
+				) {
347
+					unset($installed_refs[$page]);
348
+					continue;
349
+				}
350
+				$menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug;
351
+				$this->_menu_slugs[$menu_slug] = $page;
352
+				//flag for register hooks on extended pages b/c extended pages use the default INIT.
353
+				$extend = false;
354
+				//now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
355
+				if (isset($this->_caffeinated_extends[$page])) {
356
+					$this->_current_caf_extend_slug = $page;
357
+					$admin_page_name = $this->_installed_pages[$page]->get_admin_page_name();
358
+					$caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path'];
359
+					$caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page'];
360
+					add_filter(
361
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
362
+						function($path_to_file) use ($caf_path) {
363
+							return $caf_path;
364
+						}
365
+					);
366
+					add_filter(
367
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
368
+						function ($admin_page) use ($caf_admin_page)
369
+						{
370
+							return $caf_admin_page;
371
+						}
372
+					);
373
+					$extend = true;
374
+				}
375
+				//let's do the registered hooks
376
+				$extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
377
+				$hooks_ref      = array_merge($hooks_ref, $extended_hooks);
378
+			}
379
+		}
380
+		//the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
381
+		//first make sure we've got unique values
382
+		$hooks_ref = array_unique($hooks_ref);
383
+		//now let's loop and require!
384
+		foreach ($hooks_ref as $path) {
385
+			require_once($path);
386
+		}
387
+		//make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
388
+		global $ee_menu_slugs;
389
+		$ee_menu_slugs = $this->_menu_slugs;
390
+		//we need to loop again to run any early code
391
+		foreach ($installed_refs as $page => $path) {
392
+			if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
393
+				$this->_installed_pages[$page]->do_initial_loads();
394
+			}
395
+		}
396
+		do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
397
+	}
398
+
399
+
400
+
401
+	/**
402
+	 * get_admin_page_object
403
+	 *
404
+	 * @param string $page_slug
405
+	 * @return EE_Admin_Page
406
+	 */
407
+	public function get_admin_page_object($page_slug = '')
408
+	{
409
+		if (isset($this->_installed_pages[$page_slug])) {
410
+			return $this->_installed_pages[$page_slug]->loaded_page_object();
411
+		}
412
+		return null;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * _get_classname_for_admin_page
419
+	 * generates an "Admin Page" class based on the directory  name
420
+	 *
421
+	 * @param $dir_name
422
+	 * @return string
423
+	 */
424
+	private function _get_classname_for_admin_page($dir_name = '')
425
+	{
426
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
427
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * _get_classname_for_admin_init_page
434
+	 * generates an "Admin Page Init" class based on the directory  name
435
+	 *
436
+	 * @param $dir_name
437
+	 * @return string
438
+	 */
439
+	private function _get_classname_for_admin_init_page($dir_name = '')
440
+	{
441
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
442
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 * _load_admin_page
449
+	 * Loads and instantiates page_init object for a single EE_admin page.
450
+	 *
451
+	 * @param  string $page page_reference
452
+	 * @param string  $path
453
+	 * @throws EE_Error
454
+	 * @return object|bool  return page object if valid, bool false if not.
455
+	 */
456
+	private function _load_admin_page($page = '', $path = '')
457
+	{
458
+		$class_name = $this->_get_classname_for_admin_init_page($page);
459
+		EE_Registry::instance()->load_file($path, $class_name, 'core');
460
+		if (! class_exists($class_name)) {
461
+			$inner_error_msg = '<br />' . sprintf(
462
+					esc_html__(
463
+						'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
464
+						'event_espresso'
465
+					),
466
+					'<strong>' . $class_name . '</strong>'
467
+				);
468
+			$error_msg[]     = sprintf(
469
+				__('Something went wrong with loading the %s admin page.', 'event_espresso'),
470
+				$page
471
+			);
472
+			$error_msg[]     = $error_msg[0]
473
+							   . "\r\n"
474
+							   . sprintf(
475
+								   esc_html__(
476
+									   'There is no Init class in place for the %s admin page.',
477
+									   'event_espresso'
478
+								   ),
479
+								   $page
480
+							   )
481
+							   . $inner_error_msg;
482
+			throw new EE_Error(implode('||', $error_msg));
483
+		}
484
+		$a = new ReflectionClass($class_name);
485
+		return $a->newInstance();
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * set_menus
492
+	 * This method sets up the menus for EE Admin Pages
493
+	 *
494
+	 * @access private
495
+	 * @return void
496
+	 */
497
+	public function set_menus()
498
+	{
499
+		//prep the menu pages (sort, group.)
500
+		$this->_prep_pages();
501
+		foreach ($this->_prepped_menu_maps as $menu_map) {
502
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
503
+				$menu_map->add_menu_page(false);
504
+			}
505
+		}
506
+	}
507
+
508
+
509
+	/**
510
+	 * set_network_menus
511
+	 * This method sets up the menus for network EE Admin Pages.
512
+	 * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
513
+	 * are only added to the menu map if they are intended for the admin menu
514
+	 *
515
+	 * @return void
516
+	 */
517
+	public function set_network_menus()
518
+	{
519
+		$this->_prep_pages();
520
+		foreach ($this->_prepped_menu_maps as $menu_map) {
521
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
522
+				$menu_map->add_menu_page(true);
523
+			}
524
+		}
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * _prep_pages
531
+	 * sets the _prepped_menu_maps property
532
+	 *
533
+	 * @access private
534
+	 * @throws EE_Error
535
+	 * @return void
536
+	 */
537
+	private function _prep_pages()
538
+	{
539
+		$pages_array = array();
540
+		//rearrange _admin_menu_groups to be indexed by group slug.
541
+		$menu_groups = $this->_rearrange_menu_groups();
542
+		foreach ($this->_installed_pages as $page) {
543
+			if ($page instanceof EE_Admin_page_Init) {
544
+				$page_map = $page->get_menu_map();
545
+				//if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
546
+				if (is_array($page_map) || empty($page_map)) {
547
+					  new PersistentAdminNotice(
548
+						'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
549
+						sprintf(
550
+							__(
551
+								'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
552
+								'event_espresso'
553
+							),
554
+							$page->label
555
+						)
556
+					);
557
+					continue;
558
+				}
559
+				//if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
560
+				if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
561
+					throw new EE_Error(
562
+						sprintf(
563
+							__(
564
+								'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
565
+								'event_espresso'
566
+							),
567
+							$page->label,
568
+							$page_map
569
+						)
570
+					);
571
+				}
572
+				//use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
573
+				if (empty($page_map->maintenance_mode_parent)
574
+					&& EE_Maintenance_Mode::instance()->level()
575
+					   == EE_Maintenance_Mode::level_2_complete_maintenance) {
576
+					continue;
577
+				}
578
+				//assign to group (remember $page_map has the admin page stored in it).
579
+				$pages_array[$page_map->menu_group][] = $page_map;
580
+			}
581
+		}
582
+		if (empty($pages_array)) {
583
+			throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
584
+		}
585
+		//let's sort the groups, make sure it's a valid group, add header (if to show).
586
+		foreach ($pages_array as $group => $menu_maps) {
587
+			//valid_group?
588
+			if (! array_key_exists($group, $menu_groups)) {
589
+				continue;
590
+			}
591
+			//sort pages.
592
+			usort($menu_maps, array($this, '_sort_menu_maps'));
593
+			//prepend header
594
+			array_unshift($menu_maps, $menu_groups[$group]);
595
+			//reset $pages_array with prepped data
596
+			$pages_array[$group] = $menu_maps;
597
+		}
598
+		//now let's setup the _prepped_menu_maps property
599
+		foreach ($menu_groups as $group => $group_objs) {
600
+			if (isset($pages_array[$group])) {
601
+				$this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]);
602
+			}
603
+		}/**/
604
+	}
605
+
606
+
607
+	/**
608
+	 * This method is the "workhorse" for detecting and setting up caffeinated functionality.
609
+	 * In this method there are three checks being done:
610
+	 * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
611
+	 * array) etc.  (new page sets are found in caffeinated/new/{page})
612
+	 * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
613
+	 * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
614
+	 * Extend_Events_Admin_Page extends Events_Admin_Page.
615
+	 * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
616
+	 * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
617
+	 * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
618
+	 * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
619
+	 * admin_pages)
620
+	 *
621
+	 * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
622
+	 *                              loaded.
623
+	 * @return array
624
+	 */
625
+	private function _set_caffeinated($installed_refs)
626
+	{
627
+
628
+		//first let's check if there IS a caffeinated folder. If there is not then lets get out.
629
+		if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
630
+			return $installed_refs;
631
+		}
632
+		$this->_define_caffeinated_constants();
633
+		$exclude = array('tickets');
634
+		//okay let's setup an "New" pages first (we'll return installed refs later)
635
+		$new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
636
+		if ($new_admin_screens) {
637
+			foreach ($new_admin_screens as $admin_screen) {
638
+				// files and anything in the exclude array need not apply
639
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
640
+					// these folders represent the different NEW EE admin pages
641
+					$installed_refs[basename($admin_screen)] = $admin_screen;
642
+					// set autoloaders for our admin page classes based on included path information
643
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
644
+					//					$this->_caf_autoloader[] = array(
645
+					//						'dir' => 'new',
646
+					//						'folder' => basename( $admin_screen )
647
+					//					);
648
+				}
649
+			}
650
+		}
651
+		//let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
652
+		$extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
653
+		if ($extends) {
654
+			foreach ($extends as $extend) {
655
+				if (is_dir($extend)) {
656
+					$extend_ref = basename($extend);
657
+					//now let's make sure there is a file that matches the expected format
658
+					$filename                                              = str_replace(
659
+						' ',
660
+						'_',
661
+						ucwords(
662
+							str_replace(
663
+								'_',
664
+								' ',
665
+								$extend_ref
666
+							)
667
+						)
668
+					);
669
+					$filename                                              = 'Extend_' . $filename . '_Admin_Page';
670
+					$this->_caffeinated_extends[$extend_ref]['path']       = str_replace(
671
+						array('\\', '/'),
672
+						DS,
673
+						EE_CORE_CAF_ADMIN
674
+						. 'extend'
675
+						. DS
676
+						. $extend_ref
677
+						. DS
678
+						. $filename
679
+						. '.core.php'
680
+					);
681
+					$this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
682
+					// set autoloaders for our admin page classes based on included path information
683
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
684
+					//					$this->_caf_autoloader[] = array(
685
+					//						'dir' => 'extend',
686
+					//						'folder' => $extend_ref
687
+					//					);
688
+				}
689
+			}
690
+		}
691
+		//let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
692
+		$ee_admin_hooks = array();
693
+		$hooks          = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
694
+		if ($hooks) {
695
+			foreach ($hooks as $hook) {
696
+				if (is_readable($hook)) {
697
+					require_once $hook;
698
+					$classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
699
+					$classname = str_replace('.class.php', '', $classname);
700
+					if (class_exists($classname)) {
701
+						$a                = new ReflectionClass($classname);
702
+						$ee_admin_hooks[] = $a->newInstance();
703
+					}
704
+				}
705
+			}
706
+		}/**/
707
+		$ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
708
+		return $installed_refs;
709
+	}
710
+
711
+
712
+
713
+
714
+
715
+	/**
716
+	 * Initial autoloader registration
717
+	 * This just sets up the autoloader for the root admin files
718
+	 *
719
+	 * @param  string $className incoming classname to check for autoload
720
+	 * @return void
721
+	 */
722
+	//	public function init_autoloaders( $className ) {
723
+	//		$dir_ref = array(
724
+	//			EE_ADMIN => array('core', 'class')
725
+	//		);
726
+	//		EEH_Autoloader::try_autoload($dir_ref, $className );
727
+	//	}
728
+	/**
729
+	 * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the
730
+	 * caffeinated folders.
731
+	 *
732
+	 * @access public
733
+	 * @param  string $className in coming classname being called
734
+	 * @return void
735
+	 */
736
+	//	public function caffeinated_autoloaders( $className ) {
737
+	//		//let's setup an array of paths to check (for each subsystem)
738
+	//		$dir_ref = array();
739
+	//		foreach ( $this->_caf_autoloader as $pathinfo) {
740
+	//			$dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class');
741
+	//		}
742
+	//
743
+	//		EEH_Autoloader::try_autoload($dir_ref, $className );
744
+	//	}
745
+	/**
746
+	 * Utility method for sorting the _menu_maps (callback for usort php function)
747
+	 *
748
+	 * @since  4.4.0
749
+	 * @param  EE_Admin_Page_Menu_Map $a menu_map object
750
+	 * @param  EE_Admin_Page_Menu_Map $b being compared to
751
+	 * @return int    sort order
752
+	 */
753
+	private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
754
+	{
755
+		if ($a->menu_order == $b->menu_order) {
756
+			return 0;
757
+		}
758
+		return ($a->menu_order < $b->menu_order) ? -1 : 1;
759
+	}
760
+
761
+
762
+
763
+	/**
764
+	 * _default_header_link
765
+	 * This is just a dummy method to use with header submenu items
766
+	 *
767
+	 * @return bool false
768
+	 */
769
+	public function _default_header_link()
770
+	{
771
+		return false;
772
+	}
773 773
 
774 774
 
775 775
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice;
3 3
 use EventEspresso\core\exceptions\InvalidDataTypeException;
4 4
 
5
-if (!defined('EVENT_ESPRESSO_VERSION') )
5
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
6 6
 	exit('NO direct script access allowed');
7 7
 
8 8
 
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
      */
143 143
     private function _define_caffeinated_constants()
144 144
     {
145
-        if (! defined('EE_CORE_CAF_ADMIN')) {
146
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
147
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
148
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
149
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
150
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
151
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
145
+        if ( ! defined('EE_CORE_CAF_ADMIN')) {
146
+            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/');
147
+            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/');
148
+            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/');
149
+            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/');
150
+            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/');
151
+            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/');
152 152
         }
153 153
     }
154 154
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
262 262
         usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
263 263
         foreach ($this->_admin_menu_groups as $group) {
264
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
264
+            if ( ! $group instanceof EE_Admin_Page_Menu_Group) {
265 265
                 throw new EE_Error(
266 266
                     sprintf(
267 267
                         __(
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
         $installed_refs = array();
293 293
         $exclude        = array('assets', 'templates');
294 294
         // grab everything in the  admin core directory
295
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
295
+        $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR);
296 296
         if ($admin_screens) {
297 297
             foreach ($admin_screens as $admin_screen) {
298 298
                 // files and anything in the exclude array need not apply
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
                 'There are no EE_Admin pages detected, it looks like EE did not install properly',
308 308
                 'event_espresso'
309 309
             );
310
-            $error_msg[] = $error_msg[0] . "\r\n" . sprintf(
310
+            $error_msg[] = $error_msg[0]."\r\n".sprintf(
311 311
                     __(
312 312
                         'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
313 313
                         'event_espresso'
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
         //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
320 320
         $installed_refs = $this->_set_caffeinated($installed_refs);
321 321
         //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
322
-        $installed_refs             = apply_filters(
322
+        $installed_refs = apply_filters(
323 323
             'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
324 324
             $installed_refs
325 325
         );
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
             $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
337 337
             // verify returned object
338 338
             if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
339
-                if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
339
+                if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
340 340
                     continue;
341 341
                 }
342 342
                 //skip if in full maintenance mode and maintenance_mode_parent is set
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
                     );
366 366
                     add_filter(
367 367
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
368
-                        function ($admin_page) use ($caf_admin_page)
368
+                        function($admin_page) use ($caf_admin_page)
369 369
                         {
370 370
                             return $caf_admin_page;
371 371
                         }
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
     private function _get_classname_for_admin_page($dir_name = '')
425 425
     {
426 426
         $class_name = str_replace('_', ' ', strtolower($dir_name));
427
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
427
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page';
428 428
     }
429 429
 
430 430
 
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
     private function _get_classname_for_admin_init_page($dir_name = '')
440 440
     {
441 441
         $class_name = str_replace('_', ' ', strtolower($dir_name));
442
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
442
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init';
443 443
     }
444 444
 
445 445
 
@@ -457,19 +457,19 @@  discard block
 block discarded – undo
457 457
     {
458 458
         $class_name = $this->_get_classname_for_admin_init_page($page);
459 459
         EE_Registry::instance()->load_file($path, $class_name, 'core');
460
-        if (! class_exists($class_name)) {
461
-            $inner_error_msg = '<br />' . sprintf(
460
+        if ( ! class_exists($class_name)) {
461
+            $inner_error_msg = '<br />'.sprintf(
462 462
                     esc_html__(
463 463
                         'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
464 464
                         'event_espresso'
465 465
                     ),
466
-                    '<strong>' . $class_name . '</strong>'
466
+                    '<strong>'.$class_name.'</strong>'
467 467
                 );
468
-            $error_msg[]     = sprintf(
468
+            $error_msg[] = sprintf(
469 469
                 __('Something went wrong with loading the %s admin page.', 'event_espresso'),
470 470
                 $page
471 471
             );
472
-            $error_msg[]     = $error_msg[0]
472
+            $error_msg[] = $error_msg[0]
473 473
                                . "\r\n"
474 474
                                . sprintf(
475 475
                                    esc_html__(
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
                 //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
546 546
                 if (is_array($page_map) || empty($page_map)) {
547 547
                       new PersistentAdminNotice(
548
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
548
+                        'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION,
549 549
                         sprintf(
550 550
                             __(
551 551
                                 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
                     continue;
558 558
                 }
559 559
                 //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
560
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
560
+                if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) {
561 561
                     throw new EE_Error(
562 562
                         sprintf(
563 563
                             __(
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         //let's sort the groups, make sure it's a valid group, add header (if to show).
586 586
         foreach ($pages_array as $group => $menu_maps) {
587 587
             //valid_group?
588
-            if (! array_key_exists($group, $menu_groups)) {
588
+            if ( ! array_key_exists($group, $menu_groups)) {
589 589
                 continue;
590 590
             }
591 591
             //sort pages.
@@ -626,13 +626,13 @@  discard block
 block discarded – undo
626 626
     {
627 627
 
628 628
         //first let's check if there IS a caffeinated folder. If there is not then lets get out.
629
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
629
+        if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) {
630 630
             return $installed_refs;
631 631
         }
632 632
         $this->_define_caffeinated_constants();
633 633
         $exclude = array('tickets');
634 634
         //okay let's setup an "New" pages first (we'll return installed refs later)
635
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
635
+        $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR);
636 636
         if ($new_admin_screens) {
637 637
             foreach ($new_admin_screens as $admin_screen) {
638 638
                 // files and anything in the exclude array need not apply
@@ -649,13 +649,13 @@  discard block
 block discarded – undo
649 649
             }
650 650
         }
651 651
         //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
652
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
652
+        $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR);
653 653
         if ($extends) {
654 654
             foreach ($extends as $extend) {
655 655
                 if (is_dir($extend)) {
656 656
                     $extend_ref = basename($extend);
657 657
                     //now let's make sure there is a file that matches the expected format
658
-                    $filename                                              = str_replace(
658
+                    $filename = str_replace(
659 659
                         ' ',
660 660
                         '_',
661 661
                         ucwords(
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
                             )
667 667
                         )
668 668
                     );
669
-                    $filename                                              = 'Extend_' . $filename . '_Admin_Page';
669
+                    $filename                                              = 'Extend_'.$filename.'_Admin_Page';
670 670
                     $this->_caffeinated_extends[$extend_ref]['path']       = str_replace(
671 671
                         array('\\', '/'),
672 672
                         DS,
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
         }
691 691
         //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
692 692
         $ee_admin_hooks = array();
693
-        $hooks          = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
693
+        $hooks          = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php');
694 694
         if ($hooks) {
695 695
             foreach ($hooks as $hook) {
696 696
                 if (is_readable($hook)) {
697 697
                     require_once $hook;
698
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
698
+                    $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook);
699 699
                     $classname = str_replace('.class.php', '', $classname);
700 700
                     if (class_exists($classname)) {
701 701
                         $a                = new ReflectionClass($classname);
Please login to merge, or discard this patch.
core/domain/services/registration/CopyRegistrationService.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 use RuntimeException;
15 15
 
16 16
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
17
-    exit('No direct script access allowed');
17
+	exit('No direct script access allowed');
18 18
 }
19 19
 
20 20
 
@@ -32,155 +32,155 @@  discard block
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * @param EE_Registration $target_registration
37
-     * @param EE_Registration $registration_to_copy
38
-     * @return bool
39
-     * @throws UnexpectedEntityException
40
-     * @throws EntityNotFoundException
41
-     * @throws RuntimeException
42
-     * @throws EE_Error
43
-     */
44
-    public function copyRegistrationDetails(
45
-        EE_Registration $target_registration,
46
-        EE_Registration $registration_to_copy
47
-    ) {
48
-        // copy attendee
49
-        $target_registration->set_attendee_id($registration_to_copy->attendee_ID());
50
-        $target_registration->updateStatusBasedOnTotalPaid(false);
51
-        $target_registration->save();
52
-        // get answers to previous reg questions
53
-        $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers());
54
-        // get questions to new event reg form
55
-        $new_event       = $target_registration->event();
56
-        $question_groups = $new_event->question_groups(
57
-            array(
58
-                array(
59
-                    'Event.EVT_ID'                     => $new_event->ID(),
60
-                    'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(),
61
-                ),
62
-                'order_by' => array('QSG_order' => 'ASC'),
63
-            )
64
-        );
65
-        foreach ($question_groups as $question_group) {
66
-            if ($question_group instanceof \EE_Question_Group) {
67
-                foreach ($question_group->questions() as $question) {
68
-                    if ($question instanceof EE_Question) {
69
-                        $this->generateNewAnswer(
70
-                            $question,
71
-                            $target_registration,
72
-                            $answers
73
-                        );
74
-                    }
75
-                }
76
-            }
77
-        }
78
-        return true;
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * @param EE_Answer[] $answers
85
-     * @return array
86
-     * @throws EE_Error
87
-     */
88
-    protected function reindexAnswersByQuestionId(array $answers)
89
-    {
90
-        $reindexed_answers = array();
91
-        foreach ($answers as $answer) {
92
-            if ($answer instanceof EE_Answer) {
93
-                $reindexed_answers[ $answer->question_ID() ] = $answer->value();
94
-            }
95
-        }
96
-        return $reindexed_answers;
97
-    }
98
-
99
-
100
-
101
-    /**
102
-     * @param EE_Question      $question
103
-     * @param EE_Registration  $registration
104
-     * @param                  $previous_answers
105
-     * @return EE_Answer
106
-     * @throws UnexpectedEntityException
107
-     * @throws EE_Error
108
-     */
109
-    protected function generateNewAnswer(
110
-        EE_Question $question,
111
-        EE_Registration $registration,
112
-        $previous_answers
113
-    ) {
114
-        $old_answer_value = isset($previous_answers[ $question->ID() ])
115
-            ? $previous_answers[ $question->ID() ]
116
-            : '';
117
-        $new_answer       = EE_Answer::new_instance(
118
-            array(
119
-                'QST_ID'    => $question->ID(),
120
-                'REG_ID'    => $registration->ID(),
121
-                'ANS_value' => $old_answer_value,
122
-            )
123
-        );
124
-        if ( ! $new_answer instanceof EE_Answer) {
125
-            throw new UnexpectedEntityException($new_answer, 'EE_Answer');
126
-        }
127
-        $new_answer->save();
128
-        return $new_answer;
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @param EE_Registration $target_registration
135
-     * @param EE_Registration $registration_to_copy
136
-     * @return bool
137
-     * @throws RuntimeException
138
-     * @throws UnexpectedEntityException
139
-     * @throws EE_Error
140
-     */
141
-    public function copyPaymentDetails(
142
-        EE_Registration $target_registration,
143
-        EE_Registration $registration_to_copy
144
-    ) {
145
-        $save = false;
146
-        $previous_registration_payments = $registration_to_copy->registration_payments();
147
-        $new_registration_payment_total = 0;
148
-        $registration_to_copy_total = $registration_to_copy->paid();
149
-        foreach ($previous_registration_payments as $previous_registration_payment) {
150
-            if (
151
-                $previous_registration_payment instanceof EE_Registration_Payment
152
-                && $previous_registration_payment->payment() instanceof EE_Payment
153
-                && $previous_registration_payment->payment()->is_approved()
154
-            ) {
155
-                $payment_amount = $previous_registration_payment->amount();
156
-                $new_registration_payment = EE_Registration_Payment::new_instance(
157
-                    array(
158
-                        'REG_ID'     => $target_registration->ID(),
159
-                        'PAY_ID'     => $previous_registration_payment->payment()->ID(),
160
-                        'RPY_amount' => $payment_amount,
161
-                    )
162
-                );
163
-                if ( ! $new_registration_payment instanceof EE_Registration_Payment) {
164
-                    throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment');
165
-                }
166
-                $new_registration_payment->save();
167
-                // if new reg payment is good, then set old reg payment amount to zero
168
-                $previous_registration_payment->set_amount(0);
169
-                $previous_registration_payment->save();
170
-                // now  increment/decrement payment amounts
171
-                $new_registration_payment_total += $payment_amount;
172
-                $registration_to_copy_total -= $payment_amount;
173
-                $save = true;
174
-            }
175
-        }
176
-        if($save){
177
-            $target_registration->set_paid($new_registration_payment_total);
178
-            $target_registration->save();
179
-            $registration_to_copy->set_paid($registration_to_copy_total);
180
-            $registration_to_copy->save();
181
-        }
182
-        return true;
183
-    }
35
+	/**
36
+	 * @param EE_Registration $target_registration
37
+	 * @param EE_Registration $registration_to_copy
38
+	 * @return bool
39
+	 * @throws UnexpectedEntityException
40
+	 * @throws EntityNotFoundException
41
+	 * @throws RuntimeException
42
+	 * @throws EE_Error
43
+	 */
44
+	public function copyRegistrationDetails(
45
+		EE_Registration $target_registration,
46
+		EE_Registration $registration_to_copy
47
+	) {
48
+		// copy attendee
49
+		$target_registration->set_attendee_id($registration_to_copy->attendee_ID());
50
+		$target_registration->updateStatusBasedOnTotalPaid(false);
51
+		$target_registration->save();
52
+		// get answers to previous reg questions
53
+		$answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers());
54
+		// get questions to new event reg form
55
+		$new_event       = $target_registration->event();
56
+		$question_groups = $new_event->question_groups(
57
+			array(
58
+				array(
59
+					'Event.EVT_ID'                     => $new_event->ID(),
60
+					'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(),
61
+				),
62
+				'order_by' => array('QSG_order' => 'ASC'),
63
+			)
64
+		);
65
+		foreach ($question_groups as $question_group) {
66
+			if ($question_group instanceof \EE_Question_Group) {
67
+				foreach ($question_group->questions() as $question) {
68
+					if ($question instanceof EE_Question) {
69
+						$this->generateNewAnswer(
70
+							$question,
71
+							$target_registration,
72
+							$answers
73
+						);
74
+					}
75
+				}
76
+			}
77
+		}
78
+		return true;
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * @param EE_Answer[] $answers
85
+	 * @return array
86
+	 * @throws EE_Error
87
+	 */
88
+	protected function reindexAnswersByQuestionId(array $answers)
89
+	{
90
+		$reindexed_answers = array();
91
+		foreach ($answers as $answer) {
92
+			if ($answer instanceof EE_Answer) {
93
+				$reindexed_answers[ $answer->question_ID() ] = $answer->value();
94
+			}
95
+		}
96
+		return $reindexed_answers;
97
+	}
98
+
99
+
100
+
101
+	/**
102
+	 * @param EE_Question      $question
103
+	 * @param EE_Registration  $registration
104
+	 * @param                  $previous_answers
105
+	 * @return EE_Answer
106
+	 * @throws UnexpectedEntityException
107
+	 * @throws EE_Error
108
+	 */
109
+	protected function generateNewAnswer(
110
+		EE_Question $question,
111
+		EE_Registration $registration,
112
+		$previous_answers
113
+	) {
114
+		$old_answer_value = isset($previous_answers[ $question->ID() ])
115
+			? $previous_answers[ $question->ID() ]
116
+			: '';
117
+		$new_answer       = EE_Answer::new_instance(
118
+			array(
119
+				'QST_ID'    => $question->ID(),
120
+				'REG_ID'    => $registration->ID(),
121
+				'ANS_value' => $old_answer_value,
122
+			)
123
+		);
124
+		if ( ! $new_answer instanceof EE_Answer) {
125
+			throw new UnexpectedEntityException($new_answer, 'EE_Answer');
126
+		}
127
+		$new_answer->save();
128
+		return $new_answer;
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @param EE_Registration $target_registration
135
+	 * @param EE_Registration $registration_to_copy
136
+	 * @return bool
137
+	 * @throws RuntimeException
138
+	 * @throws UnexpectedEntityException
139
+	 * @throws EE_Error
140
+	 */
141
+	public function copyPaymentDetails(
142
+		EE_Registration $target_registration,
143
+		EE_Registration $registration_to_copy
144
+	) {
145
+		$save = false;
146
+		$previous_registration_payments = $registration_to_copy->registration_payments();
147
+		$new_registration_payment_total = 0;
148
+		$registration_to_copy_total = $registration_to_copy->paid();
149
+		foreach ($previous_registration_payments as $previous_registration_payment) {
150
+			if (
151
+				$previous_registration_payment instanceof EE_Registration_Payment
152
+				&& $previous_registration_payment->payment() instanceof EE_Payment
153
+				&& $previous_registration_payment->payment()->is_approved()
154
+			) {
155
+				$payment_amount = $previous_registration_payment->amount();
156
+				$new_registration_payment = EE_Registration_Payment::new_instance(
157
+					array(
158
+						'REG_ID'     => $target_registration->ID(),
159
+						'PAY_ID'     => $previous_registration_payment->payment()->ID(),
160
+						'RPY_amount' => $payment_amount,
161
+					)
162
+				);
163
+				if ( ! $new_registration_payment instanceof EE_Registration_Payment) {
164
+					throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment');
165
+				}
166
+				$new_registration_payment->save();
167
+				// if new reg payment is good, then set old reg payment amount to zero
168
+				$previous_registration_payment->set_amount(0);
169
+				$previous_registration_payment->save();
170
+				// now  increment/decrement payment amounts
171
+				$new_registration_payment_total += $payment_amount;
172
+				$registration_to_copy_total -= $payment_amount;
173
+				$save = true;
174
+			}
175
+		}
176
+		if($save){
177
+			$target_registration->set_paid($new_registration_payment_total);
178
+			$target_registration->save();
179
+			$registration_to_copy->set_paid($registration_to_copy_total);
180
+			$registration_to_copy->save();
181
+		}
182
+		return true;
183
+	}
184 184
 
185 185
 
186 186
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         $reindexed_answers = array();
91 91
         foreach ($answers as $answer) {
92 92
             if ($answer instanceof EE_Answer) {
93
-                $reindexed_answers[ $answer->question_ID() ] = $answer->value();
93
+                $reindexed_answers[$answer->question_ID()] = $answer->value();
94 94
             }
95 95
         }
96 96
         return $reindexed_answers;
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
         EE_Registration $registration,
112 112
         $previous_answers
113 113
     ) {
114
-        $old_answer_value = isset($previous_answers[ $question->ID() ])
115
-            ? $previous_answers[ $question->ID() ]
114
+        $old_answer_value = isset($previous_answers[$question->ID()])
115
+            ? $previous_answers[$question->ID()]
116 116
             : '';
117 117
         $new_answer       = EE_Answer::new_instance(
118 118
             array(
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
                 $save = true;
174 174
             }
175 175
         }
176
-        if($save){
176
+        if ($save) {
177 177
             $target_registration->set_paid($new_registration_payment_total);
178 178
             $target_registration->save();
179 179
             $registration_to_copy->set_paid($registration_to_copy_total);
Please login to merge, or discard this patch.