Completed
Branch models-cleanup/main (c8075d)
by
unknown
185:05 queued 175:13
created
core/services/request/middleware/PreProductionVersionWarning.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
     public function preProductionVersionAdminNotice()
79 79
     {
80 80
         new PersistentAdminNotice(
81
-            'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION,
81
+            'preProductionVersionAdminNotice_'.EVENT_ESPRESSO_VERSION,
82 82
             $this->warningNotice()
83 83
         );
84 84
     }
Please login to merge, or discard this patch.
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -18,91 +18,91 @@
 block discarded – undo
18 18
 class PreProductionVersionWarning extends Middleware
19 19
 {
20 20
 
21
-    /**
22
-     * converts a Request to a Response
23
-     *
24
-     * @param RequestInterface  $request
25
-     * @param ResponseInterface $response
26
-     * @return ResponseInterface
27
-     */
28
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
29
-    {
30
-        $this->request = $request;
31
-        $this->response = $response;
32
-        $this->displayPreProductionVersionWarning();
33
-        $this->response = $this->processRequestStack($this->request, $this->response);
34
-        return $this->response;
35
-    }
21
+	/**
22
+	 * converts a Request to a Response
23
+	 *
24
+	 * @param RequestInterface  $request
25
+	 * @param ResponseInterface $response
26
+	 * @return ResponseInterface
27
+	 */
28
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
29
+	{
30
+		$this->request = $request;
31
+		$this->response = $response;
32
+		$this->displayPreProductionVersionWarning();
33
+		$this->response = $this->processRequestStack($this->request, $this->response);
34
+		return $this->response;
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
40
-     *
41
-     * @return void
42
-     */
43
-    public function displayPreProductionVersionWarning()
44
-    {
45
-        // skip AJAX requests
46
-        if ($this->request->isAjax()) {
47
-            return;
48
-        }
49
-        // skip stable releases
50
-        if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') {
51
-            return;
52
-        }
53
-        // site admin has authorized use of non-stable release candidate for production
54
-        if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) {
55
-            return;
56
-        }
57
-        // post release candidate warning
58
-        if ($this->request->isAdmin()) {
59
-            add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999);
60
-        } else {
61
-            add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10);
62
-        }
63
-    }
38
+	/**
39
+	 * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public function displayPreProductionVersionWarning()
44
+	{
45
+		// skip AJAX requests
46
+		if ($this->request->isAjax()) {
47
+			return;
48
+		}
49
+		// skip stable releases
50
+		if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') {
51
+			return;
52
+		}
53
+		// site admin has authorized use of non-stable release candidate for production
54
+		if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) {
55
+			return;
56
+		}
57
+		// post release candidate warning
58
+		if ($this->request->isAdmin()) {
59
+			add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999);
60
+		} else {
61
+			add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10);
62
+		}
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * displays admin notice that current version of EE is not a stable release
68
-     *
69
-     * @return void
70
-     * @throws InvalidDataTypeException
71
-     */
72
-    public function preProductionVersionAdminNotice()
73
-    {
74
-        new PersistentAdminNotice(
75
-            'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION,
76
-            $this->warningNotice()
77
-        );
78
-    }
66
+	/**
67
+	 * displays admin notice that current version of EE is not a stable release
68
+	 *
69
+	 * @return void
70
+	 * @throws InvalidDataTypeException
71
+	 */
72
+	public function preProductionVersionAdminNotice()
73
+	{
74
+		new PersistentAdminNotice(
75
+			'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION,
76
+			$this->warningNotice()
77
+		);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * displays message on frontend of site notifying admin that current version of EE is not a stable release
83
-     *
84
-     * @return void
85
-     */
86
-    public function preProductionVersionWarningNotice()
87
-    {
88
-        echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>';
89
-        echo $this->warningNotice();
90
-        echo '</p></div>';
91
-    }
81
+	/**
82
+	 * displays message on frontend of site notifying admin that current version of EE is not a stable release
83
+	 *
84
+	 * @return void
85
+	 */
86
+	public function preProductionVersionWarningNotice()
87
+	{
88
+		echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>';
89
+		echo $this->warningNotice();
90
+		echo '</p></div>';
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * @return string
96
-     */
97
-    private function warningNotice()
98
-    {
99
-        return sprintf(
100
-            esc_html__(
101
-                'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.',
102
-                'event_espresso'
103
-            ),
104
-            '<strong>',
105
-            '</strong>'
106
-        );
107
-    }
94
+	/**
95
+	 * @return string
96
+	 */
97
+	private function warningNotice()
98
+	{
99
+		return sprintf(
100
+			esc_html__(
101
+				'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.',
102
+				'event_espresso'
103
+			),
104
+			'<strong>',
105
+			'</strong>'
106
+		);
107
+	}
108 108
 }
Please login to merge, or discard this patch.
core/request_stack/EE_Request.core.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      *
182 182
      * @deprecated 4.9.53
183 183
      * @param      $key
184
-     * @param null $default
184
+     * @param null|string $default
185 185
      * @return mixed
186 186
      * @throws InvalidArgumentException
187 187
      * @throws InvalidDataTypeException
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
     /**
258 258
      * @deprecated 4.9.53
259
-     * @return mixed
259
+     * @return boolean
260 260
      * @throws InvalidArgumentException
261 261
      * @throws InvalidDataTypeException
262 262
      * @throws InvalidInterfaceException
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
     /**
271 271
      * @deprecated 4.9.53
272
-     * @return mixed
272
+     * @return boolean
273 273
      * @throws InvalidArgumentException
274 274
      * @throws InvalidDataTypeException
275 275
      * @throws InvalidInterfaceException
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 
283 283
     /**
284 284
      * @deprecated 4.9.53
285
-     * @return mixed|string
285
+     * @return string
286 286
      * @throws InvalidArgumentException
287 287
      * @throws InvalidDataTypeException
288 288
      * @throws InvalidInterfaceException
Please login to merge, or discard this patch.
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -18,359 +18,359 @@
 block discarded – undo
18 18
 class EE_Request implements LegacyRequestInterface, InterminableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var RequestInterface $request
23
-     */
24
-    private $request;
25
-
26
-    /**
27
-     * whether current request is for the admin but NOT via AJAX
28
-     *
29
-     * @var boolean $admin
30
-     */
31
-    public $admin = false;
32
-
33
-    /**
34
-     * whether current request is via AJAX
35
-     *
36
-     * @var boolean $ajax
37
-     */
38
-    public $ajax = false;
39
-
40
-    /**
41
-     * whether current request is via AJAX from the frontend of the site
42
-     *
43
-     * @var boolean $front_ajax
44
-     */
45
-    public $front_ajax = false;
46
-
47
-
48
-    /**
49
-     * @deprecated 4.9.53
50
-     * @param array $get
51
-     * @param array $post
52
-     * @param array $cookie
53
-     * @param array $server
54
-     */
55
-    public function __construct(
56
-        array $get = array(),
57
-        array $post = array(),
58
-        array $cookie = array(),
59
-        array $server = array()
60
-    ) {
61
-    }
62
-
63
-
64
-    /**
65
-     * @return RequestInterface
66
-     * @throws InvalidArgumentException
67
-     * @throws InvalidInterfaceException
68
-     * @throws InvalidDataTypeException
69
-     */
70
-    private function request()
71
-    {
72
-        if ($this->request instanceof RequestInterface) {
73
-            return $this->request;
74
-        }
75
-        $loader = LoaderFactory::getLoader();
76
-        $this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface');
77
-        return $this->request;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param RequestInterface $request
83
-     */
84
-    public function setRequest(RequestInterface $request)
85
-    {
86
-        $this->request = $request;
87
-    }
88
-
89
-
90
-    /**
91
-     * @deprecated 4.9.53
92
-     * @return array
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     */
97
-    public function get_params()
98
-    {
99
-        return $this->request()->getParams();
100
-    }
101
-
102
-
103
-    /**
104
-     * @deprecated 4.9.53
105
-     * @return array
106
-     * @throws InvalidArgumentException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     */
110
-    public function post_params()
111
-    {
112
-        return $this->request()->postParams();
113
-    }
114
-
115
-
116
-    /**
117
-     * @deprecated 4.9.53
118
-     * @return array
119
-     * @throws InvalidArgumentException
120
-     * @throws InvalidDataTypeException
121
-     * @throws InvalidInterfaceException
122
-     */
123
-    public function cookie_params()
124
-    {
125
-        return $this->request()->cookieParams();
126
-    }
127
-
128
-
129
-    /**
130
-     * @deprecated 4.9.53
131
-     * @return array
132
-     * @throws InvalidArgumentException
133
-     * @throws InvalidDataTypeException
134
-     * @throws InvalidInterfaceException
135
-     */
136
-    public function server_params()
137
-    {
138
-        return $this->request()->serverParams();
139
-    }
140
-
141
-
142
-    /**
143
-     * returns contents of $_REQUEST
144
-     *
145
-     * @deprecated 4.9.53
146
-     * @return array
147
-     * @throws InvalidArgumentException
148
-     * @throws InvalidDataTypeException
149
-     * @throws InvalidInterfaceException
150
-     */
151
-    public function params()
152
-    {
153
-        return $this->request()->requestParams();
154
-    }
155
-
156
-
157
-    /**
158
-     * @deprecated 4.9.53
159
-     * @param      $key
160
-     * @param      $value
161
-     * @param bool $override_ee
162
-     * @return void
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidInterfaceException
166
-     */
167
-    public function set($key, $value, $override_ee = false)
168
-    {
169
-        $this->request()->setRequestParam($key, $value, $override_ee);
170
-    }
171
-
172
-
173
-    /**
174
-     * returns   the value for a request param if the given key exists
175
-     *
176
-     * @deprecated 4.9.53
177
-     * @param      $key
178
-     * @param null $default
179
-     * @return mixed
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     */
184
-    public function get($key, $default = null)
185
-    {
186
-        return $this->request()->getRequestParam($key, $default);
187
-    }
188
-
189
-
190
-    /**
191
-     * check if param exists
192
-     *
193
-     * @deprecated 4.9.53
194
-     * @param $key
195
-     * @return bool
196
-     * @throws InvalidArgumentException
197
-     * @throws InvalidDataTypeException
198
-     * @throws InvalidInterfaceException
199
-     */
200
-    public function is_set($key)
201
-    {
202
-        return $this->request()->requestParamIsSet($key);
203
-    }
204
-
205
-
206
-    /**
207
-     * remove param
208
-     *
209
-     * @deprecated 4.9.53
210
-     * @param      $key
211
-     * @param bool $unset_from_global_too
212
-     * @throws InvalidArgumentException
213
-     * @throws InvalidDataTypeException
214
-     * @throws InvalidInterfaceException
215
-     */
216
-    public function un_set($key, $unset_from_global_too = false)
217
-    {
218
-        $this->request()->unSetRequestParam($key, $unset_from_global_too);
219
-    }
220
-
221
-
222
-    /**
223
-     * @deprecated 4.9.53
224
-     * @return string
225
-     * @throws InvalidArgumentException
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidInterfaceException
228
-     */
229
-    public function ip_address()
230
-    {
231
-        return $this->request()->ipAddress();
232
-    }
233
-
234
-
235
-    /**
236
-     * @deprecated 4.9.53
237
-     * @return bool
238
-     * @throws InvalidArgumentException
239
-     * @throws InvalidDataTypeException
240
-     * @throws InvalidInterfaceException
241
-     */
242
-    public function isAdmin()
243
-    {
244
-        return $this->request()->isAdmin();
245
-    }
246
-
247
-
248
-    /**
249
-     * @deprecated 4.9.53
250
-     * @return mixed
251
-     * @throws InvalidArgumentException
252
-     * @throws InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     */
255
-    public function isAjax()
256
-    {
257
-        return $this->request()->isAjax();
258
-    }
259
-
260
-
261
-    /**
262
-     * @deprecated 4.9.53
263
-     * @return mixed
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     */
268
-    public function isFrontAjax()
269
-    {
270
-        return $this->request()->isFrontAjax();
271
-    }
272
-
273
-
274
-    /**
275
-     * @deprecated 4.9.53
276
-     * @return mixed|string
277
-     * @throws InvalidArgumentException
278
-     * @throws InvalidDataTypeException
279
-     * @throws InvalidInterfaceException
280
-     */
281
-    public function requestUri()
282
-    {
283
-        return $this->request()->requestUri();
284
-    }
285
-
286
-
287
-    /**
288
-     * @deprecated 4.9.53
289
-     * @return string
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public function userAgent()
295
-    {
296
-        return $this->request()->userAgent();
297
-    }
298
-
299
-
300
-    /**
301
-     * @deprecated 4.9.53
302
-     * @param string $user_agent
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     */
307
-    public function setUserAgent($user_agent = '')
308
-    {
309
-        $this->request()->setUserAgent($user_agent);
310
-    }
311
-
312
-
313
-    /**
314
-     * @deprecated 4.9.53
315
-     * @return bool
316
-     * @throws InvalidArgumentException
317
-     * @throws InvalidDataTypeException
318
-     * @throws InvalidInterfaceException
319
-     */
320
-    public function isBot()
321
-    {
322
-        return $this->request()->isBot();
323
-    }
324
-
325
-
326
-    /**
327
-     * @deprecated 4.9.53
328
-     * @param bool $is_bot
329
-     * @throws InvalidArgumentException
330
-     * @throws InvalidDataTypeException
331
-     * @throws InvalidInterfaceException
332
-     */
333
-    public function setIsBot($is_bot)
334
-    {
335
-        $this->request()->setIsBot($is_bot);
336
-    }
337
-
338
-
339
-    /**
340
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
341
-     * and return the value for the first match found
342
-     * wildcards can be either of the following:
343
-     *      ? to represent a single character of any type
344
-     *      * to represent one or more characters of any type
345
-     *
346
-     * @param string     $pattern
347
-     * @param null|mixed $default
348
-     * @return false|int
349
-     * @throws InvalidArgumentException
350
-     * @throws InvalidInterfaceException
351
-     * @throws InvalidDataTypeException
352
-     */
353
-    public function getMatch($pattern, $default = null)
354
-    {
355
-        return $this->request()->getMatch($pattern, $default);
356
-    }
357
-
358
-
359
-    /**
360
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
361
-     * wildcards can be either of the following:
362
-     *      ? to represent a single character of any type
363
-     *      * to represent one or more characters of any type
364
-     * returns true if a match is found or false if not
365
-     *
366
-     * @param string $pattern
367
-     * @return false|int
368
-     * @throws InvalidArgumentException
369
-     * @throws InvalidInterfaceException
370
-     * @throws InvalidDataTypeException
371
-     */
372
-    public function matches($pattern)
373
-    {
374
-        return $this->request()->matches($pattern);
375
-    }
21
+	/**
22
+	 * @var RequestInterface $request
23
+	 */
24
+	private $request;
25
+
26
+	/**
27
+	 * whether current request is for the admin but NOT via AJAX
28
+	 *
29
+	 * @var boolean $admin
30
+	 */
31
+	public $admin = false;
32
+
33
+	/**
34
+	 * whether current request is via AJAX
35
+	 *
36
+	 * @var boolean $ajax
37
+	 */
38
+	public $ajax = false;
39
+
40
+	/**
41
+	 * whether current request is via AJAX from the frontend of the site
42
+	 *
43
+	 * @var boolean $front_ajax
44
+	 */
45
+	public $front_ajax = false;
46
+
47
+
48
+	/**
49
+	 * @deprecated 4.9.53
50
+	 * @param array $get
51
+	 * @param array $post
52
+	 * @param array $cookie
53
+	 * @param array $server
54
+	 */
55
+	public function __construct(
56
+		array $get = array(),
57
+		array $post = array(),
58
+		array $cookie = array(),
59
+		array $server = array()
60
+	) {
61
+	}
62
+
63
+
64
+	/**
65
+	 * @return RequestInterface
66
+	 * @throws InvalidArgumentException
67
+	 * @throws InvalidInterfaceException
68
+	 * @throws InvalidDataTypeException
69
+	 */
70
+	private function request()
71
+	{
72
+		if ($this->request instanceof RequestInterface) {
73
+			return $this->request;
74
+		}
75
+		$loader = LoaderFactory::getLoader();
76
+		$this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface');
77
+		return $this->request;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param RequestInterface $request
83
+	 */
84
+	public function setRequest(RequestInterface $request)
85
+	{
86
+		$this->request = $request;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @deprecated 4.9.53
92
+	 * @return array
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 */
97
+	public function get_params()
98
+	{
99
+		return $this->request()->getParams();
100
+	}
101
+
102
+
103
+	/**
104
+	 * @deprecated 4.9.53
105
+	 * @return array
106
+	 * @throws InvalidArgumentException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 */
110
+	public function post_params()
111
+	{
112
+		return $this->request()->postParams();
113
+	}
114
+
115
+
116
+	/**
117
+	 * @deprecated 4.9.53
118
+	 * @return array
119
+	 * @throws InvalidArgumentException
120
+	 * @throws InvalidDataTypeException
121
+	 * @throws InvalidInterfaceException
122
+	 */
123
+	public function cookie_params()
124
+	{
125
+		return $this->request()->cookieParams();
126
+	}
127
+
128
+
129
+	/**
130
+	 * @deprecated 4.9.53
131
+	 * @return array
132
+	 * @throws InvalidArgumentException
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws InvalidInterfaceException
135
+	 */
136
+	public function server_params()
137
+	{
138
+		return $this->request()->serverParams();
139
+	}
140
+
141
+
142
+	/**
143
+	 * returns contents of $_REQUEST
144
+	 *
145
+	 * @deprecated 4.9.53
146
+	 * @return array
147
+	 * @throws InvalidArgumentException
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws InvalidInterfaceException
150
+	 */
151
+	public function params()
152
+	{
153
+		return $this->request()->requestParams();
154
+	}
155
+
156
+
157
+	/**
158
+	 * @deprecated 4.9.53
159
+	 * @param      $key
160
+	 * @param      $value
161
+	 * @param bool $override_ee
162
+	 * @return void
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidInterfaceException
166
+	 */
167
+	public function set($key, $value, $override_ee = false)
168
+	{
169
+		$this->request()->setRequestParam($key, $value, $override_ee);
170
+	}
171
+
172
+
173
+	/**
174
+	 * returns   the value for a request param if the given key exists
175
+	 *
176
+	 * @deprecated 4.9.53
177
+	 * @param      $key
178
+	 * @param null $default
179
+	 * @return mixed
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 */
184
+	public function get($key, $default = null)
185
+	{
186
+		return $this->request()->getRequestParam($key, $default);
187
+	}
188
+
189
+
190
+	/**
191
+	 * check if param exists
192
+	 *
193
+	 * @deprecated 4.9.53
194
+	 * @param $key
195
+	 * @return bool
196
+	 * @throws InvalidArgumentException
197
+	 * @throws InvalidDataTypeException
198
+	 * @throws InvalidInterfaceException
199
+	 */
200
+	public function is_set($key)
201
+	{
202
+		return $this->request()->requestParamIsSet($key);
203
+	}
204
+
205
+
206
+	/**
207
+	 * remove param
208
+	 *
209
+	 * @deprecated 4.9.53
210
+	 * @param      $key
211
+	 * @param bool $unset_from_global_too
212
+	 * @throws InvalidArgumentException
213
+	 * @throws InvalidDataTypeException
214
+	 * @throws InvalidInterfaceException
215
+	 */
216
+	public function un_set($key, $unset_from_global_too = false)
217
+	{
218
+		$this->request()->unSetRequestParam($key, $unset_from_global_too);
219
+	}
220
+
221
+
222
+	/**
223
+	 * @deprecated 4.9.53
224
+	 * @return string
225
+	 * @throws InvalidArgumentException
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidInterfaceException
228
+	 */
229
+	public function ip_address()
230
+	{
231
+		return $this->request()->ipAddress();
232
+	}
233
+
234
+
235
+	/**
236
+	 * @deprecated 4.9.53
237
+	 * @return bool
238
+	 * @throws InvalidArgumentException
239
+	 * @throws InvalidDataTypeException
240
+	 * @throws InvalidInterfaceException
241
+	 */
242
+	public function isAdmin()
243
+	{
244
+		return $this->request()->isAdmin();
245
+	}
246
+
247
+
248
+	/**
249
+	 * @deprecated 4.9.53
250
+	 * @return mixed
251
+	 * @throws InvalidArgumentException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 */
255
+	public function isAjax()
256
+	{
257
+		return $this->request()->isAjax();
258
+	}
259
+
260
+
261
+	/**
262
+	 * @deprecated 4.9.53
263
+	 * @return mixed
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 */
268
+	public function isFrontAjax()
269
+	{
270
+		return $this->request()->isFrontAjax();
271
+	}
272
+
273
+
274
+	/**
275
+	 * @deprecated 4.9.53
276
+	 * @return mixed|string
277
+	 * @throws InvalidArgumentException
278
+	 * @throws InvalidDataTypeException
279
+	 * @throws InvalidInterfaceException
280
+	 */
281
+	public function requestUri()
282
+	{
283
+		return $this->request()->requestUri();
284
+	}
285
+
286
+
287
+	/**
288
+	 * @deprecated 4.9.53
289
+	 * @return string
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public function userAgent()
295
+	{
296
+		return $this->request()->userAgent();
297
+	}
298
+
299
+
300
+	/**
301
+	 * @deprecated 4.9.53
302
+	 * @param string $user_agent
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 */
307
+	public function setUserAgent($user_agent = '')
308
+	{
309
+		$this->request()->setUserAgent($user_agent);
310
+	}
311
+
312
+
313
+	/**
314
+	 * @deprecated 4.9.53
315
+	 * @return bool
316
+	 * @throws InvalidArgumentException
317
+	 * @throws InvalidDataTypeException
318
+	 * @throws InvalidInterfaceException
319
+	 */
320
+	public function isBot()
321
+	{
322
+		return $this->request()->isBot();
323
+	}
324
+
325
+
326
+	/**
327
+	 * @deprecated 4.9.53
328
+	 * @param bool $is_bot
329
+	 * @throws InvalidArgumentException
330
+	 * @throws InvalidDataTypeException
331
+	 * @throws InvalidInterfaceException
332
+	 */
333
+	public function setIsBot($is_bot)
334
+	{
335
+		$this->request()->setIsBot($is_bot);
336
+	}
337
+
338
+
339
+	/**
340
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
341
+	 * and return the value for the first match found
342
+	 * wildcards can be either of the following:
343
+	 *      ? to represent a single character of any type
344
+	 *      * to represent one or more characters of any type
345
+	 *
346
+	 * @param string     $pattern
347
+	 * @param null|mixed $default
348
+	 * @return false|int
349
+	 * @throws InvalidArgumentException
350
+	 * @throws InvalidInterfaceException
351
+	 * @throws InvalidDataTypeException
352
+	 */
353
+	public function getMatch($pattern, $default = null)
354
+	{
355
+		return $this->request()->getMatch($pattern, $default);
356
+	}
357
+
358
+
359
+	/**
360
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
361
+	 * wildcards can be either of the following:
362
+	 *      ? to represent a single character of any type
363
+	 *      * to represent one or more characters of any type
364
+	 * returns true if a match is found or false if not
365
+	 *
366
+	 * @param string $pattern
367
+	 * @return false|int
368
+	 * @throws InvalidArgumentException
369
+	 * @throws InvalidInterfaceException
370
+	 * @throws InvalidDataTypeException
371
+	 */
372
+	public function matches($pattern)
373
+	{
374
+		return $this->request()->matches($pattern);
375
+	}
376 376
 }
Please login to merge, or discard this patch.
core/services/request/RequestStack.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -19,59 +19,59 @@
 block discarded – undo
19 19
 class RequestStack
20 20
 {
21 21
 
22
-    /**
23
-     * @var RequestDecoratorInterface $request_stack_app
24
-     */
25
-    protected $request_stack_app;
22
+	/**
23
+	 * @var RequestDecoratorInterface $request_stack_app
24
+	 */
25
+	protected $request_stack_app;
26 26
 
27
-    /**
28
-     * @var RequestStackCoreAppInterface $core_app
29
-     */
30
-    protected $core_app;
27
+	/**
28
+	 * @var RequestStackCoreAppInterface $core_app
29
+	 */
30
+	protected $core_app;
31 31
 
32
-    /**
33
-     * @var RequestInterface $request
34
-     */
35
-    protected $request;
32
+	/**
33
+	 * @var RequestInterface $request
34
+	 */
35
+	protected $request;
36 36
 
37
-    /**
38
-     * @var ResponseInterface $response
39
-     */
40
-    protected $response;
37
+	/**
38
+	 * @var ResponseInterface $response
39
+	 */
40
+	protected $response;
41 41
 
42 42
 
43
-    /**
44
-     * @param RequestDecoratorInterface    $request_stack_app
45
-     * @param RequestStackCoreAppInterface $core_app
46
-     */
47
-    public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
48
-    {
49
-        $this->request_stack_app = $request_stack_app;
50
-        $this->core_app      = $core_app;
51
-    }
43
+	/**
44
+	 * @param RequestDecoratorInterface    $request_stack_app
45
+	 * @param RequestStackCoreAppInterface $core_app
46
+	 */
47
+	public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
48
+	{
49
+		$this->request_stack_app = $request_stack_app;
50
+		$this->core_app      = $core_app;
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * @param RequestInterface  $request
56
-     * @param ResponseInterface $response
57
-     * @return ResponseInterface
58
-     */
59
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
60
-    {
61
-        $this->request  = $request;
62
-        $this->response = $response;
63
-        return $this->request_stack_app->handleRequest($request, $response);
64
-    }
54
+	/**
55
+	 * @param RequestInterface  $request
56
+	 * @param ResponseInterface $response
57
+	 * @return ResponseInterface
58
+	 */
59
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
60
+	{
61
+		$this->request  = $request;
62
+		$this->response = $response;
63
+		return $this->request_stack_app->handleRequest($request, $response);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * handle_response
69
-     * executes the handle_response() method on the RequestStackCoreAppInterface object
70
-     * after the request stack has been fully processed
71
-     */
72
-    public function handleResponse()
73
-    {
74
-        $this->core_app->handleResponse($this->request, $this->response);
75
-    }
67
+	/**
68
+	 * handle_response
69
+	 * executes the handle_response() method on the RequestStackCoreAppInterface object
70
+	 * after the request stack has been fully processed
71
+	 */
72
+	public function handleResponse()
73
+	{
74
+		$this->core_app->handleResponse($this->request, $this->response);
75
+	}
76 76
 }
77 77
 // Location: RequestStack.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
     public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
48 48
     {
49 49
         $this->request_stack_app = $request_stack_app;
50
-        $this->core_app      = $core_app;
50
+        $this->core_app = $core_app;
51 51
     }
52 52
 
53 53
 
Please login to merge, or discard this patch.
core/services/collections/iterators/CollectionFilterCallbackIterator.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -9,51 +9,51 @@
 block discarded – undo
9 9
 class CollectionFilterCallbackIterator extends FilterIterator
10 10
 {
11 11
 
12
-    /**
13
-     * Used for determining whether the iterated object in the Collection is "valid" or not.
14
-     * @var Closure
15
-     */
16
-    private $acceptance_callback;
17
-
18
-
19
-    /**
20
-     * CollectionFilterCallbackIterator constructor.
21
-     *
22
-     * @param Collection $collection
23
-     * @param Closure    $acceptance_callback  The closure will receive an instance of whatever object is stored on the
24
-     *                                         collection when iterating over the collection and should return boolean.
25
-     */
26
-    public function __construct(Collection $collection, Closure $acceptance_callback)
27
-    {
28
-        $this->acceptance_callback = $acceptance_callback;
29
-        parent::__construct($collection);
30
-    }
31
-
32
-    /**
33
-     * Check whether the current element of the iterator is acceptable
34
-     *
35
-     * @link  http://php.net/manual/en/filteriterator.accept.php
36
-     * @return bool true if the current element is acceptable, otherwise false.
37
-     */
38
-    public function accept()
39
-    {
40
-        $acceptance_callback = $this->acceptance_callback;
41
-        return $acceptance_callback($this->getInnerIterator()->current());
42
-    }
43
-
44
-
45
-
46
-    /**
47
-     * Returns a filtered array of objects from the collection using the provided acceptance callback
48
-     * @return array
49
-     */
50
-    public function getFiltered()
51
-    {
52
-        $filtered_array = array();
53
-        $this->rewind();
54
-        foreach ($this as $filtered_object) {
55
-            $filtered_array[] = $filtered_object;
56
-        }
57
-        return $filtered_array;
58
-    }
12
+	/**
13
+	 * Used for determining whether the iterated object in the Collection is "valid" or not.
14
+	 * @var Closure
15
+	 */
16
+	private $acceptance_callback;
17
+
18
+
19
+	/**
20
+	 * CollectionFilterCallbackIterator constructor.
21
+	 *
22
+	 * @param Collection $collection
23
+	 * @param Closure    $acceptance_callback  The closure will receive an instance of whatever object is stored on the
24
+	 *                                         collection when iterating over the collection and should return boolean.
25
+	 */
26
+	public function __construct(Collection $collection, Closure $acceptance_callback)
27
+	{
28
+		$this->acceptance_callback = $acceptance_callback;
29
+		parent::__construct($collection);
30
+	}
31
+
32
+	/**
33
+	 * Check whether the current element of the iterator is acceptable
34
+	 *
35
+	 * @link  http://php.net/manual/en/filteriterator.accept.php
36
+	 * @return bool true if the current element is acceptable, otherwise false.
37
+	 */
38
+	public function accept()
39
+	{
40
+		$acceptance_callback = $this->acceptance_callback;
41
+		return $acceptance_callback($this->getInnerIterator()->current());
42
+	}
43
+
44
+
45
+
46
+	/**
47
+	 * Returns a filtered array of objects from the collection using the provided acceptance callback
48
+	 * @return array
49
+	 */
50
+	public function getFiltered()
51
+	{
52
+		$filtered_array = array();
53
+		$this->rewind();
54
+		foreach ($this as $filtered_object) {
55
+			$filtered_array[] = $filtered_object;
56
+		}
57
+		return $filtered_array;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 2 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-use EventEspresso\core\domain\DomainFactory;
4
-use EventEspresso\core\domain\values\FilePath;
5
-use EventEspresso\core\domain\values\FullyQualifiedName;
6
-use EventEspresso\core\domain\values\Version;
7 3
 use EventEspresso\core\exceptions\InvalidDataTypeException;
8 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
9
-use EventEspresso\core\services\loaders\LoaderFactory;
10 5
 use EventEspresso\core\services\request\RequestDecoratorInterface;
11 6
 use EventEspresso\core\services\request\RequestInterface;
12 7
 use EventEspresso\core\services\request\RequestStackCoreAppInterface;
Please login to merge, or discard this patch.
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -27,114 +27,114 @@
 block discarded – undo
27 27
 class EE_Load_Espresso_Core implements RequestDecoratorInterface, RequestStackCoreAppInterface
28 28
 {
29 29
 
30
-    /**
31
-     * @var RequestInterface $request
32
-     */
33
-    protected $request;
34
-
35
-    /**
36
-     * @var ResponseInterface $response
37
-     */
38
-    protected $response;
39
-
40
-    /**
41
-     * @var EE_Dependency_Map $dependency_map
42
-     */
43
-    protected $dependency_map;
44
-
45
-    /**
46
-     * @var EE_Registry $registry
47
-     */
48
-    protected $registry;
49
-
50
-
51
-    /**
52
-     * EE_Load_Espresso_Core constructor
53
-     *
54
-     * @param EE_Registry       $registry
55
-     * @param EE_Dependency_Map $dependency_map
56
-     * @throws EE_Error
57
-     */
58
-    public function __construct(EE_Registry $registry, EE_Dependency_Map $dependency_map)
59
-    {
60
-        EE_Error::doing_it_wrong(
61
-            __METHOD__,
62
-            sprintf(
63
-                esc_html__(
64
-                    'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
65
-                    'event_espresso'
66
-                ),
67
-                'EventEspresso\core\services\request\RequestStackCoreApp',
68
-                '\core\services\request',
69
-                'EventEspresso\core\services\request'
70
-            ),
71
-            '4.9.53'
72
-        );
73
-    }
74
-
75
-
76
-    /**
77
-     * handle
78
-     * sets hooks for running rest of system
79
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
80
-     * starting EE Addons from any other point may lead to problems
81
-     *
82
-     * @param RequestInterface  $request
83
-     * @param ResponseInterface $response
84
-     * @return ResponseInterface
85
-     * @throws EE_Error
86
-     * @throws InvalidDataTypeException
87
-     * @throws InvalidInterfaceException
88
-     * @throws InvalidArgumentException
89
-     * @throws DomainException
90
-     */
91
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
92
-    {
93
-    }
94
-
95
-
96
-    /**
97
-     * @return RequestInterface
98
-     */
99
-    public function request()
100
-    {
101
-    }
102
-
103
-
104
-    /**
105
-     * @return ResponseInterface
106
-     */
107
-    public function response()
108
-    {
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EE_Dependency_Map
114
-     * @throws EE_Error
115
-     */
116
-    public function dependency_map()
117
-    {
118
-    }
119
-
120
-
121
-    /**
122
-     * @return EE_Registry
123
-     * @throws EE_Error
124
-     */
125
-    public function registry()
126
-    {
127
-    }
128
-
129
-
130
-    /**
131
-     * called after the request stack has been fully processed
132
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
133
-     *
134
-     * @param RequestInterface  $request
135
-     * @param ResponseInterface $response
136
-     */
137
-    public function handleResponse(RequestInterface $request, ResponseInterface $response)
138
-    {
139
-    }
30
+	/**
31
+	 * @var RequestInterface $request
32
+	 */
33
+	protected $request;
34
+
35
+	/**
36
+	 * @var ResponseInterface $response
37
+	 */
38
+	protected $response;
39
+
40
+	/**
41
+	 * @var EE_Dependency_Map $dependency_map
42
+	 */
43
+	protected $dependency_map;
44
+
45
+	/**
46
+	 * @var EE_Registry $registry
47
+	 */
48
+	protected $registry;
49
+
50
+
51
+	/**
52
+	 * EE_Load_Espresso_Core constructor
53
+	 *
54
+	 * @param EE_Registry       $registry
55
+	 * @param EE_Dependency_Map $dependency_map
56
+	 * @throws EE_Error
57
+	 */
58
+	public function __construct(EE_Registry $registry, EE_Dependency_Map $dependency_map)
59
+	{
60
+		EE_Error::doing_it_wrong(
61
+			__METHOD__,
62
+			sprintf(
63
+				esc_html__(
64
+					'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
65
+					'event_espresso'
66
+				),
67
+				'EventEspresso\core\services\request\RequestStackCoreApp',
68
+				'\core\services\request',
69
+				'EventEspresso\core\services\request'
70
+			),
71
+			'4.9.53'
72
+		);
73
+	}
74
+
75
+
76
+	/**
77
+	 * handle
78
+	 * sets hooks for running rest of system
79
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
80
+	 * starting EE Addons from any other point may lead to problems
81
+	 *
82
+	 * @param RequestInterface  $request
83
+	 * @param ResponseInterface $response
84
+	 * @return ResponseInterface
85
+	 * @throws EE_Error
86
+	 * @throws InvalidDataTypeException
87
+	 * @throws InvalidInterfaceException
88
+	 * @throws InvalidArgumentException
89
+	 * @throws DomainException
90
+	 */
91
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
92
+	{
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return RequestInterface
98
+	 */
99
+	public function request()
100
+	{
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return ResponseInterface
106
+	 */
107
+	public function response()
108
+	{
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EE_Dependency_Map
114
+	 * @throws EE_Error
115
+	 */
116
+	public function dependency_map()
117
+	{
118
+	}
119
+
120
+
121
+	/**
122
+	 * @return EE_Registry
123
+	 * @throws EE_Error
124
+	 */
125
+	public function registry()
126
+	{
127
+	}
128
+
129
+
130
+	/**
131
+	 * called after the request stack has been fully processed
132
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
133
+	 *
134
+	 * @param RequestInterface  $request
135
+	 * @param ResponseInterface $response
136
+	 */
137
+	public function handleResponse(RequestInterface $request, ResponseInterface $response)
138
+	{
139
+	}
140 140
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2597,7 +2597,7 @@  discard block
 block discarded – undo
2597 2597
      *
2598 2598
      * @param int $index This helps us know which template field to select from the request array.
2599 2599
      *
2600
-     * @return array
2600
+     * @return string
2601 2601
      */
2602 2602
     protected function _set_message_template_column_values($index)
2603 2603
     {
@@ -3088,7 +3088,7 @@  discard block
 block discarded – undo
3088 3088
      *
3089 3089
      * @param  int  $GRP_ID        The group being deleted
3090 3090
      * @param  bool $include_group whether to delete the Message Template Group as well.
3091
-     * @return bool boolean to indicate the success of the deletes or not.
3091
+     * @return integer boolean to indicate the success of the deletes or not.
3092 3092
      * @throws EE_Error
3093 3093
      * @throws InvalidArgumentException
3094 3094
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +4553 added lines, -4553 removed lines patch added patch discarded remove patch
@@ -19,2646 +19,2646 @@  discard block
 block discarded – undo
19 19
 class Messages_Admin_Page extends EE_Admin_Page
20 20
 {
21 21
 
22
-    /**
23
-     * @type EE_Message_Resource_Manager $_message_resource_manager
24
-     */
25
-    protected $_message_resource_manager;
26
-
27
-    /**
28
-     * @type string $_active_message_type_name
29
-     */
30
-    protected $_active_message_type_name = '';
31
-
32
-    /**
33
-     * @type EE_messenger $_active_messenger
34
-     */
35
-    protected $_active_messenger;
36
-    protected $_activate_state;
37
-    protected $_activate_meta_box_type;
38
-    protected $_current_message_meta_box;
39
-    protected $_current_message_meta_box_object;
40
-    protected $_context_switcher;
41
-    protected $_shortcodes = array();
42
-    protected $_active_messengers = array();
43
-    protected $_active_message_types = array();
44
-
45
-    /**
46
-     * @var EE_Message_Template_Group $_message_template_group
47
-     */
48
-    protected $_message_template_group;
49
-    protected $_m_mt_settings = array();
50
-
51
-
52
-    /**
53
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
54
-     * IF there is no group then it gets automatically set to the Default template pack.
55
-     *
56
-     * @since 4.5.0
57
-     *
58
-     * @var EE_Messages_Template_Pack
59
-     */
60
-    protected $_template_pack;
61
-
62
-
63
-    /**
64
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
65
-     * group is.  If there is no group then it automatically gets set to default.
66
-     *
67
-     * @since 4.5.0
68
-     *
69
-     * @var string
70
-     */
71
-    protected $_variation;
72
-
73
-
74
-    /**
75
-     * @param bool $routing
76
-     * @throws EE_Error
77
-     */
78
-    public function __construct($routing = true)
79
-    {
80
-        // make sure messages autoloader is running
81
-        EED_Messages::set_autoloaders();
82
-        parent::__construct($routing);
83
-    }
84
-
85
-
86
-    protected function _init_page_props()
87
-    {
88
-        $this->page_slug = EE_MSG_PG_SLUG;
89
-        $this->page_label = esc_html__('Messages Settings', 'event_espresso');
90
-        $this->_admin_base_url = EE_MSG_ADMIN_URL;
91
-        $this->_admin_base_path = EE_MSG_ADMIN;
92
-
93
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state']
94
-            : array();
95
-
96
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
97
-        $this->_load_message_resource_manager();
98
-    }
99
-
100
-
101
-    /**
102
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
103
-     *
104
-     * @throws EE_Error
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @throws InvalidArgumentException
108
-     * @throws ReflectionException
109
-     */
110
-    protected function _load_message_resource_manager()
111
-    {
112
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
113
-    }
114
-
115
-
116
-    /**
117
-     * @deprecated 4.9.9.rc.014
118
-     * @return array
119
-     * @throws EE_Error
120
-     * @throws InvalidArgumentException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     */
124
-    public function get_messengers_for_list_table()
125
-    {
126
-        EE_Error::doing_it_wrong(
127
-            __METHOD__,
128
-            sprintf(
129
-                esc_html__(
130
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
131
-                    'event_espresso'
132
-                ),
133
-                'Messages_Admin_Page::get_messengers_select_input()'
134
-            ),
135
-            '4.9.9.rc.014'
136
-        );
137
-
138
-        $m_values = array();
139
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
140
-        // setup messengers for selects
141
-        $i = 1;
142
-        foreach ($active_messengers as $active_messenger) {
143
-            if ($active_messenger instanceof EE_Message) {
144
-                $m_values[ $i ]['id'] = $active_messenger->messenger();
145
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
146
-                $i++;
147
-            }
148
-        }
149
-
150
-        return $m_values;
151
-    }
152
-
153
-
154
-    /**
155
-     * @deprecated 4.9.9.rc.014
156
-     * @return array
157
-     * @throws EE_Error
158
-     * @throws InvalidArgumentException
159
-     * @throws InvalidDataTypeException
160
-     * @throws InvalidInterfaceException
161
-     */
162
-    public function get_message_types_for_list_table()
163
-    {
164
-        EE_Error::doing_it_wrong(
165
-            __METHOD__,
166
-            sprintf(
167
-                esc_html__(
168
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
169
-                    'event_espresso'
170
-                ),
171
-                'Messages_Admin_Page::get_message_types_select_input()'
172
-            ),
173
-            '4.9.9.rc.014'
174
-        );
175
-
176
-        $mt_values = array();
177
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
178
-        $i = 1;
179
-        foreach ($active_messages as $active_message) {
180
-            if ($active_message instanceof EE_Message) {
181
-                $mt_values[ $i ]['id'] = $active_message->message_type();
182
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
183
-                $i++;
184
-            }
185
-        }
186
-
187
-        return $mt_values;
188
-    }
189
-
190
-
191
-    /**
192
-     * @deprecated 4.9.9.rc.014
193
-     * @return array
194
-     * @throws EE_Error
195
-     * @throws InvalidArgumentException
196
-     * @throws InvalidDataTypeException
197
-     * @throws InvalidInterfaceException
198
-     */
199
-    public function get_contexts_for_message_types_for_list_table()
200
-    {
201
-        EE_Error::doing_it_wrong(
202
-            __METHOD__,
203
-            sprintf(
204
-                esc_html__(
205
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
206
-                    'event_espresso'
207
-                ),
208
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
209
-            ),
210
-            '4.9.9.rc.014'
211
-        );
212
-
213
-        $contexts = array();
214
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
215
-        foreach ($active_message_contexts as $active_message) {
216
-            if ($active_message instanceof EE_Message) {
217
-                $message_type = $active_message->message_type_object();
218
-                if ($message_type instanceof EE_message_type) {
219
-                    $message_type_contexts = $message_type->get_contexts();
220
-                    foreach ($message_type_contexts as $context => $context_details) {
221
-                        $contexts[ $context ] = $context_details['label'];
222
-                    }
223
-                }
224
-            }
225
-        }
226
-
227
-        return $contexts;
228
-    }
229
-
230
-
231
-    /**
232
-     * Generate select input with provided messenger options array.
233
-     *
234
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
235
-     *                                 labels.
236
-     * @return string
237
-     * @throws EE_Error
238
-     */
239
-    public function get_messengers_select_input($messenger_options)
240
-    {
241
-        // if empty or just one value then just return an empty string
242
-        if (
243
-            empty($messenger_options)
244
-            || ! is_array($messenger_options)
245
-            || count($messenger_options) === 1
246
-        ) {
247
-            return '';
248
-        }
249
-        // merge in default
250
-        $messenger_options = array_merge(
251
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
252
-            $messenger_options
253
-        );
254
-        $input = new EE_Select_Input(
255
-            $messenger_options,
256
-            array(
257
-                'html_name'  => 'ee_messenger_filter_by',
258
-                'html_id'    => 'ee_messenger_filter_by',
259
-                'html_class' => 'wide',
260
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
261
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
262
-                    : 'none_selected',
263
-            )
264
-        );
265
-
266
-        return $input->get_html_for_input();
267
-    }
268
-
269
-
270
-    /**
271
-     * Generate select input with provided message type options array.
272
-     *
273
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
274
-     *                                    message type labels
275
-     * @return string
276
-     * @throws EE_Error
277
-     */
278
-    public function get_message_types_select_input($message_type_options)
279
-    {
280
-        // if empty or count of options is 1 then just return an empty string
281
-        if (
282
-            empty($message_type_options)
283
-            || ! is_array($message_type_options)
284
-            || count($message_type_options) === 1
285
-        ) {
286
-            return '';
287
-        }
288
-        // merge in default
289
-        $message_type_options = array_merge(
290
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
-            $message_type_options
292
-        );
293
-        $input = new EE_Select_Input(
294
-            $message_type_options,
295
-            array(
296
-                'html_name'  => 'ee_message_type_filter_by',
297
-                'html_id'    => 'ee_message_type_filter_by',
298
-                'html_class' => 'wide',
299
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
-                    : 'none_selected',
302
-            )
303
-        );
304
-
305
-        return $input->get_html_for_input();
306
-    }
307
-
308
-
309
-    /**
310
-     * Generate select input with provide message type contexts array.
311
-     *
312
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
-     *                               context label.
314
-     * @return string
315
-     * @throws EE_Error
316
-     */
317
-    public function get_contexts_for_message_types_select_input($context_options)
318
-    {
319
-        // if empty or count of options is one then just return empty string
320
-        if (
321
-            empty($context_options)
322
-            || ! is_array($context_options)
323
-            || count($context_options) === 1
324
-        ) {
325
-            return '';
326
-        }
327
-        // merge in default
328
-        $context_options = array_merge(
329
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
-            $context_options
331
-        );
332
-        $input = new EE_Select_Input(
333
-            $context_options,
334
-            array(
335
-                'html_name'  => 'ee_context_filter_by',
336
-                'html_id'    => 'ee_context_filter_by',
337
-                'html_class' => 'wide',
338
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
339
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
340
-                    : 'none_selected',
341
-            )
342
-        );
343
-
344
-        return $input->get_html_for_input();
345
-    }
346
-
347
-
348
-    protected function _ajax_hooks()
349
-    {
350
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
-    }
357
-
358
-
359
-    protected function _define_page_props()
360
-    {
361
-        $this->_admin_page_title = $this->page_label;
362
-        $this->_labels = array(
363
-            'buttons'    => array(
364
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
367
-            ),
368
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
369
-        );
370
-    }
371
-
372
-
373
-    /**
374
-     *        an array for storing key => value pairs of request actions and their corresponding methods
375
-     *
376
-     * @access protected
377
-     * @return void
378
-     */
379
-    protected function _set_page_routes()
380
-    {
381
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
382
-            ? $this->_req_data['GRP_ID']
383
-            : 0;
384
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
385
-            ? $this->_req_data['id']
386
-            : $grp_id;
387
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
388
-            ? $this->_req_data['MSG_ID']
389
-            : 0;
390
-
391
-        $this->_page_routes = array(
392
-            'default'                          => array(
393
-                'func'       => '_message_queue_list_table',
394
-                'capability' => 'ee_read_global_messages',
395
-            ),
396
-            'global_mtps'                      => array(
397
-                'func'       => '_ee_default_messages_overview_list_table',
398
-                'capability' => 'ee_read_global_messages',
399
-            ),
400
-            'custom_mtps'                      => array(
401
-                'func'       => '_custom_mtps_preview',
402
-                'capability' => 'ee_read_messages',
403
-            ),
404
-            'add_new_message_template'         => array(
405
-                'func'       => '_add_message_template',
406
-                'capability' => 'ee_edit_messages',
407
-                'noheader'   => true,
408
-            ),
409
-            'edit_message_template'            => array(
410
-                'func'       => '_edit_message_template',
411
-                'capability' => 'ee_edit_message',
412
-                'obj_id'     => $grp_id,
413
-            ),
414
-            'preview_message'                  => array(
415
-                'func'               => '_preview_message',
416
-                'capability'         => 'ee_read_message',
417
-                'obj_id'             => $grp_id,
418
-                'noheader'           => true,
419
-                'headers_sent_route' => 'display_preview_message',
420
-            ),
421
-            'display_preview_message'          => array(
422
-                'func'       => '_display_preview_message',
423
-                'capability' => 'ee_read_message',
424
-                'obj_id'     => $grp_id,
425
-            ),
426
-            'insert_message_template'          => array(
427
-                'func'       => '_insert_or_update_message_template',
428
-                'capability' => 'ee_edit_messages',
429
-                'args'       => array('new_template' => true),
430
-                'noheader'   => true,
431
-            ),
432
-            'update_message_template'          => array(
433
-                'func'       => '_insert_or_update_message_template',
434
-                'capability' => 'ee_edit_message',
435
-                'obj_id'     => $grp_id,
436
-                'args'       => array('new_template' => false),
437
-                'noheader'   => true,
438
-            ),
439
-            'trash_message_template'           => array(
440
-                'func'       => '_trash_or_restore_message_template',
441
-                'capability' => 'ee_delete_message',
442
-                'obj_id'     => $grp_id,
443
-                'args'       => array('trash' => true, 'all' => true),
444
-                'noheader'   => true,
445
-            ),
446
-            'trash_message_template_context'   => array(
447
-                'func'       => '_trash_or_restore_message_template',
448
-                'capability' => 'ee_delete_message',
449
-                'obj_id'     => $grp_id,
450
-                'args'       => array('trash' => true),
451
-                'noheader'   => true,
452
-            ),
453
-            'restore_message_template'         => array(
454
-                'func'       => '_trash_or_restore_message_template',
455
-                'capability' => 'ee_delete_message',
456
-                'obj_id'     => $grp_id,
457
-                'args'       => array('trash' => false, 'all' => true),
458
-                'noheader'   => true,
459
-            ),
460
-            'restore_message_template_context' => array(
461
-                'func'       => '_trash_or_restore_message_template',
462
-                'capability' => 'ee_delete_message',
463
-                'obj_id'     => $grp_id,
464
-                'args'       => array('trash' => false),
465
-                'noheader'   => true,
466
-            ),
467
-            'delete_message_template'          => array(
468
-                'func'       => '_delete_message_template',
469
-                'capability' => 'ee_delete_message',
470
-                'obj_id'     => $grp_id,
471
-                'noheader'   => true,
472
-            ),
473
-            'reset_to_default'                 => array(
474
-                'func'       => '_reset_to_default_template',
475
-                'capability' => 'ee_edit_message',
476
-                'obj_id'     => $grp_id,
477
-                'noheader'   => true,
478
-            ),
479
-            'settings'                         => array(
480
-                'func'       => '_settings',
481
-                'capability' => 'manage_options',
482
-            ),
483
-            'update_global_settings'           => array(
484
-                'func'       => '_update_global_settings',
485
-                'capability' => 'manage_options',
486
-                'noheader'   => true,
487
-            ),
488
-            'generate_now'                     => array(
489
-                'func'       => '_generate_now',
490
-                'capability' => 'ee_send_message',
491
-                'noheader'   => true,
492
-            ),
493
-            'generate_and_send_now'            => array(
494
-                'func'       => '_generate_and_send_now',
495
-                'capability' => 'ee_send_message',
496
-                'noheader'   => true,
497
-            ),
498
-            'queue_for_resending'              => array(
499
-                'func'       => '_queue_for_resending',
500
-                'capability' => 'ee_send_message',
501
-                'noheader'   => true,
502
-            ),
503
-            'send_now'                         => array(
504
-                'func'       => '_send_now',
505
-                'capability' => 'ee_send_message',
506
-                'noheader'   => true,
507
-            ),
508
-            'delete_ee_message'                => array(
509
-                'func'       => '_delete_ee_messages',
510
-                'capability' => 'ee_delete_messages',
511
-                'noheader'   => true,
512
-            ),
513
-            'delete_ee_messages'               => array(
514
-                'func'       => '_delete_ee_messages',
515
-                'capability' => 'ee_delete_messages',
516
-                'noheader'   => true,
517
-                'obj_id'     => $msg_id,
518
-            ),
519
-        );
520
-    }
521
-
522
-
523
-    protected function _set_page_config()
524
-    {
525
-        $this->_page_config = array(
526
-            'default'                  => array(
527
-                'nav'           => array(
528
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
529
-                    'order' => 10,
530
-                ),
531
-                'list_table'    => 'EE_Message_List_Table',
532
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
533
-                'require_nonce' => false,
534
-            ),
535
-            'global_mtps'              => array(
536
-                'nav'           => array(
537
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
538
-                    'order' => 20,
539
-                ),
540
-                'list_table'    => 'Messages_Template_List_Table',
541
-                'help_tabs'     => array(
542
-                    'messages_overview_help_tab'                                => array(
543
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
544
-                        'filename' => 'messages_overview',
545
-                    ),
546
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
547
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
548
-                        'filename' => 'messages_overview_table_column_headings',
549
-                    ),
550
-                    'messages_overview_messages_filters_help_tab'               => array(
551
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
552
-                        'filename' => 'messages_overview_filters',
553
-                    ),
554
-                    'messages_overview_messages_views_help_tab'                 => array(
555
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
556
-                        'filename' => 'messages_overview_views',
557
-                    ),
558
-                    'message_overview_message_types_help_tab'                   => array(
559
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
560
-                        'filename' => 'messages_overview_types',
561
-                    ),
562
-                    'messages_overview_messengers_help_tab'                     => array(
563
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
564
-                        'filename' => 'messages_overview_messengers',
565
-                    ),
566
-                ),
567
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
568
-                'require_nonce' => false,
569
-            ),
570
-            'custom_mtps'              => array(
571
-                'nav'           => array(
572
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
573
-                    'order' => 30,
574
-                ),
575
-                'help_tabs'     => array(),
576
-                'help_tour'     => array(),
577
-                'require_nonce' => false,
578
-            ),
579
-            'add_new_message_template' => array(
580
-                'nav'           => array(
581
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
582
-                    'order'      => 5,
583
-                    'persistent' => false,
584
-                ),
585
-                'require_nonce' => false,
586
-            ),
587
-            'edit_message_template'    => array(
588
-                'labels'        => array(
589
-                    'buttons'    => array(
590
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
591
-                    ),
592
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
593
-                ),
594
-                'nav'           => array(
595
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
596
-                    'order'      => 5,
597
-                    'persistent' => false,
598
-                    'url'        => '',
599
-                ),
600
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
601
-                'has_metaboxes' => true,
602
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
603
-                'help_tabs'     => array(
604
-                    'edit_message_template'            => array(
605
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
606
-                        'callback' => 'edit_message_template_help_tab',
607
-                    ),
608
-                    'message_templates_help_tab'       => array(
609
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
610
-                        'filename' => 'messages_templates',
611
-                    ),
612
-                    'message_template_shortcodes'      => array(
613
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
614
-                        'callback' => 'message_template_shortcodes_help_tab',
615
-                    ),
616
-                    'message_preview_help_tab'         => array(
617
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
618
-                        'filename' => 'messages_preview',
619
-                    ),
620
-                    'messages_overview_other_help_tab' => array(
621
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
622
-                        'filename' => 'messages_overview_other',
623
-                    ),
624
-                ),
625
-                'require_nonce' => false,
626
-            ),
627
-            'display_preview_message'  => array(
628
-                'nav'           => array(
629
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
630
-                    'order'      => 5,
631
-                    'url'        => '',
632
-                    'persistent' => false,
633
-                ),
634
-                'help_tabs'     => array(
635
-                    'preview_message' => array(
636
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
637
-                        'callback' => 'preview_message_help_tab',
638
-                    ),
639
-                ),
640
-                'require_nonce' => false,
641
-            ),
642
-            'settings'                 => array(
643
-                'nav'           => array(
644
-                    'label' => esc_html__('Settings', 'event_espresso'),
645
-                    'order' => 40,
646
-                ),
647
-                'metaboxes'     => array('_messages_settings_metaboxes'),
648
-                'help_tabs'     => array(
649
-                    'messages_settings_help_tab'               => array(
650
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
651
-                        'filename' => 'messages_settings',
652
-                    ),
653
-                    'messages_settings_message_types_help_tab' => array(
654
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
655
-                        'filename' => 'messages_settings_message_types',
656
-                    ),
657
-                    'messages_settings_messengers_help_tab'    => array(
658
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
659
-                        'filename' => 'messages_settings_messengers',
660
-                    ),
661
-                ),
662
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
663
-                'require_nonce' => false,
664
-            ),
665
-        );
666
-    }
667
-
668
-
669
-    protected function _add_screen_options()
670
-    {
671
-        // todo
672
-    }
673
-
674
-
675
-    protected function _add_screen_options_global_mtps()
676
-    {
677
-        /**
678
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
679
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
680
-         */
681
-        $page_title = $this->_admin_page_title;
682
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
683
-        $this->_per_page_screen_option();
684
-        $this->_admin_page_title = $page_title;
685
-    }
686
-
687
-
688
-    protected function _add_screen_options_default()
689
-    {
690
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
691
-        $this->_per_page_screen_option();
692
-    }
693
-
694
-
695
-    // none of the below group are currently used for Messages
696
-    protected function _add_feature_pointers()
697
-    {
698
-    }
699
-
700
-    public function admin_init()
701
-    {
702
-    }
703
-
704
-    public function admin_notices()
705
-    {
706
-    }
707
-
708
-    public function admin_footer_scripts()
709
-    {
710
-    }
711
-
712
-
713
-    public function messages_help_tab()
714
-    {
715
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
716
-    }
717
-
718
-
719
-    public function messengers_help_tab()
720
-    {
721
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
722
-    }
723
-
724
-
725
-    public function message_types_help_tab()
726
-    {
727
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
728
-    }
729
-
730
-
731
-    public function messages_overview_help_tab()
732
-    {
733
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
734
-    }
735
-
736
-
737
-    public function message_templates_help_tab()
738
-    {
739
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
740
-    }
741
-
742
-
743
-    public function edit_message_template_help_tab()
744
-    {
745
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
746
-                        . esc_attr__('Editor Title', 'event_espresso')
747
-                        . '" />';
748
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
749
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
750
-                        . '" />';
751
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
752
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
753
-                        . '" />';
754
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
755
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
756
-                        . '" />';
757
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
758
-                        . esc_attr__('Publish Metabox', 'event_espresso')
759
-                        . '" />';
760
-        EEH_Template::display_template(
761
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
762
-            $args
763
-        );
764
-    }
765
-
766
-
767
-    public function message_template_shortcodes_help_tab()
768
-    {
769
-        $this->_set_shortcodes();
770
-        $args['shortcodes'] = $this->_shortcodes;
771
-        EEH_Template::display_template(
772
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
773
-            $args
774
-        );
775
-    }
776
-
777
-
778
-    public function preview_message_help_tab()
779
-    {
780
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
781
-    }
782
-
783
-
784
-    public function settings_help_tab()
785
-    {
786
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
787
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
788
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
789
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
790
-        $args['img3'] = '<div class="switch">'
791
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
792
-                        . ' type="checkbox" checked="checked">'
793
-                        . '<label for="ee-on-off-toggle-on"></label>'
794
-                        . '</div>';
795
-        $args['img4'] = '<div class="switch">'
796
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
797
-                        . ' type="checkbox">'
798
-                        . '<label for="ee-on-off-toggle-on"></label>'
799
-                        . '</div>';
800
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
801
-    }
802
-
803
-
804
-    public function load_scripts_styles()
805
-    {
806
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
807
-        wp_enqueue_style('espresso_ee_msg');
808
-
809
-        wp_register_script(
810
-            'ee-messages-settings',
811
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
812
-            array('jquery-ui-droppable', 'ee-serialize-full-array'),
813
-            EVENT_ESPRESSO_VERSION,
814
-            true
815
-        );
816
-        wp_register_script(
817
-            'ee-msg-list-table-js',
818
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
819
-            array('ee-dialog'),
820
-            EVENT_ESPRESSO_VERSION
821
-        );
822
-    }
823
-
824
-
825
-    public function load_scripts_styles_default()
826
-    {
827
-        wp_enqueue_script('ee-msg-list-table-js');
828
-    }
829
-
830
-
831
-    public function wp_editor_css($mce_css)
832
-    {
833
-        // if we're on the edit_message_template route
834
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
835
-            $message_type_name = $this->_active_message_type_name;
836
-
837
-            // we're going to REPLACE the existing mce css
838
-            // we need to get the css file location from the active messenger
839
-            $mce_css = $this->_active_messenger->get_variation(
840
-                $this->_template_pack,
841
-                $message_type_name,
842
-                true,
843
-                'wpeditor',
844
-                $this->_variation
845
-            );
846
-        }
847
-
848
-        return $mce_css;
849
-    }
850
-
851
-
852
-    public function load_scripts_styles_edit_message_template()
853
-    {
854
-
855
-        $this->_set_shortcodes();
856
-
857
-        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
858
-            esc_html__(
859
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
860
-                'event_espresso'
861
-            ),
862
-            $this->_message_template_group->messenger_obj()->label['singular'],
863
-            $this->_message_template_group->message_type_obj()->label['singular']
864
-        );
865
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
866
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
867
-            'event_espresso'
868
-        );
869
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
870
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
871
-            'event_espresso'
872
-        );
873
-
874
-        wp_register_script(
875
-            'ee_msgs_edit_js',
876
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
877
-            array('jquery'),
878
-            EVENT_ESPRESSO_VERSION
879
-        );
880
-
881
-        wp_enqueue_script('ee_admin_js');
882
-        wp_enqueue_script('ee_msgs_edit_js');
883
-
884
-        // add in special css for tiny_mce
885
-        add_filter('mce_css', array($this, 'wp_editor_css'));
886
-    }
887
-
888
-
889
-    public function load_scripts_styles_display_preview_message()
890
-    {
891
-
892
-        $this->_set_message_template_group();
893
-
894
-        if (isset($this->_req_data['messenger'])) {
895
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
896
-                $this->_req_data['messenger']
897
-            );
898
-        }
899
-
900
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
901
-
902
-
903
-        wp_enqueue_style(
904
-            'espresso_preview_css',
905
-            $this->_active_messenger->get_variation(
906
-                $this->_template_pack,
907
-                $message_type_name,
908
-                true,
909
-                'preview',
910
-                $this->_variation
911
-            )
912
-        );
913
-    }
914
-
915
-
916
-    public function load_scripts_styles_settings()
917
-    {
918
-        wp_register_style(
919
-            'ee-message-settings',
920
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
921
-            array(),
922
-            EVENT_ESPRESSO_VERSION
923
-        );
924
-        wp_enqueue_style('ee-text-links');
925
-        wp_enqueue_style('ee-message-settings');
926
-        wp_enqueue_script('ee-messages-settings');
927
-    }
928
-
929
-
930
-    /**
931
-     * set views array for List Table
932
-     */
933
-    public function _set_list_table_views_global_mtps()
934
-    {
935
-        $this->_views = array(
936
-            'in_use' => array(
937
-                'slug'  => 'in_use',
938
-                'label' => esc_html__('In Use', 'event_espresso'),
939
-                'count' => 0,
940
-            ),
941
-        );
942
-    }
943
-
944
-
945
-    /**
946
-     * Set views array for the Custom Template List Table
947
-     */
948
-    public function _set_list_table_views_custom_mtps()
949
-    {
950
-        $this->_set_list_table_views_global_mtps();
951
-        $this->_views['in_use']['bulk_action'] = array(
952
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
953
-        );
954
-    }
955
-
956
-
957
-    /**
958
-     * set views array for message queue list table
959
-     *
960
-     * @throws InvalidDataTypeException
961
-     * @throws InvalidInterfaceException
962
-     * @throws InvalidArgumentException
963
-     * @throws EE_Error
964
-     * @throws ReflectionException
965
-     */
966
-    public function _set_list_table_views_default()
967
-    {
968
-        EE_Registry::instance()->load_helper('Template');
969
-
970
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
971
-            'ee_send_message',
972
-            'message_list_table_bulk_actions'
973
-        )
974
-            ? array(
975
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
976
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
977
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
978
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
979
-            )
980
-            : array();
981
-
982
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
983
-            'ee_delete_messages',
984
-            'message_list_table_bulk_actions'
985
-        )
986
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
987
-            : array();
988
-
989
-
990
-        $this->_views = array(
991
-            'all' => array(
992
-                'slug'        => 'all',
993
-                'label'       => esc_html__('All', 'event_espresso'),
994
-                'count'       => 0,
995
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
996
-            ),
997
-        );
998
-
999
-
1000
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
1001
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1002
-                continue;
1003
-            }
1004
-            $status_bulk_actions = $common_bulk_actions;
1005
-            // unset bulk actions not applying to status
1006
-            if (! empty($status_bulk_actions)) {
1007
-                switch ($status) {
1008
-                    case EEM_Message::status_idle:
1009
-                    case EEM_Message::status_resend:
1010
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1011
-                        break;
1012
-
1013
-                    case EEM_Message::status_failed:
1014
-                    case EEM_Message::status_debug_only:
1015
-                    case EEM_Message::status_messenger_executing:
1016
-                        $status_bulk_actions = array();
1017
-                        break;
1018
-
1019
-                    case EEM_Message::status_incomplete:
1020
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1021
-                        break;
1022
-
1023
-                    case EEM_Message::status_retry:
1024
-                    case EEM_Message::status_sent:
1025
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1026
-                        break;
1027
-                }
1028
-            }
1029
-
1030
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1031
-            if ($status === EEM_Message::status_messenger_executing) {
1032
-                continue;
1033
-            }
1034
-
1035
-            $this->_views[ strtolower($status) ] = array(
1036
-                'slug'        => strtolower($status),
1037
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1038
-                'count'       => 0,
1039
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1040
-            );
1041
-        }
1042
-    }
1043
-
1044
-
1045
-    protected function _ee_default_messages_overview_list_table()
1046
-    {
1047
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1048
-        $this->display_admin_list_table_page_with_no_sidebar();
1049
-    }
1050
-
1051
-
1052
-    protected function _message_queue_list_table()
1053
-    {
1054
-        $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso');
1055
-        $this->_template_args['per_column'] = 6;
1056
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());
1057
-        $this->_template_args['before_list_table'] = '<h3>'
1058
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1059
-                                                     . '</h3>';
1060
-        $this->display_admin_list_table_page_with_no_sidebar();
1061
-    }
1062
-
1063
-
1064
-    protected function _message_legend_items()
1065
-    {
1066
-
1067
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1068
-        $action_items = array();
1069
-
1070
-        foreach ($action_css_classes as $action_item => $action_details) {
1071
-            if ($action_item === 'see_notifications_for') {
1072
-                continue;
1073
-            }
1074
-            $action_items[ $action_item ] = array(
1075
-                'class' => $action_details['css_class'],
1076
-                'desc'  => $action_details['label'],
1077
-            );
1078
-        }
1079
-
1080
-        /** @type array $status_items status legend setup */
1081
-        $status_items = array(
1082
-            'incomplete_status'          => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1084
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1085
-            ),
1086
-            'idle_status'                => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1088
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1089
-            ),
1090
-            'resend_status'              => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1092
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1093
-            ),
1094
-            'messenger_executing_status' => array(
1095
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1096
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1097
-            ),
1098
-            'sent_status'                => array(
1099
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1100
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1101
-            ),
1102
-            'retry_status'               => array(
1103
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1104
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1105
-            ),
1106
-            'failed_status'              => array(
1107
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1108
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1109
-            ),
1110
-        );
1111
-        if (EEM_Message::debug()) {
1112
-            $status_items['debug_only_status'] = array(
1113
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1114
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1115
-            );
1116
-        }
1117
-
1118
-        return array_merge($action_items, $status_items);
1119
-    }
1120
-
1121
-
1122
-    protected function _custom_mtps_preview()
1123
-    {
1124
-        $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1125
-        $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1126
-                                               . ' alt="' . esc_attr__(
1127
-                                                   'Preview Custom Message Templates screenshot',
1128
-                                                   'event_espresso'
1129
-                                               ) . '" />';
1130
-        $this->_template_args['preview_text'] = '<strong>'
1131
-                                                . esc_html__(
1132
-                                                    'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1133
-                                                    'event_espresso'
1134
-                                                )
1135
-                                                . '</strong>';
1136
-
1137
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * get_message_templates
1143
-     * This gets all the message templates for listing on the overview list.
1144
-     *
1145
-     * @access public
1146
-     * @param int    $perpage the amount of templates groups to show per page
1147
-     * @param string $type    the current _view we're getting templates for
1148
-     * @param bool   $count   return count?
1149
-     * @param bool   $all     disregard any paging info (get all data);
1150
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1151
-     * @return array
1152
-     * @throws EE_Error
1153
-     * @throws InvalidArgumentException
1154
-     * @throws InvalidDataTypeException
1155
-     * @throws InvalidInterfaceException
1156
-     */
1157
-    public function get_message_templates(
1158
-        $perpage = 10,
1159
-        $type = 'in_use',
1160
-        $count = false,
1161
-        $all = false,
1162
-        $global = true
1163
-    ) {
1164
-
1165
-        $MTP = EEM_Message_Template_Group::instance();
1166
-
1167
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1168
-        $orderby = $this->_req_data['orderby'];
1169
-
1170
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1171
-            ? $this->_req_data['order']
1172
-            : 'ASC';
1173
-
1174
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1175
-            ? $this->_req_data['paged']
1176
-            : 1;
1177
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1178
-            ? $this->_req_data['perpage']
1179
-            : $perpage;
1180
-
1181
-        $offset = ($current_page - 1) * $per_page;
1182
-        $limit = $all ? null : array($offset, $per_page);
1183
-
1184
-
1185
-        // options will match what is in the _views array property
1186
-        switch ($type) {
1187
-            case 'in_use':
1188
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1189
-                break;
1190
-            default:
1191
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1192
-        }
1193
-
1194
-        return $templates;
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     * filters etc might need a list of installed message_types
1200
-     *
1201
-     * @return array an array of message type objects
1202
-     */
1203
-    public function get_installed_message_types()
1204
-    {
1205
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1206
-        $installed = array();
1207
-
1208
-        foreach ($installed_message_types as $message_type) {
1209
-            $installed[ $message_type->name ] = $message_type;
1210
-        }
1211
-
1212
-        return $installed;
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * _add_message_template
1218
-     *
1219
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1220
-     *
1221
-     * @param string $message_type
1222
-     * @param string $messenger
1223
-     * @param string $GRP_ID
1224
-     *
1225
-     * @throws EE_error
1226
-     */
1227
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1228
-    {
1229
-        // set values override any request data
1230
-        $message_type = ! empty($message_type) ? $message_type : '';
1231
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1232
-            ? $this->_req_data['message_type']
1233
-            : $message_type;
1234
-
1235
-        $messenger = ! empty($messenger) ? $messenger : '';
1236
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1237
-            ? $this->_req_data['messenger']
1238
-            : $messenger;
1239
-
1240
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1241
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1242
-
1243
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1244
-        if (empty($message_type) || empty($messenger)) {
1245
-            throw new EE_Error(
1246
-                esc_html__(
1247
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1248
-                    'event_espresso'
1249
-                )
1250
-            );
1251
-        }
1252
-
1253
-        // we need the GRP_ID for the template being used as the base for the new template
1254
-        if (empty($GRP_ID)) {
1255
-            throw new EE_Error(
1256
-                esc_html__(
1257
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1258
-                    'event_espresso'
1259
-                )
1260
-            );
1261
-        }
1262
-
1263
-        // let's just make sure the template gets generated!
1264
-
1265
-        // we need to reassign some variables for what the insert is expecting
1266
-        $this->_req_data['MTP_messenger'] = $messenger;
1267
-        $this->_req_data['MTP_message_type'] = $message_type;
1268
-        $this->_req_data['GRP_ID'] = $GRP_ID;
1269
-        $this->_insert_or_update_message_template(true);
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     * public wrapper for the _add_message_template method
1275
-     *
1276
-     * @param string $message_type     message type slug
1277
-     * @param string $messenger        messenger slug
1278
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1279
-     *                                 off of.
1280
-     * @throws EE_error
1281
-     */
1282
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1283
-    {
1284
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * _edit_message_template
1290
-     *
1291
-     * @access protected
1292
-     * @return void
1293
-     * @throws InvalidIdentifierException
1294
-     * @throws DomainException
1295
-     * @throws EE_Error
1296
-     * @throws InvalidArgumentException
1297
-     * @throws ReflectionException
1298
-     * @throws InvalidDataTypeException
1299
-     * @throws InvalidInterfaceException
1300
-     */
1301
-    protected function _edit_message_template()
1302
-    {
1303
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1304
-        $template_fields = '';
1305
-        $sidebar_fields = '';
1306
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1307
-        // valid html in the templates.
1308
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1309
-
1310
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1311
-            ? absint($this->_req_data['id'])
1312
-            : false;
1313
-
1314
-        $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1315
-        ? absint($this->_req_data['evt_id'])
1316
-        : false;
1317
-
1318
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1319
-        $message_template_group = $this->_message_template_group;
1320
-        $c_label = $message_template_group->context_label();
1321
-        $c_config = $message_template_group->contexts_config();
1322
-
1323
-        reset($c_config);
1324
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1325
-            ? strtolower($this->_req_data['context'])
1326
-            : key($c_config);
1327
-
1328
-
1329
-        if (empty($GRP_ID)) {
1330
-            $action = 'insert_message_template';
1331
-            $edit_message_template_form_url = add_query_arg(
1332
-                array('action' => $action, 'noheader' => true),
1333
-                EE_MSG_ADMIN_URL
1334
-            );
1335
-        } else {
1336
-            $action = 'update_message_template';
1337
-            $edit_message_template_form_url = add_query_arg(
1338
-                array('action' => $action, 'noheader' => true),
1339
-                EE_MSG_ADMIN_URL
1340
-            );
1341
-        }
1342
-
1343
-        // set active messenger for this view
1344
-        $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
1345
-            $message_template_group->messenger()
1346
-        );
1347
-        $this->_active_message_type_name = $message_template_group->message_type();
1348
-
1349
-
1350
-        // Do we have any validation errors?
1351
-        $validators = $this->_get_transient();
1352
-        $v_fields = ! empty($validators) ? array_keys($validators) : array();
1353
-
1354
-
1355
-        // we need to assemble the title from Various details
1356
-        $context_label = sprintf(
1357
-            esc_html__('(%s %s)', 'event_espresso'),
1358
-            $c_config[ $context ]['label'],
1359
-            ucwords($c_label['label'])
1360
-        );
1361
-
1362
-        $title = sprintf(
1363
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1364
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1365
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1366
-            $context_label
1367
-        );
1368
-
1369
-        $this->_template_args['GRP_ID'] = $GRP_ID;
1370
-        $this->_template_args['message_template'] = $message_template_group;
1371
-        $this->_template_args['is_extra_fields'] = false;
1372
-
1373
-
1374
-        // let's get EEH_MSG_Template so we can get template form fields
1375
-        $template_field_structure = EEH_MSG_Template::get_fields(
1376
-            $message_template_group->messenger(),
1377
-            $message_template_group->message_type()
1378
-        );
1379
-
1380
-        if (! $template_field_structure) {
1381
-            $template_field_structure = false;
1382
-            $template_fields = esc_html__(
1383
-                'There was an error in assembling the fields for this display (you should see an error message)',
1384
-                'event_espresso'
1385
-            );
1386
-        }
1387
-
1388
-
1389
-        $message_templates = $message_template_group->context_templates();
1390
-
1391
-
1392
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1393
-        // will get handled in the "extra" array.
1394
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1395
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1396
-                unset($template_field_structure[ $context ][ $reference_field ]);
1397
-            }
1398
-        }
1399
-
1400
-        // let's loop through the template_field_structure and actually assemble the input fields!
1401
-        if (! empty($template_field_structure)) {
1402
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1403
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1404
-                // the extra array and reset them.
1405
-                if ($template_field === 'extra') {
1406
-                    $this->_template_args['is_extra_fields'] = true;
1407
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1408
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1409
-                        $content = $message_template instanceof EE_Message_Template
1410
-                            ? $message_template->get('MTP_content')
1411
-                            : '';
1412
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1413
-                            // let's verify if we need this extra field via the shortcodes parameter.
1414
-                            $continue = false;
1415
-                            if (isset($extra_array['shortcodes_required'])) {
1416
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1417
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1418
-                                        $continue = true;
1419
-                                    }
1420
-                                }
1421
-                                if ($continue) {
1422
-                                    continue;
1423
-                                }
1424
-                            }
1425
-
1426
-                            $field_id = $reference_field
1427
-                                        . '-'
1428
-                                        . $extra_field
1429
-                                        . '-content';
1430
-                            $template_form_fields[ $field_id ] = $extra_array;
1431
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1432
-                                                                         . $reference_field
1433
-                                                                         . '][content]['
1434
-                                                                         . $extra_field . ']';
1435
-                            $css_class = isset($extra_array['css_class'])
1436
-                                ? $extra_array['css_class']
1437
-                                : '';
1438
-
1439
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1440
-                                                                              && in_array($extra_field, $v_fields, true)
1441
-                                                                              &&
1442
-                                                                              (
1443
-                                                                                  is_array($validators[ $extra_field ])
1444
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1445
-                                                                              )
1446
-                                ? 'validate-error ' . $css_class
1447
-                                : $css_class;
1448
-
1449
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1450
-                                                                          && isset($content[ $extra_field ])
1451
-                                ? $content[ $extra_field ]
1452
-                                : '';
1453
-
1454
-                            // do we have a validation error?  if we do then let's use that value instead
1455
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1456
-                                ? $validators[ $extra_field ]['value']
1457
-                                : $template_form_fields[ $field_id ]['value'];
1458
-
1459
-
1460
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1461
-
1462
-                            // shortcode selector
1463
-                            $field_name_to_use = $extra_field === 'main'
1464
-                                ? 'content'
1465
-                                : $extra_field;
1466
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1467
-                                $field_name_to_use,
1468
-                                $field_id
1469
-                            );
1470
-
1471
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1472
-                                // we want to decode the entities
1473
-                                $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1474
-                            }/**/
1475
-                        }
1476
-                        $templatefield_MTP_id = $reference_field . '-MTP_ID';
1477
-                        $templatefield_templatename_id = $reference_field . '-name';
1478
-
1479
-                        $template_form_fields[ $templatefield_MTP_id ] = array(
1480
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1481
-                            'label'      => null,
1482
-                            'input'      => 'hidden',
1483
-                            'type'       => 'int',
1484
-                            'required'   => false,
1485
-                            'validation' => false,
1486
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1487
-                            'css_class'  => '',
1488
-                            'format'     => '%d',
1489
-                            'db-col'     => 'MTP_ID',
1490
-                        );
1491
-
1492
-                        $template_form_fields[ $templatefield_templatename_id ] = array(
1493
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1494
-                            'label'      => null,
1495
-                            'input'      => 'hidden',
1496
-                            'type'       => 'string',
1497
-                            'required'   => false,
1498
-                            'validation' => true,
1499
-                            'value'      => $reference_field,
1500
-                            'css_class'  => '',
1501
-                            'format'     => '%s',
1502
-                            'db-col'     => 'MTP_template_field',
1503
-                        );
1504
-                    }
1505
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1506
-                } else {
1507
-                    $field_id = $template_field . '-content';
1508
-                    $template_form_fields[ $field_id ] = $field_setup_array;
1509
-                    $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1510
-                    $message_template = isset($message_templates[ $context ][ $template_field ])
1511
-                        ? $message_templates[ $context ][ $template_field ]
1512
-                        : null;
1513
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1514
-                                                                  && is_array($message_templates[ $context ])
1515
-                                                                  && $message_template instanceof EE_Message_Template
1516
-                        ? $message_template->get('MTP_content')
1517
-                        : '';
1518
-
1519
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1520
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1521
-                        ? $validators[ $template_field ]['value']
1522
-                        : $template_form_fields[ $field_id ]['value'];
1523
-
1524
-
1525
-                    $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1526
-                    $css_class = isset($field_setup_array['css_class'])
1527
-                        ? $field_setup_array['css_class']
1528
-                        : '';
1529
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1530
-                                                                      && in_array($template_field, $v_fields, true)
1531
-                                                                      && isset($validators[ $template_field ]['msg'])
1532
-                        ? 'validate-error ' . $css_class
1533
-                        : $css_class;
1534
-
1535
-                    // shortcode selector
1536
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1537
-                        $template_field,
1538
-                        $field_id
1539
-                    );
1540
-                }
1541
-
1542
-                // k took care of content field(s) now let's take care of others.
1543
-
1544
-                $templatefield_MTP_id = $template_field . '-MTP_ID';
1545
-                $templatefield_field_templatename_id = $template_field . '-name';
1546
-
1547
-                // foreach template field there are actually two form fields created
1548
-                $template_form_fields[ $templatefield_MTP_id ] = array(
1549
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1550
-                    'label'      => null,
1551
-                    'input'      => 'hidden',
1552
-                    'type'       => 'int',
1553
-                    'required'   => false,
1554
-                    'validation' => true,
1555
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1556
-                    'css_class'  => '',
1557
-                    'format'     => '%d',
1558
-                    'db-col'     => 'MTP_ID',
1559
-                );
1560
-
1561
-                $template_form_fields[ $templatefield_field_templatename_id ] = array(
1562
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1563
-                    'label'      => null,
1564
-                    'input'      => 'hidden',
1565
-                    'type'       => 'string',
1566
-                    'required'   => false,
1567
-                    'validation' => true,
1568
-                    'value'      => $template_field,
1569
-                    'css_class'  => '',
1570
-                    'format'     => '%s',
1571
-                    'db-col'     => 'MTP_template_field',
1572
-                );
1573
-            }
1574
-
1575
-            // add other fields
1576
-            $template_form_fields['ee-msg-current-context'] = array(
1577
-                'name'       => 'MTP_context',
1578
-                'label'      => null,
1579
-                'input'      => 'hidden',
1580
-                'type'       => 'string',
1581
-                'required'   => false,
1582
-                'validation' => true,
1583
-                'value'      => $context,
1584
-                'css_class'  => '',
1585
-                'format'     => '%s',
1586
-                'db-col'     => 'MTP_context',
1587
-            );
1588
-
1589
-            $template_form_fields['ee-msg-grp-id'] = array(
1590
-                'name'       => 'GRP_ID',
1591
-                'label'      => null,
1592
-                'input'      => 'hidden',
1593
-                'type'       => 'int',
1594
-                'required'   => false,
1595
-                'validation' => true,
1596
-                'value'      => $GRP_ID,
1597
-                'css_class'  => '',
1598
-                'format'     => '%d',
1599
-                'db-col'     => 'GRP_ID',
1600
-            );
1601
-
1602
-            $template_form_fields['ee-msg-messenger'] = array(
1603
-                'name'       => 'MTP_messenger',
1604
-                'label'      => null,
1605
-                'input'      => 'hidden',
1606
-                'type'       => 'string',
1607
-                'required'   => false,
1608
-                'validation' => true,
1609
-                'value'      => $message_template_group->messenger(),
1610
-                'css_class'  => '',
1611
-                'format'     => '%s',
1612
-                'db-col'     => 'MTP_messenger',
1613
-            );
1614
-
1615
-            $template_form_fields['ee-msg-message-type'] = array(
1616
-                'name'       => 'MTP_message_type',
1617
-                'label'      => null,
1618
-                'input'      => 'hidden',
1619
-                'type'       => 'string',
1620
-                'required'   => false,
1621
-                'validation' => true,
1622
-                'value'      => $message_template_group->message_type(),
1623
-                'css_class'  => '',
1624
-                'format'     => '%s',
1625
-                'db-col'     => 'MTP_message_type',
1626
-            );
1627
-
1628
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1629
-                'name'       => 'MTP_is_global',
1630
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1631
-                'input'      => 'hidden',
1632
-                'type'       => 'int',
1633
-                'required'   => false,
1634
-                'validation' => true,
1635
-                'value'      => $message_template_group->get('MTP_is_global'),
1636
-                'css_class'  => '',
1637
-                'format'     => '%d',
1638
-                'db-col'     => 'MTP_is_global',
1639
-            );
1640
-
1641
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1642
-                'name'       => 'MTP_is_override',
1643
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1644
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1645
-                'type'       => 'int',
1646
-                'required'   => false,
1647
-                'validation' => true,
1648
-                'value'      => $message_template_group->get('MTP_is_override'),
1649
-                'css_class'  => '',
1650
-                'format'     => '%d',
1651
-                'db-col'     => 'MTP_is_override',
1652
-            );
1653
-
1654
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1655
-                'name'       => 'MTP_is_active',
1656
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1657
-                'input'      => 'hidden',
1658
-                'type'       => 'int',
1659
-                'required'   => false,
1660
-                'validation' => true,
1661
-                'value'      => $message_template_group->is_active(),
1662
-                'css_class'  => '',
1663
-                'format'     => '%d',
1664
-                'db-col'     => 'MTP_is_active',
1665
-            );
1666
-
1667
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1668
-                'name'       => 'MTP_deleted',
1669
-                'label'      => null,
1670
-                'input'      => 'hidden',
1671
-                'type'       => 'int',
1672
-                'required'   => false,
1673
-                'validation' => true,
1674
-                'value'      => $message_template_group->get('MTP_deleted'),
1675
-                'css_class'  => '',
1676
-                'format'     => '%d',
1677
-                'db-col'     => 'MTP_deleted',
1678
-            );
1679
-            $sidebar_form_fields['ee-msg-author'] = array(
1680
-                'name'       => 'MTP_user_id',
1681
-                'label'      => esc_html__('Author', 'event_espresso'),
1682
-                'input'      => 'hidden',
1683
-                'type'       => 'int',
1684
-                'required'   => false,
1685
-                'validation' => false,
1686
-                'value'      => $message_template_group->user(),
1687
-                'format'     => '%d',
1688
-                'db-col'     => 'MTP_user_id',
1689
-            );
1690
-
1691
-            $sidebar_form_fields['ee-msg-route'] = array(
1692
-                'name'  => 'action',
1693
-                'input' => 'hidden',
1694
-                'type'  => 'string',
1695
-                'value' => $action,
1696
-            );
1697
-
1698
-            $sidebar_form_fields['ee-msg-id'] = array(
1699
-                'name'  => 'id',
1700
-                'input' => 'hidden',
1701
-                'type'  => 'int',
1702
-                'value' => $GRP_ID,
1703
-            );
1704
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1705
-                'name'  => $action . '_nonce',
1706
-                'input' => 'hidden',
1707
-                'type'  => 'string',
1708
-                'value' => wp_create_nonce($action . '_nonce'),
1709
-            );
1710
-
1711
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1712
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1713
-                    'name'  => 'template_switch',
1714
-                    'input' => 'hidden',
1715
-                    'type'  => 'int',
1716
-                    'value' => 1,
1717
-                );
1718
-            }
1719
-
1720
-
1721
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1722
-            $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);
1723
-        } //end if ( !empty($template_field_structure) )
1724
-
1725
-        // set extra content for publish box
1726
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1727
-        $this->_set_publish_post_box_vars(
1728
-            'id',
1729
-            $GRP_ID,
1730
-            false,
1731
-            add_query_arg(
1732
-                array('action' => 'global_mtps'),
1733
-                $this->_admin_base_url
1734
-            )
1735
-        );
1736
-
1737
-        // add preview button
1738
-        $preview_url = parent::add_query_args_and_nonce(
1739
-            array(
1740
-                'message_type' => $message_template_group->message_type(),
1741
-                'messenger'    => $message_template_group->messenger(),
1742
-                'context'      => $context,
1743
-                'GRP_ID'       => $GRP_ID,
1744
-                'evt_id'       => $EVT_ID,
1745
-                'action'       => 'preview_message',
1746
-            ),
1747
-            $this->_admin_base_url
1748
-        );
1749
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1750
-                          . esc_html__('Preview', 'event_espresso')
1751
-                          . '</a>';
1752
-
1753
-
1754
-        // setup context switcher
1755
-        $context_switcher_args = array(
1756
-            'page'    => 'espresso_messages',
1757
-            'action'  => 'edit_message_template',
1758
-            'id'      => $GRP_ID,
1759
-            'evt_id'  => $EVT_ID,
1760
-            'context' => $context,
1761
-            'extra'   => $preview_button,
1762
-        );
1763
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1764
-
1765
-
1766
-        // main box
1767
-        $this->_template_args['template_fields'] = $template_fields;
1768
-        $this->_template_args['sidebar_box_id'] = 'details';
1769
-        $this->_template_args['action'] = $action;
1770
-        $this->_template_args['context'] = $context;
1771
-        $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;
1772
-        $this->_template_args['learn_more_about_message_templates_link'] =
1773
-            $this->_learn_more_about_message_templates_link();
1774
-
1775
-
1776
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1777
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1778
-            $message_template_group,
1779
-            $context,
1780
-            $context_label
1781
-        );
1782
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1783
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1784
-
1785
-        $this->_template_path = $this->_template_args['GRP_ID']
1786
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1787
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1788
-
1789
-        // send along EE_Message_Template_Group object for further template use.
1790
-        $this->_template_args['MTP'] = $message_template_group;
1791
-
1792
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1793
-            $this->_template_path,
1794
-            $this->_template_args,
1795
-            true
1796
-        );
1797
-
1798
-
1799
-        // finally, let's set the admin_page title
1800
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1801
-
1802
-
1803
-        // we need to take care of setting the shortcodes property for use elsewhere.
1804
-        $this->_set_shortcodes();
1805
-
1806
-
1807
-        // final template wrapper
1808
-        $this->display_admin_page_with_sidebar();
1809
-    }
1810
-
1811
-
1812
-    public function filter_tinymce_init($mceInit, $editor_id)
1813
-    {
1814
-        return $mceInit;
1815
-    }
1816
-
1817
-
1818
-    public function add_context_switcher()
1819
-    {
1820
-        return $this->_context_switcher;
1821
-    }
1822
-
1823
-
1824
-    /**
1825
-     * Adds the activation/deactivation toggle for the message template context.
1826
-     *
1827
-     * @param EE_Message_Template_Group $message_template_group
1828
-     * @param string                    $context
1829
-     * @param string                    $context_label
1830
-     * @return string
1831
-     * @throws DomainException
1832
-     * @throws EE_Error
1833
-     * @throws InvalidIdentifierException
1834
-     */
1835
-    protected function add_active_context_element(
1836
-        EE_Message_Template_Group $message_template_group,
1837
-        $context,
1838
-        $context_label
1839
-    ) {
1840
-        $template_args = array(
1841
-            'context'                   => $context,
1842
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1843
-            'is_active'                 => $message_template_group->is_context_active($context),
1844
-            'on_off_action'             => $message_template_group->is_context_active($context)
1845
-                ? 'context-off'
1846
-                : 'context-on',
1847
-            'context_label'             => str_replace(array('(', ')'), '', $context_label),
1848
-            'message_template_group_id' => $message_template_group->ID(),
1849
-        );
1850
-        return EEH_Template::display_template(
1851
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1852
-            $template_args,
1853
-            true
1854
-        );
1855
-    }
1856
-
1857
-
1858
-    /**
1859
-     * Ajax callback for `toggle_context_template` ajax action.
1860
-     * Handles toggling the message context on or off.
1861
-     *
1862
-     * @throws EE_Error
1863
-     * @throws InvalidArgumentException
1864
-     * @throws InvalidDataTypeException
1865
-     * @throws InvalidIdentifierException
1866
-     * @throws InvalidInterfaceException
1867
-     */
1868
-    public function toggle_context_template()
1869
-    {
1870
-        $success = true;
1871
-        // check for required data
1872
-        if (
1873
-            ! isset(
1874
-                $this->_req_data['message_template_group_id'],
1875
-                $this->_req_data['context'],
1876
-                $this->_req_data['status']
1877
-            )
1878
-        ) {
1879
-            EE_Error::add_error(
1880
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1881
-                __FILE__,
1882
-                __FUNCTION__,
1883
-                __LINE__
1884
-            );
1885
-            $success = false;
1886
-        }
1887
-
1888
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1889
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1890
-            : '';
1891
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1892
-        $this->_verify_nonce($nonce, $nonce_ref);
1893
-        $status = $this->_req_data['status'];
1894
-        if ($status !== 'off' && $status !== 'on') {
1895
-            EE_Error::add_error(
1896
-                sprintf(
1897
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1898
-                    $this->_req_data['status']
1899
-                ),
1900
-                __FILE__,
1901
-                __FUNCTION__,
1902
-                __LINE__
1903
-            );
1904
-            $success = false;
1905
-        }
1906
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1907
-            $this->_req_data['message_template_group_id']
1908
-        );
1909
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1910
-            EE_Error::add_error(
1911
-                sprintf(
1912
-                    esc_html__(
1913
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1914
-                        'event_espresso'
1915
-                    ),
1916
-                    $this->_req_data['message_template_group_id'],
1917
-                    'EE_Message_Template_Group'
1918
-                ),
1919
-                __FILE__,
1920
-                __FUNCTION__,
1921
-                __LINE__
1922
-            );
1923
-            $success = false;
1924
-        }
1925
-        if ($success) {
1926
-            $success = $status === 'off'
1927
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1928
-                : $message_template_group->activate_context($this->_req_data['context']);
1929
-        }
1930
-        $this->_template_args['success'] = $success;
1931
-        $this->_return_json();
1932
-    }
1933
-
1934
-
1935
-    public function _add_form_element_before()
1936
-    {
1937
-        return '<form method="post" action="'
1938
-               . $this->_template_args["edit_message_template_form_url"]
1939
-               . '" id="ee-msg-edit-frm">';
1940
-    }
1941
-
1942
-    public function _add_form_element_after()
1943
-    {
1944
-        return '</form>';
1945
-    }
1946
-
1947
-
1948
-    /**
1949
-     * This executes switching the template pack for a message template.
1950
-     *
1951
-     * @since 4.5.0
1952
-     * @throws EE_Error
1953
-     * @throws InvalidDataTypeException
1954
-     * @throws InvalidInterfaceException
1955
-     * @throws InvalidArgumentException
1956
-     * @throws ReflectionException
1957
-     */
1958
-    public function switch_template_pack()
1959
-    {
1960
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1961
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1962
-
1963
-        // verify we have needed values.
1964
-        if (empty($GRP_ID) || empty($template_pack)) {
1965
-            $this->_template_args['error'] = true;
1966
-            EE_Error::add_error(
1967
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1968
-                __FILE__,
1969
-                __FUNCTION__,
1970
-                __LINE__
1971
-            );
1972
-        } else {
1973
-            // get template, set the new template_pack and then reset to default
1974
-            /** @type EE_Message_Template_Group $message_template_group */
1975
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1976
-
1977
-            $message_template_group->set_template_pack_name($template_pack);
1978
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1979
-            $this->_req_data['mt'] = $message_template_group->message_type();
1980
-
1981
-            $query_args = $this->_reset_to_default_template();
1982
-
1983
-            if (empty($query_args['id'])) {
1984
-                EE_Error::add_error(
1985
-                    esc_html__(
1986
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1987
-                        'event_espresso'
1988
-                    ),
1989
-                    __FILE__,
1990
-                    __FUNCTION__,
1991
-                    __LINE__
1992
-                );
1993
-                $this->_template_args['error'] = true;
1994
-            } else {
1995
-                $template_label = $message_template_group->get_template_pack()->label;
1996
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1997
-                EE_Error::add_success(
1998
-                    sprintf(
1999
-                        esc_html__(
2000
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2001
-                            'event_espresso'
2002
-                        ),
2003
-                        $template_label,
2004
-                        $template_pack_labels->template_pack
2005
-                    )
2006
-                );
2007
-                // generate the redirect url for js.
2008
-                $url = self::add_query_args_and_nonce(
2009
-                    $query_args,
2010
-                    $this->_admin_base_url
2011
-                );
2012
-                $this->_template_args['data']['redirect_url'] = $url;
2013
-                $this->_template_args['success'] = true;
2014
-            }
2015
-
2016
-            $this->_return_json();
2017
-        }
2018
-    }
2019
-
2020
-
2021
-    /**
2022
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2023
-     * they want.
2024
-     *
2025
-     * @access protected
2026
-     * @return array|null
2027
-     * @throws EE_Error
2028
-     * @throws InvalidArgumentException
2029
-     * @throws InvalidDataTypeException
2030
-     * @throws InvalidInterfaceException
2031
-     */
2032
-    protected function _reset_to_default_template()
2033
-    {
2034
-
2035
-        $templates = array();
2036
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2037
-        // we need to make sure we've got the info we need.
2038
-        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2039
-            EE_Error::add_error(
2040
-                esc_html__(
2041
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2042
-                    'event_espresso'
2043
-                ),
2044
-                __FILE__,
2045
-                __FUNCTION__,
2046
-                __LINE__
2047
-            );
2048
-        }
2049
-
2050
-        // all templates will be reset to whatever the defaults are
2051
-        // for the global template matching the messenger and message type.
2052
-        $success = ! empty($GRP_ID) ? true : false;
2053
-
2054
-        if ($success) {
2055
-            // let's first determine if the incoming template is a global template,
2056
-            // if it isn't then we need to get the global template matching messenger and message type.
2057
-            // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2058
-
2059
-
2060
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2061
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2062
-
2063
-            if ($success) {
2064
-                // if successfully deleted, lets generate the new ones.
2065
-                // Note. We set GLOBAL to true, because resets on ANY template
2066
-                // will use the related global template defaults for regeneration.
2067
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2068
-                // HOWEVER, we DO keep the template pack and template variation set
2069
-                // for the current custom template when resetting.
2070
-                $templates = $this->_generate_new_templates(
2071
-                    $this->_req_data['msgr'],
2072
-                    $this->_req_data['mt'],
2073
-                    $GRP_ID,
2074
-                    true
2075
-                );
2076
-            }
2077
-        }
2078
-
2079
-        // any error messages?
2080
-        if (! $success) {
2081
-            EE_Error::add_error(
2082
-                esc_html__(
2083
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2084
-                    'event_espresso'
2085
-                ),
2086
-                __FILE__,
2087
-                __FUNCTION__,
2088
-                __LINE__
2089
-            );
2090
-        }
2091
-
2092
-        // all good, let's add a success message!
2093
-        if ($success && ! empty($templates)) {
2094
-            // the info for the template we generated is the first element in the returned array
2095
-            // $templates = $templates[0];
2096
-            EE_Error::overwrite_success();
2097
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2098
-        }
2099
-
2100
-
2101
-        $query_args = array(
2102
-            'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2103
-            'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2104
-            'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2105
-        );
2106
-
2107
-        // if called via ajax then we return query args otherwise redirect
2108
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2109
-            return $query_args;
2110
-        } else {
2111
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2112
-
2113
-            return null;
2114
-        }
2115
-    }
2116
-
2117
-
2118
-    /**
2119
-     * Retrieve and set the message preview for display.
2120
-     *
2121
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2122
-     * @return string
2123
-     * @throws ReflectionException
2124
-     * @throws EE_Error
2125
-     * @throws InvalidArgumentException
2126
-     * @throws InvalidDataTypeException
2127
-     * @throws InvalidInterfaceException
2128
-     */
2129
-    public function _preview_message($send = false)
2130
-    {
2131
-        // first make sure we've got the necessary parameters
2132
-        if (
2133
-            ! isset(
2134
-                $this->_req_data['message_type'],
2135
-                $this->_req_data['messenger'],
2136
-                $this->_req_data['messenger'],
2137
-                $this->_req_data['GRP_ID']
2138
-            )
2139
-        ) {
2140
-            EE_Error::add_error(
2141
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2142
-                __FILE__,
2143
-                __FUNCTION__,
2144
-                __LINE__
2145
-            );
2146
-        }
2147
-
2148
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2149
-
2150
-        // if we have an evt_id set on the request, use it.
2151
-        $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
2152
-        ? absint($this->_req_data['evt_id'])
2153
-        : false;
2154
-
2155
-
2156
-        // get the preview!
2157
-        $preview = EED_Messages::preview_message(
2158
-            $this->_req_data['message_type'],
2159
-            $this->_req_data['context'],
2160
-            $this->_req_data['messenger'],
2161
-            $send
2162
-        );
2163
-
2164
-        if ($send) {
2165
-            return $preview;
2166
-        }
2167
-
2168
-        // let's add a button to go back to the edit view
2169
-        $query_args = array(
2170
-            'id'      => $this->_req_data['GRP_ID'],
2171
-            'evt_id'  => $EVT_ID,
2172
-            'context' => $this->_req_data['context'],
2173
-            'action'  => 'edit_message_template',
2174
-        );
2175
-        $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2176
-        $preview_button = '<a href="'
2177
-                          . $go_back_url
2178
-                          . '" class="button-secondary messages-preview-go-back-button">'
2179
-                          . esc_html__('Go Back to Edit', 'event_espresso')
2180
-                          . '</a>';
2181
-        $message_types = $this->get_installed_message_types();
2182
-        $active_messenger = $this->_message_resource_manager->get_active_messenger(
2183
-            $this->_req_data['messenger']
2184
-        );
2185
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2186
-            ? ucwords($active_messenger->label['singular'])
2187
-            : esc_html__('Unknown Messenger', 'event_espresso');
2188
-        // let's provide a helpful title for context
2189
-        $preview_title = sprintf(
2190
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2191
-            $active_messenger_label,
2192
-            ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2193
-        );
2194
-        if (empty($preview)) {
2195
-            $this->noEventsErrorMessage();
2196
-        }
2197
-        // setup display of preview.
2198
-        $this->_admin_page_title = $preview_title;
2199
-        $this->_template_args['admin_page_title'] = $preview_title;
2200
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2201
-        $this->_template_args['data']['force_json'] = true;
2202
-
2203
-        return '';
2204
-    }
2205
-
2206
-
2207
-    /**
2208
-     * Used to set an error if there are no events available for generating a preview/test send.
2209
-     *
2210
-     * @param bool $test_send  Whether the error should be generated for the context of a test send.
2211
-     */
2212
-    protected function noEventsErrorMessage($test_send = false)
2213
-    {
2214
-        $events_url = parent::add_query_args_and_nonce(
2215
-            array(
2216
-                'action' => 'default',
2217
-                'page'   => 'espresso_events',
2218
-            ),
2219
-            admin_url('admin.php')
2220
-        );
2221
-        $message = $test_send
2222
-            ? __(
2223
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2224
-                'event_espresso'
2225
-            )
2226
-            : __(
2227
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2228
-                'event_espresso'
2229
-            );
2230
-
2231
-        EE_Error::add_attention(
2232
-            sprintf(
2233
-                $message,
2234
-                "<a href='{$events_url}'>",
2235
-                '</a>'
2236
-            )
2237
-        );
2238
-    }
2239
-
2240
-
2241
-    /**
2242
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2243
-     * gets called automatically.
2244
-     *
2245
-     * @since 4.5.0
2246
-     *
2247
-     * @return string
2248
-     */
2249
-    protected function _display_preview_message()
2250
-    {
2251
-        $this->display_admin_page_with_no_sidebar();
2252
-    }
2253
-
2254
-
2255
-    /**
2256
-     * registers metaboxes that should show up on the "edit_message_template" page
2257
-     *
2258
-     * @access protected
2259
-     * @return void
2260
-     */
2261
-    protected function _register_edit_meta_boxes()
2262
-    {
2263
-        add_meta_box(
2264
-            'mtp_valid_shortcodes',
2265
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2266
-            array($this, 'shortcode_meta_box'),
2267
-            $this->_current_screen->id,
2268
-            'side',
2269
-            'default'
2270
-        );
2271
-        add_meta_box(
2272
-            'mtp_extra_actions',
2273
-            esc_html__('Extra Actions', 'event_espresso'),
2274
-            array($this, 'extra_actions_meta_box'),
2275
-            $this->_current_screen->id,
2276
-            'side',
2277
-            'high'
2278
-        );
2279
-        add_meta_box(
2280
-            'mtp_templates',
2281
-            esc_html__('Template Styles', 'event_espresso'),
2282
-            array($this, 'template_pack_meta_box'),
2283
-            $this->_current_screen->id,
2284
-            'side',
2285
-            'high'
2286
-        );
2287
-    }
2288
-
2289
-
2290
-    /**
2291
-     * metabox content for all template pack and variation selection.
2292
-     *
2293
-     * @since 4.5.0
2294
-     * @return string
2295
-     * @throws DomainException
2296
-     * @throws EE_Error
2297
-     * @throws InvalidArgumentException
2298
-     * @throws ReflectionException
2299
-     * @throws InvalidDataTypeException
2300
-     * @throws InvalidInterfaceException
2301
-     */
2302
-    public function template_pack_meta_box()
2303
-    {
2304
-        $this->_set_message_template_group();
2305
-
2306
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2307
-
2308
-        $tp_select_values = array();
2309
-
2310
-        foreach ($tp_collection as $tp) {
2311
-            // only include template packs that support this messenger and message type!
2312
-            $supports = $tp->get_supports();
2313
-            if (
2314
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2315
-                || ! in_array(
2316
-                    $this->_message_template_group->message_type(),
2317
-                    $supports[ $this->_message_template_group->messenger() ],
2318
-                    true
2319
-                )
2320
-            ) {
2321
-                // not supported
2322
-                continue;
2323
-            }
2324
-
2325
-            $tp_select_values[] = array(
2326
-                'text' => $tp->label,
2327
-                'id'   => $tp->dbref,
2328
-            );
2329
-        }
2330
-
2331
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2332
-        // the default template pack.  This still allows for the odd template pack to override.
2333
-        if (empty($tp_select_values)) {
2334
-            $tp_select_values[] = array(
2335
-                'text' => esc_html__('Default', 'event_espresso'),
2336
-                'id'   => 'default',
2337
-            );
2338
-        }
2339
-
2340
-        // setup variation select values for the currently selected template.
2341
-        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2342
-            $this->_message_template_group->messenger(),
2343
-            $this->_message_template_group->message_type()
2344
-        );
2345
-        $variations_select_values = array();
2346
-        foreach ($variations as $variation => $label) {
2347
-            $variations_select_values[] = array(
2348
-                'text' => $label,
2349
-                'id'   => $variation,
2350
-            );
2351
-        }
2352
-
2353
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2354
-
2355
-        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2356
-            'MTP_template_pack',
2357
-            $tp_select_values,
2358
-            $this->_message_template_group->get_template_pack_name()
2359
-        );
2360
-        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2361
-            'MTP_template_variation',
2362
-            $variations_select_values,
2363
-            $this->_message_template_group->get_template_pack_variation()
2364
-        );
2365
-        $template_args['template_pack_label'] = $template_pack_labels->template_pack;
2366
-        $template_args['template_variation_label'] = $template_pack_labels->template_variation;
2367
-        $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2368
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2369
-
2370
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2371
-
2372
-        EEH_Template::display_template($template, $template_args);
2373
-    }
2374
-
2375
-
2376
-    /**
2377
-     * This meta box holds any extra actions related to Message Templates
2378
-     * For now, this includes Resetting templates to defaults and sending a test email.
2379
-     *
2380
-     * @access  public
2381
-     * @return void
2382
-     * @throws EE_Error
2383
-     */
2384
-    public function extra_actions_meta_box()
2385
-    {
2386
-        $template_form_fields = array();
2387
-
2388
-        $extra_args = array(
2389
-            'msgr'   => $this->_message_template_group->messenger(),
2390
-            'mt'     => $this->_message_template_group->message_type(),
2391
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2392
-        );
2393
-        // first we need to see if there are any fields
2394
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2395
-
2396
-        if (! empty($fields)) {
2397
-            // yup there be fields
2398
-            foreach ($fields as $field => $config) {
2399
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2400
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2401
-                $default = isset($config['default']) ? $config['default'] : '';
2402
-                $default = isset($config['value']) ? $config['value'] : $default;
2403
-
2404
-                // if type is hidden and the value is empty
2405
-                // something may have gone wrong so let's correct with the defaults
2406
-                $fix = $config['input'] === 'hidden'
2407
-                       && isset($existing[ $field ])
2408
-                       && empty($existing[ $field ])
2409
-                    ? $default
2410
-                    : '';
2411
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2412
-                    ? $existing[ $field ]
2413
-                    : $fix;
2414
-
2415
-                $template_form_fields[ $field_id ] = array(
2416
-                    'name'       => 'test_settings_fld[' . $field . ']',
2417
-                    'label'      => $config['label'],
2418
-                    'input'      => $config['input'],
2419
-                    'type'       => $config['type'],
2420
-                    'required'   => $config['required'],
2421
-                    'validation' => $config['validation'],
2422
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2423
-                    'css_class'  => $config['css_class'],
2424
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2425
-                    'default'    => $default,
2426
-                    'format'     => $config['format'],
2427
-                );
2428
-            }
2429
-        }
2430
-
2431
-        $test_settings_fields = ! empty($template_form_fields)
2432
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2433
-            : '';
2434
-
2435
-        $test_settings_html = '';
2436
-        // print out $test_settings_fields
2437
-        if (! empty($test_settings_fields)) {
2438
-            echo $test_settings_fields;
2439
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2440
-            $test_settings_html .= 'name="test_button" value="';
2441
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2442
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2443
-        }
2444
-
2445
-        // and button
2446
-        $test_settings_html .= '<p>'
2447
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2448
-                               . '</p>';
2449
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2450
-        $test_settings_html .= $this->get_action_link_or_button(
2451
-            'reset_to_default',
2452
-            'reset',
2453
-            $extra_args,
2454
-            'button-primary reset-default-button'
2455
-        );
2456
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2457
-        echo $test_settings_html;
2458
-    }
2459
-
2460
-
2461
-    /**
2462
-     * This returns the shortcode selector skeleton for a given context and field.
2463
-     *
2464
-     * @since 4.9.rc.000
2465
-     * @param string $field           The name of the field retrieving shortcodes for.
2466
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2467
-     * @return string
2468
-     * @throws DomainException
2469
-     * @throws EE_Error
2470
-     * @throws InvalidArgumentException
2471
-     * @throws ReflectionException
2472
-     * @throws InvalidDataTypeException
2473
-     * @throws InvalidInterfaceException
2474
-     */
2475
-    protected function _get_shortcode_selector($field, $linked_input_id)
2476
-    {
2477
-        $template_args = array(
2478
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2479
-            'fieldname'       => $field,
2480
-            'linked_input_id' => $linked_input_id,
2481
-        );
2482
-
2483
-        return EEH_Template::display_template(
2484
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2485
-            $template_args,
2486
-            true
2487
-        );
2488
-    }
2489
-
2490
-
2491
-    /**
2492
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2493
-     * page)
2494
-     *
2495
-     * @access public
2496
-     * @return void
2497
-     * @throws EE_Error
2498
-     * @throws InvalidArgumentException
2499
-     * @throws ReflectionException
2500
-     * @throws InvalidDataTypeException
2501
-     * @throws InvalidInterfaceException
2502
-     */
2503
-    public function shortcode_meta_box()
2504
-    {
2505
-        $shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set
2506
-        // $messenger = $this->_message_template_group->messenger_obj();
2507
-        // now let's set the content depending on the status of the shortcodes array
2508
-        if (empty($shortcodes)) {
2509
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2510
-            echo $content;
2511
-        } else {
2512
-            // $alt = 0;
2513
-            ?>
22
+	/**
23
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
24
+	 */
25
+	protected $_message_resource_manager;
26
+
27
+	/**
28
+	 * @type string $_active_message_type_name
29
+	 */
30
+	protected $_active_message_type_name = '';
31
+
32
+	/**
33
+	 * @type EE_messenger $_active_messenger
34
+	 */
35
+	protected $_active_messenger;
36
+	protected $_activate_state;
37
+	protected $_activate_meta_box_type;
38
+	protected $_current_message_meta_box;
39
+	protected $_current_message_meta_box_object;
40
+	protected $_context_switcher;
41
+	protected $_shortcodes = array();
42
+	protected $_active_messengers = array();
43
+	protected $_active_message_types = array();
44
+
45
+	/**
46
+	 * @var EE_Message_Template_Group $_message_template_group
47
+	 */
48
+	protected $_message_template_group;
49
+	protected $_m_mt_settings = array();
50
+
51
+
52
+	/**
53
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
54
+	 * IF there is no group then it gets automatically set to the Default template pack.
55
+	 *
56
+	 * @since 4.5.0
57
+	 *
58
+	 * @var EE_Messages_Template_Pack
59
+	 */
60
+	protected $_template_pack;
61
+
62
+
63
+	/**
64
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
65
+	 * group is.  If there is no group then it automatically gets set to default.
66
+	 *
67
+	 * @since 4.5.0
68
+	 *
69
+	 * @var string
70
+	 */
71
+	protected $_variation;
72
+
73
+
74
+	/**
75
+	 * @param bool $routing
76
+	 * @throws EE_Error
77
+	 */
78
+	public function __construct($routing = true)
79
+	{
80
+		// make sure messages autoloader is running
81
+		EED_Messages::set_autoloaders();
82
+		parent::__construct($routing);
83
+	}
84
+
85
+
86
+	protected function _init_page_props()
87
+	{
88
+		$this->page_slug = EE_MSG_PG_SLUG;
89
+		$this->page_label = esc_html__('Messages Settings', 'event_espresso');
90
+		$this->_admin_base_url = EE_MSG_ADMIN_URL;
91
+		$this->_admin_base_path = EE_MSG_ADMIN;
92
+
93
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state']
94
+			: array();
95
+
96
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
97
+		$this->_load_message_resource_manager();
98
+	}
99
+
100
+
101
+	/**
102
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
103
+	 *
104
+	 * @throws EE_Error
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @throws InvalidArgumentException
108
+	 * @throws ReflectionException
109
+	 */
110
+	protected function _load_message_resource_manager()
111
+	{
112
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
113
+	}
114
+
115
+
116
+	/**
117
+	 * @deprecated 4.9.9.rc.014
118
+	 * @return array
119
+	 * @throws EE_Error
120
+	 * @throws InvalidArgumentException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 */
124
+	public function get_messengers_for_list_table()
125
+	{
126
+		EE_Error::doing_it_wrong(
127
+			__METHOD__,
128
+			sprintf(
129
+				esc_html__(
130
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
131
+					'event_espresso'
132
+				),
133
+				'Messages_Admin_Page::get_messengers_select_input()'
134
+			),
135
+			'4.9.9.rc.014'
136
+		);
137
+
138
+		$m_values = array();
139
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
140
+		// setup messengers for selects
141
+		$i = 1;
142
+		foreach ($active_messengers as $active_messenger) {
143
+			if ($active_messenger instanceof EE_Message) {
144
+				$m_values[ $i ]['id'] = $active_messenger->messenger();
145
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
146
+				$i++;
147
+			}
148
+		}
149
+
150
+		return $m_values;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @deprecated 4.9.9.rc.014
156
+	 * @return array
157
+	 * @throws EE_Error
158
+	 * @throws InvalidArgumentException
159
+	 * @throws InvalidDataTypeException
160
+	 * @throws InvalidInterfaceException
161
+	 */
162
+	public function get_message_types_for_list_table()
163
+	{
164
+		EE_Error::doing_it_wrong(
165
+			__METHOD__,
166
+			sprintf(
167
+				esc_html__(
168
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
169
+					'event_espresso'
170
+				),
171
+				'Messages_Admin_Page::get_message_types_select_input()'
172
+			),
173
+			'4.9.9.rc.014'
174
+		);
175
+
176
+		$mt_values = array();
177
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
178
+		$i = 1;
179
+		foreach ($active_messages as $active_message) {
180
+			if ($active_message instanceof EE_Message) {
181
+				$mt_values[ $i ]['id'] = $active_message->message_type();
182
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
183
+				$i++;
184
+			}
185
+		}
186
+
187
+		return $mt_values;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @deprecated 4.9.9.rc.014
193
+	 * @return array
194
+	 * @throws EE_Error
195
+	 * @throws InvalidArgumentException
196
+	 * @throws InvalidDataTypeException
197
+	 * @throws InvalidInterfaceException
198
+	 */
199
+	public function get_contexts_for_message_types_for_list_table()
200
+	{
201
+		EE_Error::doing_it_wrong(
202
+			__METHOD__,
203
+			sprintf(
204
+				esc_html__(
205
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
206
+					'event_espresso'
207
+				),
208
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
209
+			),
210
+			'4.9.9.rc.014'
211
+		);
212
+
213
+		$contexts = array();
214
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
215
+		foreach ($active_message_contexts as $active_message) {
216
+			if ($active_message instanceof EE_Message) {
217
+				$message_type = $active_message->message_type_object();
218
+				if ($message_type instanceof EE_message_type) {
219
+					$message_type_contexts = $message_type->get_contexts();
220
+					foreach ($message_type_contexts as $context => $context_details) {
221
+						$contexts[ $context ] = $context_details['label'];
222
+					}
223
+				}
224
+			}
225
+		}
226
+
227
+		return $contexts;
228
+	}
229
+
230
+
231
+	/**
232
+	 * Generate select input with provided messenger options array.
233
+	 *
234
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
235
+	 *                                 labels.
236
+	 * @return string
237
+	 * @throws EE_Error
238
+	 */
239
+	public function get_messengers_select_input($messenger_options)
240
+	{
241
+		// if empty or just one value then just return an empty string
242
+		if (
243
+			empty($messenger_options)
244
+			|| ! is_array($messenger_options)
245
+			|| count($messenger_options) === 1
246
+		) {
247
+			return '';
248
+		}
249
+		// merge in default
250
+		$messenger_options = array_merge(
251
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
252
+			$messenger_options
253
+		);
254
+		$input = new EE_Select_Input(
255
+			$messenger_options,
256
+			array(
257
+				'html_name'  => 'ee_messenger_filter_by',
258
+				'html_id'    => 'ee_messenger_filter_by',
259
+				'html_class' => 'wide',
260
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
261
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
262
+					: 'none_selected',
263
+			)
264
+		);
265
+
266
+		return $input->get_html_for_input();
267
+	}
268
+
269
+
270
+	/**
271
+	 * Generate select input with provided message type options array.
272
+	 *
273
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
274
+	 *                                    message type labels
275
+	 * @return string
276
+	 * @throws EE_Error
277
+	 */
278
+	public function get_message_types_select_input($message_type_options)
279
+	{
280
+		// if empty or count of options is 1 then just return an empty string
281
+		if (
282
+			empty($message_type_options)
283
+			|| ! is_array($message_type_options)
284
+			|| count($message_type_options) === 1
285
+		) {
286
+			return '';
287
+		}
288
+		// merge in default
289
+		$message_type_options = array_merge(
290
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
+			$message_type_options
292
+		);
293
+		$input = new EE_Select_Input(
294
+			$message_type_options,
295
+			array(
296
+				'html_name'  => 'ee_message_type_filter_by',
297
+				'html_id'    => 'ee_message_type_filter_by',
298
+				'html_class' => 'wide',
299
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
+					: 'none_selected',
302
+			)
303
+		);
304
+
305
+		return $input->get_html_for_input();
306
+	}
307
+
308
+
309
+	/**
310
+	 * Generate select input with provide message type contexts array.
311
+	 *
312
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
+	 *                               context label.
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 */
317
+	public function get_contexts_for_message_types_select_input($context_options)
318
+	{
319
+		// if empty or count of options is one then just return empty string
320
+		if (
321
+			empty($context_options)
322
+			|| ! is_array($context_options)
323
+			|| count($context_options) === 1
324
+		) {
325
+			return '';
326
+		}
327
+		// merge in default
328
+		$context_options = array_merge(
329
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
+			$context_options
331
+		);
332
+		$input = new EE_Select_Input(
333
+			$context_options,
334
+			array(
335
+				'html_name'  => 'ee_context_filter_by',
336
+				'html_id'    => 'ee_context_filter_by',
337
+				'html_class' => 'wide',
338
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
339
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
340
+					: 'none_selected',
341
+			)
342
+		);
343
+
344
+		return $input->get_html_for_input();
345
+	}
346
+
347
+
348
+	protected function _ajax_hooks()
349
+	{
350
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
+	}
357
+
358
+
359
+	protected function _define_page_props()
360
+	{
361
+		$this->_admin_page_title = $this->page_label;
362
+		$this->_labels = array(
363
+			'buttons'    => array(
364
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
367
+			),
368
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
369
+		);
370
+	}
371
+
372
+
373
+	/**
374
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
375
+	 *
376
+	 * @access protected
377
+	 * @return void
378
+	 */
379
+	protected function _set_page_routes()
380
+	{
381
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
382
+			? $this->_req_data['GRP_ID']
383
+			: 0;
384
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
385
+			? $this->_req_data['id']
386
+			: $grp_id;
387
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
388
+			? $this->_req_data['MSG_ID']
389
+			: 0;
390
+
391
+		$this->_page_routes = array(
392
+			'default'                          => array(
393
+				'func'       => '_message_queue_list_table',
394
+				'capability' => 'ee_read_global_messages',
395
+			),
396
+			'global_mtps'                      => array(
397
+				'func'       => '_ee_default_messages_overview_list_table',
398
+				'capability' => 'ee_read_global_messages',
399
+			),
400
+			'custom_mtps'                      => array(
401
+				'func'       => '_custom_mtps_preview',
402
+				'capability' => 'ee_read_messages',
403
+			),
404
+			'add_new_message_template'         => array(
405
+				'func'       => '_add_message_template',
406
+				'capability' => 'ee_edit_messages',
407
+				'noheader'   => true,
408
+			),
409
+			'edit_message_template'            => array(
410
+				'func'       => '_edit_message_template',
411
+				'capability' => 'ee_edit_message',
412
+				'obj_id'     => $grp_id,
413
+			),
414
+			'preview_message'                  => array(
415
+				'func'               => '_preview_message',
416
+				'capability'         => 'ee_read_message',
417
+				'obj_id'             => $grp_id,
418
+				'noheader'           => true,
419
+				'headers_sent_route' => 'display_preview_message',
420
+			),
421
+			'display_preview_message'          => array(
422
+				'func'       => '_display_preview_message',
423
+				'capability' => 'ee_read_message',
424
+				'obj_id'     => $grp_id,
425
+			),
426
+			'insert_message_template'          => array(
427
+				'func'       => '_insert_or_update_message_template',
428
+				'capability' => 'ee_edit_messages',
429
+				'args'       => array('new_template' => true),
430
+				'noheader'   => true,
431
+			),
432
+			'update_message_template'          => array(
433
+				'func'       => '_insert_or_update_message_template',
434
+				'capability' => 'ee_edit_message',
435
+				'obj_id'     => $grp_id,
436
+				'args'       => array('new_template' => false),
437
+				'noheader'   => true,
438
+			),
439
+			'trash_message_template'           => array(
440
+				'func'       => '_trash_or_restore_message_template',
441
+				'capability' => 'ee_delete_message',
442
+				'obj_id'     => $grp_id,
443
+				'args'       => array('trash' => true, 'all' => true),
444
+				'noheader'   => true,
445
+			),
446
+			'trash_message_template_context'   => array(
447
+				'func'       => '_trash_or_restore_message_template',
448
+				'capability' => 'ee_delete_message',
449
+				'obj_id'     => $grp_id,
450
+				'args'       => array('trash' => true),
451
+				'noheader'   => true,
452
+			),
453
+			'restore_message_template'         => array(
454
+				'func'       => '_trash_or_restore_message_template',
455
+				'capability' => 'ee_delete_message',
456
+				'obj_id'     => $grp_id,
457
+				'args'       => array('trash' => false, 'all' => true),
458
+				'noheader'   => true,
459
+			),
460
+			'restore_message_template_context' => array(
461
+				'func'       => '_trash_or_restore_message_template',
462
+				'capability' => 'ee_delete_message',
463
+				'obj_id'     => $grp_id,
464
+				'args'       => array('trash' => false),
465
+				'noheader'   => true,
466
+			),
467
+			'delete_message_template'          => array(
468
+				'func'       => '_delete_message_template',
469
+				'capability' => 'ee_delete_message',
470
+				'obj_id'     => $grp_id,
471
+				'noheader'   => true,
472
+			),
473
+			'reset_to_default'                 => array(
474
+				'func'       => '_reset_to_default_template',
475
+				'capability' => 'ee_edit_message',
476
+				'obj_id'     => $grp_id,
477
+				'noheader'   => true,
478
+			),
479
+			'settings'                         => array(
480
+				'func'       => '_settings',
481
+				'capability' => 'manage_options',
482
+			),
483
+			'update_global_settings'           => array(
484
+				'func'       => '_update_global_settings',
485
+				'capability' => 'manage_options',
486
+				'noheader'   => true,
487
+			),
488
+			'generate_now'                     => array(
489
+				'func'       => '_generate_now',
490
+				'capability' => 'ee_send_message',
491
+				'noheader'   => true,
492
+			),
493
+			'generate_and_send_now'            => array(
494
+				'func'       => '_generate_and_send_now',
495
+				'capability' => 'ee_send_message',
496
+				'noheader'   => true,
497
+			),
498
+			'queue_for_resending'              => array(
499
+				'func'       => '_queue_for_resending',
500
+				'capability' => 'ee_send_message',
501
+				'noheader'   => true,
502
+			),
503
+			'send_now'                         => array(
504
+				'func'       => '_send_now',
505
+				'capability' => 'ee_send_message',
506
+				'noheader'   => true,
507
+			),
508
+			'delete_ee_message'                => array(
509
+				'func'       => '_delete_ee_messages',
510
+				'capability' => 'ee_delete_messages',
511
+				'noheader'   => true,
512
+			),
513
+			'delete_ee_messages'               => array(
514
+				'func'       => '_delete_ee_messages',
515
+				'capability' => 'ee_delete_messages',
516
+				'noheader'   => true,
517
+				'obj_id'     => $msg_id,
518
+			),
519
+		);
520
+	}
521
+
522
+
523
+	protected function _set_page_config()
524
+	{
525
+		$this->_page_config = array(
526
+			'default'                  => array(
527
+				'nav'           => array(
528
+					'label' => esc_html__('Message Activity', 'event_espresso'),
529
+					'order' => 10,
530
+				),
531
+				'list_table'    => 'EE_Message_List_Table',
532
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
533
+				'require_nonce' => false,
534
+			),
535
+			'global_mtps'              => array(
536
+				'nav'           => array(
537
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
538
+					'order' => 20,
539
+				),
540
+				'list_table'    => 'Messages_Template_List_Table',
541
+				'help_tabs'     => array(
542
+					'messages_overview_help_tab'                                => array(
543
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
544
+						'filename' => 'messages_overview',
545
+					),
546
+					'messages_overview_messages_table_column_headings_help_tab' => array(
547
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
548
+						'filename' => 'messages_overview_table_column_headings',
549
+					),
550
+					'messages_overview_messages_filters_help_tab'               => array(
551
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
552
+						'filename' => 'messages_overview_filters',
553
+					),
554
+					'messages_overview_messages_views_help_tab'                 => array(
555
+						'title'    => esc_html__('Message Views', 'event_espresso'),
556
+						'filename' => 'messages_overview_views',
557
+					),
558
+					'message_overview_message_types_help_tab'                   => array(
559
+						'title'    => esc_html__('Message Types', 'event_espresso'),
560
+						'filename' => 'messages_overview_types',
561
+					),
562
+					'messages_overview_messengers_help_tab'                     => array(
563
+						'title'    => esc_html__('Messengers', 'event_espresso'),
564
+						'filename' => 'messages_overview_messengers',
565
+					),
566
+				),
567
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
568
+				'require_nonce' => false,
569
+			),
570
+			'custom_mtps'              => array(
571
+				'nav'           => array(
572
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
573
+					'order' => 30,
574
+				),
575
+				'help_tabs'     => array(),
576
+				'help_tour'     => array(),
577
+				'require_nonce' => false,
578
+			),
579
+			'add_new_message_template' => array(
580
+				'nav'           => array(
581
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
582
+					'order'      => 5,
583
+					'persistent' => false,
584
+				),
585
+				'require_nonce' => false,
586
+			),
587
+			'edit_message_template'    => array(
588
+				'labels'        => array(
589
+					'buttons'    => array(
590
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
591
+					),
592
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
593
+				),
594
+				'nav'           => array(
595
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
596
+					'order'      => 5,
597
+					'persistent' => false,
598
+					'url'        => '',
599
+				),
600
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
601
+				'has_metaboxes' => true,
602
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
603
+				'help_tabs'     => array(
604
+					'edit_message_template'            => array(
605
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
606
+						'callback' => 'edit_message_template_help_tab',
607
+					),
608
+					'message_templates_help_tab'       => array(
609
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
610
+						'filename' => 'messages_templates',
611
+					),
612
+					'message_template_shortcodes'      => array(
613
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
614
+						'callback' => 'message_template_shortcodes_help_tab',
615
+					),
616
+					'message_preview_help_tab'         => array(
617
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
618
+						'filename' => 'messages_preview',
619
+					),
620
+					'messages_overview_other_help_tab' => array(
621
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
622
+						'filename' => 'messages_overview_other',
623
+					),
624
+				),
625
+				'require_nonce' => false,
626
+			),
627
+			'display_preview_message'  => array(
628
+				'nav'           => array(
629
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
630
+					'order'      => 5,
631
+					'url'        => '',
632
+					'persistent' => false,
633
+				),
634
+				'help_tabs'     => array(
635
+					'preview_message' => array(
636
+						'title'    => esc_html__('About Previews', 'event_espresso'),
637
+						'callback' => 'preview_message_help_tab',
638
+					),
639
+				),
640
+				'require_nonce' => false,
641
+			),
642
+			'settings'                 => array(
643
+				'nav'           => array(
644
+					'label' => esc_html__('Settings', 'event_espresso'),
645
+					'order' => 40,
646
+				),
647
+				'metaboxes'     => array('_messages_settings_metaboxes'),
648
+				'help_tabs'     => array(
649
+					'messages_settings_help_tab'               => array(
650
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
651
+						'filename' => 'messages_settings',
652
+					),
653
+					'messages_settings_message_types_help_tab' => array(
654
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
655
+						'filename' => 'messages_settings_message_types',
656
+					),
657
+					'messages_settings_messengers_help_tab'    => array(
658
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
659
+						'filename' => 'messages_settings_messengers',
660
+					),
661
+				),
662
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
663
+				'require_nonce' => false,
664
+			),
665
+		);
666
+	}
667
+
668
+
669
+	protected function _add_screen_options()
670
+	{
671
+		// todo
672
+	}
673
+
674
+
675
+	protected function _add_screen_options_global_mtps()
676
+	{
677
+		/**
678
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
679
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
680
+		 */
681
+		$page_title = $this->_admin_page_title;
682
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
683
+		$this->_per_page_screen_option();
684
+		$this->_admin_page_title = $page_title;
685
+	}
686
+
687
+
688
+	protected function _add_screen_options_default()
689
+	{
690
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
691
+		$this->_per_page_screen_option();
692
+	}
693
+
694
+
695
+	// none of the below group are currently used for Messages
696
+	protected function _add_feature_pointers()
697
+	{
698
+	}
699
+
700
+	public function admin_init()
701
+	{
702
+	}
703
+
704
+	public function admin_notices()
705
+	{
706
+	}
707
+
708
+	public function admin_footer_scripts()
709
+	{
710
+	}
711
+
712
+
713
+	public function messages_help_tab()
714
+	{
715
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
716
+	}
717
+
718
+
719
+	public function messengers_help_tab()
720
+	{
721
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
722
+	}
723
+
724
+
725
+	public function message_types_help_tab()
726
+	{
727
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
728
+	}
729
+
730
+
731
+	public function messages_overview_help_tab()
732
+	{
733
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
734
+	}
735
+
736
+
737
+	public function message_templates_help_tab()
738
+	{
739
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
740
+	}
741
+
742
+
743
+	public function edit_message_template_help_tab()
744
+	{
745
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
746
+						. esc_attr__('Editor Title', 'event_espresso')
747
+						. '" />';
748
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
749
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
750
+						. '" />';
751
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
752
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
753
+						. '" />';
754
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
755
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
756
+						. '" />';
757
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
758
+						. esc_attr__('Publish Metabox', 'event_espresso')
759
+						. '" />';
760
+		EEH_Template::display_template(
761
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
762
+			$args
763
+		);
764
+	}
765
+
766
+
767
+	public function message_template_shortcodes_help_tab()
768
+	{
769
+		$this->_set_shortcodes();
770
+		$args['shortcodes'] = $this->_shortcodes;
771
+		EEH_Template::display_template(
772
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
773
+			$args
774
+		);
775
+	}
776
+
777
+
778
+	public function preview_message_help_tab()
779
+	{
780
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
781
+	}
782
+
783
+
784
+	public function settings_help_tab()
785
+	{
786
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
787
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
788
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
789
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
790
+		$args['img3'] = '<div class="switch">'
791
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
792
+						. ' type="checkbox" checked="checked">'
793
+						. '<label for="ee-on-off-toggle-on"></label>'
794
+						. '</div>';
795
+		$args['img4'] = '<div class="switch">'
796
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
797
+						. ' type="checkbox">'
798
+						. '<label for="ee-on-off-toggle-on"></label>'
799
+						. '</div>';
800
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
801
+	}
802
+
803
+
804
+	public function load_scripts_styles()
805
+	{
806
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
807
+		wp_enqueue_style('espresso_ee_msg');
808
+
809
+		wp_register_script(
810
+			'ee-messages-settings',
811
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
812
+			array('jquery-ui-droppable', 'ee-serialize-full-array'),
813
+			EVENT_ESPRESSO_VERSION,
814
+			true
815
+		);
816
+		wp_register_script(
817
+			'ee-msg-list-table-js',
818
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
819
+			array('ee-dialog'),
820
+			EVENT_ESPRESSO_VERSION
821
+		);
822
+	}
823
+
824
+
825
+	public function load_scripts_styles_default()
826
+	{
827
+		wp_enqueue_script('ee-msg-list-table-js');
828
+	}
829
+
830
+
831
+	public function wp_editor_css($mce_css)
832
+	{
833
+		// if we're on the edit_message_template route
834
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
835
+			$message_type_name = $this->_active_message_type_name;
836
+
837
+			// we're going to REPLACE the existing mce css
838
+			// we need to get the css file location from the active messenger
839
+			$mce_css = $this->_active_messenger->get_variation(
840
+				$this->_template_pack,
841
+				$message_type_name,
842
+				true,
843
+				'wpeditor',
844
+				$this->_variation
845
+			);
846
+		}
847
+
848
+		return $mce_css;
849
+	}
850
+
851
+
852
+	public function load_scripts_styles_edit_message_template()
853
+	{
854
+
855
+		$this->_set_shortcodes();
856
+
857
+		EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
858
+			esc_html__(
859
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
860
+				'event_espresso'
861
+			),
862
+			$this->_message_template_group->messenger_obj()->label['singular'],
863
+			$this->_message_template_group->message_type_obj()->label['singular']
864
+		);
865
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
866
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
867
+			'event_espresso'
868
+		);
869
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
870
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
871
+			'event_espresso'
872
+		);
873
+
874
+		wp_register_script(
875
+			'ee_msgs_edit_js',
876
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
877
+			array('jquery'),
878
+			EVENT_ESPRESSO_VERSION
879
+		);
880
+
881
+		wp_enqueue_script('ee_admin_js');
882
+		wp_enqueue_script('ee_msgs_edit_js');
883
+
884
+		// add in special css for tiny_mce
885
+		add_filter('mce_css', array($this, 'wp_editor_css'));
886
+	}
887
+
888
+
889
+	public function load_scripts_styles_display_preview_message()
890
+	{
891
+
892
+		$this->_set_message_template_group();
893
+
894
+		if (isset($this->_req_data['messenger'])) {
895
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
896
+				$this->_req_data['messenger']
897
+			);
898
+		}
899
+
900
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
901
+
902
+
903
+		wp_enqueue_style(
904
+			'espresso_preview_css',
905
+			$this->_active_messenger->get_variation(
906
+				$this->_template_pack,
907
+				$message_type_name,
908
+				true,
909
+				'preview',
910
+				$this->_variation
911
+			)
912
+		);
913
+	}
914
+
915
+
916
+	public function load_scripts_styles_settings()
917
+	{
918
+		wp_register_style(
919
+			'ee-message-settings',
920
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
921
+			array(),
922
+			EVENT_ESPRESSO_VERSION
923
+		);
924
+		wp_enqueue_style('ee-text-links');
925
+		wp_enqueue_style('ee-message-settings');
926
+		wp_enqueue_script('ee-messages-settings');
927
+	}
928
+
929
+
930
+	/**
931
+	 * set views array for List Table
932
+	 */
933
+	public function _set_list_table_views_global_mtps()
934
+	{
935
+		$this->_views = array(
936
+			'in_use' => array(
937
+				'slug'  => 'in_use',
938
+				'label' => esc_html__('In Use', 'event_espresso'),
939
+				'count' => 0,
940
+			),
941
+		);
942
+	}
943
+
944
+
945
+	/**
946
+	 * Set views array for the Custom Template List Table
947
+	 */
948
+	public function _set_list_table_views_custom_mtps()
949
+	{
950
+		$this->_set_list_table_views_global_mtps();
951
+		$this->_views['in_use']['bulk_action'] = array(
952
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
953
+		);
954
+	}
955
+
956
+
957
+	/**
958
+	 * set views array for message queue list table
959
+	 *
960
+	 * @throws InvalidDataTypeException
961
+	 * @throws InvalidInterfaceException
962
+	 * @throws InvalidArgumentException
963
+	 * @throws EE_Error
964
+	 * @throws ReflectionException
965
+	 */
966
+	public function _set_list_table_views_default()
967
+	{
968
+		EE_Registry::instance()->load_helper('Template');
969
+
970
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
971
+			'ee_send_message',
972
+			'message_list_table_bulk_actions'
973
+		)
974
+			? array(
975
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
976
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
977
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
978
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
979
+			)
980
+			: array();
981
+
982
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
983
+			'ee_delete_messages',
984
+			'message_list_table_bulk_actions'
985
+		)
986
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
987
+			: array();
988
+
989
+
990
+		$this->_views = array(
991
+			'all' => array(
992
+				'slug'        => 'all',
993
+				'label'       => esc_html__('All', 'event_espresso'),
994
+				'count'       => 0,
995
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
996
+			),
997
+		);
998
+
999
+
1000
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
1001
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1002
+				continue;
1003
+			}
1004
+			$status_bulk_actions = $common_bulk_actions;
1005
+			// unset bulk actions not applying to status
1006
+			if (! empty($status_bulk_actions)) {
1007
+				switch ($status) {
1008
+					case EEM_Message::status_idle:
1009
+					case EEM_Message::status_resend:
1010
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1011
+						break;
1012
+
1013
+					case EEM_Message::status_failed:
1014
+					case EEM_Message::status_debug_only:
1015
+					case EEM_Message::status_messenger_executing:
1016
+						$status_bulk_actions = array();
1017
+						break;
1018
+
1019
+					case EEM_Message::status_incomplete:
1020
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1021
+						break;
1022
+
1023
+					case EEM_Message::status_retry:
1024
+					case EEM_Message::status_sent:
1025
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1026
+						break;
1027
+				}
1028
+			}
1029
+
1030
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1031
+			if ($status === EEM_Message::status_messenger_executing) {
1032
+				continue;
1033
+			}
1034
+
1035
+			$this->_views[ strtolower($status) ] = array(
1036
+				'slug'        => strtolower($status),
1037
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1038
+				'count'       => 0,
1039
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1040
+			);
1041
+		}
1042
+	}
1043
+
1044
+
1045
+	protected function _ee_default_messages_overview_list_table()
1046
+	{
1047
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1048
+		$this->display_admin_list_table_page_with_no_sidebar();
1049
+	}
1050
+
1051
+
1052
+	protected function _message_queue_list_table()
1053
+	{
1054
+		$this->_search_btn_label = esc_html__('Message Activity', 'event_espresso');
1055
+		$this->_template_args['per_column'] = 6;
1056
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());
1057
+		$this->_template_args['before_list_table'] = '<h3>'
1058
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1059
+													 . '</h3>';
1060
+		$this->display_admin_list_table_page_with_no_sidebar();
1061
+	}
1062
+
1063
+
1064
+	protected function _message_legend_items()
1065
+	{
1066
+
1067
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1068
+		$action_items = array();
1069
+
1070
+		foreach ($action_css_classes as $action_item => $action_details) {
1071
+			if ($action_item === 'see_notifications_for') {
1072
+				continue;
1073
+			}
1074
+			$action_items[ $action_item ] = array(
1075
+				'class' => $action_details['css_class'],
1076
+				'desc'  => $action_details['label'],
1077
+			);
1078
+		}
1079
+
1080
+		/** @type array $status_items status legend setup */
1081
+		$status_items = array(
1082
+			'incomplete_status'          => array(
1083
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1084
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1085
+			),
1086
+			'idle_status'                => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1088
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1089
+			),
1090
+			'resend_status'              => array(
1091
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1092
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1093
+			),
1094
+			'messenger_executing_status' => array(
1095
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1096
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1097
+			),
1098
+			'sent_status'                => array(
1099
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1100
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1101
+			),
1102
+			'retry_status'               => array(
1103
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1104
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1105
+			),
1106
+			'failed_status'              => array(
1107
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1108
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1109
+			),
1110
+		);
1111
+		if (EEM_Message::debug()) {
1112
+			$status_items['debug_only_status'] = array(
1113
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1114
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1115
+			);
1116
+		}
1117
+
1118
+		return array_merge($action_items, $status_items);
1119
+	}
1120
+
1121
+
1122
+	protected function _custom_mtps_preview()
1123
+	{
1124
+		$this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1125
+		$this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1126
+											   . ' alt="' . esc_attr__(
1127
+												   'Preview Custom Message Templates screenshot',
1128
+												   'event_espresso'
1129
+											   ) . '" />';
1130
+		$this->_template_args['preview_text'] = '<strong>'
1131
+												. esc_html__(
1132
+													'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1133
+													'event_espresso'
1134
+												)
1135
+												. '</strong>';
1136
+
1137
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * get_message_templates
1143
+	 * This gets all the message templates for listing on the overview list.
1144
+	 *
1145
+	 * @access public
1146
+	 * @param int    $perpage the amount of templates groups to show per page
1147
+	 * @param string $type    the current _view we're getting templates for
1148
+	 * @param bool   $count   return count?
1149
+	 * @param bool   $all     disregard any paging info (get all data);
1150
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1151
+	 * @return array
1152
+	 * @throws EE_Error
1153
+	 * @throws InvalidArgumentException
1154
+	 * @throws InvalidDataTypeException
1155
+	 * @throws InvalidInterfaceException
1156
+	 */
1157
+	public function get_message_templates(
1158
+		$perpage = 10,
1159
+		$type = 'in_use',
1160
+		$count = false,
1161
+		$all = false,
1162
+		$global = true
1163
+	) {
1164
+
1165
+		$MTP = EEM_Message_Template_Group::instance();
1166
+
1167
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1168
+		$orderby = $this->_req_data['orderby'];
1169
+
1170
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1171
+			? $this->_req_data['order']
1172
+			: 'ASC';
1173
+
1174
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1175
+			? $this->_req_data['paged']
1176
+			: 1;
1177
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1178
+			? $this->_req_data['perpage']
1179
+			: $perpage;
1180
+
1181
+		$offset = ($current_page - 1) * $per_page;
1182
+		$limit = $all ? null : array($offset, $per_page);
1183
+
1184
+
1185
+		// options will match what is in the _views array property
1186
+		switch ($type) {
1187
+			case 'in_use':
1188
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1189
+				break;
1190
+			default:
1191
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1192
+		}
1193
+
1194
+		return $templates;
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 * filters etc might need a list of installed message_types
1200
+	 *
1201
+	 * @return array an array of message type objects
1202
+	 */
1203
+	public function get_installed_message_types()
1204
+	{
1205
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1206
+		$installed = array();
1207
+
1208
+		foreach ($installed_message_types as $message_type) {
1209
+			$installed[ $message_type->name ] = $message_type;
1210
+		}
1211
+
1212
+		return $installed;
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * _add_message_template
1218
+	 *
1219
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1220
+	 *
1221
+	 * @param string $message_type
1222
+	 * @param string $messenger
1223
+	 * @param string $GRP_ID
1224
+	 *
1225
+	 * @throws EE_error
1226
+	 */
1227
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1228
+	{
1229
+		// set values override any request data
1230
+		$message_type = ! empty($message_type) ? $message_type : '';
1231
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1232
+			? $this->_req_data['message_type']
1233
+			: $message_type;
1234
+
1235
+		$messenger = ! empty($messenger) ? $messenger : '';
1236
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1237
+			? $this->_req_data['messenger']
1238
+			: $messenger;
1239
+
1240
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1241
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1242
+
1243
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1244
+		if (empty($message_type) || empty($messenger)) {
1245
+			throw new EE_Error(
1246
+				esc_html__(
1247
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1248
+					'event_espresso'
1249
+				)
1250
+			);
1251
+		}
1252
+
1253
+		// we need the GRP_ID for the template being used as the base for the new template
1254
+		if (empty($GRP_ID)) {
1255
+			throw new EE_Error(
1256
+				esc_html__(
1257
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1258
+					'event_espresso'
1259
+				)
1260
+			);
1261
+		}
1262
+
1263
+		// let's just make sure the template gets generated!
1264
+
1265
+		// we need to reassign some variables for what the insert is expecting
1266
+		$this->_req_data['MTP_messenger'] = $messenger;
1267
+		$this->_req_data['MTP_message_type'] = $message_type;
1268
+		$this->_req_data['GRP_ID'] = $GRP_ID;
1269
+		$this->_insert_or_update_message_template(true);
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 * public wrapper for the _add_message_template method
1275
+	 *
1276
+	 * @param string $message_type     message type slug
1277
+	 * @param string $messenger        messenger slug
1278
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1279
+	 *                                 off of.
1280
+	 * @throws EE_error
1281
+	 */
1282
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1283
+	{
1284
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * _edit_message_template
1290
+	 *
1291
+	 * @access protected
1292
+	 * @return void
1293
+	 * @throws InvalidIdentifierException
1294
+	 * @throws DomainException
1295
+	 * @throws EE_Error
1296
+	 * @throws InvalidArgumentException
1297
+	 * @throws ReflectionException
1298
+	 * @throws InvalidDataTypeException
1299
+	 * @throws InvalidInterfaceException
1300
+	 */
1301
+	protected function _edit_message_template()
1302
+	{
1303
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1304
+		$template_fields = '';
1305
+		$sidebar_fields = '';
1306
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1307
+		// valid html in the templates.
1308
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1309
+
1310
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1311
+			? absint($this->_req_data['id'])
1312
+			: false;
1313
+
1314
+		$EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1315
+		? absint($this->_req_data['evt_id'])
1316
+		: false;
1317
+
1318
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1319
+		$message_template_group = $this->_message_template_group;
1320
+		$c_label = $message_template_group->context_label();
1321
+		$c_config = $message_template_group->contexts_config();
1322
+
1323
+		reset($c_config);
1324
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1325
+			? strtolower($this->_req_data['context'])
1326
+			: key($c_config);
1327
+
1328
+
1329
+		if (empty($GRP_ID)) {
1330
+			$action = 'insert_message_template';
1331
+			$edit_message_template_form_url = add_query_arg(
1332
+				array('action' => $action, 'noheader' => true),
1333
+				EE_MSG_ADMIN_URL
1334
+			);
1335
+		} else {
1336
+			$action = 'update_message_template';
1337
+			$edit_message_template_form_url = add_query_arg(
1338
+				array('action' => $action, 'noheader' => true),
1339
+				EE_MSG_ADMIN_URL
1340
+			);
1341
+		}
1342
+
1343
+		// set active messenger for this view
1344
+		$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
1345
+			$message_template_group->messenger()
1346
+		);
1347
+		$this->_active_message_type_name = $message_template_group->message_type();
1348
+
1349
+
1350
+		// Do we have any validation errors?
1351
+		$validators = $this->_get_transient();
1352
+		$v_fields = ! empty($validators) ? array_keys($validators) : array();
1353
+
1354
+
1355
+		// we need to assemble the title from Various details
1356
+		$context_label = sprintf(
1357
+			esc_html__('(%s %s)', 'event_espresso'),
1358
+			$c_config[ $context ]['label'],
1359
+			ucwords($c_label['label'])
1360
+		);
1361
+
1362
+		$title = sprintf(
1363
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1364
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1365
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1366
+			$context_label
1367
+		);
1368
+
1369
+		$this->_template_args['GRP_ID'] = $GRP_ID;
1370
+		$this->_template_args['message_template'] = $message_template_group;
1371
+		$this->_template_args['is_extra_fields'] = false;
1372
+
1373
+
1374
+		// let's get EEH_MSG_Template so we can get template form fields
1375
+		$template_field_structure = EEH_MSG_Template::get_fields(
1376
+			$message_template_group->messenger(),
1377
+			$message_template_group->message_type()
1378
+		);
1379
+
1380
+		if (! $template_field_structure) {
1381
+			$template_field_structure = false;
1382
+			$template_fields = esc_html__(
1383
+				'There was an error in assembling the fields for this display (you should see an error message)',
1384
+				'event_espresso'
1385
+			);
1386
+		}
1387
+
1388
+
1389
+		$message_templates = $message_template_group->context_templates();
1390
+
1391
+
1392
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1393
+		// will get handled in the "extra" array.
1394
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1395
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1396
+				unset($template_field_structure[ $context ][ $reference_field ]);
1397
+			}
1398
+		}
1399
+
1400
+		// let's loop through the template_field_structure and actually assemble the input fields!
1401
+		if (! empty($template_field_structure)) {
1402
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1403
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1404
+				// the extra array and reset them.
1405
+				if ($template_field === 'extra') {
1406
+					$this->_template_args['is_extra_fields'] = true;
1407
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1408
+						$message_template = $message_templates[ $context ][ $reference_field ];
1409
+						$content = $message_template instanceof EE_Message_Template
1410
+							? $message_template->get('MTP_content')
1411
+							: '';
1412
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1413
+							// let's verify if we need this extra field via the shortcodes parameter.
1414
+							$continue = false;
1415
+							if (isset($extra_array['shortcodes_required'])) {
1416
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1417
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1418
+										$continue = true;
1419
+									}
1420
+								}
1421
+								if ($continue) {
1422
+									continue;
1423
+								}
1424
+							}
1425
+
1426
+							$field_id = $reference_field
1427
+										. '-'
1428
+										. $extra_field
1429
+										. '-content';
1430
+							$template_form_fields[ $field_id ] = $extra_array;
1431
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1432
+																		 . $reference_field
1433
+																		 . '][content]['
1434
+																		 . $extra_field . ']';
1435
+							$css_class = isset($extra_array['css_class'])
1436
+								? $extra_array['css_class']
1437
+								: '';
1438
+
1439
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1440
+																			  && in_array($extra_field, $v_fields, true)
1441
+																			  &&
1442
+																			  (
1443
+																				  is_array($validators[ $extra_field ])
1444
+																				  && isset($validators[ $extra_field ]['msg'])
1445
+																			  )
1446
+								? 'validate-error ' . $css_class
1447
+								: $css_class;
1448
+
1449
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1450
+																		  && isset($content[ $extra_field ])
1451
+								? $content[ $extra_field ]
1452
+								: '';
1453
+
1454
+							// do we have a validation error?  if we do then let's use that value instead
1455
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1456
+								? $validators[ $extra_field ]['value']
1457
+								: $template_form_fields[ $field_id ]['value'];
1458
+
1459
+
1460
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1461
+
1462
+							// shortcode selector
1463
+							$field_name_to_use = $extra_field === 'main'
1464
+								? 'content'
1465
+								: $extra_field;
1466
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1467
+								$field_name_to_use,
1468
+								$field_id
1469
+							);
1470
+
1471
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1472
+								// we want to decode the entities
1473
+								$template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1474
+							}/**/
1475
+						}
1476
+						$templatefield_MTP_id = $reference_field . '-MTP_ID';
1477
+						$templatefield_templatename_id = $reference_field . '-name';
1478
+
1479
+						$template_form_fields[ $templatefield_MTP_id ] = array(
1480
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1481
+							'label'      => null,
1482
+							'input'      => 'hidden',
1483
+							'type'       => 'int',
1484
+							'required'   => false,
1485
+							'validation' => false,
1486
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1487
+							'css_class'  => '',
1488
+							'format'     => '%d',
1489
+							'db-col'     => 'MTP_ID',
1490
+						);
1491
+
1492
+						$template_form_fields[ $templatefield_templatename_id ] = array(
1493
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1494
+							'label'      => null,
1495
+							'input'      => 'hidden',
1496
+							'type'       => 'string',
1497
+							'required'   => false,
1498
+							'validation' => true,
1499
+							'value'      => $reference_field,
1500
+							'css_class'  => '',
1501
+							'format'     => '%s',
1502
+							'db-col'     => 'MTP_template_field',
1503
+						);
1504
+					}
1505
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1506
+				} else {
1507
+					$field_id = $template_field . '-content';
1508
+					$template_form_fields[ $field_id ] = $field_setup_array;
1509
+					$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1510
+					$message_template = isset($message_templates[ $context ][ $template_field ])
1511
+						? $message_templates[ $context ][ $template_field ]
1512
+						: null;
1513
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1514
+																  && is_array($message_templates[ $context ])
1515
+																  && $message_template instanceof EE_Message_Template
1516
+						? $message_template->get('MTP_content')
1517
+						: '';
1518
+
1519
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1520
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1521
+						? $validators[ $template_field ]['value']
1522
+						: $template_form_fields[ $field_id ]['value'];
1523
+
1524
+
1525
+					$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1526
+					$css_class = isset($field_setup_array['css_class'])
1527
+						? $field_setup_array['css_class']
1528
+						: '';
1529
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1530
+																	  && in_array($template_field, $v_fields, true)
1531
+																	  && isset($validators[ $template_field ]['msg'])
1532
+						? 'validate-error ' . $css_class
1533
+						: $css_class;
1534
+
1535
+					// shortcode selector
1536
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1537
+						$template_field,
1538
+						$field_id
1539
+					);
1540
+				}
1541
+
1542
+				// k took care of content field(s) now let's take care of others.
1543
+
1544
+				$templatefield_MTP_id = $template_field . '-MTP_ID';
1545
+				$templatefield_field_templatename_id = $template_field . '-name';
1546
+
1547
+				// foreach template field there are actually two form fields created
1548
+				$template_form_fields[ $templatefield_MTP_id ] = array(
1549
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1550
+					'label'      => null,
1551
+					'input'      => 'hidden',
1552
+					'type'       => 'int',
1553
+					'required'   => false,
1554
+					'validation' => true,
1555
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1556
+					'css_class'  => '',
1557
+					'format'     => '%d',
1558
+					'db-col'     => 'MTP_ID',
1559
+				);
1560
+
1561
+				$template_form_fields[ $templatefield_field_templatename_id ] = array(
1562
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1563
+					'label'      => null,
1564
+					'input'      => 'hidden',
1565
+					'type'       => 'string',
1566
+					'required'   => false,
1567
+					'validation' => true,
1568
+					'value'      => $template_field,
1569
+					'css_class'  => '',
1570
+					'format'     => '%s',
1571
+					'db-col'     => 'MTP_template_field',
1572
+				);
1573
+			}
1574
+
1575
+			// add other fields
1576
+			$template_form_fields['ee-msg-current-context'] = array(
1577
+				'name'       => 'MTP_context',
1578
+				'label'      => null,
1579
+				'input'      => 'hidden',
1580
+				'type'       => 'string',
1581
+				'required'   => false,
1582
+				'validation' => true,
1583
+				'value'      => $context,
1584
+				'css_class'  => '',
1585
+				'format'     => '%s',
1586
+				'db-col'     => 'MTP_context',
1587
+			);
1588
+
1589
+			$template_form_fields['ee-msg-grp-id'] = array(
1590
+				'name'       => 'GRP_ID',
1591
+				'label'      => null,
1592
+				'input'      => 'hidden',
1593
+				'type'       => 'int',
1594
+				'required'   => false,
1595
+				'validation' => true,
1596
+				'value'      => $GRP_ID,
1597
+				'css_class'  => '',
1598
+				'format'     => '%d',
1599
+				'db-col'     => 'GRP_ID',
1600
+			);
1601
+
1602
+			$template_form_fields['ee-msg-messenger'] = array(
1603
+				'name'       => 'MTP_messenger',
1604
+				'label'      => null,
1605
+				'input'      => 'hidden',
1606
+				'type'       => 'string',
1607
+				'required'   => false,
1608
+				'validation' => true,
1609
+				'value'      => $message_template_group->messenger(),
1610
+				'css_class'  => '',
1611
+				'format'     => '%s',
1612
+				'db-col'     => 'MTP_messenger',
1613
+			);
1614
+
1615
+			$template_form_fields['ee-msg-message-type'] = array(
1616
+				'name'       => 'MTP_message_type',
1617
+				'label'      => null,
1618
+				'input'      => 'hidden',
1619
+				'type'       => 'string',
1620
+				'required'   => false,
1621
+				'validation' => true,
1622
+				'value'      => $message_template_group->message_type(),
1623
+				'css_class'  => '',
1624
+				'format'     => '%s',
1625
+				'db-col'     => 'MTP_message_type',
1626
+			);
1627
+
1628
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1629
+				'name'       => 'MTP_is_global',
1630
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1631
+				'input'      => 'hidden',
1632
+				'type'       => 'int',
1633
+				'required'   => false,
1634
+				'validation' => true,
1635
+				'value'      => $message_template_group->get('MTP_is_global'),
1636
+				'css_class'  => '',
1637
+				'format'     => '%d',
1638
+				'db-col'     => 'MTP_is_global',
1639
+			);
1640
+
1641
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1642
+				'name'       => 'MTP_is_override',
1643
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1644
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1645
+				'type'       => 'int',
1646
+				'required'   => false,
1647
+				'validation' => true,
1648
+				'value'      => $message_template_group->get('MTP_is_override'),
1649
+				'css_class'  => '',
1650
+				'format'     => '%d',
1651
+				'db-col'     => 'MTP_is_override',
1652
+			);
1653
+
1654
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1655
+				'name'       => 'MTP_is_active',
1656
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1657
+				'input'      => 'hidden',
1658
+				'type'       => 'int',
1659
+				'required'   => false,
1660
+				'validation' => true,
1661
+				'value'      => $message_template_group->is_active(),
1662
+				'css_class'  => '',
1663
+				'format'     => '%d',
1664
+				'db-col'     => 'MTP_is_active',
1665
+			);
1666
+
1667
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1668
+				'name'       => 'MTP_deleted',
1669
+				'label'      => null,
1670
+				'input'      => 'hidden',
1671
+				'type'       => 'int',
1672
+				'required'   => false,
1673
+				'validation' => true,
1674
+				'value'      => $message_template_group->get('MTP_deleted'),
1675
+				'css_class'  => '',
1676
+				'format'     => '%d',
1677
+				'db-col'     => 'MTP_deleted',
1678
+			);
1679
+			$sidebar_form_fields['ee-msg-author'] = array(
1680
+				'name'       => 'MTP_user_id',
1681
+				'label'      => esc_html__('Author', 'event_espresso'),
1682
+				'input'      => 'hidden',
1683
+				'type'       => 'int',
1684
+				'required'   => false,
1685
+				'validation' => false,
1686
+				'value'      => $message_template_group->user(),
1687
+				'format'     => '%d',
1688
+				'db-col'     => 'MTP_user_id',
1689
+			);
1690
+
1691
+			$sidebar_form_fields['ee-msg-route'] = array(
1692
+				'name'  => 'action',
1693
+				'input' => 'hidden',
1694
+				'type'  => 'string',
1695
+				'value' => $action,
1696
+			);
1697
+
1698
+			$sidebar_form_fields['ee-msg-id'] = array(
1699
+				'name'  => 'id',
1700
+				'input' => 'hidden',
1701
+				'type'  => 'int',
1702
+				'value' => $GRP_ID,
1703
+			);
1704
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1705
+				'name'  => $action . '_nonce',
1706
+				'input' => 'hidden',
1707
+				'type'  => 'string',
1708
+				'value' => wp_create_nonce($action . '_nonce'),
1709
+			);
1710
+
1711
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1712
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1713
+					'name'  => 'template_switch',
1714
+					'input' => 'hidden',
1715
+					'type'  => 'int',
1716
+					'value' => 1,
1717
+				);
1718
+			}
1719
+
1720
+
1721
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1722
+			$sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);
1723
+		} //end if ( !empty($template_field_structure) )
1724
+
1725
+		// set extra content for publish box
1726
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1727
+		$this->_set_publish_post_box_vars(
1728
+			'id',
1729
+			$GRP_ID,
1730
+			false,
1731
+			add_query_arg(
1732
+				array('action' => 'global_mtps'),
1733
+				$this->_admin_base_url
1734
+			)
1735
+		);
1736
+
1737
+		// add preview button
1738
+		$preview_url = parent::add_query_args_and_nonce(
1739
+			array(
1740
+				'message_type' => $message_template_group->message_type(),
1741
+				'messenger'    => $message_template_group->messenger(),
1742
+				'context'      => $context,
1743
+				'GRP_ID'       => $GRP_ID,
1744
+				'evt_id'       => $EVT_ID,
1745
+				'action'       => 'preview_message',
1746
+			),
1747
+			$this->_admin_base_url
1748
+		);
1749
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1750
+						  . esc_html__('Preview', 'event_espresso')
1751
+						  . '</a>';
1752
+
1753
+
1754
+		// setup context switcher
1755
+		$context_switcher_args = array(
1756
+			'page'    => 'espresso_messages',
1757
+			'action'  => 'edit_message_template',
1758
+			'id'      => $GRP_ID,
1759
+			'evt_id'  => $EVT_ID,
1760
+			'context' => $context,
1761
+			'extra'   => $preview_button,
1762
+		);
1763
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1764
+
1765
+
1766
+		// main box
1767
+		$this->_template_args['template_fields'] = $template_fields;
1768
+		$this->_template_args['sidebar_box_id'] = 'details';
1769
+		$this->_template_args['action'] = $action;
1770
+		$this->_template_args['context'] = $context;
1771
+		$this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;
1772
+		$this->_template_args['learn_more_about_message_templates_link'] =
1773
+			$this->_learn_more_about_message_templates_link();
1774
+
1775
+
1776
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1777
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1778
+			$message_template_group,
1779
+			$context,
1780
+			$context_label
1781
+		);
1782
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1783
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1784
+
1785
+		$this->_template_path = $this->_template_args['GRP_ID']
1786
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1787
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1788
+
1789
+		// send along EE_Message_Template_Group object for further template use.
1790
+		$this->_template_args['MTP'] = $message_template_group;
1791
+
1792
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1793
+			$this->_template_path,
1794
+			$this->_template_args,
1795
+			true
1796
+		);
1797
+
1798
+
1799
+		// finally, let's set the admin_page title
1800
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1801
+
1802
+
1803
+		// we need to take care of setting the shortcodes property for use elsewhere.
1804
+		$this->_set_shortcodes();
1805
+
1806
+
1807
+		// final template wrapper
1808
+		$this->display_admin_page_with_sidebar();
1809
+	}
1810
+
1811
+
1812
+	public function filter_tinymce_init($mceInit, $editor_id)
1813
+	{
1814
+		return $mceInit;
1815
+	}
1816
+
1817
+
1818
+	public function add_context_switcher()
1819
+	{
1820
+		return $this->_context_switcher;
1821
+	}
1822
+
1823
+
1824
+	/**
1825
+	 * Adds the activation/deactivation toggle for the message template context.
1826
+	 *
1827
+	 * @param EE_Message_Template_Group $message_template_group
1828
+	 * @param string                    $context
1829
+	 * @param string                    $context_label
1830
+	 * @return string
1831
+	 * @throws DomainException
1832
+	 * @throws EE_Error
1833
+	 * @throws InvalidIdentifierException
1834
+	 */
1835
+	protected function add_active_context_element(
1836
+		EE_Message_Template_Group $message_template_group,
1837
+		$context,
1838
+		$context_label
1839
+	) {
1840
+		$template_args = array(
1841
+			'context'                   => $context,
1842
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1843
+			'is_active'                 => $message_template_group->is_context_active($context),
1844
+			'on_off_action'             => $message_template_group->is_context_active($context)
1845
+				? 'context-off'
1846
+				: 'context-on',
1847
+			'context_label'             => str_replace(array('(', ')'), '', $context_label),
1848
+			'message_template_group_id' => $message_template_group->ID(),
1849
+		);
1850
+		return EEH_Template::display_template(
1851
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1852
+			$template_args,
1853
+			true
1854
+		);
1855
+	}
1856
+
1857
+
1858
+	/**
1859
+	 * Ajax callback for `toggle_context_template` ajax action.
1860
+	 * Handles toggling the message context on or off.
1861
+	 *
1862
+	 * @throws EE_Error
1863
+	 * @throws InvalidArgumentException
1864
+	 * @throws InvalidDataTypeException
1865
+	 * @throws InvalidIdentifierException
1866
+	 * @throws InvalidInterfaceException
1867
+	 */
1868
+	public function toggle_context_template()
1869
+	{
1870
+		$success = true;
1871
+		// check for required data
1872
+		if (
1873
+			! isset(
1874
+				$this->_req_data['message_template_group_id'],
1875
+				$this->_req_data['context'],
1876
+				$this->_req_data['status']
1877
+			)
1878
+		) {
1879
+			EE_Error::add_error(
1880
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1881
+				__FILE__,
1882
+				__FUNCTION__,
1883
+				__LINE__
1884
+			);
1885
+			$success = false;
1886
+		}
1887
+
1888
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1889
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1890
+			: '';
1891
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1892
+		$this->_verify_nonce($nonce, $nonce_ref);
1893
+		$status = $this->_req_data['status'];
1894
+		if ($status !== 'off' && $status !== 'on') {
1895
+			EE_Error::add_error(
1896
+				sprintf(
1897
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1898
+					$this->_req_data['status']
1899
+				),
1900
+				__FILE__,
1901
+				__FUNCTION__,
1902
+				__LINE__
1903
+			);
1904
+			$success = false;
1905
+		}
1906
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1907
+			$this->_req_data['message_template_group_id']
1908
+		);
1909
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1910
+			EE_Error::add_error(
1911
+				sprintf(
1912
+					esc_html__(
1913
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1914
+						'event_espresso'
1915
+					),
1916
+					$this->_req_data['message_template_group_id'],
1917
+					'EE_Message_Template_Group'
1918
+				),
1919
+				__FILE__,
1920
+				__FUNCTION__,
1921
+				__LINE__
1922
+			);
1923
+			$success = false;
1924
+		}
1925
+		if ($success) {
1926
+			$success = $status === 'off'
1927
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1928
+				: $message_template_group->activate_context($this->_req_data['context']);
1929
+		}
1930
+		$this->_template_args['success'] = $success;
1931
+		$this->_return_json();
1932
+	}
1933
+
1934
+
1935
+	public function _add_form_element_before()
1936
+	{
1937
+		return '<form method="post" action="'
1938
+			   . $this->_template_args["edit_message_template_form_url"]
1939
+			   . '" id="ee-msg-edit-frm">';
1940
+	}
1941
+
1942
+	public function _add_form_element_after()
1943
+	{
1944
+		return '</form>';
1945
+	}
1946
+
1947
+
1948
+	/**
1949
+	 * This executes switching the template pack for a message template.
1950
+	 *
1951
+	 * @since 4.5.0
1952
+	 * @throws EE_Error
1953
+	 * @throws InvalidDataTypeException
1954
+	 * @throws InvalidInterfaceException
1955
+	 * @throws InvalidArgumentException
1956
+	 * @throws ReflectionException
1957
+	 */
1958
+	public function switch_template_pack()
1959
+	{
1960
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1961
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1962
+
1963
+		// verify we have needed values.
1964
+		if (empty($GRP_ID) || empty($template_pack)) {
1965
+			$this->_template_args['error'] = true;
1966
+			EE_Error::add_error(
1967
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1968
+				__FILE__,
1969
+				__FUNCTION__,
1970
+				__LINE__
1971
+			);
1972
+		} else {
1973
+			// get template, set the new template_pack and then reset to default
1974
+			/** @type EE_Message_Template_Group $message_template_group */
1975
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1976
+
1977
+			$message_template_group->set_template_pack_name($template_pack);
1978
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1979
+			$this->_req_data['mt'] = $message_template_group->message_type();
1980
+
1981
+			$query_args = $this->_reset_to_default_template();
1982
+
1983
+			if (empty($query_args['id'])) {
1984
+				EE_Error::add_error(
1985
+					esc_html__(
1986
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1987
+						'event_espresso'
1988
+					),
1989
+					__FILE__,
1990
+					__FUNCTION__,
1991
+					__LINE__
1992
+				);
1993
+				$this->_template_args['error'] = true;
1994
+			} else {
1995
+				$template_label = $message_template_group->get_template_pack()->label;
1996
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1997
+				EE_Error::add_success(
1998
+					sprintf(
1999
+						esc_html__(
2000
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2001
+							'event_espresso'
2002
+						),
2003
+						$template_label,
2004
+						$template_pack_labels->template_pack
2005
+					)
2006
+				);
2007
+				// generate the redirect url for js.
2008
+				$url = self::add_query_args_and_nonce(
2009
+					$query_args,
2010
+					$this->_admin_base_url
2011
+				);
2012
+				$this->_template_args['data']['redirect_url'] = $url;
2013
+				$this->_template_args['success'] = true;
2014
+			}
2015
+
2016
+			$this->_return_json();
2017
+		}
2018
+	}
2019
+
2020
+
2021
+	/**
2022
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2023
+	 * they want.
2024
+	 *
2025
+	 * @access protected
2026
+	 * @return array|null
2027
+	 * @throws EE_Error
2028
+	 * @throws InvalidArgumentException
2029
+	 * @throws InvalidDataTypeException
2030
+	 * @throws InvalidInterfaceException
2031
+	 */
2032
+	protected function _reset_to_default_template()
2033
+	{
2034
+
2035
+		$templates = array();
2036
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2037
+		// we need to make sure we've got the info we need.
2038
+		if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2039
+			EE_Error::add_error(
2040
+				esc_html__(
2041
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2042
+					'event_espresso'
2043
+				),
2044
+				__FILE__,
2045
+				__FUNCTION__,
2046
+				__LINE__
2047
+			);
2048
+		}
2049
+
2050
+		// all templates will be reset to whatever the defaults are
2051
+		// for the global template matching the messenger and message type.
2052
+		$success = ! empty($GRP_ID) ? true : false;
2053
+
2054
+		if ($success) {
2055
+			// let's first determine if the incoming template is a global template,
2056
+			// if it isn't then we need to get the global template matching messenger and message type.
2057
+			// $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2058
+
2059
+
2060
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2061
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2062
+
2063
+			if ($success) {
2064
+				// if successfully deleted, lets generate the new ones.
2065
+				// Note. We set GLOBAL to true, because resets on ANY template
2066
+				// will use the related global template defaults for regeneration.
2067
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2068
+				// HOWEVER, we DO keep the template pack and template variation set
2069
+				// for the current custom template when resetting.
2070
+				$templates = $this->_generate_new_templates(
2071
+					$this->_req_data['msgr'],
2072
+					$this->_req_data['mt'],
2073
+					$GRP_ID,
2074
+					true
2075
+				);
2076
+			}
2077
+		}
2078
+
2079
+		// any error messages?
2080
+		if (! $success) {
2081
+			EE_Error::add_error(
2082
+				esc_html__(
2083
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2084
+					'event_espresso'
2085
+				),
2086
+				__FILE__,
2087
+				__FUNCTION__,
2088
+				__LINE__
2089
+			);
2090
+		}
2091
+
2092
+		// all good, let's add a success message!
2093
+		if ($success && ! empty($templates)) {
2094
+			// the info for the template we generated is the first element in the returned array
2095
+			// $templates = $templates[0];
2096
+			EE_Error::overwrite_success();
2097
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2098
+		}
2099
+
2100
+
2101
+		$query_args = array(
2102
+			'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2103
+			'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2104
+			'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2105
+		);
2106
+
2107
+		// if called via ajax then we return query args otherwise redirect
2108
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2109
+			return $query_args;
2110
+		} else {
2111
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2112
+
2113
+			return null;
2114
+		}
2115
+	}
2116
+
2117
+
2118
+	/**
2119
+	 * Retrieve and set the message preview for display.
2120
+	 *
2121
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2122
+	 * @return string
2123
+	 * @throws ReflectionException
2124
+	 * @throws EE_Error
2125
+	 * @throws InvalidArgumentException
2126
+	 * @throws InvalidDataTypeException
2127
+	 * @throws InvalidInterfaceException
2128
+	 */
2129
+	public function _preview_message($send = false)
2130
+	{
2131
+		// first make sure we've got the necessary parameters
2132
+		if (
2133
+			! isset(
2134
+				$this->_req_data['message_type'],
2135
+				$this->_req_data['messenger'],
2136
+				$this->_req_data['messenger'],
2137
+				$this->_req_data['GRP_ID']
2138
+			)
2139
+		) {
2140
+			EE_Error::add_error(
2141
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2142
+				__FILE__,
2143
+				__FUNCTION__,
2144
+				__LINE__
2145
+			);
2146
+		}
2147
+
2148
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2149
+
2150
+		// if we have an evt_id set on the request, use it.
2151
+		$EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
2152
+		? absint($this->_req_data['evt_id'])
2153
+		: false;
2154
+
2155
+
2156
+		// get the preview!
2157
+		$preview = EED_Messages::preview_message(
2158
+			$this->_req_data['message_type'],
2159
+			$this->_req_data['context'],
2160
+			$this->_req_data['messenger'],
2161
+			$send
2162
+		);
2163
+
2164
+		if ($send) {
2165
+			return $preview;
2166
+		}
2167
+
2168
+		// let's add a button to go back to the edit view
2169
+		$query_args = array(
2170
+			'id'      => $this->_req_data['GRP_ID'],
2171
+			'evt_id'  => $EVT_ID,
2172
+			'context' => $this->_req_data['context'],
2173
+			'action'  => 'edit_message_template',
2174
+		);
2175
+		$go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2176
+		$preview_button = '<a href="'
2177
+						  . $go_back_url
2178
+						  . '" class="button-secondary messages-preview-go-back-button">'
2179
+						  . esc_html__('Go Back to Edit', 'event_espresso')
2180
+						  . '</a>';
2181
+		$message_types = $this->get_installed_message_types();
2182
+		$active_messenger = $this->_message_resource_manager->get_active_messenger(
2183
+			$this->_req_data['messenger']
2184
+		);
2185
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2186
+			? ucwords($active_messenger->label['singular'])
2187
+			: esc_html__('Unknown Messenger', 'event_espresso');
2188
+		// let's provide a helpful title for context
2189
+		$preview_title = sprintf(
2190
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2191
+			$active_messenger_label,
2192
+			ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2193
+		);
2194
+		if (empty($preview)) {
2195
+			$this->noEventsErrorMessage();
2196
+		}
2197
+		// setup display of preview.
2198
+		$this->_admin_page_title = $preview_title;
2199
+		$this->_template_args['admin_page_title'] = $preview_title;
2200
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2201
+		$this->_template_args['data']['force_json'] = true;
2202
+
2203
+		return '';
2204
+	}
2205
+
2206
+
2207
+	/**
2208
+	 * Used to set an error if there are no events available for generating a preview/test send.
2209
+	 *
2210
+	 * @param bool $test_send  Whether the error should be generated for the context of a test send.
2211
+	 */
2212
+	protected function noEventsErrorMessage($test_send = false)
2213
+	{
2214
+		$events_url = parent::add_query_args_and_nonce(
2215
+			array(
2216
+				'action' => 'default',
2217
+				'page'   => 'espresso_events',
2218
+			),
2219
+			admin_url('admin.php')
2220
+		);
2221
+		$message = $test_send
2222
+			? __(
2223
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2224
+				'event_espresso'
2225
+			)
2226
+			: __(
2227
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2228
+				'event_espresso'
2229
+			);
2230
+
2231
+		EE_Error::add_attention(
2232
+			sprintf(
2233
+				$message,
2234
+				"<a href='{$events_url}'>",
2235
+				'</a>'
2236
+			)
2237
+		);
2238
+	}
2239
+
2240
+
2241
+	/**
2242
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2243
+	 * gets called automatically.
2244
+	 *
2245
+	 * @since 4.5.0
2246
+	 *
2247
+	 * @return string
2248
+	 */
2249
+	protected function _display_preview_message()
2250
+	{
2251
+		$this->display_admin_page_with_no_sidebar();
2252
+	}
2253
+
2254
+
2255
+	/**
2256
+	 * registers metaboxes that should show up on the "edit_message_template" page
2257
+	 *
2258
+	 * @access protected
2259
+	 * @return void
2260
+	 */
2261
+	protected function _register_edit_meta_boxes()
2262
+	{
2263
+		add_meta_box(
2264
+			'mtp_valid_shortcodes',
2265
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2266
+			array($this, 'shortcode_meta_box'),
2267
+			$this->_current_screen->id,
2268
+			'side',
2269
+			'default'
2270
+		);
2271
+		add_meta_box(
2272
+			'mtp_extra_actions',
2273
+			esc_html__('Extra Actions', 'event_espresso'),
2274
+			array($this, 'extra_actions_meta_box'),
2275
+			$this->_current_screen->id,
2276
+			'side',
2277
+			'high'
2278
+		);
2279
+		add_meta_box(
2280
+			'mtp_templates',
2281
+			esc_html__('Template Styles', 'event_espresso'),
2282
+			array($this, 'template_pack_meta_box'),
2283
+			$this->_current_screen->id,
2284
+			'side',
2285
+			'high'
2286
+		);
2287
+	}
2288
+
2289
+
2290
+	/**
2291
+	 * metabox content for all template pack and variation selection.
2292
+	 *
2293
+	 * @since 4.5.0
2294
+	 * @return string
2295
+	 * @throws DomainException
2296
+	 * @throws EE_Error
2297
+	 * @throws InvalidArgumentException
2298
+	 * @throws ReflectionException
2299
+	 * @throws InvalidDataTypeException
2300
+	 * @throws InvalidInterfaceException
2301
+	 */
2302
+	public function template_pack_meta_box()
2303
+	{
2304
+		$this->_set_message_template_group();
2305
+
2306
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2307
+
2308
+		$tp_select_values = array();
2309
+
2310
+		foreach ($tp_collection as $tp) {
2311
+			// only include template packs that support this messenger and message type!
2312
+			$supports = $tp->get_supports();
2313
+			if (
2314
+				! isset($supports[ $this->_message_template_group->messenger() ])
2315
+				|| ! in_array(
2316
+					$this->_message_template_group->message_type(),
2317
+					$supports[ $this->_message_template_group->messenger() ],
2318
+					true
2319
+				)
2320
+			) {
2321
+				// not supported
2322
+				continue;
2323
+			}
2324
+
2325
+			$tp_select_values[] = array(
2326
+				'text' => $tp->label,
2327
+				'id'   => $tp->dbref,
2328
+			);
2329
+		}
2330
+
2331
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2332
+		// the default template pack.  This still allows for the odd template pack to override.
2333
+		if (empty($tp_select_values)) {
2334
+			$tp_select_values[] = array(
2335
+				'text' => esc_html__('Default', 'event_espresso'),
2336
+				'id'   => 'default',
2337
+			);
2338
+		}
2339
+
2340
+		// setup variation select values for the currently selected template.
2341
+		$variations = $this->_message_template_group->get_template_pack()->get_variations(
2342
+			$this->_message_template_group->messenger(),
2343
+			$this->_message_template_group->message_type()
2344
+		);
2345
+		$variations_select_values = array();
2346
+		foreach ($variations as $variation => $label) {
2347
+			$variations_select_values[] = array(
2348
+				'text' => $label,
2349
+				'id'   => $variation,
2350
+			);
2351
+		}
2352
+
2353
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2354
+
2355
+		$template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2356
+			'MTP_template_pack',
2357
+			$tp_select_values,
2358
+			$this->_message_template_group->get_template_pack_name()
2359
+		);
2360
+		$template_args['variations_selector'] = EEH_Form_Fields::select_input(
2361
+			'MTP_template_variation',
2362
+			$variations_select_values,
2363
+			$this->_message_template_group->get_template_pack_variation()
2364
+		);
2365
+		$template_args['template_pack_label'] = $template_pack_labels->template_pack;
2366
+		$template_args['template_variation_label'] = $template_pack_labels->template_variation;
2367
+		$template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2368
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2369
+
2370
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2371
+
2372
+		EEH_Template::display_template($template, $template_args);
2373
+	}
2374
+
2375
+
2376
+	/**
2377
+	 * This meta box holds any extra actions related to Message Templates
2378
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2379
+	 *
2380
+	 * @access  public
2381
+	 * @return void
2382
+	 * @throws EE_Error
2383
+	 */
2384
+	public function extra_actions_meta_box()
2385
+	{
2386
+		$template_form_fields = array();
2387
+
2388
+		$extra_args = array(
2389
+			'msgr'   => $this->_message_template_group->messenger(),
2390
+			'mt'     => $this->_message_template_group->message_type(),
2391
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2392
+		);
2393
+		// first we need to see if there are any fields
2394
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2395
+
2396
+		if (! empty($fields)) {
2397
+			// yup there be fields
2398
+			foreach ($fields as $field => $config) {
2399
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2400
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2401
+				$default = isset($config['default']) ? $config['default'] : '';
2402
+				$default = isset($config['value']) ? $config['value'] : $default;
2403
+
2404
+				// if type is hidden and the value is empty
2405
+				// something may have gone wrong so let's correct with the defaults
2406
+				$fix = $config['input'] === 'hidden'
2407
+					   && isset($existing[ $field ])
2408
+					   && empty($existing[ $field ])
2409
+					? $default
2410
+					: '';
2411
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2412
+					? $existing[ $field ]
2413
+					: $fix;
2414
+
2415
+				$template_form_fields[ $field_id ] = array(
2416
+					'name'       => 'test_settings_fld[' . $field . ']',
2417
+					'label'      => $config['label'],
2418
+					'input'      => $config['input'],
2419
+					'type'       => $config['type'],
2420
+					'required'   => $config['required'],
2421
+					'validation' => $config['validation'],
2422
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2423
+					'css_class'  => $config['css_class'],
2424
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2425
+					'default'    => $default,
2426
+					'format'     => $config['format'],
2427
+				);
2428
+			}
2429
+		}
2430
+
2431
+		$test_settings_fields = ! empty($template_form_fields)
2432
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2433
+			: '';
2434
+
2435
+		$test_settings_html = '';
2436
+		// print out $test_settings_fields
2437
+		if (! empty($test_settings_fields)) {
2438
+			echo $test_settings_fields;
2439
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2440
+			$test_settings_html .= 'name="test_button" value="';
2441
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2442
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2443
+		}
2444
+
2445
+		// and button
2446
+		$test_settings_html .= '<p>'
2447
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2448
+							   . '</p>';
2449
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2450
+		$test_settings_html .= $this->get_action_link_or_button(
2451
+			'reset_to_default',
2452
+			'reset',
2453
+			$extra_args,
2454
+			'button-primary reset-default-button'
2455
+		);
2456
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2457
+		echo $test_settings_html;
2458
+	}
2459
+
2460
+
2461
+	/**
2462
+	 * This returns the shortcode selector skeleton for a given context and field.
2463
+	 *
2464
+	 * @since 4.9.rc.000
2465
+	 * @param string $field           The name of the field retrieving shortcodes for.
2466
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2467
+	 * @return string
2468
+	 * @throws DomainException
2469
+	 * @throws EE_Error
2470
+	 * @throws InvalidArgumentException
2471
+	 * @throws ReflectionException
2472
+	 * @throws InvalidDataTypeException
2473
+	 * @throws InvalidInterfaceException
2474
+	 */
2475
+	protected function _get_shortcode_selector($field, $linked_input_id)
2476
+	{
2477
+		$template_args = array(
2478
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2479
+			'fieldname'       => $field,
2480
+			'linked_input_id' => $linked_input_id,
2481
+		);
2482
+
2483
+		return EEH_Template::display_template(
2484
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2485
+			$template_args,
2486
+			true
2487
+		);
2488
+	}
2489
+
2490
+
2491
+	/**
2492
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2493
+	 * page)
2494
+	 *
2495
+	 * @access public
2496
+	 * @return void
2497
+	 * @throws EE_Error
2498
+	 * @throws InvalidArgumentException
2499
+	 * @throws ReflectionException
2500
+	 * @throws InvalidDataTypeException
2501
+	 * @throws InvalidInterfaceException
2502
+	 */
2503
+	public function shortcode_meta_box()
2504
+	{
2505
+		$shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set
2506
+		// $messenger = $this->_message_template_group->messenger_obj();
2507
+		// now let's set the content depending on the status of the shortcodes array
2508
+		if (empty($shortcodes)) {
2509
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2510
+			echo $content;
2511
+		} else {
2512
+			// $alt = 0;
2513
+			?>
2514 2514
             <div style="float:right; margin-top:10px"><?php
2515
-                            echo $this->_get_help_tab_link('message_template_shortcodes');
2516
-            ?></div>
2515
+							echo $this->_get_help_tab_link('message_template_shortcodes');
2516
+			?></div>
2517 2517
             <p class="small-text"><?php
2518
-                                  printf(
2519
-                                      esc_html__(
2520
-                                          'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2521
-                                          'event_espresso'
2522
-                                      ),
2523
-                                      '<span class="dashicons dashicons-menu"></span>'
2524
-                                  );
2525
-                                    ?>
2518
+								  printf(
2519
+									  esc_html__(
2520
+										  'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2521
+										  'event_espresso'
2522
+									  ),
2523
+									  '<span class="dashicons dashicons-menu"></span>'
2524
+								  );
2525
+									?>
2526 2526
             </p>
2527 2527
             <?php
2528
-        }
2529
-    }
2530
-
2531
-
2532
-    /**
2533
-     * used to set the $_shortcodes property for when its needed elsewhere.
2534
-     *
2535
-     * @access protected
2536
-     * @return void
2537
-     * @throws EE_Error
2538
-     * @throws InvalidArgumentException
2539
-     * @throws ReflectionException
2540
-     * @throws InvalidDataTypeException
2541
-     * @throws InvalidInterfaceException
2542
-     */
2543
-    protected function _set_shortcodes()
2544
-    {
2545
-
2546
-        // no need to run this if the property is already set
2547
-        if (! empty($this->_shortcodes)) {
2548
-            return;
2549
-        }
2550
-
2551
-        $this->_shortcodes = $this->_get_shortcodes();
2552
-    }
2553
-
2554
-
2555
-    /**
2556
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2557
-     * property)
2558
-     *
2559
-     * @access  protected
2560
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2561
-     *                         for. Defaults to all (for the given context)
2562
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2563
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2564
-     *                         true just an array of shortcode/label pairs.
2565
-     * @throws EE_Error
2566
-     * @throws InvalidArgumentException
2567
-     * @throws ReflectionException
2568
-     * @throws InvalidDataTypeException
2569
-     * @throws InvalidInterfaceException
2570
-     */
2571
-    protected function _get_shortcodes($fields = array(), $merged = true)
2572
-    {
2573
-        $this->_set_message_template_group();
2574
-
2575
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2576
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2577
-            ? absint($this->_req_data['id'])
2578
-            : false;
2579
-        $context = isset($this->_req_data['context'])
2580
-            ? $this->_req_data['context']
2581
-            : key($this->_message_template_group->contexts_config());
2582
-
2583
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2584
-    }
2585
-
2586
-
2587
-    /**
2588
-     * This sets the _message_template property (containing the called message_template object)
2589
-     *
2590
-     * @access protected
2591
-     * @return void
2592
-     * @throws EE_Error
2593
-     * @throws InvalidArgumentException
2594
-     * @throws ReflectionException
2595
-     * @throws InvalidDataTypeException
2596
-     * @throws InvalidInterfaceException
2597
-     */
2598
-    protected function _set_message_template_group()
2599
-    {
2600
-
2601
-        if (! empty($this->_message_template_group)) {
2602
-            return;
2603
-        } //get out if this is already set.
2604
-
2605
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2606
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2607
-
2608
-        // let's get the message templates
2609
-        $MTP = EEM_Message_Template_Group::instance();
2610
-
2611
-        if (empty($GRP_ID)) {
2612
-            $this->_message_template_group = $MTP->create_default_object();
2613
-        } else {
2614
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2615
-        }
2616
-
2617
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2618
-        $this->_variation = $this->_message_template_group->get_template_pack_variation();
2619
-    }
2620
-
2621
-
2622
-    /**
2623
-     * sets up a context switcher for edit forms
2624
-     *
2625
-     * @access  protected
2626
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2627
-     * @param array                      $args                  various things the context switcher needs.
2628
-     * @throws EE_Error
2629
-     */
2630
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2631
-    {
2632
-        $context_details = $template_group_object->contexts_config();
2633
-        $context_label = $template_group_object->context_label();
2634
-        ob_start();
2635
-        ?>
2528
+		}
2529
+	}
2530
+
2531
+
2532
+	/**
2533
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2534
+	 *
2535
+	 * @access protected
2536
+	 * @return void
2537
+	 * @throws EE_Error
2538
+	 * @throws InvalidArgumentException
2539
+	 * @throws ReflectionException
2540
+	 * @throws InvalidDataTypeException
2541
+	 * @throws InvalidInterfaceException
2542
+	 */
2543
+	protected function _set_shortcodes()
2544
+	{
2545
+
2546
+		// no need to run this if the property is already set
2547
+		if (! empty($this->_shortcodes)) {
2548
+			return;
2549
+		}
2550
+
2551
+		$this->_shortcodes = $this->_get_shortcodes();
2552
+	}
2553
+
2554
+
2555
+	/**
2556
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2557
+	 * property)
2558
+	 *
2559
+	 * @access  protected
2560
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2561
+	 *                         for. Defaults to all (for the given context)
2562
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2563
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2564
+	 *                         true just an array of shortcode/label pairs.
2565
+	 * @throws EE_Error
2566
+	 * @throws InvalidArgumentException
2567
+	 * @throws ReflectionException
2568
+	 * @throws InvalidDataTypeException
2569
+	 * @throws InvalidInterfaceException
2570
+	 */
2571
+	protected function _get_shortcodes($fields = array(), $merged = true)
2572
+	{
2573
+		$this->_set_message_template_group();
2574
+
2575
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2576
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2577
+			? absint($this->_req_data['id'])
2578
+			: false;
2579
+		$context = isset($this->_req_data['context'])
2580
+			? $this->_req_data['context']
2581
+			: key($this->_message_template_group->contexts_config());
2582
+
2583
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2584
+	}
2585
+
2586
+
2587
+	/**
2588
+	 * This sets the _message_template property (containing the called message_template object)
2589
+	 *
2590
+	 * @access protected
2591
+	 * @return void
2592
+	 * @throws EE_Error
2593
+	 * @throws InvalidArgumentException
2594
+	 * @throws ReflectionException
2595
+	 * @throws InvalidDataTypeException
2596
+	 * @throws InvalidInterfaceException
2597
+	 */
2598
+	protected function _set_message_template_group()
2599
+	{
2600
+
2601
+		if (! empty($this->_message_template_group)) {
2602
+			return;
2603
+		} //get out if this is already set.
2604
+
2605
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2606
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2607
+
2608
+		// let's get the message templates
2609
+		$MTP = EEM_Message_Template_Group::instance();
2610
+
2611
+		if (empty($GRP_ID)) {
2612
+			$this->_message_template_group = $MTP->create_default_object();
2613
+		} else {
2614
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2615
+		}
2616
+
2617
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2618
+		$this->_variation = $this->_message_template_group->get_template_pack_variation();
2619
+	}
2620
+
2621
+
2622
+	/**
2623
+	 * sets up a context switcher for edit forms
2624
+	 *
2625
+	 * @access  protected
2626
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2627
+	 * @param array                      $args                  various things the context switcher needs.
2628
+	 * @throws EE_Error
2629
+	 */
2630
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2631
+	{
2632
+		$context_details = $template_group_object->contexts_config();
2633
+		$context_label = $template_group_object->context_label();
2634
+		ob_start();
2635
+		?>
2636 2636
         <div class="ee-msg-switcher-container">
2637 2637
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2638 2638
                 <?php
2639
-                foreach ($args as $name => $value) {
2640
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2641
-                        continue;
2642
-                    }
2643
-                    ?>
2639
+				foreach ($args as $name => $value) {
2640
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2641
+						continue;
2642
+					}
2643
+					?>
2644 2644
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2645 2645
                     <?php
2646
-                }
2647
-                // setup nonce_url
2648
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2649
-                ?>
2646
+				}
2647
+				// setup nonce_url
2648
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2649
+				?>
2650 2650
                 <select name="context">
2651 2651
                     <?php
2652
-                    $context_templates = $template_group_object->context_templates();
2653
-                    if (is_array($context_templates)) :
2654
-                        foreach ($context_templates as $context => $template_fields) :
2655
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2656
-                            ?>
2652
+					$context_templates = $template_group_object->context_templates();
2653
+					if (is_array($context_templates)) :
2654
+						foreach ($context_templates as $context => $template_fields) :
2655
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2656
+							?>
2657 2657
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2658 2658
                                 <?php echo $context_details[ $context ]['label']; ?>
2659 2659
                             </option>
2660 2660
                         <?php endforeach;
2661
-                    endif; ?>
2661
+					endif; ?>
2662 2662
                 </select>
2663 2663
                 <?php $button_text = sprintf(__('Switch %s', 'event_espresso'), ucwords($context_label['label'])); ?>
2664 2664
                 <input id="submit-msg-context-switcher-sbmt" class="button-secondary" type="submit"
@@ -2667,1932 +2667,1932 @@  discard block
 block discarded – undo
2667 2667
             <?php echo $args['extra']; ?>
2668 2668
         </div> <!-- end .ee-msg-switcher-container -->
2669 2669
         <?php
2670
-        $output = ob_get_contents();
2671
-        ob_clean();
2672
-        $this->_context_switcher = $output;
2673
-    }
2674
-
2675
-
2676
-    /**
2677
-     * utility for sanitizing new values coming in.
2678
-     * Note: this is only used when updating a context.
2679
-     *
2680
-     * @access protected
2681
-     *
2682
-     * @param int $index This helps us know which template field to select from the request array.
2683
-     *
2684
-     * @return array
2685
-     */
2686
-    protected function _set_message_template_column_values($index)
2687
-    {
2688
-        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2689
-            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2690
-                $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2691
-            }
2692
-        }
2693
-
2694
-
2695
-        $set_column_values = array(
2696
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2697
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2698
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2699
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2700
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2701
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2702
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2703
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2704
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2705
-                ? absint($this->_req_data['MTP_is_global'])
2706
-                : 0,
2707
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2708
-                ? absint($this->_req_data['MTP_is_override'])
2709
-                : 0,
2710
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2711
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2712
-        );
2713
-
2714
-
2715
-        return $set_column_values;
2716
-    }
2717
-
2718
-
2719
-    protected function _insert_or_update_message_template($new = false)
2720
-    {
2721
-
2722
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2723
-        $success = 0;
2724
-        $override = false;
2725
-
2726
-        // setup notices description
2727
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2728
-
2729
-        // need the message type and messenger objects to be able to use the labels for the notices
2730
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2731
-        $messenger_label = $messenger_object instanceof EE_messenger
2732
-            ? ucwords($messenger_object->label['singular'])
2733
-            : '';
2734
-
2735
-        $message_type_slug = ! empty($this->_req_data['MTP_message_type'])
2736
-            ? $this->_req_data['MTP_message_type']
2737
-            : '';
2738
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2739
-
2740
-        $message_type_label = $message_type_object instanceof EE_message_type
2741
-            ? ucwords($message_type_object->label['singular'])
2742
-            : '';
2743
-
2744
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2745
-            ? $this->_req_data['MTP_context']
2746
-            : '';
2747
-        $context = ucwords(str_replace('_', ' ', $context_slug));
2748
-
2749
-        $item_desc = $messenger_label && $message_type_label
2750
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2751
-            : '';
2752
-        $item_desc .= 'Message Template';
2753
-        $query_args = array();
2754
-        $edit_array = array();
2755
-        $action_desc = '';
2756
-
2757
-        // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2758
-        // user to edit.
2759
-        if ($new) {
2760
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2761
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2762
-                if (empty($edit_array)) {
2763
-                    $success = 0;
2764
-                } else {
2765
-                    $success = 1;
2766
-                    $edit_array = $edit_array[0];
2767
-                    $query_args = array(
2768
-                        'id'      => $edit_array['GRP_ID'],
2769
-                        'context' => $edit_array['MTP_context'],
2770
-                        'action'  => 'edit_message_template',
2771
-                    );
2772
-                }
2773
-            }
2774
-            $action_desc = 'created';
2775
-        } else {
2776
-            $MTPG = EEM_Message_Template_Group::instance();
2777
-            $MTP = EEM_Message_Template::instance();
2778
-
2779
-
2780
-            // run update for each template field in displayed context
2781
-            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2782
-                EE_Error::add_error(
2783
-                    esc_html__(
2784
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2785
-                        'event_espresso'
2786
-                    ),
2787
-                    __FILE__,
2788
-                    __FUNCTION__,
2789
-                    __LINE__
2790
-                );
2791
-                $success = 0;
2792
-            } else {
2793
-                // first validate all fields!
2794
-                // this filter allows client code to add its own validation to the template fields as well.
2795
-                // returning an empty array means everything passed validation.
2796
-                // errors in validation should be represented in an array with the following shape:
2797
-                // array(
2798
-                //   'fieldname' => array(
2799
-                //          'msg' => 'error message'
2800
-                //          'value' => 'value for field producing error'
2801
-                // )
2802
-                $custom_validation = (array) apply_filters(
2803
-                    'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2804
-                    array(),
2805
-                    $this->_req_data['MTP_template_fields'],
2806
-                    $context_slug,
2807
-                    $messenger_slug,
2808
-                    $message_type_slug
2809
-                );
2810
-
2811
-                $system_validation = $MTPG->validate(
2812
-                    $this->_req_data['MTP_template_fields'],
2813
-                    $context_slug,
2814
-                    $messenger_slug,
2815
-                    $message_type_slug
2816
-                );
2817
-
2818
-                $system_validation = ! is_array($system_validation) && $system_validation ? array()
2819
-                    : $system_validation;
2820
-                $validates = array_merge($custom_validation, $system_validation);
2821
-
2822
-                // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2823
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2824
-                //  WE need to make sure there is no actual error messages in validates.
2825
-                if (is_array($validates) && ! empty($validates)) {
2826
-                    // add the transient so when the form loads we know which fields to highlight
2827
-                    $this->_add_transient('edit_message_template', $validates);
2828
-
2829
-                    $success = 0;
2830
-
2831
-                    // setup notices
2832
-                    foreach ($validates as $field => $error) {
2833
-                        if (isset($error['msg'])) {
2834
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2835
-                        }
2836
-                    }
2837
-                } else {
2838
-                    $set_column_values = array();
2839
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2840
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2841
-
2842
-                        $where_cols_n_values = array(
2843
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2844
-                        );
2845
-                        // if they aren't allowed to use all JS, restrict them to just posty-y tags
2846
-                        if (! current_user_can('unfiltered_html')) {
2847
-                            if (is_array($set_column_values['MTP_content'])) {
2848
-                                foreach ($set_column_values['MTP_content'] as $key => $value) {
2849
-                                    // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2850
-                                    // only removes slashes from double-quotes, so attributes using single quotes always
2851
-                                    // appear invalid.) But currently the models expect slashed data, so after wp_kses
2852
-                                    // runs we need to re-slash the data. Sheesh. See
2853
-                                    // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2854
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2855
-                                        wp_kses(
2856
-                                            stripslashes($value),
2857
-                                            wp_kses_allowed_html('post')
2858
-                                        )
2859
-                                    );
2860
-                                }
2861
-                            } else {
2862
-                                $set_column_values['MTP_content'] = wp_kses(
2863
-                                    $set_column_values['MTP_content'],
2864
-                                    wp_kses_allowed_html('post')
2865
-                                );
2866
-                            }
2867
-                        }
2868
-                        $message_template_fields = array(
2869
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2870
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2871
-                            'MTP_context'        => $set_column_values['MTP_context'],
2872
-                            'MTP_content'        => $set_column_values['MTP_content'],
2873
-                        );
2874
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2875
-                            if ($updated === false) {
2876
-                                EE_Error::add_error(
2877
-                                    sprintf(
2878
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2879
-                                        $template_field
2880
-                                    ),
2881
-                                    __FILE__,
2882
-                                    __FUNCTION__,
2883
-                                    __LINE__
2884
-                                );
2885
-                            } else {
2886
-                                $success = 1;
2887
-                            }
2888
-                        } else {
2889
-                            // only do this logic if we don't have a MTP_ID for this field
2890
-                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2891
-                                // this has already been through the template field validator and sanitized, so it will be
2892
-                                // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2893
-                                // message template field in a messenger/message type and existing users don't have the
2894
-                                // default setup for it.
2895
-                                // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2896
-                                $updated = $MTP->insert($message_template_fields);
2897
-                                if (! $updated || is_wp_error($updated)) {
2898
-                                    EE_Error::add_error(
2899
-                                        sprintf(
2900
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2901
-                                            $template_field
2902
-                                        ),
2903
-                                        __FILE__,
2904
-                                        __FUNCTION__,
2905
-                                        __LINE__
2906
-                                    );
2907
-                                    $success = 0;
2908
-                                } else {
2909
-                                    $success = 1;
2910
-                                }
2911
-                            }
2912
-                        }
2913
-                        $action_desc = 'updated';
2914
-                    }
2915
-
2916
-                    // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2917
-                    $mtpg_fields = array(
2918
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2919
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2920
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2921
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2922
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2923
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2924
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2925
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2926
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2927
-                            : '',
2928
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2929
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2930
-                            : '',
2931
-                    );
2932
-
2933
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2934
-                    $updated = $MTPG->update($mtpg_fields, array($mtpg_where));
2935
-
2936
-                    if ($updated === false) {
2937
-                        EE_Error::add_error(
2938
-                            sprintf(
2939
-                                esc_html__(
2940
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2941
-                                    'event_espresso'
2942
-                                ),
2943
-                                $set_column_values['GRP_ID']
2944
-                            ),
2945
-                            __FILE__,
2946
-                            __FUNCTION__,
2947
-                            __LINE__
2948
-                        );
2949
-                    } else {
2950
-                        // k now we need to ensure the template_pack and template_variation fields are set.
2951
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2952
-                            ? $this->_req_data['MTP_template_pack']
2953
-                            : 'default';
2954
-
2955
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2956
-                            ? $this->_req_data['MTP_template_variation']
2957
-                            : 'default';
2958
-
2959
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2960
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2961
-                            $mtpg_obj->set_template_pack_name($template_pack);
2962
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2963
-                        }
2964
-                        $success = 1;
2965
-                    }
2966
-                }
2967
-            }
2968
-        }
2969
-
2970
-        // we return things differently if doing ajax
2971
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2972
-            $this->_template_args['success'] = $success;
2973
-            $this->_template_args['error'] = ! $success ? true : false;
2974
-            $this->_template_args['content'] = '';
2975
-            $this->_template_args['data'] = array(
2976
-                'grpID'        => $edit_array['GRP_ID'],
2977
-                'templateName' => $edit_array['template_name'],
2978
-            );
2979
-            if ($success) {
2980
-                EE_Error::overwrite_success();
2981
-                EE_Error::add_success(
2982
-                    esc_html__(
2983
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2984
-                        'event_espresso'
2985
-                    )
2986
-                );
2987
-            }
2988
-
2989
-            $this->_return_json();
2990
-        }
2991
-
2992
-
2993
-        // was a test send triggered?
2994
-        if (isset($this->_req_data['test_button'])) {
2995
-            EE_Error::overwrite_success();
2996
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2997
-            $override = true;
2998
-        }
2999
-
3000
-        if (empty($query_args)) {
3001
-            $query_args = array(
3002
-                'id'      => $this->_req_data['GRP_ID'],
3003
-                'context' => $context_slug,
3004
-                'action'  => 'edit_message_template',
3005
-            );
3006
-        }
3007
-
3008
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
3009
-    }
3010
-
3011
-
3012
-    /**
3013
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3014
-     *
3015
-     * @param  string $context      what context being tested
3016
-     * @param  string $messenger    messenger being tested
3017
-     * @param  string $message_type message type being tested
3018
-     * @throws EE_Error
3019
-     * @throws InvalidArgumentException
3020
-     * @throws InvalidDataTypeException
3021
-     * @throws InvalidInterfaceException
3022
-     */
3023
-    protected function _do_test_send($context, $messenger, $message_type)
3024
-    {
3025
-        // set things up for preview
3026
-        $this->_req_data['messenger'] = $messenger;
3027
-        $this->_req_data['message_type'] = $message_type;
3028
-        $this->_req_data['context'] = $context;
3029
-        $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3030
-        $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
3031
-
3032
-        // let's save any existing fields that might be required by the messenger
3033
-        if (
3034
-            isset($this->_req_data['test_settings_fld'])
3035
-            && $active_messenger instanceof EE_messenger
3036
-            && apply_filters(
3037
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3038
-                true,
3039
-                $this->_req_data['test_settings_fld'],
3040
-                $active_messenger
3041
-            )
3042
-        ) {
3043
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3044
-        }
3045
-
3046
-        /**
3047
-         * Use filter to add additional controls on whether message can send or not
3048
-         */
3049
-        if (
3050
-            apply_filters(
3051
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3052
-                true,
3053
-                $context,
3054
-                $this->_req_data,
3055
-                $messenger,
3056
-                $message_type
3057
-            )
3058
-        ) {
3059
-            if (EEM_Event::instance()->count() > 0) {
3060
-                $success = $this->_preview_message(true);
3061
-                if ($success) {
3062
-                    EE_Error::add_success(__('Test message sent', 'event_espresso'));
3063
-                } else {
3064
-                    EE_Error::add_error(
3065
-                        esc_html__('The test message was not sent', 'event_espresso'),
3066
-                        __FILE__,
3067
-                        __FUNCTION__,
3068
-                        __LINE__
3069
-                    );
3070
-                }
3071
-            } else {
3072
-                $this->noEventsErrorMessage(true);
3073
-            }
3074
-        }
3075
-    }
3076
-
3077
-
3078
-    /**
3079
-     * _generate_new_templates
3080
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3081
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3082
-     * for the event.
3083
-     *
3084
-     *
3085
-     * @param  string $messenger     the messenger we are generating templates for
3086
-     * @param array   $message_types array of message types that the templates are generated for.
3087
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3088
-     *                               indicate the message_template_group being used as the base.
3089
-     *
3090
-     * @param bool    $global
3091
-     *
3092
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3093
-     *                               encountering problems.
3094
-     * @throws EE_Error
3095
-     */
3096
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3097
-    {
3098
-
3099
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3100
-        // just don't generate any templates.
3101
-        if (empty($message_types)) {
3102
-            return true;
3103
-        }
3104
-
3105
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3106
-    }
3107
-
3108
-
3109
-    /**
3110
-     * [_trash_or_restore_message_template]
3111
-     *
3112
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3113
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3114
-     *                        an individual context (FALSE).
3115
-     * @return void
3116
-     * @throws EE_Error
3117
-     * @throws InvalidArgumentException
3118
-     * @throws InvalidDataTypeException
3119
-     * @throws InvalidInterfaceException
3120
-     */
3121
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3122
-    {
3123
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3124
-        $MTP = EEM_Message_Template_Group::instance();
3125
-
3126
-        $success = 1;
3127
-
3128
-        // incoming GRP_IDs
3129
-        if ($all) {
3130
-            // Checkboxes
3131
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3132
-                // if array has more than one element then success message should be plural.
3133
-                // todo: what about nonce?
3134
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3135
-
3136
-                // cycle through checkboxes
3137
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3138
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3139
-                    if (! $trashed_or_restored) {
3140
-                        $success = 0;
3141
-                    }
3142
-                }
3143
-            } else {
3144
-                // grab single GRP_ID and handle
3145
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3146
-                if (! empty($GRP_ID)) {
3147
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3148
-                    if (! $trashed_or_restored) {
3149
-                        $success = 0;
3150
-                    }
3151
-                } else {
3152
-                    $success = 0;
3153
-                }
3154
-            }
3155
-        }
3156
-
3157
-        $action_desc = $trash
3158
-            ? esc_html__('moved to the trash', 'event_espresso')
3159
-            : esc_html__('restored', 'event_espresso');
3160
-
3161
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3162
-
3163
-        $item_desc = $all ? _n(
3164
-            'Message Template Group',
3165
-            'Message Template Groups',
3166
-            $success,
3167
-            'event_espresso'
3168
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3169
-
3170
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3171
-            'template',
3172
-            'templates',
3173
-            $success,
3174
-            'event_espresso'
3175
-        ) : $item_desc;
3176
-
3177
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3178
-    }
3179
-
3180
-
3181
-    /**
3182
-     * [_delete_message_template]
3183
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3184
-     *
3185
-     * @return void
3186
-     * @throws EE_Error
3187
-     * @throws InvalidArgumentException
3188
-     * @throws InvalidDataTypeException
3189
-     * @throws InvalidInterfaceException
3190
-     */
3191
-    protected function _delete_message_template()
3192
-    {
3193
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3194
-
3195
-        // checkboxes
3196
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3197
-            // if array has more than one element then success message should be plural
3198
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3199
-
3200
-            // cycle through bulk action checkboxes
3201
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3202
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3203
-            }
3204
-        } else {
3205
-            // grab single grp_id and delete
3206
-            $GRP_ID = absint($this->_req_data['id']);
3207
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3208
-        }
3209
-
3210
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3211
-    }
3212
-
3213
-
3214
-    /**
3215
-     * helper for permanently deleting a mtP group and all related message_templates
3216
-     *
3217
-     * @param  int  $GRP_ID        The group being deleted
3218
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3219
-     * @return bool boolean to indicate the success of the deletes or not.
3220
-     * @throws EE_Error
3221
-     * @throws InvalidArgumentException
3222
-     * @throws InvalidDataTypeException
3223
-     * @throws InvalidInterfaceException
3224
-     */
3225
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3226
-    {
3227
-        $success = 1;
3228
-        $MTPG = EEM_Message_Template_Group::instance();
3229
-        // first let's GET this group
3230
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3231
-        // then delete permanently all the related Message Templates
3232
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3233
-
3234
-        if ($deleted === 0) {
3235
-            $success = 0;
3236
-        }
3237
-
3238
-        // now delete permanently this particular group
3239
-
3240
-        if ($include_group && ! $MTG->delete_permanently()) {
3241
-            $success = 0;
3242
-        }
3243
-
3244
-        return $success;
3245
-    }
3246
-
3247
-
3248
-    /**
3249
-     *    _learn_more_about_message_templates_link
3250
-     *
3251
-     * @access protected
3252
-     * @return string
3253
-     */
3254
-    protected function _learn_more_about_message_templates_link()
3255
-    {
3256
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3257
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3258
-               . '</a>';
3259
-    }
3260
-
3261
-
3262
-    /**
3263
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3264
-     * ajax and other routes.
3265
-     *
3266
-     * @return void
3267
-     * @throws DomainException
3268
-     */
3269
-    protected function _settings()
3270
-    {
3271
-
3272
-
3273
-        $this->_set_m_mt_settings();
3274
-
3275
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3276
-            ? $this->_req_data['selected_messenger']
3277
-            : 'email';
3278
-
3279
-        // let's setup the messenger tabs
3280
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3281
-            $this->_m_mt_settings['messenger_tabs'],
3282
-            'messenger_links',
3283
-            '|',
3284
-            $selected_messenger
3285
-        );
3286
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3287
-        $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';
3288
-
3289
-        $this->display_admin_page_with_sidebar();
3290
-    }
3291
-
3292
-
3293
-    /**
3294
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3295
-     *
3296
-     * @access protected
3297
-     * @return void
3298
-     * @throws DomainException
3299
-     */
3300
-    protected function _set_m_mt_settings()
3301
-    {
3302
-        // first if this is already set then lets get out no need to regenerate data.
3303
-        if (! empty($this->_m_mt_settings)) {
3304
-            return;
3305
-        }
3306
-
3307
-        // get all installed messengers and message_types
3308
-        /** @type EE_messenger[] $messengers */
3309
-        $messengers = $this->_message_resource_manager->installed_messengers();
3310
-        /** @type EE_message_type[] $message_types */
3311
-        $message_types = $this->_message_resource_manager->installed_message_types();
3312
-
3313
-
3314
-        // assemble the array for the _tab_text_links helper
3315
-
3316
-        foreach ($messengers as $messenger) {
3317
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3318
-                'label' => ucwords($messenger->label['singular']),
3319
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3320
-                    ? 'messenger-active'
3321
-                    : '',
3322
-                'href'  => $messenger->name,
3323
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3324
-                'slug'  => $messenger->name,
3325
-                'obj'   => $messenger,
3326
-            );
3327
-
3328
-
3329
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3330
-
3331
-            foreach ($message_types as $message_type) {
3332
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3333
-                // it shouldn't show in either the inactive OR active metabox.
3334
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3335
-                    continue;
3336
-                }
3337
-
3338
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3339
-                    $messenger->name,
3340
-                    $message_type->name
3341
-                )
3342
-                    ? 'active'
3343
-                    : 'inactive';
3344
-
3345
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3346
-                    'label'    => ucwords($message_type->label['singular']),
3347
-                    'class'    => 'message-type-' . $a_or_i,
3348
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3349
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3350
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3351
-                    'title'    => $a_or_i === 'active'
3352
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3353
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3354
-                    'content'  => $a_or_i === 'active'
3355
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3356
-                        : $this->_message_type_settings_content($message_type, $messenger),
3357
-                    'slug'     => $message_type->name,
3358
-                    'active'   => $a_or_i === 'active',
3359
-                    'obj'      => $message_type,
3360
-                );
3361
-            }
3362
-        }
3363
-    }
3364
-
3365
-
3366
-    /**
3367
-     * This just prepares the content for the message type settings
3368
-     *
3369
-     * @param  EE_message_type $message_type The message type object
3370
-     * @param  EE_messenger    $messenger    The messenger object
3371
-     * @param  boolean         $active       Whether the message type is active or not
3372
-     * @return string html output for the content
3373
-     * @throws DomainException
3374
-     */
3375
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3376
-    {
3377
-        // get message type fields
3378
-        $fields = $message_type->get_admin_settings_fields();
3379
-        $settings_template_args['template_form_fields'] = '';
3380
-
3381
-        if (! empty($fields) && $active) {
3382
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3383
-            foreach ($fields as $fldname => $fldprops) {
3384
-                $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3385
-                $template_form_field[ $field_id ] = array(
3386
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3387
-                    'label'      => $fldprops['label'],
3388
-                    'input'      => $fldprops['field_type'],
3389
-                    'type'       => $fldprops['value_type'],
3390
-                    'required'   => $fldprops['required'],
3391
-                    'validation' => $fldprops['validation'],
3392
-                    'value'      => isset($existing_settings[ $fldname ])
3393
-                        ? $existing_settings[ $fldname ]
3394
-                        : $fldprops['default'],
3395
-                    'options'    => isset($fldprops['options'])
3396
-                        ? $fldprops['options']
3397
-                        : array(),
3398
-                    'default'    => isset($existing_settings[ $fldname ])
3399
-                        ? $existing_settings[ $fldname ]
3400
-                        : $fldprops['default'],
3401
-                    'css_class'  => 'no-drag',
3402
-                    'format'     => $fldprops['format'],
3403
-                );
3404
-            }
3405
-
3406
-
3407
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3408
-                ? $this->_generate_admin_form_fields(
3409
-                    $template_form_field,
3410
-                    'string',
3411
-                    'ee_mt_activate_form'
3412
-                )
3413
-                : '';
3414
-        }
3415
-
3416
-        $settings_template_args['description'] = $message_type->description;
3417
-        // we also need some hidden fields
3418
-        $settings_template_args['hidden_fields'] = array(
3419
-            'message_type_settings[messenger]'    => array(
3420
-                'type'  => 'hidden',
3421
-                'value' => $messenger->name,
3422
-            ),
3423
-            'message_type_settings[message_type]' => array(
3424
-                'type'  => 'hidden',
3425
-                'value' => $message_type->name,
3426
-            ),
3427
-            'type'                                => array(
3428
-                'type'  => 'hidden',
3429
-                'value' => 'message_type',
3430
-            ),
3431
-        );
3432
-
3433
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3434
-            $settings_template_args['hidden_fields'],
3435
-            'array'
3436
-        );
3437
-        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3438
-            ? ' hidden'
3439
-            : '';
3440
-
3441
-
3442
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3443
-        $content = EEH_Template::display_template($template, $settings_template_args, true);
3444
-
3445
-        return $content;
3446
-    }
3447
-
3448
-
3449
-    /**
3450
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3451
-     *
3452
-     * @access protected
3453
-     * @return void
3454
-     * @throws DomainException
3455
-     */
3456
-    protected function _messages_settings_metaboxes()
3457
-    {
3458
-        $this->_set_m_mt_settings();
3459
-        $m_boxes = $mt_boxes = array();
3460
-        $m_template_args = $mt_template_args = array();
3461
-
3462
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3463
-            ? $this->_req_data['selected_messenger']
3464
-            : 'email';
3465
-
3466
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3467
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3468
-                $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3469
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3470
-                // messenger meta boxes
3471
-                $active = $selected_messenger === $messenger;
3472
-                $active_mt_tabs = isset(
3473
-                    $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3474
-                )
3475
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3476
-                    : '';
3477
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3478
-                    esc_html__('%s Settings', 'event_espresso'),
3479
-                    $tab_array['label']
3480
-                );
3481
-                $m_template_args[ $messenger . '_a_box' ] = array(
3482
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3483
-                    'inactive_message_types' => isset(
3484
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3485
-                    )
3486
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3487
-                        : '',
3488
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3489
-                    'hidden'                 => $active ? '' : ' hidden',
3490
-                    'hide_on_message'        => $hide_on_message,
3491
-                    'messenger'              => $messenger,
3492
-                    'active'                 => $active,
3493
-                );
3494
-                // message type meta boxes
3495
-                // (which is really just the inactive container for each messenger
3496
-                // showing inactive message types for that messenger)
3497
-                $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3498
-                $mt_template_args[ $messenger . '_i_box' ] = array(
3499
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3500
-                    'inactive_message_types' => isset(
3501
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3502
-                    )
3503
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3504
-                        : '',
3505
-                    'hidden'                 => $active ? '' : ' hidden',
3506
-                    'hide_on_message'        => $hide_on_message,
3507
-                    'hide_off_message'       => $hide_off_message,
3508
-                    'messenger'              => $messenger,
3509
-                    'active'                 => $active,
3510
-                );
3511
-            }
3512
-        }
3513
-
3514
-
3515
-        // register messenger metaboxes
3516
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3517
-        foreach ($m_boxes as $box => $label) {
3518
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3519
-            $msgr = str_replace('_a_box', '', $box);
3520
-            add_meta_box(
3521
-                'espresso_' . $msgr . '_settings',
3522
-                $label,
3523
-                function ($post, $metabox) {
3524
-                    echo EEH_Template::display_template(
3525
-                        $metabox["args"]["template_path"],
3526
-                        $metabox["args"]["template_args"],
3527
-                        true
3528
-                    );
3529
-                },
3530
-                $this->_current_screen->id,
3531
-                'normal',
3532
-                'high',
3533
-                $callback_args
3534
-            );
3535
-        }
3536
-
3537
-        // register message type metaboxes
3538
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3539
-        foreach ($mt_boxes as $box => $label) {
3540
-            $callback_args = array(
3541
-                'template_path' => $mt_template_path,
3542
-                'template_args' => $mt_template_args[ $box ],
3543
-            );
3544
-            $mt = str_replace('_i_box', '', $box);
3545
-            add_meta_box(
3546
-                'espresso_' . $mt . '_inactive_mts',
3547
-                $label,
3548
-                function ($post, $metabox) {
3549
-                    echo EEH_Template::display_template(
3550
-                        $metabox["args"]["template_path"],
3551
-                        $metabox["args"]["template_args"],
3552
-                        true
3553
-                    );
3554
-                },
3555
-                $this->_current_screen->id,
3556
-                'side',
3557
-                'high',
3558
-                $callback_args
3559
-            );
3560
-        }
3561
-
3562
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3563
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3564
-        if (is_main_site()) {
3565
-            add_meta_box(
3566
-                'espresso_global_message_settings',
3567
-                esc_html__('Global Message Settings', 'event_espresso'),
3568
-                array($this, 'global_messages_settings_metabox_content'),
3569
-                $this->_current_screen->id,
3570
-                'normal',
3571
-                'low',
3572
-                array()
3573
-            );
3574
-        }
3575
-    }
3576
-
3577
-
3578
-    /**
3579
-     *  This generates the content for the global messages settings metabox.
3580
-     *
3581
-     * @return string
3582
-     * @throws EE_Error
3583
-     * @throws InvalidArgumentException
3584
-     * @throws ReflectionException
3585
-     * @throws InvalidDataTypeException
3586
-     * @throws InvalidInterfaceException
3587
-     */
3588
-    public function global_messages_settings_metabox_content()
3589
-    {
3590
-        $form = $this->_generate_global_settings_form();
3591
-        echo $form->form_open(
3592
-            $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3593
-            'POST'
3594
-        )
3595
-             . $form->get_html()
3596
-             . $form->form_close();
3597
-    }
3598
-
3599
-
3600
-    /**
3601
-     * This generates and returns the form object for the global messages settings.
3602
-     *
3603
-     * @return EE_Form_Section_Proper
3604
-     * @throws EE_Error
3605
-     * @throws InvalidArgumentException
3606
-     * @throws ReflectionException
3607
-     * @throws InvalidDataTypeException
3608
-     * @throws InvalidInterfaceException
3609
-     */
3610
-    protected function _generate_global_settings_form()
3611
-    {
3612
-        EE_Registry::instance()->load_helper('HTML');
3613
-        /** @var EE_Network_Core_Config $network_config */
3614
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3615
-
3616
-        return new EE_Form_Section_Proper(
3617
-            array(
3618
-                'name'            => 'global_messages_settings',
3619
-                'html_id'         => 'global_messages_settings',
3620
-                'html_class'      => 'form-table',
3621
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3622
-                'subsections'     => apply_filters(
3623
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3624
-                    array(
3625
-                        'do_messages_on_same_request' => new EE_Select_Input(
3626
-                            array(
3627
-                                true  => esc_html__("On the same request", "event_espresso"),
3628
-                                false => esc_html__("On a separate request", "event_espresso"),
3629
-                            ),
3630
-                            array(
3631
-                                'default'         => $network_config->do_messages_on_same_request,
3632
-                                'html_label_text' => esc_html__(
3633
-                                    'Generate and send all messages:',
3634
-                                    'event_espresso'
3635
-                                ),
3636
-                                'html_help_text'  => esc_html__(
3637
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3638
-                                    'event_espresso'
3639
-                                ),
3640
-                            )
3641
-                        ),
3642
-                        'delete_threshold'            => new EE_Select_Input(
3643
-                            array(
3644
-                                0  => esc_html__('Forever', 'event_espresso'),
3645
-                                3  => esc_html__('3 Months', 'event_espresso'),
3646
-                                6  => esc_html__('6 Months', 'event_espresso'),
3647
-                                9  => esc_html__('9 Months', 'event_espresso'),
3648
-                                12 => esc_html__('12 Months', 'event_espresso'),
3649
-                                24 => esc_html__('24 Months', 'event_espresso'),
3650
-                                36 => esc_html__('36 Months', 'event_espresso'),
3651
-                            ),
3652
-                            array(
3653
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3654
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3655
-                                'html_help_text'  => esc_html__(
3656
-                                    'You can control how long a record of processed messages is kept via this option.',
3657
-                                    'event_espresso'
3658
-                                ),
3659
-                            )
3660
-                        ),
3661
-                        'update_settings'             => new EE_Submit_Input(
3662
-                            array(
3663
-                                'default'         => esc_html__('Update', 'event_espresso'),
3664
-                                'html_label_text' => '&nbsp',
3665
-                            )
3666
-                        ),
3667
-                    )
3668
-                ),
3669
-            )
3670
-        );
3671
-    }
3672
-
3673
-
3674
-    /**
3675
-     * This handles updating the global settings set on the admin page.
3676
-     *
3677
-     * @throws EE_Error
3678
-     * @throws InvalidDataTypeException
3679
-     * @throws InvalidInterfaceException
3680
-     * @throws InvalidArgumentException
3681
-     * @throws ReflectionException
3682
-     */
3683
-    protected function _update_global_settings()
3684
-    {
3685
-        /** @var EE_Network_Core_Config $network_config */
3686
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3687
-        $messages_config = EE_Registry::instance()->CFG->messages;
3688
-        $form = $this->_generate_global_settings_form();
3689
-        if ($form->was_submitted()) {
3690
-            $form->receive_form_submission();
3691
-            if ($form->is_valid()) {
3692
-                $valid_data = $form->valid_data();
3693
-                foreach ($valid_data as $property => $value) {
3694
-                    $setter = 'set_' . $property;
3695
-                    if (method_exists($network_config, $setter)) {
3696
-                        $network_config->{$setter}($value);
3697
-                    } elseif (
3698
-                        property_exists($network_config, $property)
3699
-                        && $network_config->{$property} !== $value
3700
-                    ) {
3701
-                        $network_config->{$property} = $value;
3702
-                    } elseif (
3703
-                        property_exists($messages_config, $property)
3704
-                        && $messages_config->{$property} !== $value
3705
-                    ) {
3706
-                        $messages_config->{$property} = $value;
3707
-                    }
3708
-                }
3709
-                // only update if the form submission was valid!
3710
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3711
-                EE_Registry::instance()->CFG->update_espresso_config();
3712
-                EE_Error::overwrite_success();
3713
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3714
-            }
3715
-        }
3716
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3717
-    }
3718
-
3719
-
3720
-    /**
3721
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3722
-     *
3723
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3724
-     * @return string html formatted tabs
3725
-     * @throws DomainException
3726
-     */
3727
-    protected function _get_mt_tabs($tab_array)
3728
-    {
3729
-        $tab_array = (array) $tab_array;
3730
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3731
-        $tabs = '';
3732
-
3733
-        foreach ($tab_array as $tab) {
3734
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3735
-        }
3736
-
3737
-        return $tabs;
3738
-    }
3739
-
3740
-
3741
-    /**
3742
-     * This prepares the content of the messenger meta box admin settings
3743
-     *
3744
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3745
-     * @return string html formatted content
3746
-     * @throws DomainException
3747
-     */
3748
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3749
-    {
3750
-
3751
-        $fields = $messenger->get_admin_settings_fields();
3752
-        $settings_template_args['template_form_fields'] = '';
3753
-
3754
-        // is $messenger active?
3755
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3756
-
3757
-
3758
-        if (! empty($fields)) {
3759
-            $existing_settings = $messenger->get_existing_admin_settings();
3760
-
3761
-            foreach ($fields as $fldname => $fldprops) {
3762
-                $field_id = $messenger->name . '-' . $fldname;
3763
-                $template_form_field[ $field_id ] = array(
3764
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3765
-                    'label'      => $fldprops['label'],
3766
-                    'input'      => $fldprops['field_type'],
3767
-                    'type'       => $fldprops['value_type'],
3768
-                    'required'   => $fldprops['required'],
3769
-                    'validation' => $fldprops['validation'],
3770
-                    'value'      => isset($existing_settings[ $field_id ])
3771
-                        ? $existing_settings[ $field_id ]
3772
-                        : $fldprops['default'],
3773
-                    'css_class'  => '',
3774
-                    'format'     => $fldprops['format'],
3775
-                );
3776
-            }
3777
-
3778
-
3779
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3780
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3781
-                : '';
3782
-        }
3783
-
3784
-        // we also need some hidden fields
3785
-        $settings_template_args['hidden_fields'] = array(
3786
-            'messenger_settings[messenger]' => array(
3787
-                'type'  => 'hidden',
3788
-                'value' => $messenger->name,
3789
-            ),
3790
-            'type'                          => array(
3791
-                'type'  => 'hidden',
3792
-                'value' => 'messenger',
3793
-            ),
3794
-        );
3795
-
3796
-        // make sure any active message types that are existing are included in the hidden fields
3797
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3798
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3799
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3800
-                    'type'  => 'hidden',
3801
-                    'value' => $mt,
3802
-                );
3803
-            }
3804
-        }
3805
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3806
-            $settings_template_args['hidden_fields'],
3807
-            'array'
3808
-        );
3809
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3810
-
3811
-        $settings_template_args['messenger'] = $messenger->name;
3812
-        $settings_template_args['description'] = $messenger->description;
3813
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3814
-
3815
-
3816
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3817
-            $messenger->name
3818
-        )
3819
-            ? $settings_template_args['show_hide_edit_form']
3820
-            : ' hidden';
3821
-
3822
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3823
-            ? ' hidden'
3824
-            : $settings_template_args['show_hide_edit_form'];
3825
-
3826
-
3827
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3828
-        $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3829
-        $settings_template_args['on_off_status'] = $active ? true : false;
3830
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3831
-        $content = EEH_Template::display_template(
3832
-            $template,
3833
-            $settings_template_args,
3834
-            true
3835
-        );
3836
-
3837
-        return $content;
3838
-    }
3839
-
3840
-
3841
-    /**
3842
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3843
-     *
3844
-     * @throws DomainException
3845
-     * @throws EE_Error
3846
-     * @throws InvalidDataTypeException
3847
-     * @throws InvalidInterfaceException
3848
-     * @throws InvalidArgumentException
3849
-     * @throws ReflectionException
3850
-     */
3851
-    public function activate_messenger_toggle()
3852
-    {
3853
-        $success = true;
3854
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3855
-        // let's check that we have required data
3856
-        if (! isset($this->_req_data['messenger'])) {
3857
-            EE_Error::add_error(
3858
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3859
-                __FILE__,
3860
-                __FUNCTION__,
3861
-                __LINE__
3862
-            );
3863
-            $success = false;
3864
-        }
3865
-
3866
-        // do a nonce check here since we're not arriving via a normal route
3867
-        $nonce = isset($this->_req_data['activate_nonce'])
3868
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3869
-            : '';
3870
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3871
-
3872
-        $this->_verify_nonce($nonce, $nonce_ref);
3873
-
3874
-
3875
-        if (! isset($this->_req_data['status'])) {
3876
-            EE_Error::add_error(
3877
-                esc_html__(
3878
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3879
-                    'event_espresso'
3880
-                ),
3881
-                __FILE__,
3882
-                __FUNCTION__,
3883
-                __LINE__
3884
-            );
3885
-            $success = false;
3886
-        }
3887
-
3888
-        // do check to verify we have a valid status.
3889
-        $status = $this->_req_data['status'];
3890
-
3891
-        if ($status !== 'off' && $status !== 'on') {
3892
-            EE_Error::add_error(
3893
-                sprintf(
3894
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3895
-                    $this->_req_data['status']
3896
-                ),
3897
-                __FILE__,
3898
-                __FUNCTION__,
3899
-                __LINE__
3900
-            );
3901
-            $success = false;
3902
-        }
3903
-
3904
-        if ($success) {
3905
-            // made it here?  Stop dawdling then!!
3906
-            $success = $status === 'off'
3907
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3908
-                : $this->_activate_messenger($this->_req_data['messenger']);
3909
-        }
3910
-
3911
-        $this->_template_args['success'] = $success;
3912
-
3913
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
3914
-        $this->_return_json();
3915
-    }
3916
-
3917
-
3918
-    /**
3919
-     * used by ajax from the messages settings page to activate|deactivate a message type
3920
-     *
3921
-     * @throws DomainException
3922
-     * @throws EE_Error
3923
-     * @throws ReflectionException
3924
-     * @throws InvalidDataTypeException
3925
-     * @throws InvalidInterfaceException
3926
-     * @throws InvalidArgumentException
3927
-     */
3928
-    public function activate_mt_toggle()
3929
-    {
3930
-        $success = true;
3931
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3932
-
3933
-        // let's make sure we have the necessary data
3934
-        if (! isset($this->_req_data['message_type'])) {
3935
-            EE_Error::add_error(
3936
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3937
-                __FILE__,
3938
-                __FUNCTION__,
3939
-                __LINE__
3940
-            );
3941
-            $success = false;
3942
-        }
3943
-
3944
-        if (! isset($this->_req_data['messenger'])) {
3945
-            EE_Error::add_error(
3946
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3947
-                __FILE__,
3948
-                __FUNCTION__,
3949
-                __LINE__
3950
-            );
3951
-            $success = false;
3952
-        }
3953
-
3954
-        if (! isset($this->_req_data['status'])) {
3955
-            EE_Error::add_error(
3956
-                esc_html__(
3957
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3958
-                    'event_espresso'
3959
-                ),
3960
-                __FILE__,
3961
-                __FUNCTION__,
3962
-                __LINE__
3963
-            );
3964
-            $success = false;
3965
-        }
3966
-
3967
-
3968
-        // do check to verify we have a valid status.
3969
-        $status = $this->_req_data['status'];
3970
-
3971
-        if ($status !== 'activate' && $status !== 'deactivate') {
3972
-            EE_Error::add_error(
3973
-                sprintf(
3974
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3975
-                    $this->_req_data['status']
3976
-                ),
3977
-                __FILE__,
3978
-                __FUNCTION__,
3979
-                __LINE__
3980
-            );
3981
-            $success = false;
3982
-        }
3983
-
3984
-
3985
-        // do a nonce check here since we're not arriving via a normal route
3986
-        $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3987
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3988
-
3989
-        $this->_verify_nonce($nonce, $nonce_ref);
3990
-
3991
-        if ($success) {
3992
-            // made it here? um, what are you waiting for then?
3993
-            $success = $status === 'deactivate'
3994
-                ? $this->_deactivate_message_type_for_messenger(
3995
-                    $this->_req_data['messenger'],
3996
-                    $this->_req_data['message_type']
3997
-                )
3998
-                : $this->_activate_message_type_for_messenger(
3999
-                    $this->_req_data['messenger'],
4000
-                    $this->_req_data['message_type']
4001
-                );
4002
-        }
4003
-
4004
-        $this->_template_args['success'] = $success;
4005
-        $this->_return_json();
4006
-    }
4007
-
4008
-
4009
-    /**
4010
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4011
-     *
4012
-     * @param string $messenger_name The name of the messenger being activated
4013
-     * @return bool
4014
-     * @throws DomainException
4015
-     * @throws EE_Error
4016
-     * @throws InvalidArgumentException
4017
-     * @throws ReflectionException
4018
-     * @throws InvalidDataTypeException
4019
-     * @throws InvalidInterfaceException
4020
-     */
4021
-    protected function _activate_messenger($messenger_name)
4022
-    {
4023
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4024
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4025
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4026
-            ? $active_messenger->get_default_message_types()
4027
-            : array();
4028
-
4029
-        // ensure is active
4030
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
4031
-
4032
-        // set response_data for reload
4033
-        foreach ($message_types_to_activate as $message_type_name) {
4034
-            /** @var EE_message_type $message_type */
4035
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4036
-            if (
4037
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4038
-                    $messenger_name,
4039
-                    $message_type_name
4040
-                )
4041
-                && $message_type instanceof EE_message_type
4042
-            ) {
4043
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4044
-                if ($message_type->get_admin_settings_fields()) {
4045
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4046
-                }
4047
-            }
4048
-        }
4049
-
4050
-        // add success message for activating messenger
4051
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4052
-    }
4053
-
4054
-
4055
-    /**
4056
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4057
-     *
4058
-     * @param string $messenger_name The name of the messenger being activated
4059
-     * @return bool
4060
-     * @throws DomainException
4061
-     * @throws EE_Error
4062
-     * @throws InvalidArgumentException
4063
-     * @throws ReflectionException
4064
-     * @throws InvalidDataTypeException
4065
-     * @throws InvalidInterfaceException
4066
-     */
4067
-    protected function _deactivate_messenger($messenger_name)
4068
-    {
4069
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4070
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4071
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4072
-
4073
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4074
-    }
4075
-
4076
-
4077
-    /**
4078
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4079
-     *
4080
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4081
-     * @param string $message_type_name The name of the message type being activated for the messenger
4082
-     * @return bool
4083
-     * @throws DomainException
4084
-     * @throws EE_Error
4085
-     * @throws InvalidArgumentException
4086
-     * @throws ReflectionException
4087
-     * @throws InvalidDataTypeException
4088
-     * @throws InvalidInterfaceException
4089
-     */
4090
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4091
-    {
4092
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4093
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4094
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4095
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4096
-
4097
-        // ensure is active
4098
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
4099
-
4100
-        // set response for load
4101
-        if (
4102
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4103
-                $messenger_name,
4104
-                $message_type_name
4105
-            )
4106
-        ) {
4107
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4108
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4109
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4110
-            }
4111
-        }
4112
-
4113
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4114
-            $active_messenger,
4115
-            $message_type_to_activate
4116
-        );
4117
-    }
4118
-
4119
-
4120
-    /**
4121
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4122
-     *
4123
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4124
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4125
-     * @return bool
4126
-     * @throws DomainException
4127
-     * @throws EE_Error
4128
-     * @throws InvalidArgumentException
4129
-     * @throws ReflectionException
4130
-     * @throws InvalidDataTypeException
4131
-     * @throws InvalidInterfaceException
4132
-     */
4133
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4134
-    {
4135
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4136
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4137
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4138
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4139
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4140
-
4141
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4142
-            $active_messenger,
4143
-            $message_type_to_deactivate
4144
-        );
4145
-    }
4146
-
4147
-
4148
-    /**
4149
-     * This just initializes the defaults for activating messenger and message type responses.
4150
-     */
4151
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4152
-    {
4153
-        $this->_template_args['data']['active_mts'] = array();
4154
-        $this->_template_args['data']['mt_reload'] = array();
4155
-    }
4156
-
4157
-
4158
-    /**
4159
-     * Setup appropriate response for activating a messenger and/or message types
4160
-     *
4161
-     * @param EE_messenger         $messenger
4162
-     * @param EE_message_type|null $message_type
4163
-     * @return bool
4164
-     * @throws DomainException
4165
-     * @throws EE_Error
4166
-     * @throws InvalidArgumentException
4167
-     * @throws ReflectionException
4168
-     * @throws InvalidDataTypeException
4169
-     * @throws InvalidInterfaceException
4170
-     */
4171
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4172
-        $messenger,
4173
-        EE_Message_Type $message_type = null
4174
-    ) {
4175
-        // if $messenger isn't a valid messenger object then get out.
4176
-        if (! $messenger instanceof EE_Messenger) {
4177
-            EE_Error::add_error(
4178
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4179
-                __FILE__,
4180
-                __FUNCTION__,
4181
-                __LINE__
4182
-            );
4183
-
4184
-            return false;
4185
-        }
4186
-        // activated
4187
-        if ($this->_template_args['data']['active_mts']) {
4188
-            EE_Error::overwrite_success();
4189
-            // activated a message type with the messenger
4190
-            if ($message_type instanceof EE_message_type) {
4191
-                EE_Error::add_success(
4192
-                    sprintf(
4193
-                        esc_html__(
4194
-                            '%s message type has been successfully activated with the %s messenger',
4195
-                            'event_espresso'
4196
-                        ),
4197
-                        ucwords($message_type->label['singular']),
4198
-                        ucwords($messenger->label['singular'])
4199
-                    )
4200
-                );
4201
-
4202
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4203
-                if ($message_type->name === 'invoice') {
4204
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4205
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4206
-                    if ($pm instanceof EE_Payment_Method) {
4207
-                        EE_Error::add_attention(
4208
-                            esc_html__(
4209
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4210
-                                'event_espresso'
4211
-                            )
4212
-                        );
4213
-                    }
4214
-                }
4215
-                // just toggles the entire messenger
4216
-            } else {
4217
-                EE_Error::add_success(
4218
-                    sprintf(
4219
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4220
-                        ucwords($messenger->label['singular'])
4221
-                    )
4222
-                );
4223
-            }
4224
-
4225
-            return true;
4226
-
4227
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4228
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4229
-            // in which case we just give a success message for the messenger being successfully activated.
4230
-        } else {
4231
-            if (! $messenger->get_default_message_types()) {
4232
-                // messenger doesn't have any default message types so still a success.
4233
-                EE_Error::add_success(
4234
-                    sprintf(
4235
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4236
-                        ucwords($messenger->label['singular'])
4237
-                    )
4238
-                );
4239
-
4240
-                return true;
4241
-            } else {
4242
-                EE_Error::add_error(
4243
-                    $message_type instanceof EE_message_type
4244
-                        ? sprintf(
4245
-                            esc_html__(
4246
-                                '%s message type was not successfully activated with the %s messenger',
4247
-                                'event_espresso'
4248
-                            ),
4249
-                            ucwords($message_type->label['singular']),
4250
-                            ucwords($messenger->label['singular'])
4251
-                        )
4252
-                        : sprintf(
4253
-                            esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4254
-                            ucwords($messenger->label['singular'])
4255
-                        ),
4256
-                    __FILE__,
4257
-                    __FUNCTION__,
4258
-                    __LINE__
4259
-                );
4260
-
4261
-                return false;
4262
-            }
4263
-        }
4264
-    }
4265
-
4266
-
4267
-    /**
4268
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4269
-     *
4270
-     * @param EE_messenger         $messenger
4271
-     * @param EE_message_type|null $message_type
4272
-     * @return bool
4273
-     * @throws DomainException
4274
-     * @throws EE_Error
4275
-     * @throws InvalidArgumentException
4276
-     * @throws ReflectionException
4277
-     * @throws InvalidDataTypeException
4278
-     * @throws InvalidInterfaceException
4279
-     */
4280
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4281
-        $messenger,
4282
-        EE_message_type $message_type = null
4283
-    ) {
4284
-        EE_Error::overwrite_success();
4285
-
4286
-        // if $messenger isn't a valid messenger object then get out.
4287
-        if (! $messenger instanceof EE_Messenger) {
4288
-            EE_Error::add_error(
4289
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4290
-                __FILE__,
4291
-                __FUNCTION__,
4292
-                __LINE__
4293
-            );
4294
-
4295
-            return false;
4296
-        }
4297
-
4298
-        if ($message_type instanceof EE_message_type) {
4299
-            $message_type_name = $message_type->name;
4300
-            EE_Error::add_success(
4301
-                sprintf(
4302
-                    esc_html__(
4303
-                        '%s message type has been successfully deactivated for the %s messenger.',
4304
-                        'event_espresso'
4305
-                    ),
4306
-                    ucwords($message_type->label['singular']),
4307
-                    ucwords($messenger->label['singular'])
4308
-                )
4309
-            );
4310
-        } else {
4311
-            $message_type_name = '';
4312
-            EE_Error::add_success(
4313
-                sprintf(
4314
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4315
-                    ucwords($messenger->label['singular'])
4316
-                )
4317
-            );
4318
-        }
4319
-
4320
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4321
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4322
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4323
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4324
-            if ($count_updated > 0) {
4325
-                $msg = $message_type_name === 'invoice'
4326
-                    ? esc_html__(
4327
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4328
-                        'event_espresso'
4329
-                    )
4330
-                    : esc_html__(
4331
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4332
-                        'event_espresso'
4333
-                    );
4334
-                EE_Error::add_attention($msg);
4335
-            }
4336
-        }
4337
-
4338
-        return true;
4339
-    }
4340
-
4341
-
4342
-    /**
4343
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4344
-     *
4345
-     * @throws DomainException
4346
-     */
4347
-    public function update_mt_form()
4348
-    {
4349
-        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4350
-            EE_Error::add_error(
4351
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4352
-                __FILE__,
4353
-                __FUNCTION__,
4354
-                __LINE__
4355
-            );
4356
-            $this->_return_json();
4357
-        }
4358
-
4359
-        $message_types = $this->get_installed_message_types();
4360
-
4361
-        $message_type = $message_types[ $this->_req_data['message_type'] ];
4362
-        $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4363
-
4364
-        $content = $this->_message_type_settings_content(
4365
-            $message_type,
4366
-            $messenger,
4367
-            true
4368
-        );
4369
-        $this->_template_args['success'] = true;
4370
-        $this->_template_args['content'] = $content;
4371
-        $this->_return_json();
4372
-    }
4373
-
4374
-
4375
-    /**
4376
-     * this handles saving the settings for a messenger or message type
4377
-     *
4378
-     */
4379
-    public function save_settings()
4380
-    {
4381
-        if (! isset($this->_req_data['type'])) {
4382
-            EE_Error::add_error(
4383
-                esc_html__(
4384
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4385
-                    'event_espresso'
4386
-                ),
4387
-                __FILE__,
4388
-                __FUNCTION__,
4389
-                __LINE__
4390
-            );
4391
-            $this->_template_args['error'] = true;
4392
-            $this->_return_json();
4393
-        }
4394
-
4395
-
4396
-        if ($this->_req_data['type'] === 'messenger') {
4397
-            // this should be an array.
4398
-            $settings = $this->_req_data['messenger_settings'];
4399
-            $messenger = $settings['messenger'];
4400
-            // let's setup the settings data
4401
-            foreach ($settings as $key => $value) {
4402
-                switch ($key) {
4403
-                    case 'messenger':
4404
-                        unset($settings['messenger']);
4405
-                        break;
4406
-                    case 'message_types':
4407
-                        unset($settings['message_types']);
4408
-                        break;
4409
-                    default:
4410
-                        $settings[ $key ] = $value;
4411
-                        break;
4412
-                }
4413
-            }
4414
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4415
-        } elseif ($this->_req_data['type'] === 'message_type') {
4416
-            $settings = $this->_req_data['message_type_settings'];
4417
-            $messenger = $settings['messenger'];
4418
-            $message_type = $settings['message_type'];
4419
-
4420
-            foreach ($settings as $key => $value) {
4421
-                switch ($key) {
4422
-                    case 'messenger':
4423
-                        unset($settings['messenger']);
4424
-                        break;
4425
-                    case 'message_type':
4426
-                        unset($settings['message_type']);
4427
-                        break;
4428
-                    default:
4429
-                        $settings[ $key ] = $value;
4430
-                        break;
4431
-                }
4432
-            }
4433
-
4434
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4435
-        }
4436
-
4437
-        // okay we should have the data all setup.  Now we just update!
4438
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4439
-
4440
-        if ($success) {
4441
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4442
-        } else {
4443
-            EE_Error::add_error(
4444
-                esc_html__(
4445
-                    'Settings did not get updated',
4446
-                    'event_espresso'
4447
-                ),
4448
-                __FILE__,
4449
-                __FUNCTION__,
4450
-                __LINE__
4451
-            );
4452
-        }
4453
-
4454
-        $this->_template_args['success'] = $success;
4455
-        $this->_return_json();
4456
-    }
4457
-
4458
-
4459
-
4460
-
4461
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4462
-
4463
-
4464
-    /**
4465
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4466
-     * However, this does not send immediately, it just queues for sending.
4467
-     *
4468
-     * @since 4.9.0
4469
-     * @throws EE_Error
4470
-     * @throws InvalidDataTypeException
4471
-     * @throws InvalidInterfaceException
4472
-     * @throws InvalidArgumentException
4473
-     * @throws ReflectionException
4474
-     */
4475
-    protected function _generate_now()
4476
-    {
4477
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4478
-        $this->_redirect_after_action(false, '', '', array(), true);
4479
-    }
4480
-
4481
-
4482
-    /**
4483
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4484
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4485
-     *
4486
-     * @since 4.9.0
4487
-     * @throws EE_Error
4488
-     * @throws InvalidDataTypeException
4489
-     * @throws InvalidInterfaceException
4490
-     * @throws InvalidArgumentException
4491
-     * @throws ReflectionException
4492
-     */
4493
-    protected function _generate_and_send_now()
4494
-    {
4495
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4496
-        $this->_redirect_after_action(false, '', '', array(), true);
4497
-    }
4498
-
4499
-
4500
-    /**
4501
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4502
-     *
4503
-     * @since 4.9.0
4504
-     * @throws EE_Error
4505
-     * @throws InvalidDataTypeException
4506
-     * @throws InvalidInterfaceException
4507
-     * @throws InvalidArgumentException
4508
-     * @throws ReflectionException
4509
-     */
4510
-    protected function _queue_for_resending()
4511
-    {
4512
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4513
-        $this->_redirect_after_action(false, '', '', array(), true);
4514
-    }
4515
-
4516
-
4517
-    /**
4518
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4519
-     *
4520
-     * @since 4.9.0
4521
-     * @throws EE_Error
4522
-     * @throws InvalidDataTypeException
4523
-     * @throws InvalidInterfaceException
4524
-     * @throws InvalidArgumentException
4525
-     * @throws ReflectionException
4526
-     */
4527
-    protected function _send_now()
4528
-    {
4529
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4530
-        $this->_redirect_after_action(false, '', '', array(), true);
4531
-    }
4532
-
4533
-
4534
-    /**
4535
-     * Deletes EE_messages for IDs in the request.
4536
-     *
4537
-     * @since 4.9.0
4538
-     * @throws EE_Error
4539
-     * @throws InvalidDataTypeException
4540
-     * @throws InvalidInterfaceException
4541
-     * @throws InvalidArgumentException
4542
-     */
4543
-    protected function _delete_ee_messages()
4544
-    {
4545
-        $msg_ids = $this->_get_msg_ids_from_request();
4546
-        $deleted_count = 0;
4547
-        foreach ($msg_ids as $msg_id) {
4548
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4549
-                $deleted_count++;
4550
-            }
4551
-        }
4552
-        if ($deleted_count) {
4553
-            EE_Error::add_success(
4554
-                esc_html(
4555
-                    _n(
4556
-                        'Message successfully deleted',
4557
-                        'Messages successfully deleted',
4558
-                        $deleted_count,
4559
-                        'event_espresso'
4560
-                    )
4561
-                )
4562
-            );
4563
-            $this->_redirect_after_action(
4564
-                false,
4565
-                '',
4566
-                '',
4567
-                array(),
4568
-                true
4569
-            );
4570
-        } else {
4571
-            EE_Error::add_error(
4572
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4573
-                __FILE__,
4574
-                __FUNCTION__,
4575
-                __LINE__
4576
-            );
4577
-            $this->_redirect_after_action(false, '', '', array(), true);
4578
-        }
4579
-    }
4580
-
4581
-
4582
-    /**
4583
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4584
-     *
4585
-     * @since 4.9.0
4586
-     * @return array
4587
-     */
4588
-    protected function _get_msg_ids_from_request()
4589
-    {
4590
-        if (! isset($this->_req_data['MSG_ID'])) {
4591
-            return array();
4592
-        }
4593
-
4594
-        return is_array($this->_req_data['MSG_ID'])
4595
-            ? array_keys($this->_req_data['MSG_ID'])
4596
-            : array($this->_req_data['MSG_ID']);
4597
-    }
2670
+		$output = ob_get_contents();
2671
+		ob_clean();
2672
+		$this->_context_switcher = $output;
2673
+	}
2674
+
2675
+
2676
+	/**
2677
+	 * utility for sanitizing new values coming in.
2678
+	 * Note: this is only used when updating a context.
2679
+	 *
2680
+	 * @access protected
2681
+	 *
2682
+	 * @param int $index This helps us know which template field to select from the request array.
2683
+	 *
2684
+	 * @return array
2685
+	 */
2686
+	protected function _set_message_template_column_values($index)
2687
+	{
2688
+		if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2689
+			foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2690
+				$this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2691
+			}
2692
+		}
2693
+
2694
+
2695
+		$set_column_values = array(
2696
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2697
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2698
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2699
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2700
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2701
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2702
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2703
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2704
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2705
+				? absint($this->_req_data['MTP_is_global'])
2706
+				: 0,
2707
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2708
+				? absint($this->_req_data['MTP_is_override'])
2709
+				: 0,
2710
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2711
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2712
+		);
2713
+
2714
+
2715
+		return $set_column_values;
2716
+	}
2717
+
2718
+
2719
+	protected function _insert_or_update_message_template($new = false)
2720
+	{
2721
+
2722
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2723
+		$success = 0;
2724
+		$override = false;
2725
+
2726
+		// setup notices description
2727
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2728
+
2729
+		// need the message type and messenger objects to be able to use the labels for the notices
2730
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2731
+		$messenger_label = $messenger_object instanceof EE_messenger
2732
+			? ucwords($messenger_object->label['singular'])
2733
+			: '';
2734
+
2735
+		$message_type_slug = ! empty($this->_req_data['MTP_message_type'])
2736
+			? $this->_req_data['MTP_message_type']
2737
+			: '';
2738
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2739
+
2740
+		$message_type_label = $message_type_object instanceof EE_message_type
2741
+			? ucwords($message_type_object->label['singular'])
2742
+			: '';
2743
+
2744
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2745
+			? $this->_req_data['MTP_context']
2746
+			: '';
2747
+		$context = ucwords(str_replace('_', ' ', $context_slug));
2748
+
2749
+		$item_desc = $messenger_label && $message_type_label
2750
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2751
+			: '';
2752
+		$item_desc .= 'Message Template';
2753
+		$query_args = array();
2754
+		$edit_array = array();
2755
+		$action_desc = '';
2756
+
2757
+		// if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2758
+		// user to edit.
2759
+		if ($new) {
2760
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2761
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2762
+				if (empty($edit_array)) {
2763
+					$success = 0;
2764
+				} else {
2765
+					$success = 1;
2766
+					$edit_array = $edit_array[0];
2767
+					$query_args = array(
2768
+						'id'      => $edit_array['GRP_ID'],
2769
+						'context' => $edit_array['MTP_context'],
2770
+						'action'  => 'edit_message_template',
2771
+					);
2772
+				}
2773
+			}
2774
+			$action_desc = 'created';
2775
+		} else {
2776
+			$MTPG = EEM_Message_Template_Group::instance();
2777
+			$MTP = EEM_Message_Template::instance();
2778
+
2779
+
2780
+			// run update for each template field in displayed context
2781
+			if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2782
+				EE_Error::add_error(
2783
+					esc_html__(
2784
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2785
+						'event_espresso'
2786
+					),
2787
+					__FILE__,
2788
+					__FUNCTION__,
2789
+					__LINE__
2790
+				);
2791
+				$success = 0;
2792
+			} else {
2793
+				// first validate all fields!
2794
+				// this filter allows client code to add its own validation to the template fields as well.
2795
+				// returning an empty array means everything passed validation.
2796
+				// errors in validation should be represented in an array with the following shape:
2797
+				// array(
2798
+				//   'fieldname' => array(
2799
+				//          'msg' => 'error message'
2800
+				//          'value' => 'value for field producing error'
2801
+				// )
2802
+				$custom_validation = (array) apply_filters(
2803
+					'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2804
+					array(),
2805
+					$this->_req_data['MTP_template_fields'],
2806
+					$context_slug,
2807
+					$messenger_slug,
2808
+					$message_type_slug
2809
+				);
2810
+
2811
+				$system_validation = $MTPG->validate(
2812
+					$this->_req_data['MTP_template_fields'],
2813
+					$context_slug,
2814
+					$messenger_slug,
2815
+					$message_type_slug
2816
+				);
2817
+
2818
+				$system_validation = ! is_array($system_validation) && $system_validation ? array()
2819
+					: $system_validation;
2820
+				$validates = array_merge($custom_validation, $system_validation);
2821
+
2822
+				// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2823
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2824
+				//  WE need to make sure there is no actual error messages in validates.
2825
+				if (is_array($validates) && ! empty($validates)) {
2826
+					// add the transient so when the form loads we know which fields to highlight
2827
+					$this->_add_transient('edit_message_template', $validates);
2828
+
2829
+					$success = 0;
2830
+
2831
+					// setup notices
2832
+					foreach ($validates as $field => $error) {
2833
+						if (isset($error['msg'])) {
2834
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2835
+						}
2836
+					}
2837
+				} else {
2838
+					$set_column_values = array();
2839
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2840
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2841
+
2842
+						$where_cols_n_values = array(
2843
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2844
+						);
2845
+						// if they aren't allowed to use all JS, restrict them to just posty-y tags
2846
+						if (! current_user_can('unfiltered_html')) {
2847
+							if (is_array($set_column_values['MTP_content'])) {
2848
+								foreach ($set_column_values['MTP_content'] as $key => $value) {
2849
+									// remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2850
+									// only removes slashes from double-quotes, so attributes using single quotes always
2851
+									// appear invalid.) But currently the models expect slashed data, so after wp_kses
2852
+									// runs we need to re-slash the data. Sheesh. See
2853
+									// https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2854
+									$set_column_values['MTP_content'][ $key ] = addslashes(
2855
+										wp_kses(
2856
+											stripslashes($value),
2857
+											wp_kses_allowed_html('post')
2858
+										)
2859
+									);
2860
+								}
2861
+							} else {
2862
+								$set_column_values['MTP_content'] = wp_kses(
2863
+									$set_column_values['MTP_content'],
2864
+									wp_kses_allowed_html('post')
2865
+								);
2866
+							}
2867
+						}
2868
+						$message_template_fields = array(
2869
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2870
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2871
+							'MTP_context'        => $set_column_values['MTP_context'],
2872
+							'MTP_content'        => $set_column_values['MTP_content'],
2873
+						);
2874
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2875
+							if ($updated === false) {
2876
+								EE_Error::add_error(
2877
+									sprintf(
2878
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2879
+										$template_field
2880
+									),
2881
+									__FILE__,
2882
+									__FUNCTION__,
2883
+									__LINE__
2884
+								);
2885
+							} else {
2886
+								$success = 1;
2887
+							}
2888
+						} else {
2889
+							// only do this logic if we don't have a MTP_ID for this field
2890
+							if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2891
+								// this has already been through the template field validator and sanitized, so it will be
2892
+								// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2893
+								// message template field in a messenger/message type and existing users don't have the
2894
+								// default setup for it.
2895
+								// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2896
+								$updated = $MTP->insert($message_template_fields);
2897
+								if (! $updated || is_wp_error($updated)) {
2898
+									EE_Error::add_error(
2899
+										sprintf(
2900
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2901
+											$template_field
2902
+										),
2903
+										__FILE__,
2904
+										__FUNCTION__,
2905
+										__LINE__
2906
+									);
2907
+									$success = 0;
2908
+								} else {
2909
+									$success = 1;
2910
+								}
2911
+							}
2912
+						}
2913
+						$action_desc = 'updated';
2914
+					}
2915
+
2916
+					// we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2917
+					$mtpg_fields = array(
2918
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2919
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2920
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2921
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2922
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2923
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2924
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2925
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2926
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2927
+							: '',
2928
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2929
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2930
+							: '',
2931
+					);
2932
+
2933
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2934
+					$updated = $MTPG->update($mtpg_fields, array($mtpg_where));
2935
+
2936
+					if ($updated === false) {
2937
+						EE_Error::add_error(
2938
+							sprintf(
2939
+								esc_html__(
2940
+									'The Message Template Group (%d) was NOT updated for some reason',
2941
+									'event_espresso'
2942
+								),
2943
+								$set_column_values['GRP_ID']
2944
+							),
2945
+							__FILE__,
2946
+							__FUNCTION__,
2947
+							__LINE__
2948
+						);
2949
+					} else {
2950
+						// k now we need to ensure the template_pack and template_variation fields are set.
2951
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2952
+							? $this->_req_data['MTP_template_pack']
2953
+							: 'default';
2954
+
2955
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2956
+							? $this->_req_data['MTP_template_variation']
2957
+							: 'default';
2958
+
2959
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2960
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2961
+							$mtpg_obj->set_template_pack_name($template_pack);
2962
+							$mtpg_obj->set_template_pack_variation($template_variation);
2963
+						}
2964
+						$success = 1;
2965
+					}
2966
+				}
2967
+			}
2968
+		}
2969
+
2970
+		// we return things differently if doing ajax
2971
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2972
+			$this->_template_args['success'] = $success;
2973
+			$this->_template_args['error'] = ! $success ? true : false;
2974
+			$this->_template_args['content'] = '';
2975
+			$this->_template_args['data'] = array(
2976
+				'grpID'        => $edit_array['GRP_ID'],
2977
+				'templateName' => $edit_array['template_name'],
2978
+			);
2979
+			if ($success) {
2980
+				EE_Error::overwrite_success();
2981
+				EE_Error::add_success(
2982
+					esc_html__(
2983
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2984
+						'event_espresso'
2985
+					)
2986
+				);
2987
+			}
2988
+
2989
+			$this->_return_json();
2990
+		}
2991
+
2992
+
2993
+		// was a test send triggered?
2994
+		if (isset($this->_req_data['test_button'])) {
2995
+			EE_Error::overwrite_success();
2996
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2997
+			$override = true;
2998
+		}
2999
+
3000
+		if (empty($query_args)) {
3001
+			$query_args = array(
3002
+				'id'      => $this->_req_data['GRP_ID'],
3003
+				'context' => $context_slug,
3004
+				'action'  => 'edit_message_template',
3005
+			);
3006
+		}
3007
+
3008
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
3009
+	}
3010
+
3011
+
3012
+	/**
3013
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3014
+	 *
3015
+	 * @param  string $context      what context being tested
3016
+	 * @param  string $messenger    messenger being tested
3017
+	 * @param  string $message_type message type being tested
3018
+	 * @throws EE_Error
3019
+	 * @throws InvalidArgumentException
3020
+	 * @throws InvalidDataTypeException
3021
+	 * @throws InvalidInterfaceException
3022
+	 */
3023
+	protected function _do_test_send($context, $messenger, $message_type)
3024
+	{
3025
+		// set things up for preview
3026
+		$this->_req_data['messenger'] = $messenger;
3027
+		$this->_req_data['message_type'] = $message_type;
3028
+		$this->_req_data['context'] = $context;
3029
+		$this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3030
+		$active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
3031
+
3032
+		// let's save any existing fields that might be required by the messenger
3033
+		if (
3034
+			isset($this->_req_data['test_settings_fld'])
3035
+			&& $active_messenger instanceof EE_messenger
3036
+			&& apply_filters(
3037
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3038
+				true,
3039
+				$this->_req_data['test_settings_fld'],
3040
+				$active_messenger
3041
+			)
3042
+		) {
3043
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3044
+		}
3045
+
3046
+		/**
3047
+		 * Use filter to add additional controls on whether message can send or not
3048
+		 */
3049
+		if (
3050
+			apply_filters(
3051
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3052
+				true,
3053
+				$context,
3054
+				$this->_req_data,
3055
+				$messenger,
3056
+				$message_type
3057
+			)
3058
+		) {
3059
+			if (EEM_Event::instance()->count() > 0) {
3060
+				$success = $this->_preview_message(true);
3061
+				if ($success) {
3062
+					EE_Error::add_success(__('Test message sent', 'event_espresso'));
3063
+				} else {
3064
+					EE_Error::add_error(
3065
+						esc_html__('The test message was not sent', 'event_espresso'),
3066
+						__FILE__,
3067
+						__FUNCTION__,
3068
+						__LINE__
3069
+					);
3070
+				}
3071
+			} else {
3072
+				$this->noEventsErrorMessage(true);
3073
+			}
3074
+		}
3075
+	}
3076
+
3077
+
3078
+	/**
3079
+	 * _generate_new_templates
3080
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3081
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3082
+	 * for the event.
3083
+	 *
3084
+	 *
3085
+	 * @param  string $messenger     the messenger we are generating templates for
3086
+	 * @param array   $message_types array of message types that the templates are generated for.
3087
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3088
+	 *                               indicate the message_template_group being used as the base.
3089
+	 *
3090
+	 * @param bool    $global
3091
+	 *
3092
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3093
+	 *                               encountering problems.
3094
+	 * @throws EE_Error
3095
+	 */
3096
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3097
+	{
3098
+
3099
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3100
+		// just don't generate any templates.
3101
+		if (empty($message_types)) {
3102
+			return true;
3103
+		}
3104
+
3105
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3106
+	}
3107
+
3108
+
3109
+	/**
3110
+	 * [_trash_or_restore_message_template]
3111
+	 *
3112
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3113
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3114
+	 *                        an individual context (FALSE).
3115
+	 * @return void
3116
+	 * @throws EE_Error
3117
+	 * @throws InvalidArgumentException
3118
+	 * @throws InvalidDataTypeException
3119
+	 * @throws InvalidInterfaceException
3120
+	 */
3121
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3122
+	{
3123
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3124
+		$MTP = EEM_Message_Template_Group::instance();
3125
+
3126
+		$success = 1;
3127
+
3128
+		// incoming GRP_IDs
3129
+		if ($all) {
3130
+			// Checkboxes
3131
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3132
+				// if array has more than one element then success message should be plural.
3133
+				// todo: what about nonce?
3134
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3135
+
3136
+				// cycle through checkboxes
3137
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3138
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3139
+					if (! $trashed_or_restored) {
3140
+						$success = 0;
3141
+					}
3142
+				}
3143
+			} else {
3144
+				// grab single GRP_ID and handle
3145
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3146
+				if (! empty($GRP_ID)) {
3147
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3148
+					if (! $trashed_or_restored) {
3149
+						$success = 0;
3150
+					}
3151
+				} else {
3152
+					$success = 0;
3153
+				}
3154
+			}
3155
+		}
3156
+
3157
+		$action_desc = $trash
3158
+			? esc_html__('moved to the trash', 'event_espresso')
3159
+			: esc_html__('restored', 'event_espresso');
3160
+
3161
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3162
+
3163
+		$item_desc = $all ? _n(
3164
+			'Message Template Group',
3165
+			'Message Template Groups',
3166
+			$success,
3167
+			'event_espresso'
3168
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3169
+
3170
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3171
+			'template',
3172
+			'templates',
3173
+			$success,
3174
+			'event_espresso'
3175
+		) : $item_desc;
3176
+
3177
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3178
+	}
3179
+
3180
+
3181
+	/**
3182
+	 * [_delete_message_template]
3183
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3184
+	 *
3185
+	 * @return void
3186
+	 * @throws EE_Error
3187
+	 * @throws InvalidArgumentException
3188
+	 * @throws InvalidDataTypeException
3189
+	 * @throws InvalidInterfaceException
3190
+	 */
3191
+	protected function _delete_message_template()
3192
+	{
3193
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3194
+
3195
+		// checkboxes
3196
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3197
+			// if array has more than one element then success message should be plural
3198
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3199
+
3200
+			// cycle through bulk action checkboxes
3201
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3202
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3203
+			}
3204
+		} else {
3205
+			// grab single grp_id and delete
3206
+			$GRP_ID = absint($this->_req_data['id']);
3207
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3208
+		}
3209
+
3210
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3211
+	}
3212
+
3213
+
3214
+	/**
3215
+	 * helper for permanently deleting a mtP group and all related message_templates
3216
+	 *
3217
+	 * @param  int  $GRP_ID        The group being deleted
3218
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3219
+	 * @return bool boolean to indicate the success of the deletes or not.
3220
+	 * @throws EE_Error
3221
+	 * @throws InvalidArgumentException
3222
+	 * @throws InvalidDataTypeException
3223
+	 * @throws InvalidInterfaceException
3224
+	 */
3225
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3226
+	{
3227
+		$success = 1;
3228
+		$MTPG = EEM_Message_Template_Group::instance();
3229
+		// first let's GET this group
3230
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3231
+		// then delete permanently all the related Message Templates
3232
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3233
+
3234
+		if ($deleted === 0) {
3235
+			$success = 0;
3236
+		}
3237
+
3238
+		// now delete permanently this particular group
3239
+
3240
+		if ($include_group && ! $MTG->delete_permanently()) {
3241
+			$success = 0;
3242
+		}
3243
+
3244
+		return $success;
3245
+	}
3246
+
3247
+
3248
+	/**
3249
+	 *    _learn_more_about_message_templates_link
3250
+	 *
3251
+	 * @access protected
3252
+	 * @return string
3253
+	 */
3254
+	protected function _learn_more_about_message_templates_link()
3255
+	{
3256
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3257
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3258
+			   . '</a>';
3259
+	}
3260
+
3261
+
3262
+	/**
3263
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3264
+	 * ajax and other routes.
3265
+	 *
3266
+	 * @return void
3267
+	 * @throws DomainException
3268
+	 */
3269
+	protected function _settings()
3270
+	{
3271
+
3272
+
3273
+		$this->_set_m_mt_settings();
3274
+
3275
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3276
+			? $this->_req_data['selected_messenger']
3277
+			: 'email';
3278
+
3279
+		// let's setup the messenger tabs
3280
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3281
+			$this->_m_mt_settings['messenger_tabs'],
3282
+			'messenger_links',
3283
+			'|',
3284
+			$selected_messenger
3285
+		);
3286
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3287
+		$this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';
3288
+
3289
+		$this->display_admin_page_with_sidebar();
3290
+	}
3291
+
3292
+
3293
+	/**
3294
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3295
+	 *
3296
+	 * @access protected
3297
+	 * @return void
3298
+	 * @throws DomainException
3299
+	 */
3300
+	protected function _set_m_mt_settings()
3301
+	{
3302
+		// first if this is already set then lets get out no need to regenerate data.
3303
+		if (! empty($this->_m_mt_settings)) {
3304
+			return;
3305
+		}
3306
+
3307
+		// get all installed messengers and message_types
3308
+		/** @type EE_messenger[] $messengers */
3309
+		$messengers = $this->_message_resource_manager->installed_messengers();
3310
+		/** @type EE_message_type[] $message_types */
3311
+		$message_types = $this->_message_resource_manager->installed_message_types();
3312
+
3313
+
3314
+		// assemble the array for the _tab_text_links helper
3315
+
3316
+		foreach ($messengers as $messenger) {
3317
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3318
+				'label' => ucwords($messenger->label['singular']),
3319
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3320
+					? 'messenger-active'
3321
+					: '',
3322
+				'href'  => $messenger->name,
3323
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3324
+				'slug'  => $messenger->name,
3325
+				'obj'   => $messenger,
3326
+			);
3327
+
3328
+
3329
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3330
+
3331
+			foreach ($message_types as $message_type) {
3332
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3333
+				// it shouldn't show in either the inactive OR active metabox.
3334
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3335
+					continue;
3336
+				}
3337
+
3338
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3339
+					$messenger->name,
3340
+					$message_type->name
3341
+				)
3342
+					? 'active'
3343
+					: 'inactive';
3344
+
3345
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3346
+					'label'    => ucwords($message_type->label['singular']),
3347
+					'class'    => 'message-type-' . $a_or_i,
3348
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3349
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3350
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3351
+					'title'    => $a_or_i === 'active'
3352
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3353
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3354
+					'content'  => $a_or_i === 'active'
3355
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3356
+						: $this->_message_type_settings_content($message_type, $messenger),
3357
+					'slug'     => $message_type->name,
3358
+					'active'   => $a_or_i === 'active',
3359
+					'obj'      => $message_type,
3360
+				);
3361
+			}
3362
+		}
3363
+	}
3364
+
3365
+
3366
+	/**
3367
+	 * This just prepares the content for the message type settings
3368
+	 *
3369
+	 * @param  EE_message_type $message_type The message type object
3370
+	 * @param  EE_messenger    $messenger    The messenger object
3371
+	 * @param  boolean         $active       Whether the message type is active or not
3372
+	 * @return string html output for the content
3373
+	 * @throws DomainException
3374
+	 */
3375
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3376
+	{
3377
+		// get message type fields
3378
+		$fields = $message_type->get_admin_settings_fields();
3379
+		$settings_template_args['template_form_fields'] = '';
3380
+
3381
+		if (! empty($fields) && $active) {
3382
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3383
+			foreach ($fields as $fldname => $fldprops) {
3384
+				$field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3385
+				$template_form_field[ $field_id ] = array(
3386
+					'name'       => 'message_type_settings[' . $fldname . ']',
3387
+					'label'      => $fldprops['label'],
3388
+					'input'      => $fldprops['field_type'],
3389
+					'type'       => $fldprops['value_type'],
3390
+					'required'   => $fldprops['required'],
3391
+					'validation' => $fldprops['validation'],
3392
+					'value'      => isset($existing_settings[ $fldname ])
3393
+						? $existing_settings[ $fldname ]
3394
+						: $fldprops['default'],
3395
+					'options'    => isset($fldprops['options'])
3396
+						? $fldprops['options']
3397
+						: array(),
3398
+					'default'    => isset($existing_settings[ $fldname ])
3399
+						? $existing_settings[ $fldname ]
3400
+						: $fldprops['default'],
3401
+					'css_class'  => 'no-drag',
3402
+					'format'     => $fldprops['format'],
3403
+				);
3404
+			}
3405
+
3406
+
3407
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3408
+				? $this->_generate_admin_form_fields(
3409
+					$template_form_field,
3410
+					'string',
3411
+					'ee_mt_activate_form'
3412
+				)
3413
+				: '';
3414
+		}
3415
+
3416
+		$settings_template_args['description'] = $message_type->description;
3417
+		// we also need some hidden fields
3418
+		$settings_template_args['hidden_fields'] = array(
3419
+			'message_type_settings[messenger]'    => array(
3420
+				'type'  => 'hidden',
3421
+				'value' => $messenger->name,
3422
+			),
3423
+			'message_type_settings[message_type]' => array(
3424
+				'type'  => 'hidden',
3425
+				'value' => $message_type->name,
3426
+			),
3427
+			'type'                                => array(
3428
+				'type'  => 'hidden',
3429
+				'value' => 'message_type',
3430
+			),
3431
+		);
3432
+
3433
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3434
+			$settings_template_args['hidden_fields'],
3435
+			'array'
3436
+		);
3437
+		$settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3438
+			? ' hidden'
3439
+			: '';
3440
+
3441
+
3442
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3443
+		$content = EEH_Template::display_template($template, $settings_template_args, true);
3444
+
3445
+		return $content;
3446
+	}
3447
+
3448
+
3449
+	/**
3450
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3451
+	 *
3452
+	 * @access protected
3453
+	 * @return void
3454
+	 * @throws DomainException
3455
+	 */
3456
+	protected function _messages_settings_metaboxes()
3457
+	{
3458
+		$this->_set_m_mt_settings();
3459
+		$m_boxes = $mt_boxes = array();
3460
+		$m_template_args = $mt_template_args = array();
3461
+
3462
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3463
+			? $this->_req_data['selected_messenger']
3464
+			: 'email';
3465
+
3466
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3467
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3468
+				$hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3469
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3470
+				// messenger meta boxes
3471
+				$active = $selected_messenger === $messenger;
3472
+				$active_mt_tabs = isset(
3473
+					$this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3474
+				)
3475
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3476
+					: '';
3477
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3478
+					esc_html__('%s Settings', 'event_espresso'),
3479
+					$tab_array['label']
3480
+				);
3481
+				$m_template_args[ $messenger . '_a_box' ] = array(
3482
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3483
+					'inactive_message_types' => isset(
3484
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3485
+					)
3486
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3487
+						: '',
3488
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3489
+					'hidden'                 => $active ? '' : ' hidden',
3490
+					'hide_on_message'        => $hide_on_message,
3491
+					'messenger'              => $messenger,
3492
+					'active'                 => $active,
3493
+				);
3494
+				// message type meta boxes
3495
+				// (which is really just the inactive container for each messenger
3496
+				// showing inactive message types for that messenger)
3497
+				$mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3498
+				$mt_template_args[ $messenger . '_i_box' ] = array(
3499
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3500
+					'inactive_message_types' => isset(
3501
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3502
+					)
3503
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3504
+						: '',
3505
+					'hidden'                 => $active ? '' : ' hidden',
3506
+					'hide_on_message'        => $hide_on_message,
3507
+					'hide_off_message'       => $hide_off_message,
3508
+					'messenger'              => $messenger,
3509
+					'active'                 => $active,
3510
+				);
3511
+			}
3512
+		}
3513
+
3514
+
3515
+		// register messenger metaboxes
3516
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3517
+		foreach ($m_boxes as $box => $label) {
3518
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3519
+			$msgr = str_replace('_a_box', '', $box);
3520
+			add_meta_box(
3521
+				'espresso_' . $msgr . '_settings',
3522
+				$label,
3523
+				function ($post, $metabox) {
3524
+					echo EEH_Template::display_template(
3525
+						$metabox["args"]["template_path"],
3526
+						$metabox["args"]["template_args"],
3527
+						true
3528
+					);
3529
+				},
3530
+				$this->_current_screen->id,
3531
+				'normal',
3532
+				'high',
3533
+				$callback_args
3534
+			);
3535
+		}
3536
+
3537
+		// register message type metaboxes
3538
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3539
+		foreach ($mt_boxes as $box => $label) {
3540
+			$callback_args = array(
3541
+				'template_path' => $mt_template_path,
3542
+				'template_args' => $mt_template_args[ $box ],
3543
+			);
3544
+			$mt = str_replace('_i_box', '', $box);
3545
+			add_meta_box(
3546
+				'espresso_' . $mt . '_inactive_mts',
3547
+				$label,
3548
+				function ($post, $metabox) {
3549
+					echo EEH_Template::display_template(
3550
+						$metabox["args"]["template_path"],
3551
+						$metabox["args"]["template_args"],
3552
+						true
3553
+					);
3554
+				},
3555
+				$this->_current_screen->id,
3556
+				'side',
3557
+				'high',
3558
+				$callback_args
3559
+			);
3560
+		}
3561
+
3562
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3563
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3564
+		if (is_main_site()) {
3565
+			add_meta_box(
3566
+				'espresso_global_message_settings',
3567
+				esc_html__('Global Message Settings', 'event_espresso'),
3568
+				array($this, 'global_messages_settings_metabox_content'),
3569
+				$this->_current_screen->id,
3570
+				'normal',
3571
+				'low',
3572
+				array()
3573
+			);
3574
+		}
3575
+	}
3576
+
3577
+
3578
+	/**
3579
+	 *  This generates the content for the global messages settings metabox.
3580
+	 *
3581
+	 * @return string
3582
+	 * @throws EE_Error
3583
+	 * @throws InvalidArgumentException
3584
+	 * @throws ReflectionException
3585
+	 * @throws InvalidDataTypeException
3586
+	 * @throws InvalidInterfaceException
3587
+	 */
3588
+	public function global_messages_settings_metabox_content()
3589
+	{
3590
+		$form = $this->_generate_global_settings_form();
3591
+		echo $form->form_open(
3592
+			$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3593
+			'POST'
3594
+		)
3595
+			 . $form->get_html()
3596
+			 . $form->form_close();
3597
+	}
3598
+
3599
+
3600
+	/**
3601
+	 * This generates and returns the form object for the global messages settings.
3602
+	 *
3603
+	 * @return EE_Form_Section_Proper
3604
+	 * @throws EE_Error
3605
+	 * @throws InvalidArgumentException
3606
+	 * @throws ReflectionException
3607
+	 * @throws InvalidDataTypeException
3608
+	 * @throws InvalidInterfaceException
3609
+	 */
3610
+	protected function _generate_global_settings_form()
3611
+	{
3612
+		EE_Registry::instance()->load_helper('HTML');
3613
+		/** @var EE_Network_Core_Config $network_config */
3614
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3615
+
3616
+		return new EE_Form_Section_Proper(
3617
+			array(
3618
+				'name'            => 'global_messages_settings',
3619
+				'html_id'         => 'global_messages_settings',
3620
+				'html_class'      => 'form-table',
3621
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3622
+				'subsections'     => apply_filters(
3623
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3624
+					array(
3625
+						'do_messages_on_same_request' => new EE_Select_Input(
3626
+							array(
3627
+								true  => esc_html__("On the same request", "event_espresso"),
3628
+								false => esc_html__("On a separate request", "event_espresso"),
3629
+							),
3630
+							array(
3631
+								'default'         => $network_config->do_messages_on_same_request,
3632
+								'html_label_text' => esc_html__(
3633
+									'Generate and send all messages:',
3634
+									'event_espresso'
3635
+								),
3636
+								'html_help_text'  => esc_html__(
3637
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3638
+									'event_espresso'
3639
+								),
3640
+							)
3641
+						),
3642
+						'delete_threshold'            => new EE_Select_Input(
3643
+							array(
3644
+								0  => esc_html__('Forever', 'event_espresso'),
3645
+								3  => esc_html__('3 Months', 'event_espresso'),
3646
+								6  => esc_html__('6 Months', 'event_espresso'),
3647
+								9  => esc_html__('9 Months', 'event_espresso'),
3648
+								12 => esc_html__('12 Months', 'event_espresso'),
3649
+								24 => esc_html__('24 Months', 'event_espresso'),
3650
+								36 => esc_html__('36 Months', 'event_espresso'),
3651
+							),
3652
+							array(
3653
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3654
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3655
+								'html_help_text'  => esc_html__(
3656
+									'You can control how long a record of processed messages is kept via this option.',
3657
+									'event_espresso'
3658
+								),
3659
+							)
3660
+						),
3661
+						'update_settings'             => new EE_Submit_Input(
3662
+							array(
3663
+								'default'         => esc_html__('Update', 'event_espresso'),
3664
+								'html_label_text' => '&nbsp',
3665
+							)
3666
+						),
3667
+					)
3668
+				),
3669
+			)
3670
+		);
3671
+	}
3672
+
3673
+
3674
+	/**
3675
+	 * This handles updating the global settings set on the admin page.
3676
+	 *
3677
+	 * @throws EE_Error
3678
+	 * @throws InvalidDataTypeException
3679
+	 * @throws InvalidInterfaceException
3680
+	 * @throws InvalidArgumentException
3681
+	 * @throws ReflectionException
3682
+	 */
3683
+	protected function _update_global_settings()
3684
+	{
3685
+		/** @var EE_Network_Core_Config $network_config */
3686
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3687
+		$messages_config = EE_Registry::instance()->CFG->messages;
3688
+		$form = $this->_generate_global_settings_form();
3689
+		if ($form->was_submitted()) {
3690
+			$form->receive_form_submission();
3691
+			if ($form->is_valid()) {
3692
+				$valid_data = $form->valid_data();
3693
+				foreach ($valid_data as $property => $value) {
3694
+					$setter = 'set_' . $property;
3695
+					if (method_exists($network_config, $setter)) {
3696
+						$network_config->{$setter}($value);
3697
+					} elseif (
3698
+						property_exists($network_config, $property)
3699
+						&& $network_config->{$property} !== $value
3700
+					) {
3701
+						$network_config->{$property} = $value;
3702
+					} elseif (
3703
+						property_exists($messages_config, $property)
3704
+						&& $messages_config->{$property} !== $value
3705
+					) {
3706
+						$messages_config->{$property} = $value;
3707
+					}
3708
+				}
3709
+				// only update if the form submission was valid!
3710
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3711
+				EE_Registry::instance()->CFG->update_espresso_config();
3712
+				EE_Error::overwrite_success();
3713
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3714
+			}
3715
+		}
3716
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3717
+	}
3718
+
3719
+
3720
+	/**
3721
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3722
+	 *
3723
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3724
+	 * @return string html formatted tabs
3725
+	 * @throws DomainException
3726
+	 */
3727
+	protected function _get_mt_tabs($tab_array)
3728
+	{
3729
+		$tab_array = (array) $tab_array;
3730
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3731
+		$tabs = '';
3732
+
3733
+		foreach ($tab_array as $tab) {
3734
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3735
+		}
3736
+
3737
+		return $tabs;
3738
+	}
3739
+
3740
+
3741
+	/**
3742
+	 * This prepares the content of the messenger meta box admin settings
3743
+	 *
3744
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3745
+	 * @return string html formatted content
3746
+	 * @throws DomainException
3747
+	 */
3748
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3749
+	{
3750
+
3751
+		$fields = $messenger->get_admin_settings_fields();
3752
+		$settings_template_args['template_form_fields'] = '';
3753
+
3754
+		// is $messenger active?
3755
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3756
+
3757
+
3758
+		if (! empty($fields)) {
3759
+			$existing_settings = $messenger->get_existing_admin_settings();
3760
+
3761
+			foreach ($fields as $fldname => $fldprops) {
3762
+				$field_id = $messenger->name . '-' . $fldname;
3763
+				$template_form_field[ $field_id ] = array(
3764
+					'name'       => 'messenger_settings[' . $field_id . ']',
3765
+					'label'      => $fldprops['label'],
3766
+					'input'      => $fldprops['field_type'],
3767
+					'type'       => $fldprops['value_type'],
3768
+					'required'   => $fldprops['required'],
3769
+					'validation' => $fldprops['validation'],
3770
+					'value'      => isset($existing_settings[ $field_id ])
3771
+						? $existing_settings[ $field_id ]
3772
+						: $fldprops['default'],
3773
+					'css_class'  => '',
3774
+					'format'     => $fldprops['format'],
3775
+				);
3776
+			}
3777
+
3778
+
3779
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3780
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3781
+				: '';
3782
+		}
3783
+
3784
+		// we also need some hidden fields
3785
+		$settings_template_args['hidden_fields'] = array(
3786
+			'messenger_settings[messenger]' => array(
3787
+				'type'  => 'hidden',
3788
+				'value' => $messenger->name,
3789
+			),
3790
+			'type'                          => array(
3791
+				'type'  => 'hidden',
3792
+				'value' => 'messenger',
3793
+			),
3794
+		);
3795
+
3796
+		// make sure any active message types that are existing are included in the hidden fields
3797
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3798
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3799
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3800
+					'type'  => 'hidden',
3801
+					'value' => $mt,
3802
+				);
3803
+			}
3804
+		}
3805
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3806
+			$settings_template_args['hidden_fields'],
3807
+			'array'
3808
+		);
3809
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3810
+
3811
+		$settings_template_args['messenger'] = $messenger->name;
3812
+		$settings_template_args['description'] = $messenger->description;
3813
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3814
+
3815
+
3816
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3817
+			$messenger->name
3818
+		)
3819
+			? $settings_template_args['show_hide_edit_form']
3820
+			: ' hidden';
3821
+
3822
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3823
+			? ' hidden'
3824
+			: $settings_template_args['show_hide_edit_form'];
3825
+
3826
+
3827
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3828
+		$settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3829
+		$settings_template_args['on_off_status'] = $active ? true : false;
3830
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3831
+		$content = EEH_Template::display_template(
3832
+			$template,
3833
+			$settings_template_args,
3834
+			true
3835
+		);
3836
+
3837
+		return $content;
3838
+	}
3839
+
3840
+
3841
+	/**
3842
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3843
+	 *
3844
+	 * @throws DomainException
3845
+	 * @throws EE_Error
3846
+	 * @throws InvalidDataTypeException
3847
+	 * @throws InvalidInterfaceException
3848
+	 * @throws InvalidArgumentException
3849
+	 * @throws ReflectionException
3850
+	 */
3851
+	public function activate_messenger_toggle()
3852
+	{
3853
+		$success = true;
3854
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3855
+		// let's check that we have required data
3856
+		if (! isset($this->_req_data['messenger'])) {
3857
+			EE_Error::add_error(
3858
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3859
+				__FILE__,
3860
+				__FUNCTION__,
3861
+				__LINE__
3862
+			);
3863
+			$success = false;
3864
+		}
3865
+
3866
+		// do a nonce check here since we're not arriving via a normal route
3867
+		$nonce = isset($this->_req_data['activate_nonce'])
3868
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3869
+			: '';
3870
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3871
+
3872
+		$this->_verify_nonce($nonce, $nonce_ref);
3873
+
3874
+
3875
+		if (! isset($this->_req_data['status'])) {
3876
+			EE_Error::add_error(
3877
+				esc_html__(
3878
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3879
+					'event_espresso'
3880
+				),
3881
+				__FILE__,
3882
+				__FUNCTION__,
3883
+				__LINE__
3884
+			);
3885
+			$success = false;
3886
+		}
3887
+
3888
+		// do check to verify we have a valid status.
3889
+		$status = $this->_req_data['status'];
3890
+
3891
+		if ($status !== 'off' && $status !== 'on') {
3892
+			EE_Error::add_error(
3893
+				sprintf(
3894
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3895
+					$this->_req_data['status']
3896
+				),
3897
+				__FILE__,
3898
+				__FUNCTION__,
3899
+				__LINE__
3900
+			);
3901
+			$success = false;
3902
+		}
3903
+
3904
+		if ($success) {
3905
+			// made it here?  Stop dawdling then!!
3906
+			$success = $status === 'off'
3907
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3908
+				: $this->_activate_messenger($this->_req_data['messenger']);
3909
+		}
3910
+
3911
+		$this->_template_args['success'] = $success;
3912
+
3913
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
3914
+		$this->_return_json();
3915
+	}
3916
+
3917
+
3918
+	/**
3919
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3920
+	 *
3921
+	 * @throws DomainException
3922
+	 * @throws EE_Error
3923
+	 * @throws ReflectionException
3924
+	 * @throws InvalidDataTypeException
3925
+	 * @throws InvalidInterfaceException
3926
+	 * @throws InvalidArgumentException
3927
+	 */
3928
+	public function activate_mt_toggle()
3929
+	{
3930
+		$success = true;
3931
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3932
+
3933
+		// let's make sure we have the necessary data
3934
+		if (! isset($this->_req_data['message_type'])) {
3935
+			EE_Error::add_error(
3936
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3937
+				__FILE__,
3938
+				__FUNCTION__,
3939
+				__LINE__
3940
+			);
3941
+			$success = false;
3942
+		}
3943
+
3944
+		if (! isset($this->_req_data['messenger'])) {
3945
+			EE_Error::add_error(
3946
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3947
+				__FILE__,
3948
+				__FUNCTION__,
3949
+				__LINE__
3950
+			);
3951
+			$success = false;
3952
+		}
3953
+
3954
+		if (! isset($this->_req_data['status'])) {
3955
+			EE_Error::add_error(
3956
+				esc_html__(
3957
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3958
+					'event_espresso'
3959
+				),
3960
+				__FILE__,
3961
+				__FUNCTION__,
3962
+				__LINE__
3963
+			);
3964
+			$success = false;
3965
+		}
3966
+
3967
+
3968
+		// do check to verify we have a valid status.
3969
+		$status = $this->_req_data['status'];
3970
+
3971
+		if ($status !== 'activate' && $status !== 'deactivate') {
3972
+			EE_Error::add_error(
3973
+				sprintf(
3974
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3975
+					$this->_req_data['status']
3976
+				),
3977
+				__FILE__,
3978
+				__FUNCTION__,
3979
+				__LINE__
3980
+			);
3981
+			$success = false;
3982
+		}
3983
+
3984
+
3985
+		// do a nonce check here since we're not arriving via a normal route
3986
+		$nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3987
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3988
+
3989
+		$this->_verify_nonce($nonce, $nonce_ref);
3990
+
3991
+		if ($success) {
3992
+			// made it here? um, what are you waiting for then?
3993
+			$success = $status === 'deactivate'
3994
+				? $this->_deactivate_message_type_for_messenger(
3995
+					$this->_req_data['messenger'],
3996
+					$this->_req_data['message_type']
3997
+				)
3998
+				: $this->_activate_message_type_for_messenger(
3999
+					$this->_req_data['messenger'],
4000
+					$this->_req_data['message_type']
4001
+				);
4002
+		}
4003
+
4004
+		$this->_template_args['success'] = $success;
4005
+		$this->_return_json();
4006
+	}
4007
+
4008
+
4009
+	/**
4010
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4011
+	 *
4012
+	 * @param string $messenger_name The name of the messenger being activated
4013
+	 * @return bool
4014
+	 * @throws DomainException
4015
+	 * @throws EE_Error
4016
+	 * @throws InvalidArgumentException
4017
+	 * @throws ReflectionException
4018
+	 * @throws InvalidDataTypeException
4019
+	 * @throws InvalidInterfaceException
4020
+	 */
4021
+	protected function _activate_messenger($messenger_name)
4022
+	{
4023
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4024
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4025
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4026
+			? $active_messenger->get_default_message_types()
4027
+			: array();
4028
+
4029
+		// ensure is active
4030
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
4031
+
4032
+		// set response_data for reload
4033
+		foreach ($message_types_to_activate as $message_type_name) {
4034
+			/** @var EE_message_type $message_type */
4035
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4036
+			if (
4037
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4038
+					$messenger_name,
4039
+					$message_type_name
4040
+				)
4041
+				&& $message_type instanceof EE_message_type
4042
+			) {
4043
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4044
+				if ($message_type->get_admin_settings_fields()) {
4045
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4046
+				}
4047
+			}
4048
+		}
4049
+
4050
+		// add success message for activating messenger
4051
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4052
+	}
4053
+
4054
+
4055
+	/**
4056
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4057
+	 *
4058
+	 * @param string $messenger_name The name of the messenger being activated
4059
+	 * @return bool
4060
+	 * @throws DomainException
4061
+	 * @throws EE_Error
4062
+	 * @throws InvalidArgumentException
4063
+	 * @throws ReflectionException
4064
+	 * @throws InvalidDataTypeException
4065
+	 * @throws InvalidInterfaceException
4066
+	 */
4067
+	protected function _deactivate_messenger($messenger_name)
4068
+	{
4069
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4070
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4071
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4072
+
4073
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4074
+	}
4075
+
4076
+
4077
+	/**
4078
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4079
+	 *
4080
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4081
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4082
+	 * @return bool
4083
+	 * @throws DomainException
4084
+	 * @throws EE_Error
4085
+	 * @throws InvalidArgumentException
4086
+	 * @throws ReflectionException
4087
+	 * @throws InvalidDataTypeException
4088
+	 * @throws InvalidInterfaceException
4089
+	 */
4090
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4091
+	{
4092
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4093
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4094
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4095
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4096
+
4097
+		// ensure is active
4098
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
4099
+
4100
+		// set response for load
4101
+		if (
4102
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4103
+				$messenger_name,
4104
+				$message_type_name
4105
+			)
4106
+		) {
4107
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4108
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4109
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4110
+			}
4111
+		}
4112
+
4113
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4114
+			$active_messenger,
4115
+			$message_type_to_activate
4116
+		);
4117
+	}
4118
+
4119
+
4120
+	/**
4121
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4122
+	 *
4123
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4124
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4125
+	 * @return bool
4126
+	 * @throws DomainException
4127
+	 * @throws EE_Error
4128
+	 * @throws InvalidArgumentException
4129
+	 * @throws ReflectionException
4130
+	 * @throws InvalidDataTypeException
4131
+	 * @throws InvalidInterfaceException
4132
+	 */
4133
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4134
+	{
4135
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4136
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4137
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4138
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4139
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4140
+
4141
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4142
+			$active_messenger,
4143
+			$message_type_to_deactivate
4144
+		);
4145
+	}
4146
+
4147
+
4148
+	/**
4149
+	 * This just initializes the defaults for activating messenger and message type responses.
4150
+	 */
4151
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4152
+	{
4153
+		$this->_template_args['data']['active_mts'] = array();
4154
+		$this->_template_args['data']['mt_reload'] = array();
4155
+	}
4156
+
4157
+
4158
+	/**
4159
+	 * Setup appropriate response for activating a messenger and/or message types
4160
+	 *
4161
+	 * @param EE_messenger         $messenger
4162
+	 * @param EE_message_type|null $message_type
4163
+	 * @return bool
4164
+	 * @throws DomainException
4165
+	 * @throws EE_Error
4166
+	 * @throws InvalidArgumentException
4167
+	 * @throws ReflectionException
4168
+	 * @throws InvalidDataTypeException
4169
+	 * @throws InvalidInterfaceException
4170
+	 */
4171
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4172
+		$messenger,
4173
+		EE_Message_Type $message_type = null
4174
+	) {
4175
+		// if $messenger isn't a valid messenger object then get out.
4176
+		if (! $messenger instanceof EE_Messenger) {
4177
+			EE_Error::add_error(
4178
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4179
+				__FILE__,
4180
+				__FUNCTION__,
4181
+				__LINE__
4182
+			);
4183
+
4184
+			return false;
4185
+		}
4186
+		// activated
4187
+		if ($this->_template_args['data']['active_mts']) {
4188
+			EE_Error::overwrite_success();
4189
+			// activated a message type with the messenger
4190
+			if ($message_type instanceof EE_message_type) {
4191
+				EE_Error::add_success(
4192
+					sprintf(
4193
+						esc_html__(
4194
+							'%s message type has been successfully activated with the %s messenger',
4195
+							'event_espresso'
4196
+						),
4197
+						ucwords($message_type->label['singular']),
4198
+						ucwords($messenger->label['singular'])
4199
+					)
4200
+				);
4201
+
4202
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4203
+				if ($message_type->name === 'invoice') {
4204
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4205
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4206
+					if ($pm instanceof EE_Payment_Method) {
4207
+						EE_Error::add_attention(
4208
+							esc_html__(
4209
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4210
+								'event_espresso'
4211
+							)
4212
+						);
4213
+					}
4214
+				}
4215
+				// just toggles the entire messenger
4216
+			} else {
4217
+				EE_Error::add_success(
4218
+					sprintf(
4219
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4220
+						ucwords($messenger->label['singular'])
4221
+					)
4222
+				);
4223
+			}
4224
+
4225
+			return true;
4226
+
4227
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4228
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4229
+			// in which case we just give a success message for the messenger being successfully activated.
4230
+		} else {
4231
+			if (! $messenger->get_default_message_types()) {
4232
+				// messenger doesn't have any default message types so still a success.
4233
+				EE_Error::add_success(
4234
+					sprintf(
4235
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4236
+						ucwords($messenger->label['singular'])
4237
+					)
4238
+				);
4239
+
4240
+				return true;
4241
+			} else {
4242
+				EE_Error::add_error(
4243
+					$message_type instanceof EE_message_type
4244
+						? sprintf(
4245
+							esc_html__(
4246
+								'%s message type was not successfully activated with the %s messenger',
4247
+								'event_espresso'
4248
+							),
4249
+							ucwords($message_type->label['singular']),
4250
+							ucwords($messenger->label['singular'])
4251
+						)
4252
+						: sprintf(
4253
+							esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4254
+							ucwords($messenger->label['singular'])
4255
+						),
4256
+					__FILE__,
4257
+					__FUNCTION__,
4258
+					__LINE__
4259
+				);
4260
+
4261
+				return false;
4262
+			}
4263
+		}
4264
+	}
4265
+
4266
+
4267
+	/**
4268
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4269
+	 *
4270
+	 * @param EE_messenger         $messenger
4271
+	 * @param EE_message_type|null $message_type
4272
+	 * @return bool
4273
+	 * @throws DomainException
4274
+	 * @throws EE_Error
4275
+	 * @throws InvalidArgumentException
4276
+	 * @throws ReflectionException
4277
+	 * @throws InvalidDataTypeException
4278
+	 * @throws InvalidInterfaceException
4279
+	 */
4280
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4281
+		$messenger,
4282
+		EE_message_type $message_type = null
4283
+	) {
4284
+		EE_Error::overwrite_success();
4285
+
4286
+		// if $messenger isn't a valid messenger object then get out.
4287
+		if (! $messenger instanceof EE_Messenger) {
4288
+			EE_Error::add_error(
4289
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4290
+				__FILE__,
4291
+				__FUNCTION__,
4292
+				__LINE__
4293
+			);
4294
+
4295
+			return false;
4296
+		}
4297
+
4298
+		if ($message_type instanceof EE_message_type) {
4299
+			$message_type_name = $message_type->name;
4300
+			EE_Error::add_success(
4301
+				sprintf(
4302
+					esc_html__(
4303
+						'%s message type has been successfully deactivated for the %s messenger.',
4304
+						'event_espresso'
4305
+					),
4306
+					ucwords($message_type->label['singular']),
4307
+					ucwords($messenger->label['singular'])
4308
+				)
4309
+			);
4310
+		} else {
4311
+			$message_type_name = '';
4312
+			EE_Error::add_success(
4313
+				sprintf(
4314
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4315
+					ucwords($messenger->label['singular'])
4316
+				)
4317
+			);
4318
+		}
4319
+
4320
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4321
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4322
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4323
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4324
+			if ($count_updated > 0) {
4325
+				$msg = $message_type_name === 'invoice'
4326
+					? esc_html__(
4327
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4328
+						'event_espresso'
4329
+					)
4330
+					: esc_html__(
4331
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4332
+						'event_espresso'
4333
+					);
4334
+				EE_Error::add_attention($msg);
4335
+			}
4336
+		}
4337
+
4338
+		return true;
4339
+	}
4340
+
4341
+
4342
+	/**
4343
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4344
+	 *
4345
+	 * @throws DomainException
4346
+	 */
4347
+	public function update_mt_form()
4348
+	{
4349
+		if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4350
+			EE_Error::add_error(
4351
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4352
+				__FILE__,
4353
+				__FUNCTION__,
4354
+				__LINE__
4355
+			);
4356
+			$this->_return_json();
4357
+		}
4358
+
4359
+		$message_types = $this->get_installed_message_types();
4360
+
4361
+		$message_type = $message_types[ $this->_req_data['message_type'] ];
4362
+		$messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4363
+
4364
+		$content = $this->_message_type_settings_content(
4365
+			$message_type,
4366
+			$messenger,
4367
+			true
4368
+		);
4369
+		$this->_template_args['success'] = true;
4370
+		$this->_template_args['content'] = $content;
4371
+		$this->_return_json();
4372
+	}
4373
+
4374
+
4375
+	/**
4376
+	 * this handles saving the settings for a messenger or message type
4377
+	 *
4378
+	 */
4379
+	public function save_settings()
4380
+	{
4381
+		if (! isset($this->_req_data['type'])) {
4382
+			EE_Error::add_error(
4383
+				esc_html__(
4384
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4385
+					'event_espresso'
4386
+				),
4387
+				__FILE__,
4388
+				__FUNCTION__,
4389
+				__LINE__
4390
+			);
4391
+			$this->_template_args['error'] = true;
4392
+			$this->_return_json();
4393
+		}
4394
+
4395
+
4396
+		if ($this->_req_data['type'] === 'messenger') {
4397
+			// this should be an array.
4398
+			$settings = $this->_req_data['messenger_settings'];
4399
+			$messenger = $settings['messenger'];
4400
+			// let's setup the settings data
4401
+			foreach ($settings as $key => $value) {
4402
+				switch ($key) {
4403
+					case 'messenger':
4404
+						unset($settings['messenger']);
4405
+						break;
4406
+					case 'message_types':
4407
+						unset($settings['message_types']);
4408
+						break;
4409
+					default:
4410
+						$settings[ $key ] = $value;
4411
+						break;
4412
+				}
4413
+			}
4414
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4415
+		} elseif ($this->_req_data['type'] === 'message_type') {
4416
+			$settings = $this->_req_data['message_type_settings'];
4417
+			$messenger = $settings['messenger'];
4418
+			$message_type = $settings['message_type'];
4419
+
4420
+			foreach ($settings as $key => $value) {
4421
+				switch ($key) {
4422
+					case 'messenger':
4423
+						unset($settings['messenger']);
4424
+						break;
4425
+					case 'message_type':
4426
+						unset($settings['message_type']);
4427
+						break;
4428
+					default:
4429
+						$settings[ $key ] = $value;
4430
+						break;
4431
+				}
4432
+			}
4433
+
4434
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4435
+		}
4436
+
4437
+		// okay we should have the data all setup.  Now we just update!
4438
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4439
+
4440
+		if ($success) {
4441
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4442
+		} else {
4443
+			EE_Error::add_error(
4444
+				esc_html__(
4445
+					'Settings did not get updated',
4446
+					'event_espresso'
4447
+				),
4448
+				__FILE__,
4449
+				__FUNCTION__,
4450
+				__LINE__
4451
+			);
4452
+		}
4453
+
4454
+		$this->_template_args['success'] = $success;
4455
+		$this->_return_json();
4456
+	}
4457
+
4458
+
4459
+
4460
+
4461
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4462
+
4463
+
4464
+	/**
4465
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4466
+	 * However, this does not send immediately, it just queues for sending.
4467
+	 *
4468
+	 * @since 4.9.0
4469
+	 * @throws EE_Error
4470
+	 * @throws InvalidDataTypeException
4471
+	 * @throws InvalidInterfaceException
4472
+	 * @throws InvalidArgumentException
4473
+	 * @throws ReflectionException
4474
+	 */
4475
+	protected function _generate_now()
4476
+	{
4477
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4478
+		$this->_redirect_after_action(false, '', '', array(), true);
4479
+	}
4480
+
4481
+
4482
+	/**
4483
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4484
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4485
+	 *
4486
+	 * @since 4.9.0
4487
+	 * @throws EE_Error
4488
+	 * @throws InvalidDataTypeException
4489
+	 * @throws InvalidInterfaceException
4490
+	 * @throws InvalidArgumentException
4491
+	 * @throws ReflectionException
4492
+	 */
4493
+	protected function _generate_and_send_now()
4494
+	{
4495
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4496
+		$this->_redirect_after_action(false, '', '', array(), true);
4497
+	}
4498
+
4499
+
4500
+	/**
4501
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4502
+	 *
4503
+	 * @since 4.9.0
4504
+	 * @throws EE_Error
4505
+	 * @throws InvalidDataTypeException
4506
+	 * @throws InvalidInterfaceException
4507
+	 * @throws InvalidArgumentException
4508
+	 * @throws ReflectionException
4509
+	 */
4510
+	protected function _queue_for_resending()
4511
+	{
4512
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4513
+		$this->_redirect_after_action(false, '', '', array(), true);
4514
+	}
4515
+
4516
+
4517
+	/**
4518
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4519
+	 *
4520
+	 * @since 4.9.0
4521
+	 * @throws EE_Error
4522
+	 * @throws InvalidDataTypeException
4523
+	 * @throws InvalidInterfaceException
4524
+	 * @throws InvalidArgumentException
4525
+	 * @throws ReflectionException
4526
+	 */
4527
+	protected function _send_now()
4528
+	{
4529
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4530
+		$this->_redirect_after_action(false, '', '', array(), true);
4531
+	}
4532
+
4533
+
4534
+	/**
4535
+	 * Deletes EE_messages for IDs in the request.
4536
+	 *
4537
+	 * @since 4.9.0
4538
+	 * @throws EE_Error
4539
+	 * @throws InvalidDataTypeException
4540
+	 * @throws InvalidInterfaceException
4541
+	 * @throws InvalidArgumentException
4542
+	 */
4543
+	protected function _delete_ee_messages()
4544
+	{
4545
+		$msg_ids = $this->_get_msg_ids_from_request();
4546
+		$deleted_count = 0;
4547
+		foreach ($msg_ids as $msg_id) {
4548
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4549
+				$deleted_count++;
4550
+			}
4551
+		}
4552
+		if ($deleted_count) {
4553
+			EE_Error::add_success(
4554
+				esc_html(
4555
+					_n(
4556
+						'Message successfully deleted',
4557
+						'Messages successfully deleted',
4558
+						$deleted_count,
4559
+						'event_espresso'
4560
+					)
4561
+				)
4562
+			);
4563
+			$this->_redirect_after_action(
4564
+				false,
4565
+				'',
4566
+				'',
4567
+				array(),
4568
+				true
4569
+			);
4570
+		} else {
4571
+			EE_Error::add_error(
4572
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4573
+				__FILE__,
4574
+				__FUNCTION__,
4575
+				__LINE__
4576
+			);
4577
+			$this->_redirect_after_action(false, '', '', array(), true);
4578
+		}
4579
+	}
4580
+
4581
+
4582
+	/**
4583
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4584
+	 *
4585
+	 * @since 4.9.0
4586
+	 * @return array
4587
+	 */
4588
+	protected function _get_msg_ids_from_request()
4589
+	{
4590
+		if (! isset($this->_req_data['MSG_ID'])) {
4591
+			return array();
4592
+		}
4593
+
4594
+		return is_array($this->_req_data['MSG_ID'])
4595
+			? array_keys($this->_req_data['MSG_ID'])
4596
+			: array($this->_req_data['MSG_ID']);
4597
+	}
4598 4598
 }
Please login to merge, or discard this patch.
Spacing   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
         $i = 1;
142 142
         foreach ($active_messengers as $active_messenger) {
143 143
             if ($active_messenger instanceof EE_Message) {
144
-                $m_values[ $i ]['id'] = $active_messenger->messenger();
145
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
144
+                $m_values[$i]['id'] = $active_messenger->messenger();
145
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
146 146
                 $i++;
147 147
             }
148 148
         }
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
         $i = 1;
179 179
         foreach ($active_messages as $active_message) {
180 180
             if ($active_message instanceof EE_Message) {
181
-                $mt_values[ $i ]['id'] = $active_message->message_type();
182
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
181
+                $mt_values[$i]['id'] = $active_message->message_type();
182
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
183 183
                 $i++;
184 184
             }
185 185
         }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
                 if ($message_type instanceof EE_message_type) {
219 219
                     $message_type_contexts = $message_type->get_contexts();
220 220
                     foreach ($message_type_contexts as $context => $context_details) {
221
-                        $contexts[ $context ] = $context_details['label'];
221
+                        $contexts[$context] = $context_details['label'];
222 222
                     }
223 223
                 }
224 224
             }
@@ -712,53 +712,53 @@  discard block
 block discarded – undo
712 712
 
713 713
     public function messages_help_tab()
714 714
     {
715
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
716 716
     }
717 717
 
718 718
 
719 719
     public function messengers_help_tab()
720 720
     {
721
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
722 722
     }
723 723
 
724 724
 
725 725
     public function message_types_help_tab()
726 726
     {
727
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
728 728
     }
729 729
 
730 730
 
731 731
     public function messages_overview_help_tab()
732 732
     {
733
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
734 734
     }
735 735
 
736 736
 
737 737
     public function message_templates_help_tab()
738 738
     {
739
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
740 740
     }
741 741
 
742 742
 
743 743
     public function edit_message_template_help_tab()
744 744
     {
745
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
746 746
                         . esc_attr__('Editor Title', 'event_espresso')
747 747
                         . '" />';
748
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
749 749
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
750 750
                         . '" />';
751
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
752 752
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
753 753
                         . '" />';
754
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
755 755
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
756 756
                         . '" />';
757
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
758 758
                         . esc_attr__('Publish Metabox', 'event_espresso')
759 759
                         . '" />';
760 760
         EEH_Template::display_template(
761
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
762 762
             $args
763 763
         );
764 764
     }
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
         $this->_set_shortcodes();
770 770
         $args['shortcodes'] = $this->_shortcodes;
771 771
         EEH_Template::display_template(
772
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
773 773
             $args
774 774
         );
775 775
     }
@@ -777,16 +777,16 @@  discard block
 block discarded – undo
777 777
 
778 778
     public function preview_message_help_tab()
779 779
     {
780
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
781 781
     }
782 782
 
783 783
 
784 784
     public function settings_help_tab()
785 785
     {
786
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
787
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
788
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
789
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
786
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
787
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
788
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
789
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
790 790
         $args['img3'] = '<div class="switch">'
791 791
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
792 792
                         . ' type="checkbox" checked="checked">'
@@ -797,25 +797,25 @@  discard block
 block discarded – undo
797 797
                         . ' type="checkbox">'
798 798
                         . '<label for="ee-on-off-toggle-on"></label>'
799 799
                         . '</div>';
800
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
801 801
     }
802 802
 
803 803
 
804 804
     public function load_scripts_styles()
805 805
     {
806
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
807 807
         wp_enqueue_style('espresso_ee_msg');
808 808
 
809 809
         wp_register_script(
810 810
             'ee-messages-settings',
811
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
811
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
812 812
             array('jquery-ui-droppable', 'ee-serialize-full-array'),
813 813
             EVENT_ESPRESSO_VERSION,
814 814
             true
815 815
         );
816 816
         wp_register_script(
817 817
             'ee-msg-list-table-js',
818
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
818
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
819 819
             array('ee-dialog'),
820 820
             EVENT_ESPRESSO_VERSION
821 821
         );
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 
874 874
         wp_register_script(
875 875
             'ee_msgs_edit_js',
876
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
876
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
877 877
             array('jquery'),
878 878
             EVENT_ESPRESSO_VERSION
879 879
         );
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
     {
918 918
         wp_register_style(
919 919
             'ee-message-settings',
920
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
920
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
921 921
             array(),
922 922
             EVENT_ESPRESSO_VERSION
923 923
         );
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
             }
1004 1004
             $status_bulk_actions = $common_bulk_actions;
1005 1005
             // unset bulk actions not applying to status
1006
-            if (! empty($status_bulk_actions)) {
1006
+            if ( ! empty($status_bulk_actions)) {
1007 1007
                 switch ($status) {
1008 1008
                     case EEM_Message::status_idle:
1009 1009
                     case EEM_Message::status_resend:
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
                 continue;
1033 1033
             }
1034 1034
 
1035
-            $this->_views[ strtolower($status) ] = array(
1035
+            $this->_views[strtolower($status)] = array(
1036 1036
                 'slug'        => strtolower($status),
1037 1037
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1038 1038
                 'count'       => 0,
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
             if ($action_item === 'see_notifications_for') {
1072 1072
                 continue;
1073 1073
             }
1074
-            $action_items[ $action_item ] = array(
1074
+            $action_items[$action_item] = array(
1075 1075
                 'class' => $action_details['css_class'],
1076 1076
                 'desc'  => $action_details['label'],
1077 1077
             );
@@ -1080,37 +1080,37 @@  discard block
 block discarded – undo
1080 1080
         /** @type array $status_items status legend setup */
1081 1081
         $status_items = array(
1082 1082
             'incomplete_status'          => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1083
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1084 1084
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1085 1085
             ),
1086 1086
             'idle_status'                => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1087
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1088 1088
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1089 1089
             ),
1090 1090
             'resend_status'              => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1091
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1092 1092
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1093 1093
             ),
1094 1094
             'messenger_executing_status' => array(
1095
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1095
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1096 1096
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1097 1097
             ),
1098 1098
             'sent_status'                => array(
1099
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1099
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1100 1100
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1101 1101
             ),
1102 1102
             'retry_status'               => array(
1103
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1103
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1104 1104
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1105 1105
             ),
1106 1106
             'failed_status'              => array(
1107
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1107
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1108 1108
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1109 1109
             ),
1110 1110
         );
1111 1111
         if (EEM_Message::debug()) {
1112 1112
             $status_items['debug_only_status'] = array(
1113
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1113
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1114 1114
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1115 1115
             );
1116 1116
         }
@@ -1122,11 +1122,11 @@  discard block
 block discarded – undo
1122 1122
     protected function _custom_mtps_preview()
1123 1123
     {
1124 1124
         $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1125
-        $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1126
-                                               . ' alt="' . esc_attr__(
1125
+        $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1126
+                                               . ' alt="'.esc_attr__(
1127 1127
                                                    'Preview Custom Message Templates screenshot',
1128 1128
                                                    'event_espresso'
1129
-                                               ) . '" />';
1129
+                                               ).'" />';
1130 1130
         $this->_template_args['preview_text'] = '<strong>'
1131 1131
                                                 . esc_html__(
1132 1132
                                                     'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
         $installed = array();
1207 1207
 
1208 1208
         foreach ($installed_message_types as $message_type) {
1209
-            $installed[ $message_type->name ] = $message_type;
1209
+            $installed[$message_type->name] = $message_type;
1210 1210
         }
1211 1211
 
1212 1212
         return $installed;
@@ -1355,7 +1355,7 @@  discard block
 block discarded – undo
1355 1355
         // we need to assemble the title from Various details
1356 1356
         $context_label = sprintf(
1357 1357
             esc_html__('(%s %s)', 'event_espresso'),
1358
-            $c_config[ $context ]['label'],
1358
+            $c_config[$context]['label'],
1359 1359
             ucwords($c_label['label'])
1360 1360
         );
1361 1361
 
@@ -1377,7 +1377,7 @@  discard block
 block discarded – undo
1377 1377
             $message_template_group->message_type()
1378 1378
         );
1379 1379
 
1380
-        if (! $template_field_structure) {
1380
+        if ( ! $template_field_structure) {
1381 1381
             $template_field_structure = false;
1382 1382
             $template_fields = esc_html__(
1383 1383
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1391,21 +1391,21 @@  discard block
 block discarded – undo
1391 1391
 
1392 1392
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1393 1393
         // will get handled in the "extra" array.
1394
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1395
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1396
-                unset($template_field_structure[ $context ][ $reference_field ]);
1394
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1395
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1396
+                unset($template_field_structure[$context][$reference_field]);
1397 1397
             }
1398 1398
         }
1399 1399
 
1400 1400
         // let's loop through the template_field_structure and actually assemble the input fields!
1401
-        if (! empty($template_field_structure)) {
1402
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1401
+        if ( ! empty($template_field_structure)) {
1402
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1403 1403
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1404 1404
                 // the extra array and reset them.
1405 1405
                 if ($template_field === 'extra') {
1406 1406
                     $this->_template_args['is_extra_fields'] = true;
1407 1407
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1408
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1408
+                        $message_template = $message_templates[$context][$reference_field];
1409 1409
                         $content = $message_template instanceof EE_Message_Template
1410 1410
                             ? $message_template->get('MTP_content')
1411 1411
                             : '';
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
                             $continue = false;
1415 1415
                             if (isset($extra_array['shortcodes_required'])) {
1416 1416
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1417
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1417
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1418 1418
                                         $continue = true;
1419 1419
                                     }
1420 1420
                                 }
@@ -1427,57 +1427,57 @@  discard block
 block discarded – undo
1427 1427
                                         . '-'
1428 1428
                                         . $extra_field
1429 1429
                                         . '-content';
1430
-                            $template_form_fields[ $field_id ] = $extra_array;
1431
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1430
+                            $template_form_fields[$field_id] = $extra_array;
1431
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1432 1432
                                                                          . $reference_field
1433 1433
                                                                          . '][content]['
1434
-                                                                         . $extra_field . ']';
1434
+                                                                         . $extra_field.']';
1435 1435
                             $css_class = isset($extra_array['css_class'])
1436 1436
                                 ? $extra_array['css_class']
1437 1437
                                 : '';
1438 1438
 
1439
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1439
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1440 1440
                                                                               && in_array($extra_field, $v_fields, true)
1441 1441
                                                                               &&
1442 1442
                                                                               (
1443
-                                                                                  is_array($validators[ $extra_field ])
1444
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1443
+                                                                                  is_array($validators[$extra_field])
1444
+                                                                                  && isset($validators[$extra_field]['msg'])
1445 1445
                                                                               )
1446
-                                ? 'validate-error ' . $css_class
1446
+                                ? 'validate-error '.$css_class
1447 1447
                                 : $css_class;
1448 1448
 
1449
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1450
-                                                                          && isset($content[ $extra_field ])
1451
-                                ? $content[ $extra_field ]
1449
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1450
+                                                                          && isset($content[$extra_field])
1451
+                                ? $content[$extra_field]
1452 1452
                                 : '';
1453 1453
 
1454 1454
                             // do we have a validation error?  if we do then let's use that value instead
1455
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1456
-                                ? $validators[ $extra_field ]['value']
1457
-                                : $template_form_fields[ $field_id ]['value'];
1455
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1456
+                                ? $validators[$extra_field]['value']
1457
+                                : $template_form_fields[$field_id]['value'];
1458 1458
 
1459 1459
 
1460
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1460
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1461 1461
 
1462 1462
                             // shortcode selector
1463 1463
                             $field_name_to_use = $extra_field === 'main'
1464 1464
                                 ? 'content'
1465 1465
                                 : $extra_field;
1466
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1466
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1467 1467
                                 $field_name_to_use,
1468 1468
                                 $field_id
1469 1469
                             );
1470 1470
 
1471 1471
                             if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1472 1472
                                 // we want to decode the entities
1473
-                                $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1473
+                                $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value'];
1474 1474
                             }/**/
1475 1475
                         }
1476
-                        $templatefield_MTP_id = $reference_field . '-MTP_ID';
1477
-                        $templatefield_templatename_id = $reference_field . '-name';
1476
+                        $templatefield_MTP_id = $reference_field.'-MTP_ID';
1477
+                        $templatefield_templatename_id = $reference_field.'-name';
1478 1478
 
1479
-                        $template_form_fields[ $templatefield_MTP_id ] = array(
1480
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1479
+                        $template_form_fields[$templatefield_MTP_id] = array(
1480
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1481 1481
                             'label'      => null,
1482 1482
                             'input'      => 'hidden',
1483 1483
                             'type'       => 'int',
@@ -1489,8 +1489,8 @@  discard block
 block discarded – undo
1489 1489
                             'db-col'     => 'MTP_ID',
1490 1490
                         );
1491 1491
 
1492
-                        $template_form_fields[ $templatefield_templatename_id ] = array(
1493
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1492
+                        $template_form_fields[$templatefield_templatename_id] = array(
1493
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1494 1494
                             'label'      => null,
1495 1495
                             'input'      => 'hidden',
1496 1496
                             'type'       => 'string',
@@ -1504,36 +1504,36 @@  discard block
 block discarded – undo
1504 1504
                     }
1505 1505
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1506 1506
                 } else {
1507
-                    $field_id = $template_field . '-content';
1508
-                    $template_form_fields[ $field_id ] = $field_setup_array;
1509
-                    $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1510
-                    $message_template = isset($message_templates[ $context ][ $template_field ])
1511
-                        ? $message_templates[ $context ][ $template_field ]
1507
+                    $field_id = $template_field.'-content';
1508
+                    $template_form_fields[$field_id] = $field_setup_array;
1509
+                    $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]';
1510
+                    $message_template = isset($message_templates[$context][$template_field])
1511
+                        ? $message_templates[$context][$template_field]
1512 1512
                         : null;
1513
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1514
-                                                                  && is_array($message_templates[ $context ])
1513
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1514
+                                                                  && is_array($message_templates[$context])
1515 1515
                                                                   && $message_template instanceof EE_Message_Template
1516 1516
                         ? $message_template->get('MTP_content')
1517 1517
                         : '';
1518 1518
 
1519 1519
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1520
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1521
-                        ? $validators[ $template_field ]['value']
1522
-                        : $template_form_fields[ $field_id ]['value'];
1520
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1521
+                        ? $validators[$template_field]['value']
1522
+                        : $template_form_fields[$field_id]['value'];
1523 1523
 
1524 1524
 
1525
-                    $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1525
+                    $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1526 1526
                     $css_class = isset($field_setup_array['css_class'])
1527 1527
                         ? $field_setup_array['css_class']
1528 1528
                         : '';
1529
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1529
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1530 1530
                                                                       && in_array($template_field, $v_fields, true)
1531
-                                                                      && isset($validators[ $template_field ]['msg'])
1532
-                        ? 'validate-error ' . $css_class
1531
+                                                                      && isset($validators[$template_field]['msg'])
1532
+                        ? 'validate-error '.$css_class
1533 1533
                         : $css_class;
1534 1534
 
1535 1535
                     // shortcode selector
1536
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1536
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1537 1537
                         $template_field,
1538 1538
                         $field_id
1539 1539
                     );
@@ -1541,12 +1541,12 @@  discard block
 block discarded – undo
1541 1541
 
1542 1542
                 // k took care of content field(s) now let's take care of others.
1543 1543
 
1544
-                $templatefield_MTP_id = $template_field . '-MTP_ID';
1545
-                $templatefield_field_templatename_id = $template_field . '-name';
1544
+                $templatefield_MTP_id = $template_field.'-MTP_ID';
1545
+                $templatefield_field_templatename_id = $template_field.'-name';
1546 1546
 
1547 1547
                 // foreach template field there are actually two form fields created
1548
-                $template_form_fields[ $templatefield_MTP_id ] = array(
1549
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1548
+                $template_form_fields[$templatefield_MTP_id] = array(
1549
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1550 1550
                     'label'      => null,
1551 1551
                     'input'      => 'hidden',
1552 1552
                     'type'       => 'int',
@@ -1558,8 +1558,8 @@  discard block
 block discarded – undo
1558 1558
                     'db-col'     => 'MTP_ID',
1559 1559
                 );
1560 1560
 
1561
-                $template_form_fields[ $templatefield_field_templatename_id ] = array(
1562
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1561
+                $template_form_fields[$templatefield_field_templatename_id] = array(
1562
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1563 1563
                     'label'      => null,
1564 1564
                     'input'      => 'hidden',
1565 1565
                     'type'       => 'string',
@@ -1702,10 +1702,10 @@  discard block
 block discarded – undo
1702 1702
                 'value' => $GRP_ID,
1703 1703
             );
1704 1704
             $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1705
-                'name'  => $action . '_nonce',
1705
+                'name'  => $action.'_nonce',
1706 1706
                 'input' => 'hidden',
1707 1707
                 'type'  => 'string',
1708
-                'value' => wp_create_nonce($action . '_nonce'),
1708
+                'value' => wp_create_nonce($action.'_nonce'),
1709 1709
             );
1710 1710
 
1711 1711
             if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
             ),
1747 1747
             $this->_admin_base_url
1748 1748
         );
1749
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1749
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1750 1750
                           . esc_html__('Preview', 'event_espresso')
1751 1751
                           . '</a>';
1752 1752
 
@@ -1784,7 +1784,7 @@  discard block
 block discarded – undo
1784 1784
 
1785 1785
         $this->_template_path = $this->_template_args['GRP_ID']
1786 1786
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1787
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1787
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1788 1788
 
1789 1789
         // send along EE_Message_Template_Group object for further template use.
1790 1790
         $this->_template_args['MTP'] = $message_template_group;
@@ -1839,7 +1839,7 @@  discard block
 block discarded – undo
1839 1839
     ) {
1840 1840
         $template_args = array(
1841 1841
             'context'                   => $context,
1842
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1842
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1843 1843
             'is_active'                 => $message_template_group->is_context_active($context),
1844 1844
             'on_off_action'             => $message_template_group->is_context_active($context)
1845 1845
                 ? 'context-off'
@@ -1848,7 +1848,7 @@  discard block
 block discarded – undo
1848 1848
             'message_template_group_id' => $message_template_group->ID(),
1849 1849
         );
1850 1850
         return EEH_Template::display_template(
1851
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1851
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1852 1852
             $template_args,
1853 1853
             true
1854 1854
         );
@@ -1888,7 +1888,7 @@  discard block
 block discarded – undo
1888 1888
         $nonce = isset($this->_req_data['toggle_context_nonce'])
1889 1889
             ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1890 1890
             : '';
1891
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1891
+        $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce';
1892 1892
         $this->_verify_nonce($nonce, $nonce_ref);
1893 1893
         $status = $this->_req_data['status'];
1894 1894
         if ($status !== 'off' && $status !== 'on') {
@@ -1906,7 +1906,7 @@  discard block
 block discarded – undo
1906 1906
         $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1907 1907
             $this->_req_data['message_template_group_id']
1908 1908
         );
1909
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1909
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1910 1910
             EE_Error::add_error(
1911 1911
                 sprintf(
1912 1912
                     esc_html__(
@@ -2035,7 +2035,7 @@  discard block
 block discarded – undo
2035 2035
         $templates = array();
2036 2036
         $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2037 2037
         // we need to make sure we've got the info we need.
2038
-        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2038
+        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2039 2039
             EE_Error::add_error(
2040 2040
                 esc_html__(
2041 2041
                     'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
@@ -2077,7 +2077,7 @@  discard block
 block discarded – undo
2077 2077
         }
2078 2078
 
2079 2079
         // any error messages?
2080
-        if (! $success) {
2080
+        if ( ! $success) {
2081 2081
             EE_Error::add_error(
2082 2082
                 esc_html__(
2083 2083
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2189,7 +2189,7 @@  discard block
 block discarded – undo
2189 2189
         $preview_title = sprintf(
2190 2190
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2191 2191
             $active_messenger_label,
2192
-            ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2192
+            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2193 2193
         );
2194 2194
         if (empty($preview)) {
2195 2195
             $this->noEventsErrorMessage();
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
         // setup display of preview.
2198 2198
         $this->_admin_page_title = $preview_title;
2199 2199
         $this->_template_args['admin_page_title'] = $preview_title;
2200
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2200
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2201 2201
         $this->_template_args['data']['force_json'] = true;
2202 2202
 
2203 2203
         return '';
@@ -2311,10 +2311,10 @@  discard block
 block discarded – undo
2311 2311
             // only include template packs that support this messenger and message type!
2312 2312
             $supports = $tp->get_supports();
2313 2313
             if (
2314
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2314
+                ! isset($supports[$this->_message_template_group->messenger()])
2315 2315
                 || ! in_array(
2316 2316
                     $this->_message_template_group->message_type(),
2317
-                    $supports[ $this->_message_template_group->messenger() ],
2317
+                    $supports[$this->_message_template_group->messenger()],
2318 2318
                     true
2319 2319
                 )
2320 2320
             ) {
@@ -2367,7 +2367,7 @@  discard block
 block discarded – undo
2367 2367
         $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2368 2368
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2369 2369
 
2370
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2370
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2371 2371
 
2372 2372
         EEH_Template::display_template($template, $template_args);
2373 2373
     }
@@ -2393,10 +2393,10 @@  discard block
 block discarded – undo
2393 2393
         // first we need to see if there are any fields
2394 2394
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2395 2395
 
2396
-        if (! empty($fields)) {
2396
+        if ( ! empty($fields)) {
2397 2397
             // yup there be fields
2398 2398
             foreach ($fields as $field => $config) {
2399
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2399
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2400 2400
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2401 2401
                 $default = isset($config['default']) ? $config['default'] : '';
2402 2402
                 $default = isset($config['value']) ? $config['value'] : $default;
@@ -2404,22 +2404,22 @@  discard block
 block discarded – undo
2404 2404
                 // if type is hidden and the value is empty
2405 2405
                 // something may have gone wrong so let's correct with the defaults
2406 2406
                 $fix = $config['input'] === 'hidden'
2407
-                       && isset($existing[ $field ])
2408
-                       && empty($existing[ $field ])
2407
+                       && isset($existing[$field])
2408
+                       && empty($existing[$field])
2409 2409
                     ? $default
2410 2410
                     : '';
2411
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2412
-                    ? $existing[ $field ]
2411
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2412
+                    ? $existing[$field]
2413 2413
                     : $fix;
2414 2414
 
2415
-                $template_form_fields[ $field_id ] = array(
2416
-                    'name'       => 'test_settings_fld[' . $field . ']',
2415
+                $template_form_fields[$field_id] = array(
2416
+                    'name'       => 'test_settings_fld['.$field.']',
2417 2417
                     'label'      => $config['label'],
2418 2418
                     'input'      => $config['input'],
2419 2419
                     'type'       => $config['type'],
2420 2420
                     'required'   => $config['required'],
2421 2421
                     'validation' => $config['validation'],
2422
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2422
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2423 2423
                     'css_class'  => $config['css_class'],
2424 2424
                     'options'    => isset($config['options']) ? $config['options'] : array(),
2425 2425
                     'default'    => $default,
@@ -2434,7 +2434,7 @@  discard block
 block discarded – undo
2434 2434
 
2435 2435
         $test_settings_html = '';
2436 2436
         // print out $test_settings_fields
2437
-        if (! empty($test_settings_fields)) {
2437
+        if ( ! empty($test_settings_fields)) {
2438 2438
             echo $test_settings_fields;
2439 2439
             $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2440 2440
             $test_settings_html .= 'name="test_button" value="';
@@ -2481,7 +2481,7 @@  discard block
 block discarded – undo
2481 2481
         );
2482 2482
 
2483 2483
         return EEH_Template::display_template(
2484
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2484
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2485 2485
             $template_args,
2486 2486
             true
2487 2487
         );
@@ -2506,7 +2506,7 @@  discard block
 block discarded – undo
2506 2506
         // $messenger = $this->_message_template_group->messenger_obj();
2507 2507
         // now let's set the content depending on the status of the shortcodes array
2508 2508
         if (empty($shortcodes)) {
2509
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2509
+            $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2510 2510
             echo $content;
2511 2511
         } else {
2512 2512
             // $alt = 0;
@@ -2544,7 +2544,7 @@  discard block
 block discarded – undo
2544 2544
     {
2545 2545
 
2546 2546
         // no need to run this if the property is already set
2547
-        if (! empty($this->_shortcodes)) {
2547
+        if ( ! empty($this->_shortcodes)) {
2548 2548
             return;
2549 2549
         }
2550 2550
 
@@ -2598,7 +2598,7 @@  discard block
 block discarded – undo
2598 2598
     protected function _set_message_template_group()
2599 2599
     {
2600 2600
 
2601
-        if (! empty($this->_message_template_group)) {
2601
+        if ( ! empty($this->_message_template_group)) {
2602 2602
             return;
2603 2603
         } //get out if this is already set.
2604 2604
 
@@ -2645,7 +2645,7 @@  discard block
 block discarded – undo
2645 2645
                     <?php
2646 2646
                 }
2647 2647
                 // setup nonce_url
2648
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2648
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2649 2649
                 ?>
2650 2650
                 <select name="context">
2651 2651
                     <?php
@@ -2655,7 +2655,7 @@  discard block
 block discarded – undo
2655 2655
                             $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2656 2656
                             ?>
2657 2657
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2658
-                                <?php echo $context_details[ $context ]['label']; ?>
2658
+                                <?php echo $context_details[$context]['label']; ?>
2659 2659
                             </option>
2660 2660
                         <?php endforeach;
2661 2661
                     endif; ?>
@@ -2685,22 +2685,22 @@  discard block
 block discarded – undo
2685 2685
      */
2686 2686
     protected function _set_message_template_column_values($index)
2687 2687
     {
2688
-        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2689
-            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2690
-                $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2688
+        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2689
+            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2690
+                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2691 2691
             }
2692 2692
         }
2693 2693
 
2694 2694
 
2695 2695
         $set_column_values = array(
2696
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2696
+            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2697 2697
             'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2698 2698
             'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2699 2699
             'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2700 2700
             'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2701
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2701
+            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2702 2702
             'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2703
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2703
+            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2704 2704
             'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2705 2705
                 ? absint($this->_req_data['MTP_is_global'])
2706 2706
                 : 0,
@@ -2747,7 +2747,7 @@  discard block
 block discarded – undo
2747 2747
         $context = ucwords(str_replace('_', ' ', $context_slug));
2748 2748
 
2749 2749
         $item_desc = $messenger_label && $message_type_label
2750
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2750
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2751 2751
             : '';
2752 2752
         $item_desc .= 'Message Template';
2753 2753
         $query_args = array();
@@ -2778,7 +2778,7 @@  discard block
 block discarded – undo
2778 2778
 
2779 2779
 
2780 2780
             // run update for each template field in displayed context
2781
-            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2781
+            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2782 2782
                 EE_Error::add_error(
2783 2783
                     esc_html__(
2784 2784
                         'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
@@ -2840,10 +2840,10 @@  discard block
 block discarded – undo
2840 2840
                         $set_column_values = $this->_set_message_template_column_values($template_field);
2841 2841
 
2842 2842
                         $where_cols_n_values = array(
2843
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2843
+                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'],
2844 2844
                         );
2845 2845
                         // if they aren't allowed to use all JS, restrict them to just posty-y tags
2846
-                        if (! current_user_can('unfiltered_html')) {
2846
+                        if ( ! current_user_can('unfiltered_html')) {
2847 2847
                             if (is_array($set_column_values['MTP_content'])) {
2848 2848
                                 foreach ($set_column_values['MTP_content'] as $key => $value) {
2849 2849
                                     // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
@@ -2851,7 +2851,7 @@  discard block
 block discarded – undo
2851 2851
                                     // appear invalid.) But currently the models expect slashed data, so after wp_kses
2852 2852
                                     // runs we need to re-slash the data. Sheesh. See
2853 2853
                                     // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2854
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2854
+                                    $set_column_values['MTP_content'][$key] = addslashes(
2855 2855
                                         wp_kses(
2856 2856
                                             stripslashes($value),
2857 2857
                                             wp_kses_allowed_html('post')
@@ -2887,14 +2887,14 @@  discard block
 block discarded – undo
2887 2887
                             }
2888 2888
                         } else {
2889 2889
                             // only do this logic if we don't have a MTP_ID for this field
2890
-                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2890
+                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2891 2891
                                 // this has already been through the template field validator and sanitized, so it will be
2892 2892
                                 // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2893 2893
                                 // message template field in a messenger/message type and existing users don't have the
2894 2894
                                 // default setup for it.
2895 2895
                                 // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2896 2896
                                 $updated = $MTP->insert($message_template_fields);
2897
-                                if (! $updated || is_wp_error($updated)) {
2897
+                                if ( ! $updated || is_wp_error($updated)) {
2898 2898
                                     EE_Error::add_error(
2899 2899
                                         sprintf(
2900 2900
                                             esc_html__('%s field could not be updated.', 'event_espresso'),
@@ -3128,7 +3128,7 @@  discard block
 block discarded – undo
3128 3128
         // incoming GRP_IDs
3129 3129
         if ($all) {
3130 3130
             // Checkboxes
3131
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3131
+            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3132 3132
                 // if array has more than one element then success message should be plural.
3133 3133
                 // todo: what about nonce?
3134 3134
                 $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
@@ -3136,16 +3136,16 @@  discard block
 block discarded – undo
3136 3136
                 // cycle through checkboxes
3137 3137
                 while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3138 3138
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3139
-                    if (! $trashed_or_restored) {
3139
+                    if ( ! $trashed_or_restored) {
3140 3140
                         $success = 0;
3141 3141
                     }
3142 3142
                 }
3143 3143
             } else {
3144 3144
                 // grab single GRP_ID and handle
3145 3145
                 $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3146
-                if (! empty($GRP_ID)) {
3146
+                if ( ! empty($GRP_ID)) {
3147 3147
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3148
-                    if (! $trashed_or_restored) {
3148
+                    if ( ! $trashed_or_restored) {
3149 3149
                         $success = 0;
3150 3150
                     }
3151 3151
                 } else {
@@ -3193,7 +3193,7 @@  discard block
 block discarded – undo
3193 3193
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3194 3194
 
3195 3195
         // checkboxes
3196
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3196
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3197 3197
             // if array has more than one element then success message should be plural
3198 3198
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3199 3199
 
@@ -3300,7 +3300,7 @@  discard block
 block discarded – undo
3300 3300
     protected function _set_m_mt_settings()
3301 3301
     {
3302 3302
         // first if this is already set then lets get out no need to regenerate data.
3303
-        if (! empty($this->_m_mt_settings)) {
3303
+        if ( ! empty($this->_m_mt_settings)) {
3304 3304
             return;
3305 3305
         }
3306 3306
 
@@ -3314,7 +3314,7 @@  discard block
 block discarded – undo
3314 3314
         // assemble the array for the _tab_text_links helper
3315 3315
 
3316 3316
         foreach ($messengers as $messenger) {
3317
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3317
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3318 3318
                 'label' => ucwords($messenger->label['singular']),
3319 3319
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3320 3320
                     ? 'messenger-active'
@@ -3331,7 +3331,7 @@  discard block
 block discarded – undo
3331 3331
             foreach ($message_types as $message_type) {
3332 3332
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3333 3333
                 // it shouldn't show in either the inactive OR active metabox.
3334
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3334
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3335 3335
                     continue;
3336 3336
                 }
3337 3337
 
@@ -3342,12 +3342,12 @@  discard block
 block discarded – undo
3342 3342
                     ? 'active'
3343 3343
                     : 'inactive';
3344 3344
 
3345
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3345
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3346 3346
                     'label'    => ucwords($message_type->label['singular']),
3347
-                    'class'    => 'message-type-' . $a_or_i,
3348
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3349
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3350
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3347
+                    'class'    => 'message-type-'.$a_or_i,
3348
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3349
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3350
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3351 3351
                     'title'    => $a_or_i === 'active'
3352 3352
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3353 3353
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3378,25 +3378,25 @@  discard block
 block discarded – undo
3378 3378
         $fields = $message_type->get_admin_settings_fields();
3379 3379
         $settings_template_args['template_form_fields'] = '';
3380 3380
 
3381
-        if (! empty($fields) && $active) {
3381
+        if ( ! empty($fields) && $active) {
3382 3382
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3383 3383
             foreach ($fields as $fldname => $fldprops) {
3384
-                $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3385
-                $template_form_field[ $field_id ] = array(
3386
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3384
+                $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3385
+                $template_form_field[$field_id] = array(
3386
+                    'name'       => 'message_type_settings['.$fldname.']',
3387 3387
                     'label'      => $fldprops['label'],
3388 3388
                     'input'      => $fldprops['field_type'],
3389 3389
                     'type'       => $fldprops['value_type'],
3390 3390
                     'required'   => $fldprops['required'],
3391 3391
                     'validation' => $fldprops['validation'],
3392
-                    'value'      => isset($existing_settings[ $fldname ])
3393
-                        ? $existing_settings[ $fldname ]
3392
+                    'value'      => isset($existing_settings[$fldname])
3393
+                        ? $existing_settings[$fldname]
3394 3394
                         : $fldprops['default'],
3395 3395
                     'options'    => isset($fldprops['options'])
3396 3396
                         ? $fldprops['options']
3397 3397
                         : array(),
3398
-                    'default'    => isset($existing_settings[ $fldname ])
3399
-                        ? $existing_settings[ $fldname ]
3398
+                    'default'    => isset($existing_settings[$fldname])
3399
+                        ? $existing_settings[$fldname]
3400 3400
                         : $fldprops['default'],
3401 3401
                     'css_class'  => 'no-drag',
3402 3402
                     'format'     => $fldprops['format'],
@@ -3439,7 +3439,7 @@  discard block
 block discarded – undo
3439 3439
             : '';
3440 3440
 
3441 3441
 
3442
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3442
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3443 3443
         $content = EEH_Template::display_template($template, $settings_template_args, true);
3444 3444
 
3445 3445
         return $content;
@@ -3470,20 +3470,20 @@  discard block
 block discarded – undo
3470 3470
                 // messenger meta boxes
3471 3471
                 $active = $selected_messenger === $messenger;
3472 3472
                 $active_mt_tabs = isset(
3473
-                    $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3473
+                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3474 3474
                 )
3475
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3475
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3476 3476
                     : '';
3477
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3477
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3478 3478
                     esc_html__('%s Settings', 'event_espresso'),
3479 3479
                     $tab_array['label']
3480 3480
                 );
3481
-                $m_template_args[ $messenger . '_a_box' ] = array(
3481
+                $m_template_args[$messenger.'_a_box'] = array(
3482 3482
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3483 3483
                     'inactive_message_types' => isset(
3484
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3484
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3485 3485
                     )
3486
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3486
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3487 3487
                         : '',
3488 3488
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3489 3489
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3494,13 +3494,13 @@  discard block
 block discarded – undo
3494 3494
                 // message type meta boxes
3495 3495
                 // (which is really just the inactive container for each messenger
3496 3496
                 // showing inactive message types for that messenger)
3497
-                $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3498
-                $mt_template_args[ $messenger . '_i_box' ] = array(
3497
+                $mt_boxes[$messenger.'_i_box'] = esc_html__('Inactive Message Types', 'event_espresso');
3498
+                $mt_template_args[$messenger.'_i_box'] = array(
3499 3499
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3500 3500
                     'inactive_message_types' => isset(
3501
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3501
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3502 3502
                     )
3503
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3503
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3504 3504
                         : '',
3505 3505
                     'hidden'                 => $active ? '' : ' hidden',
3506 3506
                     'hide_on_message'        => $hide_on_message,
@@ -3513,14 +3513,14 @@  discard block
 block discarded – undo
3513 3513
 
3514 3514
 
3515 3515
         // register messenger metaboxes
3516
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3516
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3517 3517
         foreach ($m_boxes as $box => $label) {
3518
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3518
+            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3519 3519
             $msgr = str_replace('_a_box', '', $box);
3520 3520
             add_meta_box(
3521
-                'espresso_' . $msgr . '_settings',
3521
+                'espresso_'.$msgr.'_settings',
3522 3522
                 $label,
3523
-                function ($post, $metabox) {
3523
+                function($post, $metabox) {
3524 3524
                     echo EEH_Template::display_template(
3525 3525
                         $metabox["args"]["template_path"],
3526 3526
                         $metabox["args"]["template_args"],
@@ -3535,17 +3535,17 @@  discard block
 block discarded – undo
3535 3535
         }
3536 3536
 
3537 3537
         // register message type metaboxes
3538
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3538
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3539 3539
         foreach ($mt_boxes as $box => $label) {
3540 3540
             $callback_args = array(
3541 3541
                 'template_path' => $mt_template_path,
3542
-                'template_args' => $mt_template_args[ $box ],
3542
+                'template_args' => $mt_template_args[$box],
3543 3543
             );
3544 3544
             $mt = str_replace('_i_box', '', $box);
3545 3545
             add_meta_box(
3546
-                'espresso_' . $mt . '_inactive_mts',
3546
+                'espresso_'.$mt.'_inactive_mts',
3547 3547
                 $label,
3548
-                function ($post, $metabox) {
3548
+                function($post, $metabox) {
3549 3549
                     echo EEH_Template::display_template(
3550 3550
                         $metabox["args"]["template_path"],
3551 3551
                         $metabox["args"]["template_args"],
@@ -3691,7 +3691,7 @@  discard block
 block discarded – undo
3691 3691
             if ($form->is_valid()) {
3692 3692
                 $valid_data = $form->valid_data();
3693 3693
                 foreach ($valid_data as $property => $value) {
3694
-                    $setter = 'set_' . $property;
3694
+                    $setter = 'set_'.$property;
3695 3695
                     if (method_exists($network_config, $setter)) {
3696 3696
                         $network_config->{$setter}($value);
3697 3697
                     } elseif (
@@ -3727,7 +3727,7 @@  discard block
 block discarded – undo
3727 3727
     protected function _get_mt_tabs($tab_array)
3728 3728
     {
3729 3729
         $tab_array = (array) $tab_array;
3730
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3730
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3731 3731
         $tabs = '';
3732 3732
 
3733 3733
         foreach ($tab_array as $tab) {
@@ -3755,20 +3755,20 @@  discard block
 block discarded – undo
3755 3755
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3756 3756
 
3757 3757
 
3758
-        if (! empty($fields)) {
3758
+        if ( ! empty($fields)) {
3759 3759
             $existing_settings = $messenger->get_existing_admin_settings();
3760 3760
 
3761 3761
             foreach ($fields as $fldname => $fldprops) {
3762
-                $field_id = $messenger->name . '-' . $fldname;
3763
-                $template_form_field[ $field_id ] = array(
3764
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3762
+                $field_id = $messenger->name.'-'.$fldname;
3763
+                $template_form_field[$field_id] = array(
3764
+                    'name'       => 'messenger_settings['.$field_id.']',
3765 3765
                     'label'      => $fldprops['label'],
3766 3766
                     'input'      => $fldprops['field_type'],
3767 3767
                     'type'       => $fldprops['value_type'],
3768 3768
                     'required'   => $fldprops['required'],
3769 3769
                     'validation' => $fldprops['validation'],
3770
-                    'value'      => isset($existing_settings[ $field_id ])
3771
-                        ? $existing_settings[ $field_id ]
3770
+                    'value'      => isset($existing_settings[$field_id])
3771
+                        ? $existing_settings[$field_id]
3772 3772
                         : $fldprops['default'],
3773 3773
                     'css_class'  => '',
3774 3774
                     'format'     => $fldprops['format'],
@@ -3794,9 +3794,9 @@  discard block
 block discarded – undo
3794 3794
         );
3795 3795
 
3796 3796
         // make sure any active message types that are existing are included in the hidden fields
3797
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3798
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3799
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3797
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3798
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3799
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(
3800 3800
                     'type'  => 'hidden',
3801 3801
                     'value' => $mt,
3802 3802
                 );
@@ -3825,9 +3825,9 @@  discard block
 block discarded – undo
3825 3825
 
3826 3826
 
3827 3827
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3828
-        $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3828
+        $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3829 3829
         $settings_template_args['on_off_status'] = $active ? true : false;
3830
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3830
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3831 3831
         $content = EEH_Template::display_template(
3832 3832
             $template,
3833 3833
             $settings_template_args,
@@ -3853,7 +3853,7 @@  discard block
 block discarded – undo
3853 3853
         $success = true;
3854 3854
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3855 3855
         // let's check that we have required data
3856
-        if (! isset($this->_req_data['messenger'])) {
3856
+        if ( ! isset($this->_req_data['messenger'])) {
3857 3857
             EE_Error::add_error(
3858 3858
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3859 3859
                 __FILE__,
@@ -3867,12 +3867,12 @@  discard block
 block discarded – undo
3867 3867
         $nonce = isset($this->_req_data['activate_nonce'])
3868 3868
             ? sanitize_text_field($this->_req_data['activate_nonce'])
3869 3869
             : '';
3870
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3870
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3871 3871
 
3872 3872
         $this->_verify_nonce($nonce, $nonce_ref);
3873 3873
 
3874 3874
 
3875
-        if (! isset($this->_req_data['status'])) {
3875
+        if ( ! isset($this->_req_data['status'])) {
3876 3876
             EE_Error::add_error(
3877 3877
                 esc_html__(
3878 3878
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3931,7 +3931,7 @@  discard block
 block discarded – undo
3931 3931
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3932 3932
 
3933 3933
         // let's make sure we have the necessary data
3934
-        if (! isset($this->_req_data['message_type'])) {
3934
+        if ( ! isset($this->_req_data['message_type'])) {
3935 3935
             EE_Error::add_error(
3936 3936
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3937 3937
                 __FILE__,
@@ -3941,7 +3941,7 @@  discard block
 block discarded – undo
3941 3941
             $success = false;
3942 3942
         }
3943 3943
 
3944
-        if (! isset($this->_req_data['messenger'])) {
3944
+        if ( ! isset($this->_req_data['messenger'])) {
3945 3945
             EE_Error::add_error(
3946 3946
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3947 3947
                 __FILE__,
@@ -3951,7 +3951,7 @@  discard block
 block discarded – undo
3951 3951
             $success = false;
3952 3952
         }
3953 3953
 
3954
-        if (! isset($this->_req_data['status'])) {
3954
+        if ( ! isset($this->_req_data['status'])) {
3955 3955
             EE_Error::add_error(
3956 3956
                 esc_html__(
3957 3957
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3984,7 +3984,7 @@  discard block
 block discarded – undo
3984 3984
 
3985 3985
         // do a nonce check here since we're not arriving via a normal route
3986 3986
         $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3987
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3987
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
3988 3988
 
3989 3989
         $this->_verify_nonce($nonce, $nonce_ref);
3990 3990
 
@@ -4173,7 +4173,7 @@  discard block
 block discarded – undo
4173 4173
         EE_Message_Type $message_type = null
4174 4174
     ) {
4175 4175
         // if $messenger isn't a valid messenger object then get out.
4176
-        if (! $messenger instanceof EE_Messenger) {
4176
+        if ( ! $messenger instanceof EE_Messenger) {
4177 4177
             EE_Error::add_error(
4178 4178
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4179 4179
                 __FILE__,
@@ -4228,7 +4228,7 @@  discard block
 block discarded – undo
4228 4228
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4229 4229
             // in which case we just give a success message for the messenger being successfully activated.
4230 4230
         } else {
4231
-            if (! $messenger->get_default_message_types()) {
4231
+            if ( ! $messenger->get_default_message_types()) {
4232 4232
                 // messenger doesn't have any default message types so still a success.
4233 4233
                 EE_Error::add_success(
4234 4234
                     sprintf(
@@ -4284,7 +4284,7 @@  discard block
 block discarded – undo
4284 4284
         EE_Error::overwrite_success();
4285 4285
 
4286 4286
         // if $messenger isn't a valid messenger object then get out.
4287
-        if (! $messenger instanceof EE_Messenger) {
4287
+        if ( ! $messenger instanceof EE_Messenger) {
4288 4288
             EE_Error::add_error(
4289 4289
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4290 4290
                 __FILE__,
@@ -4346,7 +4346,7 @@  discard block
 block discarded – undo
4346 4346
      */
4347 4347
     public function update_mt_form()
4348 4348
     {
4349
-        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4349
+        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4350 4350
             EE_Error::add_error(
4351 4351
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4352 4352
                 __FILE__,
@@ -4358,7 +4358,7 @@  discard block
 block discarded – undo
4358 4358
 
4359 4359
         $message_types = $this->get_installed_message_types();
4360 4360
 
4361
-        $message_type = $message_types[ $this->_req_data['message_type'] ];
4361
+        $message_type = $message_types[$this->_req_data['message_type']];
4362 4362
         $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4363 4363
 
4364 4364
         $content = $this->_message_type_settings_content(
@@ -4378,7 +4378,7 @@  discard block
 block discarded – undo
4378 4378
      */
4379 4379
     public function save_settings()
4380 4380
     {
4381
-        if (! isset($this->_req_data['type'])) {
4381
+        if ( ! isset($this->_req_data['type'])) {
4382 4382
             EE_Error::add_error(
4383 4383
                 esc_html__(
4384 4384
                     'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
@@ -4407,7 +4407,7 @@  discard block
 block discarded – undo
4407 4407
                         unset($settings['message_types']);
4408 4408
                         break;
4409 4409
                     default:
4410
-                        $settings[ $key ] = $value;
4410
+                        $settings[$key] = $value;
4411 4411
                         break;
4412 4412
                 }
4413 4413
             }
@@ -4426,7 +4426,7 @@  discard block
 block discarded – undo
4426 4426
                         unset($settings['message_type']);
4427 4427
                         break;
4428 4428
                     default:
4429
-                        $settings[ $key ] = $value;
4429
+                        $settings[$key] = $value;
4430 4430
                         break;
4431 4431
                 }
4432 4432
             }
@@ -4587,7 +4587,7 @@  discard block
 block discarded – undo
4587 4587
      */
4588 4588
     protected function _get_msg_ids_from_request()
4589 4589
     {
4590
-        if (! isset($this->_req_data['MSG_ID'])) {
4590
+        if ( ! isset($this->_req_data['MSG_ID'])) {
4591 4591
             return array();
4592 4592
         }
4593 4593
 
Please login to merge, or discard this patch.
core/helpers/EEH_DTT_Helper.helper.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
      * Get Timezone Offset for given timezone object.
198 198
      *
199 199
      * @param DateTimeZone $date_time_zone
200
-     * @param null         $time
201
-     * @return mixed
200
+     * @param integer|null         $time
201
+     * @return integer
202 202
      * @throws InvalidArgumentException
203 203
      * @throws InvalidDataTypeException
204 204
      * @throws InvalidInterfaceException
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      * @param  DateTime   $DateTime DateTime object
321 321
      * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
322 322
      *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
323
-     * @param  int|string $value    What you want to increment the date by
323
+     * @param  integer $value    What you want to increment the date by
324 324
      * @param  string     $operand  What operand you wish to use for the calculation
325 325
      * @return DateTime return whatever type came in.
326 326
      * @throws Exception
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
      * this method will add that "1" into your date regardless of the format.
857 857
      *
858 858
      * @param string $month
859
-     * @return string
859
+     * @return integer
860 860
      */
861 861
     public static function first_of_month_timestamp($month = '')
862 862
     {
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
     /**
1005 1005
      * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1006 1006
      *
1007
-     * @param int|WP_User $user_id
1007
+     * @param integer $user_id
1008 1008
      * @return string
1009 1009
      */
1010 1010
     public static function get_user_locale($user_id = 0)
Please login to merge, or discard this patch.
Indentation   +983 added lines, -983 removed lines patch added patch discarded remove patch
@@ -17,1045 +17,1045 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * return the timezone set for the WP install
22
-     *
23
-     * @return string valid timezone string for PHP DateTimeZone() class
24
-     * @throws InvalidArgumentException
25
-     * @throws InvalidDataTypeException
26
-     * @throws InvalidInterfaceException
27
-     */
28
-    public static function get_timezone()
29
-    {
30
-        return EEH_DTT_Helper::get_valid_timezone_string();
31
-    }
20
+	/**
21
+	 * return the timezone set for the WP install
22
+	 *
23
+	 * @return string valid timezone string for PHP DateTimeZone() class
24
+	 * @throws InvalidArgumentException
25
+	 * @throws InvalidDataTypeException
26
+	 * @throws InvalidInterfaceException
27
+	 */
28
+	public static function get_timezone()
29
+	{
30
+		return EEH_DTT_Helper::get_valid_timezone_string();
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * get_valid_timezone_string
36
-     *    ensures that a valid timezone string is returned
37
-     *
38
-     * @param string $timezone_string
39
-     * @return string
40
-     * @throws InvalidArgumentException
41
-     * @throws InvalidDataTypeException
42
-     * @throws InvalidInterfaceException
43
-     */
44
-    public static function get_valid_timezone_string($timezone_string = '')
45
-    {
46
-        return self::getHelperAdapter()->getValidTimezoneString($timezone_string);
47
-    }
34
+	/**
35
+	 * get_valid_timezone_string
36
+	 *    ensures that a valid timezone string is returned
37
+	 *
38
+	 * @param string $timezone_string
39
+	 * @return string
40
+	 * @throws InvalidArgumentException
41
+	 * @throws InvalidDataTypeException
42
+	 * @throws InvalidInterfaceException
43
+	 */
44
+	public static function get_valid_timezone_string($timezone_string = '')
45
+	{
46
+		return self::getHelperAdapter()->getValidTimezoneString($timezone_string);
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
52
-     *
53
-     * @static
54
-     * @param  string $timezone_string Timezone string to check
55
-     * @param bool    $throw_error
56
-     * @return bool
57
-     * @throws InvalidArgumentException
58
-     * @throws InvalidDataTypeException
59
-     * @throws InvalidInterfaceException
60
-     */
61
-    public static function validate_timezone($timezone_string, $throw_error = true)
62
-    {
63
-        return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error);
64
-    }
50
+	/**
51
+	 * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
52
+	 *
53
+	 * @static
54
+	 * @param  string $timezone_string Timezone string to check
55
+	 * @param bool    $throw_error
56
+	 * @return bool
57
+	 * @throws InvalidArgumentException
58
+	 * @throws InvalidDataTypeException
59
+	 * @throws InvalidInterfaceException
60
+	 */
61
+	public static function validate_timezone($timezone_string, $throw_error = true)
62
+	{
63
+		return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * This returns a string that can represent the provided gmt offset in format that can be passed into
69
-     * DateTimeZone.  This is NOT a string that can be passed as a value on the WordPress timezone_string option.
70
-     *
71
-     * @param float|string $gmt_offset
72
-     * @return string
73
-     * @throws InvalidArgumentException
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     */
77
-    public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
78
-    {
79
-        return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset);
80
-    }
67
+	/**
68
+	 * This returns a string that can represent the provided gmt offset in format that can be passed into
69
+	 * DateTimeZone.  This is NOT a string that can be passed as a value on the WordPress timezone_string option.
70
+	 *
71
+	 * @param float|string $gmt_offset
72
+	 * @return string
73
+	 * @throws InvalidArgumentException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 */
77
+	public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
78
+	{
79
+		return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset);
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * Gets the site's GMT offset based on either the timezone string
85
-     * (in which case teh gmt offset will vary depending on the location's
86
-     * observance of daylight savings time) or the gmt_offset wp option
87
-     *
88
-     * @return int seconds offset
89
-     * @throws InvalidArgumentException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidInterfaceException
92
-     */
93
-    public static function get_site_timezone_gmt_offset()
94
-    {
95
-        return self::getHelperAdapter()->getSiteTimezoneGmtOffset();
96
-    }
83
+	/**
84
+	 * Gets the site's GMT offset based on either the timezone string
85
+	 * (in which case teh gmt offset will vary depending on the location's
86
+	 * observance of daylight savings time) or the gmt_offset wp option
87
+	 *
88
+	 * @return int seconds offset
89
+	 * @throws InvalidArgumentException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidInterfaceException
92
+	 */
93
+	public static function get_site_timezone_gmt_offset()
94
+	{
95
+		return self::getHelperAdapter()->getSiteTimezoneGmtOffset();
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * Depending on PHP version,
101
-     * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
102
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
103
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
104
-     *
105
-     * @deprecated 4.9.54.rc    Developers this was always meant to only be an internally used method.  This will be
106
-     *                          removed in a future version of EE.
107
-     * @param int $gmt_offset
108
-     * @return int
109
-     * @throws InvalidArgumentException
110
-     * @throws InvalidDataTypeException
111
-     * @throws InvalidInterfaceException
112
-     */
113
-    public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
114
-    {
115
-        return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset);
116
-    }
99
+	/**
100
+	 * Depending on PHP version,
101
+	 * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
102
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
103
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
104
+	 *
105
+	 * @deprecated 4.9.54.rc    Developers this was always meant to only be an internally used method.  This will be
106
+	 *                          removed in a future version of EE.
107
+	 * @param int $gmt_offset
108
+	 * @return int
109
+	 * @throws InvalidArgumentException
110
+	 * @throws InvalidDataTypeException
111
+	 * @throws InvalidInterfaceException
112
+	 */
113
+	public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
114
+	{
115
+		return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset);
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * get_timezone_string_from_abbreviations_list
121
-     *
122
-     * @deprecated 4.9.54.rc  Developers, this was never intended to be public.  This is a soft deprecation for now.
123
-     *                        If you are using this, you'll want to work out an alternate way of getting the value.
124
-     * @param int  $gmt_offset
125
-     * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
126
-     * @return string
127
-     * @throws EE_Error
128
-     * @throws InvalidArgumentException
129
-     * @throws InvalidDataTypeException
130
-     * @throws InvalidInterfaceException
131
-     */
132
-    public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
133
-    {
134
-        $gmt_offset =  (int) $gmt_offset;
135
-        /** @var array[] $abbreviations */
136
-        $abbreviations = DateTimeZone::listAbbreviations();
137
-        foreach ($abbreviations as $abbreviation) {
138
-            foreach ($abbreviation as $timezone) {
139
-                if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
140
-                    try {
141
-                        $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id']));
142
-                        if ($offset !== $gmt_offset) {
143
-                            continue;
144
-                        }
145
-                        return $timezone['timezone_id'];
146
-                    } catch (Exception $e) {
147
-                        continue;
148
-                    }
149
-                }
150
-            }
151
-        }
152
-        // if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
153
-        if ($coerce === true) {
154
-            $timezone_string = self::get_timezone_string_from_abbreviations_list(
155
-                self::adjust_invalid_gmt_offsets($gmt_offset),
156
-                false
157
-            );
158
-            if ($timezone_string) {
159
-                return $timezone_string;
160
-            }
161
-        }
162
-        throw new EE_Error(
163
-            sprintf(
164
-                esc_html__(
165
-                    'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
166
-                    'event_espresso'
167
-                ),
168
-                $gmt_offset / HOUR_IN_SECONDS,
169
-                '<a href="http://www.php.net/manual/en/timezones.php">',
170
-                '</a>'
171
-            )
172
-        );
173
-    }
119
+	/**
120
+	 * get_timezone_string_from_abbreviations_list
121
+	 *
122
+	 * @deprecated 4.9.54.rc  Developers, this was never intended to be public.  This is a soft deprecation for now.
123
+	 *                        If you are using this, you'll want to work out an alternate way of getting the value.
124
+	 * @param int  $gmt_offset
125
+	 * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
126
+	 * @return string
127
+	 * @throws EE_Error
128
+	 * @throws InvalidArgumentException
129
+	 * @throws InvalidDataTypeException
130
+	 * @throws InvalidInterfaceException
131
+	 */
132
+	public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
133
+	{
134
+		$gmt_offset =  (int) $gmt_offset;
135
+		/** @var array[] $abbreviations */
136
+		$abbreviations = DateTimeZone::listAbbreviations();
137
+		foreach ($abbreviations as $abbreviation) {
138
+			foreach ($abbreviation as $timezone) {
139
+				if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
140
+					try {
141
+						$offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id']));
142
+						if ($offset !== $gmt_offset) {
143
+							continue;
144
+						}
145
+						return $timezone['timezone_id'];
146
+					} catch (Exception $e) {
147
+						continue;
148
+					}
149
+				}
150
+			}
151
+		}
152
+		// if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
153
+		if ($coerce === true) {
154
+			$timezone_string = self::get_timezone_string_from_abbreviations_list(
155
+				self::adjust_invalid_gmt_offsets($gmt_offset),
156
+				false
157
+			);
158
+			if ($timezone_string) {
159
+				return $timezone_string;
160
+			}
161
+		}
162
+		throw new EE_Error(
163
+			sprintf(
164
+				esc_html__(
165
+					'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
166
+					'event_espresso'
167
+				),
168
+				$gmt_offset / HOUR_IN_SECONDS,
169
+				'<a href="http://www.php.net/manual/en/timezones.php">',
170
+				'</a>'
171
+			)
172
+		);
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * Get Timezone Transitions
178
-     *
179
-     * @param DateTimeZone $date_time_zone
180
-     * @param int|null     $time
181
-     * @param bool         $first_only
182
-     * @return array
183
-     * @throws InvalidArgumentException
184
-     * @throws InvalidDataTypeException
185
-     * @throws InvalidInterfaceException
186
-     */
187
-    public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
188
-    {
189
-        return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only);
190
-    }
176
+	/**
177
+	 * Get Timezone Transitions
178
+	 *
179
+	 * @param DateTimeZone $date_time_zone
180
+	 * @param int|null     $time
181
+	 * @param bool         $first_only
182
+	 * @return array
183
+	 * @throws InvalidArgumentException
184
+	 * @throws InvalidDataTypeException
185
+	 * @throws InvalidInterfaceException
186
+	 */
187
+	public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
188
+	{
189
+		return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only);
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * Get Timezone Offset for given timezone object.
195
-     *
196
-     * @param DateTimeZone $date_time_zone
197
-     * @param null         $time
198
-     * @return mixed
199
-     * @throws InvalidArgumentException
200
-     * @throws InvalidDataTypeException
201
-     * @throws InvalidInterfaceException
202
-     */
203
-    public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
204
-    {
205
-        return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time);
206
-    }
193
+	/**
194
+	 * Get Timezone Offset for given timezone object.
195
+	 *
196
+	 * @param DateTimeZone $date_time_zone
197
+	 * @param null         $time
198
+	 * @return mixed
199
+	 * @throws InvalidArgumentException
200
+	 * @throws InvalidDataTypeException
201
+	 * @throws InvalidInterfaceException
202
+	 */
203
+	public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
204
+	{
205
+		return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time);
206
+	}
207 207
 
208 208
 
209
-    /**
210
-     * Prints a select input for the given timezone string.
211
-     * @param string $timezone_string
212
-     * @deprecatd 4.9.54.rc   Soft deprecation.  Consider using \EEH_DTT_Helper::wp_timezone_choice instead.
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     */
217
-    public static function timezone_select_input($timezone_string = '')
218
-    {
219
-        self::getHelperAdapter()->timezoneSelectInput($timezone_string);
220
-    }
209
+	/**
210
+	 * Prints a select input for the given timezone string.
211
+	 * @param string $timezone_string
212
+	 * @deprecatd 4.9.54.rc   Soft deprecation.  Consider using \EEH_DTT_Helper::wp_timezone_choice instead.
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 */
217
+	public static function timezone_select_input($timezone_string = '')
218
+	{
219
+		self::getHelperAdapter()->timezoneSelectInput($timezone_string);
220
+	}
221 221
 
222 222
 
223
-    /**
224
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
225
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
226
-     * the site is used.
227
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
228
-     * computed timestamp (i.e. date_i18n() )
229
-     *
230
-     * @param int    $unix_timestamp                  if 0, then time() will be used.
231
-     * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
232
-     *                                                site will be used.
233
-     * @return int $unix_timestamp with the offset applied for the given timezone.
234
-     * @throws InvalidArgumentException
235
-     * @throws InvalidDataTypeException
236
-     * @throws InvalidInterfaceException
237
-     */
238
-    public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
239
-    {
240
-        return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string);
241
-    }
223
+	/**
224
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
225
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
226
+	 * the site is used.
227
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
228
+	 * computed timestamp (i.e. date_i18n() )
229
+	 *
230
+	 * @param int    $unix_timestamp                  if 0, then time() will be used.
231
+	 * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
232
+	 *                                                site will be used.
233
+	 * @return int $unix_timestamp with the offset applied for the given timezone.
234
+	 * @throws InvalidArgumentException
235
+	 * @throws InvalidDataTypeException
236
+	 * @throws InvalidInterfaceException
237
+	 */
238
+	public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
239
+	{
240
+		return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string);
241
+	}
242 242
 
243 243
 
244
-    /**
245
-     *    _set_date_time_field
246
-     *    modifies EE_Base_Class EE_Datetime_Field objects
247
-     *
248
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
249
-     * @param    DateTime    $DateTime            PHP DateTime object
250
-     * @param  string        $datetime_field_name the datetime fieldname to be manipulated
251
-     * @return EE_Base_Class
252
-     * @throws EE_Error
253
-     */
254
-    protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
255
-    {
256
-        // grab current datetime format
257
-        $current_format = $obj->get_format();
258
-        // set new full timestamp format
259
-        $obj->set_date_format(EE_Datetime_Field::mysql_date_format);
260
-        $obj->set_time_format(EE_Datetime_Field::mysql_time_format);
261
-        // set the new date value using a full timestamp format so that no data is lost
262
-        $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
263
-        // reset datetime formats
264
-        $obj->set_date_format($current_format[0]);
265
-        $obj->set_time_format($current_format[1]);
266
-        return $obj;
267
-    }
244
+	/**
245
+	 *    _set_date_time_field
246
+	 *    modifies EE_Base_Class EE_Datetime_Field objects
247
+	 *
248
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
249
+	 * @param    DateTime    $DateTime            PHP DateTime object
250
+	 * @param  string        $datetime_field_name the datetime fieldname to be manipulated
251
+	 * @return EE_Base_Class
252
+	 * @throws EE_Error
253
+	 */
254
+	protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
255
+	{
256
+		// grab current datetime format
257
+		$current_format = $obj->get_format();
258
+		// set new full timestamp format
259
+		$obj->set_date_format(EE_Datetime_Field::mysql_date_format);
260
+		$obj->set_time_format(EE_Datetime_Field::mysql_time_format);
261
+		// set the new date value using a full timestamp format so that no data is lost
262
+		$obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
263
+		// reset datetime formats
264
+		$obj->set_date_format($current_format[0]);
265
+		$obj->set_time_format($current_format[1]);
266
+		return $obj;
267
+	}
268 268
 
269 269
 
270
-    /**
271
-     *    date_time_add
272
-     *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
273
-     *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
274
-     *
275
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
276
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
277
-     * @param  string        $period              what you are adding. The options are (years, months, days, hours,
278
-     *                                            minutes, seconds) defaults to years
279
-     * @param  integer       $value               what you want to increment the time by
280
-     * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it
281
-     *                                            (chaining)
282
-     * @throws EE_Error
283
-     * @throws Exception
284
-     */
285
-    public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
286
-    {
287
-        // get the raw UTC date.
288
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
289
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
290
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
291
-    }
270
+	/**
271
+	 *    date_time_add
272
+	 *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
273
+	 *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
274
+	 *
275
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
276
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
277
+	 * @param  string        $period              what you are adding. The options are (years, months, days, hours,
278
+	 *                                            minutes, seconds) defaults to years
279
+	 * @param  integer       $value               what you want to increment the time by
280
+	 * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it
281
+	 *                                            (chaining)
282
+	 * @throws EE_Error
283
+	 * @throws Exception
284
+	 */
285
+	public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
286
+	{
287
+		// get the raw UTC date.
288
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
289
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
290
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
291
+	}
292 292
 
293 293
 
294
-    /**
295
-     *    date_time_subtract
296
-     *    same as date_time_add except subtracting value instead of adding.
297
-     *
298
-     * @param EE_Base_Class $obj
299
-     * @param  string       $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
300
-     * @param string        $period
301
-     * @param int           $value
302
-     * @return EE_Base_Class
303
-     * @throws EE_Error
304
-     * @throws Exception
305
-     */
306
-    public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
307
-    {
308
-        // get the raw UTC date
309
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
310
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
311
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
312
-    }
294
+	/**
295
+	 *    date_time_subtract
296
+	 *    same as date_time_add except subtracting value instead of adding.
297
+	 *
298
+	 * @param EE_Base_Class $obj
299
+	 * @param  string       $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
300
+	 * @param string        $period
301
+	 * @param int           $value
302
+	 * @return EE_Base_Class
303
+	 * @throws EE_Error
304
+	 * @throws Exception
305
+	 */
306
+	public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
307
+	{
308
+		// get the raw UTC date
309
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
310
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
311
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
312
+	}
313 313
 
314 314
 
315
-    /**
316
-     * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
317
-     *
318
-     * @param  DateTime   $DateTime DateTime object
319
-     * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
320
-     *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
321
-     * @param  int|string $value    What you want to increment the date by
322
-     * @param  string     $operand  What operand you wish to use for the calculation
323
-     * @return DateTime return whatever type came in.
324
-     * @throws Exception
325
-     * @throws EE_Error
326
-     */
327
-    protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
328
-    {
329
-        if (! $DateTime instanceof DateTime) {
330
-            throw new EE_Error(
331
-                sprintf(
332
-                    esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
333
-                    print_r($DateTime, true)
334
-                )
335
-            );
336
-        }
337
-        switch ($period) {
338
-            case 'years':
339
-                $value = 'P' . $value . 'Y';
340
-                break;
341
-            case 'months':
342
-                $value = 'P' . $value . 'M';
343
-                break;
344
-            case 'weeks':
345
-                $value = 'P' . $value . 'W';
346
-                break;
347
-            case 'days':
348
-                $value = 'P' . $value . 'D';
349
-                break;
350
-            case 'hours':
351
-                $value = 'PT' . $value . 'H';
352
-                break;
353
-            case 'minutes':
354
-                $value = 'PT' . $value . 'M';
355
-                break;
356
-            case 'seconds':
357
-                $value = 'PT' . $value . 'S';
358
-                break;
359
-        }
360
-        switch ($operand) {
361
-            case '+':
362
-                $DateTime->add(new DateInterval($value));
363
-                break;
364
-            case '-':
365
-                $DateTime->sub(new DateInterval($value));
366
-                break;
367
-        }
368
-        return $DateTime;
369
-    }
315
+	/**
316
+	 * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
317
+	 *
318
+	 * @param  DateTime   $DateTime DateTime object
319
+	 * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
320
+	 *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
321
+	 * @param  int|string $value    What you want to increment the date by
322
+	 * @param  string     $operand  What operand you wish to use for the calculation
323
+	 * @return DateTime return whatever type came in.
324
+	 * @throws Exception
325
+	 * @throws EE_Error
326
+	 */
327
+	protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
328
+	{
329
+		if (! $DateTime instanceof DateTime) {
330
+			throw new EE_Error(
331
+				sprintf(
332
+					esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
333
+					print_r($DateTime, true)
334
+				)
335
+			);
336
+		}
337
+		switch ($period) {
338
+			case 'years':
339
+				$value = 'P' . $value . 'Y';
340
+				break;
341
+			case 'months':
342
+				$value = 'P' . $value . 'M';
343
+				break;
344
+			case 'weeks':
345
+				$value = 'P' . $value . 'W';
346
+				break;
347
+			case 'days':
348
+				$value = 'P' . $value . 'D';
349
+				break;
350
+			case 'hours':
351
+				$value = 'PT' . $value . 'H';
352
+				break;
353
+			case 'minutes':
354
+				$value = 'PT' . $value . 'M';
355
+				break;
356
+			case 'seconds':
357
+				$value = 'PT' . $value . 'S';
358
+				break;
359
+		}
360
+		switch ($operand) {
361
+			case '+':
362
+				$DateTime->add(new DateInterval($value));
363
+				break;
364
+			case '-':
365
+				$DateTime->sub(new DateInterval($value));
366
+				break;
367
+		}
368
+		return $DateTime;
369
+	}
370 370
 
371 371
 
372
-    /**
373
-     * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
374
-     *
375
-     * @param  int     $timestamp Unix timestamp
376
-     * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
377
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
378
-     * @param  integer $value     What you want to increment the date by
379
-     * @param  string  $operand   What operand you wish to use for the calculation
380
-     * @return int
381
-     * @throws EE_Error
382
-     */
383
-    protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
384
-    {
385
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
386
-            throw new EE_Error(
387
-                sprintf(
388
-                    esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
389
-                    print_r($timestamp, true)
390
-                )
391
-            );
392
-        }
393
-        switch ($period) {
394
-            case 'years':
395
-                $value = YEAR_IN_SECONDS * $value;
396
-                break;
397
-            case 'months':
398
-                $value = YEAR_IN_SECONDS / 12 * $value;
399
-                break;
400
-            case 'weeks':
401
-                $value = WEEK_IN_SECONDS * $value;
402
-                break;
403
-            case 'days':
404
-                $value = DAY_IN_SECONDS * $value;
405
-                break;
406
-            case 'hours':
407
-                $value = HOUR_IN_SECONDS * $value;
408
-                break;
409
-            case 'minutes':
410
-                $value = MINUTE_IN_SECONDS * $value;
411
-                break;
412
-        }
413
-        switch ($operand) {
414
-            case '+':
415
-                $timestamp += $value;
416
-                break;
417
-            case '-':
418
-                $timestamp -= $value;
419
-                break;
420
-        }
421
-        return $timestamp;
422
-    }
372
+	/**
373
+	 * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
374
+	 *
375
+	 * @param  int     $timestamp Unix timestamp
376
+	 * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
377
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
378
+	 * @param  integer $value     What you want to increment the date by
379
+	 * @param  string  $operand   What operand you wish to use for the calculation
380
+	 * @return int
381
+	 * @throws EE_Error
382
+	 */
383
+	protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
384
+	{
385
+		if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
386
+			throw new EE_Error(
387
+				sprintf(
388
+					esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
389
+					print_r($timestamp, true)
390
+				)
391
+			);
392
+		}
393
+		switch ($period) {
394
+			case 'years':
395
+				$value = YEAR_IN_SECONDS * $value;
396
+				break;
397
+			case 'months':
398
+				$value = YEAR_IN_SECONDS / 12 * $value;
399
+				break;
400
+			case 'weeks':
401
+				$value = WEEK_IN_SECONDS * $value;
402
+				break;
403
+			case 'days':
404
+				$value = DAY_IN_SECONDS * $value;
405
+				break;
406
+			case 'hours':
407
+				$value = HOUR_IN_SECONDS * $value;
408
+				break;
409
+			case 'minutes':
410
+				$value = MINUTE_IN_SECONDS * $value;
411
+				break;
412
+		}
413
+		switch ($operand) {
414
+			case '+':
415
+				$timestamp += $value;
416
+				break;
417
+			case '-':
418
+				$timestamp -= $value;
419
+				break;
420
+		}
421
+		return $timestamp;
422
+	}
423 423
 
424 424
 
425
-    /**
426
-     * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
427
-     * parameters and returns the new timestamp or DateTime.
428
-     *
429
-     * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
430
-     * @param  string         $period                a value to indicate what interval is being used in the
431
-     *                                               calculation. The options are 'years', 'months', 'days', 'hours',
432
-     *                                               'minutes', 'seconds'. Defaults to years.
433
-     * @param  integer        $value                 What you want to increment the date by
434
-     * @param  string         $operand               What operand you wish to use for the calculation
435
-     * @return mixed string|DateTime          return whatever type came in.
436
-     * @throws Exception
437
-     * @throws EE_Error
438
-     */
439
-    public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
440
-    {
441
-        if ($DateTime_or_timestamp instanceof DateTime) {
442
-            return EEH_DTT_Helper::_modify_datetime_object(
443
-                $DateTime_or_timestamp,
444
-                $period,
445
-                $value,
446
-                $operand
447
-            );
448
-        }
449
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
450
-            return EEH_DTT_Helper::_modify_timestamp(
451
-                $DateTime_or_timestamp,
452
-                $period,
453
-                $value,
454
-                $operand
455
-            );
456
-        }
457
-        // error
458
-        return $DateTime_or_timestamp;
459
-    }
425
+	/**
426
+	 * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
427
+	 * parameters and returns the new timestamp or DateTime.
428
+	 *
429
+	 * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
430
+	 * @param  string         $period                a value to indicate what interval is being used in the
431
+	 *                                               calculation. The options are 'years', 'months', 'days', 'hours',
432
+	 *                                               'minutes', 'seconds'. Defaults to years.
433
+	 * @param  integer        $value                 What you want to increment the date by
434
+	 * @param  string         $operand               What operand you wish to use for the calculation
435
+	 * @return mixed string|DateTime          return whatever type came in.
436
+	 * @throws Exception
437
+	 * @throws EE_Error
438
+	 */
439
+	public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
440
+	{
441
+		if ($DateTime_or_timestamp instanceof DateTime) {
442
+			return EEH_DTT_Helper::_modify_datetime_object(
443
+				$DateTime_or_timestamp,
444
+				$period,
445
+				$value,
446
+				$operand
447
+			);
448
+		}
449
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
450
+			return EEH_DTT_Helper::_modify_timestamp(
451
+				$DateTime_or_timestamp,
452
+				$period,
453
+				$value,
454
+				$operand
455
+			);
456
+		}
457
+		// error
458
+		return $DateTime_or_timestamp;
459
+	}
460 460
 
461 461
 
462
-    /**
463
-     * The purpose of this helper method is to receive an incoming format string in php date/time format
464
-     * and spit out the js and moment.js equivalent formats.
465
-     * Note, if no format string is given, then it is assumed the user wants what is set for WP.
466
-     * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
467
-     * time picker.
468
-     *
469
-     * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
470
-     * @param string $date_format_string
471
-     * @param string $time_format_string
472
-     * @return array
473
-     *              array(
474
-     *              'js' => array (
475
-     *              'date' => //date format
476
-     *              'time' => //time format
477
-     *              ),
478
-     *              'moment' => //date and time format.
479
-     *              )
480
-     */
481
-    public static function convert_php_to_js_and_moment_date_formats(
482
-        $date_format_string = null,
483
-        $time_format_string = null
484
-    ) {
485
-        if ($date_format_string === null) {
486
-            $date_format_string = (string) get_option('date_format');
487
-        }
488
-        if ($time_format_string === null) {
489
-            $time_format_string = (string) get_option('time_format');
490
-        }
491
-        $date_format = self::_php_to_js_moment_converter($date_format_string);
492
-        $time_format = self::_php_to_js_moment_converter($time_format_string);
493
-        return array(
494
-            'js'     => array(
495
-                'date' => $date_format['js'],
496
-                'time' => $time_format['js'],
497
-            ),
498
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
499
-            'moment_split' => array(
500
-                'date' => $date_format['moment'],
501
-                'time' => $time_format['moment']
502
-            )
503
-        );
504
-    }
462
+	/**
463
+	 * The purpose of this helper method is to receive an incoming format string in php date/time format
464
+	 * and spit out the js and moment.js equivalent formats.
465
+	 * Note, if no format string is given, then it is assumed the user wants what is set for WP.
466
+	 * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
467
+	 * time picker.
468
+	 *
469
+	 * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
470
+	 * @param string $date_format_string
471
+	 * @param string $time_format_string
472
+	 * @return array
473
+	 *              array(
474
+	 *              'js' => array (
475
+	 *              'date' => //date format
476
+	 *              'time' => //time format
477
+	 *              ),
478
+	 *              'moment' => //date and time format.
479
+	 *              )
480
+	 */
481
+	public static function convert_php_to_js_and_moment_date_formats(
482
+		$date_format_string = null,
483
+		$time_format_string = null
484
+	) {
485
+		if ($date_format_string === null) {
486
+			$date_format_string = (string) get_option('date_format');
487
+		}
488
+		if ($time_format_string === null) {
489
+			$time_format_string = (string) get_option('time_format');
490
+		}
491
+		$date_format = self::_php_to_js_moment_converter($date_format_string);
492
+		$time_format = self::_php_to_js_moment_converter($time_format_string);
493
+		return array(
494
+			'js'     => array(
495
+				'date' => $date_format['js'],
496
+				'time' => $time_format['js'],
497
+			),
498
+			'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
499
+			'moment_split' => array(
500
+				'date' => $date_format['moment'],
501
+				'time' => $time_format['moment']
502
+			)
503
+		);
504
+	}
505 505
 
506 506
 
507
-    /**
508
-     * This converts incoming format string into js and moment variations.
509
-     *
510
-     * @param string $format_string incoming php format string
511
-     * @return array js and moment formats.
512
-     */
513
-    protected static function _php_to_js_moment_converter($format_string)
514
-    {
515
-        /**
516
-         * This is a map of symbols for formats.
517
-         * The index is the php symbol, the equivalent values are in the array.
518
-         *
519
-         * @var array
520
-         */
521
-        $symbols_map          = array(
522
-            // Day
523
-            // 01
524
-            'd' => array(
525
-                'js'     => 'dd',
526
-                'moment' => 'DD',
527
-            ),
528
-            // Mon
529
-            'D' => array(
530
-                'js'     => 'D',
531
-                'moment' => 'ddd',
532
-            ),
533
-            // 1,2,...31
534
-            'j' => array(
535
-                'js'     => 'd',
536
-                'moment' => 'D',
537
-            ),
538
-            // Monday
539
-            'l' => array(
540
-                'js'     => 'DD',
541
-                'moment' => 'dddd',
542
-            ),
543
-            // ISO numeric representation of the day of the week (1-6)
544
-            'N' => array(
545
-                'js'     => '',
546
-                'moment' => 'E',
547
-            ),
548
-            // st,nd.rd
549
-            'S' => array(
550
-                'js'     => '',
551
-                'moment' => 'o',
552
-            ),
553
-            // numeric representation of day of week (0-6)
554
-            'w' => array(
555
-                'js'     => '',
556
-                'moment' => 'd',
557
-            ),
558
-            // day of year starting from 0 (0-365)
559
-            'z' => array(
560
-                'js'     => 'o',
561
-                'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1
562
-            ),
563
-            // Week
564
-            // ISO-8601 week number of year (weeks starting on monday)
565
-            'W' => array(
566
-                'js'     => '',
567
-                'moment' => 'w',
568
-            ),
569
-            // Month
570
-            // January...December
571
-            'F' => array(
572
-                'js'     => 'MM',
573
-                'moment' => 'MMMM',
574
-            ),
575
-            // 01...12
576
-            'm' => array(
577
-                'js'     => 'mm',
578
-                'moment' => 'MM',
579
-            ),
580
-            // Jan...Dec
581
-            'M' => array(
582
-                'js'     => 'M',
583
-                'moment' => 'MMM',
584
-            ),
585
-            // 1-12
586
-            'n' => array(
587
-                'js'     => 'm',
588
-                'moment' => 'M',
589
-            ),
590
-            // number of days in given month
591
-            't' => array(
592
-                'js'     => '',
593
-                'moment' => '',
594
-            ),
595
-            // Year
596
-            // whether leap year or not 1/0
597
-            'L' => array(
598
-                'js'     => '',
599
-                'moment' => '',
600
-            ),
601
-            // ISO-8601 year number
602
-            'o' => array(
603
-                'js'     => '',
604
-                'moment' => 'GGGG',
605
-            ),
606
-            // 1999...2003
607
-            'Y' => array(
608
-                'js'     => 'yy',
609
-                'moment' => 'YYYY',
610
-            ),
611
-            // 99...03
612
-            'y' => array(
613
-                'js'     => 'y',
614
-                'moment' => 'YY',
615
-            ),
616
-            // Time
617
-            // am/pm
618
-            'a' => array(
619
-                'js'     => 'tt',
620
-                'moment' => 'a',
621
-            ),
622
-            // AM/PM
623
-            'A' => array(
624
-                'js'     => 'TT',
625
-                'moment' => 'A',
626
-            ),
627
-            // Swatch Internet Time?!?
628
-            'B' => array(
629
-                'js'     => '',
630
-                'moment' => '',
631
-            ),
632
-            // 1...12
633
-            'g' => array(
634
-                'js'     => 'h',
635
-                'moment' => 'h',
636
-            ),
637
-            // 0...23
638
-            'G' => array(
639
-                'js'     => 'H',
640
-                'moment' => 'H',
641
-            ),
642
-            // 01...12
643
-            'h' => array(
644
-                'js'     => 'hh',
645
-                'moment' => 'hh',
646
-            ),
647
-            // 00...23
648
-            'H' => array(
649
-                'js'     => 'HH',
650
-                'moment' => 'HH',
651
-            ),
652
-            // 00..59
653
-            'i' => array(
654
-                'js'     => 'mm',
655
-                'moment' => 'mm',
656
-            ),
657
-            // seconds... 00...59
658
-            's' => array(
659
-                'js'     => 'ss',
660
-                'moment' => 'ss',
661
-            ),
662
-            // microseconds
663
-            'u' => array(
664
-                'js'     => '',
665
-                'moment' => '',
666
-            ),
667
-        );
668
-        $jquery_ui_format     = '';
669
-        $moment_format        = '';
670
-        $escaping             = false;
671
-        $format_string_length = strlen($format_string);
672
-        for ($i = 0; $i < $format_string_length; $i++) {
673
-            $char = $format_string[ $i ];
674
-            if ($char === '\\') { // PHP date format escaping character
675
-                $i++;
676
-                if ($escaping) {
677
-                    $jquery_ui_format .= $format_string[ $i ];
678
-                    $moment_format    .= $format_string[ $i ];
679
-                } else {
680
-                    $jquery_ui_format .= '\'' . $format_string[ $i ];
681
-                    $moment_format    .= $format_string[ $i ];
682
-                }
683
-                $escaping = true;
684
-            } else {
685
-                if ($escaping) {
686
-                    $jquery_ui_format .= "'";
687
-                    $moment_format    .= "'";
688
-                    $escaping         = false;
689
-                }
690
-                if (isset($symbols_map[ $char ])) {
691
-                    $jquery_ui_format .= $symbols_map[ $char ]['js'];
692
-                    $moment_format    .= $symbols_map[ $char ]['moment'];
693
-                } else {
694
-                    $jquery_ui_format .= $char;
695
-                    $moment_format    .= $char;
696
-                }
697
-            }
698
-        }
699
-        return array('js' => $jquery_ui_format, 'moment' => $moment_format);
700
-    }
507
+	/**
508
+	 * This converts incoming format string into js and moment variations.
509
+	 *
510
+	 * @param string $format_string incoming php format string
511
+	 * @return array js and moment formats.
512
+	 */
513
+	protected static function _php_to_js_moment_converter($format_string)
514
+	{
515
+		/**
516
+		 * This is a map of symbols for formats.
517
+		 * The index is the php symbol, the equivalent values are in the array.
518
+		 *
519
+		 * @var array
520
+		 */
521
+		$symbols_map          = array(
522
+			// Day
523
+			// 01
524
+			'd' => array(
525
+				'js'     => 'dd',
526
+				'moment' => 'DD',
527
+			),
528
+			// Mon
529
+			'D' => array(
530
+				'js'     => 'D',
531
+				'moment' => 'ddd',
532
+			),
533
+			// 1,2,...31
534
+			'j' => array(
535
+				'js'     => 'd',
536
+				'moment' => 'D',
537
+			),
538
+			// Monday
539
+			'l' => array(
540
+				'js'     => 'DD',
541
+				'moment' => 'dddd',
542
+			),
543
+			// ISO numeric representation of the day of the week (1-6)
544
+			'N' => array(
545
+				'js'     => '',
546
+				'moment' => 'E',
547
+			),
548
+			// st,nd.rd
549
+			'S' => array(
550
+				'js'     => '',
551
+				'moment' => 'o',
552
+			),
553
+			// numeric representation of day of week (0-6)
554
+			'w' => array(
555
+				'js'     => '',
556
+				'moment' => 'd',
557
+			),
558
+			// day of year starting from 0 (0-365)
559
+			'z' => array(
560
+				'js'     => 'o',
561
+				'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1
562
+			),
563
+			// Week
564
+			// ISO-8601 week number of year (weeks starting on monday)
565
+			'W' => array(
566
+				'js'     => '',
567
+				'moment' => 'w',
568
+			),
569
+			// Month
570
+			// January...December
571
+			'F' => array(
572
+				'js'     => 'MM',
573
+				'moment' => 'MMMM',
574
+			),
575
+			// 01...12
576
+			'm' => array(
577
+				'js'     => 'mm',
578
+				'moment' => 'MM',
579
+			),
580
+			// Jan...Dec
581
+			'M' => array(
582
+				'js'     => 'M',
583
+				'moment' => 'MMM',
584
+			),
585
+			// 1-12
586
+			'n' => array(
587
+				'js'     => 'm',
588
+				'moment' => 'M',
589
+			),
590
+			// number of days in given month
591
+			't' => array(
592
+				'js'     => '',
593
+				'moment' => '',
594
+			),
595
+			// Year
596
+			// whether leap year or not 1/0
597
+			'L' => array(
598
+				'js'     => '',
599
+				'moment' => '',
600
+			),
601
+			// ISO-8601 year number
602
+			'o' => array(
603
+				'js'     => '',
604
+				'moment' => 'GGGG',
605
+			),
606
+			// 1999...2003
607
+			'Y' => array(
608
+				'js'     => 'yy',
609
+				'moment' => 'YYYY',
610
+			),
611
+			// 99...03
612
+			'y' => array(
613
+				'js'     => 'y',
614
+				'moment' => 'YY',
615
+			),
616
+			// Time
617
+			// am/pm
618
+			'a' => array(
619
+				'js'     => 'tt',
620
+				'moment' => 'a',
621
+			),
622
+			// AM/PM
623
+			'A' => array(
624
+				'js'     => 'TT',
625
+				'moment' => 'A',
626
+			),
627
+			// Swatch Internet Time?!?
628
+			'B' => array(
629
+				'js'     => '',
630
+				'moment' => '',
631
+			),
632
+			// 1...12
633
+			'g' => array(
634
+				'js'     => 'h',
635
+				'moment' => 'h',
636
+			),
637
+			// 0...23
638
+			'G' => array(
639
+				'js'     => 'H',
640
+				'moment' => 'H',
641
+			),
642
+			// 01...12
643
+			'h' => array(
644
+				'js'     => 'hh',
645
+				'moment' => 'hh',
646
+			),
647
+			// 00...23
648
+			'H' => array(
649
+				'js'     => 'HH',
650
+				'moment' => 'HH',
651
+			),
652
+			// 00..59
653
+			'i' => array(
654
+				'js'     => 'mm',
655
+				'moment' => 'mm',
656
+			),
657
+			// seconds... 00...59
658
+			's' => array(
659
+				'js'     => 'ss',
660
+				'moment' => 'ss',
661
+			),
662
+			// microseconds
663
+			'u' => array(
664
+				'js'     => '',
665
+				'moment' => '',
666
+			),
667
+		);
668
+		$jquery_ui_format     = '';
669
+		$moment_format        = '';
670
+		$escaping             = false;
671
+		$format_string_length = strlen($format_string);
672
+		for ($i = 0; $i < $format_string_length; $i++) {
673
+			$char = $format_string[ $i ];
674
+			if ($char === '\\') { // PHP date format escaping character
675
+				$i++;
676
+				if ($escaping) {
677
+					$jquery_ui_format .= $format_string[ $i ];
678
+					$moment_format    .= $format_string[ $i ];
679
+				} else {
680
+					$jquery_ui_format .= '\'' . $format_string[ $i ];
681
+					$moment_format    .= $format_string[ $i ];
682
+				}
683
+				$escaping = true;
684
+			} else {
685
+				if ($escaping) {
686
+					$jquery_ui_format .= "'";
687
+					$moment_format    .= "'";
688
+					$escaping         = false;
689
+				}
690
+				if (isset($symbols_map[ $char ])) {
691
+					$jquery_ui_format .= $symbols_map[ $char ]['js'];
692
+					$moment_format    .= $symbols_map[ $char ]['moment'];
693
+				} else {
694
+					$jquery_ui_format .= $char;
695
+					$moment_format    .= $char;
696
+				}
697
+			}
698
+		}
699
+		return array('js' => $jquery_ui_format, 'moment' => $moment_format);
700
+	}
701 701
 
702 702
 
703
-    /**
704
-     * This takes an incoming format string and validates it to ensure it will work fine with PHP.
705
-     *
706
-     * @param string $format_string   Incoming format string for php date().
707
-     * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
708
-     *                                errors is returned.  So for client code calling, check for is_array() to
709
-     *                                indicate failed validations.
710
-     */
711
-    public static function validate_format_string($format_string)
712
-    {
713
-        $error_msg = array();
714
-        // time format checks
715
-        switch (true) {
716
-            case strpos($format_string, 'h') !== false:
717
-            case strpos($format_string, 'g') !== false:
718
-                /**
719
-                 * if the time string has a lowercase 'h' which == 12 hour time format and there
720
-                 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
721
-                 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
722
-                 */
723
-                if (stripos($format_string, 'A') === false) {
724
-                    $error_msg[] = esc_html__(
725
-                        'There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
726
-                        'event_espresso'
727
-                    );
728
-                }
729
-                break;
730
-        }
731
-        return empty($error_msg) ? true : $error_msg;
732
-    }
703
+	/**
704
+	 * This takes an incoming format string and validates it to ensure it will work fine with PHP.
705
+	 *
706
+	 * @param string $format_string   Incoming format string for php date().
707
+	 * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
708
+	 *                                errors is returned.  So for client code calling, check for is_array() to
709
+	 *                                indicate failed validations.
710
+	 */
711
+	public static function validate_format_string($format_string)
712
+	{
713
+		$error_msg = array();
714
+		// time format checks
715
+		switch (true) {
716
+			case strpos($format_string, 'h') !== false:
717
+			case strpos($format_string, 'g') !== false:
718
+				/**
719
+				 * if the time string has a lowercase 'h' which == 12 hour time format and there
720
+				 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
721
+				 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
722
+				 */
723
+				if (stripos($format_string, 'A') === false) {
724
+					$error_msg[] = esc_html__(
725
+						'There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
726
+						'event_espresso'
727
+					);
728
+				}
729
+				break;
730
+		}
731
+		return empty($error_msg) ? true : $error_msg;
732
+	}
733 733
 
734 734
 
735
-    /**
736
-     *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
737
-     *     very next day then this method will return true.
738
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
739
-     *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
740
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
741
-     *
742
-     * @param mixed $date_1
743
-     * @param mixed $date_2
744
-     * @return bool
745
-     */
746
-    public static function dates_represent_one_24_hour_date($date_1, $date_2)
747
-    {
735
+	/**
736
+	 *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
737
+	 *     very next day then this method will return true.
738
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
739
+	 *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
740
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
741
+	 *
742
+	 * @param mixed $date_1
743
+	 * @param mixed $date_2
744
+	 * @return bool
745
+	 */
746
+	public static function dates_represent_one_24_hour_date($date_1, $date_2)
747
+	{
748 748
 
749
-        if (
750
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
751
-            || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
752
-                || $date_2->format(
753
-                    EE_Datetime_Field::mysql_time_format
754
-                ) !== '00:00:00')
755
-        ) {
756
-            return false;
757
-        }
758
-        return $date_2->format('U') - $date_1->format('U') === 86400;
759
-    }
749
+		if (
750
+			(! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
751
+			|| ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
752
+				|| $date_2->format(
753
+					EE_Datetime_Field::mysql_time_format
754
+				) !== '00:00:00')
755
+		) {
756
+			return false;
757
+		}
758
+		return $date_2->format('U') - $date_1->format('U') === 86400;
759
+	}
760 760
 
761 761
 
762
-    /**
763
-     * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
764
-     * Functions.
765
-     *
766
-     * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
767
-     * @param string $field_for_interval The Database field that is the interval is applied to in the query.
768
-     * @return string
769
-     */
770
-    public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
771
-    {
772
-        try {
773
-            /** need to account for timezone offset on the selects */
774
-            $DateTimeZone = new DateTimeZone($timezone_string);
775
-        } catch (Exception $e) {
776
-            $DateTimeZone = null;
777
-        }
778
-        /**
779
-         * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
780
-         * Hence we do the calc for DateTimeZone::getOffset.
781
-         */
782
-        $offset         = $DateTimeZone instanceof DateTimeZone
783
-            ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
784
-            : (float) get_option('gmt_offset');
785
-        $query_interval = $offset < 0
786
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
787
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
788
-        return $query_interval;
789
-    }
762
+	/**
763
+	 * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
764
+	 * Functions.
765
+	 *
766
+	 * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
767
+	 * @param string $field_for_interval The Database field that is the interval is applied to in the query.
768
+	 * @return string
769
+	 */
770
+	public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
771
+	{
772
+		try {
773
+			/** need to account for timezone offset on the selects */
774
+			$DateTimeZone = new DateTimeZone($timezone_string);
775
+		} catch (Exception $e) {
776
+			$DateTimeZone = null;
777
+		}
778
+		/**
779
+		 * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
780
+		 * Hence we do the calc for DateTimeZone::getOffset.
781
+		 */
782
+		$offset         = $DateTimeZone instanceof DateTimeZone
783
+			? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
784
+			: (float) get_option('gmt_offset');
785
+		$query_interval = $offset < 0
786
+			? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
787
+			: 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
788
+		return $query_interval;
789
+	}
790 790
 
791 791
 
792
-    /**
793
-     * Retrieves the site's default timezone and returns it formatted so it's ready for display
794
-     * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
795
-     * and 'gmt_offset' WordPress options directly; or use the filter
796
-     * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
797
-     * (although note that we remove any HTML that may be added)
798
-     *
799
-     * @return string
800
-     */
801
-    public static function get_timezone_string_for_display()
802
-    {
803
-        $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
804
-        if (! empty($pretty_timezone)) {
805
-            return esc_html($pretty_timezone);
806
-        }
807
-        $timezone_string = get_option('timezone_string');
808
-        if ($timezone_string) {
809
-            static $mo_loaded = false;
810
-            // Load translations for continents and cities just like wp_timezone_choice does
811
-            if (! $mo_loaded) {
812
-                $locale = get_locale();
813
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
814
-                load_textdomain('continents-cities', $mofile);
815
-                $mo_loaded = true;
816
-            }
817
-            // well that was easy.
818
-            $parts = explode('/', $timezone_string);
819
-            // remove the continent
820
-            unset($parts[0]);
821
-            $t_parts = array();
822
-            // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
823
-            // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
824
-            // disabled because this code is copied from WordPress and is a WordPress domain
825
-            foreach ($parts as $part) {
826
-                $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
827
-            }
828
-            return implode(' - ', $t_parts);
829
-            // phpcs:enable
830
-        }
831
-        // they haven't set the timezone string, so let's return a string like "UTC+1"
832
-        $gmt_offset = get_option('gmt_offset');
833
-        $prefix     = (int) $gmt_offset >= 0 ? '+' : '';
834
-        $parts      = explode('.', (string) $gmt_offset);
835
-        if (count($parts) === 1) {
836
-            $parts[1] = '00';
837
-        } else {
838
-            // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
839
-            // to minutes, eg 30 or 15, respectively
840
-            $hour_fraction = (float) ('0.' . $parts[1]);
841
-            $parts[1]      = (string) $hour_fraction * 60;
842
-        }
843
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
844
-    }
792
+	/**
793
+	 * Retrieves the site's default timezone and returns it formatted so it's ready for display
794
+	 * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
795
+	 * and 'gmt_offset' WordPress options directly; or use the filter
796
+	 * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
797
+	 * (although note that we remove any HTML that may be added)
798
+	 *
799
+	 * @return string
800
+	 */
801
+	public static function get_timezone_string_for_display()
802
+	{
803
+		$pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
804
+		if (! empty($pretty_timezone)) {
805
+			return esc_html($pretty_timezone);
806
+		}
807
+		$timezone_string = get_option('timezone_string');
808
+		if ($timezone_string) {
809
+			static $mo_loaded = false;
810
+			// Load translations for continents and cities just like wp_timezone_choice does
811
+			if (! $mo_loaded) {
812
+				$locale = get_locale();
813
+				$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
814
+				load_textdomain('continents-cities', $mofile);
815
+				$mo_loaded = true;
816
+			}
817
+			// well that was easy.
818
+			$parts = explode('/', $timezone_string);
819
+			// remove the continent
820
+			unset($parts[0]);
821
+			$t_parts = array();
822
+			// phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
823
+			// phpcs:disable WordPress.WP.I18n.TextDomainMismatch
824
+			// disabled because this code is copied from WordPress and is a WordPress domain
825
+			foreach ($parts as $part) {
826
+				$t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
827
+			}
828
+			return implode(' - ', $t_parts);
829
+			// phpcs:enable
830
+		}
831
+		// they haven't set the timezone string, so let's return a string like "UTC+1"
832
+		$gmt_offset = get_option('gmt_offset');
833
+		$prefix     = (int) $gmt_offset >= 0 ? '+' : '';
834
+		$parts      = explode('.', (string) $gmt_offset);
835
+		if (count($parts) === 1) {
836
+			$parts[1] = '00';
837
+		} else {
838
+			// convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
839
+			// to minutes, eg 30 or 15, respectively
840
+			$hour_fraction = (float) ('0.' . $parts[1]);
841
+			$parts[1]      = (string) $hour_fraction * 60;
842
+		}
843
+		return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
844
+	}
845 845
 
846 846
 
847 847
 
848
-    /**
849
-     * So PHP does this awesome thing where if you are trying to get a timestamp
850
-     * for a month using a string like "February" or "February 2017",
851
-     * and you don't specify a day as part of your string,
852
-     * then PHP will use whatever the current day of the month is.
853
-     * IF the current day of the month happens to be the 30th or 31st,
854
-     * then PHP gets really confused by a date like February 30,
855
-     * so instead of saying
856
-     *      "Hey February only has 28 days (this year)...
857
-     *      ...you must have meant the last day of the month!"
858
-     * PHP does the next most logical thing, and bumps the date up to March 2nd,
859
-     * because someone requesting February 30th obviously meant March 1st!
860
-     * The way around this is to always set the day to the first,
861
-     * so that the month will stay on the month you wanted.
862
-     * this method will add that "1" into your date regardless of the format.
863
-     *
864
-     * @param string $month
865
-     * @return string
866
-     */
867
-    public static function first_of_month_timestamp($month = '')
868
-    {
869
-        $month = (string) $month;
870
-        $year  = '';
871
-        // check if the incoming string has a year in it or not
872
-        if (preg_match('/\b\d{4}\b/', $month, $matches)) {
873
-            $year = $matches[0];
874
-            // ten remove that from the month string as well as any spaces
875
-            $month = trim(str_replace($year, '', $month));
876
-            // add a space before the year
877
-            $year = " {$year}";
878
-        }
879
-        // return timestamp for something like "February 1 2017"
880
-        return strtotime("{$month} 1{$year}");
881
-    }
848
+	/**
849
+	 * So PHP does this awesome thing where if you are trying to get a timestamp
850
+	 * for a month using a string like "February" or "February 2017",
851
+	 * and you don't specify a day as part of your string,
852
+	 * then PHP will use whatever the current day of the month is.
853
+	 * IF the current day of the month happens to be the 30th or 31st,
854
+	 * then PHP gets really confused by a date like February 30,
855
+	 * so instead of saying
856
+	 *      "Hey February only has 28 days (this year)...
857
+	 *      ...you must have meant the last day of the month!"
858
+	 * PHP does the next most logical thing, and bumps the date up to March 2nd,
859
+	 * because someone requesting February 30th obviously meant March 1st!
860
+	 * The way around this is to always set the day to the first,
861
+	 * so that the month will stay on the month you wanted.
862
+	 * this method will add that "1" into your date regardless of the format.
863
+	 *
864
+	 * @param string $month
865
+	 * @return string
866
+	 */
867
+	public static function first_of_month_timestamp($month = '')
868
+	{
869
+		$month = (string) $month;
870
+		$year  = '';
871
+		// check if the incoming string has a year in it or not
872
+		if (preg_match('/\b\d{4}\b/', $month, $matches)) {
873
+			$year = $matches[0];
874
+			// ten remove that from the month string as well as any spaces
875
+			$month = trim(str_replace($year, '', $month));
876
+			// add a space before the year
877
+			$year = " {$year}";
878
+		}
879
+		// return timestamp for something like "February 1 2017"
880
+		return strtotime("{$month} 1{$year}");
881
+	}
882 882
 
883 883
 
884
-    /**
885
-     * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
886
-     * for this sites timezone, but the timestamp could be some other time GMT.
887
-     */
888
-    public static function tomorrow()
889
-    {
890
-        // The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
891
-        // before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
892
-        // not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
893
-        // final timestamp is equivalent to midnight in this timezone as represented in GMT.
894
-        return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
895
-    }
884
+	/**
885
+	 * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
886
+	 * for this sites timezone, but the timestamp could be some other time GMT.
887
+	 */
888
+	public static function tomorrow()
889
+	{
890
+		// The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
891
+		// before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
892
+		// not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
893
+		// final timestamp is equivalent to midnight in this timezone as represented in GMT.
894
+		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
895
+	}
896 896
 
897 897
 
898
-    /**
899
-     * **
900
-     * Gives a nicely-formatted list of timezone strings.
901
-     * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
902
-     *
903
-     * @since     4.9.40.rc.008
904
-     * @staticvar bool $mo_loaded
905
-     * @staticvar string $locale_loaded
906
-     * @param string $selected_zone Selected timezone.
907
-     * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
908
-     * @return string
909
-     */
910
-    public static function wp_timezone_choice($selected_zone, $locale = null)
911
-    {
912
-        static $mo_loaded = false, $locale_loaded = null;
913
-        $continents = array(
914
-            'Africa',
915
-            'America',
916
-            'Antarctica',
917
-            'Arctic',
918
-            'Asia',
919
-            'Atlantic',
920
-            'Australia',
921
-            'Europe',
922
-            'Indian',
923
-            'Pacific',
924
-        );
925
-        // Load translations for continents and cities.
926
-        if (! $mo_loaded || $locale !== $locale_loaded) {
927
-            $locale_loaded = $locale ? $locale : get_locale();
928
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
929
-            unload_textdomain('continents-cities');
930
-            load_textdomain('continents-cities', $mofile);
931
-            $mo_loaded = true;
932
-        }
933
-        $zone_data = array();
934
-        foreach (timezone_identifiers_list() as $zone) {
935
-            $zone = explode('/', $zone);
936
-            if (! in_array($zone[0], $continents, true)) {
937
-                continue;
938
-            }
939
-            // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
940
-            $exists      = array(
941
-                0 => isset($zone[0]) && $zone[0],
942
-                1 => isset($zone[1]) && $zone[1],
943
-                2 => isset($zone[2]) && $zone[2],
944
-            );
945
-            $exists[3]   = $exists[0] && $zone[0] !== 'Etc';
946
-            $exists[4]   = $exists[1] && $exists[3];
947
-            $exists[5]   = $exists[2] && $exists[3];
948
-            // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
949
-            // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
950
-            // disabled because this code is copied from WordPress and is a WordPress domain
951
-            $zone_data[] = array(
952
-                'continent'   => $exists[0] ? $zone[0] : '',
953
-                'city'        => $exists[1] ? $zone[1] : '',
954
-                'subcity'     => $exists[2] ? $zone[2] : '',
955
-                't_continent' => $exists[3]
956
-                    ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities')
957
-                    : '',
958
-                't_city'      => $exists[4]
959
-                    ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities')
960
-                    : '',
961
-                't_subcity'   => $exists[5]
962
-                    ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities')
963
-                    : '',
964
-            );
965
-            // phpcs:enable
966
-        }
967
-        usort($zone_data, '_wp_timezone_choice_usort_callback');
968
-        $structure = array();
969
-        if (empty($selected_zone)) {
970
-            $structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>';
971
-        }
972
-        foreach ($zone_data as $key => $zone) {
973
-            // Build value in an array to join later
974
-            $value = array($zone['continent']);
975
-            if (empty($zone['city'])) {
976
-                // It's at the continent level (generally won't happen)
977
-                $display = $zone['t_continent'];
978
-            } else {
979
-                // It's inside a continent group
980
-                // Continent optgroup
981
-                if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
982
-                    $label       = $zone['t_continent'];
983
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
984
-                }
985
-                // Add the city to the value
986
-                $value[] = $zone['city'];
987
-                $display = $zone['t_city'];
988
-                if (! empty($zone['subcity'])) {
989
-                    // Add the subcity to the value
990
-                    $value[] = $zone['subcity'];
991
-                    $display .= ' - ' . $zone['t_subcity'];
992
-                }
993
-            }
994
-            // Build the value
995
-            $value       = implode('/', $value);
996
-            $selected    = $value === $selected_zone ? ' selected="selected"' : '';
997
-            $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
998
-                           . esc_html($display)
999
-                           . '</option>';
1000
-            // Close continent optgroup
1001
-            if (
1002
-                ! empty($zone['city'])
1003
-                && (
1004
-                    ! isset($zone_data[ $key + 1 ])
1005
-                    || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
1006
-                )
1007
-            ) {
1008
-                $structure[] = '</optgroup>';
1009
-            }
1010
-        }
1011
-        return implode("\n", $structure);
1012
-    }
898
+	/**
899
+	 * **
900
+	 * Gives a nicely-formatted list of timezone strings.
901
+	 * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
902
+	 *
903
+	 * @since     4.9.40.rc.008
904
+	 * @staticvar bool $mo_loaded
905
+	 * @staticvar string $locale_loaded
906
+	 * @param string $selected_zone Selected timezone.
907
+	 * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
908
+	 * @return string
909
+	 */
910
+	public static function wp_timezone_choice($selected_zone, $locale = null)
911
+	{
912
+		static $mo_loaded = false, $locale_loaded = null;
913
+		$continents = array(
914
+			'Africa',
915
+			'America',
916
+			'Antarctica',
917
+			'Arctic',
918
+			'Asia',
919
+			'Atlantic',
920
+			'Australia',
921
+			'Europe',
922
+			'Indian',
923
+			'Pacific',
924
+		);
925
+		// Load translations for continents and cities.
926
+		if (! $mo_loaded || $locale !== $locale_loaded) {
927
+			$locale_loaded = $locale ? $locale : get_locale();
928
+			$mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
929
+			unload_textdomain('continents-cities');
930
+			load_textdomain('continents-cities', $mofile);
931
+			$mo_loaded = true;
932
+		}
933
+		$zone_data = array();
934
+		foreach (timezone_identifiers_list() as $zone) {
935
+			$zone = explode('/', $zone);
936
+			if (! in_array($zone[0], $continents, true)) {
937
+				continue;
938
+			}
939
+			// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
940
+			$exists      = array(
941
+				0 => isset($zone[0]) && $zone[0],
942
+				1 => isset($zone[1]) && $zone[1],
943
+				2 => isset($zone[2]) && $zone[2],
944
+			);
945
+			$exists[3]   = $exists[0] && $zone[0] !== 'Etc';
946
+			$exists[4]   = $exists[1] && $exists[3];
947
+			$exists[5]   = $exists[2] && $exists[3];
948
+			// phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText
949
+			// phpcs:disable WordPress.WP.I18n.TextDomainMismatch
950
+			// disabled because this code is copied from WordPress and is a WordPress domain
951
+			$zone_data[] = array(
952
+				'continent'   => $exists[0] ? $zone[0] : '',
953
+				'city'        => $exists[1] ? $zone[1] : '',
954
+				'subcity'     => $exists[2] ? $zone[2] : '',
955
+				't_continent' => $exists[3]
956
+					? translate(str_replace('_', ' ', $zone[0]), 'continents-cities')
957
+					: '',
958
+				't_city'      => $exists[4]
959
+					? translate(str_replace('_', ' ', $zone[1]), 'continents-cities')
960
+					: '',
961
+				't_subcity'   => $exists[5]
962
+					? translate(str_replace('_', ' ', $zone[2]), 'continents-cities')
963
+					: '',
964
+			);
965
+			// phpcs:enable
966
+		}
967
+		usort($zone_data, '_wp_timezone_choice_usort_callback');
968
+		$structure = array();
969
+		if (empty($selected_zone)) {
970
+			$structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>';
971
+		}
972
+		foreach ($zone_data as $key => $zone) {
973
+			// Build value in an array to join later
974
+			$value = array($zone['continent']);
975
+			if (empty($zone['city'])) {
976
+				// It's at the continent level (generally won't happen)
977
+				$display = $zone['t_continent'];
978
+			} else {
979
+				// It's inside a continent group
980
+				// Continent optgroup
981
+				if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
982
+					$label       = $zone['t_continent'];
983
+					$structure[] = '<optgroup label="' . esc_attr($label) . '">';
984
+				}
985
+				// Add the city to the value
986
+				$value[] = $zone['city'];
987
+				$display = $zone['t_city'];
988
+				if (! empty($zone['subcity'])) {
989
+					// Add the subcity to the value
990
+					$value[] = $zone['subcity'];
991
+					$display .= ' - ' . $zone['t_subcity'];
992
+				}
993
+			}
994
+			// Build the value
995
+			$value       = implode('/', $value);
996
+			$selected    = $value === $selected_zone ? ' selected="selected"' : '';
997
+			$structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
998
+						   . esc_html($display)
999
+						   . '</option>';
1000
+			// Close continent optgroup
1001
+			if (
1002
+				! empty($zone['city'])
1003
+				&& (
1004
+					! isset($zone_data[ $key + 1 ])
1005
+					|| (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
1006
+				)
1007
+			) {
1008
+				$structure[] = '</optgroup>';
1009
+			}
1010
+		}
1011
+		return implode("\n", $structure);
1012
+	}
1013 1013
 
1014 1014
 
1015
-    /**
1016
-     * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1017
-     *
1018
-     * @param int|WP_User $user_id
1019
-     * @return string
1020
-     */
1021
-    public static function get_user_locale($user_id = 0)
1022
-    {
1023
-        if (function_exists('get_user_locale')) {
1024
-            return get_user_locale($user_id);
1025
-        }
1026
-        return get_locale();
1027
-    }
1015
+	/**
1016
+	 * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1017
+	 *
1018
+	 * @param int|WP_User $user_id
1019
+	 * @return string
1020
+	 */
1021
+	public static function get_user_locale($user_id = 0)
1022
+	{
1023
+		if (function_exists('get_user_locale')) {
1024
+			return get_user_locale($user_id);
1025
+		}
1026
+		return get_locale();
1027
+	}
1028 1028
 
1029 1029
 
1030
-    /**
1031
-     * Return the appropriate helper adapter for DTT related things.
1032
-     *
1033
-     * @return HelperInterface
1034
-     * @throws InvalidArgumentException
1035
-     * @throws InvalidDataTypeException
1036
-     * @throws InvalidInterfaceException
1037
-     */
1038
-    private static function getHelperAdapter()
1039
-    {
1040
-        $dtt_helper_fqcn = PHP_VERSION_ID < 50600
1041
-            ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
1042
-            : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper';
1043
-        return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn);
1044
-    }
1030
+	/**
1031
+	 * Return the appropriate helper adapter for DTT related things.
1032
+	 *
1033
+	 * @return HelperInterface
1034
+	 * @throws InvalidArgumentException
1035
+	 * @throws InvalidDataTypeException
1036
+	 * @throws InvalidInterfaceException
1037
+	 */
1038
+	private static function getHelperAdapter()
1039
+	{
1040
+		$dtt_helper_fqcn = PHP_VERSION_ID < 50600
1041
+			? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
1042
+			: 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper';
1043
+		return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn);
1044
+	}
1045 1045
 
1046 1046
 
1047
-    /**
1048
-     * Helper function for setting the timezone on a DateTime object.
1049
-     * This is implemented to standardize a workaround for a PHP bug outlined in
1050
-     * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and
1051
-     * https://events.codebasehq.com/projects/event-espresso/tickets/11233
1052
-     *
1053
-     * @param DateTime     $datetime
1054
-     * @param DateTimeZone $timezone
1055
-     */
1056
-    public static function setTimezone(DateTime $datetime, DateTimeZone $timezone)
1057
-    {
1058
-        $datetime->setTimezone($timezone);
1059
-        $datetime->getTimestamp();
1060
-    }
1047
+	/**
1048
+	 * Helper function for setting the timezone on a DateTime object.
1049
+	 * This is implemented to standardize a workaround for a PHP bug outlined in
1050
+	 * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and
1051
+	 * https://events.codebasehq.com/projects/event-espresso/tickets/11233
1052
+	 *
1053
+	 * @param DateTime     $datetime
1054
+	 * @param DateTimeZone $timezone
1055
+	 */
1056
+	public static function setTimezone(DateTime $datetime, DateTimeZone $timezone)
1057
+	{
1058
+		$datetime->setTimezone($timezone);
1059
+		$datetime->getTimestamp();
1060
+	}
1061 1061
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
133 133
     {
134
-        $gmt_offset =  (int) $gmt_offset;
134
+        $gmt_offset = (int) $gmt_offset;
135 135
         /** @var array[] $abbreviations */
136 136
         $abbreviations = DateTimeZone::listAbbreviations();
137 137
         foreach ($abbreviations as $abbreviation) {
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      */
327 327
     protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
328 328
     {
329
-        if (! $DateTime instanceof DateTime) {
329
+        if ( ! $DateTime instanceof DateTime) {
330 330
             throw new EE_Error(
331 331
                 sprintf(
332 332
                     esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
@@ -336,25 +336,25 @@  discard block
 block discarded – undo
336 336
         }
337 337
         switch ($period) {
338 338
             case 'years':
339
-                $value = 'P' . $value . 'Y';
339
+                $value = 'P'.$value.'Y';
340 340
                 break;
341 341
             case 'months':
342
-                $value = 'P' . $value . 'M';
342
+                $value = 'P'.$value.'M';
343 343
                 break;
344 344
             case 'weeks':
345
-                $value = 'P' . $value . 'W';
345
+                $value = 'P'.$value.'W';
346 346
                 break;
347 347
             case 'days':
348
-                $value = 'P' . $value . 'D';
348
+                $value = 'P'.$value.'D';
349 349
                 break;
350 350
             case 'hours':
351
-                $value = 'PT' . $value . 'H';
351
+                $value = 'PT'.$value.'H';
352 352
                 break;
353 353
             case 'minutes':
354
-                $value = 'PT' . $value . 'M';
354
+                $value = 'PT'.$value.'M';
355 355
                 break;
356 356
             case 'seconds':
357
-                $value = 'PT' . $value . 'S';
357
+                $value = 'PT'.$value.'S';
358 358
                 break;
359 359
         }
360 360
         switch ($operand) {
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
      */
383 383
     protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
384 384
     {
385
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
385
+        if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
386 386
             throw new EE_Error(
387 387
                 sprintf(
388 388
                     esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
                 'date' => $date_format['js'],
496 496
                 'time' => $time_format['js'],
497 497
             ),
498
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
498
+            'moment' => $date_format['moment'].' '.$time_format['moment'],
499 499
             'moment_split' => array(
500 500
                 'date' => $date_format['moment'],
501 501
                 'time' => $time_format['moment']
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
          *
519 519
          * @var array
520 520
          */
521
-        $symbols_map          = array(
521
+        $symbols_map = array(
522 522
             // Day
523 523
             // 01
524 524
             'd' => array(
@@ -670,26 +670,26 @@  discard block
 block discarded – undo
670 670
         $escaping             = false;
671 671
         $format_string_length = strlen($format_string);
672 672
         for ($i = 0; $i < $format_string_length; $i++) {
673
-            $char = $format_string[ $i ];
673
+            $char = $format_string[$i];
674 674
             if ($char === '\\') { // PHP date format escaping character
675 675
                 $i++;
676 676
                 if ($escaping) {
677
-                    $jquery_ui_format .= $format_string[ $i ];
678
-                    $moment_format    .= $format_string[ $i ];
677
+                    $jquery_ui_format .= $format_string[$i];
678
+                    $moment_format    .= $format_string[$i];
679 679
                 } else {
680
-                    $jquery_ui_format .= '\'' . $format_string[ $i ];
681
-                    $moment_format    .= $format_string[ $i ];
680
+                    $jquery_ui_format .= '\''.$format_string[$i];
681
+                    $moment_format    .= $format_string[$i];
682 682
                 }
683 683
                 $escaping = true;
684 684
             } else {
685 685
                 if ($escaping) {
686 686
                     $jquery_ui_format .= "'";
687 687
                     $moment_format    .= "'";
688
-                    $escaping         = false;
688
+                    $escaping = false;
689 689
                 }
690
-                if (isset($symbols_map[ $char ])) {
691
-                    $jquery_ui_format .= $symbols_map[ $char ]['js'];
692
-                    $moment_format    .= $symbols_map[ $char ]['moment'];
690
+                if (isset($symbols_map[$char])) {
691
+                    $jquery_ui_format .= $symbols_map[$char]['js'];
692
+                    $moment_format    .= $symbols_map[$char]['moment'];
693 693
                 } else {
694 694
                     $jquery_ui_format .= $char;
695 695
                     $moment_format    .= $char;
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
     {
748 748
 
749 749
         if (
750
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
750
+            ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
751 751
             || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
752 752
                 || $date_2->format(
753 753
                     EE_Datetime_Field::mysql_time_format
@@ -783,8 +783,8 @@  discard block
 block discarded – undo
783 783
             ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
784 784
             : (float) get_option('gmt_offset');
785 785
         $query_interval = $offset < 0
786
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
787
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
786
+            ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)'
787
+            : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)';
788 788
         return $query_interval;
789 789
     }
790 790
 
@@ -801,16 +801,16 @@  discard block
 block discarded – undo
801 801
     public static function get_timezone_string_for_display()
802 802
     {
803 803
         $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
804
-        if (! empty($pretty_timezone)) {
804
+        if ( ! empty($pretty_timezone)) {
805 805
             return esc_html($pretty_timezone);
806 806
         }
807 807
         $timezone_string = get_option('timezone_string');
808 808
         if ($timezone_string) {
809 809
             static $mo_loaded = false;
810 810
             // Load translations for continents and cities just like wp_timezone_choice does
811
-            if (! $mo_loaded) {
811
+            if ( ! $mo_loaded) {
812 812
                 $locale = get_locale();
813
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
813
+                $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo';
814 814
                 load_textdomain('continents-cities', $mofile);
815 815
                 $mo_loaded = true;
816 816
             }
@@ -837,10 +837,10 @@  discard block
 block discarded – undo
837 837
         } else {
838 838
             // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
839 839
             // to minutes, eg 30 or 15, respectively
840
-            $hour_fraction = (float) ('0.' . $parts[1]);
840
+            $hour_fraction = (float) ('0.'.$parts[1]);
841 841
             $parts[1]      = (string) $hour_fraction * 60;
842 842
         }
843
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
843
+        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts));
844 844
     }
845 845
 
846 846
 
@@ -923,9 +923,9 @@  discard block
 block discarded – undo
923 923
             'Pacific',
924 924
         );
925 925
         // Load translations for continents and cities.
926
-        if (! $mo_loaded || $locale !== $locale_loaded) {
926
+        if ( ! $mo_loaded || $locale !== $locale_loaded) {
927 927
             $locale_loaded = $locale ? $locale : get_locale();
928
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
928
+            $mofile        = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo';
929 929
             unload_textdomain('continents-cities');
930 930
             load_textdomain('continents-cities', $mofile);
931 931
             $mo_loaded = true;
@@ -933,11 +933,11 @@  discard block
 block discarded – undo
933 933
         $zone_data = array();
934 934
         foreach (timezone_identifiers_list() as $zone) {
935 935
             $zone = explode('/', $zone);
936
-            if (! in_array($zone[0], $continents, true)) {
936
+            if ( ! in_array($zone[0], $continents, true)) {
937 937
                 continue;
938 938
             }
939 939
             // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
940
-            $exists      = array(
940
+            $exists = array(
941 941
                 0 => isset($zone[0]) && $zone[0],
942 942
                 1 => isset($zone[1]) && $zone[1],
943 943
                 2 => isset($zone[2]) && $zone[2],
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
         usort($zone_data, '_wp_timezone_choice_usort_callback');
968 968
         $structure = array();
969 969
         if (empty($selected_zone)) {
970
-            $structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>';
970
+            $structure[] = '<option selected="selected" value="">'.__('Select a city', 'event_espresso').'</option>';
971 971
         }
972 972
         foreach ($zone_data as $key => $zone) {
973 973
             // Build value in an array to join later
@@ -978,31 +978,31 @@  discard block
 block discarded – undo
978 978
             } else {
979 979
                 // It's inside a continent group
980 980
                 // Continent optgroup
981
-                if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
981
+                if ( ! isset($zone_data[$key - 1]) || $zone_data[$key - 1]['continent'] !== $zone['continent']) {
982 982
                     $label       = $zone['t_continent'];
983
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
983
+                    $structure[] = '<optgroup label="'.esc_attr($label).'">';
984 984
                 }
985 985
                 // Add the city to the value
986 986
                 $value[] = $zone['city'];
987 987
                 $display = $zone['t_city'];
988
-                if (! empty($zone['subcity'])) {
988
+                if ( ! empty($zone['subcity'])) {
989 989
                     // Add the subcity to the value
990 990
                     $value[] = $zone['subcity'];
991
-                    $display .= ' - ' . $zone['t_subcity'];
991
+                    $display .= ' - '.$zone['t_subcity'];
992 992
                 }
993 993
             }
994 994
             // Build the value
995 995
             $value       = implode('/', $value);
996 996
             $selected    = $value === $selected_zone ? ' selected="selected"' : '';
997
-            $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
997
+            $structure[] = '<option value="'.esc_attr($value).'"'.$selected.'>'
998 998
                            . esc_html($display)
999 999
                            . '</option>';
1000 1000
             // Close continent optgroup
1001 1001
             if (
1002 1002
                 ! empty($zone['city'])
1003 1003
                 && (
1004
-                    ! isset($zone_data[ $key + 1 ])
1005
-                    || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
1004
+                    ! isset($zone_data[$key + 1])
1005
+                    || (isset($zone_data[$key + 1]) && $zone_data[$key + 1]['continent'] !== $zone['continent'])
1006 1006
                 )
1007 1007
             ) {
1008 1008
                 $structure[] = '</optgroup>';
Please login to merge, or discard this patch.
core/services/helpers/datetime/HelperInterface.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -16,94 +16,94 @@
 block discarded – undo
16 16
 interface HelperInterface
17 17
 {
18 18
 
19
-    /**
20
-     * Ensures that a valid timezone string is returned.
21
-     *
22
-     * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
23
-     *                                 settings (or derive from set UTC offset).
24
-     * @return string
25
-     */
26
-    public function getValidTimezoneString($timezone_string = '');
27
-
28
-
29
-    /**
30
-     * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
31
-     *
32
-     * @param string $timezone_string
33
-     * @param bool   $throw_error
34
-     * @return bool
35
-     */
36
-    public function validateTimezone($timezone_string, $throw_error = true);
37
-
38
-
39
-    /**
40
-     * Returns a timezone string for the provided gmt_offset.
41
-     * @param float|string $gmt_offset
42
-     * @return string
43
-     */
44
-    public function getTimezoneStringFromGmtOffset($gmt_offset = '');
45
-
46
-
47
-    /**
48
-     * Gets the site's GMT offset based on either the timezone string
49
-     * (in which case the gmt offset will vary depending on the location's
50
-     * observance of daylight savings time) or the gmt_offset wp option
51
-     *
52
-     * @return int  seconds offset
53
-     */
54
-    public function getSiteTimezoneGmtOffset();
55
-
56
-
57
-    /**
58
-     * Get timezone transitions
59
-     * @param DateTimeZone $date_time_zone
60
-     * @param int|null     $time
61
-     * @param bool         $first_only
62
-     * @return array
63
-     */
64
-    public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true);
65
-
66
-
67
-    /**
68
-     * Get Timezone offset for given timezone object
69
-     * @param DateTimeZone $date_time_zone
70
-     * @param null|int         $time
71
-     * @return int
72
-     */
73
-    public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null);
74
-
75
-
76
-    /**
77
-     * Provide a timezone select input
78
-     * @param string $timezone_string
79
-     * @return string
80
-     */
81
-    public function timezoneSelectInput($timezone_string = '');
82
-
83
-
84
-    /**
85
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
86
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
87
-     * the site is used.
88
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
89
-     * computed timestamp (i.e. date_i18n() )
90
-     *
91
-     * @param int    $unix_timestamp    if 0, then time() will be used.
92
-     * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
93
-     *                                site will be used.
94
-     * @return int      unix_timestamp value with the offset applied for the given timezone.
95
-     */
96
-    public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '');
97
-
98
-
99
-    /**
100
-     * Depending on PHP version,
101
-     * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
102
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
103
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
104
-     *
105
-     * @param int $gmt_offset
106
-     * @return int
107
-     */
108
-    public function adjustInvalidGmtOffsets($gmt_offset);
19
+	/**
20
+	 * Ensures that a valid timezone string is returned.
21
+	 *
22
+	 * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
23
+	 *                                 settings (or derive from set UTC offset).
24
+	 * @return string
25
+	 */
26
+	public function getValidTimezoneString($timezone_string = '');
27
+
28
+
29
+	/**
30
+	 * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
31
+	 *
32
+	 * @param string $timezone_string
33
+	 * @param bool   $throw_error
34
+	 * @return bool
35
+	 */
36
+	public function validateTimezone($timezone_string, $throw_error = true);
37
+
38
+
39
+	/**
40
+	 * Returns a timezone string for the provided gmt_offset.
41
+	 * @param float|string $gmt_offset
42
+	 * @return string
43
+	 */
44
+	public function getTimezoneStringFromGmtOffset($gmt_offset = '');
45
+
46
+
47
+	/**
48
+	 * Gets the site's GMT offset based on either the timezone string
49
+	 * (in which case the gmt offset will vary depending on the location's
50
+	 * observance of daylight savings time) or the gmt_offset wp option
51
+	 *
52
+	 * @return int  seconds offset
53
+	 */
54
+	public function getSiteTimezoneGmtOffset();
55
+
56
+
57
+	/**
58
+	 * Get timezone transitions
59
+	 * @param DateTimeZone $date_time_zone
60
+	 * @param int|null     $time
61
+	 * @param bool         $first_only
62
+	 * @return array
63
+	 */
64
+	public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true);
65
+
66
+
67
+	/**
68
+	 * Get Timezone offset for given timezone object
69
+	 * @param DateTimeZone $date_time_zone
70
+	 * @param null|int         $time
71
+	 * @return int
72
+	 */
73
+	public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null);
74
+
75
+
76
+	/**
77
+	 * Provide a timezone select input
78
+	 * @param string $timezone_string
79
+	 * @return string
80
+	 */
81
+	public function timezoneSelectInput($timezone_string = '');
82
+
83
+
84
+	/**
85
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
86
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
87
+	 * the site is used.
88
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
89
+	 * computed timestamp (i.e. date_i18n() )
90
+	 *
91
+	 * @param int    $unix_timestamp    if 0, then time() will be used.
92
+	 * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
93
+	 *                                site will be used.
94
+	 * @return int      unix_timestamp value with the offset applied for the given timezone.
95
+	 */
96
+	public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '');
97
+
98
+
99
+	/**
100
+	 * Depending on PHP version,
101
+	 * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
102
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
103
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
104
+	 *
105
+	 * @param int $gmt_offset
106
+	 * @return int
107
+	 */
108
+	public function adjustInvalidGmtOffsets($gmt_offset);
109 109
 }
Please login to merge, or discard this patch.
core/domain/values/Url.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function setScheme($url)
93 93
     {
94
-        $this->scheme = $url['scheme'] . '://';
94
+        $this->scheme = $url['scheme'].'://';
95 95
     }
96 96
 
97 97
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      */
146 146
     public function queryString()
147 147
     {
148
-        return $this->query !== '' ? '?' . $this->query : '';
148
+        return $this->query !== '' ? '?'.$this->query : '';
149 149
     }
150 150
 
151 151
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function fragment()
180 180
     {
181
-        return $this->fragment !== '' ? '#' . $this->fragment : '';
181
+        return $this->fragment !== '' ? '#'.$this->fragment : '';
182 182
     }
183 183
 
184 184
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     public function getFullUrl()
201 201
     {
202
-        return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment();
202
+        return $this->scheme().$this->host().$this->path().$this->queryString().$this->fragment();
203 203
     }
204 204
 
205 205
 
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -17,200 +17,200 @@
 block discarded – undo
17 17
 class Url
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $scheme
22
-     */
23
-    private $scheme;
24
-
25
-    /**
26
-     * @var string $host
27
-     */
28
-    private $host;
29
-
30
-    /**
31
-     * @var string $path
32
-     */
33
-    private $path;
34
-
35
-    /**
36
-     * @var string $query
37
-     */
38
-    private $query;
39
-
40
-    /**
41
-     * @var string $fragment
42
-     */
43
-    private $fragment;
44
-
45
-
46
-    /**
47
-     * Url constructor.
48
-     *
49
-     * @param $url
50
-     * @throws InvalidArgumentException
51
-     */
52
-    public function __construct($url)
53
-    {
54
-        if (
55
-            ! filter_var(
56
-                $url,
57
-                FILTER_VALIDATE_URL,
58
-                array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED)
59
-            )
60
-        ) {
61
-            throw new InvalidArgumentException(
62
-                esc_html__(
63
-                    'Invalid URL. Both the "Scheme" and "Host" are required.',
64
-                    'event_espresso'
65
-                )
66
-            );
67
-        }
68
-        $url = parse_url($url);
69
-        $this->setScheme($url);
70
-        $this->setHost($url);
71
-        $this->setPath($url);
72
-        $this->setQuery($url);
73
-        $this->setFragment($url);
74
-    }
75
-
76
-
77
-    /**
78
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
79
-     * will return a string like: 'abc://'
80
-     *
81
-     * @return string
82
-     */
83
-    public function scheme()
84
-    {
85
-        return $this->scheme;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param array $url
91
-     */
92
-    private function setScheme($url)
93
-    {
94
-        $this->scheme = $url['scheme'] . '://';
95
-    }
96
-
97
-
98
-    /**
99
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
100
-     * will return a string like: 'example.com'
101
-     *
102
-     * @return string
103
-     */
104
-    public function host()
105
-    {
106
-        return $this->host;
107
-    }
108
-
109
-
110
-    /**
111
-     * @param array $url
112
-     */
113
-    private function setHost($url)
114
-    {
115
-        $this->host = $url['host'];
116
-    }
117
-
118
-
119
-    /**
120
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
121
-     * will return a string like: '/path/data'
122
-     *
123
-     * @return string
124
-     */
125
-    public function path()
126
-    {
127
-        return $this->path;
128
-    }
129
-
130
-
131
-    /**
132
-     * @param array $url
133
-     */
134
-    private function setPath($url)
135
-    {
136
-        $this->path = isset($url['path']) ? $url['path'] : '';
137
-    }
138
-
139
-
140
-    /**
141
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
142
-     * will return a string like: '?key=value'
143
-     *
144
-     * @return string
145
-     */
146
-    public function queryString()
147
-    {
148
-        return $this->query !== '' ? '?' . $this->query : '';
149
-    }
150
-
151
-
152
-    /**
153
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
154
-     * will return an array like: array('key' => 'value')
155
-     *
156
-     * @return array
157
-     */
158
-    public function queryParams()
159
-    {
160
-        return wp_parse_args($this->query);
161
-    }
162
-
163
-
164
-    /**
165
-     * @param array $url
166
-     */
167
-    private function setQuery($url)
168
-    {
169
-        $this->query = isset($url['query']) ? $url['query'] : '';
170
-    }
171
-
172
-
173
-    /**
174
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
175
-     * will return a string like: '#id'
176
-     *
177
-     * @return string
178
-     */
179
-    public function fragment()
180
-    {
181
-        return $this->fragment !== '' ? '#' . $this->fragment : '';
182
-    }
183
-
184
-
185
-    /**
186
-     * @param array $url
187
-     */
188
-    private function setFragment($url)
189
-    {
190
-        $this->fragment = isset($url['fragment']) ? $url['fragment'] : '';
191
-    }
192
-
193
-
194
-    /**
195
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
196
-     * will return a string like: 'abc://example.com/path/data?key=value#id'
197
-     *
198
-     * @return string
199
-     */
200
-    public function getFullUrl()
201
-    {
202
-        return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment();
203
-    }
204
-
205
-
206
-    /**
207
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
208
-     * will return a string like: 'abc://example.com/path/data?key=value#id'
209
-     *
210
-     * @return string
211
-     */
212
-    public function __toString()
213
-    {
214
-        return $this->getFullUrl();
215
-    }
20
+	/**
21
+	 * @var string $scheme
22
+	 */
23
+	private $scheme;
24
+
25
+	/**
26
+	 * @var string $host
27
+	 */
28
+	private $host;
29
+
30
+	/**
31
+	 * @var string $path
32
+	 */
33
+	private $path;
34
+
35
+	/**
36
+	 * @var string $query
37
+	 */
38
+	private $query;
39
+
40
+	/**
41
+	 * @var string $fragment
42
+	 */
43
+	private $fragment;
44
+
45
+
46
+	/**
47
+	 * Url constructor.
48
+	 *
49
+	 * @param $url
50
+	 * @throws InvalidArgumentException
51
+	 */
52
+	public function __construct($url)
53
+	{
54
+		if (
55
+			! filter_var(
56
+				$url,
57
+				FILTER_VALIDATE_URL,
58
+				array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED)
59
+			)
60
+		) {
61
+			throw new InvalidArgumentException(
62
+				esc_html__(
63
+					'Invalid URL. Both the "Scheme" and "Host" are required.',
64
+					'event_espresso'
65
+				)
66
+			);
67
+		}
68
+		$url = parse_url($url);
69
+		$this->setScheme($url);
70
+		$this->setHost($url);
71
+		$this->setPath($url);
72
+		$this->setQuery($url);
73
+		$this->setFragment($url);
74
+	}
75
+
76
+
77
+	/**
78
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
79
+	 * will return a string like: 'abc://'
80
+	 *
81
+	 * @return string
82
+	 */
83
+	public function scheme()
84
+	{
85
+		return $this->scheme;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param array $url
91
+	 */
92
+	private function setScheme($url)
93
+	{
94
+		$this->scheme = $url['scheme'] . '://';
95
+	}
96
+
97
+
98
+	/**
99
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
100
+	 * will return a string like: 'example.com'
101
+	 *
102
+	 * @return string
103
+	 */
104
+	public function host()
105
+	{
106
+		return $this->host;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @param array $url
112
+	 */
113
+	private function setHost($url)
114
+	{
115
+		$this->host = $url['host'];
116
+	}
117
+
118
+
119
+	/**
120
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
121
+	 * will return a string like: '/path/data'
122
+	 *
123
+	 * @return string
124
+	 */
125
+	public function path()
126
+	{
127
+		return $this->path;
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param array $url
133
+	 */
134
+	private function setPath($url)
135
+	{
136
+		$this->path = isset($url['path']) ? $url['path'] : '';
137
+	}
138
+
139
+
140
+	/**
141
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
142
+	 * will return a string like: '?key=value'
143
+	 *
144
+	 * @return string
145
+	 */
146
+	public function queryString()
147
+	{
148
+		return $this->query !== '' ? '?' . $this->query : '';
149
+	}
150
+
151
+
152
+	/**
153
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
154
+	 * will return an array like: array('key' => 'value')
155
+	 *
156
+	 * @return array
157
+	 */
158
+	public function queryParams()
159
+	{
160
+		return wp_parse_args($this->query);
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param array $url
166
+	 */
167
+	private function setQuery($url)
168
+	{
169
+		$this->query = isset($url['query']) ? $url['query'] : '';
170
+	}
171
+
172
+
173
+	/**
174
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
175
+	 * will return a string like: '#id'
176
+	 *
177
+	 * @return string
178
+	 */
179
+	public function fragment()
180
+	{
181
+		return $this->fragment !== '' ? '#' . $this->fragment : '';
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param array $url
187
+	 */
188
+	private function setFragment($url)
189
+	{
190
+		$this->fragment = isset($url['fragment']) ? $url['fragment'] : '';
191
+	}
192
+
193
+
194
+	/**
195
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
196
+	 * will return a string like: 'abc://example.com/path/data?key=value#id'
197
+	 *
198
+	 * @return string
199
+	 */
200
+	public function getFullUrl()
201
+	{
202
+		return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment();
203
+	}
204
+
205
+
206
+	/**
207
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
208
+	 * will return a string like: 'abc://example.com/path/data?key=value#id'
209
+	 *
210
+	 * @return string
211
+	 */
212
+	public function __toString()
213
+	{
214
+		return $this->getFullUrl();
215
+	}
216 216
 }
Please login to merge, or discard this patch.