Completed
Branch db-repair-tool (e5ee69)
by
unknown
23:46 queued 16:15
created
modules/batch/templates/batch_wrapper.template.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,5 +4,5 @@
 block discarded – undo
4 4
 if( $batch_request_type == EED_Batch::batch_job ) {
5 5
 	require( 'batch_runner.template.php' );
6 6
 } elseif( $batch_request_type == EED_Batch::batch_file_job ) {
7
-    require( 'batch_file_runner.template.php' );
7
+	require( 'batch_file_runner.template.php' );
8 8
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 //just makes the template conditional on the batch request type
3 3
 $batch_request_type = EED_Batch::instance()->batch_request_type();
4
-if( $batch_request_type == EED_Batch::batch_job ) {
5
-	require( 'batch_runner.template.php' );
6
-} elseif( $batch_request_type == EED_Batch::batch_file_job ) {
7
-    require( 'batch_file_runner.template.php' );
4
+if ($batch_request_type == EED_Batch::batch_job) {
5
+	require('batch_runner.template.php');
6
+} elseif ($batch_request_type == EED_Batch::batch_file_job) {
7
+    require('batch_file_runner.template.php');
8 8
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Array.helper.php 2 patches
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -11,221 +11,221 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class EEH_Array extends EEH_Base
13 13
 {
14
-    /**
15
-     * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays
16
-     * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects
17
-     *
18
-     * @uses array_udiff core php function for setting up our own array comparison
19
-     * @uses self::_compare_objects as the custom method for array_udiff
20
-     * @param  array $array1 an array of objects
21
-     * @param  array $array2 an array of objects
22
-     * @return array         an array of objects found in array 1 that aren't found in array 2.
23
-     */
24
-    public static function object_array_diff($array1, $array2)
25
-    {
26
-        return array_udiff($array1, $array2, array('self', '_compare_objects'));
27
-    }
14
+	/**
15
+	 * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays
16
+	 * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects
17
+	 *
18
+	 * @uses array_udiff core php function for setting up our own array comparison
19
+	 * @uses self::_compare_objects as the custom method for array_udiff
20
+	 * @param  array $array1 an array of objects
21
+	 * @param  array $array2 an array of objects
22
+	 * @return array         an array of objects found in array 1 that aren't found in array 2.
23
+	 */
24
+	public static function object_array_diff($array1, $array2)
25
+	{
26
+		return array_udiff($array1, $array2, array('self', '_compare_objects'));
27
+	}
28 28
 
29
-    /**
30
-     * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed
31
-     *
32
-     * @param array $array
33
-     * @return boolean
34
-     */
35
-    public static function is_associative_array(array $array): bool
36
-    {
37
-        return ! empty($array) && array_keys($array) !== range(0, count($array) - 1);
38
-    }
29
+	/**
30
+	 * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed
31
+	 *
32
+	 * @param array $array
33
+	 * @return boolean
34
+	 */
35
+	public static function is_associative_array(array $array): bool
36
+	{
37
+		return ! empty($array) && array_keys($array) !== range(0, count($array) - 1);
38
+	}
39 39
 
40
-    /**
41
-     * Gets an item from the array and leave the array intact. Use in place of end()
42
-     * when you don't want to change the array
43
-     *
44
-     * @param array $arr
45
-     * @return mixed what ever is in the array
46
-     */
47
-    public static function get_one_item_from_array($arr)
48
-    {
49
-        $item = end($arr);
50
-        reset($arr);
51
-        return $item;
52
-    }
40
+	/**
41
+	 * Gets an item from the array and leave the array intact. Use in place of end()
42
+	 * when you don't want to change the array
43
+	 *
44
+	 * @param array $arr
45
+	 * @return mixed what ever is in the array
46
+	 */
47
+	public static function get_one_item_from_array($arr)
48
+	{
49
+		$item = end($arr);
50
+		reset($arr);
51
+		return $item;
52
+	}
53 53
 
54
-    /**
55
-     * Detects if this is a multi-dimensional array
56
-     * meaning that at least one top-level value is an array. Eg [ [], ...]
57
-     *
58
-     * @param mixed $arr
59
-     * @return boolean
60
-     */
61
-    public static function is_multi_dimensional_array($arr)
62
-    {
63
-        if (is_array($arr)) {
64
-            foreach ($arr as $item) {
65
-                if (is_array($item)) {
66
-                    return true; // yep, there's at least 2 levels to this array
67
-                }
68
-            }
69
-        }
70
-        return false; // there's only 1 level, or it's not an array at all!
71
-    }
54
+	/**
55
+	 * Detects if this is a multi-dimensional array
56
+	 * meaning that at least one top-level value is an array. Eg [ [], ...]
57
+	 *
58
+	 * @param mixed $arr
59
+	 * @return boolean
60
+	 */
61
+	public static function is_multi_dimensional_array($arr)
62
+	{
63
+		if (is_array($arr)) {
64
+			foreach ($arr as $item) {
65
+				if (is_array($item)) {
66
+					return true; // yep, there's at least 2 levels to this array
67
+				}
68
+			}
69
+		}
70
+		return false; // there's only 1 level, or it's not an array at all!
71
+	}
72 72
 
73
-    /**
74
-     * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default
75
-     *
76
-     * @param array $arr
77
-     * @param mixed $index
78
-     * @param mixed $default
79
-     * @return mixed
80
-     */
81
-    public static function is_set($arr, $index, $default)
82
-    {
83
-        return isset($arr[ $index ]) ? $arr[ $index ] : $default;
84
-    }
73
+	/**
74
+	 * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default
75
+	 *
76
+	 * @param array $arr
77
+	 * @param mixed $index
78
+	 * @param mixed $default
79
+	 * @return mixed
80
+	 */
81
+	public static function is_set($arr, $index, $default)
82
+	{
83
+		return isset($arr[ $index ]) ? $arr[ $index ] : $default;
84
+	}
85 85
 
86
-    /**
87
-     * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118
88
-     *
89
-     * @param mixed $value usually a string, but could be an array or object
90
-     * @return mixed the UN-serialized data
91
-     */
92
-    public static function maybe_unserialize($value)
93
-    {
94
-        $data = maybe_unserialize($value);
95
-        // it's possible that this still has serialized data if it's the session.
96
-        //  WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically.
97
-        $token = 'C';
98
-        $data = is_string($data) ? trim($data) : $data;
99
-        if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) {
100
-            return unserialize($data);
101
-        } else {
102
-            return $data;
103
-        }
104
-    }
86
+	/**
87
+	 * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118
88
+	 *
89
+	 * @param mixed $value usually a string, but could be an array or object
90
+	 * @return mixed the UN-serialized data
91
+	 */
92
+	public static function maybe_unserialize($value)
93
+	{
94
+		$data = maybe_unserialize($value);
95
+		// it's possible that this still has serialized data if it's the session.
96
+		//  WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically.
97
+		$token = 'C';
98
+		$data = is_string($data) ? trim($data) : $data;
99
+		if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) {
100
+			return unserialize($data);
101
+		} else {
102
+			return $data;
103
+		}
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * insert_into_array
109
-     *
110
-     * @param array        $target_array the array to insert new data into
111
-     * @param array        $array_to_insert the new data to be inserted
112
-     * @param int|string|null $offset a known key within $target_array where new data will be inserted
113
-     * @param bool         $add_before whether to add new data before or after the offset key
114
-     * @param bool         $preserve_keys whether or not to reset numerically indexed arrays
115
-     * @return array
116
-     */
117
-    public static function insert_into_array(
118
-        array $target_array = array(),
119
-        array $array_to_insert = array(),
120
-        $offset = null,
121
-        bool $add_before = true,
122
-        bool $preserve_keys = true
123
-    ) {
124
-        $target_array_keys = array_keys($target_array);
125
-        // if no offset key was supplied
126
-        if (empty($offset)) {
127
-            // use start or end of $target_array based on whether we are adding before or not
128
-            $offset = $add_before ? 0 : count($target_array);
129
-        }
130
-        // if offset key is a string, then find the corresponding numeric location for that element
131
-        $offset = is_int($offset) ? $offset : array_search($offset, $target_array_keys, true);
132
-        // add one to the offset if adding after
133
-        $offset = $add_before ? $offset : $offset + 1;
134
-        // but ensure offset does not exceed the length of the array
135
-        $offset = $offset > count($target_array) ? count($target_array) : $offset;
136
-        // reindex array ???
137
-        if ($preserve_keys) {
138
-            // take a slice of the target array from the beginning till the offset,
139
-            // then add the new data
140
-            // then add another slice that starts at the offset and goes till the end
141
-            return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice(
142
-                $target_array,
143
-                $offset,
144
-                null,
145
-                true
146
-            );
147
-        } else {
148
-            // since we don't want to preserve keys, we can use array_splice
149
-            array_splice($target_array, $offset, 0, $array_to_insert);
150
-            return $target_array;
151
-        }
152
-    }
107
+	/**
108
+	 * insert_into_array
109
+	 *
110
+	 * @param array        $target_array the array to insert new data into
111
+	 * @param array        $array_to_insert the new data to be inserted
112
+	 * @param int|string|null $offset a known key within $target_array where new data will be inserted
113
+	 * @param bool         $add_before whether to add new data before or after the offset key
114
+	 * @param bool         $preserve_keys whether or not to reset numerically indexed arrays
115
+	 * @return array
116
+	 */
117
+	public static function insert_into_array(
118
+		array $target_array = array(),
119
+		array $array_to_insert = array(),
120
+		$offset = null,
121
+		bool $add_before = true,
122
+		bool $preserve_keys = true
123
+	) {
124
+		$target_array_keys = array_keys($target_array);
125
+		// if no offset key was supplied
126
+		if (empty($offset)) {
127
+			// use start or end of $target_array based on whether we are adding before or not
128
+			$offset = $add_before ? 0 : count($target_array);
129
+		}
130
+		// if offset key is a string, then find the corresponding numeric location for that element
131
+		$offset = is_int($offset) ? $offset : array_search($offset, $target_array_keys, true);
132
+		// add one to the offset if adding after
133
+		$offset = $add_before ? $offset : $offset + 1;
134
+		// but ensure offset does not exceed the length of the array
135
+		$offset = $offset > count($target_array) ? count($target_array) : $offset;
136
+		// reindex array ???
137
+		if ($preserve_keys) {
138
+			// take a slice of the target array from the beginning till the offset,
139
+			// then add the new data
140
+			// then add another slice that starts at the offset and goes till the end
141
+			return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice(
142
+				$target_array,
143
+				$offset,
144
+				null,
145
+				true
146
+			);
147
+		} else {
148
+			// since we don't want to preserve keys, we can use array_splice
149
+			array_splice($target_array, $offset, 0, $array_to_insert);
150
+			return $target_array;
151
+		}
152
+	}
153 153
 
154 154
 
155
-    /**
156
-     * array_merge() is slow and should never be used while looping over data
157
-     * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster
158
-     * so really this acts more like array_replace( $array1, $array2 )
159
-     * or a union with the arrays flipped ( $array2 + $array1 )
160
-     * this saves a few lines of code and improves readability
161
-     *
162
-     * @param array $array1
163
-     * @param array $array2
164
-     * @return array
165
-     */
166
-    public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
167
-    {
168
-        foreach ($array2 as $key => $value) {
169
-            $array1[ $key ] = $value;
170
-        }
171
-        return $array1;
172
-    }
155
+	/**
156
+	 * array_merge() is slow and should never be used while looping over data
157
+	 * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster
158
+	 * so really this acts more like array_replace( $array1, $array2 )
159
+	 * or a union with the arrays flipped ( $array2 + $array1 )
160
+	 * this saves a few lines of code and improves readability
161
+	 *
162
+	 * @param array $array1
163
+	 * @param array $array2
164
+	 * @return array
165
+	 */
166
+	public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
167
+	{
168
+		foreach ($array2 as $key => $value) {
169
+			$array1[ $key ] = $value;
170
+		}
171
+		return $array1;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * given a flat array like $array = array('A', 'B', 'C')
177
-     * will convert into a multidimensional array like $array[A][B][C]
178
-     * if $final_value is provided and is anything other than null,
179
-     * then that will be set as the value for the innermost array key
180
-     * like so: $array[A][B][C] = $final_value
181
-     *
182
-     * @param array $flat_array
183
-     * @param mixed $final_value
184
-     * @return array
185
-     */
186
-    public static function convert_array_values_to_keys(array $flat_array, $final_value = null)
187
-    {
188
-        $multidimensional = array();
189
-        $reference = &$multidimensional;
190
-        foreach ($flat_array as $key) {
191
-            $reference[ $key ] = array();
192
-            $reference = &$reference[ $key ];
193
-        }
194
-        if ($final_value !== null) {
195
-            $reference = $final_value;
196
-        }
197
-        return $multidimensional;
198
-    }
175
+	/**
176
+	 * given a flat array like $array = array('A', 'B', 'C')
177
+	 * will convert into a multidimensional array like $array[A][B][C]
178
+	 * if $final_value is provided and is anything other than null,
179
+	 * then that will be set as the value for the innermost array key
180
+	 * like so: $array[A][B][C] = $final_value
181
+	 *
182
+	 * @param array $flat_array
183
+	 * @param mixed $final_value
184
+	 * @return array
185
+	 */
186
+	public static function convert_array_values_to_keys(array $flat_array, $final_value = null)
187
+	{
188
+		$multidimensional = array();
189
+		$reference = &$multidimensional;
190
+		foreach ($flat_array as $key) {
191
+			$reference[ $key ] = array();
192
+			$reference = &$reference[ $key ];
193
+		}
194
+		if ($final_value !== null) {
195
+			$reference = $final_value;
196
+		}
197
+		return $multidimensional;
198
+	}
199 199
 
200 200
 
201
-    /**
202
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
203
-     * @param array $array
204
-     * @return bool
205
-     */
206
-    public static function is_array_numerically_and_sequentially_indexed(array $array)
207
-    {
208
-        return empty($array) || array_keys($array) === range(0, count($array) - 1);
209
-    }
201
+	/**
202
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
203
+	 * @param array $array
204
+	 * @return bool
205
+	 */
206
+	public static function is_array_numerically_and_sequentially_indexed(array $array)
207
+	{
208
+		return empty($array) || array_keys($array) === range(0, count($array) - 1);
209
+	}
210 210
 
211 211
 
212
-    /**
213
-     * recursively walks through an array and adds slashes to all no array elements
214
-     *
215
-     * @param mixed $element
216
-     * @return array|string
217
-     * @since   4.10.29.p
218
-     */
219
-    public static function addSlashesRecursively($element)
220
-    {
221
-        if (is_array($element)) {
222
-            foreach ($element as $key => $value) {
223
-                $element[ $key ] = EEH_Array::addSlashesRecursively($value);
224
-            }
225
-            return $element;
226
-        }
227
-        return is_string($element) ? addslashes($element) : $element;
228
-    }
212
+	/**
213
+	 * recursively walks through an array and adds slashes to all no array elements
214
+	 *
215
+	 * @param mixed $element
216
+	 * @return array|string
217
+	 * @since   4.10.29.p
218
+	 */
219
+	public static function addSlashesRecursively($element)
220
+	{
221
+		if (is_array($element)) {
222
+			foreach ($element as $key => $value) {
223
+				$element[ $key ] = EEH_Array::addSlashesRecursively($value);
224
+			}
225
+			return $element;
226
+		}
227
+		return is_string($element) ? addslashes($element) : $element;
228
+	}
229 229
 
230 230
 
231 231
 	/**
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	 *	print_r( EEH_Array::flattenArray($example, true) );
295 295
 	 *
296 296
 	 * 	"a:A, b:B, c:[ d:D, e:E, f:[ G, H, I ] ], [ J, K ], L, M, n:[ o:P ]"
297
- 	 *
297
+	 *
298 298
 	 * @param array $array		the array to be flattened
299 299
 	 * @param bool  $to_string	[true] will flatten the entire array down into a string
300 300
 	 *                         	[false] will only flatten sub-arrays down into strings and return a array
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function is_set($arr, $index, $default)
82 82
     {
83
-        return isset($arr[ $index ]) ? $arr[ $index ] : $default;
83
+        return isset($arr[$index]) ? $arr[$index] : $default;
84 84
     }
85 85
 
86 86
     /**
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
167 167
     {
168 168
         foreach ($array2 as $key => $value) {
169
-            $array1[ $key ] = $value;
169
+            $array1[$key] = $value;
170 170
         }
171 171
         return $array1;
172 172
     }
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
         $multidimensional = array();
189 189
         $reference = &$multidimensional;
190 190
         foreach ($flat_array as $key) {
191
-            $reference[ $key ] = array();
192
-            $reference = &$reference[ $key ];
191
+            $reference[$key] = array();
192
+            $reference = &$reference[$key];
193 193
         }
194 194
         if ($final_value !== null) {
195 195
             $reference = $final_value;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
     {
221 221
         if (is_array($element)) {
222 222
             foreach ($element as $key => $value) {
223
-                $element[ $key ] = EEH_Array::addSlashesRecursively($value);
223
+                $element[$key] = EEH_Array::addSlashesRecursively($value);
224 224
             }
225 225
             return $element;
226 226
         }
@@ -242,17 +242,17 @@  discard block
 block discarded – undo
242 242
 		foreach ($array_1 as $key => $value) {
243 243
 			if (array_key_exists($key, $array_2)) {
244 244
 				if (is_array($value)) {
245
-					$inner_diff = EEH_Array::array_diff_recursive($value, $array_2[ $key ]);
245
+					$inner_diff = EEH_Array::array_diff_recursive($value, $array_2[$key]);
246 246
 					if (count($inner_diff)) {
247
-						$diff[ $key ] = $inner_diff;
247
+						$diff[$key] = $inner_diff;
248 248
 					}
249 249
 				} else {
250
-					if ($value != $array_2[ $key ]) {
251
-						$diff[ $key ] = $value;
250
+					if ($value != $array_2[$key]) {
251
+						$diff[$key] = $value;
252 252
 					}
253 253
 				}
254 254
 			} else {
255
-				$diff[ $key ] = $value;
255
+				$diff[$key] = $value;
256 256
 			}
257 257
 		}
258 258
 		return $diff;
@@ -306,11 +306,11 @@  discard block
 block discarded – undo
306 306
 	{
307 307
 		$flat_array = [];
308 308
 		foreach ($array as $key => $value) {
309
-			$flat_array[ $key ] = is_array($value)
309
+			$flat_array[$key] = is_array($value)
310 310
 				? EEH_Array::flattenArray($value, true, false)
311 311
 				: $value;
312 312
 		}
313
-		if (! $to_string) {
313
+		if ( ! $to_string) {
314 314
 			return $flat_array;
315 315
 		}
316 316
 		$flat = '';
Please login to merge, or discard this patch.
modules/batch/EED_Batch.module.php 2 patches
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -31,94 +31,94 @@  discard block
 block discarded – undo
31 31
 
32 32
 	public const PAGE_SLUG = 'espresso_batch';
33 33
 
34
-    /**
35
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
36
-     * processes data only
37
-     */
38
-    const batch_job = 'job';
39
-
40
-    /**
41
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
42
-     * produces a file for download
43
-     */
44
-    const batch_file_job = 'file';
45
-
46
-    /**
47
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
48
-     * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
49
-     * at all
50
-     */
51
-    const batch_not_job = 'none';
52
-
53
-    /**
54
-     *
55
-     * @var string 'file', or 'job', or false to indicate its not a batch request at all
56
-     */
57
-    protected $_batch_request_type = '';
58
-
59
-    /**
60
-     * Because we want to use the response in both the localized JS and in the body
61
-     * we need to make this response available between method calls
62
-     *
63
-     * @var JobStepResponse|null
34
+	/**
35
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
36
+	 * processes data only
64 37
 	 */
65
-    protected $_job_step_response = null;
38
+	const batch_job = 'job';
66 39
 
67
-    /**
68
-     * @var LoaderInterface|null
40
+	/**
41
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
42
+	 * produces a file for download
43
+	 */
44
+	const batch_file_job = 'file';
45
+
46
+	/**
47
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
48
+	 * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
49
+	 * at all
69 50
 	 */
70
-    protected $loader = null;
71
-
72
-
73
-    /**
74
-     * Gets the batch instance
75
-     *
76
-     * @return  EED_Module|EED_Batch
77
-     * @throws EE_Error
78
-     * @throws ReflectionException
79
-     */
80
-    public static function instance(): EED_Batch
81
-    {
82
-        return parent::get_instance(__CLASS__);
83
-    }
84
-
85
-
86
-    /**
87
-     * Sets hooks to enable batch jobs on the frontend. Disabled by default
88
-     * because it's an attack vector and there are currently no implementations
89
-     *
90
-     * @throws EE_Error
91
-     * @throws ReflectionException
92
-     */
93
-    public static function set_hooks()
94
-    {
95
-        // because this is a possible attack vector, let's have this disabled until
96
-        // we at least have a real use for it on the frontend
97
-        if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
98
-            add_action('wp_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
99
-            add_filter('template_include', [self::instance(), 'override_template'], 99);
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     * Initializes some hooks for the admin in order to run batch jobs
106
-     *
107
-     * @throws EE_Error
108
-     * @throws ReflectionException
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        add_action('admin_menu', [self::instance(), 'register_admin_pages']);
113
-        add_action('admin_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
114
-
115
-        // ajax
116
-        add_action('wp_ajax_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
117
-        add_action('wp_ajax_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
118
-        add_action('wp_ajax_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
119
-        add_action('wp_ajax_nopriv_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
120
-        add_action('wp_ajax_nopriv_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
121
-        add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
51
+	const batch_not_job = 'none';
52
+
53
+	/**
54
+	 *
55
+	 * @var string 'file', or 'job', or false to indicate its not a batch request at all
56
+	 */
57
+	protected $_batch_request_type = '';
58
+
59
+	/**
60
+	 * Because we want to use the response in both the localized JS and in the body
61
+	 * we need to make this response available between method calls
62
+	 *
63
+	 * @var JobStepResponse|null
64
+	 */
65
+	protected $_job_step_response = null;
66
+
67
+	/**
68
+	 * @var LoaderInterface|null
69
+	 */
70
+	protected $loader = null;
71
+
72
+
73
+	/**
74
+	 * Gets the batch instance
75
+	 *
76
+	 * @return  EED_Module|EED_Batch
77
+	 * @throws EE_Error
78
+	 * @throws ReflectionException
79
+	 */
80
+	public static function instance(): EED_Batch
81
+	{
82
+		return parent::get_instance(__CLASS__);
83
+	}
84
+
85
+
86
+	/**
87
+	 * Sets hooks to enable batch jobs on the frontend. Disabled by default
88
+	 * because it's an attack vector and there are currently no implementations
89
+	 *
90
+	 * @throws EE_Error
91
+	 * @throws ReflectionException
92
+	 */
93
+	public static function set_hooks()
94
+	{
95
+		// because this is a possible attack vector, let's have this disabled until
96
+		// we at least have a real use for it on the frontend
97
+		if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
98
+			add_action('wp_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
99
+			add_filter('template_include', [self::instance(), 'override_template'], 99);
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 * Initializes some hooks for the admin in order to run batch jobs
106
+	 *
107
+	 * @throws EE_Error
108
+	 * @throws ReflectionException
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		add_action('admin_menu', [self::instance(), 'register_admin_pages']);
113
+		add_action('admin_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
114
+
115
+		// ajax
116
+		add_action('wp_ajax_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
117
+		add_action('wp_ajax_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
118
+		add_action('wp_ajax_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
119
+		add_action('wp_ajax_nopriv_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
120
+		add_action('wp_ajax_nopriv_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
121
+		add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
122 122
 		add_filter(
123 123
 			'admin_body_class',
124 124
 			function ($classes) {
@@ -128,72 +128,72 @@  discard block
 block discarded – undo
128 128
 				return $classes;
129 129
 			}
130 130
 		);
131
-    }
131
+	}
132 132
 
133 133
 
134
-    /**
135
-     * @return LoaderInterface
136
-     * @throws InvalidArgumentException
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @since 4.9.80.p
140
-     */
141
-    protected function getLoader(): LoaderInterface
134
+	/**
135
+	 * @return LoaderInterface
136
+	 * @throws InvalidArgumentException
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @since 4.9.80.p
140
+	 */
141
+	protected function getLoader(): LoaderInterface
142
+	{
143
+		if (! $this->loader instanceof LoaderInterface) {
144
+			$this->loader = LoaderFactory::getLoader();
145
+		}
146
+		return $this->loader;
147
+	}
148
+
149
+
150
+	/**
151
+	 * Enqueues batch scripts on the frontend or admin, and creates a job
152
+	 */
153
+	public function enqueue_scripts()
142 154
 	{
143
-        if (! $this->loader instanceof LoaderInterface) {
144
-            $this->loader = LoaderFactory::getLoader();
145
-        }
146
-        return $this->loader;
147
-    }
148
-
149
-
150
-    /**
151
-     * Enqueues batch scripts on the frontend or admin, and creates a job
152
-     */
153
-    public function enqueue_scripts()
154
-    {
155
-        $request = EED_Batch::getRequest();
156
-        if (
157
-            $request->getRequestParam(EED_Batch::PAGE_SLUG)
158
-            || $request->getRequestParam('page') === EED_Batch::PAGE_SLUG
159
-        ) {
160
-            if (
161
-                ! $request->requestParamIsSet('default_nonce')
162
-                || ! wp_verify_nonce($request->getRequestParam('default_nonce'), 'default_nonce')
163
-            ) {
164
-                wp_die(
165
-                    esc_html__(
166
-                        'The link you clicked to start the batch job has expired. Please go back and refresh the previous page.',
167
-                        'event_espresso'
168
-                    )
169
-                );
170
-            }
171
-            switch ($this->batch_request_type()) {
172
-                case self::batch_job:
173
-                    $this->enqueue_scripts_styles_batch_create();
174
-                    break;
175
-                case self::batch_file_job:
176
-                    $this->enqueue_scripts_styles_batch_file_create();
177
-                    break;
178
-            }
179
-        }
180
-    }
181
-
182
-
183
-    /**
184
-     * Create a batch job, enqueues a script to run it, and localizes some data for it
185
-     */
186
-    public function enqueue_scripts_styles_batch_create()
187
-    {
188
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
189
-        wp_enqueue_script(
190
-            'batch_runner_init',
191
-            BATCH_URL . 'assets/batch_runner_init.js',
192
-            ['batch_runner'],
155
+		$request = EED_Batch::getRequest();
156
+		if (
157
+			$request->getRequestParam(EED_Batch::PAGE_SLUG)
158
+			|| $request->getRequestParam('page') === EED_Batch::PAGE_SLUG
159
+		) {
160
+			if (
161
+				! $request->requestParamIsSet('default_nonce')
162
+				|| ! wp_verify_nonce($request->getRequestParam('default_nonce'), 'default_nonce')
163
+			) {
164
+				wp_die(
165
+					esc_html__(
166
+						'The link you clicked to start the batch job has expired. Please go back and refresh the previous page.',
167
+						'event_espresso'
168
+					)
169
+				);
170
+			}
171
+			switch ($this->batch_request_type()) {
172
+				case self::batch_job:
173
+					$this->enqueue_scripts_styles_batch_create();
174
+					break;
175
+				case self::batch_file_job:
176
+					$this->enqueue_scripts_styles_batch_file_create();
177
+					break;
178
+			}
179
+		}
180
+	}
181
+
182
+
183
+	/**
184
+	 * Create a batch job, enqueues a script to run it, and localizes some data for it
185
+	 */
186
+	public function enqueue_scripts_styles_batch_create()
187
+	{
188
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
189
+		wp_enqueue_script(
190
+			'batch_runner_init',
191
+			BATCH_URL . 'assets/batch_runner_init.js',
192
+			['batch_runner'],
193 193
 			date('Y-m-d-H:i', time()),
194
-            true
195
-        );
196
-        wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
194
+			true
195
+		);
196
+		wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
197 197
 		wp_localize_script('batch_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
198 198
 
199 199
 		$return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', 'url');
@@ -209,24 +209,24 @@  discard block
 block discarded – undo
209 209
 				]
210 210
 			);
211 211
 		}
212
-    }
213
-
214
-
215
-    /**
216
-     * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
217
-     */
218
-    public function enqueue_scripts_styles_batch_file_create()
219
-    {
220
-        // creates a job based on the request variable
221
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
222
-        wp_enqueue_script(
223
-            'batch_file_runner_init',
224
-            BATCH_URL . 'assets/batch_file_runner_init.js',
225
-            ['batch_runner'],
212
+	}
213
+
214
+
215
+	/**
216
+	 * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
217
+	 */
218
+	public function enqueue_scripts_styles_batch_file_create()
219
+	{
220
+		// creates a job based on the request variable
221
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
222
+		wp_enqueue_script(
223
+			'batch_file_runner_init',
224
+			BATCH_URL . 'assets/batch_file_runner_init.js',
225
+			['batch_runner'],
226 226
 			date('Y-m-d-H:i', time()),
227
-            true
228
-        );
229
-        wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
227
+			true
228
+		);
229
+		wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
230 230
 		wp_localize_script('batch_file_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
231 231
 
232 232
 		$return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', 'url');
@@ -246,24 +246,24 @@  discard block
 block discarded – undo
246 246
 				]
247 247
 			);
248 248
 		}
249
-    }
250
-
251
-
252
-    /**
253
-     * Enqueues scripts and styles common to any batch job, and creates
254
-     * a job from the request data, and stores the response in the
255
-     * $this->_job_step_response property
256
-     *
257
-     * @return JobStepResponse
258
-     */
259
-    protected function _enqueue_batch_job_scripts_and_styles_and_start_job(): JobStepResponse
260
-    {
261
-        // just copy the bits of EE admin's eei18n that we need in the JS
262
-        EE_Registry::$i18n_js_strings['batchJobError'] = __(
263
-            'An error occurred and the job has been stopped. Please refresh the page to try again.',
264
-            'event_espresso'
265
-        );
266
-        EE_Registry::$i18n_js_strings['is_admin'] = is_admin();
249
+	}
250
+
251
+
252
+	/**
253
+	 * Enqueues scripts and styles common to any batch job, and creates
254
+	 * a job from the request data, and stores the response in the
255
+	 * $this->_job_step_response property
256
+	 *
257
+	 * @return JobStepResponse
258
+	 */
259
+	protected function _enqueue_batch_job_scripts_and_styles_and_start_job(): JobStepResponse
260
+	{
261
+		// just copy the bits of EE admin's eei18n that we need in the JS
262
+		EE_Registry::$i18n_js_strings['batchJobError'] = __(
263
+			'An error occurred and the job has been stopped. Please refresh the page to try again.',
264
+			'event_espresso'
265
+		);
266
+		EE_Registry::$i18n_js_strings['is_admin'] = is_admin();
267 267
 		wp_enqueue_style(
268 268
 			EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
269 269
 			EE_ADMIN_URL . 'assets/ee-admin-page.css',
@@ -276,86 +276,86 @@  discard block
 block discarded – undo
276 276
 			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
277 277
 			date('Y-m-d-H:i', time())
278 278
 		);
279
-        wp_register_script(
280
-            'progress_bar',
281
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
282
-            ['jquery'],
283
-            date('Y-m-d-H:i', time()),
284
-            true
285
-        );
286
-        wp_enqueue_style(
287
-            'progress_bar',
288
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
289
-            [],
279
+		wp_register_script(
280
+			'progress_bar',
281
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
282
+			['jquery'],
283
+			date('Y-m-d-H:i', time()),
284
+			true
285
+		);
286
+		wp_enqueue_style(
287
+			'progress_bar',
288
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
289
+			[],
290 290
 			date('Y-m-d-H:i', time())
291
-        );
292
-        wp_enqueue_script(
293
-            'batch_runner',
294
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
295
-            ['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
291
+		);
292
+		wp_enqueue_script(
293
+			'batch_runner',
294
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
295
+			['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
296 296
 			date('Y-m-d-H:i', time()),
297
-            true
298
-        );
299
-        /** @var BatchRequestProcessor $batch_runner */
300
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
301
-        // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
302
-        // remember the response for later. We need it to display the page body
297
+			true
298
+		);
299
+		/** @var BatchRequestProcessor $batch_runner */
300
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
301
+		// eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
302
+		// remember the response for later. We need it to display the page body
303 303
 		$this->_job_step_response = $batch_runner->createJob();
304
-        return $this->_job_step_response;
305
-    }
306
-
307
-
308
-    /**
309
-     * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
310
-     *
311
-     * @param string $template
312
-     * @return string
313
-     */
314
-    public function override_template(string $template): string
315
-    {
316
-        $request = EED_Batch::getRequest();
317
-        if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
318
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
319
-        }
320
-        return $template;
321
-    }
322
-
323
-
324
-    /**
325
-     * Adds an admin page which doesn't appear in the admin menu
326
-     *
327
-     * @throws EE_Error
328
-     * @throws ReflectionException
329
-     */
330
-    public function register_admin_pages()
331
-    {
332
-        add_submenu_page(
333
-            '',                                        // parent slug. we don't want this to actually appear in the menu
334
-            esc_html__('Batch Job', 'event_espresso'), // page title
335
-            'n/a',                                     // menu title
336
-            'read',                                    // we want this page to actually be accessible to anyone,
337
-            EED_Batch::PAGE_SLUG,                          // menu slug
338
-            [self::instance(), 'show_admin_page']
339
-        );
340
-    }
341
-
342
-
343
-    /**
344
-     * Renders the admin page, after most of the work was already done during enqueuing scripts
345
-     * of creating the job and localizing some data
346
-     */
347
-    public function show_admin_page()
348
-    {
304
+		return $this->_job_step_response;
305
+	}
306
+
307
+
308
+	/**
309
+	 * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
310
+	 *
311
+	 * @param string $template
312
+	 * @return string
313
+	 */
314
+	public function override_template(string $template): string
315
+	{
316
+		$request = EED_Batch::getRequest();
317
+		if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
318
+			return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
319
+		}
320
+		return $template;
321
+	}
322
+
323
+
324
+	/**
325
+	 * Adds an admin page which doesn't appear in the admin menu
326
+	 *
327
+	 * @throws EE_Error
328
+	 * @throws ReflectionException
329
+	 */
330
+	public function register_admin_pages()
331
+	{
332
+		add_submenu_page(
333
+			'',                                        // parent slug. we don't want this to actually appear in the menu
334
+			esc_html__('Batch Job', 'event_espresso'), // page title
335
+			'n/a',                                     // menu title
336
+			'read',                                    // we want this page to actually be accessible to anyone,
337
+			EED_Batch::PAGE_SLUG,                          // menu slug
338
+			[self::instance(), 'show_admin_page']
339
+		);
340
+	}
341
+
342
+
343
+	/**
344
+	 * Renders the admin page, after most of the work was already done during enqueuing scripts
345
+	 * of creating the job and localizing some data
346
+	 */
347
+	public function show_admin_page()
348
+	{
349 349
 		echo EEH_Template::locate_template(
350
-            EE_MODULES . 'batch/templates/batch_wrapper.template.php',
351
-            [
350
+			EE_MODULES . 'batch/templates/batch_wrapper.template.php',
351
+			[
352 352
 				'batch_request_type' => $this->batch_request_type(),
353 353
 				'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
354 354
 				'user_message' => EED_Batch::getRequest()->getRequestParam('assessment_notice')
355 355
 					?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
356 356
 			]
357
-        );
358
-    }
357
+		);
358
+	}
359 359
 
360 360
 
361 361
 	private function runBatchRunnerJob(string $job)
@@ -368,13 +368,13 @@  discard block
 block discarded – undo
368 368
 	}
369 369
 
370 370
 
371
-    /**
372
-     * Receives ajax calls for continuing a job
373
-     */
374
-    public function continueBatchJob()
375
-    {
371
+	/**
372
+	 * Receives ajax calls for continuing a job
373
+	 */
374
+	public function continueBatchJob()
375
+	{
376 376
 		$this->runBatchRunnerJob('continueJob');
377
-    }
377
+	}
378 378
 
379 379
 
380 380
 	/**
@@ -386,92 +386,92 @@  discard block
 block discarded – undo
386 386
 	}
387 387
 
388 388
 
389
-    /**
390
-     * Receives the ajax call to cleanup a job
391
-     *
392
-     * @return void
393
-     */
394
-    public function cleanupBatchJob()
395
-    {
389
+	/**
390
+	 * Receives the ajax call to cleanup a job
391
+	 *
392
+	 * @return void
393
+	 */
394
+	public function cleanupBatchJob()
395
+	{
396 396
 		$this->runBatchRunnerJob('cleanupJob');
397
-    }
398
-
399
-
400
-    /**
401
-     * Returns a json response
402
-     *
403
-     * @param array $data The data we want to send echo via in the JSON response's "data" element
404
-     *
405
-     * The returned json object is created from an array in the following format:
406
-     * array(
407
-     *    'notices' => '', // - contains any EE_Error formatted notices
408
-     *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
409
-     *    We're also going to include the template args with every package (so js can pick out any specific template
410
-     *    args that might be included in here)
411
-     *    'isEEajax' => true,//indicates this is a response from EE
412
-     * )
413
-     */
414
-    protected function _return_json(array $data)
415
-    {
416
-        $json = [
417
-            'notices'  => EE_Error::get_notices(),
418
-            'data'     => $data,
419
-            'isEEajax' => true
420
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
421
-        ];
422
-
423
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
424
-        if (error_get_last() === null || ! headers_sent()) {
425
-            header('Content-Type: application/json; charset=UTF-8');
397
+	}
398
+
399
+
400
+	/**
401
+	 * Returns a json response
402
+	 *
403
+	 * @param array $data The data we want to send echo via in the JSON response's "data" element
404
+	 *
405
+	 * The returned json object is created from an array in the following format:
406
+	 * array(
407
+	 *    'notices' => '', // - contains any EE_Error formatted notices
408
+	 *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
409
+	 *    We're also going to include the template args with every package (so js can pick out any specific template
410
+	 *    args that might be included in here)
411
+	 *    'isEEajax' => true,//indicates this is a response from EE
412
+	 * )
413
+	 */
414
+	protected function _return_json(array $data)
415
+	{
416
+		$json = [
417
+			'notices'  => EE_Error::get_notices(),
418
+			'data'     => $data,
419
+			'isEEajax' => true
420
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
421
+		];
422
+
423
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
424
+		if (error_get_last() === null || ! headers_sent()) {
425
+			header('Content-Type: application/json; charset=UTF-8');
426 426
 			echo wp_json_encode($json);
427 427
 			exit();
428
-        }
429
-    }
430
-
431
-
432
-    /**
433
-     * Gets the job step response which was done during the enqueuing of scripts
434
-     *
435
-     * @return JobStepResponse
436
-     */
437
-    public function job_step_response(): JobStepResponse
438
-    {
439
-        return $this->_job_step_response;
440
-    }
441
-
442
-
443
-    /**
444
-     * Gets the batch request type indicated in the current request
445
-     *
446
-     * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
447
-     */
448
-    public function batch_request_type(): string
449
-    {
450
-        if (! $this->_batch_request_type) {
451
-        	$request = EED_Batch::getRequest();
452
-            $batch = $request->getRequestParam('batch');
453
-            switch ($batch) {
454
-                case self::batch_job:
455
-                    $this->_batch_request_type = self::batch_job;
456
-                    break;
457
-                case self::batch_file_job:
458
-                    $this->_batch_request_type = self::batch_file_job;
459
-                    break;
460
-                default:
461
-                    // if we didn't find that it was a batch request, indicate it wasn't
462
-                    $this->_batch_request_type = self::batch_not_job;
463
-            }
464
-        }
428
+		}
429
+	}
430
+
431
+
432
+	/**
433
+	 * Gets the job step response which was done during the enqueuing of scripts
434
+	 *
435
+	 * @return JobStepResponse
436
+	 */
437
+	public function job_step_response(): JobStepResponse
438
+	{
439
+		return $this->_job_step_response;
440
+	}
441
+
442
+
443
+	/**
444
+	 * Gets the batch request type indicated in the current request
445
+	 *
446
+	 * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
447
+	 */
448
+	public function batch_request_type(): string
449
+	{
450
+		if (! $this->_batch_request_type) {
451
+			$request = EED_Batch::getRequest();
452
+			$batch = $request->getRequestParam('batch');
453
+			switch ($batch) {
454
+				case self::batch_job:
455
+					$this->_batch_request_type = self::batch_job;
456
+					break;
457
+				case self::batch_file_job:
458
+					$this->_batch_request_type = self::batch_file_job;
459
+					break;
460
+				default:
461
+					// if we didn't find that it was a batch request, indicate it wasn't
462
+					$this->_batch_request_type = self::batch_not_job;
463
+			}
464
+		}
465 465
 		return $this->_batch_request_type;
466
-    }
466
+	}
467 467
 
468 468
 
469
-    /**
470
-     * Unnecessary
471
-     *
472
-     * @param WP $WP
473
-     */
474
-    public function run($WP)
475
-    {
476
-    }
469
+	/**
470
+	 * Unnecessary
471
+	 *
472
+	 * @param WP $WP
473
+	 */
474
+	public function run($WP)
475
+	{
476
+	}
477 477
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
122 122
 		add_filter(
123 123
 			'admin_body_class',
124
-			function ($classes) {
124
+			function($classes) {
125 125
 				if (strpos($classes, 'espresso-admin') === false) {
126 126
 					$classes .= ' espresso-admin';
127 127
 				}
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     protected function getLoader(): LoaderInterface
142 142
 	{
143
-        if (! $this->loader instanceof LoaderInterface) {
143
+        if ( ! $this->loader instanceof LoaderInterface) {
144 144
             $this->loader = LoaderFactory::getLoader();
145 145
         }
146 146
         return $this->loader;
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
189 189
         wp_enqueue_script(
190 190
             'batch_runner_init',
191
-            BATCH_URL . 'assets/batch_runner_init.js',
191
+            BATCH_URL.'assets/batch_runner_init.js',
192 192
             ['batch_runner'],
193 193
 			date('Y-m-d-H:i', time()),
194 194
             true
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
222 222
         wp_enqueue_script(
223 223
             'batch_file_runner_init',
224
-            BATCH_URL . 'assets/batch_file_runner_init.js',
224
+            BATCH_URL.'assets/batch_file_runner_init.js',
225 225
             ['batch_runner'],
226 226
 			date('Y-m-d-H:i', time()),
227 227
             true
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 						wp_strip_all_tags(
240 240
 							__('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso')
241 241
 						),
242
-						'<a href="' . $return_url . '">',
242
+						'<a href="'.$return_url.'">',
243 243
 						'</a>'
244 244
 					),
245 245
 					'return_url'               => $return_url,
@@ -266,32 +266,32 @@  discard block
 block discarded – undo
266 266
         EE_Registry::$i18n_js_strings['is_admin'] = is_admin();
267 267
 		wp_enqueue_style(
268 268
 			EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
269
-			EE_ADMIN_URL . 'assets/ee-admin-page.css',
269
+			EE_ADMIN_URL.'assets/ee-admin-page.css',
270 270
 			[],
271 271
 			EVENT_ESPRESSO_VERSION
272 272
 		);
273 273
 		wp_enqueue_style(
274 274
 			'batch_runner',
275
-			BATCH_URL . 'assets/batch_runner.css',
275
+			BATCH_URL.'assets/batch_runner.css',
276 276
 			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
277 277
 			date('Y-m-d-H:i', time())
278 278
 		);
279 279
         wp_register_script(
280 280
             'progress_bar',
281
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
281
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js',
282 282
             ['jquery'],
283 283
             date('Y-m-d-H:i', time()),
284 284
             true
285 285
         );
286 286
         wp_enqueue_style(
287 287
             'progress_bar',
288
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
288
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css',
289 289
             [],
290 290
 			date('Y-m-d-H:i', time())
291 291
         );
292 292
         wp_enqueue_script(
293 293
             'batch_runner',
294
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
294
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js',
295 295
             ['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
296 296
 			date('Y-m-d-H:i', time()),
297 297
             true
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     {
316 316
         $request = EED_Batch::getRequest();
317 317
         if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
318
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
318
+            return EE_MODULES.'batch/templates/batch_frontend_wrapper.template.php';
319 319
         }
320 320
         return $template;
321 321
     }
@@ -330,11 +330,11 @@  discard block
 block discarded – undo
330 330
     public function register_admin_pages()
331 331
     {
332 332
         add_submenu_page(
333
-            '',                                        // parent slug. we don't want this to actually appear in the menu
333
+            '', // parent slug. we don't want this to actually appear in the menu
334 334
             esc_html__('Batch Job', 'event_espresso'), // page title
335
-            'n/a',                                     // menu title
336
-            'read',                                    // we want this page to actually be accessible to anyone,
337
-            EED_Batch::PAGE_SLUG,                          // menu slug
335
+            'n/a', // menu title
336
+            'read', // we want this page to actually be accessible to anyone,
337
+            EED_Batch::PAGE_SLUG, // menu slug
338 338
             [self::instance(), 'show_admin_page']
339 339
         );
340 340
     }
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
     public function show_admin_page()
348 348
     {
349 349
 		echo EEH_Template::locate_template(
350
-            EE_MODULES . 'batch/templates/batch_wrapper.template.php',
350
+            EE_MODULES.'batch/templates/batch_wrapper.template.php',
351 351
             [
352 352
 				'batch_request_type' => $this->batch_request_type(),
353 353
 				'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
      */
448 448
     public function batch_request_type(): string
449 449
     {
450
-        if (! $this->_batch_request_type) {
450
+        if ( ! $this->_batch_request_type) {
451 451
         	$request = EED_Batch::getRequest();
452 452
             $batch = $request->getRequestParam('batch');
453 453
             switch ($batch) {
Please login to merge, or discard this patch.
modules/batch/templates/batch_frontend_wrapper.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 //wraps the template in the typical wordpress header and footer
3 3
 get_header();
4
-require( 'batch_wrapper.template.php');
4
+require('batch_wrapper.template.php');
5 5
 get_footer();
Please login to merge, or discard this patch.
modules/batch/templates/batch_runner.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 <div class="ee-batch-runner__wrapper ee-admin-container">
6 6
 	<div class="padding">
7
-		<h1><?php esc_html_e( 'Running Batch Job...', 'event_espresso' );?></h1>
7
+		<h1><?php esc_html_e('Running Batch Job...', 'event_espresso'); ?></h1>
8 8
 		<div class="progress-bar-wrapper">
9 9
 			<div id='batch-progress' class='progress-responsive'></div>
10 10
 			<label><?php esc_html_e('progress', 'event_espresso'); ?></label>
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2907 added lines, -2907 removed lines patch added patch discarded remove patch
@@ -16,2914 +16,2914 @@
 block discarded – undo
16 16
  */
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+	/**
55
+	 * @var AdvancedEditorAdminFormSection
56
+	 */
57
+	protected $advanced_editor_admin_form;
58
+
59
+
60
+	/**
61
+	 * Initialize page props for this admin page group.
62
+	 */
63
+	protected function _init_page_props()
64
+	{
65
+		$this->page_slug        = EVENTS_PG_SLUG;
66
+		$this->page_label       = EVENTS_LABEL;
67
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
68
+		$this->_admin_base_path = EVENTS_ADMIN;
69
+		$this->_cpt_model_names = [
70
+			'create_new' => 'EEM_Event',
71
+			'edit'       => 'EEM_Event',
72
+		];
73
+		$this->_cpt_edit_routes = [
74
+			'espresso_events' => 'edit',
75
+		];
76
+		add_action(
77
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
78
+			[$this, 'verify_event_edit'],
79
+			10,
80
+			2
81
+		);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Sets the ajax hooks used for this admin page group.
87
+	 */
88
+	protected function _ajax_hooks()
89
+	{
90
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Sets the page properties for this admin page group.
96
+	 */
97
+	protected function _define_page_props()
98
+	{
99
+		$this->_admin_page_title = EVENTS_LABEL;
100
+		$this->_labels           = [
101
+			'buttons'      => [
102
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
103
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
104
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
105
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
106
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
107
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
108
+			],
109
+			'editor_title' => [
110
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
111
+			],
112
+			'publishbox'   => [
113
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
114
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
115
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
116
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
117
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
118
+			],
119
+		];
120
+	}
121
+
122
+
123
+	/**
124
+	 * Sets the page routes property for this admin page group.
125
+	 */
126
+	protected function _set_page_routes()
127
+	{
128
+		// load formatter helper
129
+		// load field generator helper
130
+		// is there a evt_id in the request?
131
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
132
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
133
+
134
+		$this->_page_routes = [
135
+			'default'                       => [
136
+				'func'       => '_events_overview_list_table',
137
+				'capability' => 'ee_read_events',
138
+			],
139
+			'create_new'                    => [
140
+				'func'       => '_create_new_cpt_item',
141
+				'capability' => 'ee_edit_events',
142
+			],
143
+			'edit'                          => [
144
+				'func'       => '_edit_cpt_item',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+			],
148
+			'copy_event'                    => [
149
+				'func'       => '_copy_events',
150
+				'capability' => 'ee_edit_event',
151
+				'obj_id'     => $EVT_ID,
152
+				'noheader'   => true,
153
+			],
154
+			'trash_event'                   => [
155
+				'func'       => '_trash_or_restore_event',
156
+				'args'       => ['event_status' => 'trash'],
157
+				'capability' => 'ee_delete_event',
158
+				'obj_id'     => $EVT_ID,
159
+				'noheader'   => true,
160
+			],
161
+			'trash_events'                  => [
162
+				'func'       => '_trash_or_restore_events',
163
+				'args'       => ['event_status' => 'trash'],
164
+				'capability' => 'ee_delete_events',
165
+				'noheader'   => true,
166
+			],
167
+			'restore_event'                 => [
168
+				'func'       => '_trash_or_restore_event',
169
+				'args'       => ['event_status' => 'draft'],
170
+				'capability' => 'ee_delete_event',
171
+				'obj_id'     => $EVT_ID,
172
+				'noheader'   => true,
173
+			],
174
+			'restore_events'                => [
175
+				'func'       => '_trash_or_restore_events',
176
+				'args'       => ['event_status' => 'draft'],
177
+				'capability' => 'ee_delete_events',
178
+				'noheader'   => true,
179
+			],
180
+			'delete_event'                  => [
181
+				'func'       => '_delete_event',
182
+				'capability' => 'ee_delete_event',
183
+				'obj_id'     => $EVT_ID,
184
+				'noheader'   => true,
185
+			],
186
+			'delete_events'                 => [
187
+				'func'       => '_delete_events',
188
+				'capability' => 'ee_delete_events',
189
+				'noheader'   => true,
190
+			],
191
+			'view_report'                   => [
192
+				'func'       => '_view_report',
193
+				'capability' => 'ee_edit_events',
194
+			],
195
+			'default_event_settings'        => [
196
+				'func'       => '_default_event_settings',
197
+				'capability' => 'manage_options',
198
+			],
199
+			'update_default_event_settings' => [
200
+				'func'       => '_update_default_event_settings',
201
+				'capability' => 'manage_options',
202
+				'noheader'   => true,
203
+			],
204
+			'template_settings'             => [
205
+				'func'       => '_template_settings',
206
+				'capability' => 'manage_options',
207
+			],
208
+			// event category tab related
209
+			'add_category'                  => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['add'],
213
+			],
214
+			'edit_category'                 => [
215
+				'func'       => '_category_details',
216
+				'capability' => 'ee_edit_event_category',
217
+				'args'       => ['edit'],
218
+			],
219
+			'delete_categories'             => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'delete_category'               => [
225
+				'func'       => '_delete_categories',
226
+				'capability' => 'ee_delete_event_category',
227
+				'noheader'   => true,
228
+			],
229
+			'insert_category'               => [
230
+				'func'       => '_insert_or_update_category',
231
+				'args'       => ['new_category' => true],
232
+				'capability' => 'ee_edit_event_category',
233
+				'noheader'   => true,
234
+			],
235
+			'update_category'               => [
236
+				'func'       => '_insert_or_update_category',
237
+				'args'       => ['new_category' => false],
238
+				'capability' => 'ee_edit_event_category',
239
+				'noheader'   => true,
240
+			],
241
+			'category_list'                 => [
242
+				'func'       => '_category_list_table',
243
+				'capability' => 'ee_manage_event_categories',
244
+			],
245
+			'preview_deletion'              => [
246
+				'func'       => 'previewDeletion',
247
+				'capability' => 'ee_delete_events',
248
+			],
249
+			'confirm_deletion'              => [
250
+				'func'       => 'confirmDeletion',
251
+				'capability' => 'ee_delete_events',
252
+				'noheader'   => true,
253
+			],
254
+		];
255
+	}
256
+
257
+
258
+	/**
259
+	 * Set the _page_config property for this admin page group.
260
+	 */
261
+	protected function _set_page_config()
262
+	{
263
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
264
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
265
+		$this->_page_config = [
266
+			'default'                => [
267
+				'nav'           => [
268
+					'label' => esc_html__('Overview', 'event_espresso'),
269
+					'order' => 10,
270
+				],
271
+				'list_table'    => 'Events_Admin_List_Table',
272
+				'help_tabs'     => [
273
+					'events_overview_help_tab'                       => [
274
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
275
+						'filename' => 'events_overview',
276
+					],
277
+					'events_overview_table_column_headings_help_tab' => [
278
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
279
+						'filename' => 'events_overview_table_column_headings',
280
+					],
281
+					'events_overview_filters_help_tab'               => [
282
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
283
+						'filename' => 'events_overview_filters',
284
+					],
285
+					'events_overview_view_help_tab'                  => [
286
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
287
+						'filename' => 'events_overview_views',
288
+					],
289
+					'events_overview_other_help_tab'                 => [
290
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
291
+						'filename' => 'events_overview_other',
292
+					],
293
+				],
294
+				'require_nonce' => false,
295
+			],
296
+			'create_new'             => [
297
+				'nav'           => [
298
+					'label'      => esc_html__('Add New Event', 'event_espresso'),
299
+					'order'      => 5,
300
+					'persistent' => false,
301
+				],
302
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
303
+				'help_tabs'     => [
304
+					'event_editor_help_tab'                            => [
305
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
306
+						'filename' => 'event_editor',
307
+					],
308
+					'event_editor_title_richtexteditor_help_tab'       => [
309
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
310
+						'filename' => 'event_editor_title_richtexteditor',
311
+					],
312
+					'event_editor_venue_details_help_tab'              => [
313
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
314
+						'filename' => 'event_editor_venue_details',
315
+					],
316
+					'event_editor_event_datetimes_help_tab'            => [
317
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
318
+						'filename' => 'event_editor_event_datetimes',
319
+					],
320
+					'event_editor_event_tickets_help_tab'              => [
321
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
322
+						'filename' => 'event_editor_event_tickets',
323
+					],
324
+					'event_editor_event_registration_options_help_tab' => [
325
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
326
+						'filename' => 'event_editor_event_registration_options',
327
+					],
328
+					'event_editor_tags_categories_help_tab'            => [
329
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
330
+						'filename' => 'event_editor_tags_categories',
331
+					],
332
+					'event_editor_questions_registrants_help_tab'      => [
333
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
334
+						'filename' => 'event_editor_questions_registrants',
335
+					],
336
+					'event_editor_save_new_event_help_tab'             => [
337
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
338
+						'filename' => 'event_editor_save_new_event',
339
+					],
340
+					'event_editor_other_help_tab'                      => [
341
+						'title'    => esc_html__('Event Other', 'event_espresso'),
342
+						'filename' => 'event_editor_other',
343
+					],
344
+				],
345
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
346
+				'require_nonce' => false,
347
+			],
348
+			'edit'                   => [
349
+				'nav'           => [
350
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
351
+					'order'      => 5,
352
+					'persistent' => false,
353
+					'url'        => $post_id
354
+						? EE_Admin_Page::add_query_args_and_nonce(
355
+							['post' => $post_id, 'action' => 'edit'],
356
+							$this->_current_page_view_url
357
+						)
358
+						: $this->_admin_base_url,
359
+				],
360
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
361
+				'help_tabs'     => [
362
+					'event_editor_help_tab'                            => [
363
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
364
+						'filename' => 'event_editor',
365
+					],
366
+					'event_editor_title_richtexteditor_help_tab'       => [
367
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
368
+						'filename' => 'event_editor_title_richtexteditor',
369
+					],
370
+					'event_editor_venue_details_help_tab'              => [
371
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
372
+						'filename' => 'event_editor_venue_details',
373
+					],
374
+					'event_editor_event_datetimes_help_tab'            => [
375
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
376
+						'filename' => 'event_editor_event_datetimes',
377
+					],
378
+					'event_editor_event_tickets_help_tab'              => [
379
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
380
+						'filename' => 'event_editor_event_tickets',
381
+					],
382
+					'event_editor_event_registration_options_help_tab' => [
383
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
384
+						'filename' => 'event_editor_event_registration_options',
385
+					],
386
+					'event_editor_tags_categories_help_tab'            => [
387
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
388
+						'filename' => 'event_editor_tags_categories',
389
+					],
390
+					'event_editor_questions_registrants_help_tab'      => [
391
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
392
+						'filename' => 'event_editor_questions_registrants',
393
+					],
394
+					'event_editor_save_new_event_help_tab'             => [
395
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
396
+						'filename' => 'event_editor_save_new_event',
397
+					],
398
+					'event_editor_other_help_tab'                      => [
399
+						'title'    => esc_html__('Event Other', 'event_espresso'),
400
+						'filename' => 'event_editor_other',
401
+					],
402
+				],
403
+				'require_nonce' => false,
404
+			],
405
+			'default_event_settings' => [
406
+				'nav'           => [
407
+					'label' => esc_html__('Default Settings', 'event_espresso'),
408
+					'order' => 40,
409
+				],
410
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
411
+				'labels'        => [
412
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
413
+				],
414
+				'help_tabs'     => [
415
+					'default_settings_help_tab'        => [
416
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
417
+						'filename' => 'events_default_settings',
418
+					],
419
+					'default_settings_status_help_tab' => [
420
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
421
+						'filename' => 'events_default_settings_status',
422
+					],
423
+					'default_maximum_tickets_help_tab' => [
424
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
425
+						'filename' => 'events_default_settings_max_tickets',
426
+					],
427
+				],
428
+				'require_nonce' => false,
429
+			],
430
+			// template settings
431
+			'template_settings'      => [
432
+				'nav'           => [
433
+					'label' => esc_html__('Templates', 'event_espresso'),
434
+					'order' => 30,
435
+				],
436
+				'metaboxes'     => $this->_default_espresso_metaboxes,
437
+				'help_tabs'     => [
438
+					'general_settings_templates_help_tab' => [
439
+						'title'    => esc_html__('Templates', 'event_espresso'),
440
+						'filename' => 'general_settings_templates',
441
+					],
442
+				],
443
+				'require_nonce' => false,
444
+			],
445
+			// event category stuff
446
+			'add_category'           => [
447
+				'nav'           => [
448
+					'label'      => esc_html__('Add Category', 'event_espresso'),
449
+					'order'      => 15,
450
+					'persistent' => false,
451
+				],
452
+				'help_tabs'     => [
453
+					'add_category_help_tab' => [
454
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
455
+						'filename' => 'events_add_category',
456
+					],
457
+				],
458
+				'metaboxes'     => ['_publish_post_box'],
459
+				'require_nonce' => false,
460
+			],
461
+			'edit_category'          => [
462
+				'nav'           => [
463
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
464
+					'order'      => 15,
465
+					'persistent' => false,
466
+					'url'        => $EVT_CAT_ID
467
+						? add_query_arg(
468
+							['EVT_CAT_ID' => $EVT_CAT_ID],
469
+							$this->_current_page_view_url
470
+						)
471
+						: $this->_admin_base_url,
472
+				],
473
+				'help_tabs'     => [
474
+					'edit_category_help_tab' => [
475
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
476
+						'filename' => 'events_edit_category',
477
+					],
478
+				],
479
+				'metaboxes'     => ['_publish_post_box'],
480
+				'require_nonce' => false,
481
+			],
482
+			'category_list'          => [
483
+				'nav'           => [
484
+					'label' => esc_html__('Categories', 'event_espresso'),
485
+					'order' => 20,
486
+				],
487
+				'list_table'    => 'Event_Categories_Admin_List_Table',
488
+				'help_tabs'     => [
489
+					'events_categories_help_tab'                       => [
490
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
491
+						'filename' => 'events_categories',
492
+					],
493
+					'events_categories_table_column_headings_help_tab' => [
494
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
495
+						'filename' => 'events_categories_table_column_headings',
496
+					],
497
+					'events_categories_view_help_tab'                  => [
498
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
499
+						'filename' => 'events_categories_views',
500
+					],
501
+					'events_categories_other_help_tab'                 => [
502
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
503
+						'filename' => 'events_categories_other',
504
+					],
505
+				],
506
+				'metaboxes'     => $this->_default_espresso_metaboxes,
507
+				'require_nonce' => false,
508
+			],
509
+			'preview_deletion'       => [
510
+				'nav'           => [
511
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
512
+					'order'      => 15,
513
+					'persistent' => false,
514
+					'url'        => '',
515
+				],
516
+				'require_nonce' => false,
517
+			],
518
+		];
519
+	}
520
+
521
+
522
+	/**
523
+	 * Used to register any global screen options if necessary for every route in this admin page group.
524
+	 */
525
+	protected function _add_screen_options()
526
+	{
527
+	}
528
+
529
+
530
+	/**
531
+	 * Implementing the screen options for the 'default' route.
532
+	 *
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 */
537
+	protected function _add_screen_options_default()
538
+	{
539
+		$this->_per_page_screen_option();
540
+	}
541
+
542
+
543
+	/**
544
+	 * Implementing screen options for the category list route.
545
+	 *
546
+	 * @throws InvalidArgumentException
547
+	 * @throws InvalidDataTypeException
548
+	 * @throws InvalidInterfaceException
549
+	 */
550
+	protected function _add_screen_options_category_list()
551
+	{
552
+		$page_title              = $this->_admin_page_title;
553
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
554
+		$this->_per_page_screen_option();
555
+		$this->_admin_page_title = $page_title;
556
+	}
557
+
558
+
559
+	/**
560
+	 * Used to register any global feature pointers for the admin page group.
561
+	 */
562
+	protected function _add_feature_pointers()
563
+	{
564
+	}
565
+
566
+
567
+	/**
568
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
569
+	 */
570
+	public function load_scripts_styles()
571
+	{
572
+		wp_register_style(
573
+			'events-admin-css',
574
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
575
+			[],
576
+			EVENT_ESPRESSO_VERSION
577
+		);
578
+		wp_register_style(
579
+			'ee-cat-admin',
580
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
581
+			[],
582
+			EVENT_ESPRESSO_VERSION
583
+		);
584
+		wp_enqueue_style('events-admin-css');
585
+		wp_enqueue_style('ee-cat-admin');
586
+		// scripts
587
+		wp_register_script(
588
+			'event_editor_js',
589
+			EVENTS_ASSETS_URL . 'event_editor.js',
590
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
591
+			EVENT_ESPRESSO_VERSION,
592
+			true
593
+		);
594
+	}
595
+
596
+
597
+	/**
598
+	 * Enqueuing scripts and styles specific to this view
599
+	 */
600
+	public function load_scripts_styles_create_new()
601
+	{
602
+		$this->load_scripts_styles_edit();
603
+	}
604
+
605
+
606
+	/**
607
+	 * Enqueuing scripts and styles specific to this view
608
+	 */
609
+	public function load_scripts_styles_edit()
610
+	{
611
+		// styles
612
+		wp_enqueue_style('espresso-ui-theme');
613
+		wp_register_style(
614
+			'event-editor-css',
615
+			EVENTS_ASSETS_URL . 'event-editor.css',
616
+			['ee-admin-css'],
617
+			EVENT_ESPRESSO_VERSION
618
+		);
619
+		wp_enqueue_style('event-editor-css');
620
+		// scripts
621
+		if (! $this->admin_config->useAdvancedEditor()) {
622
+			wp_register_script(
623
+				'event-datetime-metabox',
624
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
625
+				['event_editor_js', 'ee-datepicker'],
626
+				EVENT_ESPRESSO_VERSION
627
+			);
628
+			wp_enqueue_script('event-datetime-metabox');
629
+		}
630
+	}
631
+
632
+
633
+	/**
634
+	 * Populating the _views property for the category list table view.
635
+	 */
636
+	protected function _set_list_table_views_category_list()
637
+	{
638
+		$this->_views = [
639
+			'all' => [
640
+				'slug'        => 'all',
641
+				'label'       => esc_html__('All', 'event_espresso'),
642
+				'count'       => 0,
643
+				'bulk_action' => [
644
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
645
+				],
646
+			],
647
+		];
648
+	}
649
+
650
+
651
+	/**
652
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
653
+	 */
654
+	public function admin_init()
655
+	{
656
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
657
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
658
+			'event_espresso'
659
+		);
660
+	}
661
+
662
+
663
+	/**
664
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
665
+	 * group.
666
+	 */
667
+	public function admin_notices()
668
+	{
669
+	}
670
+
671
+
672
+	/**
673
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
674
+	 * this admin page group.
675
+	 */
676
+	public function admin_footer_scripts()
677
+	{
678
+	}
679
+
680
+
681
+	/**
682
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
683
+	 * warning (via EE_Error::add_error());
684
+	 *
685
+	 * @param EE_Event $event Event object
686
+	 * @param string   $req_type
687
+	 * @return void
688
+	 * @throws EE_Error
689
+	 * @throws ReflectionException
690
+	 */
691
+	public function verify_event_edit($event = null, $req_type = '')
692
+	{
693
+		// don't need to do this when processing
694
+		if (! empty($req_type)) {
695
+			return;
696
+		}
697
+		// no event?
698
+		if (! $event instanceof EE_Event) {
699
+			$event = $this->_cpt_model_obj;
700
+		}
701
+		// STILL no event?
702
+		if (! $event instanceof EE_Event) {
703
+			return;
704
+		}
705
+		$orig_status = $event->status();
706
+		// first check if event is active.
707
+		if (
708
+			$orig_status === EEM_Event::cancelled
709
+			|| $orig_status === EEM_Event::postponed
710
+			|| $event->is_expired()
711
+			|| $event->is_inactive()
712
+		) {
713
+			return;
714
+		}
715
+		// made it here so it IS active... next check that any of the tickets are sold.
716
+		if ($event->is_sold_out(true)) {
717
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
718
+				EE_Error::add_attention(
719
+					sprintf(
720
+						esc_html__(
721
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
722
+							'event_espresso'
723
+						),
724
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
725
+					)
726
+				);
727
+			}
728
+			return;
729
+		}
730
+		if ($orig_status === EEM_Event::sold_out) {
731
+			EE_Error::add_attention(
732
+				sprintf(
733
+					esc_html__(
734
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
735
+						'event_espresso'
736
+					),
737
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
738
+				)
739
+			);
740
+		}
741
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
742
+		if (! $event->tickets_on_sale()) {
743
+			return;
744
+		}
745
+		// made it here so show warning
746
+		$this->_edit_event_warning();
747
+	}
748
+
749
+
750
+	/**
751
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
752
+	 * When needed, hook this into a EE_Error::add_error() notice.
753
+	 *
754
+	 * @access protected
755
+	 * @return void
756
+	 */
757
+	protected function _edit_event_warning()
758
+	{
759
+		// we don't want to add warnings during these requests
760
+		if ($this->request->getRequestParam('action') === 'editpost') {
761
+			return;
762
+		}
763
+		EE_Error::add_attention(
764
+			sprintf(
765
+				esc_html__(
766
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
767
+					'event_espresso'
768
+				),
769
+				'<a class="espresso-help-tab-lnk ee-help-tab-link">',
770
+				'</a>'
771
+			)
772
+		);
773
+	}
774
+
775
+
776
+	/**
777
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
778
+	 * Otherwise, do the normal logic
779
+	 *
780
+	 * @return void
781
+	 * @throws EE_Error
782
+	 * @throws InvalidArgumentException
783
+	 * @throws InvalidDataTypeException
784
+	 * @throws InvalidInterfaceException
785
+	 */
786
+	protected function _create_new_cpt_item()
787
+	{
788
+		$has_timezone_string = get_option('timezone_string');
789
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
790
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
791
+			EE_Error::add_attention(
792
+				sprintf(
793
+					esc_html__(
794
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
795
+						'event_espresso'
796
+					),
797
+					'<br>',
798
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
799
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
800
+					. '</select>',
801
+					'<button class="button button--secondary timezone-submit">',
802
+					'</button><span class="spinner"></span>'
803
+				),
804
+				__FILE__,
805
+				__FUNCTION__,
806
+				__LINE__
807
+			);
808
+		}
809
+		parent::_create_new_cpt_item();
810
+	}
811
+
812
+
813
+	/**
814
+	 * Sets the _views property for the default route in this admin page group.
815
+	 */
816
+	protected function _set_list_table_views_default()
817
+	{
818
+		$this->_views = [
819
+			'all'   => [
820
+				'slug'        => 'all',
821
+				'label'       => esc_html__('View All Events', 'event_espresso'),
822
+				'count'       => 0,
823
+				'bulk_action' => [
824
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
825
+				],
826
+			],
827
+			'draft' => [
828
+				'slug'        => 'draft',
829
+				'label'       => esc_html__('Draft', 'event_espresso'),
830
+				'count'       => 0,
831
+				'bulk_action' => [
832
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
833
+				],
834
+			],
835
+		];
836
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
837
+			$this->_views['trash'] = [
838
+				'slug'        => 'trash',
839
+				'label'       => esc_html__('Trash', 'event_espresso'),
840
+				'count'       => 0,
841
+				'bulk_action' => [
842
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
843
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
844
+				],
845
+			];
846
+		}
847
+	}
848
+
849
+
850
+	/**
851
+	 * Provides the legend item array for the default list table view.
852
+	 *
853
+	 * @return array
854
+	 * @throws EE_Error
855
+	 * @throws EE_Error
856
+	 */
857
+	protected function _event_legend_items()
858
+	{
859
+		$items    = [
860
+			'view_details'   => [
861
+				'class' => 'dashicons dashicons-visibility',
862
+				'desc'  => esc_html__('View Event', 'event_espresso'),
863
+			],
864
+			'edit_event'     => [
865
+				'class' => 'dashicons dashicons-calendar-alt',
866
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
867
+			],
868
+			'view_attendees' => [
869
+				'class' => 'dashicons dashicons-groups',
870
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
871
+			],
872
+		];
873
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
874
+		$statuses = [
875
+			'sold_out_status'  => [
876
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
877
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
878
+			],
879
+			'active_status'    => [
880
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
881
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
882
+			],
883
+			'upcoming_status'  => [
884
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
885
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
886
+			],
887
+			'postponed_status' => [
888
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
889
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
890
+			],
891
+			'cancelled_status' => [
892
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
893
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
894
+			],
895
+			'expired_status'   => [
896
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
897
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
898
+			],
899
+			'inactive_status'  => [
900
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
901
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
902
+			],
903
+		];
904
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
905
+		return array_merge($items, $statuses);
906
+	}
907
+
908
+
909
+	/**
910
+	 * @return EEM_Event
911
+	 * @throws EE_Error
912
+	 * @throws InvalidArgumentException
913
+	 * @throws InvalidDataTypeException
914
+	 * @throws InvalidInterfaceException
915
+	 * @throws ReflectionException
916
+	 */
917
+	private function _event_model()
918
+	{
919
+		if (! $this->_event_model instanceof EEM_Event) {
920
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
921
+		}
922
+		return $this->_event_model;
923
+	}
924
+
925
+
926
+	/**
927
+	 * Adds extra buttons to the WP CPT permalink field row.
928
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
929
+	 *
930
+	 * @param string $return    the current html
931
+	 * @param int    $id        the post id for the page
932
+	 * @param string $new_title What the title is
933
+	 * @param string $new_slug  what the slug is
934
+	 * @return string            The new html string for the permalink area
935
+	 */
936
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
937
+	{
938
+		// make sure this is only when editing
939
+		if (! empty($id)) {
940
+			$post = get_post($id);
941
+			$return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
942
+					   . esc_html__('Shortcode', 'event_espresso')
943
+					   . '</a> ';
944
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
945
+					   . $post->ID
946
+					   . ']">';
947
+		}
948
+		return $return;
949
+	}
950
+
951
+
952
+	/**
953
+	 * _events_overview_list_table
954
+	 * This contains the logic for showing the events_overview list
955
+	 *
956
+	 * @access protected
957
+	 * @return void
958
+	 * @throws DomainException
959
+	 * @throws EE_Error
960
+	 * @throws InvalidArgumentException
961
+	 * @throws InvalidDataTypeException
962
+	 * @throws InvalidInterfaceException
963
+	 */
964
+	protected function _events_overview_list_table()
965
+	{
966
+		$after_list_table                           = [];
967
+		$links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
968
+		$links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
969
+		$links_html .= EEH_HTML::div(
970
+			EEH_Template::get_button_or_link(
971
+				get_post_type_archive_link('espresso_events'),
972
+				esc_html__('View Event Archive Page', 'event_espresso'),
973
+				'button button--small button--secondary'
974
+			),
975
+			'',
976
+			'ee-admin-button-row ee-admin-button-row--align-start'
977
+		);
978
+		$links_html .= EEH_HTML::divx();
979
+
980
+		$after_list_table['view_event_list_button'] = $links_html;
981
+
982
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
983
+		$this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
984
+			'create_new',
985
+			'add',
986
+			[],
987
+			'add-new-h2'
988
+		);
989
+
990
+		$this->_template_args['after_list_table']   = array_merge(
991
+			(array) $this->_template_args['after_list_table'],
992
+			$after_list_table
993
+		);
994
+		$this->display_admin_list_table_page_with_no_sidebar();
995
+	}
996
+
997
+
998
+	/**
999
+	 * this allows for extra misc actions in the default WP publish box
1000
+	 *
1001
+	 * @return void
1002
+	 * @throws DomainException
1003
+	 * @throws EE_Error
1004
+	 * @throws InvalidArgumentException
1005
+	 * @throws InvalidDataTypeException
1006
+	 * @throws InvalidInterfaceException
1007
+	 * @throws ReflectionException
1008
+	 */
1009
+	public function extra_misc_actions_publish_box()
1010
+	{
1011
+		$this->_generate_publish_box_extra_content();
1012
+	}
1013
+
1014
+
1015
+	/**
1016
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1017
+	 * saved.
1018
+	 * Typically you would use this to save any additional data.
1019
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1020
+	 * ALSO very important.  When a post transitions from scheduled to published,
1021
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1022
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1023
+	 *
1024
+	 * @access protected
1025
+	 * @abstract
1026
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1027
+	 * @param WP_Post $post    The post object of the cpt that was saved.
1028
+	 * @return void
1029
+	 * @throws EE_Error
1030
+	 * @throws InvalidArgumentException
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidInterfaceException
1033
+	 * @throws ReflectionException
1034
+	 */
1035
+	protected function _insert_update_cpt_item($post_id, $post)
1036
+	{
1037
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1038
+			// get out we're not processing an event save.
1039
+			return;
1040
+		}
1041
+		$event_values = [
1042
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1043
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1044
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1045
+		];
1046
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1047
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1048
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1049
+				'display_ticket_selector',
1050
+				false,
1051
+				'bool'
1052
+			);
1053
+			$event_values['EVT_additional_limit']            = min(
1054
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1055
+				$this->request->getRequestParam('additional_limit', null, 'int')
1056
+			);
1057
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1058
+				'EVT_default_registration_status',
1059
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1060
+			);
1061
+
1062
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1063
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1064
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1065
+		}
1066
+		// update event
1067
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1068
+		// get event_object for other metaboxes...
1069
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1070
+		// i have to setup where conditions to override the filters in the model
1071
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1072
+		$event = $this->_event_model()->get_one(
1073
+			[
1074
+				[
1075
+					$this->_event_model()->primary_key_name() => $post_id,
1076
+					'OR'                                      => [
1077
+						'status'   => $post->post_status,
1078
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1079
+						// but the returned object here has a status of "publish", so use the original post status as well
1080
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1081
+					],
1082
+				],
1083
+			]
1084
+		);
1085
+
1086
+		// the following are default callbacks for event attachment updates
1087
+		// that can be overridden by caffeinated functionality and/or addons.
1088
+		$event_update_callbacks = [];
1089
+		if (! $this->admin_config->useAdvancedEditor()) {
1090
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1091
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1092
+		}
1093
+		$event_update_callbacks = apply_filters(
1094
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1095
+			$event_update_callbacks
1096
+		);
1097
+
1098
+		$att_success = true;
1099
+		foreach ($event_update_callbacks as $e_callback) {
1100
+			$_success = is_callable($e_callback)
1101
+				? $e_callback($event, $this->request->requestParams())
1102
+				: false;
1103
+			// if ANY of these updates fail then we want the appropriate global error message
1104
+			$att_success = $_success !== false ? $att_success : false;
1105
+		}
1106
+		// any errors?
1107
+		if ($success && $att_success === false) {
1108
+			EE_Error::add_error(
1109
+				esc_html__(
1110
+					'Event Details saved successfully but something went wrong with saving attachments.',
1111
+					'event_espresso'
1112
+				),
1113
+				__FILE__,
1114
+				__FUNCTION__,
1115
+				__LINE__
1116
+			);
1117
+		} elseif ($success === false) {
1118
+			EE_Error::add_error(
1119
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1120
+				__FILE__,
1121
+				__FUNCTION__,
1122
+				__LINE__
1123
+			);
1124
+		}
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * @param int $post_id
1130
+	 * @param int $revision_id
1131
+	 * @throws EE_Error
1132
+	 * @throws EE_Error
1133
+	 * @throws ReflectionException
1134
+	 * @see parent::restore_item()
1135
+	 */
1136
+	protected function _restore_cpt_item($post_id, $revision_id)
1137
+	{
1138
+		// copy existing event meta to new post
1139
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1140
+		if ($post_evt instanceof EE_Event) {
1141
+			// meta revision restore
1142
+			$post_evt->restore_revision($revision_id);
1143
+			// related objs restore
1144
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1145
+		}
1146
+	}
1147
+
1148
+
1149
+	/**
1150
+	 * Attach the venue to the Event
1151
+	 *
1152
+	 * @param EE_Event $event Event Object to add the venue to
1153
+	 * @param array    $data  The request data from the form
1154
+	 * @return bool           Success or fail.
1155
+	 * @throws EE_Error
1156
+	 * @throws ReflectionException
1157
+	 */
1158
+	protected function _default_venue_update(EE_Event $event, $data)
1159
+	{
1160
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1161
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1162
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1163
+		// very important.  If we don't have a venue name...
1164
+		// then we'll get out because not necessary to create empty venue
1165
+		if (empty($data['venue_title'])) {
1166
+			return false;
1167
+		}
1168
+		$venue_array = [
1169
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1170
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1171
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1172
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1173
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1174
+				? $data['venue_short_description']
1175
+				: null,
1176
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1177
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1178
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1179
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1180
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1181
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1182
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1183
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1184
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1185
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1186
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1187
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1188
+			'status'              => 'publish',
1189
+		];
1190
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1191
+		if (! empty($venue_id)) {
1192
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1193
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1194
+			// we've gotta make sure that the venue is always attached to a revision..
1195
+			// add_relation_to should take care of making sure that the relation is already present.
1196
+			$event->_add_relation_to($venue_id, 'Venue');
1197
+			return $rows_affected > 0;
1198
+		}
1199
+		// we insert the venue
1200
+		$venue_id = $venue_model->insert($venue_array);
1201
+		$event->_add_relation_to($venue_id, 'Venue');
1202
+		return ! empty($venue_id);
1203
+		// when we have the ancestor come in it's already been handled by the revision save.
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1209
+	 *
1210
+	 * @param EE_Event $event The Event object we're attaching data to
1211
+	 * @param array    $data  The request data from the form
1212
+	 * @return array
1213
+	 * @throws EE_Error
1214
+	 * @throws ReflectionException
1215
+	 * @throws Exception
1216
+	 */
1217
+	protected function _default_tickets_update(EE_Event $event, $data)
1218
+	{
1219
+		if ($this->admin_config->useAdvancedEditor()) {
1220
+			return [];
1221
+		}
1222
+		$datetime       = null;
1223
+		$saved_tickets  = [];
1224
+		$event_timezone = $event->get_timezone();
1225
+		$date_formats   = ['Y-m-d', 'h:i a'];
1226
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1227
+			// trim all values to ensure any excess whitespace is removed.
1228
+			$datetime_data                = array_map('trim', $datetime_data);
1229
+			$datetime_data['DTT_EVT_end'] =
1230
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1231
+					? $datetime_data['DTT_EVT_end']
1232
+					: $datetime_data['DTT_EVT_start'];
1233
+			$datetime_values              = [
1234
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1235
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1236
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1237
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1238
+				'DTT_order'     => $row,
1239
+			];
1240
+			// if we have an id then let's get existing object first and then set the new values.
1241
+			//  Otherwise we instantiate a new object for save.
1242
+			if (! empty($datetime_data['DTT_ID'])) {
1243
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1244
+				if (! $datetime instanceof EE_Datetime) {
1245
+					throw new RuntimeException(
1246
+						sprintf(
1247
+							esc_html__(
1248
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1249
+								'event_espresso'
1250
+							),
1251
+							$datetime_data['DTT_ID']
1252
+						)
1253
+					);
1254
+				}
1255
+				$datetime->set_date_format($date_formats[0]);
1256
+				$datetime->set_time_format($date_formats[1]);
1257
+				foreach ($datetime_values as $field => $value) {
1258
+					$datetime->set($field, $value);
1259
+				}
1260
+			} else {
1261
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1262
+			}
1263
+			if (! $datetime instanceof EE_Datetime) {
1264
+				throw new RuntimeException(
1265
+					sprintf(
1266
+						esc_html__(
1267
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1268
+							'event_espresso'
1269
+						),
1270
+						print_r($datetime_values, true)
1271
+					)
1272
+				);
1273
+			}
1274
+			// before going any further make sure our dates are setup correctly
1275
+			// so that the end date is always equal or greater than the start date.
1276
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1277
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1278
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1279
+			}
1280
+			$datetime->save();
1281
+			$event->_add_relation_to($datetime, 'Datetime');
1282
+		}
1283
+		// no datetimes get deleted so we don't do any of that logic here.
1284
+		// update tickets next
1285
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1286
+
1287
+		// set up some default start and end dates in case those are not present in the incoming data
1288
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1289
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1290
+		// use the start date of the first datetime for the end date
1291
+		$first_datetime   = $event->first_datetime();
1292
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1293
+
1294
+		// now process the incoming data
1295
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1296
+			$update_prices = false;
1297
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1298
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1299
+				: 0;
1300
+			// trim inputs to ensure any excess whitespace is removed.
1301
+			$ticket_data   = array_map('trim', $ticket_data);
1302
+			$ticket_values = [
1303
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1304
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1305
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1306
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1307
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1308
+					? $ticket_data['TKT_start_date']
1309
+					: $default_start_date,
1310
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1311
+					? $ticket_data['TKT_end_date']
1312
+					: $default_end_date,
1313
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1314
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1315
+					? $ticket_data['TKT_qty']
1316
+					: EE_INF,
1317
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1318
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1319
+					? $ticket_data['TKT_uses']
1320
+					: EE_INF,
1321
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1322
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1323
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1324
+				'TKT_price'       => $ticket_price,
1325
+				'TKT_row'         => $row,
1326
+			];
1327
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1328
+			// which means in turn that the prices will become new prices as well.
1329
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1330
+				$ticket_values['TKT_ID']         = 0;
1331
+				$ticket_values['TKT_is_default'] = 0;
1332
+				$update_prices                   = true;
1333
+			}
1334
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1335
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1336
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1337
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1338
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1339
+			if (! empty($ticket_data['TKT_ID'])) {
1340
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1341
+				if (! $existing_ticket instanceof EE_Ticket) {
1342
+					throw new RuntimeException(
1343
+						sprintf(
1344
+							esc_html__(
1345
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1346
+								'event_espresso'
1347
+							),
1348
+							$ticket_data['TKT_ID']
1349
+						)
1350
+					);
1351
+				}
1352
+				$ticket_sold = $existing_ticket->count_related(
1353
+					'Registration',
1354
+					[
1355
+							[
1356
+								'STS_ID' => [
1357
+									'NOT IN',
1358
+									[EEM_Registration::status_id_incomplete],
1359
+								],
1360
+							],
1361
+						]
1362
+				) > 0;
1363
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1364
+				// if they are different then we create a new ticket (if $ticket_sold)
1365
+				// if they aren't different then we go ahead and modify existing ticket.
1366
+				$create_new_ticket = $ticket_sold
1367
+									 && $ticket_price !== $existing_ticket->price()
1368
+									 && ! $existing_ticket->deleted();
1369
+				$existing_ticket->set_date_format($date_formats[0]);
1370
+				$existing_ticket->set_time_format($date_formats[1]);
1371
+				// set new values
1372
+				foreach ($ticket_values as $field => $value) {
1373
+					if ($field == 'TKT_qty') {
1374
+						$existing_ticket->set_qty($value);
1375
+					} elseif ($field == 'TKT_price') {
1376
+						$existing_ticket->set('TKT_price', $ticket_price);
1377
+					} else {
1378
+						$existing_ticket->set($field, $value);
1379
+					}
1380
+				}
1381
+				$ticket = $existing_ticket;
1382
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1383
+				//  Otherwise we have to create a new ticket.
1384
+				if ($create_new_ticket) {
1385
+					// archive the old ticket first
1386
+					$existing_ticket->set('TKT_deleted', 1);
1387
+					$existing_ticket->save();
1388
+					// make sure this ticket is still recorded in our $saved_tickets
1389
+					// so we don't run it through the regular trash routine.
1390
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1391
+					// create new ticket that's a copy of the existing except,
1392
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1393
+					$new_ticket = clone $existing_ticket;
1394
+					$new_ticket->set('TKT_ID', 0);
1395
+					$new_ticket->set('TKT_deleted', 0);
1396
+					$new_ticket->set('TKT_sold', 0);
1397
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1398
+					$update_prices = true;
1399
+					$ticket        = $new_ticket;
1400
+				}
1401
+			} else {
1402
+				// no TKT_id so a new ticket
1403
+				$ticket_values['TKT_price'] = $ticket_price;
1404
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1405
+				$update_prices              = true;
1406
+			}
1407
+			if (! $ticket instanceof EE_Ticket) {
1408
+				throw new RuntimeException(
1409
+					sprintf(
1410
+						esc_html__(
1411
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1412
+							'event_espresso'
1413
+						),
1414
+						print_r($ticket_values, true)
1415
+					)
1416
+				);
1417
+			}
1418
+			// cap ticket qty by datetime reg limits
1419
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1420
+			// update ticket.
1421
+			$ticket->save();
1422
+			// before going any further make sure our dates are setup correctly
1423
+			// so that the end date is always equal or greater than the start date.
1424
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1425
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1426
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1427
+				$ticket->save();
1428
+			}
1429
+			// initially let's add the ticket to the datetime
1430
+			$datetime->_add_relation_to($ticket, 'Ticket');
1431
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1432
+			// add prices to ticket
1433
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1434
+				? $data['edit_prices'][ $row ]
1435
+				: [];
1436
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1437
+		}
1438
+		// however now we need to handle permanently deleting tickets via the ui.
1439
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1440
+		// However, it does allow for deleting tickets that have no tickets sold,
1441
+		// in which case we want to get rid of permanently because there is no need to save in db.
1442
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1443
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1444
+		foreach ($tickets_removed as $id) {
1445
+			$id = absint($id);
1446
+			// get the ticket for this id
1447
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1448
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1449
+				continue;
1450
+			}
1451
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1452
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1453
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1454
+			foreach ($related_datetimes as $related_datetime) {
1455
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1456
+			}
1457
+			// need to do the same for prices (except these prices can also be deleted because again,
1458
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1459
+			$ticket_to_remove->delete_related_permanently('Price');
1460
+			// finally let's delete this ticket
1461
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1462
+			$ticket_to_remove->delete_permanently();
1463
+		}
1464
+		return [$datetime, $saved_tickets];
1465
+	}
1466
+
1467
+
1468
+	/**
1469
+	 * This attaches a list of given prices to a ticket.
1470
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1471
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1472
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1473
+	 *
1474
+	 * @access  private
1475
+	 * @param array     $prices_data Array of prices from the form.
1476
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1477
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1478
+	 * @return  void
1479
+	 * @throws EE_Error
1480
+	 * @throws ReflectionException
1481
+	 */
1482
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1483
+	{
1484
+		$timezone = $ticket->get_timezone();
1485
+		foreach ($prices_data as $row => $price_data) {
1486
+			$price_values = [
1487
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1488
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1489
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1490
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1491
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1492
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1493
+				'PRC_order'      => $row,
1494
+			];
1495
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1496
+				$price_values['PRC_ID'] = 0;
1497
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1498
+			} else {
1499
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1500
+				// update this price with new values
1501
+				foreach ($price_values as $field => $new_price) {
1502
+					$price->set($field, $new_price);
1503
+				}
1504
+			}
1505
+			if (! $price instanceof EE_Price) {
1506
+				throw new RuntimeException(
1507
+					sprintf(
1508
+						esc_html__(
1509
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1510
+							'event_espresso'
1511
+						),
1512
+						print_r($price_values, true)
1513
+					)
1514
+				);
1515
+			}
1516
+			$price->save();
1517
+			$ticket->_add_relation_to($price, 'Price');
1518
+		}
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * Add in our autosave ajax handlers
1524
+	 *
1525
+	 */
1526
+	protected function _ee_autosave_create_new()
1527
+	{
1528
+	}
1529
+
1530
+
1531
+	/**
1532
+	 * More autosave handlers.
1533
+	 */
1534
+	protected function _ee_autosave_edit()
1535
+	{
1536
+	}
1537
+
1538
+
1539
+	/**
1540
+	 * @throws EE_Error
1541
+	 * @throws ReflectionException
1542
+	 */
1543
+	private function _generate_publish_box_extra_content()
1544
+	{
1545
+		// load formatter helper
1546
+		// args for getting related registrations
1547
+		$approved_query_args        = [
1548
+			[
1549
+				'REG_deleted' => 0,
1550
+				'STS_ID'      => EEM_Registration::status_id_approved,
1551
+			],
1552
+		];
1553
+		$not_approved_query_args    = [
1554
+			[
1555
+				'REG_deleted' => 0,
1556
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1557
+			],
1558
+		];
1559
+		$pending_payment_query_args = [
1560
+			[
1561
+				'REG_deleted' => 0,
1562
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1563
+			],
1564
+		];
1565
+		// publish box
1566
+		$publish_box_extra_args = [
1567
+			'view_approved_reg_url'        => add_query_arg(
1568
+				[
1569
+					'action'      => 'default',
1570
+					'event_id'    => $this->_cpt_model_obj->ID(),
1571
+					'_reg_status' => EEM_Registration::status_id_approved,
1572
+				],
1573
+				REG_ADMIN_URL
1574
+			),
1575
+			'view_not_approved_reg_url'    => add_query_arg(
1576
+				[
1577
+					'action'      => 'default',
1578
+					'event_id'    => $this->_cpt_model_obj->ID(),
1579
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1580
+				],
1581
+				REG_ADMIN_URL
1582
+			),
1583
+			'view_pending_payment_reg_url' => add_query_arg(
1584
+				[
1585
+					'action'      => 'default',
1586
+					'event_id'    => $this->_cpt_model_obj->ID(),
1587
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1588
+				],
1589
+				REG_ADMIN_URL
1590
+			),
1591
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1592
+				'Registration',
1593
+				$approved_query_args
1594
+			),
1595
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1596
+				'Registration',
1597
+				$not_approved_query_args
1598
+			),
1599
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1600
+				'Registration',
1601
+				$pending_payment_query_args
1602
+			),
1603
+			'misc_pub_section_class'       => apply_filters(
1604
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1605
+				'misc-pub-section'
1606
+			),
1607
+		];
1608
+		ob_start();
1609
+		do_action(
1610
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1611
+			$this->_cpt_model_obj
1612
+		);
1613
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1614
+		// load template
1615
+		EEH_Template::display_template(
1616
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1617
+			$publish_box_extra_args
1618
+		);
1619
+	}
1620
+
1621
+
1622
+	/**
1623
+	 * @return EE_Event
1624
+	 */
1625
+	public function get_event_object()
1626
+	{
1627
+		return $this->_cpt_model_obj;
1628
+	}
1629
+
1630
+
1631
+
1632
+
1633
+	/** METABOXES * */
1634
+	/**
1635
+	 * _register_event_editor_meta_boxes
1636
+	 * add all metaboxes related to the event_editor
1637
+	 *
1638
+	 * @return void
1639
+	 * @throws EE_Error
1640
+	 * @throws ReflectionException
1641
+	 */
1642
+	protected function _register_event_editor_meta_boxes()
1643
+	{
1644
+		$this->verify_cpt_object();
1645
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1646
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1647
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1648
+			$this->addMetaBox(
1649
+				'espresso_event_editor_event_options',
1650
+				esc_html__('Event Registration Options', 'event_espresso'),
1651
+				[$this, 'registration_options_meta_box'],
1652
+				$this->page_slug,
1653
+				'side'
1654
+			);
1655
+		}
1656
+		if (! $use_advanced_editor) {
1657
+			$this->addMetaBox(
1658
+				'espresso_event_editor_tickets',
1659
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1660
+				[$this, 'ticket_metabox'],
1661
+				$this->page_slug,
1662
+				'normal',
1663
+				'high'
1664
+			);
1665
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1666
+			add_action(
1667
+				'add_meta_boxes_espresso_events',
1668
+				function () {
1669
+					global $current_screen;
1670
+					remove_meta_box('authordiv', $current_screen, 'normal');
1671
+				},
1672
+				99
1673
+			);
1674
+		}
1675
+		// NOTE: if you're looking for other metaboxes in here,
1676
+		// where a metabox has a related management page in the admin
1677
+		// you will find it setup in the related management page's "_Hooks" file.
1678
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * @throws DomainException
1684
+	 * @throws EE_Error
1685
+	 * @throws ReflectionException
1686
+	 */
1687
+	public function ticket_metabox()
1688
+	{
1689
+		$existing_datetime_ids = $existing_ticket_ids = [];
1690
+		// defaults for template args
1691
+		$template_args = [
1692
+			'existing_datetime_ids'    => '',
1693
+			'event_datetime_help_link' => '',
1694
+			'ticket_options_help_link' => '',
1695
+			'time'                     => null,
1696
+			'ticket_rows'              => '',
1697
+			'existing_ticket_ids'      => '',
1698
+			'total_ticket_rows'        => 1,
1699
+			'ticket_js_structure'      => '',
1700
+			'trash_icon'               => 'dashicons dashicons-lock',
1701
+			'disabled'                 => '',
1702
+		];
1703
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1704
+		/**
1705
+		 * 1. Start with retrieving Datetimes
1706
+		 * 2. Fore each datetime get related tickets
1707
+		 * 3. For each ticket get related prices
1708
+		 */
1709
+		/** @var EEM_Datetime $datetime_model */
1710
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1711
+		/** @var EEM_Ticket $datetime_model */
1712
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1713
+		$times        = $datetime_model->get_all_event_dates($event_id);
1714
+		/** @type EE_Datetime $first_datetime */
1715
+		$first_datetime = reset($times);
1716
+		// do we get related tickets?
1717
+		if (
1718
+			$first_datetime instanceof EE_Datetime
1719
+			&& $first_datetime->ID() !== 0
1720
+		) {
1721
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1722
+			$template_args['time']   = $first_datetime;
1723
+			$related_tickets         = $first_datetime->tickets(
1724
+				[
1725
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1726
+					'default_where_conditions' => 'none',
1727
+				]
1728
+			);
1729
+			if (! empty($related_tickets)) {
1730
+				$template_args['total_ticket_rows'] = count($related_tickets);
1731
+				$row                                = 0;
1732
+				foreach ($related_tickets as $ticket) {
1733
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1734
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1735
+					$row++;
1736
+				}
1737
+			} else {
1738
+				$template_args['total_ticket_rows'] = 1;
1739
+				/** @type EE_Ticket $ticket */
1740
+				$ticket                       = $ticket_model->create_default_object();
1741
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1742
+			}
1743
+		} else {
1744
+			$template_args['time'] = $times[0];
1745
+			/** @type EE_Ticket[] $tickets */
1746
+			$tickets                      = $ticket_model->get_all_default_tickets();
1747
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1748
+			// NOTE: we're just sending the first default row
1749
+			// (decaf can't manage default tickets so this should be sufficient);
1750
+		}
1751
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1752
+			'event_editor_event_datetimes_help_tab'
1753
+		);
1754
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1755
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1756
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1757
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1758
+			$ticket_model->create_default_object(),
1759
+			true
1760
+		);
1761
+		$template                                  = apply_filters(
1762
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1763
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1764
+		);
1765
+		EEH_Template::display_template($template, $template_args);
1766
+	}
1767
+
1768
+
1769
+	/**
1770
+	 * Setup an individual ticket form for the decaf event editor page
1771
+	 *
1772
+	 * @access private
1773
+	 * @param EE_Ticket $ticket   the ticket object
1774
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1775
+	 * @param int       $row
1776
+	 * @return string generated html for the ticket row.
1777
+	 * @throws EE_Error
1778
+	 * @throws ReflectionException
1779
+	 */
1780
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1781
+	{
1782
+		$template_args = [
1783
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1784
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1785
+				: '',
1786
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1787
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1788
+			'TKT_name'            => $ticket->get('TKT_name'),
1789
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1790
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1791
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1792
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1793
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1794
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1795
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1796
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1797
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1798
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1799
+				: ' disabled=disabled',
1800
+		];
1801
+		$price         = $ticket->ID() !== 0
1802
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1803
+			: null;
1804
+		$price         = $price instanceof EE_Price
1805
+			? $price
1806
+			: EEM_Price::instance()->create_default_object();
1807
+		$price_args    = [
1808
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1809
+			'PRC_amount'            => $price->get('PRC_amount'),
1810
+			'PRT_ID'                => $price->get('PRT_ID'),
1811
+			'PRC_ID'                => $price->get('PRC_ID'),
1812
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1813
+		];
1814
+		// make sure we have default start and end dates if skeleton
1815
+		// handle rows that should NOT be empty
1816
+		if (empty($template_args['TKT_start_date'])) {
1817
+			// if empty then the start date will be now.
1818
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1819
+		}
1820
+		if (empty($template_args['TKT_end_date'])) {
1821
+			// get the earliest datetime (if present);
1822
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1823
+				? $this->_cpt_model_obj->get_first_related(
1824
+					'Datetime',
1825
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1826
+				)
1827
+				: null;
1828
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1829
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1830
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1831
+		}
1832
+		$template_args = array_merge($template_args, $price_args);
1833
+		$template      = apply_filters(
1834
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1835
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1836
+			$ticket
1837
+		);
1838
+		return EEH_Template::display_template($template, $template_args, true);
1839
+	}
1840
+
1841
+
1842
+	/**
1843
+	 * @throws EE_Error
1844
+	 * @throws ReflectionException
1845
+	 */
1846
+	public function registration_options_meta_box()
1847
+	{
1848
+		$yes_no_values             = [
1849
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1850
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1851
+		];
1852
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1853
+			[
1854
+				EEM_Registration::status_id_cancelled,
1855
+				EEM_Registration::status_id_declined,
1856
+				EEM_Registration::status_id_incomplete,
1857
+			],
1858
+			true
1859
+		);
1860
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1861
+		$template_args['_event']                          = $this->_cpt_model_obj;
1862
+		$template_args['event']                           = $this->_cpt_model_obj;
1863
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1864
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1865
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1866
+			'default_reg_status',
1867
+			$default_reg_status_values,
1868
+			$this->_cpt_model_obj->default_registration_status()
1869
+		);
1870
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1871
+			'display_desc',
1872
+			$yes_no_values,
1873
+			$this->_cpt_model_obj->display_description()
1874
+		);
1875
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1876
+			'display_ticket_selector',
1877
+			$yes_no_values,
1878
+			$this->_cpt_model_obj->display_ticket_selector(),
1879
+			'',
1880
+			'',
1881
+			false
1882
+		);
1883
+		$template_args['additional_registration_options'] = apply_filters(
1884
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1885
+			'',
1886
+			$template_args,
1887
+			$yes_no_values,
1888
+			$default_reg_status_values
1889
+		);
1890
+		EEH_Template::display_template(
1891
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1892
+			$template_args
1893
+		);
1894
+	}
1895
+
1896
+
1897
+	/**
1898
+	 * _get_events()
1899
+	 * This method simply returns all the events (for the given _view and paging)
1900
+	 *
1901
+	 * @access public
1902
+	 * @param int  $per_page     count of items per page (20 default);
1903
+	 * @param int  $current_page what is the current page being viewed.
1904
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1905
+	 *                           If FALSE then we return an array of event objects
1906
+	 *                           that match the given _view and paging parameters.
1907
+	 * @return array|int         an array of event objects or a count of them.
1908
+	 * @throws Exception
1909
+	 */
1910
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1911
+	{
1912
+		$EEM_Event   = $this->_event_model();
1913
+		$offset      = ($current_page - 1) * $per_page;
1914
+		$limit       = $count ? null : $offset . ',' . $per_page;
1915
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1916
+		$order       = $this->request->getRequestParam('order', 'DESC');
1917
+		$month_range = $this->request->getRequestParam('month_range');
1918
+		if ($month_range) {
1919
+			$pieces = explode(' ', $month_range, 3);
1920
+			// simulate the FIRST day of the month, that fixes issues for months like February
1921
+			// where PHP doesn't know what to assume for date.
1922
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1923
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1924
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1925
+		}
1926
+		$where  = [];
1927
+		$status = $this->request->getRequestParam('status');
1928
+		// determine what post_status our condition will have for the query.
1929
+		switch ($status) {
1930
+			case 'month':
1931
+			case 'today':
1932
+			case null:
1933
+			case 'all':
1934
+				break;
1935
+			case 'draft':
1936
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1937
+				break;
1938
+			default:
1939
+				$where['status'] = $status;
1940
+		}
1941
+		// categories? The default for all categories is -1
1942
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1943
+		if ($category !== -1) {
1944
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1945
+			$where['Term_Taxonomy.term_id']  = $category;
1946
+		}
1947
+		// date where conditions
1948
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1949
+		if ($month_range) {
1950
+			$DateTime = new DateTime(
1951
+				$year_r . '-' . $month_r . '-01 00:00:00',
1952
+				new DateTimeZone('UTC')
1953
+			);
1954
+			$start    = $DateTime->getTimestamp();
1955
+			// set the datetime to be the end of the month
1956
+			$DateTime->setDate(
1957
+				$year_r,
1958
+				$month_r,
1959
+				$DateTime->format('t')
1960
+			)->setTime(23, 59, 59);
1961
+			$end                             = $DateTime->getTimestamp();
1962
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1963
+		} elseif ($status === 'today') {
1964
+			$DateTime                        =
1965
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1966
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1967
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1968
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1969
+		} elseif ($status === 'month') {
1970
+			$now                             = date('Y-m-01');
1971
+			$DateTime                        =
1972
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1973
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1974
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1975
+														->setTime(23, 59, 59)
1976
+														->format(implode(' ', $start_formats));
1977
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1978
+		}
1979
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1980
+			$where['EVT_wp_user'] = get_current_user_id();
1981
+		} else {
1982
+			if (! isset($where['status'])) {
1983
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1984
+					$where['OR'] = [
1985
+						'status*restrict_private' => ['!=', 'private'],
1986
+						'AND'                     => [
1987
+							'status*inclusive' => ['=', 'private'],
1988
+							'EVT_wp_user'      => get_current_user_id(),
1989
+						],
1990
+					];
1991
+				}
1992
+			}
1993
+		}
1994
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1995
+		if (
1996
+			$wp_user
1997
+			&& $wp_user !== get_current_user_id()
1998
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1999
+		) {
2000
+			$where['EVT_wp_user'] = $wp_user;
2001
+		}
2002
+		// search query handling
2003
+		$search_term = $this->request->getRequestParam('s');
2004
+		if ($search_term) {
2005
+			$search_term = '%' . $search_term . '%';
2006
+			$where['OR'] = [
2007
+				'EVT_name'       => ['LIKE', $search_term],
2008
+				'EVT_desc'       => ['LIKE', $search_term],
2009
+				'EVT_short_desc' => ['LIKE', $search_term],
2010
+			];
2011
+		}
2012
+		// filter events by venue.
2013
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
2014
+		if ($venue) {
2015
+			$where['Venue.VNU_ID'] = $venue;
2016
+		}
2017
+		$request_params = $this->request->requestParams();
2018
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2019
+		$query_params   = apply_filters(
2020
+			'FHEE__Events_Admin_Page__get_events__query_params',
2021
+			[
2022
+				$where,
2023
+				'limit'    => $limit,
2024
+				'order_by' => $orderby,
2025
+				'order'    => $order,
2026
+				'group_by' => 'EVT_ID',
2027
+			],
2028
+			$request_params
2029
+		);
2030
+
2031
+		// let's first check if we have special requests coming in.
2032
+		$active_status = $this->request->getRequestParam('active_status');
2033
+		if ($active_status) {
2034
+			switch ($active_status) {
2035
+				case 'upcoming':
2036
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2037
+				case 'expired':
2038
+					return $EEM_Event->get_expired_events($query_params, $count);
2039
+				case 'active':
2040
+					return $EEM_Event->get_active_events($query_params, $count);
2041
+				case 'inactive':
2042
+					return $EEM_Event->get_inactive_events($query_params, $count);
2043
+			}
2044
+		}
2045
+
2046
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 * handling for WordPress CPT actions (trash, restore, delete)
2052
+	 *
2053
+	 * @param string $post_id
2054
+	 * @throws EE_Error
2055
+	 * @throws ReflectionException
2056
+	 */
2057
+	public function trash_cpt_item($post_id)
2058
+	{
2059
+		$this->request->setRequestParam('EVT_ID', $post_id);
2060
+		$this->_trash_or_restore_event('trash', false);
2061
+	}
2062
+
2063
+
2064
+	/**
2065
+	 * @param string $post_id
2066
+	 * @throws EE_Error
2067
+	 * @throws ReflectionException
2068
+	 */
2069
+	public function restore_cpt_item($post_id)
2070
+	{
2071
+		$this->request->setRequestParam('EVT_ID', $post_id);
2072
+		$this->_trash_or_restore_event('draft', false);
2073
+	}
2074
+
2075
+
2076
+	/**
2077
+	 * @param string $post_id
2078
+	 * @throws EE_Error
2079
+	 * @throws EE_Error
2080
+	 */
2081
+	public function delete_cpt_item($post_id)
2082
+	{
2083
+		throw new EE_Error(
2084
+			esc_html__(
2085
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2086
+				'event_espresso'
2087
+			)
2088
+		);
2089
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2090
+		// $this->_delete_event();
2091
+	}
2092
+
2093
+
2094
+	/**
2095
+	 * _trash_or_restore_event
2096
+	 *
2097
+	 * @access protected
2098
+	 * @param string $event_status
2099
+	 * @param bool   $redirect_after
2100
+	 * @throws EE_Error
2101
+	 * @throws EE_Error
2102
+	 * @throws ReflectionException
2103
+	 */
2104
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2105
+	{
2106
+		// determine the event id and set to array.
2107
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2108
+		// loop thru events
2109
+		if ($EVT_ID) {
2110
+			// clean status
2111
+			$event_status = sanitize_key($event_status);
2112
+			// grab status
2113
+			if (! empty($event_status)) {
2114
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2115
+			} else {
2116
+				$success = false;
2117
+				$msg     = esc_html__(
2118
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2119
+					'event_espresso'
2120
+				);
2121
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
+			}
2123
+		} else {
2124
+			$success = false;
2125
+			$msg     = esc_html__(
2126
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2127
+				'event_espresso'
2128
+			);
2129
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2130
+		}
2131
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2132
+		if ($redirect_after) {
2133
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2134
+		}
2135
+	}
2136
+
2137
+
2138
+	/**
2139
+	 * _trash_or_restore_events
2140
+	 *
2141
+	 * @access protected
2142
+	 * @param string $event_status
2143
+	 * @return void
2144
+	 * @throws EE_Error
2145
+	 * @throws EE_Error
2146
+	 * @throws ReflectionException
2147
+	 */
2148
+	protected function _trash_or_restore_events($event_status = 'trash')
2149
+	{
2150
+		// clean status
2151
+		$event_status = sanitize_key($event_status);
2152
+		// grab status
2153
+		if (! empty($event_status)) {
2154
+			$success = true;
2155
+			// determine the event id and set to array.
2156
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2157
+			// loop thru events
2158
+			foreach ($EVT_IDs as $EVT_ID) {
2159
+				if ($EVT_ID = absint($EVT_ID)) {
2160
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2161
+					$success = $results !== false ? $success : false;
2162
+				} else {
2163
+					$msg = sprintf(
2164
+						esc_html__(
2165
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2166
+							'event_espresso'
2167
+						),
2168
+						$EVT_ID
2169
+					);
2170
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
+					$success = false;
2172
+				}
2173
+			}
2174
+		} else {
2175
+			$success = false;
2176
+			$msg     = esc_html__(
2177
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2178
+				'event_espresso'
2179
+			);
2180
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2181
+		}
2182
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2183
+		$success = $success ? 2 : false;
2184
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2185
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2186
+	}
2187
+
2188
+
2189
+	/**
2190
+	 * @param int    $EVT_ID
2191
+	 * @param string $event_status
2192
+	 * @return bool
2193
+	 * @throws EE_Error
2194
+	 * @throws ReflectionException
2195
+	 */
2196
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2197
+	{
2198
+		// grab event id
2199
+		if (! $EVT_ID) {
2200
+			$msg = esc_html__(
2201
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2202
+				'event_espresso'
2203
+			);
2204
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2205
+			return false;
2206
+		}
2207
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2208
+		// clean status
2209
+		$event_status = sanitize_key($event_status);
2210
+		// grab status
2211
+		if (empty($event_status)) {
2212
+			$msg = esc_html__(
2213
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2214
+				'event_espresso'
2215
+			);
2216
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2217
+			return false;
2218
+		}
2219
+		// was event trashed or restored ?
2220
+		switch ($event_status) {
2221
+			case 'draft':
2222
+				$action = 'restored from the trash';
2223
+				$hook   = 'AHEE_event_restored_from_trash';
2224
+				break;
2225
+			case 'trash':
2226
+				$action = 'moved to the trash';
2227
+				$hook   = 'AHEE_event_moved_to_trash';
2228
+				break;
2229
+			default:
2230
+				$action = 'updated';
2231
+				$hook   = false;
2232
+		}
2233
+		// use class to change status
2234
+		$this->_cpt_model_obj->set_status($event_status);
2235
+		$success = $this->_cpt_model_obj->save();
2236
+		if (! $success) {
2237
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2238
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2239
+			return false;
2240
+		}
2241
+		if ($hook) {
2242
+			do_action($hook);
2243
+		}
2244
+		return true;
2245
+	}
2246
+
2247
+
2248
+	/**
2249
+	 * @param array $event_ids
2250
+	 * @return array
2251
+	 * @since   4.10.23.p
2252
+	 */
2253
+	private function cleanEventIds(array $event_ids)
2254
+	{
2255
+		return array_map('absint', $event_ids);
2256
+	}
2257
+
2258
+
2259
+	/**
2260
+	 * @return array
2261
+	 * @since   4.10.23.p
2262
+	 */
2263
+	private function getEventIdsFromRequest()
2264
+	{
2265
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2266
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2267
+		} else {
2268
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2269
+		}
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * @param bool $preview_delete
2275
+	 * @throws EE_Error
2276
+	 */
2277
+	protected function _delete_event($preview_delete = true)
2278
+	{
2279
+		$this->_delete_events($preview_delete);
2280
+	}
2281
+
2282
+
2283
+	/**
2284
+	 * Gets the tree traversal batch persister.
2285
+	 *
2286
+	 * @return NodeGroupDao
2287
+	 * @throws InvalidArgumentException
2288
+	 * @throws InvalidDataTypeException
2289
+	 * @throws InvalidInterfaceException
2290
+	 * @since 4.10.12.p
2291
+	 */
2292
+	protected function getModelObjNodeGroupPersister()
2293
+	{
2294
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2295
+			$this->model_obj_node_group_persister =
2296
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2297
+		}
2298
+		return $this->model_obj_node_group_persister;
2299
+	}
2300
+
2301
+
2302
+	/**
2303
+	 * @param bool $preview_delete
2304
+	 * @return void
2305
+	 * @throws EE_Error
2306
+	 */
2307
+	protected function _delete_events($preview_delete = true)
2308
+	{
2309
+		$event_ids = $this->getEventIdsFromRequest();
2310
+		if ($preview_delete) {
2311
+			$this->generateDeletionPreview($event_ids);
2312
+		} else {
2313
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2314
+		}
2315
+	}
2316
+
2317
+
2318
+	/**
2319
+	 * @param array $event_ids
2320
+	 */
2321
+	protected function generateDeletionPreview(array $event_ids)
2322
+	{
2323
+		$event_ids = $this->cleanEventIds($event_ids);
2324
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2325
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2326
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2327
+			[
2328
+				'action'            => 'preview_deletion',
2329
+				'deletion_job_code' => $deletion_job_code,
2330
+			],
2331
+			$this->_admin_base_url
2332
+		);
2333
+		EEH_URL::safeRedirectAndExit(
2334
+			EE_Admin_Page::add_query_args_and_nonce(
2335
+				[
2336
+					'page'              => EED_Batch::PAGE_SLUG,
2337
+					'batch'             => EED_Batch::batch_job,
2338
+					'EVT_IDs'           => $event_ids,
2339
+					'deletion_job_code' => $deletion_job_code,
2340
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2341
+					'return_url'        => urlencode($return_url),
2342
+				],
2343
+				admin_url()
2344
+			)
2345
+		);
2346
+	}
2347
+
2348
+
2349
+	/**
2350
+	 * Checks for a POST submission
2351
+	 *
2352
+	 * @since 4.10.12.p
2353
+	 */
2354
+	protected function confirmDeletion()
2355
+	{
2356
+		$deletion_redirect_logic =
2357
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2358
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2359
+	}
2360
+
2361
+
2362
+	/**
2363
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2364
+	 *
2365
+	 * @throws EE_Error
2366
+	 * @since 4.10.12.p
2367
+	 */
2368
+	protected function previewDeletion()
2369
+	{
2370
+		$preview_deletion_logic =
2371
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2372
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2373
+		$this->display_admin_page_with_no_sidebar();
2374
+	}
2375
+
2376
+
2377
+	/**
2378
+	 * get total number of events
2379
+	 *
2380
+	 * @access public
2381
+	 * @return int
2382
+	 * @throws EE_Error
2383
+	 * @throws EE_Error
2384
+	 */
2385
+	public function total_events()
2386
+	{
2387
+		return EEM_Event::instance()->count(
2388
+			['caps' => 'read_admin'],
2389
+			'EVT_ID',
2390
+			true
2391
+		);
2392
+	}
2393
+
2394
+
2395
+	/**
2396
+	 * get total number of draft events
2397
+	 *
2398
+	 * @access public
2399
+	 * @return int
2400
+	 * @throws EE_Error
2401
+	 * @throws EE_Error
2402
+	 */
2403
+	public function total_events_draft()
2404
+	{
2405
+		return EEM_Event::instance()->count(
2406
+			[
2407
+				['status' => ['IN', ['draft', 'auto-draft']]],
2408
+				'caps' => 'read_admin',
2409
+			],
2410
+			'EVT_ID',
2411
+			true
2412
+		);
2413
+	}
2414
+
2415
+
2416
+	/**
2417
+	 * get total number of trashed events
2418
+	 *
2419
+	 * @access public
2420
+	 * @return int
2421
+	 * @throws EE_Error
2422
+	 * @throws EE_Error
2423
+	 */
2424
+	public function total_trashed_events()
2425
+	{
2426
+		return EEM_Event::instance()->count(
2427
+			[
2428
+				['status' => 'trash'],
2429
+				'caps' => 'read_admin',
2430
+			],
2431
+			'EVT_ID',
2432
+			true
2433
+		);
2434
+	}
2435
+
2436
+
2437
+	/**
2438
+	 *    _default_event_settings
2439
+	 *    This generates the Default Settings Tab
2440
+	 *
2441
+	 * @return void
2442
+	 * @throws DomainException
2443
+	 * @throws EE_Error
2444
+	 * @throws InvalidArgumentException
2445
+	 * @throws InvalidDataTypeException
2446
+	 * @throws InvalidInterfaceException
2447
+	 */
2448
+	protected function _default_event_settings()
2449
+	{
2450
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2451
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2452
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
2453
+			$this->_default_event_settings_form()->get_html(),
2454
+			'',
2455
+			'padding'
2456
+		);
2457
+		$this->display_admin_page_with_sidebar();
2458
+	}
2459
+
2460
+
2461
+	/**
2462
+	 * Return the form for event settings.
2463
+	 *
2464
+	 * @return EE_Form_Section_Proper
2465
+	 * @throws EE_Error
2466
+	 */
2467
+	protected function _default_event_settings_form()
2468
+	{
2469
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2470
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2471
+		// exclude
2472
+			[
2473
+				EEM_Registration::status_id_cancelled,
2474
+				EEM_Registration::status_id_declined,
2475
+				EEM_Registration::status_id_incomplete,
2476
+				EEM_Registration::status_id_wait_list,
2477
+			],
2478
+			true
2479
+		);
2480
+		// setup Advanced Editor ???
2481
+		if (
2482
+			$this->raw_req_action === 'default_event_settings'
2483
+			|| $this->raw_req_action === 'update_default_event_settings'
2484
+		) {
2485
+			$this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2486
+		}
2487
+		return new EE_Form_Section_Proper(
2488
+			[
2489
+				'name'            => 'update_default_event_settings',
2490
+				'html_id'         => 'update_default_event_settings',
2491
+				'html_class'      => 'form-table',
2492
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2493
+				'subsections'     => apply_filters(
2494
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2495
+					[
2496
+						'defaults_section_header' => new EE_Form_Section_HTML(
2497
+							EEH_HTML::h2(
2498
+								esc_html__('Default Settings', 'event_espresso'),
2499
+								'',
2500
+								'ee-admin-settings-hdr'
2501
+							)
2502
+						),
2503
+						'default_reg_status'  => new EE_Select_Input(
2504
+							$registration_stati_for_selection,
2505
+							[
2506
+								'default'         => isset($registration_config->default_STS_ID)
2507
+													 && array_key_exists(
2508
+														 $registration_config->default_STS_ID,
2509
+														 $registration_stati_for_selection
2510
+													 )
2511
+									? sanitize_text_field($registration_config->default_STS_ID)
2512
+									: EEM_Registration::status_id_pending_payment,
2513
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2514
+													 . EEH_Template::get_help_tab_link(
2515
+														 'default_settings_status_help_tab'
2516
+													 ),
2517
+								'html_help_text'  => esc_html__(
2518
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2519
+									'event_espresso'
2520
+								),
2521
+							]
2522
+						),
2523
+						'default_max_tickets' => new EE_Integer_Input(
2524
+							[
2525
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2526
+									? $registration_config->default_maximum_number_of_tickets
2527
+									: EEM_Event::get_default_additional_limit(),
2528
+								'html_label_text' => esc_html__(
2529
+									'Default Maximum Tickets Allowed Per Order:',
2530
+									'event_espresso'
2531
+								)
2532
+													 . EEH_Template::get_help_tab_link(
2533
+														 'default_maximum_tickets_help_tab"'
2534
+													 ),
2535
+								'html_help_text'  => esc_html__(
2536
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2537
+									'event_espresso'
2538
+								),
2539
+							]
2540
+						),
2541
+					]
2542
+				),
2543
+			]
2544
+		);
2545
+	}
2546
+
2547
+
2548
+	/**
2549
+	 * @return void
2550
+	 * @throws EE_Error
2551
+	 * @throws InvalidArgumentException
2552
+	 * @throws InvalidDataTypeException
2553
+	 * @throws InvalidInterfaceException
2554
+	 */
2555
+	protected function _update_default_event_settings()
2556
+	{
2557
+		$form = $this->_default_event_settings_form();
2558
+		if ($form->was_submitted()) {
2559
+			$form->receive_form_submission();
2560
+			if ($form->is_valid()) {
2561
+				$registration_config = EE_Registry::instance()->CFG->registration;
2562
+				$valid_data          = $form->valid_data();
2563
+				if (isset($valid_data['default_reg_status'])) {
2564
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2565
+				}
2566
+				if (isset($valid_data['default_max_tickets'])) {
2567
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2568
+				}
2569
+				do_action(
2570
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2571
+					$valid_data,
2572
+					EE_Registry::instance()->CFG,
2573
+					$this
2574
+				);
2575
+				// update because data was valid!
2576
+				EE_Registry::instance()->CFG->update_espresso_config();
2577
+				EE_Error::overwrite_success();
2578
+				EE_Error::add_success(
2579
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2580
+				);
2581
+			}
2582
+		}
2583
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2584
+	}
2585
+
2586
+
2587
+	/*************        Templates        *************
21 2588
      *
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-    /**
55
-     * @var AdvancedEditorAdminFormSection
56
-     */
57
-    protected $advanced_editor_admin_form;
58
-
59
-
60
-    /**
61
-     * Initialize page props for this admin page group.
62
-     */
63
-    protected function _init_page_props()
64
-    {
65
-        $this->page_slug        = EVENTS_PG_SLUG;
66
-        $this->page_label       = EVENTS_LABEL;
67
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
68
-        $this->_admin_base_path = EVENTS_ADMIN;
69
-        $this->_cpt_model_names = [
70
-            'create_new' => 'EEM_Event',
71
-            'edit'       => 'EEM_Event',
72
-        ];
73
-        $this->_cpt_edit_routes = [
74
-            'espresso_events' => 'edit',
75
-        ];
76
-        add_action(
77
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
78
-            [$this, 'verify_event_edit'],
79
-            10,
80
-            2
81
-        );
82
-    }
83
-
84
-
85
-    /**
86
-     * Sets the ajax hooks used for this admin page group.
87
-     */
88
-    protected function _ajax_hooks()
89
-    {
90
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
91
-    }
92
-
93
-
94
-    /**
95
-     * Sets the page properties for this admin page group.
96
-     */
97
-    protected function _define_page_props()
98
-    {
99
-        $this->_admin_page_title = EVENTS_LABEL;
100
-        $this->_labels           = [
101
-            'buttons'      => [
102
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
103
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
104
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
105
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
106
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
107
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
108
-            ],
109
-            'editor_title' => [
110
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
111
-            ],
112
-            'publishbox'   => [
113
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
114
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
115
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
116
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
117
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
118
-            ],
119
-        ];
120
-    }
121
-
122
-
123
-    /**
124
-     * Sets the page routes property for this admin page group.
125
-     */
126
-    protected function _set_page_routes()
127
-    {
128
-        // load formatter helper
129
-        // load field generator helper
130
-        // is there a evt_id in the request?
131
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
132
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
133
-
134
-        $this->_page_routes = [
135
-            'default'                       => [
136
-                'func'       => '_events_overview_list_table',
137
-                'capability' => 'ee_read_events',
138
-            ],
139
-            'create_new'                    => [
140
-                'func'       => '_create_new_cpt_item',
141
-                'capability' => 'ee_edit_events',
142
-            ],
143
-            'edit'                          => [
144
-                'func'       => '_edit_cpt_item',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-            ],
148
-            'copy_event'                    => [
149
-                'func'       => '_copy_events',
150
-                'capability' => 'ee_edit_event',
151
-                'obj_id'     => $EVT_ID,
152
-                'noheader'   => true,
153
-            ],
154
-            'trash_event'                   => [
155
-                'func'       => '_trash_or_restore_event',
156
-                'args'       => ['event_status' => 'trash'],
157
-                'capability' => 'ee_delete_event',
158
-                'obj_id'     => $EVT_ID,
159
-                'noheader'   => true,
160
-            ],
161
-            'trash_events'                  => [
162
-                'func'       => '_trash_or_restore_events',
163
-                'args'       => ['event_status' => 'trash'],
164
-                'capability' => 'ee_delete_events',
165
-                'noheader'   => true,
166
-            ],
167
-            'restore_event'                 => [
168
-                'func'       => '_trash_or_restore_event',
169
-                'args'       => ['event_status' => 'draft'],
170
-                'capability' => 'ee_delete_event',
171
-                'obj_id'     => $EVT_ID,
172
-                'noheader'   => true,
173
-            ],
174
-            'restore_events'                => [
175
-                'func'       => '_trash_or_restore_events',
176
-                'args'       => ['event_status' => 'draft'],
177
-                'capability' => 'ee_delete_events',
178
-                'noheader'   => true,
179
-            ],
180
-            'delete_event'                  => [
181
-                'func'       => '_delete_event',
182
-                'capability' => 'ee_delete_event',
183
-                'obj_id'     => $EVT_ID,
184
-                'noheader'   => true,
185
-            ],
186
-            'delete_events'                 => [
187
-                'func'       => '_delete_events',
188
-                'capability' => 'ee_delete_events',
189
-                'noheader'   => true,
190
-            ],
191
-            'view_report'                   => [
192
-                'func'       => '_view_report',
193
-                'capability' => 'ee_edit_events',
194
-            ],
195
-            'default_event_settings'        => [
196
-                'func'       => '_default_event_settings',
197
-                'capability' => 'manage_options',
198
-            ],
199
-            'update_default_event_settings' => [
200
-                'func'       => '_update_default_event_settings',
201
-                'capability' => 'manage_options',
202
-                'noheader'   => true,
203
-            ],
204
-            'template_settings'             => [
205
-                'func'       => '_template_settings',
206
-                'capability' => 'manage_options',
207
-            ],
208
-            // event category tab related
209
-            'add_category'                  => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['add'],
213
-            ],
214
-            'edit_category'                 => [
215
-                'func'       => '_category_details',
216
-                'capability' => 'ee_edit_event_category',
217
-                'args'       => ['edit'],
218
-            ],
219
-            'delete_categories'             => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'delete_category'               => [
225
-                'func'       => '_delete_categories',
226
-                'capability' => 'ee_delete_event_category',
227
-                'noheader'   => true,
228
-            ],
229
-            'insert_category'               => [
230
-                'func'       => '_insert_or_update_category',
231
-                'args'       => ['new_category' => true],
232
-                'capability' => 'ee_edit_event_category',
233
-                'noheader'   => true,
234
-            ],
235
-            'update_category'               => [
236
-                'func'       => '_insert_or_update_category',
237
-                'args'       => ['new_category' => false],
238
-                'capability' => 'ee_edit_event_category',
239
-                'noheader'   => true,
240
-            ],
241
-            'category_list'                 => [
242
-                'func'       => '_category_list_table',
243
-                'capability' => 'ee_manage_event_categories',
244
-            ],
245
-            'preview_deletion'              => [
246
-                'func'       => 'previewDeletion',
247
-                'capability' => 'ee_delete_events',
248
-            ],
249
-            'confirm_deletion'              => [
250
-                'func'       => 'confirmDeletion',
251
-                'capability' => 'ee_delete_events',
252
-                'noheader'   => true,
253
-            ],
254
-        ];
255
-    }
256
-
257
-
258
-    /**
259
-     * Set the _page_config property for this admin page group.
260
-     */
261
-    protected function _set_page_config()
262
-    {
263
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
264
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
265
-        $this->_page_config = [
266
-            'default'                => [
267
-                'nav'           => [
268
-                    'label' => esc_html__('Overview', 'event_espresso'),
269
-                    'order' => 10,
270
-                ],
271
-                'list_table'    => 'Events_Admin_List_Table',
272
-                'help_tabs'     => [
273
-                    'events_overview_help_tab'                       => [
274
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
275
-                        'filename' => 'events_overview',
276
-                    ],
277
-                    'events_overview_table_column_headings_help_tab' => [
278
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
279
-                        'filename' => 'events_overview_table_column_headings',
280
-                    ],
281
-                    'events_overview_filters_help_tab'               => [
282
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
283
-                        'filename' => 'events_overview_filters',
284
-                    ],
285
-                    'events_overview_view_help_tab'                  => [
286
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
287
-                        'filename' => 'events_overview_views',
288
-                    ],
289
-                    'events_overview_other_help_tab'                 => [
290
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
291
-                        'filename' => 'events_overview_other',
292
-                    ],
293
-                ],
294
-                'require_nonce' => false,
295
-            ],
296
-            'create_new'             => [
297
-                'nav'           => [
298
-                    'label'      => esc_html__('Add New Event', 'event_espresso'),
299
-                    'order'      => 5,
300
-                    'persistent' => false,
301
-                ],
302
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
303
-                'help_tabs'     => [
304
-                    'event_editor_help_tab'                            => [
305
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
306
-                        'filename' => 'event_editor',
307
-                    ],
308
-                    'event_editor_title_richtexteditor_help_tab'       => [
309
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
310
-                        'filename' => 'event_editor_title_richtexteditor',
311
-                    ],
312
-                    'event_editor_venue_details_help_tab'              => [
313
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
314
-                        'filename' => 'event_editor_venue_details',
315
-                    ],
316
-                    'event_editor_event_datetimes_help_tab'            => [
317
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
318
-                        'filename' => 'event_editor_event_datetimes',
319
-                    ],
320
-                    'event_editor_event_tickets_help_tab'              => [
321
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
322
-                        'filename' => 'event_editor_event_tickets',
323
-                    ],
324
-                    'event_editor_event_registration_options_help_tab' => [
325
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
326
-                        'filename' => 'event_editor_event_registration_options',
327
-                    ],
328
-                    'event_editor_tags_categories_help_tab'            => [
329
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
330
-                        'filename' => 'event_editor_tags_categories',
331
-                    ],
332
-                    'event_editor_questions_registrants_help_tab'      => [
333
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
334
-                        'filename' => 'event_editor_questions_registrants',
335
-                    ],
336
-                    'event_editor_save_new_event_help_tab'             => [
337
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
338
-                        'filename' => 'event_editor_save_new_event',
339
-                    ],
340
-                    'event_editor_other_help_tab'                      => [
341
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
342
-                        'filename' => 'event_editor_other',
343
-                    ],
344
-                ],
345
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
346
-                'require_nonce' => false,
347
-            ],
348
-            'edit'                   => [
349
-                'nav'           => [
350
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
351
-                    'order'      => 5,
352
-                    'persistent' => false,
353
-                    'url'        => $post_id
354
-                        ? EE_Admin_Page::add_query_args_and_nonce(
355
-                            ['post' => $post_id, 'action' => 'edit'],
356
-                            $this->_current_page_view_url
357
-                        )
358
-                        : $this->_admin_base_url,
359
-                ],
360
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
361
-                'help_tabs'     => [
362
-                    'event_editor_help_tab'                            => [
363
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
364
-                        'filename' => 'event_editor',
365
-                    ],
366
-                    'event_editor_title_richtexteditor_help_tab'       => [
367
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
368
-                        'filename' => 'event_editor_title_richtexteditor',
369
-                    ],
370
-                    'event_editor_venue_details_help_tab'              => [
371
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
372
-                        'filename' => 'event_editor_venue_details',
373
-                    ],
374
-                    'event_editor_event_datetimes_help_tab'            => [
375
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
376
-                        'filename' => 'event_editor_event_datetimes',
377
-                    ],
378
-                    'event_editor_event_tickets_help_tab'              => [
379
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
380
-                        'filename' => 'event_editor_event_tickets',
381
-                    ],
382
-                    'event_editor_event_registration_options_help_tab' => [
383
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
384
-                        'filename' => 'event_editor_event_registration_options',
385
-                    ],
386
-                    'event_editor_tags_categories_help_tab'            => [
387
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
388
-                        'filename' => 'event_editor_tags_categories',
389
-                    ],
390
-                    'event_editor_questions_registrants_help_tab'      => [
391
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
392
-                        'filename' => 'event_editor_questions_registrants',
393
-                    ],
394
-                    'event_editor_save_new_event_help_tab'             => [
395
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
396
-                        'filename' => 'event_editor_save_new_event',
397
-                    ],
398
-                    'event_editor_other_help_tab'                      => [
399
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
400
-                        'filename' => 'event_editor_other',
401
-                    ],
402
-                ],
403
-                'require_nonce' => false,
404
-            ],
405
-            'default_event_settings' => [
406
-                'nav'           => [
407
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
408
-                    'order' => 40,
409
-                ],
410
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
411
-                'labels'        => [
412
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
413
-                ],
414
-                'help_tabs'     => [
415
-                    'default_settings_help_tab'        => [
416
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
417
-                        'filename' => 'events_default_settings',
418
-                    ],
419
-                    'default_settings_status_help_tab' => [
420
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
421
-                        'filename' => 'events_default_settings_status',
422
-                    ],
423
-                    'default_maximum_tickets_help_tab' => [
424
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
425
-                        'filename' => 'events_default_settings_max_tickets',
426
-                    ],
427
-                ],
428
-                'require_nonce' => false,
429
-            ],
430
-            // template settings
431
-            'template_settings'      => [
432
-                'nav'           => [
433
-                    'label' => esc_html__('Templates', 'event_espresso'),
434
-                    'order' => 30,
435
-                ],
436
-                'metaboxes'     => $this->_default_espresso_metaboxes,
437
-                'help_tabs'     => [
438
-                    'general_settings_templates_help_tab' => [
439
-                        'title'    => esc_html__('Templates', 'event_espresso'),
440
-                        'filename' => 'general_settings_templates',
441
-                    ],
442
-                ],
443
-                'require_nonce' => false,
444
-            ],
445
-            // event category stuff
446
-            'add_category'           => [
447
-                'nav'           => [
448
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
449
-                    'order'      => 15,
450
-                    'persistent' => false,
451
-                ],
452
-                'help_tabs'     => [
453
-                    'add_category_help_tab' => [
454
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
455
-                        'filename' => 'events_add_category',
456
-                    ],
457
-                ],
458
-                'metaboxes'     => ['_publish_post_box'],
459
-                'require_nonce' => false,
460
-            ],
461
-            'edit_category'          => [
462
-                'nav'           => [
463
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
464
-                    'order'      => 15,
465
-                    'persistent' => false,
466
-                    'url'        => $EVT_CAT_ID
467
-                        ? add_query_arg(
468
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
469
-                            $this->_current_page_view_url
470
-                        )
471
-                        : $this->_admin_base_url,
472
-                ],
473
-                'help_tabs'     => [
474
-                    'edit_category_help_tab' => [
475
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
476
-                        'filename' => 'events_edit_category',
477
-                    ],
478
-                ],
479
-                'metaboxes'     => ['_publish_post_box'],
480
-                'require_nonce' => false,
481
-            ],
482
-            'category_list'          => [
483
-                'nav'           => [
484
-                    'label' => esc_html__('Categories', 'event_espresso'),
485
-                    'order' => 20,
486
-                ],
487
-                'list_table'    => 'Event_Categories_Admin_List_Table',
488
-                'help_tabs'     => [
489
-                    'events_categories_help_tab'                       => [
490
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
491
-                        'filename' => 'events_categories',
492
-                    ],
493
-                    'events_categories_table_column_headings_help_tab' => [
494
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
495
-                        'filename' => 'events_categories_table_column_headings',
496
-                    ],
497
-                    'events_categories_view_help_tab'                  => [
498
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
499
-                        'filename' => 'events_categories_views',
500
-                    ],
501
-                    'events_categories_other_help_tab'                 => [
502
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
503
-                        'filename' => 'events_categories_other',
504
-                    ],
505
-                ],
506
-                'metaboxes'     => $this->_default_espresso_metaboxes,
507
-                'require_nonce' => false,
508
-            ],
509
-            'preview_deletion'       => [
510
-                'nav'           => [
511
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
512
-                    'order'      => 15,
513
-                    'persistent' => false,
514
-                    'url'        => '',
515
-                ],
516
-                'require_nonce' => false,
517
-            ],
518
-        ];
519
-    }
520
-
521
-
522
-    /**
523
-     * Used to register any global screen options if necessary for every route in this admin page group.
524
-     */
525
-    protected function _add_screen_options()
526
-    {
527
-    }
528
-
529
-
530
-    /**
531
-     * Implementing the screen options for the 'default' route.
532
-     *
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     */
537
-    protected function _add_screen_options_default()
538
-    {
539
-        $this->_per_page_screen_option();
540
-    }
541
-
542
-
543
-    /**
544
-     * Implementing screen options for the category list route.
545
-     *
546
-     * @throws InvalidArgumentException
547
-     * @throws InvalidDataTypeException
548
-     * @throws InvalidInterfaceException
549
-     */
550
-    protected function _add_screen_options_category_list()
551
-    {
552
-        $page_title              = $this->_admin_page_title;
553
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
554
-        $this->_per_page_screen_option();
555
-        $this->_admin_page_title = $page_title;
556
-    }
557
-
558
-
559
-    /**
560
-     * Used to register any global feature pointers for the admin page group.
561
-     */
562
-    protected function _add_feature_pointers()
563
-    {
564
-    }
565
-
566
-
567
-    /**
568
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
569
-     */
570
-    public function load_scripts_styles()
571
-    {
572
-        wp_register_style(
573
-            'events-admin-css',
574
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
575
-            [],
576
-            EVENT_ESPRESSO_VERSION
577
-        );
578
-        wp_register_style(
579
-            'ee-cat-admin',
580
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
581
-            [],
582
-            EVENT_ESPRESSO_VERSION
583
-        );
584
-        wp_enqueue_style('events-admin-css');
585
-        wp_enqueue_style('ee-cat-admin');
586
-        // scripts
587
-        wp_register_script(
588
-            'event_editor_js',
589
-            EVENTS_ASSETS_URL . 'event_editor.js',
590
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
591
-            EVENT_ESPRESSO_VERSION,
592
-            true
593
-        );
594
-    }
595
-
596
-
597
-    /**
598
-     * Enqueuing scripts and styles specific to this view
599
-     */
600
-    public function load_scripts_styles_create_new()
601
-    {
602
-        $this->load_scripts_styles_edit();
603
-    }
604
-
605
-
606
-    /**
607
-     * Enqueuing scripts and styles specific to this view
608
-     */
609
-    public function load_scripts_styles_edit()
610
-    {
611
-        // styles
612
-        wp_enqueue_style('espresso-ui-theme');
613
-        wp_register_style(
614
-            'event-editor-css',
615
-            EVENTS_ASSETS_URL . 'event-editor.css',
616
-            ['ee-admin-css'],
617
-            EVENT_ESPRESSO_VERSION
618
-        );
619
-        wp_enqueue_style('event-editor-css');
620
-        // scripts
621
-        if (! $this->admin_config->useAdvancedEditor()) {
622
-            wp_register_script(
623
-                'event-datetime-metabox',
624
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
625
-                ['event_editor_js', 'ee-datepicker'],
626
-                EVENT_ESPRESSO_VERSION
627
-            );
628
-            wp_enqueue_script('event-datetime-metabox');
629
-        }
630
-    }
631
-
632
-
633
-    /**
634
-     * Populating the _views property for the category list table view.
635
-     */
636
-    protected function _set_list_table_views_category_list()
637
-    {
638
-        $this->_views = [
639
-            'all' => [
640
-                'slug'        => 'all',
641
-                'label'       => esc_html__('All', 'event_espresso'),
642
-                'count'       => 0,
643
-                'bulk_action' => [
644
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
645
-                ],
646
-            ],
647
-        ];
648
-    }
649
-
650
-
651
-    /**
652
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
653
-     */
654
-    public function admin_init()
655
-    {
656
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
657
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
658
-            'event_espresso'
659
-        );
660
-    }
661
-
662
-
663
-    /**
664
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
665
-     * group.
666
-     */
667
-    public function admin_notices()
668
-    {
669
-    }
670
-
671
-
672
-    /**
673
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
674
-     * this admin page group.
675
-     */
676
-    public function admin_footer_scripts()
677
-    {
678
-    }
679
-
680
-
681
-    /**
682
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
683
-     * warning (via EE_Error::add_error());
684
-     *
685
-     * @param EE_Event $event Event object
686
-     * @param string   $req_type
687
-     * @return void
688
-     * @throws EE_Error
689
-     * @throws ReflectionException
690
-     */
691
-    public function verify_event_edit($event = null, $req_type = '')
692
-    {
693
-        // don't need to do this when processing
694
-        if (! empty($req_type)) {
695
-            return;
696
-        }
697
-        // no event?
698
-        if (! $event instanceof EE_Event) {
699
-            $event = $this->_cpt_model_obj;
700
-        }
701
-        // STILL no event?
702
-        if (! $event instanceof EE_Event) {
703
-            return;
704
-        }
705
-        $orig_status = $event->status();
706
-        // first check if event is active.
707
-        if (
708
-            $orig_status === EEM_Event::cancelled
709
-            || $orig_status === EEM_Event::postponed
710
-            || $event->is_expired()
711
-            || $event->is_inactive()
712
-        ) {
713
-            return;
714
-        }
715
-        // made it here so it IS active... next check that any of the tickets are sold.
716
-        if ($event->is_sold_out(true)) {
717
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
718
-                EE_Error::add_attention(
719
-                    sprintf(
720
-                        esc_html__(
721
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
722
-                            'event_espresso'
723
-                        ),
724
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
725
-                    )
726
-                );
727
-            }
728
-            return;
729
-        }
730
-        if ($orig_status === EEM_Event::sold_out) {
731
-            EE_Error::add_attention(
732
-                sprintf(
733
-                    esc_html__(
734
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
735
-                        'event_espresso'
736
-                    ),
737
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
738
-                )
739
-            );
740
-        }
741
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
742
-        if (! $event->tickets_on_sale()) {
743
-            return;
744
-        }
745
-        // made it here so show warning
746
-        $this->_edit_event_warning();
747
-    }
748
-
749
-
750
-    /**
751
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
752
-     * When needed, hook this into a EE_Error::add_error() notice.
753
-     *
754
-     * @access protected
755
-     * @return void
756
-     */
757
-    protected function _edit_event_warning()
758
-    {
759
-        // we don't want to add warnings during these requests
760
-        if ($this->request->getRequestParam('action') === 'editpost') {
761
-            return;
762
-        }
763
-        EE_Error::add_attention(
764
-            sprintf(
765
-                esc_html__(
766
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
767
-                    'event_espresso'
768
-                ),
769
-                '<a class="espresso-help-tab-lnk ee-help-tab-link">',
770
-                '</a>'
771
-            )
772
-        );
773
-    }
774
-
775
-
776
-    /**
777
-     * When a user is creating a new event, notify them if they haven't set their timezone.
778
-     * Otherwise, do the normal logic
779
-     *
780
-     * @return void
781
-     * @throws EE_Error
782
-     * @throws InvalidArgumentException
783
-     * @throws InvalidDataTypeException
784
-     * @throws InvalidInterfaceException
785
-     */
786
-    protected function _create_new_cpt_item()
787
-    {
788
-        $has_timezone_string = get_option('timezone_string');
789
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
790
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
791
-            EE_Error::add_attention(
792
-                sprintf(
793
-                    esc_html__(
794
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
795
-                        'event_espresso'
796
-                    ),
797
-                    '<br>',
798
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
799
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
800
-                    . '</select>',
801
-                    '<button class="button button--secondary timezone-submit">',
802
-                    '</button><span class="spinner"></span>'
803
-                ),
804
-                __FILE__,
805
-                __FUNCTION__,
806
-                __LINE__
807
-            );
808
-        }
809
-        parent::_create_new_cpt_item();
810
-    }
811
-
812
-
813
-    /**
814
-     * Sets the _views property for the default route in this admin page group.
815
-     */
816
-    protected function _set_list_table_views_default()
817
-    {
818
-        $this->_views = [
819
-            'all'   => [
820
-                'slug'        => 'all',
821
-                'label'       => esc_html__('View All Events', 'event_espresso'),
822
-                'count'       => 0,
823
-                'bulk_action' => [
824
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
825
-                ],
826
-            ],
827
-            'draft' => [
828
-                'slug'        => 'draft',
829
-                'label'       => esc_html__('Draft', 'event_espresso'),
830
-                'count'       => 0,
831
-                'bulk_action' => [
832
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
833
-                ],
834
-            ],
835
-        ];
836
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
837
-            $this->_views['trash'] = [
838
-                'slug'        => 'trash',
839
-                'label'       => esc_html__('Trash', 'event_espresso'),
840
-                'count'       => 0,
841
-                'bulk_action' => [
842
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
843
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
844
-                ],
845
-            ];
846
-        }
847
-    }
848
-
849
-
850
-    /**
851
-     * Provides the legend item array for the default list table view.
852
-     *
853
-     * @return array
854
-     * @throws EE_Error
855
-     * @throws EE_Error
856
-     */
857
-    protected function _event_legend_items()
858
-    {
859
-        $items    = [
860
-            'view_details'   => [
861
-                'class' => 'dashicons dashicons-visibility',
862
-                'desc'  => esc_html__('View Event', 'event_espresso'),
863
-            ],
864
-            'edit_event'     => [
865
-                'class' => 'dashicons dashicons-calendar-alt',
866
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
867
-            ],
868
-            'view_attendees' => [
869
-                'class' => 'dashicons dashicons-groups',
870
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
871
-            ],
872
-        ];
873
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
874
-        $statuses = [
875
-            'sold_out_status'  => [
876
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
877
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
878
-            ],
879
-            'active_status'    => [
880
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
881
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
882
-            ],
883
-            'upcoming_status'  => [
884
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
885
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
886
-            ],
887
-            'postponed_status' => [
888
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
889
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
890
-            ],
891
-            'cancelled_status' => [
892
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
893
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
894
-            ],
895
-            'expired_status'   => [
896
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
897
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
898
-            ],
899
-            'inactive_status'  => [
900
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
901
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
902
-            ],
903
-        ];
904
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
905
-        return array_merge($items, $statuses);
906
-    }
907
-
908
-
909
-    /**
910
-     * @return EEM_Event
911
-     * @throws EE_Error
912
-     * @throws InvalidArgumentException
913
-     * @throws InvalidDataTypeException
914
-     * @throws InvalidInterfaceException
915
-     * @throws ReflectionException
916
-     */
917
-    private function _event_model()
918
-    {
919
-        if (! $this->_event_model instanceof EEM_Event) {
920
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
921
-        }
922
-        return $this->_event_model;
923
-    }
924
-
925
-
926
-    /**
927
-     * Adds extra buttons to the WP CPT permalink field row.
928
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
929
-     *
930
-     * @param string $return    the current html
931
-     * @param int    $id        the post id for the page
932
-     * @param string $new_title What the title is
933
-     * @param string $new_slug  what the slug is
934
-     * @return string            The new html string for the permalink area
935
-     */
936
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
937
-    {
938
-        // make sure this is only when editing
939
-        if (! empty($id)) {
940
-            $post = get_post($id);
941
-            $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
942
-                       . esc_html__('Shortcode', 'event_espresso')
943
-                       . '</a> ';
944
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
945
-                       . $post->ID
946
-                       . ']">';
947
-        }
948
-        return $return;
949
-    }
950
-
951
-
952
-    /**
953
-     * _events_overview_list_table
954
-     * This contains the logic for showing the events_overview list
955
-     *
956
-     * @access protected
957
-     * @return void
958
-     * @throws DomainException
959
-     * @throws EE_Error
960
-     * @throws InvalidArgumentException
961
-     * @throws InvalidDataTypeException
962
-     * @throws InvalidInterfaceException
963
-     */
964
-    protected function _events_overview_list_table()
965
-    {
966
-        $after_list_table                           = [];
967
-        $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
968
-        $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
969
-        $links_html .= EEH_HTML::div(
970
-            EEH_Template::get_button_or_link(
971
-                get_post_type_archive_link('espresso_events'),
972
-                esc_html__('View Event Archive Page', 'event_espresso'),
973
-                'button button--small button--secondary'
974
-            ),
975
-            '',
976
-            'ee-admin-button-row ee-admin-button-row--align-start'
977
-        );
978
-        $links_html .= EEH_HTML::divx();
979
-
980
-        $after_list_table['view_event_list_button'] = $links_html;
981
-
982
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
983
-        $this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
984
-            'create_new',
985
-            'add',
986
-            [],
987
-            'add-new-h2'
988
-        );
989
-
990
-        $this->_template_args['after_list_table']   = array_merge(
991
-            (array) $this->_template_args['after_list_table'],
992
-            $after_list_table
993
-        );
994
-        $this->display_admin_list_table_page_with_no_sidebar();
995
-    }
996
-
997
-
998
-    /**
999
-     * this allows for extra misc actions in the default WP publish box
1000
-     *
1001
-     * @return void
1002
-     * @throws DomainException
1003
-     * @throws EE_Error
1004
-     * @throws InvalidArgumentException
1005
-     * @throws InvalidDataTypeException
1006
-     * @throws InvalidInterfaceException
1007
-     * @throws ReflectionException
1008
-     */
1009
-    public function extra_misc_actions_publish_box()
1010
-    {
1011
-        $this->_generate_publish_box_extra_content();
1012
-    }
1013
-
1014
-
1015
-    /**
1016
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1017
-     * saved.
1018
-     * Typically you would use this to save any additional data.
1019
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1020
-     * ALSO very important.  When a post transitions from scheduled to published,
1021
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1022
-     * other meta saves. So MAKE sure that you handle this accordingly.
1023
-     *
1024
-     * @access protected
1025
-     * @abstract
1026
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1027
-     * @param WP_Post $post    The post object of the cpt that was saved.
1028
-     * @return void
1029
-     * @throws EE_Error
1030
-     * @throws InvalidArgumentException
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidInterfaceException
1033
-     * @throws ReflectionException
1034
-     */
1035
-    protected function _insert_update_cpt_item($post_id, $post)
1036
-    {
1037
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1038
-            // get out we're not processing an event save.
1039
-            return;
1040
-        }
1041
-        $event_values = [
1042
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1043
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1044
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1045
-        ];
1046
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1047
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1048
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1049
-                'display_ticket_selector',
1050
-                false,
1051
-                'bool'
1052
-            );
1053
-            $event_values['EVT_additional_limit']            = min(
1054
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1055
-                $this->request->getRequestParam('additional_limit', null, 'int')
1056
-            );
1057
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1058
-                'EVT_default_registration_status',
1059
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1060
-            );
1061
-
1062
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1063
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1064
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1065
-        }
1066
-        // update event
1067
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1068
-        // get event_object for other metaboxes...
1069
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1070
-        // i have to setup where conditions to override the filters in the model
1071
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1072
-        $event = $this->_event_model()->get_one(
1073
-            [
1074
-                [
1075
-                    $this->_event_model()->primary_key_name() => $post_id,
1076
-                    'OR'                                      => [
1077
-                        'status'   => $post->post_status,
1078
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1079
-                        // but the returned object here has a status of "publish", so use the original post status as well
1080
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1081
-                    ],
1082
-                ],
1083
-            ]
1084
-        );
1085
-
1086
-        // the following are default callbacks for event attachment updates
1087
-        // that can be overridden by caffeinated functionality and/or addons.
1088
-        $event_update_callbacks = [];
1089
-        if (! $this->admin_config->useAdvancedEditor()) {
1090
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1091
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1092
-        }
1093
-        $event_update_callbacks = apply_filters(
1094
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1095
-            $event_update_callbacks
1096
-        );
1097
-
1098
-        $att_success = true;
1099
-        foreach ($event_update_callbacks as $e_callback) {
1100
-            $_success = is_callable($e_callback)
1101
-                ? $e_callback($event, $this->request->requestParams())
1102
-                : false;
1103
-            // if ANY of these updates fail then we want the appropriate global error message
1104
-            $att_success = $_success !== false ? $att_success : false;
1105
-        }
1106
-        // any errors?
1107
-        if ($success && $att_success === false) {
1108
-            EE_Error::add_error(
1109
-                esc_html__(
1110
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1111
-                    'event_espresso'
1112
-                ),
1113
-                __FILE__,
1114
-                __FUNCTION__,
1115
-                __LINE__
1116
-            );
1117
-        } elseif ($success === false) {
1118
-            EE_Error::add_error(
1119
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1120
-                __FILE__,
1121
-                __FUNCTION__,
1122
-                __LINE__
1123
-            );
1124
-        }
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * @param int $post_id
1130
-     * @param int $revision_id
1131
-     * @throws EE_Error
1132
-     * @throws EE_Error
1133
-     * @throws ReflectionException
1134
-     * @see parent::restore_item()
1135
-     */
1136
-    protected function _restore_cpt_item($post_id, $revision_id)
1137
-    {
1138
-        // copy existing event meta to new post
1139
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1140
-        if ($post_evt instanceof EE_Event) {
1141
-            // meta revision restore
1142
-            $post_evt->restore_revision($revision_id);
1143
-            // related objs restore
1144
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1145
-        }
1146
-    }
1147
-
1148
-
1149
-    /**
1150
-     * Attach the venue to the Event
1151
-     *
1152
-     * @param EE_Event $event Event Object to add the venue to
1153
-     * @param array    $data  The request data from the form
1154
-     * @return bool           Success or fail.
1155
-     * @throws EE_Error
1156
-     * @throws ReflectionException
1157
-     */
1158
-    protected function _default_venue_update(EE_Event $event, $data)
1159
-    {
1160
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1161
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1162
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1163
-        // very important.  If we don't have a venue name...
1164
-        // then we'll get out because not necessary to create empty venue
1165
-        if (empty($data['venue_title'])) {
1166
-            return false;
1167
-        }
1168
-        $venue_array = [
1169
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1170
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1171
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1172
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1173
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1174
-                ? $data['venue_short_description']
1175
-                : null,
1176
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1177
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1178
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1179
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1180
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1181
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1182
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1183
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1184
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1185
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1186
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1187
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1188
-            'status'              => 'publish',
1189
-        ];
1190
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1191
-        if (! empty($venue_id)) {
1192
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1193
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1194
-            // we've gotta make sure that the venue is always attached to a revision..
1195
-            // add_relation_to should take care of making sure that the relation is already present.
1196
-            $event->_add_relation_to($venue_id, 'Venue');
1197
-            return $rows_affected > 0;
1198
-        }
1199
-        // we insert the venue
1200
-        $venue_id = $venue_model->insert($venue_array);
1201
-        $event->_add_relation_to($venue_id, 'Venue');
1202
-        return ! empty($venue_id);
1203
-        // when we have the ancestor come in it's already been handled by the revision save.
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1209
-     *
1210
-     * @param EE_Event $event The Event object we're attaching data to
1211
-     * @param array    $data  The request data from the form
1212
-     * @return array
1213
-     * @throws EE_Error
1214
-     * @throws ReflectionException
1215
-     * @throws Exception
1216
-     */
1217
-    protected function _default_tickets_update(EE_Event $event, $data)
1218
-    {
1219
-        if ($this->admin_config->useAdvancedEditor()) {
1220
-            return [];
1221
-        }
1222
-        $datetime       = null;
1223
-        $saved_tickets  = [];
1224
-        $event_timezone = $event->get_timezone();
1225
-        $date_formats   = ['Y-m-d', 'h:i a'];
1226
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1227
-            // trim all values to ensure any excess whitespace is removed.
1228
-            $datetime_data                = array_map('trim', $datetime_data);
1229
-            $datetime_data['DTT_EVT_end'] =
1230
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1231
-                    ? $datetime_data['DTT_EVT_end']
1232
-                    : $datetime_data['DTT_EVT_start'];
1233
-            $datetime_values              = [
1234
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1235
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1236
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1237
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1238
-                'DTT_order'     => $row,
1239
-            ];
1240
-            // if we have an id then let's get existing object first and then set the new values.
1241
-            //  Otherwise we instantiate a new object for save.
1242
-            if (! empty($datetime_data['DTT_ID'])) {
1243
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1244
-                if (! $datetime instanceof EE_Datetime) {
1245
-                    throw new RuntimeException(
1246
-                        sprintf(
1247
-                            esc_html__(
1248
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1249
-                                'event_espresso'
1250
-                            ),
1251
-                            $datetime_data['DTT_ID']
1252
-                        )
1253
-                    );
1254
-                }
1255
-                $datetime->set_date_format($date_formats[0]);
1256
-                $datetime->set_time_format($date_formats[1]);
1257
-                foreach ($datetime_values as $field => $value) {
1258
-                    $datetime->set($field, $value);
1259
-                }
1260
-            } else {
1261
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1262
-            }
1263
-            if (! $datetime instanceof EE_Datetime) {
1264
-                throw new RuntimeException(
1265
-                    sprintf(
1266
-                        esc_html__(
1267
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1268
-                            'event_espresso'
1269
-                        ),
1270
-                        print_r($datetime_values, true)
1271
-                    )
1272
-                );
1273
-            }
1274
-            // before going any further make sure our dates are setup correctly
1275
-            // so that the end date is always equal or greater than the start date.
1276
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1277
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1278
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1279
-            }
1280
-            $datetime->save();
1281
-            $event->_add_relation_to($datetime, 'Datetime');
1282
-        }
1283
-        // no datetimes get deleted so we don't do any of that logic here.
1284
-        // update tickets next
1285
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1286
-
1287
-        // set up some default start and end dates in case those are not present in the incoming data
1288
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1289
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1290
-        // use the start date of the first datetime for the end date
1291
-        $first_datetime   = $event->first_datetime();
1292
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1293
-
1294
-        // now process the incoming data
1295
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1296
-            $update_prices = false;
1297
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1298
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1299
-                : 0;
1300
-            // trim inputs to ensure any excess whitespace is removed.
1301
-            $ticket_data   = array_map('trim', $ticket_data);
1302
-            $ticket_values = [
1303
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1304
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1305
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1306
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1307
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1308
-                    ? $ticket_data['TKT_start_date']
1309
-                    : $default_start_date,
1310
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1311
-                    ? $ticket_data['TKT_end_date']
1312
-                    : $default_end_date,
1313
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1314
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1315
-                    ? $ticket_data['TKT_qty']
1316
-                    : EE_INF,
1317
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1318
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1319
-                    ? $ticket_data['TKT_uses']
1320
-                    : EE_INF,
1321
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1322
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1323
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1324
-                'TKT_price'       => $ticket_price,
1325
-                'TKT_row'         => $row,
1326
-            ];
1327
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1328
-            // which means in turn that the prices will become new prices as well.
1329
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1330
-                $ticket_values['TKT_ID']         = 0;
1331
-                $ticket_values['TKT_is_default'] = 0;
1332
-                $update_prices                   = true;
1333
-            }
1334
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1335
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1336
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1337
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1338
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1339
-            if (! empty($ticket_data['TKT_ID'])) {
1340
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1341
-                if (! $existing_ticket instanceof EE_Ticket) {
1342
-                    throw new RuntimeException(
1343
-                        sprintf(
1344
-                            esc_html__(
1345
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1346
-                                'event_espresso'
1347
-                            ),
1348
-                            $ticket_data['TKT_ID']
1349
-                        )
1350
-                    );
1351
-                }
1352
-                $ticket_sold = $existing_ticket->count_related(
1353
-                    'Registration',
1354
-                    [
1355
-                            [
1356
-                                'STS_ID' => [
1357
-                                    'NOT IN',
1358
-                                    [EEM_Registration::status_id_incomplete],
1359
-                                ],
1360
-                            ],
1361
-                        ]
1362
-                ) > 0;
1363
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1364
-                // if they are different then we create a new ticket (if $ticket_sold)
1365
-                // if they aren't different then we go ahead and modify existing ticket.
1366
-                $create_new_ticket = $ticket_sold
1367
-                                     && $ticket_price !== $existing_ticket->price()
1368
-                                     && ! $existing_ticket->deleted();
1369
-                $existing_ticket->set_date_format($date_formats[0]);
1370
-                $existing_ticket->set_time_format($date_formats[1]);
1371
-                // set new values
1372
-                foreach ($ticket_values as $field => $value) {
1373
-                    if ($field == 'TKT_qty') {
1374
-                        $existing_ticket->set_qty($value);
1375
-                    } elseif ($field == 'TKT_price') {
1376
-                        $existing_ticket->set('TKT_price', $ticket_price);
1377
-                    } else {
1378
-                        $existing_ticket->set($field, $value);
1379
-                    }
1380
-                }
1381
-                $ticket = $existing_ticket;
1382
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1383
-                //  Otherwise we have to create a new ticket.
1384
-                if ($create_new_ticket) {
1385
-                    // archive the old ticket first
1386
-                    $existing_ticket->set('TKT_deleted', 1);
1387
-                    $existing_ticket->save();
1388
-                    // make sure this ticket is still recorded in our $saved_tickets
1389
-                    // so we don't run it through the regular trash routine.
1390
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1391
-                    // create new ticket that's a copy of the existing except,
1392
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1393
-                    $new_ticket = clone $existing_ticket;
1394
-                    $new_ticket->set('TKT_ID', 0);
1395
-                    $new_ticket->set('TKT_deleted', 0);
1396
-                    $new_ticket->set('TKT_sold', 0);
1397
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1398
-                    $update_prices = true;
1399
-                    $ticket        = $new_ticket;
1400
-                }
1401
-            } else {
1402
-                // no TKT_id so a new ticket
1403
-                $ticket_values['TKT_price'] = $ticket_price;
1404
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1405
-                $update_prices              = true;
1406
-            }
1407
-            if (! $ticket instanceof EE_Ticket) {
1408
-                throw new RuntimeException(
1409
-                    sprintf(
1410
-                        esc_html__(
1411
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1412
-                            'event_espresso'
1413
-                        ),
1414
-                        print_r($ticket_values, true)
1415
-                    )
1416
-                );
1417
-            }
1418
-            // cap ticket qty by datetime reg limits
1419
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1420
-            // update ticket.
1421
-            $ticket->save();
1422
-            // before going any further make sure our dates are setup correctly
1423
-            // so that the end date is always equal or greater than the start date.
1424
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1425
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1426
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1427
-                $ticket->save();
1428
-            }
1429
-            // initially let's add the ticket to the datetime
1430
-            $datetime->_add_relation_to($ticket, 'Ticket');
1431
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1432
-            // add prices to ticket
1433
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1434
-                ? $data['edit_prices'][ $row ]
1435
-                : [];
1436
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1437
-        }
1438
-        // however now we need to handle permanently deleting tickets via the ui.
1439
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1440
-        // However, it does allow for deleting tickets that have no tickets sold,
1441
-        // in which case we want to get rid of permanently because there is no need to save in db.
1442
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1443
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1444
-        foreach ($tickets_removed as $id) {
1445
-            $id = absint($id);
1446
-            // get the ticket for this id
1447
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1448
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1449
-                continue;
1450
-            }
1451
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1452
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1453
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1454
-            foreach ($related_datetimes as $related_datetime) {
1455
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1456
-            }
1457
-            // need to do the same for prices (except these prices can also be deleted because again,
1458
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1459
-            $ticket_to_remove->delete_related_permanently('Price');
1460
-            // finally let's delete this ticket
1461
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1462
-            $ticket_to_remove->delete_permanently();
1463
-        }
1464
-        return [$datetime, $saved_tickets];
1465
-    }
1466
-
1467
-
1468
-    /**
1469
-     * This attaches a list of given prices to a ticket.
1470
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1471
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1472
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1473
-     *
1474
-     * @access  private
1475
-     * @param array     $prices_data Array of prices from the form.
1476
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1477
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1478
-     * @return  void
1479
-     * @throws EE_Error
1480
-     * @throws ReflectionException
1481
-     */
1482
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1483
-    {
1484
-        $timezone = $ticket->get_timezone();
1485
-        foreach ($prices_data as $row => $price_data) {
1486
-            $price_values = [
1487
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1488
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1489
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1490
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1491
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1492
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1493
-                'PRC_order'      => $row,
1494
-            ];
1495
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1496
-                $price_values['PRC_ID'] = 0;
1497
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1498
-            } else {
1499
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1500
-                // update this price with new values
1501
-                foreach ($price_values as $field => $new_price) {
1502
-                    $price->set($field, $new_price);
1503
-                }
1504
-            }
1505
-            if (! $price instanceof EE_Price) {
1506
-                throw new RuntimeException(
1507
-                    sprintf(
1508
-                        esc_html__(
1509
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1510
-                            'event_espresso'
1511
-                        ),
1512
-                        print_r($price_values, true)
1513
-                    )
1514
-                );
1515
-            }
1516
-            $price->save();
1517
-            $ticket->_add_relation_to($price, 'Price');
1518
-        }
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * Add in our autosave ajax handlers
1524
-     *
1525
-     */
1526
-    protected function _ee_autosave_create_new()
1527
-    {
1528
-    }
1529
-
1530
-
1531
-    /**
1532
-     * More autosave handlers.
1533
-     */
1534
-    protected function _ee_autosave_edit()
1535
-    {
1536
-    }
1537
-
1538
-
1539
-    /**
1540
-     * @throws EE_Error
1541
-     * @throws ReflectionException
1542
-     */
1543
-    private function _generate_publish_box_extra_content()
1544
-    {
1545
-        // load formatter helper
1546
-        // args for getting related registrations
1547
-        $approved_query_args        = [
1548
-            [
1549
-                'REG_deleted' => 0,
1550
-                'STS_ID'      => EEM_Registration::status_id_approved,
1551
-            ],
1552
-        ];
1553
-        $not_approved_query_args    = [
1554
-            [
1555
-                'REG_deleted' => 0,
1556
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1557
-            ],
1558
-        ];
1559
-        $pending_payment_query_args = [
1560
-            [
1561
-                'REG_deleted' => 0,
1562
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1563
-            ],
1564
-        ];
1565
-        // publish box
1566
-        $publish_box_extra_args = [
1567
-            'view_approved_reg_url'        => add_query_arg(
1568
-                [
1569
-                    'action'      => 'default',
1570
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1571
-                    '_reg_status' => EEM_Registration::status_id_approved,
1572
-                ],
1573
-                REG_ADMIN_URL
1574
-            ),
1575
-            'view_not_approved_reg_url'    => add_query_arg(
1576
-                [
1577
-                    'action'      => 'default',
1578
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1579
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1580
-                ],
1581
-                REG_ADMIN_URL
1582
-            ),
1583
-            'view_pending_payment_reg_url' => add_query_arg(
1584
-                [
1585
-                    'action'      => 'default',
1586
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1587
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1588
-                ],
1589
-                REG_ADMIN_URL
1590
-            ),
1591
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1592
-                'Registration',
1593
-                $approved_query_args
1594
-            ),
1595
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1596
-                'Registration',
1597
-                $not_approved_query_args
1598
-            ),
1599
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1600
-                'Registration',
1601
-                $pending_payment_query_args
1602
-            ),
1603
-            'misc_pub_section_class'       => apply_filters(
1604
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1605
-                'misc-pub-section'
1606
-            ),
1607
-        ];
1608
-        ob_start();
1609
-        do_action(
1610
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1611
-            $this->_cpt_model_obj
1612
-        );
1613
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1614
-        // load template
1615
-        EEH_Template::display_template(
1616
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1617
-            $publish_box_extra_args
1618
-        );
1619
-    }
1620
-
1621
-
1622
-    /**
1623
-     * @return EE_Event
1624
-     */
1625
-    public function get_event_object()
1626
-    {
1627
-        return $this->_cpt_model_obj;
1628
-    }
1629
-
1630
-
1631
-
1632
-
1633
-    /** METABOXES * */
1634
-    /**
1635
-     * _register_event_editor_meta_boxes
1636
-     * add all metaboxes related to the event_editor
1637
-     *
1638
-     * @return void
1639
-     * @throws EE_Error
1640
-     * @throws ReflectionException
1641
-     */
1642
-    protected function _register_event_editor_meta_boxes()
1643
-    {
1644
-        $this->verify_cpt_object();
1645
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1646
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1647
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1648
-            $this->addMetaBox(
1649
-                'espresso_event_editor_event_options',
1650
-                esc_html__('Event Registration Options', 'event_espresso'),
1651
-                [$this, 'registration_options_meta_box'],
1652
-                $this->page_slug,
1653
-                'side'
1654
-            );
1655
-        }
1656
-        if (! $use_advanced_editor) {
1657
-            $this->addMetaBox(
1658
-                'espresso_event_editor_tickets',
1659
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1660
-                [$this, 'ticket_metabox'],
1661
-                $this->page_slug,
1662
-                'normal',
1663
-                'high'
1664
-            );
1665
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1666
-            add_action(
1667
-                'add_meta_boxes_espresso_events',
1668
-                function () {
1669
-                    global $current_screen;
1670
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1671
-                },
1672
-                99
1673
-            );
1674
-        }
1675
-        // NOTE: if you're looking for other metaboxes in here,
1676
-        // where a metabox has a related management page in the admin
1677
-        // you will find it setup in the related management page's "_Hooks" file.
1678
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * @throws DomainException
1684
-     * @throws EE_Error
1685
-     * @throws ReflectionException
1686
-     */
1687
-    public function ticket_metabox()
1688
-    {
1689
-        $existing_datetime_ids = $existing_ticket_ids = [];
1690
-        // defaults for template args
1691
-        $template_args = [
1692
-            'existing_datetime_ids'    => '',
1693
-            'event_datetime_help_link' => '',
1694
-            'ticket_options_help_link' => '',
1695
-            'time'                     => null,
1696
-            'ticket_rows'              => '',
1697
-            'existing_ticket_ids'      => '',
1698
-            'total_ticket_rows'        => 1,
1699
-            'ticket_js_structure'      => '',
1700
-            'trash_icon'               => 'dashicons dashicons-lock',
1701
-            'disabled'                 => '',
1702
-        ];
1703
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1704
-        /**
1705
-         * 1. Start with retrieving Datetimes
1706
-         * 2. Fore each datetime get related tickets
1707
-         * 3. For each ticket get related prices
1708
-         */
1709
-        /** @var EEM_Datetime $datetime_model */
1710
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1711
-        /** @var EEM_Ticket $datetime_model */
1712
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1713
-        $times        = $datetime_model->get_all_event_dates($event_id);
1714
-        /** @type EE_Datetime $first_datetime */
1715
-        $first_datetime = reset($times);
1716
-        // do we get related tickets?
1717
-        if (
1718
-            $first_datetime instanceof EE_Datetime
1719
-            && $first_datetime->ID() !== 0
1720
-        ) {
1721
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1722
-            $template_args['time']   = $first_datetime;
1723
-            $related_tickets         = $first_datetime->tickets(
1724
-                [
1725
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1726
-                    'default_where_conditions' => 'none',
1727
-                ]
1728
-            );
1729
-            if (! empty($related_tickets)) {
1730
-                $template_args['total_ticket_rows'] = count($related_tickets);
1731
-                $row                                = 0;
1732
-                foreach ($related_tickets as $ticket) {
1733
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1734
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1735
-                    $row++;
1736
-                }
1737
-            } else {
1738
-                $template_args['total_ticket_rows'] = 1;
1739
-                /** @type EE_Ticket $ticket */
1740
-                $ticket                       = $ticket_model->create_default_object();
1741
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1742
-            }
1743
-        } else {
1744
-            $template_args['time'] = $times[0];
1745
-            /** @type EE_Ticket[] $tickets */
1746
-            $tickets                      = $ticket_model->get_all_default_tickets();
1747
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1748
-            // NOTE: we're just sending the first default row
1749
-            // (decaf can't manage default tickets so this should be sufficient);
1750
-        }
1751
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1752
-            'event_editor_event_datetimes_help_tab'
1753
-        );
1754
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1755
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1756
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1757
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1758
-            $ticket_model->create_default_object(),
1759
-            true
1760
-        );
1761
-        $template                                  = apply_filters(
1762
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1763
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1764
-        );
1765
-        EEH_Template::display_template($template, $template_args);
1766
-    }
1767
-
1768
-
1769
-    /**
1770
-     * Setup an individual ticket form for the decaf event editor page
1771
-     *
1772
-     * @access private
1773
-     * @param EE_Ticket $ticket   the ticket object
1774
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1775
-     * @param int       $row
1776
-     * @return string generated html for the ticket row.
1777
-     * @throws EE_Error
1778
-     * @throws ReflectionException
1779
-     */
1780
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1781
-    {
1782
-        $template_args = [
1783
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1784
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1785
-                : '',
1786
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1787
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1788
-            'TKT_name'            => $ticket->get('TKT_name'),
1789
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1790
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1791
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1792
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1793
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1794
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1795
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1796
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1797
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1798
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1799
-                : ' disabled=disabled',
1800
-        ];
1801
-        $price         = $ticket->ID() !== 0
1802
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1803
-            : null;
1804
-        $price         = $price instanceof EE_Price
1805
-            ? $price
1806
-            : EEM_Price::instance()->create_default_object();
1807
-        $price_args    = [
1808
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1809
-            'PRC_amount'            => $price->get('PRC_amount'),
1810
-            'PRT_ID'                => $price->get('PRT_ID'),
1811
-            'PRC_ID'                => $price->get('PRC_ID'),
1812
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1813
-        ];
1814
-        // make sure we have default start and end dates if skeleton
1815
-        // handle rows that should NOT be empty
1816
-        if (empty($template_args['TKT_start_date'])) {
1817
-            // if empty then the start date will be now.
1818
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1819
-        }
1820
-        if (empty($template_args['TKT_end_date'])) {
1821
-            // get the earliest datetime (if present);
1822
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1823
-                ? $this->_cpt_model_obj->get_first_related(
1824
-                    'Datetime',
1825
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1826
-                )
1827
-                : null;
1828
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1829
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1830
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1831
-        }
1832
-        $template_args = array_merge($template_args, $price_args);
1833
-        $template      = apply_filters(
1834
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1835
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1836
-            $ticket
1837
-        );
1838
-        return EEH_Template::display_template($template, $template_args, true);
1839
-    }
1840
-
1841
-
1842
-    /**
1843
-     * @throws EE_Error
1844
-     * @throws ReflectionException
1845
-     */
1846
-    public function registration_options_meta_box()
1847
-    {
1848
-        $yes_no_values             = [
1849
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1850
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1851
-        ];
1852
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1853
-            [
1854
-                EEM_Registration::status_id_cancelled,
1855
-                EEM_Registration::status_id_declined,
1856
-                EEM_Registration::status_id_incomplete,
1857
-            ],
1858
-            true
1859
-        );
1860
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1861
-        $template_args['_event']                          = $this->_cpt_model_obj;
1862
-        $template_args['event']                           = $this->_cpt_model_obj;
1863
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1864
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1865
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1866
-            'default_reg_status',
1867
-            $default_reg_status_values,
1868
-            $this->_cpt_model_obj->default_registration_status()
1869
-        );
1870
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1871
-            'display_desc',
1872
-            $yes_no_values,
1873
-            $this->_cpt_model_obj->display_description()
1874
-        );
1875
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1876
-            'display_ticket_selector',
1877
-            $yes_no_values,
1878
-            $this->_cpt_model_obj->display_ticket_selector(),
1879
-            '',
1880
-            '',
1881
-            false
1882
-        );
1883
-        $template_args['additional_registration_options'] = apply_filters(
1884
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1885
-            '',
1886
-            $template_args,
1887
-            $yes_no_values,
1888
-            $default_reg_status_values
1889
-        );
1890
-        EEH_Template::display_template(
1891
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1892
-            $template_args
1893
-        );
1894
-    }
1895
-
1896
-
1897
-    /**
1898
-     * _get_events()
1899
-     * This method simply returns all the events (for the given _view and paging)
1900
-     *
1901
-     * @access public
1902
-     * @param int  $per_page     count of items per page (20 default);
1903
-     * @param int  $current_page what is the current page being viewed.
1904
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1905
-     *                           If FALSE then we return an array of event objects
1906
-     *                           that match the given _view and paging parameters.
1907
-     * @return array|int         an array of event objects or a count of them.
1908
-     * @throws Exception
1909
-     */
1910
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1911
-    {
1912
-        $EEM_Event   = $this->_event_model();
1913
-        $offset      = ($current_page - 1) * $per_page;
1914
-        $limit       = $count ? null : $offset . ',' . $per_page;
1915
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1916
-        $order       = $this->request->getRequestParam('order', 'DESC');
1917
-        $month_range = $this->request->getRequestParam('month_range');
1918
-        if ($month_range) {
1919
-            $pieces = explode(' ', $month_range, 3);
1920
-            // simulate the FIRST day of the month, that fixes issues for months like February
1921
-            // where PHP doesn't know what to assume for date.
1922
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1923
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1924
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1925
-        }
1926
-        $where  = [];
1927
-        $status = $this->request->getRequestParam('status');
1928
-        // determine what post_status our condition will have for the query.
1929
-        switch ($status) {
1930
-            case 'month':
1931
-            case 'today':
1932
-            case null:
1933
-            case 'all':
1934
-                break;
1935
-            case 'draft':
1936
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1937
-                break;
1938
-            default:
1939
-                $where['status'] = $status;
1940
-        }
1941
-        // categories? The default for all categories is -1
1942
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1943
-        if ($category !== -1) {
1944
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1945
-            $where['Term_Taxonomy.term_id']  = $category;
1946
-        }
1947
-        // date where conditions
1948
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1949
-        if ($month_range) {
1950
-            $DateTime = new DateTime(
1951
-                $year_r . '-' . $month_r . '-01 00:00:00',
1952
-                new DateTimeZone('UTC')
1953
-            );
1954
-            $start    = $DateTime->getTimestamp();
1955
-            // set the datetime to be the end of the month
1956
-            $DateTime->setDate(
1957
-                $year_r,
1958
-                $month_r,
1959
-                $DateTime->format('t')
1960
-            )->setTime(23, 59, 59);
1961
-            $end                             = $DateTime->getTimestamp();
1962
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1963
-        } elseif ($status === 'today') {
1964
-            $DateTime                        =
1965
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1966
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1967
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1968
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1969
-        } elseif ($status === 'month') {
1970
-            $now                             = date('Y-m-01');
1971
-            $DateTime                        =
1972
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1973
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1974
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1975
-                                                        ->setTime(23, 59, 59)
1976
-                                                        ->format(implode(' ', $start_formats));
1977
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1978
-        }
1979
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1980
-            $where['EVT_wp_user'] = get_current_user_id();
1981
-        } else {
1982
-            if (! isset($where['status'])) {
1983
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1984
-                    $where['OR'] = [
1985
-                        'status*restrict_private' => ['!=', 'private'],
1986
-                        'AND'                     => [
1987
-                            'status*inclusive' => ['=', 'private'],
1988
-                            'EVT_wp_user'      => get_current_user_id(),
1989
-                        ],
1990
-                    ];
1991
-                }
1992
-            }
1993
-        }
1994
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1995
-        if (
1996
-            $wp_user
1997
-            && $wp_user !== get_current_user_id()
1998
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1999
-        ) {
2000
-            $where['EVT_wp_user'] = $wp_user;
2001
-        }
2002
-        // search query handling
2003
-        $search_term = $this->request->getRequestParam('s');
2004
-        if ($search_term) {
2005
-            $search_term = '%' . $search_term . '%';
2006
-            $where['OR'] = [
2007
-                'EVT_name'       => ['LIKE', $search_term],
2008
-                'EVT_desc'       => ['LIKE', $search_term],
2009
-                'EVT_short_desc' => ['LIKE', $search_term],
2010
-            ];
2011
-        }
2012
-        // filter events by venue.
2013
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
2014
-        if ($venue) {
2015
-            $where['Venue.VNU_ID'] = $venue;
2016
-        }
2017
-        $request_params = $this->request->requestParams();
2018
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2019
-        $query_params   = apply_filters(
2020
-            'FHEE__Events_Admin_Page__get_events__query_params',
2021
-            [
2022
-                $where,
2023
-                'limit'    => $limit,
2024
-                'order_by' => $orderby,
2025
-                'order'    => $order,
2026
-                'group_by' => 'EVT_ID',
2027
-            ],
2028
-            $request_params
2029
-        );
2030
-
2031
-        // let's first check if we have special requests coming in.
2032
-        $active_status = $this->request->getRequestParam('active_status');
2033
-        if ($active_status) {
2034
-            switch ($active_status) {
2035
-                case 'upcoming':
2036
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2037
-                case 'expired':
2038
-                    return $EEM_Event->get_expired_events($query_params, $count);
2039
-                case 'active':
2040
-                    return $EEM_Event->get_active_events($query_params, $count);
2041
-                case 'inactive':
2042
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2043
-            }
2044
-        }
2045
-
2046
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     * handling for WordPress CPT actions (trash, restore, delete)
2052
-     *
2053
-     * @param string $post_id
2054
-     * @throws EE_Error
2055
-     * @throws ReflectionException
2056
-     */
2057
-    public function trash_cpt_item($post_id)
2058
-    {
2059
-        $this->request->setRequestParam('EVT_ID', $post_id);
2060
-        $this->_trash_or_restore_event('trash', false);
2061
-    }
2062
-
2063
-
2064
-    /**
2065
-     * @param string $post_id
2066
-     * @throws EE_Error
2067
-     * @throws ReflectionException
2068
-     */
2069
-    public function restore_cpt_item($post_id)
2070
-    {
2071
-        $this->request->setRequestParam('EVT_ID', $post_id);
2072
-        $this->_trash_or_restore_event('draft', false);
2073
-    }
2074
-
2075
-
2076
-    /**
2077
-     * @param string $post_id
2078
-     * @throws EE_Error
2079
-     * @throws EE_Error
2080
-     */
2081
-    public function delete_cpt_item($post_id)
2082
-    {
2083
-        throw new EE_Error(
2084
-            esc_html__(
2085
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2086
-                'event_espresso'
2087
-            )
2088
-        );
2089
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2090
-        // $this->_delete_event();
2091
-    }
2092
-
2093
-
2094
-    /**
2095
-     * _trash_or_restore_event
2096
-     *
2097
-     * @access protected
2098
-     * @param string $event_status
2099
-     * @param bool   $redirect_after
2100
-     * @throws EE_Error
2101
-     * @throws EE_Error
2102
-     * @throws ReflectionException
2103
-     */
2104
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2105
-    {
2106
-        // determine the event id and set to array.
2107
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2108
-        // loop thru events
2109
-        if ($EVT_ID) {
2110
-            // clean status
2111
-            $event_status = sanitize_key($event_status);
2112
-            // grab status
2113
-            if (! empty($event_status)) {
2114
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2115
-            } else {
2116
-                $success = false;
2117
-                $msg     = esc_html__(
2118
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2119
-                    'event_espresso'
2120
-                );
2121
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
-            }
2123
-        } else {
2124
-            $success = false;
2125
-            $msg     = esc_html__(
2126
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2127
-                'event_espresso'
2128
-            );
2129
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2130
-        }
2131
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2132
-        if ($redirect_after) {
2133
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2134
-        }
2135
-    }
2136
-
2137
-
2138
-    /**
2139
-     * _trash_or_restore_events
2140
-     *
2141
-     * @access protected
2142
-     * @param string $event_status
2143
-     * @return void
2144
-     * @throws EE_Error
2145
-     * @throws EE_Error
2146
-     * @throws ReflectionException
2147
-     */
2148
-    protected function _trash_or_restore_events($event_status = 'trash')
2149
-    {
2150
-        // clean status
2151
-        $event_status = sanitize_key($event_status);
2152
-        // grab status
2153
-        if (! empty($event_status)) {
2154
-            $success = true;
2155
-            // determine the event id and set to array.
2156
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2157
-            // loop thru events
2158
-            foreach ($EVT_IDs as $EVT_ID) {
2159
-                if ($EVT_ID = absint($EVT_ID)) {
2160
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2161
-                    $success = $results !== false ? $success : false;
2162
-                } else {
2163
-                    $msg = sprintf(
2164
-                        esc_html__(
2165
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2166
-                            'event_espresso'
2167
-                        ),
2168
-                        $EVT_ID
2169
-                    );
2170
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
-                    $success = false;
2172
-                }
2173
-            }
2174
-        } else {
2175
-            $success = false;
2176
-            $msg     = esc_html__(
2177
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2178
-                'event_espresso'
2179
-            );
2180
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2181
-        }
2182
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2183
-        $success = $success ? 2 : false;
2184
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2185
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2186
-    }
2187
-
2188
-
2189
-    /**
2190
-     * @param int    $EVT_ID
2191
-     * @param string $event_status
2192
-     * @return bool
2193
-     * @throws EE_Error
2194
-     * @throws ReflectionException
2195
-     */
2196
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2197
-    {
2198
-        // grab event id
2199
-        if (! $EVT_ID) {
2200
-            $msg = esc_html__(
2201
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2202
-                'event_espresso'
2203
-            );
2204
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2205
-            return false;
2206
-        }
2207
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2208
-        // clean status
2209
-        $event_status = sanitize_key($event_status);
2210
-        // grab status
2211
-        if (empty($event_status)) {
2212
-            $msg = esc_html__(
2213
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2214
-                'event_espresso'
2215
-            );
2216
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2217
-            return false;
2218
-        }
2219
-        // was event trashed or restored ?
2220
-        switch ($event_status) {
2221
-            case 'draft':
2222
-                $action = 'restored from the trash';
2223
-                $hook   = 'AHEE_event_restored_from_trash';
2224
-                break;
2225
-            case 'trash':
2226
-                $action = 'moved to the trash';
2227
-                $hook   = 'AHEE_event_moved_to_trash';
2228
-                break;
2229
-            default:
2230
-                $action = 'updated';
2231
-                $hook   = false;
2232
-        }
2233
-        // use class to change status
2234
-        $this->_cpt_model_obj->set_status($event_status);
2235
-        $success = $this->_cpt_model_obj->save();
2236
-        if (! $success) {
2237
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2238
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2239
-            return false;
2240
-        }
2241
-        if ($hook) {
2242
-            do_action($hook);
2243
-        }
2244
-        return true;
2245
-    }
2246
-
2247
-
2248
-    /**
2249
-     * @param array $event_ids
2250
-     * @return array
2251
-     * @since   4.10.23.p
2252
-     */
2253
-    private function cleanEventIds(array $event_ids)
2254
-    {
2255
-        return array_map('absint', $event_ids);
2256
-    }
2257
-
2258
-
2259
-    /**
2260
-     * @return array
2261
-     * @since   4.10.23.p
2262
-     */
2263
-    private function getEventIdsFromRequest()
2264
-    {
2265
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2266
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2267
-        } else {
2268
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2269
-        }
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * @param bool $preview_delete
2275
-     * @throws EE_Error
2276
-     */
2277
-    protected function _delete_event($preview_delete = true)
2278
-    {
2279
-        $this->_delete_events($preview_delete);
2280
-    }
2281
-
2282
-
2283
-    /**
2284
-     * Gets the tree traversal batch persister.
2285
-     *
2286
-     * @return NodeGroupDao
2287
-     * @throws InvalidArgumentException
2288
-     * @throws InvalidDataTypeException
2289
-     * @throws InvalidInterfaceException
2290
-     * @since 4.10.12.p
2291
-     */
2292
-    protected function getModelObjNodeGroupPersister()
2293
-    {
2294
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2295
-            $this->model_obj_node_group_persister =
2296
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2297
-        }
2298
-        return $this->model_obj_node_group_persister;
2299
-    }
2300
-
2301
-
2302
-    /**
2303
-     * @param bool $preview_delete
2304
-     * @return void
2305
-     * @throws EE_Error
2306
-     */
2307
-    protected function _delete_events($preview_delete = true)
2308
-    {
2309
-        $event_ids = $this->getEventIdsFromRequest();
2310
-        if ($preview_delete) {
2311
-            $this->generateDeletionPreview($event_ids);
2312
-        } else {
2313
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2314
-        }
2315
-    }
2316
-
2317
-
2318
-    /**
2319
-     * @param array $event_ids
2320
-     */
2321
-    protected function generateDeletionPreview(array $event_ids)
2322
-    {
2323
-        $event_ids = $this->cleanEventIds($event_ids);
2324
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2325
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2326
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2327
-            [
2328
-                'action'            => 'preview_deletion',
2329
-                'deletion_job_code' => $deletion_job_code,
2330
-            ],
2331
-            $this->_admin_base_url
2332
-        );
2333
-        EEH_URL::safeRedirectAndExit(
2334
-            EE_Admin_Page::add_query_args_and_nonce(
2335
-                [
2336
-                    'page'              => EED_Batch::PAGE_SLUG,
2337
-                    'batch'             => EED_Batch::batch_job,
2338
-                    'EVT_IDs'           => $event_ids,
2339
-                    'deletion_job_code' => $deletion_job_code,
2340
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2341
-                    'return_url'        => urlencode($return_url),
2342
-                ],
2343
-                admin_url()
2344
-            )
2345
-        );
2346
-    }
2347
-
2348
-
2349
-    /**
2350
-     * Checks for a POST submission
2351
-     *
2352
-     * @since 4.10.12.p
2353
-     */
2354
-    protected function confirmDeletion()
2355
-    {
2356
-        $deletion_redirect_logic =
2357
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2358
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2359
-    }
2360
-
2361
-
2362
-    /**
2363
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2364
-     *
2365
-     * @throws EE_Error
2366
-     * @since 4.10.12.p
2367
-     */
2368
-    protected function previewDeletion()
2369
-    {
2370
-        $preview_deletion_logic =
2371
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2372
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2373
-        $this->display_admin_page_with_no_sidebar();
2374
-    }
2375
-
2376
-
2377
-    /**
2378
-     * get total number of events
2379
-     *
2380
-     * @access public
2381
-     * @return int
2382
-     * @throws EE_Error
2383
-     * @throws EE_Error
2384
-     */
2385
-    public function total_events()
2386
-    {
2387
-        return EEM_Event::instance()->count(
2388
-            ['caps' => 'read_admin'],
2389
-            'EVT_ID',
2390
-            true
2391
-        );
2392
-    }
2393
-
2394
-
2395
-    /**
2396
-     * get total number of draft events
2397
-     *
2398
-     * @access public
2399
-     * @return int
2400
-     * @throws EE_Error
2401
-     * @throws EE_Error
2402
-     */
2403
-    public function total_events_draft()
2404
-    {
2405
-        return EEM_Event::instance()->count(
2406
-            [
2407
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2408
-                'caps' => 'read_admin',
2409
-            ],
2410
-            'EVT_ID',
2411
-            true
2412
-        );
2413
-    }
2414
-
2415
-
2416
-    /**
2417
-     * get total number of trashed events
2418
-     *
2419
-     * @access public
2420
-     * @return int
2421
-     * @throws EE_Error
2422
-     * @throws EE_Error
2423
-     */
2424
-    public function total_trashed_events()
2425
-    {
2426
-        return EEM_Event::instance()->count(
2427
-            [
2428
-                ['status' => 'trash'],
2429
-                'caps' => 'read_admin',
2430
-            ],
2431
-            'EVT_ID',
2432
-            true
2433
-        );
2434
-    }
2435
-
2436
-
2437
-    /**
2438
-     *    _default_event_settings
2439
-     *    This generates the Default Settings Tab
2440
-     *
2441
-     * @return void
2442
-     * @throws DomainException
2443
-     * @throws EE_Error
2444
-     * @throws InvalidArgumentException
2445
-     * @throws InvalidDataTypeException
2446
-     * @throws InvalidInterfaceException
2447
-     */
2448
-    protected function _default_event_settings()
2449
-    {
2450
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2451
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2452
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
2453
-            $this->_default_event_settings_form()->get_html(),
2454
-            '',
2455
-            'padding'
2456
-        );
2457
-        $this->display_admin_page_with_sidebar();
2458
-    }
2459
-
2460
-
2461
-    /**
2462
-     * Return the form for event settings.
2463
-     *
2464
-     * @return EE_Form_Section_Proper
2465
-     * @throws EE_Error
2466
-     */
2467
-    protected function _default_event_settings_form()
2468
-    {
2469
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2470
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2471
-        // exclude
2472
-            [
2473
-                EEM_Registration::status_id_cancelled,
2474
-                EEM_Registration::status_id_declined,
2475
-                EEM_Registration::status_id_incomplete,
2476
-                EEM_Registration::status_id_wait_list,
2477
-            ],
2478
-            true
2479
-        );
2480
-        // setup Advanced Editor ???
2481
-        if (
2482
-            $this->raw_req_action === 'default_event_settings'
2483
-            || $this->raw_req_action === 'update_default_event_settings'
2484
-        ) {
2485
-            $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2486
-        }
2487
-        return new EE_Form_Section_Proper(
2488
-            [
2489
-                'name'            => 'update_default_event_settings',
2490
-                'html_id'         => 'update_default_event_settings',
2491
-                'html_class'      => 'form-table',
2492
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2493
-                'subsections'     => apply_filters(
2494
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2495
-                    [
2496
-                        'defaults_section_header' => new EE_Form_Section_HTML(
2497
-                            EEH_HTML::h2(
2498
-                                esc_html__('Default Settings', 'event_espresso'),
2499
-                                '',
2500
-                                'ee-admin-settings-hdr'
2501
-                            )
2502
-                        ),
2503
-                        'default_reg_status'  => new EE_Select_Input(
2504
-                            $registration_stati_for_selection,
2505
-                            [
2506
-                                'default'         => isset($registration_config->default_STS_ID)
2507
-                                                     && array_key_exists(
2508
-                                                         $registration_config->default_STS_ID,
2509
-                                                         $registration_stati_for_selection
2510
-                                                     )
2511
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2512
-                                    : EEM_Registration::status_id_pending_payment,
2513
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2514
-                                                     . EEH_Template::get_help_tab_link(
2515
-                                                         'default_settings_status_help_tab'
2516
-                                                     ),
2517
-                                'html_help_text'  => esc_html__(
2518
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2519
-                                    'event_espresso'
2520
-                                ),
2521
-                            ]
2522
-                        ),
2523
-                        'default_max_tickets' => new EE_Integer_Input(
2524
-                            [
2525
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2526
-                                    ? $registration_config->default_maximum_number_of_tickets
2527
-                                    : EEM_Event::get_default_additional_limit(),
2528
-                                'html_label_text' => esc_html__(
2529
-                                    'Default Maximum Tickets Allowed Per Order:',
2530
-                                    'event_espresso'
2531
-                                )
2532
-                                                     . EEH_Template::get_help_tab_link(
2533
-                                                         'default_maximum_tickets_help_tab"'
2534
-                                                     ),
2535
-                                'html_help_text'  => esc_html__(
2536
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2537
-                                    'event_espresso'
2538
-                                ),
2539
-                            ]
2540
-                        ),
2541
-                    ]
2542
-                ),
2543
-            ]
2544
-        );
2545
-    }
2546
-
2547
-
2548
-    /**
2549
-     * @return void
2550
-     * @throws EE_Error
2551
-     * @throws InvalidArgumentException
2552
-     * @throws InvalidDataTypeException
2553
-     * @throws InvalidInterfaceException
2554
-     */
2555
-    protected function _update_default_event_settings()
2556
-    {
2557
-        $form = $this->_default_event_settings_form();
2558
-        if ($form->was_submitted()) {
2559
-            $form->receive_form_submission();
2560
-            if ($form->is_valid()) {
2561
-                $registration_config = EE_Registry::instance()->CFG->registration;
2562
-                $valid_data          = $form->valid_data();
2563
-                if (isset($valid_data['default_reg_status'])) {
2564
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2565
-                }
2566
-                if (isset($valid_data['default_max_tickets'])) {
2567
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2568
-                }
2569
-                do_action(
2570
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2571
-                    $valid_data,
2572
-                    EE_Registry::instance()->CFG,
2573
-                    $this
2574
-                );
2575
-                // update because data was valid!
2576
-                EE_Registry::instance()->CFG->update_espresso_config();
2577
-                EE_Error::overwrite_success();
2578
-                EE_Error::add_success(
2579
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2580
-                );
2581
-            }
2582
-        }
2583
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2584
-    }
2585
-
2586
-
2587
-    /*************        Templates        *************
2588
-     *
2589
-     * @throws EE_Error
2590
-     */
2591
-    protected function _template_settings()
2592
-    {
2593
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2594
-        $this->_template_args['preview_img']  = '<img src="'
2595
-                                                . EVENTS_ASSETS_URL
2596
-                                                . '/images/'
2597
-                                                . 'caffeinated_template_features.jpg" alt="'
2598
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2599
-                                                . '" />';
2600
-        $this->_template_args['preview_text'] = '<strong>'
2601
-                                                . esc_html__(
2602
-                                                    'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2603
-                                                    'event_espresso'
2604
-                                                ) . '</strong>';
2605
-        $this->display_admin_caf_preview_page('template_settings_tab');
2606
-    }
2607
-
2608
-
2609
-    /** Event Category Stuff **/
2610
-    /**
2611
-     * set the _category property with the category object for the loaded page.
2612
-     *
2613
-     * @access private
2614
-     * @return void
2615
-     */
2616
-    private function _set_category_object()
2617
-    {
2618
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2619
-            return;
2620
-        } //already have the category object so get out.
2621
-        // set default category object
2622
-        $this->_set_empty_category_object();
2623
-        // only set if we've got an id
2624
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2625
-        if (! $category_ID) {
2626
-            return;
2627
-        }
2628
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2629
-        if (! empty($term)) {
2630
-            $this->_category->category_name       = $term->name;
2631
-            $this->_category->category_identifier = $term->slug;
2632
-            $this->_category->category_desc       = $term->description;
2633
-            $this->_category->id                  = $term->term_id;
2634
-            $this->_category->parent              = $term->parent;
2635
-        }
2636
-    }
2637
-
2638
-
2639
-    /**
2640
-     * Clears out category properties.
2641
-     */
2642
-    private function _set_empty_category_object()
2643
-    {
2644
-        $this->_category                = new stdClass();
2645
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2646
-        $this->_category->id            = $this->_category->parent = 0;
2647
-    }
2648
-
2649
-
2650
-    /**
2651
-     * @throws DomainException
2652
-     * @throws EE_Error
2653
-     * @throws InvalidArgumentException
2654
-     * @throws InvalidDataTypeException
2655
-     * @throws InvalidInterfaceException
2656
-     */
2657
-    protected function _category_list_table()
2658
-    {
2659
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2660
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2661
-        $this->_admin_page_title .= ' ';
2662
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2663
-            'add_category',
2664
-            'add_category',
2665
-            [],
2666
-            'add-new-h2'
2667
-        );
2668
-        $this->display_admin_list_table_page_with_sidebar();
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * Output category details view.
2674
-     *
2675
-     * @throws EE_Error
2676
-     * @throws EE_Error
2677
-     */
2678
-    protected function _category_details($view)
2679
-    {
2680
-        // load formatter helper
2681
-        // load field generator helper
2682
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2683
-        $this->_set_add_edit_form_tags($route);
2684
-        $this->_set_category_object();
2685
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2686
-        $delete_action = 'delete_category';
2687
-        // custom redirect
2688
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2689
-            ['action' => 'category_list'],
2690
-            $this->_admin_base_url
2691
-        );
2692
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2693
-        // take care of contents
2694
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2695
-        $this->display_admin_page_with_sidebar();
2696
-    }
2697
-
2698
-
2699
-    /**
2700
-     * Output category details content.
2701
-     *
2702
-     * @throws DomainException
2703
-     */
2704
-    protected function _category_details_content()
2705
-    {
2706
-        $editor_args['category_desc'] = [
2707
-            'type'          => 'wp_editor',
2708
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2709
-            'class'         => 'my_editor_custom',
2710
-            'wpeditor_args' => ['media_buttons' => false],
2711
-        ];
2712
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2713
-        $all_terms                    = get_terms(
2714
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2715
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2716
-        );
2717
-        // setup category select for term parents.
2718
-        $category_select_values[] = [
2719
-            'text' => esc_html__('No Parent', 'event_espresso'),
2720
-            'id'   => 0,
2721
-        ];
2722
-        foreach ($all_terms as $term) {
2723
-            $category_select_values[] = [
2724
-                'text' => $term->name,
2725
-                'id'   => $term->term_id,
2726
-            ];
2727
-        }
2728
-        $category_select = EEH_Form_Fields::select_input(
2729
-            'category_parent',
2730
-            $category_select_values,
2731
-            $this->_category->parent
2732
-        );
2733
-        $template_args   = [
2734
-            'category'                 => $this->_category,
2735
-            'category_select'          => $category_select,
2736
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2737
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2738
-            'disable'                  => '',
2739
-            'disabled_message'         => false,
2740
-        ];
2741
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2742
-        return EEH_Template::display_template($template, $template_args, true);
2743
-    }
2744
-
2745
-
2746
-    /**
2747
-     * Handles deleting categories.
2748
-     *
2749
-     * @throws EE_Error
2750
-     */
2751
-    protected function _delete_categories()
2752
-    {
2753
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2754
-        foreach ($category_IDs as $category_ID) {
2755
-            $this->_delete_category($category_ID);
2756
-        }
2757
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2758
-        $query_args = [
2759
-            'action' => 'category_list',
2760
-        ];
2761
-        $this->_redirect_after_action(0, '', '', $query_args);
2762
-    }
2763
-
2764
-
2765
-    /**
2766
-     * Handles deleting specific category.
2767
-     *
2768
-     * @param int $cat_id
2769
-     */
2770
-    protected function _delete_category($cat_id)
2771
-    {
2772
-        $cat_id = absint($cat_id);
2773
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2774
-    }
2775
-
2776
-
2777
-    /**
2778
-     * Handles triggering the update or insertion of a new category.
2779
-     *
2780
-     * @param bool $new_category true means we're triggering the insert of a new category.
2781
-     * @throws EE_Error
2782
-     * @throws EE_Error
2783
-     */
2784
-    protected function _insert_or_update_category($new_category)
2785
-    {
2786
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2787
-        $success = 0; // we already have a success message so lets not send another.
2788
-        if ($cat_id) {
2789
-            $query_args = [
2790
-                'action'     => 'edit_category',
2791
-                'EVT_CAT_ID' => $cat_id,
2792
-            ];
2793
-        } else {
2794
-            $query_args = ['action' => 'add_category'];
2795
-        }
2796
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2797
-    }
2798
-
2799
-
2800
-    /**
2801
-     * Inserts or updates category
2802
-     *
2803
-     * @param bool $update (true indicates we're updating a category).
2804
-     * @return bool|mixed|string
2805
-     */
2806
-    private function _insert_category($update = false)
2807
-    {
2808
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2809
-        $category_name       = $this->request->getRequestParam('category_name', '');
2810
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2811
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2812
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2813
-
2814
-        if (empty($category_name)) {
2815
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2816
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2817
-            return false;
2818
-        }
2819
-        $term_args = [
2820
-            'name'        => $category_name,
2821
-            'description' => $category_desc,
2822
-            'parent'      => $category_parent,
2823
-        ];
2824
-        // was the category_identifier input disabled?
2825
-        if ($category_identifier) {
2826
-            $term_args['slug'] = $category_identifier;
2827
-        }
2828
-        $insert_ids = $update
2829
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2830
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2831
-        if (! is_array($insert_ids)) {
2832
-            $msg = esc_html__(
2833
-                'An error occurred and the category has not been saved to the database.',
2834
-                'event_espresso'
2835
-            );
2836
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2837
-        } else {
2838
-            $category_ID = $insert_ids['term_id'];
2839
-            $msg         = sprintf(
2840
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2841
-                $category_name
2842
-            );
2843
-            EE_Error::add_success($msg);
2844
-        }
2845
-        return $category_ID;
2846
-    }
2847
-
2848
-
2849
-    /**
2850
-     * Gets categories or count of categories matching the arguments in the request.
2851
-     *
2852
-     * @param int  $per_page
2853
-     * @param int  $current_page
2854
-     * @param bool $count
2855
-     * @return EE_Term_Taxonomy[]|int
2856
-     * @throws EE_Error
2857
-     */
2858
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2859
-    {
2860
-        // testing term stuff
2861
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2862
-        $order       = $this->request->getRequestParam('order', 'DESC');
2863
-        $limit       = ($current_page - 1) * $per_page;
2864
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2865
-        $search_term = $this->request->getRequestParam('s');
2866
-        if ($search_term) {
2867
-            $search_term = '%' . $search_term . '%';
2868
-            $where['OR'] = [
2869
-                'Term.name'   => ['LIKE', $search_term],
2870
-                'description' => ['LIKE', $search_term],
2871
-            ];
2872
-        }
2873
-        $query_params = [
2874
-            $where,
2875
-            'order_by'   => [$orderby => $order],
2876
-            'limit'      => $limit . ',' . $per_page,
2877
-            'force_join' => ['Term'],
2878
-        ];
2879
-        return $count
2880
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2881
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2882
-    }
2883
-
2884
-    /* end category stuff */
2885
-
2886
-
2887
-    /**************/
2888
-
2889
-
2890
-    /**
2891
-     * Callback for the `ee_save_timezone_setting` ajax action.
2892
-     *
2893
-     * @throws EE_Error
2894
-     * @throws InvalidArgumentException
2895
-     * @throws InvalidDataTypeException
2896
-     * @throws InvalidInterfaceException
2897
-     */
2898
-    public function saveTimezoneString()
2899
-    {
2900
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2901
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2902
-            EE_Error::add_error(
2903
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2904
-                __FILE__,
2905
-                __FUNCTION__,
2906
-                __LINE__
2907
-            );
2908
-            $this->_template_args['error'] = true;
2909
-            $this->_return_json();
2910
-        }
2911
-
2912
-        update_option('timezone_string', $timezone_string);
2913
-        EE_Error::add_success(
2914
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2915
-        );
2916
-        $this->_template_args['success'] = true;
2917
-        $this->_return_json(true, ['action' => 'create_new']);
2918
-    }
2919
-
2920
-
2921
-    /**
2922 2589
      * @throws EE_Error
2923
-     * @deprecated 4.10.25.p
2924 2590
      */
2925
-    public function save_timezonestring_setting()
2926
-    {
2927
-        $this->saveTimezoneString();
2928
-    }
2591
+	protected function _template_settings()
2592
+	{
2593
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2594
+		$this->_template_args['preview_img']  = '<img src="'
2595
+												. EVENTS_ASSETS_URL
2596
+												. '/images/'
2597
+												. 'caffeinated_template_features.jpg" alt="'
2598
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2599
+												. '" />';
2600
+		$this->_template_args['preview_text'] = '<strong>'
2601
+												. esc_html__(
2602
+													'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2603
+													'event_espresso'
2604
+												) . '</strong>';
2605
+		$this->display_admin_caf_preview_page('template_settings_tab');
2606
+	}
2607
+
2608
+
2609
+	/** Event Category Stuff **/
2610
+	/**
2611
+	 * set the _category property with the category object for the loaded page.
2612
+	 *
2613
+	 * @access private
2614
+	 * @return void
2615
+	 */
2616
+	private function _set_category_object()
2617
+	{
2618
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2619
+			return;
2620
+		} //already have the category object so get out.
2621
+		// set default category object
2622
+		$this->_set_empty_category_object();
2623
+		// only set if we've got an id
2624
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2625
+		if (! $category_ID) {
2626
+			return;
2627
+		}
2628
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2629
+		if (! empty($term)) {
2630
+			$this->_category->category_name       = $term->name;
2631
+			$this->_category->category_identifier = $term->slug;
2632
+			$this->_category->category_desc       = $term->description;
2633
+			$this->_category->id                  = $term->term_id;
2634
+			$this->_category->parent              = $term->parent;
2635
+		}
2636
+	}
2637
+
2638
+
2639
+	/**
2640
+	 * Clears out category properties.
2641
+	 */
2642
+	private function _set_empty_category_object()
2643
+	{
2644
+		$this->_category                = new stdClass();
2645
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2646
+		$this->_category->id            = $this->_category->parent = 0;
2647
+	}
2648
+
2649
+
2650
+	/**
2651
+	 * @throws DomainException
2652
+	 * @throws EE_Error
2653
+	 * @throws InvalidArgumentException
2654
+	 * @throws InvalidDataTypeException
2655
+	 * @throws InvalidInterfaceException
2656
+	 */
2657
+	protected function _category_list_table()
2658
+	{
2659
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2660
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2661
+		$this->_admin_page_title .= ' ';
2662
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2663
+			'add_category',
2664
+			'add_category',
2665
+			[],
2666
+			'add-new-h2'
2667
+		);
2668
+		$this->display_admin_list_table_page_with_sidebar();
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * Output category details view.
2674
+	 *
2675
+	 * @throws EE_Error
2676
+	 * @throws EE_Error
2677
+	 */
2678
+	protected function _category_details($view)
2679
+	{
2680
+		// load formatter helper
2681
+		// load field generator helper
2682
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2683
+		$this->_set_add_edit_form_tags($route);
2684
+		$this->_set_category_object();
2685
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2686
+		$delete_action = 'delete_category';
2687
+		// custom redirect
2688
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2689
+			['action' => 'category_list'],
2690
+			$this->_admin_base_url
2691
+		);
2692
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2693
+		// take care of contents
2694
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2695
+		$this->display_admin_page_with_sidebar();
2696
+	}
2697
+
2698
+
2699
+	/**
2700
+	 * Output category details content.
2701
+	 *
2702
+	 * @throws DomainException
2703
+	 */
2704
+	protected function _category_details_content()
2705
+	{
2706
+		$editor_args['category_desc'] = [
2707
+			'type'          => 'wp_editor',
2708
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2709
+			'class'         => 'my_editor_custom',
2710
+			'wpeditor_args' => ['media_buttons' => false],
2711
+		];
2712
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2713
+		$all_terms                    = get_terms(
2714
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2715
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2716
+		);
2717
+		// setup category select for term parents.
2718
+		$category_select_values[] = [
2719
+			'text' => esc_html__('No Parent', 'event_espresso'),
2720
+			'id'   => 0,
2721
+		];
2722
+		foreach ($all_terms as $term) {
2723
+			$category_select_values[] = [
2724
+				'text' => $term->name,
2725
+				'id'   => $term->term_id,
2726
+			];
2727
+		}
2728
+		$category_select = EEH_Form_Fields::select_input(
2729
+			'category_parent',
2730
+			$category_select_values,
2731
+			$this->_category->parent
2732
+		);
2733
+		$template_args   = [
2734
+			'category'                 => $this->_category,
2735
+			'category_select'          => $category_select,
2736
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2737
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2738
+			'disable'                  => '',
2739
+			'disabled_message'         => false,
2740
+		];
2741
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2742
+		return EEH_Template::display_template($template, $template_args, true);
2743
+	}
2744
+
2745
+
2746
+	/**
2747
+	 * Handles deleting categories.
2748
+	 *
2749
+	 * @throws EE_Error
2750
+	 */
2751
+	protected function _delete_categories()
2752
+	{
2753
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2754
+		foreach ($category_IDs as $category_ID) {
2755
+			$this->_delete_category($category_ID);
2756
+		}
2757
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2758
+		$query_args = [
2759
+			'action' => 'category_list',
2760
+		];
2761
+		$this->_redirect_after_action(0, '', '', $query_args);
2762
+	}
2763
+
2764
+
2765
+	/**
2766
+	 * Handles deleting specific category.
2767
+	 *
2768
+	 * @param int $cat_id
2769
+	 */
2770
+	protected function _delete_category($cat_id)
2771
+	{
2772
+		$cat_id = absint($cat_id);
2773
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2774
+	}
2775
+
2776
+
2777
+	/**
2778
+	 * Handles triggering the update or insertion of a new category.
2779
+	 *
2780
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2781
+	 * @throws EE_Error
2782
+	 * @throws EE_Error
2783
+	 */
2784
+	protected function _insert_or_update_category($new_category)
2785
+	{
2786
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2787
+		$success = 0; // we already have a success message so lets not send another.
2788
+		if ($cat_id) {
2789
+			$query_args = [
2790
+				'action'     => 'edit_category',
2791
+				'EVT_CAT_ID' => $cat_id,
2792
+			];
2793
+		} else {
2794
+			$query_args = ['action' => 'add_category'];
2795
+		}
2796
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2797
+	}
2798
+
2799
+
2800
+	/**
2801
+	 * Inserts or updates category
2802
+	 *
2803
+	 * @param bool $update (true indicates we're updating a category).
2804
+	 * @return bool|mixed|string
2805
+	 */
2806
+	private function _insert_category($update = false)
2807
+	{
2808
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2809
+		$category_name       = $this->request->getRequestParam('category_name', '');
2810
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2811
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2812
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2813
+
2814
+		if (empty($category_name)) {
2815
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2816
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2817
+			return false;
2818
+		}
2819
+		$term_args = [
2820
+			'name'        => $category_name,
2821
+			'description' => $category_desc,
2822
+			'parent'      => $category_parent,
2823
+		];
2824
+		// was the category_identifier input disabled?
2825
+		if ($category_identifier) {
2826
+			$term_args['slug'] = $category_identifier;
2827
+		}
2828
+		$insert_ids = $update
2829
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2830
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2831
+		if (! is_array($insert_ids)) {
2832
+			$msg = esc_html__(
2833
+				'An error occurred and the category has not been saved to the database.',
2834
+				'event_espresso'
2835
+			);
2836
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2837
+		} else {
2838
+			$category_ID = $insert_ids['term_id'];
2839
+			$msg         = sprintf(
2840
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2841
+				$category_name
2842
+			);
2843
+			EE_Error::add_success($msg);
2844
+		}
2845
+		return $category_ID;
2846
+	}
2847
+
2848
+
2849
+	/**
2850
+	 * Gets categories or count of categories matching the arguments in the request.
2851
+	 *
2852
+	 * @param int  $per_page
2853
+	 * @param int  $current_page
2854
+	 * @param bool $count
2855
+	 * @return EE_Term_Taxonomy[]|int
2856
+	 * @throws EE_Error
2857
+	 */
2858
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2859
+	{
2860
+		// testing term stuff
2861
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2862
+		$order       = $this->request->getRequestParam('order', 'DESC');
2863
+		$limit       = ($current_page - 1) * $per_page;
2864
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2865
+		$search_term = $this->request->getRequestParam('s');
2866
+		if ($search_term) {
2867
+			$search_term = '%' . $search_term . '%';
2868
+			$where['OR'] = [
2869
+				'Term.name'   => ['LIKE', $search_term],
2870
+				'description' => ['LIKE', $search_term],
2871
+			];
2872
+		}
2873
+		$query_params = [
2874
+			$where,
2875
+			'order_by'   => [$orderby => $order],
2876
+			'limit'      => $limit . ',' . $per_page,
2877
+			'force_join' => ['Term'],
2878
+		];
2879
+		return $count
2880
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2881
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2882
+	}
2883
+
2884
+	/* end category stuff */
2885
+
2886
+
2887
+	/**************/
2888
+
2889
+
2890
+	/**
2891
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2892
+	 *
2893
+	 * @throws EE_Error
2894
+	 * @throws InvalidArgumentException
2895
+	 * @throws InvalidDataTypeException
2896
+	 * @throws InvalidInterfaceException
2897
+	 */
2898
+	public function saveTimezoneString()
2899
+	{
2900
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2901
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2902
+			EE_Error::add_error(
2903
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2904
+				__FILE__,
2905
+				__FUNCTION__,
2906
+				__LINE__
2907
+			);
2908
+			$this->_template_args['error'] = true;
2909
+			$this->_return_json();
2910
+		}
2911
+
2912
+		update_option('timezone_string', $timezone_string);
2913
+		EE_Error::add_success(
2914
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2915
+		);
2916
+		$this->_template_args['success'] = true;
2917
+		$this->_return_json(true, ['action' => 'create_new']);
2918
+	}
2919
+
2920
+
2921
+	/**
2922
+	 * @throws EE_Error
2923
+	 * @deprecated 4.10.25.p
2924
+	 */
2925
+	public function save_timezonestring_setting()
2926
+	{
2927
+		$this->saveTimezoneString();
2928
+	}
2929 2929
 }
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3649 added lines, -3649 removed lines patch added patch discarded remove patch
@@ -19,2202 +19,2202 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
21 21
 {
22
-    /**
23
-     * @var EE_Registration
24
-     */
25
-    private $_registration;
26
-
27
-    /**
28
-     * @var EE_Event
29
-     */
30
-    private $_reg_event;
31
-
32
-    /**
33
-     * @var EE_Session
34
-     */
35
-    private $_session;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private static $_reg_status;
41
-
42
-    /**
43
-     * Form for displaying the custom questions for this registration.
44
-     * This gets used a few times throughout the request so its best to cache it
45
-     *
46
-     * @var EE_Registration_Custom_Questions_Form
47
-     */
48
-    protected $_reg_custom_questions_form;
49
-
50
-    /**
51
-     * @var EEM_Registration $registration_model
52
-     */
53
-    private $registration_model;
54
-
55
-    /**
56
-     * @var EEM_Attendee $attendee_model
57
-     */
58
-    private $attendee_model;
59
-
60
-    /**
61
-     * @var EEM_Event $event_model
62
-     */
63
-    private $event_model;
64
-
65
-    /**
66
-     * @var EEM_Status $status_model
67
-     */
68
-    private $status_model;
69
-
70
-
71
-    /**
72
-     * @param bool $routing
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws ReflectionException
78
-     */
79
-    public function __construct($routing = true)
80
-    {
81
-        parent::__construct($routing);
82
-        add_action('wp_loaded', [$this, 'wp_loaded']);
83
-    }
84
-
85
-
86
-    /**
87
-     * @return EEM_Registration
88
-     * @throws InvalidArgumentException
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @since 4.10.2.p
92
-     */
93
-    protected function getRegistrationModel()
94
-    {
95
-        if (! $this->registration_model instanceof EEM_Registration) {
96
-            $this->registration_model = $this->loader->getShared('EEM_Registration');
97
-        }
98
-        return $this->registration_model;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return EEM_Attendee
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @since 4.10.2.p
108
-     */
109
-    protected function getAttendeeModel()
110
-    {
111
-        if (! $this->attendee_model instanceof EEM_Attendee) {
112
-            $this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
-        }
114
-        return $this->attendee_model;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return EEM_Event
120
-     * @throws InvalidArgumentException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     * @since 4.10.2.p
124
-     */
125
-    protected function getEventModel()
126
-    {
127
-        if (! $this->event_model instanceof EEM_Event) {
128
-            $this->event_model = $this->loader->getShared('EEM_Event');
129
-        }
130
-        return $this->event_model;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return EEM_Status
136
-     * @throws InvalidArgumentException
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @since 4.10.2.p
140
-     */
141
-    protected function getStatusModel()
142
-    {
143
-        if (! $this->status_model instanceof EEM_Status) {
144
-            $this->status_model = $this->loader->getShared('EEM_Status');
145
-        }
146
-        return $this->status_model;
147
-    }
148
-
149
-
150
-    public function wp_loaded()
151
-    {
152
-        // when adding a new registration...
153
-        $action = $this->request->getRequestParam('action');
154
-        if ($action === 'new_registration') {
155
-            EE_System::do_not_cache();
156
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
-                // and it's NOT the attendee information reg step
158
-                // force cookie expiration by setting time to last week
159
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
-                // and update the global
161
-                $_COOKIE['ee_registration_added'] = 0;
162
-            }
163
-        }
164
-    }
165
-
166
-
167
-    protected function _init_page_props()
168
-    {
169
-        $this->page_slug        = REG_PG_SLUG;
170
-        $this->_admin_base_url  = REG_ADMIN_URL;
171
-        $this->_admin_base_path = REG_ADMIN;
172
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
173
-        $this->_cpt_routes      = [
174
-            'add_new_attendee' => 'espresso_attendees',
175
-            'edit_attendee'    => 'espresso_attendees',
176
-            'insert_attendee'  => 'espresso_attendees',
177
-            'update_attendee'  => 'espresso_attendees',
178
-        ];
179
-        $this->_cpt_model_names = [
180
-            'add_new_attendee' => 'EEM_Attendee',
181
-            'edit_attendee'    => 'EEM_Attendee',
182
-        ];
183
-        $this->_cpt_edit_routes = [
184
-            'espresso_attendees' => 'edit_attendee',
185
-        ];
186
-        $this->_pagenow_map     = [
187
-            'add_new_attendee' => 'post-new.php',
188
-            'edit_attendee'    => 'post.php',
189
-            'trash'            => 'post.php',
190
-        ];
191
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
-        // add filters so that the comment urls don't take users to a confusing 404 page
193
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
-    }
195
-
196
-
197
-    /**
198
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
199
-     * @param WP_Comment $comment The current comment object.
200
-     * @return string
201
-     */
202
-    public function clear_comment_link($link, WP_Comment $comment)
203
-    {
204
-        // gotta make sure this only happens on this route
205
-        $post_type = get_post_type($comment->comment_post_ID);
206
-        if ($post_type === 'espresso_attendees') {
207
-            return '#commentsdiv';
208
-        }
209
-        return $link;
210
-    }
211
-
212
-
213
-    protected function _ajax_hooks()
214
-    {
215
-        // todo: all hooks for registrations ajax goes in here
216
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
-    }
218
-
219
-
220
-    protected function _define_page_props()
221
-    {
222
-        $this->_admin_page_title = $this->page_label;
223
-        $this->_labels           = [
224
-            'buttons'                      => [
225
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
-            ],
234
-            'publishbox'                   => [
235
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
-            ],
238
-            'hide_add_button_on_cpt_route' => [
239
-                'edit_attendee' => true,
240
-            ],
241
-        ];
242
-    }
243
-
244
-
245
-    /**
246
-     * grab url requests and route them
247
-     *
248
-     * @return void
249
-     * @throws EE_Error
250
-     */
251
-    public function _set_page_routes()
252
-    {
253
-        $this->_get_registration_status_array();
254
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
-        $this->_page_routes = [
259
-            'default'                             => [
260
-                'func'       => '_registrations_overview_list_table',
261
-                'capability' => 'ee_read_registrations',
262
-            ],
263
-            'view_registration'                   => [
264
-                'func'       => '_registration_details',
265
-                'capability' => 'ee_read_registration',
266
-                'obj_id'     => $REG_ID,
267
-            ],
268
-            'edit_registration'                   => [
269
-                'func'               => '_update_attendee_registration_form',
270
-                'noheader'           => true,
271
-                'headers_sent_route' => 'view_registration',
272
-                'capability'         => 'ee_edit_registration',
273
-                'obj_id'             => $REG_ID,
274
-                '_REG_ID'            => $REG_ID,
275
-            ],
276
-            'trash_registrations'                 => [
277
-                'func'       => '_trash_or_restore_registrations',
278
-                'args'       => ['trash' => true],
279
-                'noheader'   => true,
280
-                'capability' => 'ee_delete_registrations',
281
-            ],
282
-            'restore_registrations'               => [
283
-                'func'       => '_trash_or_restore_registrations',
284
-                'args'       => ['trash' => false],
285
-                'noheader'   => true,
286
-                'capability' => 'ee_delete_registrations',
287
-            ],
288
-            'delete_registrations'                => [
289
-                'func'       => '_delete_registrations',
290
-                'noheader'   => true,
291
-                'capability' => 'ee_delete_registrations',
292
-            ],
293
-            'new_registration'                    => [
294
-                'func'       => 'new_registration',
295
-                'capability' => 'ee_edit_registrations',
296
-            ],
297
-            'process_reg_step'                    => [
298
-                'func'       => 'process_reg_step',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-            ],
302
-            'redirect_to_txn'                     => [
303
-                'func'       => 'redirect_to_txn',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-            ],
307
-            'change_reg_status'                   => [
308
-                'func'       => '_change_reg_status',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $REG_ID,
312
-            ],
313
-            'approve_registration'                => [
314
-                'func'       => 'approve_registration',
315
-                'noheader'   => true,
316
-                'capability' => 'ee_edit_registration',
317
-                'obj_id'     => $REG_ID,
318
-            ],
319
-            'approve_and_notify_registration'     => [
320
-                'func'       => 'approve_registration',
321
-                'noheader'   => true,
322
-                'args'       => [true],
323
-                'capability' => 'ee_edit_registration',
324
-                'obj_id'     => $REG_ID,
325
-            ],
326
-            'approve_registrations'               => [
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args'       => ['approve'],
331
-            ],
332
-            'approve_and_notify_registrations'    => [
333
-                'func'       => 'bulk_action_on_registrations',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registrations',
336
-                'args'       => ['approve', true],
337
-            ],
338
-            'decline_registration'                => [
339
-                'func'       => 'decline_registration',
340
-                'noheader'   => true,
341
-                'capability' => 'ee_edit_registration',
342
-                'obj_id'     => $REG_ID,
343
-            ],
344
-            'decline_and_notify_registration'     => [
345
-                'func'       => 'decline_registration',
346
-                'noheader'   => true,
347
-                'args'       => [true],
348
-                'capability' => 'ee_edit_registration',
349
-                'obj_id'     => $REG_ID,
350
-            ],
351
-            'decline_registrations'               => [
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args'       => ['decline'],
356
-            ],
357
-            'decline_and_notify_registrations'    => [
358
-                'func'       => 'bulk_action_on_registrations',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registrations',
361
-                'args'       => ['decline', true],
362
-            ],
363
-            'pending_registration'                => [
364
-                'func'       => 'pending_registration',
365
-                'noheader'   => true,
366
-                'capability' => 'ee_edit_registration',
367
-                'obj_id'     => $REG_ID,
368
-            ],
369
-            'pending_and_notify_registration'     => [
370
-                'func'       => 'pending_registration',
371
-                'noheader'   => true,
372
-                'args'       => [true],
373
-                'capability' => 'ee_edit_registration',
374
-                'obj_id'     => $REG_ID,
375
-            ],
376
-            'pending_registrations'               => [
377
-                'func'       => 'bulk_action_on_registrations',
378
-                'noheader'   => true,
379
-                'capability' => 'ee_edit_registrations',
380
-                'args'       => ['pending'],
381
-            ],
382
-            'pending_and_notify_registrations'    => [
383
-                'func'       => 'bulk_action_on_registrations',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_registrations',
386
-                'args'       => ['pending', true],
387
-            ],
388
-            'no_approve_registration'             => [
389
-                'func'       => 'not_approve_registration',
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_registration',
392
-                'obj_id'     => $REG_ID,
393
-            ],
394
-            'no_approve_and_notify_registration'  => [
395
-                'func'       => 'not_approve_registration',
396
-                'noheader'   => true,
397
-                'args'       => [true],
398
-                'capability' => 'ee_edit_registration',
399
-                'obj_id'     => $REG_ID,
400
-            ],
401
-            'no_approve_registrations'            => [
402
-                'func'       => 'bulk_action_on_registrations',
403
-                'noheader'   => true,
404
-                'capability' => 'ee_edit_registrations',
405
-                'args'       => ['not_approve'],
406
-            ],
407
-            'no_approve_and_notify_registrations' => [
408
-                'func'       => 'bulk_action_on_registrations',
409
-                'noheader'   => true,
410
-                'capability' => 'ee_edit_registrations',
411
-                'args'       => ['not_approve', true],
412
-            ],
413
-            'cancel_registration'                 => [
414
-                'func'       => 'cancel_registration',
415
-                'noheader'   => true,
416
-                'capability' => 'ee_edit_registration',
417
-                'obj_id'     => $REG_ID,
418
-            ],
419
-            'cancel_and_notify_registration'      => [
420
-                'func'       => 'cancel_registration',
421
-                'noheader'   => true,
422
-                'args'       => [true],
423
-                'capability' => 'ee_edit_registration',
424
-                'obj_id'     => $REG_ID,
425
-            ],
426
-            'cancel_registrations'                => [
427
-                'func'       => 'bulk_action_on_registrations',
428
-                'noheader'   => true,
429
-                'capability' => 'ee_edit_registrations',
430
-                'args'       => ['cancel'],
431
-            ],
432
-            'cancel_and_notify_registrations'     => [
433
-                'func'       => 'bulk_action_on_registrations',
434
-                'noheader'   => true,
435
-                'capability' => 'ee_edit_registrations',
436
-                'args'       => ['cancel', true],
437
-            ],
438
-            'wait_list_registration'              => [
439
-                'func'       => 'wait_list_registration',
440
-                'noheader'   => true,
441
-                'capability' => 'ee_edit_registration',
442
-                'obj_id'     => $REG_ID,
443
-            ],
444
-            'wait_list_and_notify_registration'   => [
445
-                'func'       => 'wait_list_registration',
446
-                'noheader'   => true,
447
-                'args'       => [true],
448
-                'capability' => 'ee_edit_registration',
449
-                'obj_id'     => $REG_ID,
450
-            ],
451
-            'contact_list'                        => [
452
-                'func'       => '_attendee_contact_list_table',
453
-                'capability' => 'ee_read_contacts',
454
-            ],
455
-            'add_new_attendee'                    => [
456
-                'func' => '_create_new_cpt_item',
457
-                'args' => [
458
-                    'new_attendee' => true,
459
-                    'capability'   => 'ee_edit_contacts',
460
-                ],
461
-            ],
462
-            'edit_attendee'                       => [
463
-                'func'       => '_edit_cpt_item',
464
-                'capability' => 'ee_edit_contacts',
465
-                'obj_id'     => $ATT_ID,
466
-            ],
467
-            'duplicate_attendee'                  => [
468
-                'func'       => '_duplicate_attendee',
469
-                'noheader'   => true,
470
-                'capability' => 'ee_edit_contacts',
471
-                'obj_id'     => $ATT_ID,
472
-            ],
473
-            'insert_attendee'                     => [
474
-                'func'       => '_insert_or_update_attendee',
475
-                'args'       => [
476
-                    'new_attendee' => true,
477
-                ],
478
-                'noheader'   => true,
479
-                'capability' => 'ee_edit_contacts',
480
-            ],
481
-            'update_attendee'                     => [
482
-                'func'       => '_insert_or_update_attendee',
483
-                'args'       => [
484
-                    'new_attendee' => false,
485
-                ],
486
-                'noheader'   => true,
487
-                'capability' => 'ee_edit_contacts',
488
-                'obj_id'     => $ATT_ID,
489
-            ],
490
-            'trash_attendees'                     => [
491
-                'func'       => '_trash_or_restore_attendees',
492
-                'args'       => [
493
-                    'trash' => 'true',
494
-                ],
495
-                'noheader'   => true,
496
-                'capability' => 'ee_delete_contacts',
497
-            ],
498
-            'trash_attendee'                      => [
499
-                'func'       => '_trash_or_restore_attendees',
500
-                'args'       => [
501
-                    'trash' => true,
502
-                ],
503
-                'noheader'   => true,
504
-                'capability' => 'ee_delete_contacts',
505
-                'obj_id'     => $ATT_ID,
506
-            ],
507
-            'restore_attendees'                   => [
508
-                'func'       => '_trash_or_restore_attendees',
509
-                'args'       => [
510
-                    'trash' => false,
511
-                ],
512
-                'noheader'   => true,
513
-                'capability' => 'ee_delete_contacts',
514
-                'obj_id'     => $ATT_ID,
515
-            ],
516
-            'resend_registration'                 => [
517
-                'func'       => '_resend_registration',
518
-                'noheader'   => true,
519
-                'capability' => 'ee_send_message',
520
-            ],
521
-            'registrations_report'                => [
522
-                'func'       => '_registrations_report',
523
-                'noheader'   => true,
524
-                'capability' => 'ee_read_registrations',
525
-            ],
526
-            'contact_list_export'                 => [
527
-                'func'       => '_contact_list_export',
528
-                'noheader'   => true,
529
-                'capability' => 'export',
530
-            ],
531
-            'contact_list_report'                 => [
532
-                'func'       => '_contact_list_report',
533
-                'noheader'   => true,
534
-                'capability' => 'ee_read_contacts',
535
-            ],
536
-        ];
537
-    }
538
-
539
-
540
-    protected function _set_page_config()
541
-    {
542
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
-        $this->_page_config = [
545
-            'default'           => [
546
-                'nav'           => [
547
-                    'label' => esc_html__('Overview', 'event_espresso'),
548
-                    'order' => 5,
549
-                ],
550
-                'help_tabs'     => [
551
-                    'registrations_overview_help_tab'                       => [
552
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
-                        'filename' => 'registrations_overview',
554
-                    ],
555
-                    'registrations_overview_table_column_headings_help_tab' => [
556
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
-                        'filename' => 'registrations_overview_table_column_headings',
558
-                    ],
559
-                    'registrations_overview_filters_help_tab'               => [
560
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
-                        'filename' => 'registrations_overview_filters',
562
-                    ],
563
-                    'registrations_overview_views_help_tab'                 => [
564
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
565
-                        'filename' => 'registrations_overview_views',
566
-                    ],
567
-                    'registrations_regoverview_other_help_tab'              => [
568
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
-                        'filename' => 'registrations_overview_other',
570
-                    ],
571
-                ],
572
-                'list_table'    => 'EE_Registrations_List_Table',
573
-                'require_nonce' => false,
574
-            ],
575
-            'view_registration' => [
576
-                'nav'           => [
577
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
578
-                    'order'      => 15,
579
-                    'url'        => $REG_ID
580
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
581
-                        : $this->_admin_base_url,
582
-                    'persistent' => false,
583
-                ],
584
-                'help_tabs'     => [
585
-                    'registrations_details_help_tab'                    => [
586
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
587
-                        'filename' => 'registrations_details',
588
-                    ],
589
-                    'registrations_details_table_help_tab'              => [
590
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
591
-                        'filename' => 'registrations_details_table',
592
-                    ],
593
-                    'registrations_details_form_answers_help_tab'       => [
594
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
595
-                        'filename' => 'registrations_details_form_answers',
596
-                    ],
597
-                    'registrations_details_registrant_details_help_tab' => [
598
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
599
-                        'filename' => 'registrations_details_registrant_details',
600
-                    ],
601
-                ],
602
-                'metaboxes'     => array_merge(
603
-                    $this->_default_espresso_metaboxes,
604
-                    ['_registration_details_metaboxes']
605
-                ),
606
-                'require_nonce' => false,
607
-            ],
608
-            'new_registration'  => [
609
-                'nav'           => [
610
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
611
-                    'url'        => '#',
612
-                    'order'      => 15,
613
-                    'persistent' => false,
614
-                ],
615
-                'metaboxes'     => $this->_default_espresso_metaboxes,
616
-                'labels'        => [
617
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
-                ],
619
-                'require_nonce' => false,
620
-            ],
621
-            'add_new_attendee'  => [
622
-                'nav'           => [
623
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
624
-                    'order'      => 15,
625
-                    'persistent' => false,
626
-                ],
627
-                'metaboxes'     => array_merge(
628
-                    $this->_default_espresso_metaboxes,
629
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
630
-                ),
631
-                'require_nonce' => false,
632
-            ],
633
-            'edit_attendee'     => [
634
-                'nav'           => [
635
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
-                    'order'      => 15,
637
-                    'persistent' => false,
638
-                    'url'        => $ATT_ID
639
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
640
-                        : $this->_admin_base_url,
641
-                ],
642
-                'metaboxes'     => array_merge(
643
-                    $this->_default_espresso_metaboxes,
644
-                    ['attendee_editor_metaboxes']
645
-                ),
646
-                'require_nonce' => false,
647
-            ],
648
-            'contact_list'      => [
649
-                'nav'           => [
650
-                    'label' => esc_html__('Contact List', 'event_espresso'),
651
-                    'order' => 20,
652
-                ],
653
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
654
-                'help_tabs'     => [
655
-                    'registrations_contact_list_help_tab'                       => [
656
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
657
-                        'filename' => 'registrations_contact_list',
658
-                    ],
659
-                    'registrations_contact-list_table_column_headings_help_tab' => [
660
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
661
-                        'filename' => 'registrations_contact_list_table_column_headings',
662
-                    ],
663
-                    'registrations_contact_list_views_help_tab'                 => [
664
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
665
-                        'filename' => 'registrations_contact_list_views',
666
-                    ],
667
-                    'registrations_contact_list_other_help_tab'                 => [
668
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
669
-                        'filename' => 'registrations_contact_list_other',
670
-                    ],
671
-                ],
672
-                'metaboxes'     => [],
673
-                'require_nonce' => false,
674
-            ],
675
-            // override default cpt routes
676
-            'create_new'        => '',
677
-            'edit'              => '',
678
-        ];
679
-    }
680
-
681
-
682
-    /**
683
-     * The below methods aren't used by this class currently
684
-     */
685
-    protected function _add_screen_options()
686
-    {
687
-    }
688
-
689
-
690
-    protected function _add_feature_pointers()
691
-    {
692
-    }
693
-
694
-
695
-    public function admin_init()
696
-    {
697
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
698
-            'click "Update Registration Questions" to save your changes',
699
-            'event_espresso'
700
-        );
701
-    }
702
-
703
-
704
-    public function admin_notices()
705
-    {
706
-    }
707
-
708
-
709
-    public function admin_footer_scripts()
710
-    {
711
-    }
712
-
713
-
714
-    /**
715
-     * get list of registration statuses
716
-     *
717
-     * @return void
718
-     * @throws EE_Error
719
-     */
720
-    private function _get_registration_status_array()
721
-    {
722
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
723
-    }
724
-
725
-
726
-    /**
727
-     * @throws InvalidArgumentException
728
-     * @throws InvalidDataTypeException
729
-     * @throws InvalidInterfaceException
730
-     * @since 4.10.2.p
731
-     */
732
-    protected function _add_screen_options_default()
733
-    {
734
-        $this->_per_page_screen_option();
735
-    }
736
-
737
-
738
-    /**
739
-     * @throws InvalidArgumentException
740
-     * @throws InvalidDataTypeException
741
-     * @throws InvalidInterfaceException
742
-     * @since 4.10.2.p
743
-     */
744
-    protected function _add_screen_options_contact_list()
745
-    {
746
-        $page_title              = $this->_admin_page_title;
747
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
-        $this->_per_page_screen_option();
749
-        $this->_admin_page_title = $page_title;
750
-    }
751
-
752
-
753
-    public function load_scripts_styles()
754
-    {
755
-        // style
756
-        wp_register_style(
757
-            'espresso_reg',
758
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
-            ['ee-admin-css'],
760
-            EVENT_ESPRESSO_VERSION
761
-        );
762
-        wp_enqueue_style('espresso_reg');
763
-        // script
764
-        wp_register_script(
765
-            'espresso_reg',
766
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
768
-            EVENT_ESPRESSO_VERSION,
769
-            true
770
-        );
771
-        wp_enqueue_script('espresso_reg');
772
-    }
773
-
774
-
775
-    /**
776
-     * @throws EE_Error
777
-     * @throws InvalidArgumentException
778
-     * @throws InvalidDataTypeException
779
-     * @throws InvalidInterfaceException
780
-     * @throws ReflectionException
781
-     * @since 4.10.2.p
782
-     */
783
-    public function load_scripts_styles_edit_attendee()
784
-    {
785
-        // stuff to only show up on our attendee edit details page.
786
-        $attendee_details_translations = [
787
-            'att_publish_text' => sprintf(
788
-            /* translators: The date and time */
789
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
-            ),
792
-        ];
793
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
-        wp_enqueue_script('jquery-validate');
795
-    }
796
-
797
-
798
-    /**
799
-     * @throws EE_Error
800
-     * @throws InvalidArgumentException
801
-     * @throws InvalidDataTypeException
802
-     * @throws InvalidInterfaceException
803
-     * @throws ReflectionException
804
-     * @since 4.10.2.p
805
-     */
806
-    public function load_scripts_styles_view_registration()
807
-    {
808
-        // styles
809
-        wp_enqueue_style('espresso-ui-theme');
810
-        // scripts
811
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
812
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
813
-    }
814
-
815
-
816
-    public function load_scripts_styles_contact_list()
817
-    {
818
-        wp_dequeue_style('espresso_reg');
819
-        wp_register_style(
820
-            'espresso_att',
821
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
-            ['ee-admin-css'],
823
-            EVENT_ESPRESSO_VERSION
824
-        );
825
-        wp_enqueue_style('espresso_att');
826
-    }
827
-
828
-
829
-    public function load_scripts_styles_new_registration()
830
-    {
831
-        wp_register_script(
832
-            'ee-spco-for-admin',
833
-            REG_ASSETS_URL . 'spco_for_admin.js',
834
-            ['underscore', 'jquery'],
835
-            EVENT_ESPRESSO_VERSION,
836
-            true
837
-        );
838
-        wp_enqueue_script('ee-spco-for-admin');
839
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
-        EE_Form_Section_Proper::wp_enqueue_scripts();
841
-        EED_Ticket_Selector::load_tckt_slctr_assets();
842
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
843
-    }
844
-
845
-
846
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
-    {
848
-        add_filter('FHEE_load_EE_messages', '__return_true');
849
-    }
850
-
851
-
852
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
-    {
854
-        add_filter('FHEE_load_EE_messages', '__return_true');
855
-    }
856
-
857
-
858
-    /**
859
-     * @throws EE_Error
860
-     * @throws InvalidArgumentException
861
-     * @throws InvalidDataTypeException
862
-     * @throws InvalidInterfaceException
863
-     * @throws ReflectionException
864
-     * @since 4.10.2.p
865
-     */
866
-    protected function _set_list_table_views_default()
867
-    {
868
-        // for notification related bulk actions we need to make sure only active messengers have an option.
869
-        EED_Messages::set_autoloaders();
870
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
871
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
873
-        // key= bulk_action_slug, value= message type.
874
-        $match_array = [
875
-            'approve_registrations'    => 'registration',
876
-            'decline_registrations'    => 'declined_registration',
877
-            'pending_registrations'    => 'pending_approval',
878
-            'no_approve_registrations' => 'not_approved_registration',
879
-            'cancel_registrations'     => 'cancelled_registration',
880
-        ];
881
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
882
-            'ee_send_message',
883
-            'batch_send_messages'
884
-        );
885
-        /** setup reg status bulk actions **/
886
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
-                'Approve and Notify Registrations',
890
-                'event_espresso'
891
-            );
892
-        }
893
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
-                'Decline and Notify Registrations',
897
-                'event_espresso'
898
-            );
899
-        }
900
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
901
-            'Set Registrations to Pending Payment',
902
-            'event_espresso'
903
-        );
904
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
-                'Set Registrations to Pending Payment and Notify',
907
-                'event_espresso'
908
-            );
909
-        }
910
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
-            'Set Registrations to Not Approved',
912
-            'event_espresso'
913
-        );
914
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
-                'Set Registrations to Not Approved and Notify',
917
-                'event_espresso'
918
-            );
919
-        }
920
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
-                'Cancel Registrations and Notify',
924
-                'event_espresso'
925
-            );
926
-        }
927
-        $def_reg_status_actions = apply_filters(
928
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
-            $def_reg_status_actions,
930
-            $active_mts,
931
-            $can_send
932
-        );
933
-
934
-        $this->_views = [
935
-            'all'   => [
936
-                'slug'        => 'all',
937
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
-                'count'       => 0,
939
-                'bulk_action' => array_merge(
940
-                    $def_reg_status_actions,
941
-                    [
942
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
-                    ]
944
-                ),
945
-            ],
946
-            'month' => [
947
-                'slug'        => 'month',
948
-                'label'       => esc_html__('This Month', 'event_espresso'),
949
-                'count'       => 0,
950
-                'bulk_action' => array_merge(
951
-                    $def_reg_status_actions,
952
-                    [
953
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
-                    ]
955
-                ),
956
-            ],
957
-            'today' => [
958
-                'slug'        => 'today',
959
-                'label'       => sprintf(
960
-                    esc_html__('Today - %s', 'event_espresso'),
961
-                    date('M d, Y', current_time('timestamp'))
962
-                ),
963
-                'count'       => 0,
964
-                'bulk_action' => array_merge(
965
-                    $def_reg_status_actions,
966
-                    [
967
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
-                    ]
969
-                ),
970
-            ],
971
-        ];
972
-        if (
973
-            EE_Registry::instance()->CAP->current_user_can(
974
-                'ee_delete_registrations',
975
-                'espresso_registrations_delete_registration'
976
-            )
977
-        ) {
978
-            $this->_views['incomplete'] = [
979
-                'slug'        => 'incomplete',
980
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
981
-                'count'       => 0,
982
-                'bulk_action' => [
983
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
-                ],
985
-            ];
986
-            $this->_views['trash']      = [
987
-                'slug'        => 'trash',
988
-                'label'       => esc_html__('Trash', 'event_espresso'),
989
-                'count'       => 0,
990
-                'bulk_action' => [
991
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
-                ],
994
-            ];
995
-        }
996
-    }
997
-
998
-
999
-    protected function _set_list_table_views_contact_list()
1000
-    {
1001
-        $this->_views = [
1002
-            'in_use' => [
1003
-                'slug'        => 'in_use',
1004
-                'label'       => esc_html__('In Use', 'event_espresso'),
1005
-                'count'       => 0,
1006
-                'bulk_action' => [
1007
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
-                ],
1009
-            ],
1010
-        ];
1011
-        if (
1012
-            EE_Registry::instance()->CAP->current_user_can(
1013
-                'ee_delete_contacts',
1014
-                'espresso_registrations_trash_attendees'
1015
-            )
1016
-        ) {
1017
-            $this->_views['trash'] = [
1018
-                'slug'        => 'trash',
1019
-                'label'       => esc_html__('Trash', 'event_espresso'),
1020
-                'count'       => 0,
1021
-                'bulk_action' => [
1022
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
-                ],
1024
-            ];
1025
-        }
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * @return array
1031
-     * @throws EE_Error
1032
-     */
1033
-    protected function _registration_legend_items()
1034
-    {
1035
-        $fc_items = [
1036
-            'star-icon'        => [
1037
-                'class' => 'dashicons dashicons-star-filled gold-icon',
1038
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1039
-            ],
1040
-            'view_details'     => [
1041
-                'class' => 'dashicons dashicons-clipboard',
1042
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1043
-            ],
1044
-            'edit_attendee'    => [
1045
-                'class' => 'dashicons dashicons-admin-users',
1046
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1047
-            ],
1048
-            'view_transaction' => [
1049
-                'class' => 'dashicons dashicons-cart',
1050
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1051
-            ],
1052
-            'view_invoice'     => [
1053
-                'class' => 'dashicons dashicons-media-spreadsheet',
1054
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1055
-            ],
1056
-        ];
1057
-        if (
1058
-            EE_Registry::instance()->CAP->current_user_can(
1059
-                'ee_send_message',
1060
-                'espresso_registrations_resend_registration'
1061
-            )
1062
-        ) {
1063
-            $fc_items['resend_registration'] = [
1064
-                'class' => 'dashicons dashicons-email-alt',
1065
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1066
-            ];
1067
-        } else {
1068
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1069
-        }
1070
-        if (
1071
-            EE_Registry::instance()->CAP->current_user_can(
1072
-                'ee_read_global_messages',
1073
-                'view_filtered_messages'
1074
-            )
1075
-        ) {
1076
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1077
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1078
-                $fc_items['view_related_messages'] = [
1079
-                    'class' => $related_for_icon['css_class'],
1080
-                    'desc'  => $related_for_icon['label'],
1081
-                ];
1082
-            }
1083
-        }
1084
-        $sc_items = [
1085
-            'approved_status'   => [
1086
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1087
-                'desc'  => EEH_Template::pretty_status(
1088
-                    EEM_Registration::status_id_approved,
1089
-                    false,
1090
-                    'sentence'
1091
-                ),
1092
-            ],
1093
-            'pending_status'    => [
1094
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1095
-                'desc'  => EEH_Template::pretty_status(
1096
-                    EEM_Registration::status_id_pending_payment,
1097
-                    false,
1098
-                    'sentence'
1099
-                ),
1100
-            ],
1101
-            'wait_list'         => [
1102
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1103
-                'desc'  => EEH_Template::pretty_status(
1104
-                    EEM_Registration::status_id_wait_list,
1105
-                    false,
1106
-                    'sentence'
1107
-                ),
1108
-            ],
1109
-            'incomplete_status' => [
1110
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1111
-                'desc'  => EEH_Template::pretty_status(
1112
-                    EEM_Registration::status_id_incomplete,
1113
-                    false,
1114
-                    'sentence'
1115
-                ),
1116
-            ],
1117
-            'not_approved'      => [
1118
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1119
-                'desc'  => EEH_Template::pretty_status(
1120
-                    EEM_Registration::status_id_not_approved,
1121
-                    false,
1122
-                    'sentence'
1123
-                ),
1124
-            ],
1125
-            'declined_status'   => [
1126
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1127
-                'desc'  => EEH_Template::pretty_status(
1128
-                    EEM_Registration::status_id_declined,
1129
-                    false,
1130
-                    'sentence'
1131
-                ),
1132
-            ],
1133
-            'cancelled_status'  => [
1134
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1135
-                'desc'  => EEH_Template::pretty_status(
1136
-                    EEM_Registration::status_id_cancelled,
1137
-                    false,
1138
-                    'sentence'
1139
-                ),
1140
-            ],
1141
-        ];
1142
-        return array_merge($fc_items, $sc_items);
1143
-    }
1144
-
1145
-
1146
-
1147
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1148
-
1149
-
1150
-    /**
1151
-     * @throws DomainException
1152
-     * @throws EE_Error
1153
-     * @throws InvalidArgumentException
1154
-     * @throws InvalidDataTypeException
1155
-     * @throws InvalidInterfaceException
1156
-     */
1157
-    protected function _registrations_overview_list_table()
1158
-    {
1159
-        $this->appendAddNewRegistrationButtonToPageTitle();
1160
-        $header_text                  = '';
1161
-        $admin_page_header_decorators = [
1162
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1164
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1165
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1166
-        ];
1167
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1168
-            $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1169
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1170
-        }
1171
-        $this->_template_args['admin_page_header'] = $header_text;
1172
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1173
-        $this->display_admin_list_table_page_with_no_sidebar();
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * @throws EE_Error
1179
-     * @throws InvalidArgumentException
1180
-     * @throws InvalidDataTypeException
1181
-     * @throws InvalidInterfaceException
1182
-     */
1183
-    private function appendAddNewRegistrationButtonToPageTitle()
1184
-    {
1185
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1186
-        if (
1187
-            $EVT_ID
1188
-            && EE_Registry::instance()->CAP->current_user_can(
1189
-                'ee_edit_registrations',
1190
-                'espresso_registrations_new_registration',
1191
-                $EVT_ID
1192
-            )
1193
-        ) {
1194
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
-                'new_registration',
1196
-                'add-registrant',
1197
-                ['event_id' => $EVT_ID],
1198
-                'add-new-h2'
1199
-            );
1200
-        }
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * This sets the _registration property for the registration details screen
1206
-     *
1207
-     * @return void
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws InvalidDataTypeException
1211
-     * @throws InvalidInterfaceException
1212
-     */
1213
-    private function _set_registration_object()
1214
-    {
1215
-        // get out if we've already set the object
1216
-        if ($this->_registration instanceof EE_Registration) {
1217
-            return;
1218
-        }
1219
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1220
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1221
-            return;
1222
-        }
1223
-        $error_msg = sprintf(
1224
-            esc_html__(
1225
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1226
-                'event_espresso'
1227
-            ),
1228
-            $REG_ID
1229
-        );
1230
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1231
-        $this->_registration = null;
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * Used to retrieve registrations for the list table.
1237
-     *
1238
-     * @param int  $per_page
1239
-     * @param bool $count
1240
-     * @param bool $this_month
1241
-     * @param bool $today
1242
-     * @return EE_Registration[]|int
1243
-     * @throws EE_Error
1244
-     * @throws InvalidArgumentException
1245
-     * @throws InvalidDataTypeException
1246
-     * @throws InvalidInterfaceException
1247
-     */
1248
-    public function get_registrations(
1249
-        $per_page = 10,
1250
-        $count = false,
1251
-        $this_month = false,
1252
-        $today = false
1253
-    ) {
1254
-        if ($this_month) {
1255
-            $this->request->setRequestParam('status', 'month');
1256
-        }
1257
-        if ($today) {
1258
-            $this->request->setRequestParam('status', 'today');
1259
-        }
1260
-        $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1261
-        /**
1262
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
-         *
1264
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1265
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1266
-         *                      or if you have the development copy of EE you can view this at the path:
1267
-         *                      /docs/G--Model-System/model-query-params.md
1268
-         */
1269
-        $query_params['group_by'] = '';
1270
-
1271
-        return $count
1272
-            ? $this->getRegistrationModel()->count($query_params)
1273
-            /** @type EE_Registration[] */
1274
-            : $this->getRegistrationModel()->get_all($query_params);
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1280
-     * Note: this listens to values on the request for some of the query parameters.
1281
-     *
1282
-     * @param array $request
1283
-     * @param int   $per_page
1284
-     * @param bool  $count
1285
-     * @return array
1286
-     * @throws EE_Error
1287
-     * @throws InvalidArgumentException
1288
-     * @throws InvalidDataTypeException
1289
-     * @throws InvalidInterfaceException
1290
-     */
1291
-    protected function _get_registration_query_parameters(
1292
-        $request = [],
1293
-        $per_page = 10,
1294
-        $count = false
1295
-    ) {
1296
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1297
-        $list_table_query_builder = $this->loader->getNew(
1298
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1299
-            [null, null, $request]
1300
-        );
1301
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1302
-    }
1303
-
1304
-
1305
-    public function get_registration_status_array()
1306
-    {
1307
-        return self::$_reg_status;
1308
-    }
1309
-
1310
-
1311
-
1312
-
1313
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1314
-    /**
1315
-     * generates HTML for the View Registration Details Admin page
1316
-     *
1317
-     * @return void
1318
-     * @throws DomainException
1319
-     * @throws EE_Error
1320
-     * @throws InvalidArgumentException
1321
-     * @throws InvalidDataTypeException
1322
-     * @throws InvalidInterfaceException
1323
-     * @throws EntityNotFoundException
1324
-     * @throws ReflectionException
1325
-     */
1326
-    protected function _registration_details()
1327
-    {
1328
-        $this->_template_args = [];
1329
-        $this->_set_registration_object();
1330
-        if (is_object($this->_registration)) {
1331
-            $transaction                                   = $this->_registration->transaction()
1332
-                ? $this->_registration->transaction()
1333
-                : EE_Transaction::new_instance();
1334
-            $this->_session                                = $transaction->session_data();
1335
-            $event_id                                      = $this->_registration->event_ID();
1336
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1337
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1338
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1339
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1340
-            $this->_template_args['grand_total']           = $transaction->total();
1341
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1342
-            // link back to overview
1343
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1344
-            $this->_template_args['registration']                = $this->_registration;
1345
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1346
-                [
1347
-                    'action'   => 'default',
1348
-                    'event_id' => $event_id,
1349
-                ],
1350
-                REG_ADMIN_URL
1351
-            );
1352
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1353
-                [
1354
-                    'action' => 'default',
1355
-                    'EVT_ID' => $event_id,
1356
-                    'page'   => 'espresso_transactions',
1357
-                ],
1358
-                admin_url('admin.php')
1359
-            );
1360
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1361
-                [
1362
-                    'page'   => 'espresso_events',
1363
-                    'action' => 'edit',
1364
-                    'post'   => $event_id,
1365
-                ],
1366
-                admin_url('admin.php')
1367
-            );
1368
-            // next and previous links
1369
-            $next_reg                                      = $this->_registration->next(
1370
-                null,
1371
-                [],
1372
-                'REG_ID'
1373
-            );
1374
-            $this->_template_args['next_registration']     = $next_reg
1375
-                ? $this->_next_link(
1376
-                    EE_Admin_Page::add_query_args_and_nonce(
1377
-                        [
1378
-                            'action'  => 'view_registration',
1379
-                            '_REG_ID' => $next_reg['REG_ID'],
1380
-                        ],
1381
-                        REG_ADMIN_URL
1382
-                    ),
1383
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1384
-                )
1385
-                : '';
1386
-            $previous_reg                                  = $this->_registration->previous(
1387
-                null,
1388
-                [],
1389
-                'REG_ID'
1390
-            );
1391
-            $this->_template_args['previous_registration'] = $previous_reg
1392
-                ? $this->_previous_link(
1393
-                    EE_Admin_Page::add_query_args_and_nonce(
1394
-                        [
1395
-                            'action'  => 'view_registration',
1396
-                            '_REG_ID' => $previous_reg['REG_ID'],
1397
-                        ],
1398
-                        REG_ADMIN_URL
1399
-                    ),
1400
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1401
-                )
1402
-                : '';
1403
-            // grab header
1404
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1405
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1406
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1407
-                $template_path,
1408
-                $this->_template_args,
1409
-                true
1410
-            );
1411
-        } else {
1412
-            $this->_template_args['admin_page_header'] = '';
1413
-            $this->_display_espresso_notices();
1414
-        }
1415
-        // the details template wrapper
1416
-        $this->display_admin_page_with_sidebar();
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     * @throws EE_Error
1422
-     * @throws InvalidArgumentException
1423
-     * @throws InvalidDataTypeException
1424
-     * @throws InvalidInterfaceException
1425
-     * @throws ReflectionException
1426
-     * @since 4.10.2.p
1427
-     */
1428
-    protected function _registration_details_metaboxes()
1429
-    {
1430
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1431
-        $this->_set_registration_object();
1432
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1433
-        $this->addMetaBox(
1434
-            'edit-reg-status-mbox',
1435
-            esc_html__('Registration Status', 'event_espresso'),
1436
-            [$this, 'set_reg_status_buttons_metabox'],
1437
-            $this->_wp_page_slug
1438
-        );
1439
-        $this->addMetaBox(
1440
-            'edit-reg-details-mbox',
1441
-            '<span>' . esc_html__('Registration Details', 'event_espresso')
1442
-            . '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1443
-            [$this, '_reg_details_meta_box'],
1444
-            $this->_wp_page_slug
1445
-        );
1446
-        if (
1447
-            $attendee instanceof EE_Attendee
1448
-            && EE_Registry::instance()->CAP->current_user_can(
1449
-                'ee_read_registration',
1450
-                'edit-reg-questions-mbox',
1451
-                $this->_registration->ID()
1452
-            )
1453
-        ) {
1454
-            $this->addMetaBox(
1455
-                'edit-reg-questions-mbox',
1456
-                esc_html__('Registration Form Answers', 'event_espresso'),
1457
-                [$this, '_reg_questions_meta_box'],
1458
-                $this->_wp_page_slug
1459
-            );
1460
-        }
1461
-        $this->addMetaBox(
1462
-            'edit-reg-registrant-mbox',
1463
-            esc_html__('Contact Details', 'event_espresso'),
1464
-            [$this, '_reg_registrant_side_meta_box'],
1465
-            $this->_wp_page_slug,
1466
-            'side'
1467
-        );
1468
-        if ($this->_registration->group_size() > 1) {
1469
-            $this->addMetaBox(
1470
-                'edit-reg-attendees-mbox',
1471
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1472
-                [$this, '_reg_attendees_meta_box'],
1473
-                $this->_wp_page_slug
1474
-            );
1475
-        }
1476
-    }
1477
-
1478
-
1479
-    /**
1480
-     * set_reg_status_buttons_metabox
1481
-     *
1482
-     * @return void
1483
-     * @throws EE_Error
1484
-     * @throws EntityNotFoundException
1485
-     * @throws InvalidArgumentException
1486
-     * @throws InvalidDataTypeException
1487
-     * @throws InvalidInterfaceException
1488
-     * @throws ReflectionException
1489
-     */
1490
-    public function set_reg_status_buttons_metabox()
1491
-    {
1492
-        $this->_set_registration_object();
1493
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1494
-        $output                 = $change_reg_status_form->form_open(
1495
-            self::add_query_args_and_nonce(
1496
-                [
1497
-                    'action' => 'change_reg_status',
1498
-                ],
1499
-                REG_ADMIN_URL
1500
-            )
1501
-        );
1502
-        $output                 .= $change_reg_status_form->get_html();
1503
-        $output                 .= $change_reg_status_form->form_close();
1504
-        echo wp_kses($output, AllowedTags::getWithFormTags());
1505
-    }
1506
-
1507
-
1508
-    /**
1509
-     * @return EE_Form_Section_Proper
1510
-     * @throws EE_Error
1511
-     * @throws InvalidArgumentException
1512
-     * @throws InvalidDataTypeException
1513
-     * @throws InvalidInterfaceException
1514
-     * @throws EntityNotFoundException
1515
-     * @throws ReflectionException
1516
-     */
1517
-    protected function _generate_reg_status_change_form()
1518
-    {
1519
-        $reg_status_change_form_array = [
1520
-            'name'            => 'reg_status_change_form',
1521
-            'html_id'         => 'reg-status-change-form',
1522
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1523
-            'subsections'     => [
1524
-                'return'         => new EE_Hidden_Input(
1525
-                    [
1526
-                        'name'    => 'return',
1527
-                        'default' => 'view_registration',
1528
-                    ]
1529
-                ),
1530
-                'REG_ID'         => new EE_Hidden_Input(
1531
-                    [
1532
-                        'name'    => 'REG_ID',
1533
-                        'default' => $this->_registration->ID(),
1534
-                    ]
1535
-                ),
1536
-            ],
1537
-        ];
1538
-        if (
1539
-            EE_Registry::instance()->CAP->current_user_can(
1540
-                'ee_edit_registration',
1541
-                'toggle_registration_status',
1542
-                $this->_registration->ID()
1543
-            )
1544
-        ) {
1545
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1546
-                $this->_get_reg_statuses(),
1547
-                [
1548
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1549
-                    'default'         => $this->_registration->status_ID(),
1550
-                ]
1551
-            );
1552
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1553
-                [
1554
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1555
-                    'default'         => false,
1556
-                    'html_help_text'  => esc_html__(
1557
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1558
-                        'event_espresso'
1559
-                    ),
1560
-                ]
1561
-            );
1562
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1563
-                [
1564
-                    'html_class'      => 'button--primary',
1565
-                    'html_label_text' => '&nbsp;',
1566
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1567
-                ]
1568
-            );
1569
-        }
1570
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1571
-    }
1572
-
1573
-
1574
-    /**
1575
-     * Returns an array of all the buttons for the various statuses and switch status actions
1576
-     *
1577
-     * @return array
1578
-     * @throws EE_Error
1579
-     * @throws InvalidArgumentException
1580
-     * @throws InvalidDataTypeException
1581
-     * @throws InvalidInterfaceException
1582
-     * @throws EntityNotFoundException
1583
-     */
1584
-    protected function _get_reg_statuses()
1585
-    {
1586
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1587
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1588
-        // get current reg status
1589
-        $current_status = $this->_registration->status_ID();
1590
-        // is registration for free event? This will determine whether to display the pending payment option
1591
-        if (
1592
-            $current_status !== EEM_Registration::status_id_pending_payment
1593
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1594
-        ) {
1595
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1596
-        }
1597
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1603
-     *
1604
-     * @param bool $status REG status given for changing registrations to.
1605
-     * @param bool $notify Whether to send messages notifications or not.
1606
-     * @return array (array with reg_id(s) updated and whether update was successful.
1607
-     * @throws DomainException
1608
-     * @throws EE_Error
1609
-     * @throws EntityNotFoundException
1610
-     * @throws InvalidArgumentException
1611
-     * @throws InvalidDataTypeException
1612
-     * @throws InvalidInterfaceException
1613
-     * @throws ReflectionException
1614
-     * @throws RuntimeException
1615
-     */
1616
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1617
-    {
1618
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1619
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1620
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1621
-
1622
-        // sanitize $REG_IDs
1623
-        $REG_IDs = array_map('absint', $REG_IDs);
1624
-        // and remove empty entries
1625
-        $REG_IDs = array_filter($REG_IDs);
1626
-
1627
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1628
-
1629
-        /**
1630
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1631
-         * Currently this value is used downstream by the _process_resend_registration method.
1632
-         *
1633
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1634
-         * @param bool                     $status           The status registrations were changed to.
1635
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1636
-         * @param Registrations_Admin_Page $admin_page_object
1637
-         */
1638
-        $REG_ID = apply_filters(
1639
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1640
-            $result['REG_ID'],
1641
-            $status,
1642
-            $result['success'],
1643
-            $this
1644
-        );
1645
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1646
-
1647
-        // notify?
1648
-        if (
1649
-            $notify
1650
-            && $result['success']
1651
-            && ! empty($REG_ID)
1652
-            && EE_Registry::instance()->CAP->current_user_can(
1653
-                'ee_send_message',
1654
-                'espresso_registrations_resend_registration'
1655
-            )
1656
-        ) {
1657
-            $this->_process_resend_registration();
1658
-        }
1659
-        return $result;
1660
-    }
1661
-
1662
-
1663
-    /**
1664
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1665
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1666
-     *
1667
-     * @param array  $REG_IDs
1668
-     * @param string $status
1669
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1670
-     *                       slug sent with setting the registration status.
1671
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1672
-     * @throws EE_Error
1673
-     * @throws InvalidArgumentException
1674
-     * @throws InvalidDataTypeException
1675
-     * @throws InvalidInterfaceException
1676
-     * @throws ReflectionException
1677
-     * @throws RuntimeException
1678
-     * @throws EntityNotFoundException
1679
-     * @throws DomainException
1680
-     */
1681
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1682
-    {
1683
-        $success = false;
1684
-        // typecast $REG_IDs
1685
-        $REG_IDs = (array) $REG_IDs;
1686
-        if (! empty($REG_IDs)) {
1687
-            $success = true;
1688
-            // set default status if none is passed
1689
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1690
-            $status_context = $notify
1691
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1692
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1693
-            // loop through REG_ID's and change status
1694
-            foreach ($REG_IDs as $REG_ID) {
1695
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1696
-                if ($registration instanceof EE_Registration) {
1697
-                    $registration->set_status(
1698
-                        $status,
1699
-                        false,
1700
-                        new Context(
1701
-                            $status_context,
1702
-                            esc_html__(
1703
-                                'Manually triggered status change on a Registration Admin Page route.',
1704
-                                'event_espresso'
1705
-                            )
1706
-                        )
1707
-                    );
1708
-                    $result = $registration->save();
1709
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1710
-                    $success = $result !== false ? $success : false;
1711
-                }
1712
-            }
1713
-        }
1714
-
1715
-        // return $success and processed registrations
1716
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1717
-    }
1718
-
1719
-
1720
-    /**
1721
-     * Common logic for setting up success message and redirecting to appropriate route
1722
-     *
1723
-     * @param string $STS_ID status id for the registration changed to
1724
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1725
-     * @return void
1726
-     * @throws DomainException
1727
-     * @throws EE_Error
1728
-     * @throws EntityNotFoundException
1729
-     * @throws InvalidArgumentException
1730
-     * @throws InvalidDataTypeException
1731
-     * @throws InvalidInterfaceException
1732
-     * @throws ReflectionException
1733
-     * @throws RuntimeException
1734
-     */
1735
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1736
-    {
1737
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1738
-            : ['success' => false];
1739
-        $success = isset($result['success']) && $result['success'];
1740
-        // setup success message
1741
-        if ($success) {
1742
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1743
-                $msg = sprintf(
1744
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1745
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1746
-                );
1747
-            } else {
1748
-                $msg = sprintf(
1749
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1750
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1751
-                );
1752
-            }
1753
-            EE_Error::add_success($msg);
1754
-        } else {
1755
-            EE_Error::add_error(
1756
-                esc_html__(
1757
-                    'Something went wrong, and the status was not changed',
1758
-                    'event_espresso'
1759
-                ),
1760
-                __FILE__,
1761
-                __LINE__,
1762
-                __FUNCTION__
1763
-            );
1764
-        }
1765
-        $return = $this->request->getRequestParam('return');
1766
-        $route  = $return === 'view_registration'
1767
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1768
-            : ['action' => 'default'];
1769
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1770
-        $this->_redirect_after_action($success, '', '', $route, true);
1771
-    }
1772
-
1773
-
1774
-    /**
1775
-     * incoming reg status change from reg details page.
1776
-     *
1777
-     * @return void
1778
-     * @throws EE_Error
1779
-     * @throws EntityNotFoundException
1780
-     * @throws InvalidArgumentException
1781
-     * @throws InvalidDataTypeException
1782
-     * @throws InvalidInterfaceException
1783
-     * @throws ReflectionException
1784
-     * @throws RuntimeException
1785
-     * @throws DomainException
1786
-     */
1787
-    protected function _change_reg_status()
1788
-    {
1789
-        $this->request->setRequestParam('return', 'view_registration');
1790
-        // set notify based on whether the send notifications toggle is set or not
1791
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1792
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1793
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1794
-        switch ($reg_status) {
1795
-            case EEM_Registration::status_id_approved:
1796
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1797
-                $this->approve_registration($notify);
1798
-                break;
1799
-            case EEM_Registration::status_id_pending_payment:
1800
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1801
-                $this->pending_registration($notify);
1802
-                break;
1803
-            case EEM_Registration::status_id_not_approved:
1804
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1805
-                $this->not_approve_registration($notify);
1806
-                break;
1807
-            case EEM_Registration::status_id_declined:
1808
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1809
-                $this->decline_registration($notify);
1810
-                break;
1811
-            case EEM_Registration::status_id_cancelled:
1812
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1813
-                $this->cancel_registration($notify);
1814
-                break;
1815
-            case EEM_Registration::status_id_wait_list:
1816
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1817
-                $this->wait_list_registration($notify);
1818
-                break;
1819
-            case EEM_Registration::status_id_incomplete:
1820
-            default:
1821
-                $this->request->unSetRequestParam('return');
1822
-                $this->_reg_status_change_return('');
1823
-                break;
1824
-        }
1825
-    }
1826
-
1827
-
1828
-    /**
1829
-     * Callback for bulk action routes.
1830
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1831
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1832
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1833
-     * when an action is happening on just a single registration).
1834
-     *
1835
-     * @param      $action
1836
-     * @param bool $notify
1837
-     */
1838
-    protected function bulk_action_on_registrations($action, $notify = false)
1839
-    {
1840
-        do_action(
1841
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1842
-            $this,
1843
-            $action,
1844
-            $notify
1845
-        );
1846
-        $method = $action . '_registration';
1847
-        if (method_exists($this, $method)) {
1848
-            $this->$method($notify);
1849
-        }
1850
-    }
1851
-
1852
-
1853
-    /**
1854
-     * approve_registration
1855
-     *
1856
-     * @param bool $notify whether or not to notify the registrant about their approval.
1857
-     * @return void
1858
-     * @throws EE_Error
1859
-     * @throws EntityNotFoundException
1860
-     * @throws InvalidArgumentException
1861
-     * @throws InvalidDataTypeException
1862
-     * @throws InvalidInterfaceException
1863
-     * @throws ReflectionException
1864
-     * @throws RuntimeException
1865
-     * @throws DomainException
1866
-     */
1867
-    protected function approve_registration($notify = false)
1868
-    {
1869
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1870
-    }
1871
-
1872
-
1873
-    /**
1874
-     * decline_registration
1875
-     *
1876
-     * @param bool $notify whether or not to notify the registrant about their status change.
1877
-     * @return void
1878
-     * @throws EE_Error
1879
-     * @throws EntityNotFoundException
1880
-     * @throws InvalidArgumentException
1881
-     * @throws InvalidDataTypeException
1882
-     * @throws InvalidInterfaceException
1883
-     * @throws ReflectionException
1884
-     * @throws RuntimeException
1885
-     * @throws DomainException
1886
-     */
1887
-    protected function decline_registration($notify = false)
1888
-    {
1889
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1890
-    }
1891
-
1892
-
1893
-    /**
1894
-     * cancel_registration
1895
-     *
1896
-     * @param bool $notify whether or not to notify the registrant about their status change.
1897
-     * @return void
1898
-     * @throws EE_Error
1899
-     * @throws EntityNotFoundException
1900
-     * @throws InvalidArgumentException
1901
-     * @throws InvalidDataTypeException
1902
-     * @throws InvalidInterfaceException
1903
-     * @throws ReflectionException
1904
-     * @throws RuntimeException
1905
-     * @throws DomainException
1906
-     */
1907
-    protected function cancel_registration($notify = false)
1908
-    {
1909
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1910
-    }
1911
-
1912
-
1913
-    /**
1914
-     * not_approve_registration
1915
-     *
1916
-     * @param bool $notify whether or not to notify the registrant about their status change.
1917
-     * @return void
1918
-     * @throws EE_Error
1919
-     * @throws EntityNotFoundException
1920
-     * @throws InvalidArgumentException
1921
-     * @throws InvalidDataTypeException
1922
-     * @throws InvalidInterfaceException
1923
-     * @throws ReflectionException
1924
-     * @throws RuntimeException
1925
-     * @throws DomainException
1926
-     */
1927
-    protected function not_approve_registration($notify = false)
1928
-    {
1929
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1930
-    }
1931
-
1932
-
1933
-    /**
1934
-     * decline_registration
1935
-     *
1936
-     * @param bool $notify whether or not to notify the registrant about their status change.
1937
-     * @return void
1938
-     * @throws EE_Error
1939
-     * @throws EntityNotFoundException
1940
-     * @throws InvalidArgumentException
1941
-     * @throws InvalidDataTypeException
1942
-     * @throws InvalidInterfaceException
1943
-     * @throws ReflectionException
1944
-     * @throws RuntimeException
1945
-     * @throws DomainException
1946
-     */
1947
-    protected function pending_registration($notify = false)
1948
-    {
1949
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1950
-    }
1951
-
1952
-
1953
-    /**
1954
-     * waitlist_registration
1955
-     *
1956
-     * @param bool $notify whether or not to notify the registrant about their status change.
1957
-     * @return void
1958
-     * @throws EE_Error
1959
-     * @throws EntityNotFoundException
1960
-     * @throws InvalidArgumentException
1961
-     * @throws InvalidDataTypeException
1962
-     * @throws InvalidInterfaceException
1963
-     * @throws ReflectionException
1964
-     * @throws RuntimeException
1965
-     * @throws DomainException
1966
-     */
1967
-    protected function wait_list_registration($notify = false)
1968
-    {
1969
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1970
-    }
1971
-
1972
-
1973
-    /**
1974
-     * generates HTML for the Registration main meta box
1975
-     *
1976
-     * @return void
1977
-     * @throws DomainException
1978
-     * @throws EE_Error
1979
-     * @throws InvalidArgumentException
1980
-     * @throws InvalidDataTypeException
1981
-     * @throws InvalidInterfaceException
1982
-     * @throws ReflectionException
1983
-     * @throws EntityNotFoundException
1984
-     */
1985
-    public function _reg_details_meta_box()
1986
-    {
1987
-        EEH_Autoloader::register_line_item_display_autoloaders();
1988
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1989
-        EE_Registry::instance()->load_helper('Line_Item');
1990
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1991
-            : EE_Transaction::new_instance();
1992
-        $this->_session = $transaction->session_data();
1993
-        $filters        = new EE_Line_Item_Filter_Collection();
1994
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1995
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
1996
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
1997
-            $filters,
1998
-            $transaction->total_line_item()
1999
-        );
2000
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2001
-        $line_item_display                       = new EE_Line_Item_Display(
2002
-            'reg_admin_table',
2003
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2004
-        );
2005
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2006
-            $filtered_line_item_tree,
2007
-            ['EE_Registration' => $this->_registration]
2008
-        );
2009
-        $attendee                                = $this->_registration->attendee();
2010
-        if (
2011
-            EE_Registry::instance()->CAP->current_user_can(
2012
-                'ee_read_transaction',
2013
-                'espresso_transactions_view_transaction'
2014
-            )
2015
-        ) {
2016
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2017
-                EE_Admin_Page::add_query_args_and_nonce(
2018
-                    [
2019
-                        'action' => 'view_transaction',
2020
-                        'TXN_ID' => $transaction->ID(),
2021
-                    ],
2022
-                    TXN_ADMIN_URL
2023
-                ),
2024
-                esc_html__(' View Transaction', 'event_espresso'),
2025
-                'button button--secondary right',
2026
-                'dashicons dashicons-cart'
2027
-            );
2028
-        } else {
2029
-            $this->_template_args['view_transaction_button'] = '';
2030
-        }
2031
-        if (
2032
-            $attendee instanceof EE_Attendee
2033
-            && EE_Registry::instance()->CAP->current_user_can(
2034
-                'ee_send_message',
2035
-                'espresso_registrations_resend_registration'
2036
-            )
2037
-        ) {
2038
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2039
-                EE_Admin_Page::add_query_args_and_nonce(
2040
-                    [
2041
-                        'action'      => 'resend_registration',
2042
-                        '_REG_ID'     => $this->_registration->ID(),
2043
-                        'redirect_to' => 'view_registration',
2044
-                    ],
2045
-                    REG_ADMIN_URL
2046
-                ),
2047
-                esc_html__(' Resend Registration', 'event_espresso'),
2048
-                'button button--secondary right',
2049
-                'dashicons dashicons-email-alt'
2050
-            );
2051
-        } else {
2052
-            $this->_template_args['resend_registration_button'] = '';
2053
-        }
2054
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2055
-        $payment                               = $transaction->get_first_related('Payment');
2056
-        $payment                               = ! $payment instanceof EE_Payment
2057
-            ? EE_Payment::new_instance()
2058
-            : $payment;
2059
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2060
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2061
-            ? EE_Payment_Method::new_instance()
2062
-            : $payment_method;
2063
-        $reg_details                           = [
2064
-            'payment_method'       => $payment_method->name(),
2065
-            'response_msg'         => $payment->gateway_response(),
2066
-            'registration_id'      => $this->_registration->get('REG_code'),
2067
-            'registration_session' => $this->_registration->session_ID(),
2068
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2069
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2070
-        ];
2071
-        if (isset($reg_details['registration_id'])) {
2072
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2073
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2074
-                'Registration ID',
2075
-                'event_espresso'
2076
-            );
2077
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2078
-        }
2079
-        if (isset($reg_details['payment_method'])) {
2080
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2081
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2082
-                'Most Recent Payment Method',
2083
-                'event_espresso'
2084
-            );
2085
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2086
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2087
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2088
-                'Payment method response',
2089
-                'event_espresso'
2090
-            );
2091
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2092
-        }
2093
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2094
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2095
-            'Registration Session',
2096
-            'event_espresso'
2097
-        );
2098
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2099
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2100
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2101
-            'Registration placed from IP',
2102
-            'event_espresso'
2103
-        );
2104
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2105
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2106
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2107
-            'Registrant User Agent',
2108
-            'event_espresso'
2109
-        );
2110
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2111
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2112
-            [
2113
-                'action'   => 'default',
2114
-                'event_id' => $this->_registration->event_ID(),
2115
-            ],
2116
-            REG_ADMIN_URL
2117
-        );
2118
-
2119
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2120
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2121
-
2122
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2123
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2124
-    }
2125
-
2126
-
2127
-    /**
2128
-     * generates HTML for the Registration Questions meta box.
2129
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2130
-     * otherwise uses new forms system
2131
-     *
2132
-     * @return void
2133
-     * @throws DomainException
2134
-     * @throws EE_Error
2135
-     * @throws InvalidArgumentException
2136
-     * @throws InvalidDataTypeException
2137
-     * @throws InvalidInterfaceException
2138
-     * @throws ReflectionException
2139
-     */
2140
-    public function _reg_questions_meta_box()
2141
-    {
2142
-        // allow someone to override this method entirely
2143
-        if (
2144
-            apply_filters(
2145
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2146
-                true,
2147
-                $this,
2148
-                $this->_registration
2149
-            )
2150
-        ) {
2151
-            $form = $this->_get_reg_custom_questions_form(
2152
-                $this->_registration->ID()
2153
-            );
2154
-
2155
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2156
-                ? $form->get_html_and_js()
2157
-                : '';
2158
-
2159
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2160
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2161
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2162
-            EEH_Template::display_template($template_path, $this->_template_args);
2163
-        }
2164
-    }
2165
-
2166
-
2167
-    /**
2168
-     * form_before_question_group
2169
-     *
2170
-     * @param string $output
2171
-     * @return        string
2172
-     * @deprecated    as of 4.8.32.rc.000
2173
-     */
2174
-    public function form_before_question_group($output)
2175
-    {
2176
-        EE_Error::doing_it_wrong(
2177
-            __CLASS__ . '::' . __FUNCTION__,
2178
-            esc_html__(
2179
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2180
-                'event_espresso'
2181
-            ),
2182
-            '4.8.32.rc.000'
2183
-        );
2184
-        return '
22
+	/**
23
+	 * @var EE_Registration
24
+	 */
25
+	private $_registration;
26
+
27
+	/**
28
+	 * @var EE_Event
29
+	 */
30
+	private $_reg_event;
31
+
32
+	/**
33
+	 * @var EE_Session
34
+	 */
35
+	private $_session;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private static $_reg_status;
41
+
42
+	/**
43
+	 * Form for displaying the custom questions for this registration.
44
+	 * This gets used a few times throughout the request so its best to cache it
45
+	 *
46
+	 * @var EE_Registration_Custom_Questions_Form
47
+	 */
48
+	protected $_reg_custom_questions_form;
49
+
50
+	/**
51
+	 * @var EEM_Registration $registration_model
52
+	 */
53
+	private $registration_model;
54
+
55
+	/**
56
+	 * @var EEM_Attendee $attendee_model
57
+	 */
58
+	private $attendee_model;
59
+
60
+	/**
61
+	 * @var EEM_Event $event_model
62
+	 */
63
+	private $event_model;
64
+
65
+	/**
66
+	 * @var EEM_Status $status_model
67
+	 */
68
+	private $status_model;
69
+
70
+
71
+	/**
72
+	 * @param bool $routing
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws ReflectionException
78
+	 */
79
+	public function __construct($routing = true)
80
+	{
81
+		parent::__construct($routing);
82
+		add_action('wp_loaded', [$this, 'wp_loaded']);
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return EEM_Registration
88
+	 * @throws InvalidArgumentException
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @since 4.10.2.p
92
+	 */
93
+	protected function getRegistrationModel()
94
+	{
95
+		if (! $this->registration_model instanceof EEM_Registration) {
96
+			$this->registration_model = $this->loader->getShared('EEM_Registration');
97
+		}
98
+		return $this->registration_model;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return EEM_Attendee
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @since 4.10.2.p
108
+	 */
109
+	protected function getAttendeeModel()
110
+	{
111
+		if (! $this->attendee_model instanceof EEM_Attendee) {
112
+			$this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
+		}
114
+		return $this->attendee_model;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return EEM_Event
120
+	 * @throws InvalidArgumentException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 * @since 4.10.2.p
124
+	 */
125
+	protected function getEventModel()
126
+	{
127
+		if (! $this->event_model instanceof EEM_Event) {
128
+			$this->event_model = $this->loader->getShared('EEM_Event');
129
+		}
130
+		return $this->event_model;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return EEM_Status
136
+	 * @throws InvalidArgumentException
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @since 4.10.2.p
140
+	 */
141
+	protected function getStatusModel()
142
+	{
143
+		if (! $this->status_model instanceof EEM_Status) {
144
+			$this->status_model = $this->loader->getShared('EEM_Status');
145
+		}
146
+		return $this->status_model;
147
+	}
148
+
149
+
150
+	public function wp_loaded()
151
+	{
152
+		// when adding a new registration...
153
+		$action = $this->request->getRequestParam('action');
154
+		if ($action === 'new_registration') {
155
+			EE_System::do_not_cache();
156
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
+				// and it's NOT the attendee information reg step
158
+				// force cookie expiration by setting time to last week
159
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
+				// and update the global
161
+				$_COOKIE['ee_registration_added'] = 0;
162
+			}
163
+		}
164
+	}
165
+
166
+
167
+	protected function _init_page_props()
168
+	{
169
+		$this->page_slug        = REG_PG_SLUG;
170
+		$this->_admin_base_url  = REG_ADMIN_URL;
171
+		$this->_admin_base_path = REG_ADMIN;
172
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
173
+		$this->_cpt_routes      = [
174
+			'add_new_attendee' => 'espresso_attendees',
175
+			'edit_attendee'    => 'espresso_attendees',
176
+			'insert_attendee'  => 'espresso_attendees',
177
+			'update_attendee'  => 'espresso_attendees',
178
+		];
179
+		$this->_cpt_model_names = [
180
+			'add_new_attendee' => 'EEM_Attendee',
181
+			'edit_attendee'    => 'EEM_Attendee',
182
+		];
183
+		$this->_cpt_edit_routes = [
184
+			'espresso_attendees' => 'edit_attendee',
185
+		];
186
+		$this->_pagenow_map     = [
187
+			'add_new_attendee' => 'post-new.php',
188
+			'edit_attendee'    => 'post.php',
189
+			'trash'            => 'post.php',
190
+		];
191
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
+		// add filters so that the comment urls don't take users to a confusing 404 page
193
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
199
+	 * @param WP_Comment $comment The current comment object.
200
+	 * @return string
201
+	 */
202
+	public function clear_comment_link($link, WP_Comment $comment)
203
+	{
204
+		// gotta make sure this only happens on this route
205
+		$post_type = get_post_type($comment->comment_post_ID);
206
+		if ($post_type === 'espresso_attendees') {
207
+			return '#commentsdiv';
208
+		}
209
+		return $link;
210
+	}
211
+
212
+
213
+	protected function _ajax_hooks()
214
+	{
215
+		// todo: all hooks for registrations ajax goes in here
216
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
+	}
218
+
219
+
220
+	protected function _define_page_props()
221
+	{
222
+		$this->_admin_page_title = $this->page_label;
223
+		$this->_labels           = [
224
+			'buttons'                      => [
225
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
+			],
234
+			'publishbox'                   => [
235
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
+			],
238
+			'hide_add_button_on_cpt_route' => [
239
+				'edit_attendee' => true,
240
+			],
241
+		];
242
+	}
243
+
244
+
245
+	/**
246
+	 * grab url requests and route them
247
+	 *
248
+	 * @return void
249
+	 * @throws EE_Error
250
+	 */
251
+	public function _set_page_routes()
252
+	{
253
+		$this->_get_registration_status_array();
254
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
+		$this->_page_routes = [
259
+			'default'                             => [
260
+				'func'       => '_registrations_overview_list_table',
261
+				'capability' => 'ee_read_registrations',
262
+			],
263
+			'view_registration'                   => [
264
+				'func'       => '_registration_details',
265
+				'capability' => 'ee_read_registration',
266
+				'obj_id'     => $REG_ID,
267
+			],
268
+			'edit_registration'                   => [
269
+				'func'               => '_update_attendee_registration_form',
270
+				'noheader'           => true,
271
+				'headers_sent_route' => 'view_registration',
272
+				'capability'         => 'ee_edit_registration',
273
+				'obj_id'             => $REG_ID,
274
+				'_REG_ID'            => $REG_ID,
275
+			],
276
+			'trash_registrations'                 => [
277
+				'func'       => '_trash_or_restore_registrations',
278
+				'args'       => ['trash' => true],
279
+				'noheader'   => true,
280
+				'capability' => 'ee_delete_registrations',
281
+			],
282
+			'restore_registrations'               => [
283
+				'func'       => '_trash_or_restore_registrations',
284
+				'args'       => ['trash' => false],
285
+				'noheader'   => true,
286
+				'capability' => 'ee_delete_registrations',
287
+			],
288
+			'delete_registrations'                => [
289
+				'func'       => '_delete_registrations',
290
+				'noheader'   => true,
291
+				'capability' => 'ee_delete_registrations',
292
+			],
293
+			'new_registration'                    => [
294
+				'func'       => 'new_registration',
295
+				'capability' => 'ee_edit_registrations',
296
+			],
297
+			'process_reg_step'                    => [
298
+				'func'       => 'process_reg_step',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+			],
302
+			'redirect_to_txn'                     => [
303
+				'func'       => 'redirect_to_txn',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+			],
307
+			'change_reg_status'                   => [
308
+				'func'       => '_change_reg_status',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $REG_ID,
312
+			],
313
+			'approve_registration'                => [
314
+				'func'       => 'approve_registration',
315
+				'noheader'   => true,
316
+				'capability' => 'ee_edit_registration',
317
+				'obj_id'     => $REG_ID,
318
+			],
319
+			'approve_and_notify_registration'     => [
320
+				'func'       => 'approve_registration',
321
+				'noheader'   => true,
322
+				'args'       => [true],
323
+				'capability' => 'ee_edit_registration',
324
+				'obj_id'     => $REG_ID,
325
+			],
326
+			'approve_registrations'               => [
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args'       => ['approve'],
331
+			],
332
+			'approve_and_notify_registrations'    => [
333
+				'func'       => 'bulk_action_on_registrations',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registrations',
336
+				'args'       => ['approve', true],
337
+			],
338
+			'decline_registration'                => [
339
+				'func'       => 'decline_registration',
340
+				'noheader'   => true,
341
+				'capability' => 'ee_edit_registration',
342
+				'obj_id'     => $REG_ID,
343
+			],
344
+			'decline_and_notify_registration'     => [
345
+				'func'       => 'decline_registration',
346
+				'noheader'   => true,
347
+				'args'       => [true],
348
+				'capability' => 'ee_edit_registration',
349
+				'obj_id'     => $REG_ID,
350
+			],
351
+			'decline_registrations'               => [
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args'       => ['decline'],
356
+			],
357
+			'decline_and_notify_registrations'    => [
358
+				'func'       => 'bulk_action_on_registrations',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registrations',
361
+				'args'       => ['decline', true],
362
+			],
363
+			'pending_registration'                => [
364
+				'func'       => 'pending_registration',
365
+				'noheader'   => true,
366
+				'capability' => 'ee_edit_registration',
367
+				'obj_id'     => $REG_ID,
368
+			],
369
+			'pending_and_notify_registration'     => [
370
+				'func'       => 'pending_registration',
371
+				'noheader'   => true,
372
+				'args'       => [true],
373
+				'capability' => 'ee_edit_registration',
374
+				'obj_id'     => $REG_ID,
375
+			],
376
+			'pending_registrations'               => [
377
+				'func'       => 'bulk_action_on_registrations',
378
+				'noheader'   => true,
379
+				'capability' => 'ee_edit_registrations',
380
+				'args'       => ['pending'],
381
+			],
382
+			'pending_and_notify_registrations'    => [
383
+				'func'       => 'bulk_action_on_registrations',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_registrations',
386
+				'args'       => ['pending', true],
387
+			],
388
+			'no_approve_registration'             => [
389
+				'func'       => 'not_approve_registration',
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_registration',
392
+				'obj_id'     => $REG_ID,
393
+			],
394
+			'no_approve_and_notify_registration'  => [
395
+				'func'       => 'not_approve_registration',
396
+				'noheader'   => true,
397
+				'args'       => [true],
398
+				'capability' => 'ee_edit_registration',
399
+				'obj_id'     => $REG_ID,
400
+			],
401
+			'no_approve_registrations'            => [
402
+				'func'       => 'bulk_action_on_registrations',
403
+				'noheader'   => true,
404
+				'capability' => 'ee_edit_registrations',
405
+				'args'       => ['not_approve'],
406
+			],
407
+			'no_approve_and_notify_registrations' => [
408
+				'func'       => 'bulk_action_on_registrations',
409
+				'noheader'   => true,
410
+				'capability' => 'ee_edit_registrations',
411
+				'args'       => ['not_approve', true],
412
+			],
413
+			'cancel_registration'                 => [
414
+				'func'       => 'cancel_registration',
415
+				'noheader'   => true,
416
+				'capability' => 'ee_edit_registration',
417
+				'obj_id'     => $REG_ID,
418
+			],
419
+			'cancel_and_notify_registration'      => [
420
+				'func'       => 'cancel_registration',
421
+				'noheader'   => true,
422
+				'args'       => [true],
423
+				'capability' => 'ee_edit_registration',
424
+				'obj_id'     => $REG_ID,
425
+			],
426
+			'cancel_registrations'                => [
427
+				'func'       => 'bulk_action_on_registrations',
428
+				'noheader'   => true,
429
+				'capability' => 'ee_edit_registrations',
430
+				'args'       => ['cancel'],
431
+			],
432
+			'cancel_and_notify_registrations'     => [
433
+				'func'       => 'bulk_action_on_registrations',
434
+				'noheader'   => true,
435
+				'capability' => 'ee_edit_registrations',
436
+				'args'       => ['cancel', true],
437
+			],
438
+			'wait_list_registration'              => [
439
+				'func'       => 'wait_list_registration',
440
+				'noheader'   => true,
441
+				'capability' => 'ee_edit_registration',
442
+				'obj_id'     => $REG_ID,
443
+			],
444
+			'wait_list_and_notify_registration'   => [
445
+				'func'       => 'wait_list_registration',
446
+				'noheader'   => true,
447
+				'args'       => [true],
448
+				'capability' => 'ee_edit_registration',
449
+				'obj_id'     => $REG_ID,
450
+			],
451
+			'contact_list'                        => [
452
+				'func'       => '_attendee_contact_list_table',
453
+				'capability' => 'ee_read_contacts',
454
+			],
455
+			'add_new_attendee'                    => [
456
+				'func' => '_create_new_cpt_item',
457
+				'args' => [
458
+					'new_attendee' => true,
459
+					'capability'   => 'ee_edit_contacts',
460
+				],
461
+			],
462
+			'edit_attendee'                       => [
463
+				'func'       => '_edit_cpt_item',
464
+				'capability' => 'ee_edit_contacts',
465
+				'obj_id'     => $ATT_ID,
466
+			],
467
+			'duplicate_attendee'                  => [
468
+				'func'       => '_duplicate_attendee',
469
+				'noheader'   => true,
470
+				'capability' => 'ee_edit_contacts',
471
+				'obj_id'     => $ATT_ID,
472
+			],
473
+			'insert_attendee'                     => [
474
+				'func'       => '_insert_or_update_attendee',
475
+				'args'       => [
476
+					'new_attendee' => true,
477
+				],
478
+				'noheader'   => true,
479
+				'capability' => 'ee_edit_contacts',
480
+			],
481
+			'update_attendee'                     => [
482
+				'func'       => '_insert_or_update_attendee',
483
+				'args'       => [
484
+					'new_attendee' => false,
485
+				],
486
+				'noheader'   => true,
487
+				'capability' => 'ee_edit_contacts',
488
+				'obj_id'     => $ATT_ID,
489
+			],
490
+			'trash_attendees'                     => [
491
+				'func'       => '_trash_or_restore_attendees',
492
+				'args'       => [
493
+					'trash' => 'true',
494
+				],
495
+				'noheader'   => true,
496
+				'capability' => 'ee_delete_contacts',
497
+			],
498
+			'trash_attendee'                      => [
499
+				'func'       => '_trash_or_restore_attendees',
500
+				'args'       => [
501
+					'trash' => true,
502
+				],
503
+				'noheader'   => true,
504
+				'capability' => 'ee_delete_contacts',
505
+				'obj_id'     => $ATT_ID,
506
+			],
507
+			'restore_attendees'                   => [
508
+				'func'       => '_trash_or_restore_attendees',
509
+				'args'       => [
510
+					'trash' => false,
511
+				],
512
+				'noheader'   => true,
513
+				'capability' => 'ee_delete_contacts',
514
+				'obj_id'     => $ATT_ID,
515
+			],
516
+			'resend_registration'                 => [
517
+				'func'       => '_resend_registration',
518
+				'noheader'   => true,
519
+				'capability' => 'ee_send_message',
520
+			],
521
+			'registrations_report'                => [
522
+				'func'       => '_registrations_report',
523
+				'noheader'   => true,
524
+				'capability' => 'ee_read_registrations',
525
+			],
526
+			'contact_list_export'                 => [
527
+				'func'       => '_contact_list_export',
528
+				'noheader'   => true,
529
+				'capability' => 'export',
530
+			],
531
+			'contact_list_report'                 => [
532
+				'func'       => '_contact_list_report',
533
+				'noheader'   => true,
534
+				'capability' => 'ee_read_contacts',
535
+			],
536
+		];
537
+	}
538
+
539
+
540
+	protected function _set_page_config()
541
+	{
542
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
+		$this->_page_config = [
545
+			'default'           => [
546
+				'nav'           => [
547
+					'label' => esc_html__('Overview', 'event_espresso'),
548
+					'order' => 5,
549
+				],
550
+				'help_tabs'     => [
551
+					'registrations_overview_help_tab'                       => [
552
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
+						'filename' => 'registrations_overview',
554
+					],
555
+					'registrations_overview_table_column_headings_help_tab' => [
556
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
+						'filename' => 'registrations_overview_table_column_headings',
558
+					],
559
+					'registrations_overview_filters_help_tab'               => [
560
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
+						'filename' => 'registrations_overview_filters',
562
+					],
563
+					'registrations_overview_views_help_tab'                 => [
564
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
565
+						'filename' => 'registrations_overview_views',
566
+					],
567
+					'registrations_regoverview_other_help_tab'              => [
568
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
+						'filename' => 'registrations_overview_other',
570
+					],
571
+				],
572
+				'list_table'    => 'EE_Registrations_List_Table',
573
+				'require_nonce' => false,
574
+			],
575
+			'view_registration' => [
576
+				'nav'           => [
577
+					'label'      => esc_html__('REG Details', 'event_espresso'),
578
+					'order'      => 15,
579
+					'url'        => $REG_ID
580
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
581
+						: $this->_admin_base_url,
582
+					'persistent' => false,
583
+				],
584
+				'help_tabs'     => [
585
+					'registrations_details_help_tab'                    => [
586
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
587
+						'filename' => 'registrations_details',
588
+					],
589
+					'registrations_details_table_help_tab'              => [
590
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
591
+						'filename' => 'registrations_details_table',
592
+					],
593
+					'registrations_details_form_answers_help_tab'       => [
594
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
595
+						'filename' => 'registrations_details_form_answers',
596
+					],
597
+					'registrations_details_registrant_details_help_tab' => [
598
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
599
+						'filename' => 'registrations_details_registrant_details',
600
+					],
601
+				],
602
+				'metaboxes'     => array_merge(
603
+					$this->_default_espresso_metaboxes,
604
+					['_registration_details_metaboxes']
605
+				),
606
+				'require_nonce' => false,
607
+			],
608
+			'new_registration'  => [
609
+				'nav'           => [
610
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
611
+					'url'        => '#',
612
+					'order'      => 15,
613
+					'persistent' => false,
614
+				],
615
+				'metaboxes'     => $this->_default_espresso_metaboxes,
616
+				'labels'        => [
617
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
+				],
619
+				'require_nonce' => false,
620
+			],
621
+			'add_new_attendee'  => [
622
+				'nav'           => [
623
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
624
+					'order'      => 15,
625
+					'persistent' => false,
626
+				],
627
+				'metaboxes'     => array_merge(
628
+					$this->_default_espresso_metaboxes,
629
+					['_publish_post_box', 'attendee_editor_metaboxes']
630
+				),
631
+				'require_nonce' => false,
632
+			],
633
+			'edit_attendee'     => [
634
+				'nav'           => [
635
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
+					'order'      => 15,
637
+					'persistent' => false,
638
+					'url'        => $ATT_ID
639
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
640
+						: $this->_admin_base_url,
641
+				],
642
+				'metaboxes'     => array_merge(
643
+					$this->_default_espresso_metaboxes,
644
+					['attendee_editor_metaboxes']
645
+				),
646
+				'require_nonce' => false,
647
+			],
648
+			'contact_list'      => [
649
+				'nav'           => [
650
+					'label' => esc_html__('Contact List', 'event_espresso'),
651
+					'order' => 20,
652
+				],
653
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
654
+				'help_tabs'     => [
655
+					'registrations_contact_list_help_tab'                       => [
656
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
657
+						'filename' => 'registrations_contact_list',
658
+					],
659
+					'registrations_contact-list_table_column_headings_help_tab' => [
660
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
661
+						'filename' => 'registrations_contact_list_table_column_headings',
662
+					],
663
+					'registrations_contact_list_views_help_tab'                 => [
664
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
665
+						'filename' => 'registrations_contact_list_views',
666
+					],
667
+					'registrations_contact_list_other_help_tab'                 => [
668
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
669
+						'filename' => 'registrations_contact_list_other',
670
+					],
671
+				],
672
+				'metaboxes'     => [],
673
+				'require_nonce' => false,
674
+			],
675
+			// override default cpt routes
676
+			'create_new'        => '',
677
+			'edit'              => '',
678
+		];
679
+	}
680
+
681
+
682
+	/**
683
+	 * The below methods aren't used by this class currently
684
+	 */
685
+	protected function _add_screen_options()
686
+	{
687
+	}
688
+
689
+
690
+	protected function _add_feature_pointers()
691
+	{
692
+	}
693
+
694
+
695
+	public function admin_init()
696
+	{
697
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
698
+			'click "Update Registration Questions" to save your changes',
699
+			'event_espresso'
700
+		);
701
+	}
702
+
703
+
704
+	public function admin_notices()
705
+	{
706
+	}
707
+
708
+
709
+	public function admin_footer_scripts()
710
+	{
711
+	}
712
+
713
+
714
+	/**
715
+	 * get list of registration statuses
716
+	 *
717
+	 * @return void
718
+	 * @throws EE_Error
719
+	 */
720
+	private function _get_registration_status_array()
721
+	{
722
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
723
+	}
724
+
725
+
726
+	/**
727
+	 * @throws InvalidArgumentException
728
+	 * @throws InvalidDataTypeException
729
+	 * @throws InvalidInterfaceException
730
+	 * @since 4.10.2.p
731
+	 */
732
+	protected function _add_screen_options_default()
733
+	{
734
+		$this->_per_page_screen_option();
735
+	}
736
+
737
+
738
+	/**
739
+	 * @throws InvalidArgumentException
740
+	 * @throws InvalidDataTypeException
741
+	 * @throws InvalidInterfaceException
742
+	 * @since 4.10.2.p
743
+	 */
744
+	protected function _add_screen_options_contact_list()
745
+	{
746
+		$page_title              = $this->_admin_page_title;
747
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
+		$this->_per_page_screen_option();
749
+		$this->_admin_page_title = $page_title;
750
+	}
751
+
752
+
753
+	public function load_scripts_styles()
754
+	{
755
+		// style
756
+		wp_register_style(
757
+			'espresso_reg',
758
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
+			['ee-admin-css'],
760
+			EVENT_ESPRESSO_VERSION
761
+		);
762
+		wp_enqueue_style('espresso_reg');
763
+		// script
764
+		wp_register_script(
765
+			'espresso_reg',
766
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
768
+			EVENT_ESPRESSO_VERSION,
769
+			true
770
+		);
771
+		wp_enqueue_script('espresso_reg');
772
+	}
773
+
774
+
775
+	/**
776
+	 * @throws EE_Error
777
+	 * @throws InvalidArgumentException
778
+	 * @throws InvalidDataTypeException
779
+	 * @throws InvalidInterfaceException
780
+	 * @throws ReflectionException
781
+	 * @since 4.10.2.p
782
+	 */
783
+	public function load_scripts_styles_edit_attendee()
784
+	{
785
+		// stuff to only show up on our attendee edit details page.
786
+		$attendee_details_translations = [
787
+			'att_publish_text' => sprintf(
788
+			/* translators: The date and time */
789
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
+			),
792
+		];
793
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
+		wp_enqueue_script('jquery-validate');
795
+	}
796
+
797
+
798
+	/**
799
+	 * @throws EE_Error
800
+	 * @throws InvalidArgumentException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws InvalidInterfaceException
803
+	 * @throws ReflectionException
804
+	 * @since 4.10.2.p
805
+	 */
806
+	public function load_scripts_styles_view_registration()
807
+	{
808
+		// styles
809
+		wp_enqueue_style('espresso-ui-theme');
810
+		// scripts
811
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
812
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
813
+	}
814
+
815
+
816
+	public function load_scripts_styles_contact_list()
817
+	{
818
+		wp_dequeue_style('espresso_reg');
819
+		wp_register_style(
820
+			'espresso_att',
821
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
+			['ee-admin-css'],
823
+			EVENT_ESPRESSO_VERSION
824
+		);
825
+		wp_enqueue_style('espresso_att');
826
+	}
827
+
828
+
829
+	public function load_scripts_styles_new_registration()
830
+	{
831
+		wp_register_script(
832
+			'ee-spco-for-admin',
833
+			REG_ASSETS_URL . 'spco_for_admin.js',
834
+			['underscore', 'jquery'],
835
+			EVENT_ESPRESSO_VERSION,
836
+			true
837
+		);
838
+		wp_enqueue_script('ee-spco-for-admin');
839
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
+		EE_Form_Section_Proper::wp_enqueue_scripts();
841
+		EED_Ticket_Selector::load_tckt_slctr_assets();
842
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
843
+	}
844
+
845
+
846
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
+	{
848
+		add_filter('FHEE_load_EE_messages', '__return_true');
849
+	}
850
+
851
+
852
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
+	{
854
+		add_filter('FHEE_load_EE_messages', '__return_true');
855
+	}
856
+
857
+
858
+	/**
859
+	 * @throws EE_Error
860
+	 * @throws InvalidArgumentException
861
+	 * @throws InvalidDataTypeException
862
+	 * @throws InvalidInterfaceException
863
+	 * @throws ReflectionException
864
+	 * @since 4.10.2.p
865
+	 */
866
+	protected function _set_list_table_views_default()
867
+	{
868
+		// for notification related bulk actions we need to make sure only active messengers have an option.
869
+		EED_Messages::set_autoloaders();
870
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
871
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
873
+		// key= bulk_action_slug, value= message type.
874
+		$match_array = [
875
+			'approve_registrations'    => 'registration',
876
+			'decline_registrations'    => 'declined_registration',
877
+			'pending_registrations'    => 'pending_approval',
878
+			'no_approve_registrations' => 'not_approved_registration',
879
+			'cancel_registrations'     => 'cancelled_registration',
880
+		];
881
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
882
+			'ee_send_message',
883
+			'batch_send_messages'
884
+		);
885
+		/** setup reg status bulk actions **/
886
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
+				'Approve and Notify Registrations',
890
+				'event_espresso'
891
+			);
892
+		}
893
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
+				'Decline and Notify Registrations',
897
+				'event_espresso'
898
+			);
899
+		}
900
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
901
+			'Set Registrations to Pending Payment',
902
+			'event_espresso'
903
+		);
904
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
+				'Set Registrations to Pending Payment and Notify',
907
+				'event_espresso'
908
+			);
909
+		}
910
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
+			'Set Registrations to Not Approved',
912
+			'event_espresso'
913
+		);
914
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
+				'Set Registrations to Not Approved and Notify',
917
+				'event_espresso'
918
+			);
919
+		}
920
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
+				'Cancel Registrations and Notify',
924
+				'event_espresso'
925
+			);
926
+		}
927
+		$def_reg_status_actions = apply_filters(
928
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
+			$def_reg_status_actions,
930
+			$active_mts,
931
+			$can_send
932
+		);
933
+
934
+		$this->_views = [
935
+			'all'   => [
936
+				'slug'        => 'all',
937
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
+				'count'       => 0,
939
+				'bulk_action' => array_merge(
940
+					$def_reg_status_actions,
941
+					[
942
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
+					]
944
+				),
945
+			],
946
+			'month' => [
947
+				'slug'        => 'month',
948
+				'label'       => esc_html__('This Month', 'event_espresso'),
949
+				'count'       => 0,
950
+				'bulk_action' => array_merge(
951
+					$def_reg_status_actions,
952
+					[
953
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
+					]
955
+				),
956
+			],
957
+			'today' => [
958
+				'slug'        => 'today',
959
+				'label'       => sprintf(
960
+					esc_html__('Today - %s', 'event_espresso'),
961
+					date('M d, Y', current_time('timestamp'))
962
+				),
963
+				'count'       => 0,
964
+				'bulk_action' => array_merge(
965
+					$def_reg_status_actions,
966
+					[
967
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
+					]
969
+				),
970
+			],
971
+		];
972
+		if (
973
+			EE_Registry::instance()->CAP->current_user_can(
974
+				'ee_delete_registrations',
975
+				'espresso_registrations_delete_registration'
976
+			)
977
+		) {
978
+			$this->_views['incomplete'] = [
979
+				'slug'        => 'incomplete',
980
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
981
+				'count'       => 0,
982
+				'bulk_action' => [
983
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
+				],
985
+			];
986
+			$this->_views['trash']      = [
987
+				'slug'        => 'trash',
988
+				'label'       => esc_html__('Trash', 'event_espresso'),
989
+				'count'       => 0,
990
+				'bulk_action' => [
991
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
+				],
994
+			];
995
+		}
996
+	}
997
+
998
+
999
+	protected function _set_list_table_views_contact_list()
1000
+	{
1001
+		$this->_views = [
1002
+			'in_use' => [
1003
+				'slug'        => 'in_use',
1004
+				'label'       => esc_html__('In Use', 'event_espresso'),
1005
+				'count'       => 0,
1006
+				'bulk_action' => [
1007
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
+				],
1009
+			],
1010
+		];
1011
+		if (
1012
+			EE_Registry::instance()->CAP->current_user_can(
1013
+				'ee_delete_contacts',
1014
+				'espresso_registrations_trash_attendees'
1015
+			)
1016
+		) {
1017
+			$this->_views['trash'] = [
1018
+				'slug'        => 'trash',
1019
+				'label'       => esc_html__('Trash', 'event_espresso'),
1020
+				'count'       => 0,
1021
+				'bulk_action' => [
1022
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
+				],
1024
+			];
1025
+		}
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * @return array
1031
+	 * @throws EE_Error
1032
+	 */
1033
+	protected function _registration_legend_items()
1034
+	{
1035
+		$fc_items = [
1036
+			'star-icon'        => [
1037
+				'class' => 'dashicons dashicons-star-filled gold-icon',
1038
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1039
+			],
1040
+			'view_details'     => [
1041
+				'class' => 'dashicons dashicons-clipboard',
1042
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1043
+			],
1044
+			'edit_attendee'    => [
1045
+				'class' => 'dashicons dashicons-admin-users',
1046
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1047
+			],
1048
+			'view_transaction' => [
1049
+				'class' => 'dashicons dashicons-cart',
1050
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1051
+			],
1052
+			'view_invoice'     => [
1053
+				'class' => 'dashicons dashicons-media-spreadsheet',
1054
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1055
+			],
1056
+		];
1057
+		if (
1058
+			EE_Registry::instance()->CAP->current_user_can(
1059
+				'ee_send_message',
1060
+				'espresso_registrations_resend_registration'
1061
+			)
1062
+		) {
1063
+			$fc_items['resend_registration'] = [
1064
+				'class' => 'dashicons dashicons-email-alt',
1065
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1066
+			];
1067
+		} else {
1068
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1069
+		}
1070
+		if (
1071
+			EE_Registry::instance()->CAP->current_user_can(
1072
+				'ee_read_global_messages',
1073
+				'view_filtered_messages'
1074
+			)
1075
+		) {
1076
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1077
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1078
+				$fc_items['view_related_messages'] = [
1079
+					'class' => $related_for_icon['css_class'],
1080
+					'desc'  => $related_for_icon['label'],
1081
+				];
1082
+			}
1083
+		}
1084
+		$sc_items = [
1085
+			'approved_status'   => [
1086
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1087
+				'desc'  => EEH_Template::pretty_status(
1088
+					EEM_Registration::status_id_approved,
1089
+					false,
1090
+					'sentence'
1091
+				),
1092
+			],
1093
+			'pending_status'    => [
1094
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1095
+				'desc'  => EEH_Template::pretty_status(
1096
+					EEM_Registration::status_id_pending_payment,
1097
+					false,
1098
+					'sentence'
1099
+				),
1100
+			],
1101
+			'wait_list'         => [
1102
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1103
+				'desc'  => EEH_Template::pretty_status(
1104
+					EEM_Registration::status_id_wait_list,
1105
+					false,
1106
+					'sentence'
1107
+				),
1108
+			],
1109
+			'incomplete_status' => [
1110
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1111
+				'desc'  => EEH_Template::pretty_status(
1112
+					EEM_Registration::status_id_incomplete,
1113
+					false,
1114
+					'sentence'
1115
+				),
1116
+			],
1117
+			'not_approved'      => [
1118
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1119
+				'desc'  => EEH_Template::pretty_status(
1120
+					EEM_Registration::status_id_not_approved,
1121
+					false,
1122
+					'sentence'
1123
+				),
1124
+			],
1125
+			'declined_status'   => [
1126
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1127
+				'desc'  => EEH_Template::pretty_status(
1128
+					EEM_Registration::status_id_declined,
1129
+					false,
1130
+					'sentence'
1131
+				),
1132
+			],
1133
+			'cancelled_status'  => [
1134
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1135
+				'desc'  => EEH_Template::pretty_status(
1136
+					EEM_Registration::status_id_cancelled,
1137
+					false,
1138
+					'sentence'
1139
+				),
1140
+			],
1141
+		];
1142
+		return array_merge($fc_items, $sc_items);
1143
+	}
1144
+
1145
+
1146
+
1147
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1148
+
1149
+
1150
+	/**
1151
+	 * @throws DomainException
1152
+	 * @throws EE_Error
1153
+	 * @throws InvalidArgumentException
1154
+	 * @throws InvalidDataTypeException
1155
+	 * @throws InvalidInterfaceException
1156
+	 */
1157
+	protected function _registrations_overview_list_table()
1158
+	{
1159
+		$this->appendAddNewRegistrationButtonToPageTitle();
1160
+		$header_text                  = '';
1161
+		$admin_page_header_decorators = [
1162
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1164
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1165
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1166
+		];
1167
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1168
+			$filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1169
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1170
+		}
1171
+		$this->_template_args['admin_page_header'] = $header_text;
1172
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1173
+		$this->display_admin_list_table_page_with_no_sidebar();
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * @throws EE_Error
1179
+	 * @throws InvalidArgumentException
1180
+	 * @throws InvalidDataTypeException
1181
+	 * @throws InvalidInterfaceException
1182
+	 */
1183
+	private function appendAddNewRegistrationButtonToPageTitle()
1184
+	{
1185
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1186
+		if (
1187
+			$EVT_ID
1188
+			&& EE_Registry::instance()->CAP->current_user_can(
1189
+				'ee_edit_registrations',
1190
+				'espresso_registrations_new_registration',
1191
+				$EVT_ID
1192
+			)
1193
+		) {
1194
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
+				'new_registration',
1196
+				'add-registrant',
1197
+				['event_id' => $EVT_ID],
1198
+				'add-new-h2'
1199
+			);
1200
+		}
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * This sets the _registration property for the registration details screen
1206
+	 *
1207
+	 * @return void
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws InvalidDataTypeException
1211
+	 * @throws InvalidInterfaceException
1212
+	 */
1213
+	private function _set_registration_object()
1214
+	{
1215
+		// get out if we've already set the object
1216
+		if ($this->_registration instanceof EE_Registration) {
1217
+			return;
1218
+		}
1219
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1220
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1221
+			return;
1222
+		}
1223
+		$error_msg = sprintf(
1224
+			esc_html__(
1225
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1226
+				'event_espresso'
1227
+			),
1228
+			$REG_ID
1229
+		);
1230
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1231
+		$this->_registration = null;
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * Used to retrieve registrations for the list table.
1237
+	 *
1238
+	 * @param int  $per_page
1239
+	 * @param bool $count
1240
+	 * @param bool $this_month
1241
+	 * @param bool $today
1242
+	 * @return EE_Registration[]|int
1243
+	 * @throws EE_Error
1244
+	 * @throws InvalidArgumentException
1245
+	 * @throws InvalidDataTypeException
1246
+	 * @throws InvalidInterfaceException
1247
+	 */
1248
+	public function get_registrations(
1249
+		$per_page = 10,
1250
+		$count = false,
1251
+		$this_month = false,
1252
+		$today = false
1253
+	) {
1254
+		if ($this_month) {
1255
+			$this->request->setRequestParam('status', 'month');
1256
+		}
1257
+		if ($today) {
1258
+			$this->request->setRequestParam('status', 'today');
1259
+		}
1260
+		$query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1261
+		/**
1262
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
+		 *
1264
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1265
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1266
+		 *                      or if you have the development copy of EE you can view this at the path:
1267
+		 *                      /docs/G--Model-System/model-query-params.md
1268
+		 */
1269
+		$query_params['group_by'] = '';
1270
+
1271
+		return $count
1272
+			? $this->getRegistrationModel()->count($query_params)
1273
+			/** @type EE_Registration[] */
1274
+			: $this->getRegistrationModel()->get_all($query_params);
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1280
+	 * Note: this listens to values on the request for some of the query parameters.
1281
+	 *
1282
+	 * @param array $request
1283
+	 * @param int   $per_page
1284
+	 * @param bool  $count
1285
+	 * @return array
1286
+	 * @throws EE_Error
1287
+	 * @throws InvalidArgumentException
1288
+	 * @throws InvalidDataTypeException
1289
+	 * @throws InvalidInterfaceException
1290
+	 */
1291
+	protected function _get_registration_query_parameters(
1292
+		$request = [],
1293
+		$per_page = 10,
1294
+		$count = false
1295
+	) {
1296
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1297
+		$list_table_query_builder = $this->loader->getNew(
1298
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1299
+			[null, null, $request]
1300
+		);
1301
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1302
+	}
1303
+
1304
+
1305
+	public function get_registration_status_array()
1306
+	{
1307
+		return self::$_reg_status;
1308
+	}
1309
+
1310
+
1311
+
1312
+
1313
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1314
+	/**
1315
+	 * generates HTML for the View Registration Details Admin page
1316
+	 *
1317
+	 * @return void
1318
+	 * @throws DomainException
1319
+	 * @throws EE_Error
1320
+	 * @throws InvalidArgumentException
1321
+	 * @throws InvalidDataTypeException
1322
+	 * @throws InvalidInterfaceException
1323
+	 * @throws EntityNotFoundException
1324
+	 * @throws ReflectionException
1325
+	 */
1326
+	protected function _registration_details()
1327
+	{
1328
+		$this->_template_args = [];
1329
+		$this->_set_registration_object();
1330
+		if (is_object($this->_registration)) {
1331
+			$transaction                                   = $this->_registration->transaction()
1332
+				? $this->_registration->transaction()
1333
+				: EE_Transaction::new_instance();
1334
+			$this->_session                                = $transaction->session_data();
1335
+			$event_id                                      = $this->_registration->event_ID();
1336
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1337
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1338
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1339
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1340
+			$this->_template_args['grand_total']           = $transaction->total();
1341
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1342
+			// link back to overview
1343
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1344
+			$this->_template_args['registration']                = $this->_registration;
1345
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1346
+				[
1347
+					'action'   => 'default',
1348
+					'event_id' => $event_id,
1349
+				],
1350
+				REG_ADMIN_URL
1351
+			);
1352
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1353
+				[
1354
+					'action' => 'default',
1355
+					'EVT_ID' => $event_id,
1356
+					'page'   => 'espresso_transactions',
1357
+				],
1358
+				admin_url('admin.php')
1359
+			);
1360
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1361
+				[
1362
+					'page'   => 'espresso_events',
1363
+					'action' => 'edit',
1364
+					'post'   => $event_id,
1365
+				],
1366
+				admin_url('admin.php')
1367
+			);
1368
+			// next and previous links
1369
+			$next_reg                                      = $this->_registration->next(
1370
+				null,
1371
+				[],
1372
+				'REG_ID'
1373
+			);
1374
+			$this->_template_args['next_registration']     = $next_reg
1375
+				? $this->_next_link(
1376
+					EE_Admin_Page::add_query_args_and_nonce(
1377
+						[
1378
+							'action'  => 'view_registration',
1379
+							'_REG_ID' => $next_reg['REG_ID'],
1380
+						],
1381
+						REG_ADMIN_URL
1382
+					),
1383
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1384
+				)
1385
+				: '';
1386
+			$previous_reg                                  = $this->_registration->previous(
1387
+				null,
1388
+				[],
1389
+				'REG_ID'
1390
+			);
1391
+			$this->_template_args['previous_registration'] = $previous_reg
1392
+				? $this->_previous_link(
1393
+					EE_Admin_Page::add_query_args_and_nonce(
1394
+						[
1395
+							'action'  => 'view_registration',
1396
+							'_REG_ID' => $previous_reg['REG_ID'],
1397
+						],
1398
+						REG_ADMIN_URL
1399
+					),
1400
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1401
+				)
1402
+				: '';
1403
+			// grab header
1404
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1405
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1406
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1407
+				$template_path,
1408
+				$this->_template_args,
1409
+				true
1410
+			);
1411
+		} else {
1412
+			$this->_template_args['admin_page_header'] = '';
1413
+			$this->_display_espresso_notices();
1414
+		}
1415
+		// the details template wrapper
1416
+		$this->display_admin_page_with_sidebar();
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 * @throws EE_Error
1422
+	 * @throws InvalidArgumentException
1423
+	 * @throws InvalidDataTypeException
1424
+	 * @throws InvalidInterfaceException
1425
+	 * @throws ReflectionException
1426
+	 * @since 4.10.2.p
1427
+	 */
1428
+	protected function _registration_details_metaboxes()
1429
+	{
1430
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1431
+		$this->_set_registration_object();
1432
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1433
+		$this->addMetaBox(
1434
+			'edit-reg-status-mbox',
1435
+			esc_html__('Registration Status', 'event_espresso'),
1436
+			[$this, 'set_reg_status_buttons_metabox'],
1437
+			$this->_wp_page_slug
1438
+		);
1439
+		$this->addMetaBox(
1440
+			'edit-reg-details-mbox',
1441
+			'<span>' . esc_html__('Registration Details', 'event_espresso')
1442
+			. '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1443
+			[$this, '_reg_details_meta_box'],
1444
+			$this->_wp_page_slug
1445
+		);
1446
+		if (
1447
+			$attendee instanceof EE_Attendee
1448
+			&& EE_Registry::instance()->CAP->current_user_can(
1449
+				'ee_read_registration',
1450
+				'edit-reg-questions-mbox',
1451
+				$this->_registration->ID()
1452
+			)
1453
+		) {
1454
+			$this->addMetaBox(
1455
+				'edit-reg-questions-mbox',
1456
+				esc_html__('Registration Form Answers', 'event_espresso'),
1457
+				[$this, '_reg_questions_meta_box'],
1458
+				$this->_wp_page_slug
1459
+			);
1460
+		}
1461
+		$this->addMetaBox(
1462
+			'edit-reg-registrant-mbox',
1463
+			esc_html__('Contact Details', 'event_espresso'),
1464
+			[$this, '_reg_registrant_side_meta_box'],
1465
+			$this->_wp_page_slug,
1466
+			'side'
1467
+		);
1468
+		if ($this->_registration->group_size() > 1) {
1469
+			$this->addMetaBox(
1470
+				'edit-reg-attendees-mbox',
1471
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1472
+				[$this, '_reg_attendees_meta_box'],
1473
+				$this->_wp_page_slug
1474
+			);
1475
+		}
1476
+	}
1477
+
1478
+
1479
+	/**
1480
+	 * set_reg_status_buttons_metabox
1481
+	 *
1482
+	 * @return void
1483
+	 * @throws EE_Error
1484
+	 * @throws EntityNotFoundException
1485
+	 * @throws InvalidArgumentException
1486
+	 * @throws InvalidDataTypeException
1487
+	 * @throws InvalidInterfaceException
1488
+	 * @throws ReflectionException
1489
+	 */
1490
+	public function set_reg_status_buttons_metabox()
1491
+	{
1492
+		$this->_set_registration_object();
1493
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1494
+		$output                 = $change_reg_status_form->form_open(
1495
+			self::add_query_args_and_nonce(
1496
+				[
1497
+					'action' => 'change_reg_status',
1498
+				],
1499
+				REG_ADMIN_URL
1500
+			)
1501
+		);
1502
+		$output                 .= $change_reg_status_form->get_html();
1503
+		$output                 .= $change_reg_status_form->form_close();
1504
+		echo wp_kses($output, AllowedTags::getWithFormTags());
1505
+	}
1506
+
1507
+
1508
+	/**
1509
+	 * @return EE_Form_Section_Proper
1510
+	 * @throws EE_Error
1511
+	 * @throws InvalidArgumentException
1512
+	 * @throws InvalidDataTypeException
1513
+	 * @throws InvalidInterfaceException
1514
+	 * @throws EntityNotFoundException
1515
+	 * @throws ReflectionException
1516
+	 */
1517
+	protected function _generate_reg_status_change_form()
1518
+	{
1519
+		$reg_status_change_form_array = [
1520
+			'name'            => 'reg_status_change_form',
1521
+			'html_id'         => 'reg-status-change-form',
1522
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1523
+			'subsections'     => [
1524
+				'return'         => new EE_Hidden_Input(
1525
+					[
1526
+						'name'    => 'return',
1527
+						'default' => 'view_registration',
1528
+					]
1529
+				),
1530
+				'REG_ID'         => new EE_Hidden_Input(
1531
+					[
1532
+						'name'    => 'REG_ID',
1533
+						'default' => $this->_registration->ID(),
1534
+					]
1535
+				),
1536
+			],
1537
+		];
1538
+		if (
1539
+			EE_Registry::instance()->CAP->current_user_can(
1540
+				'ee_edit_registration',
1541
+				'toggle_registration_status',
1542
+				$this->_registration->ID()
1543
+			)
1544
+		) {
1545
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1546
+				$this->_get_reg_statuses(),
1547
+				[
1548
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1549
+					'default'         => $this->_registration->status_ID(),
1550
+				]
1551
+			);
1552
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1553
+				[
1554
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1555
+					'default'         => false,
1556
+					'html_help_text'  => esc_html__(
1557
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1558
+						'event_espresso'
1559
+					),
1560
+				]
1561
+			);
1562
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1563
+				[
1564
+					'html_class'      => 'button--primary',
1565
+					'html_label_text' => '&nbsp;',
1566
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1567
+				]
1568
+			);
1569
+		}
1570
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1571
+	}
1572
+
1573
+
1574
+	/**
1575
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1576
+	 *
1577
+	 * @return array
1578
+	 * @throws EE_Error
1579
+	 * @throws InvalidArgumentException
1580
+	 * @throws InvalidDataTypeException
1581
+	 * @throws InvalidInterfaceException
1582
+	 * @throws EntityNotFoundException
1583
+	 */
1584
+	protected function _get_reg_statuses()
1585
+	{
1586
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1587
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1588
+		// get current reg status
1589
+		$current_status = $this->_registration->status_ID();
1590
+		// is registration for free event? This will determine whether to display the pending payment option
1591
+		if (
1592
+			$current_status !== EEM_Registration::status_id_pending_payment
1593
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1594
+		) {
1595
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1596
+		}
1597
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1603
+	 *
1604
+	 * @param bool $status REG status given for changing registrations to.
1605
+	 * @param bool $notify Whether to send messages notifications or not.
1606
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1607
+	 * @throws DomainException
1608
+	 * @throws EE_Error
1609
+	 * @throws EntityNotFoundException
1610
+	 * @throws InvalidArgumentException
1611
+	 * @throws InvalidDataTypeException
1612
+	 * @throws InvalidInterfaceException
1613
+	 * @throws ReflectionException
1614
+	 * @throws RuntimeException
1615
+	 */
1616
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1617
+	{
1618
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1619
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1620
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1621
+
1622
+		// sanitize $REG_IDs
1623
+		$REG_IDs = array_map('absint', $REG_IDs);
1624
+		// and remove empty entries
1625
+		$REG_IDs = array_filter($REG_IDs);
1626
+
1627
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1628
+
1629
+		/**
1630
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1631
+		 * Currently this value is used downstream by the _process_resend_registration method.
1632
+		 *
1633
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1634
+		 * @param bool                     $status           The status registrations were changed to.
1635
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1636
+		 * @param Registrations_Admin_Page $admin_page_object
1637
+		 */
1638
+		$REG_ID = apply_filters(
1639
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1640
+			$result['REG_ID'],
1641
+			$status,
1642
+			$result['success'],
1643
+			$this
1644
+		);
1645
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1646
+
1647
+		// notify?
1648
+		if (
1649
+			$notify
1650
+			&& $result['success']
1651
+			&& ! empty($REG_ID)
1652
+			&& EE_Registry::instance()->CAP->current_user_can(
1653
+				'ee_send_message',
1654
+				'espresso_registrations_resend_registration'
1655
+			)
1656
+		) {
1657
+			$this->_process_resend_registration();
1658
+		}
1659
+		return $result;
1660
+	}
1661
+
1662
+
1663
+	/**
1664
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1665
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1666
+	 *
1667
+	 * @param array  $REG_IDs
1668
+	 * @param string $status
1669
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1670
+	 *                       slug sent with setting the registration status.
1671
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1672
+	 * @throws EE_Error
1673
+	 * @throws InvalidArgumentException
1674
+	 * @throws InvalidDataTypeException
1675
+	 * @throws InvalidInterfaceException
1676
+	 * @throws ReflectionException
1677
+	 * @throws RuntimeException
1678
+	 * @throws EntityNotFoundException
1679
+	 * @throws DomainException
1680
+	 */
1681
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1682
+	{
1683
+		$success = false;
1684
+		// typecast $REG_IDs
1685
+		$REG_IDs = (array) $REG_IDs;
1686
+		if (! empty($REG_IDs)) {
1687
+			$success = true;
1688
+			// set default status if none is passed
1689
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1690
+			$status_context = $notify
1691
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1692
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1693
+			// loop through REG_ID's and change status
1694
+			foreach ($REG_IDs as $REG_ID) {
1695
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1696
+				if ($registration instanceof EE_Registration) {
1697
+					$registration->set_status(
1698
+						$status,
1699
+						false,
1700
+						new Context(
1701
+							$status_context,
1702
+							esc_html__(
1703
+								'Manually triggered status change on a Registration Admin Page route.',
1704
+								'event_espresso'
1705
+							)
1706
+						)
1707
+					);
1708
+					$result = $registration->save();
1709
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1710
+					$success = $result !== false ? $success : false;
1711
+				}
1712
+			}
1713
+		}
1714
+
1715
+		// return $success and processed registrations
1716
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1717
+	}
1718
+
1719
+
1720
+	/**
1721
+	 * Common logic for setting up success message and redirecting to appropriate route
1722
+	 *
1723
+	 * @param string $STS_ID status id for the registration changed to
1724
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1725
+	 * @return void
1726
+	 * @throws DomainException
1727
+	 * @throws EE_Error
1728
+	 * @throws EntityNotFoundException
1729
+	 * @throws InvalidArgumentException
1730
+	 * @throws InvalidDataTypeException
1731
+	 * @throws InvalidInterfaceException
1732
+	 * @throws ReflectionException
1733
+	 * @throws RuntimeException
1734
+	 */
1735
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1736
+	{
1737
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1738
+			: ['success' => false];
1739
+		$success = isset($result['success']) && $result['success'];
1740
+		// setup success message
1741
+		if ($success) {
1742
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1743
+				$msg = sprintf(
1744
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1745
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1746
+				);
1747
+			} else {
1748
+				$msg = sprintf(
1749
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1750
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1751
+				);
1752
+			}
1753
+			EE_Error::add_success($msg);
1754
+		} else {
1755
+			EE_Error::add_error(
1756
+				esc_html__(
1757
+					'Something went wrong, and the status was not changed',
1758
+					'event_espresso'
1759
+				),
1760
+				__FILE__,
1761
+				__LINE__,
1762
+				__FUNCTION__
1763
+			);
1764
+		}
1765
+		$return = $this->request->getRequestParam('return');
1766
+		$route  = $return === 'view_registration'
1767
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1768
+			: ['action' => 'default'];
1769
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1770
+		$this->_redirect_after_action($success, '', '', $route, true);
1771
+	}
1772
+
1773
+
1774
+	/**
1775
+	 * incoming reg status change from reg details page.
1776
+	 *
1777
+	 * @return void
1778
+	 * @throws EE_Error
1779
+	 * @throws EntityNotFoundException
1780
+	 * @throws InvalidArgumentException
1781
+	 * @throws InvalidDataTypeException
1782
+	 * @throws InvalidInterfaceException
1783
+	 * @throws ReflectionException
1784
+	 * @throws RuntimeException
1785
+	 * @throws DomainException
1786
+	 */
1787
+	protected function _change_reg_status()
1788
+	{
1789
+		$this->request->setRequestParam('return', 'view_registration');
1790
+		// set notify based on whether the send notifications toggle is set or not
1791
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1792
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1793
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1794
+		switch ($reg_status) {
1795
+			case EEM_Registration::status_id_approved:
1796
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1797
+				$this->approve_registration($notify);
1798
+				break;
1799
+			case EEM_Registration::status_id_pending_payment:
1800
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1801
+				$this->pending_registration($notify);
1802
+				break;
1803
+			case EEM_Registration::status_id_not_approved:
1804
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1805
+				$this->not_approve_registration($notify);
1806
+				break;
1807
+			case EEM_Registration::status_id_declined:
1808
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1809
+				$this->decline_registration($notify);
1810
+				break;
1811
+			case EEM_Registration::status_id_cancelled:
1812
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1813
+				$this->cancel_registration($notify);
1814
+				break;
1815
+			case EEM_Registration::status_id_wait_list:
1816
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1817
+				$this->wait_list_registration($notify);
1818
+				break;
1819
+			case EEM_Registration::status_id_incomplete:
1820
+			default:
1821
+				$this->request->unSetRequestParam('return');
1822
+				$this->_reg_status_change_return('');
1823
+				break;
1824
+		}
1825
+	}
1826
+
1827
+
1828
+	/**
1829
+	 * Callback for bulk action routes.
1830
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1831
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1832
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1833
+	 * when an action is happening on just a single registration).
1834
+	 *
1835
+	 * @param      $action
1836
+	 * @param bool $notify
1837
+	 */
1838
+	protected function bulk_action_on_registrations($action, $notify = false)
1839
+	{
1840
+		do_action(
1841
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1842
+			$this,
1843
+			$action,
1844
+			$notify
1845
+		);
1846
+		$method = $action . '_registration';
1847
+		if (method_exists($this, $method)) {
1848
+			$this->$method($notify);
1849
+		}
1850
+	}
1851
+
1852
+
1853
+	/**
1854
+	 * approve_registration
1855
+	 *
1856
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1857
+	 * @return void
1858
+	 * @throws EE_Error
1859
+	 * @throws EntityNotFoundException
1860
+	 * @throws InvalidArgumentException
1861
+	 * @throws InvalidDataTypeException
1862
+	 * @throws InvalidInterfaceException
1863
+	 * @throws ReflectionException
1864
+	 * @throws RuntimeException
1865
+	 * @throws DomainException
1866
+	 */
1867
+	protected function approve_registration($notify = false)
1868
+	{
1869
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1870
+	}
1871
+
1872
+
1873
+	/**
1874
+	 * decline_registration
1875
+	 *
1876
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1877
+	 * @return void
1878
+	 * @throws EE_Error
1879
+	 * @throws EntityNotFoundException
1880
+	 * @throws InvalidArgumentException
1881
+	 * @throws InvalidDataTypeException
1882
+	 * @throws InvalidInterfaceException
1883
+	 * @throws ReflectionException
1884
+	 * @throws RuntimeException
1885
+	 * @throws DomainException
1886
+	 */
1887
+	protected function decline_registration($notify = false)
1888
+	{
1889
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1890
+	}
1891
+
1892
+
1893
+	/**
1894
+	 * cancel_registration
1895
+	 *
1896
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1897
+	 * @return void
1898
+	 * @throws EE_Error
1899
+	 * @throws EntityNotFoundException
1900
+	 * @throws InvalidArgumentException
1901
+	 * @throws InvalidDataTypeException
1902
+	 * @throws InvalidInterfaceException
1903
+	 * @throws ReflectionException
1904
+	 * @throws RuntimeException
1905
+	 * @throws DomainException
1906
+	 */
1907
+	protected function cancel_registration($notify = false)
1908
+	{
1909
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1910
+	}
1911
+
1912
+
1913
+	/**
1914
+	 * not_approve_registration
1915
+	 *
1916
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1917
+	 * @return void
1918
+	 * @throws EE_Error
1919
+	 * @throws EntityNotFoundException
1920
+	 * @throws InvalidArgumentException
1921
+	 * @throws InvalidDataTypeException
1922
+	 * @throws InvalidInterfaceException
1923
+	 * @throws ReflectionException
1924
+	 * @throws RuntimeException
1925
+	 * @throws DomainException
1926
+	 */
1927
+	protected function not_approve_registration($notify = false)
1928
+	{
1929
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1930
+	}
1931
+
1932
+
1933
+	/**
1934
+	 * decline_registration
1935
+	 *
1936
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1937
+	 * @return void
1938
+	 * @throws EE_Error
1939
+	 * @throws EntityNotFoundException
1940
+	 * @throws InvalidArgumentException
1941
+	 * @throws InvalidDataTypeException
1942
+	 * @throws InvalidInterfaceException
1943
+	 * @throws ReflectionException
1944
+	 * @throws RuntimeException
1945
+	 * @throws DomainException
1946
+	 */
1947
+	protected function pending_registration($notify = false)
1948
+	{
1949
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1950
+	}
1951
+
1952
+
1953
+	/**
1954
+	 * waitlist_registration
1955
+	 *
1956
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1957
+	 * @return void
1958
+	 * @throws EE_Error
1959
+	 * @throws EntityNotFoundException
1960
+	 * @throws InvalidArgumentException
1961
+	 * @throws InvalidDataTypeException
1962
+	 * @throws InvalidInterfaceException
1963
+	 * @throws ReflectionException
1964
+	 * @throws RuntimeException
1965
+	 * @throws DomainException
1966
+	 */
1967
+	protected function wait_list_registration($notify = false)
1968
+	{
1969
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1970
+	}
1971
+
1972
+
1973
+	/**
1974
+	 * generates HTML for the Registration main meta box
1975
+	 *
1976
+	 * @return void
1977
+	 * @throws DomainException
1978
+	 * @throws EE_Error
1979
+	 * @throws InvalidArgumentException
1980
+	 * @throws InvalidDataTypeException
1981
+	 * @throws InvalidInterfaceException
1982
+	 * @throws ReflectionException
1983
+	 * @throws EntityNotFoundException
1984
+	 */
1985
+	public function _reg_details_meta_box()
1986
+	{
1987
+		EEH_Autoloader::register_line_item_display_autoloaders();
1988
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1989
+		EE_Registry::instance()->load_helper('Line_Item');
1990
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1991
+			: EE_Transaction::new_instance();
1992
+		$this->_session = $transaction->session_data();
1993
+		$filters        = new EE_Line_Item_Filter_Collection();
1994
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1995
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
1996
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
1997
+			$filters,
1998
+			$transaction->total_line_item()
1999
+		);
2000
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2001
+		$line_item_display                       = new EE_Line_Item_Display(
2002
+			'reg_admin_table',
2003
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2004
+		);
2005
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2006
+			$filtered_line_item_tree,
2007
+			['EE_Registration' => $this->_registration]
2008
+		);
2009
+		$attendee                                = $this->_registration->attendee();
2010
+		if (
2011
+			EE_Registry::instance()->CAP->current_user_can(
2012
+				'ee_read_transaction',
2013
+				'espresso_transactions_view_transaction'
2014
+			)
2015
+		) {
2016
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2017
+				EE_Admin_Page::add_query_args_and_nonce(
2018
+					[
2019
+						'action' => 'view_transaction',
2020
+						'TXN_ID' => $transaction->ID(),
2021
+					],
2022
+					TXN_ADMIN_URL
2023
+				),
2024
+				esc_html__(' View Transaction', 'event_espresso'),
2025
+				'button button--secondary right',
2026
+				'dashicons dashicons-cart'
2027
+			);
2028
+		} else {
2029
+			$this->_template_args['view_transaction_button'] = '';
2030
+		}
2031
+		if (
2032
+			$attendee instanceof EE_Attendee
2033
+			&& EE_Registry::instance()->CAP->current_user_can(
2034
+				'ee_send_message',
2035
+				'espresso_registrations_resend_registration'
2036
+			)
2037
+		) {
2038
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2039
+				EE_Admin_Page::add_query_args_and_nonce(
2040
+					[
2041
+						'action'      => 'resend_registration',
2042
+						'_REG_ID'     => $this->_registration->ID(),
2043
+						'redirect_to' => 'view_registration',
2044
+					],
2045
+					REG_ADMIN_URL
2046
+				),
2047
+				esc_html__(' Resend Registration', 'event_espresso'),
2048
+				'button button--secondary right',
2049
+				'dashicons dashicons-email-alt'
2050
+			);
2051
+		} else {
2052
+			$this->_template_args['resend_registration_button'] = '';
2053
+		}
2054
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2055
+		$payment                               = $transaction->get_first_related('Payment');
2056
+		$payment                               = ! $payment instanceof EE_Payment
2057
+			? EE_Payment::new_instance()
2058
+			: $payment;
2059
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2060
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2061
+			? EE_Payment_Method::new_instance()
2062
+			: $payment_method;
2063
+		$reg_details                           = [
2064
+			'payment_method'       => $payment_method->name(),
2065
+			'response_msg'         => $payment->gateway_response(),
2066
+			'registration_id'      => $this->_registration->get('REG_code'),
2067
+			'registration_session' => $this->_registration->session_ID(),
2068
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2069
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2070
+		];
2071
+		if (isset($reg_details['registration_id'])) {
2072
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2073
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2074
+				'Registration ID',
2075
+				'event_espresso'
2076
+			);
2077
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2078
+		}
2079
+		if (isset($reg_details['payment_method'])) {
2080
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2081
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2082
+				'Most Recent Payment Method',
2083
+				'event_espresso'
2084
+			);
2085
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2086
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2087
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2088
+				'Payment method response',
2089
+				'event_espresso'
2090
+			);
2091
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2092
+		}
2093
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2094
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2095
+			'Registration Session',
2096
+			'event_espresso'
2097
+		);
2098
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2099
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2100
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2101
+			'Registration placed from IP',
2102
+			'event_espresso'
2103
+		);
2104
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2105
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2106
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2107
+			'Registrant User Agent',
2108
+			'event_espresso'
2109
+		);
2110
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2111
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2112
+			[
2113
+				'action'   => 'default',
2114
+				'event_id' => $this->_registration->event_ID(),
2115
+			],
2116
+			REG_ADMIN_URL
2117
+		);
2118
+
2119
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2120
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2121
+
2122
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2123
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2124
+	}
2125
+
2126
+
2127
+	/**
2128
+	 * generates HTML for the Registration Questions meta box.
2129
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2130
+	 * otherwise uses new forms system
2131
+	 *
2132
+	 * @return void
2133
+	 * @throws DomainException
2134
+	 * @throws EE_Error
2135
+	 * @throws InvalidArgumentException
2136
+	 * @throws InvalidDataTypeException
2137
+	 * @throws InvalidInterfaceException
2138
+	 * @throws ReflectionException
2139
+	 */
2140
+	public function _reg_questions_meta_box()
2141
+	{
2142
+		// allow someone to override this method entirely
2143
+		if (
2144
+			apply_filters(
2145
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2146
+				true,
2147
+				$this,
2148
+				$this->_registration
2149
+			)
2150
+		) {
2151
+			$form = $this->_get_reg_custom_questions_form(
2152
+				$this->_registration->ID()
2153
+			);
2154
+
2155
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2156
+				? $form->get_html_and_js()
2157
+				: '';
2158
+
2159
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2160
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2161
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2162
+			EEH_Template::display_template($template_path, $this->_template_args);
2163
+		}
2164
+	}
2165
+
2166
+
2167
+	/**
2168
+	 * form_before_question_group
2169
+	 *
2170
+	 * @param string $output
2171
+	 * @return        string
2172
+	 * @deprecated    as of 4.8.32.rc.000
2173
+	 */
2174
+	public function form_before_question_group($output)
2175
+	{
2176
+		EE_Error::doing_it_wrong(
2177
+			__CLASS__ . '::' . __FUNCTION__,
2178
+			esc_html__(
2179
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2180
+				'event_espresso'
2181
+			),
2182
+			'4.8.32.rc.000'
2183
+		);
2184
+		return '
2185 2185
 	<table class="form-table ee-width-100">
2186 2186
 		<tbody>
2187 2187
 			';
2188
-    }
2189
-
2190
-
2191
-    /**
2192
-     * form_after_question_group
2193
-     *
2194
-     * @param string $output
2195
-     * @return        string
2196
-     * @deprecated    as of 4.8.32.rc.000
2197
-     */
2198
-    public function form_after_question_group($output)
2199
-    {
2200
-        EE_Error::doing_it_wrong(
2201
-            __CLASS__ . '::' . __FUNCTION__,
2202
-            esc_html__(
2203
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2204
-                'event_espresso'
2205
-            ),
2206
-            '4.8.32.rc.000'
2207
-        );
2208
-        return '
2188
+	}
2189
+
2190
+
2191
+	/**
2192
+	 * form_after_question_group
2193
+	 *
2194
+	 * @param string $output
2195
+	 * @return        string
2196
+	 * @deprecated    as of 4.8.32.rc.000
2197
+	 */
2198
+	public function form_after_question_group($output)
2199
+	{
2200
+		EE_Error::doing_it_wrong(
2201
+			__CLASS__ . '::' . __FUNCTION__,
2202
+			esc_html__(
2203
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2204
+				'event_espresso'
2205
+			),
2206
+			'4.8.32.rc.000'
2207
+		);
2208
+		return '
2209 2209
 			<tr class="hide-if-no-js">
2210 2210
 				<th> </th>
2211 2211
 				<td class="reg-admin-edit-attendee-question-td">
2212 2212
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2213
-               . esc_attr__('click to edit question', 'event_espresso')
2214
-               . '">
2213
+			   . esc_attr__('click to edit question', 'event_espresso')
2214
+			   . '">
2215 2215
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2216
-               . esc_html__('edit the above question group', 'event_espresso')
2217
-               . '</span>
2216
+			   . esc_html__('edit the above question group', 'event_espresso')
2217
+			   . '</span>
2218 2218
 						<div class="dashicons dashicons-edit"></div>
2219 2219
 					</a>
2220 2220
 				</td>
@@ -2222,636 +2222,636 @@  discard block
 block discarded – undo
2222 2222
 		</tbody>
2223 2223
 	</table>
2224 2224
 ';
2225
-    }
2226
-
2227
-
2228
-    /**
2229
-     * form_form_field_label_wrap
2230
-     *
2231
-     * @param string $label
2232
-     * @return        string
2233
-     * @deprecated    as of 4.8.32.rc.000
2234
-     */
2235
-    public function form_form_field_label_wrap($label)
2236
-    {
2237
-        EE_Error::doing_it_wrong(
2238
-            __CLASS__ . '::' . __FUNCTION__,
2239
-            esc_html__(
2240
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2241
-                'event_espresso'
2242
-            ),
2243
-            '4.8.32.rc.000'
2244
-        );
2245
-        return '
2225
+	}
2226
+
2227
+
2228
+	/**
2229
+	 * form_form_field_label_wrap
2230
+	 *
2231
+	 * @param string $label
2232
+	 * @return        string
2233
+	 * @deprecated    as of 4.8.32.rc.000
2234
+	 */
2235
+	public function form_form_field_label_wrap($label)
2236
+	{
2237
+		EE_Error::doing_it_wrong(
2238
+			__CLASS__ . '::' . __FUNCTION__,
2239
+			esc_html__(
2240
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2241
+				'event_espresso'
2242
+			),
2243
+			'4.8.32.rc.000'
2244
+		);
2245
+		return '
2246 2246
 			<tr>
2247 2247
 				<th>
2248 2248
 					' . $label . '
2249 2249
 				</th>';
2250
-    }
2251
-
2252
-
2253
-    /**
2254
-     * form_form_field_input__wrap
2255
-     *
2256
-     * @param string $input
2257
-     * @return        string
2258
-     * @deprecated    as of 4.8.32.rc.000
2259
-     */
2260
-    public function form_form_field_input__wrap($input)
2261
-    {
2262
-        EE_Error::doing_it_wrong(
2263
-            __CLASS__ . '::' . __FUNCTION__,
2264
-            esc_html__(
2265
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
-                'event_espresso'
2267
-            ),
2268
-            '4.8.32.rc.000'
2269
-        );
2270
-        return '
2250
+	}
2251
+
2252
+
2253
+	/**
2254
+	 * form_form_field_input__wrap
2255
+	 *
2256
+	 * @param string $input
2257
+	 * @return        string
2258
+	 * @deprecated    as of 4.8.32.rc.000
2259
+	 */
2260
+	public function form_form_field_input__wrap($input)
2261
+	{
2262
+		EE_Error::doing_it_wrong(
2263
+			__CLASS__ . '::' . __FUNCTION__,
2264
+			esc_html__(
2265
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
+				'event_espresso'
2267
+			),
2268
+			'4.8.32.rc.000'
2269
+		);
2270
+		return '
2271 2271
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2272 2272
 					' . $input . '
2273 2273
 				</td>
2274 2274
 			</tr>';
2275
-    }
2276
-
2277
-
2278
-    /**
2279
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2280
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2281
-     * to display the page
2282
-     *
2283
-     * @return void
2284
-     * @throws EE_Error
2285
-     * @throws InvalidArgumentException
2286
-     * @throws InvalidDataTypeException
2287
-     * @throws InvalidInterfaceException
2288
-     * @throws ReflectionException
2289
-     */
2290
-    protected function _update_attendee_registration_form()
2291
-    {
2292
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2293
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2294
-            $REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2295
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2296
-            if ($success) {
2297
-                $what  = esc_html__('Registration Form', 'event_espresso');
2298
-                $route = $REG_ID
2299
-                    ? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2300
-                    : ['action' => 'default'];
2301
-                $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2302
-            }
2303
-        }
2304
-    }
2305
-
2306
-
2307
-    /**
2308
-     * Gets the form for saving registrations custom questions (if done
2309
-     * previously retrieves the cached form object, which may have validation errors in it)
2310
-     *
2311
-     * @param int $REG_ID
2312
-     * @return EE_Registration_Custom_Questions_Form
2313
-     * @throws EE_Error
2314
-     * @throws InvalidArgumentException
2315
-     * @throws InvalidDataTypeException
2316
-     * @throws InvalidInterfaceException
2317
-     * @throws ReflectionException
2318
-     */
2319
-    protected function _get_reg_custom_questions_form($REG_ID)
2320
-    {
2321
-        if (! $this->_reg_custom_questions_form) {
2322
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2323
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2324
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2325
-            );
2326
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2327
-        }
2328
-        return $this->_reg_custom_questions_form;
2329
-    }
2330
-
2331
-
2332
-    /**
2333
-     * Saves
2334
-     *
2335
-     * @param bool $REG_ID
2336
-     * @return bool
2337
-     * @throws EE_Error
2338
-     * @throws InvalidArgumentException
2339
-     * @throws InvalidDataTypeException
2340
-     * @throws InvalidInterfaceException
2341
-     * @throws ReflectionException
2342
-     */
2343
-    private function _save_reg_custom_questions_form($REG_ID = 0)
2344
-    {
2345
-        if (! $REG_ID) {
2346
-            EE_Error::add_error(
2347
-                esc_html__(
2348
-                    'An error occurred. No registration ID was received.',
2349
-                    'event_espresso'
2350
-                ),
2351
-                __FILE__,
2352
-                __FUNCTION__,
2353
-                __LINE__
2354
-            );
2355
-        }
2356
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2357
-        $form->receive_form_submission($this->request->requestParams());
2358
-        $success = false;
2359
-        if ($form->is_valid()) {
2360
-            foreach ($form->subforms() as $question_group_form) {
2361
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2362
-                    $where_conditions    = [
2363
-                        'QST_ID' => $question_id,
2364
-                        'REG_ID' => $REG_ID,
2365
-                    ];
2366
-                    $possibly_new_values = [
2367
-                        'ANS_value' => $input->normalized_value(),
2368
-                    ];
2369
-                    $answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2370
-                    if ($answer instanceof EE_Answer) {
2371
-                        $success = $answer->save($possibly_new_values);
2372
-                    } else {
2373
-                        // insert it then
2374
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2375
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2376
-                        $success     = $answer->save();
2377
-                    }
2378
-                }
2379
-            }
2380
-        } else {
2381
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2382
-        }
2383
-        return $success;
2384
-    }
2385
-
2386
-
2387
-    /**
2388
-     * generates HTML for the Registration main meta box
2389
-     *
2390
-     * @return void
2391
-     * @throws DomainException
2392
-     * @throws EE_Error
2393
-     * @throws InvalidArgumentException
2394
-     * @throws InvalidDataTypeException
2395
-     * @throws InvalidInterfaceException
2396
-     * @throws ReflectionException
2397
-     */
2398
-    public function _reg_attendees_meta_box()
2399
-    {
2400
-        $REG = $this->getRegistrationModel();
2401
-        // get all other registrations on this transaction, and cache
2402
-        // the attendees for them so we don't have to run another query using force_join
2403
-        $registrations                           = $REG->get_all(
2404
-            [
2405
-                [
2406
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2407
-                    'REG_ID' => ['!=', $this->_registration->ID()],
2408
-                ],
2409
-                'force_join'               => ['Attendee'],
2410
-                'default_where_conditions' => 'other_models_only',
2411
-            ]
2412
-        );
2413
-        $this->_template_args['attendees']       = [];
2414
-        $this->_template_args['attendee_notice'] = '';
2415
-        if (
2416
-            empty($registrations)
2417
-            || (is_array($registrations)
2418
-                && ! EEH_Array::get_one_item_from_array($registrations))
2419
-        ) {
2420
-            EE_Error::add_error(
2421
-                esc_html__(
2422
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2423
-                    'event_espresso'
2424
-                ),
2425
-                __FILE__,
2426
-                __FUNCTION__,
2427
-                __LINE__
2428
-            );
2429
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2430
-        } else {
2431
-            $att_nmbr = 1;
2432
-            foreach ($registrations as $registration) {
2433
-                /* @var $registration EE_Registration */
2434
-                $attendee                                                      = $registration->attendee()
2435
-                    ? $registration->attendee()
2436
-                    : $this->getAttendeeModel()->create_default_object();
2437
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2438
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2439
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2440
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2441
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2442
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2443
-                    ', ',
2444
-                    $attendee->full_address_as_array()
2445
-                );
2446
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2447
-                    [
2448
-                        'action' => 'edit_attendee',
2449
-                        'post'   => $attendee->ID(),
2450
-                    ],
2451
-                    REG_ADMIN_URL
2452
-                );
2453
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2454
-                    $registration->event_obj() instanceof EE_Event
2455
-                        ? $registration->event_obj()->name()
2456
-                        : '';
2457
-                $att_nmbr++;
2458
-            }
2459
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2460
-        }
2461
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2462
-        EEH_Template::display_template($template_path, $this->_template_args);
2463
-    }
2464
-
2465
-
2466
-    /**
2467
-     * generates HTML for the Edit Registration side meta box
2468
-     *
2469
-     * @return void
2470
-     * @throws DomainException
2471
-     * @throws EE_Error
2472
-     * @throws InvalidArgumentException
2473
-     * @throws InvalidDataTypeException
2474
-     * @throws InvalidInterfaceException
2475
-     * @throws ReflectionException
2476
-     */
2477
-    public function _reg_registrant_side_meta_box()
2478
-    {
2479
-        /*@var $attendee EE_Attendee */
2480
-        $att_check = $this->_registration->attendee();
2481
-        $attendee  = $att_check instanceof EE_Attendee
2482
-            ? $att_check
2483
-            : $this->getAttendeeModel()->create_default_object();
2484
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2485
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2486
-        // primary registration object (that way we know if we need to show create button or not)
2487
-        if (! $this->_registration->is_primary_registrant()) {
2488
-            $primary_registration = $this->_registration->get_primary_registration();
2489
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2490
-                : null;
2491
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2492
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2493
-                // custom attendee object so let's not worry about the primary reg.
2494
-                $primary_registration = null;
2495
-            }
2496
-        } else {
2497
-            $primary_registration = null;
2498
-        }
2499
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2500
-        $this->_template_args['fname']             = $attendee->fname();
2501
-        $this->_template_args['lname']             = $attendee->lname();
2502
-        $this->_template_args['email']             = $attendee->email();
2503
-        $this->_template_args['phone']             = $attendee->phone();
2504
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2505
-        // edit link
2506
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2507
-            [
2508
-                'action' => 'edit_attendee',
2509
-                'post'   => $attendee->ID(),
2510
-            ],
2511
-            REG_ADMIN_URL
2512
-        );
2513
-        $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2514
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2515
-        // create link
2516
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2517
-            ? EE_Admin_Page::add_query_args_and_nonce(
2518
-                [
2519
-                    'action'  => 'duplicate_attendee',
2520
-                    '_REG_ID' => $this->_registration->ID(),
2521
-                ],
2522
-                REG_ADMIN_URL
2523
-            ) : '';
2524
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2525
-        $this->_template_args['att_check'] = $att_check;
2526
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2527
-        EEH_Template::display_template($template_path, $this->_template_args);
2528
-    }
2529
-
2530
-
2531
-    /**
2532
-     * trash or restore registrations
2533
-     *
2534
-     * @param boolean $trash whether to archive or restore
2535
-     * @return void
2536
-     * @throws EE_Error
2537
-     * @throws InvalidArgumentException
2538
-     * @throws InvalidDataTypeException
2539
-     * @throws InvalidInterfaceException
2540
-     * @throws RuntimeException
2541
-     */
2542
-    protected function _trash_or_restore_registrations($trash = true)
2543
-    {
2544
-        // if empty _REG_ID then get out because there's nothing to do
2545
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2546
-        if (empty($REG_IDs)) {
2547
-            EE_Error::add_error(
2548
-                sprintf(
2549
-                    esc_html__(
2550
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2551
-                        'event_espresso'
2552
-                    ),
2553
-                    $trash ? 'trash' : 'restore'
2554
-                ),
2555
-                __FILE__,
2556
-                __LINE__,
2557
-                __FUNCTION__
2558
-            );
2559
-            $this->_redirect_after_action(false, '', '', [], true);
2560
-        }
2561
-        $success        = 0;
2562
-        $overwrite_msgs = false;
2563
-        // Checkboxes
2564
-        $reg_count = count($REG_IDs);
2565
-        // cycle thru checkboxes
2566
-        foreach ($REG_IDs as $REG_ID) {
2567
-            /** @var EE_Registration $REG */
2568
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2569
-            $payments = $REG->registration_payments();
2570
-            if (! empty($payments)) {
2571
-                $name           = $REG->attendee() instanceof EE_Attendee
2572
-                    ? $REG->attendee()->full_name()
2573
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2574
-                $overwrite_msgs = true;
2575
-                EE_Error::add_error(
2576
-                    sprintf(
2577
-                        esc_html__(
2578
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2579
-                            'event_espresso'
2580
-                        ),
2581
-                        $name
2582
-                    ),
2583
-                    __FILE__,
2584
-                    __FUNCTION__,
2585
-                    __LINE__
2586
-                );
2587
-                // can't trash this registration because it has payments.
2588
-                continue;
2589
-            }
2590
-            $updated = $trash ? $REG->delete() : $REG->restore();
2591
-            if ($updated) {
2592
-                $success++;
2593
-            }
2594
-        }
2595
-        $this->_redirect_after_action(
2596
-            $success === $reg_count, // were ALL registrations affected?
2597
-            $success > 1
2598
-                ? esc_html__('Registrations', 'event_espresso')
2599
-                : esc_html__('Registration', 'event_espresso'),
2600
-            $trash
2601
-                ? esc_html__('moved to the trash', 'event_espresso')
2602
-                : esc_html__('restored', 'event_espresso'),
2603
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2604
-            $overwrite_msgs
2605
-        );
2606
-    }
2607
-
2608
-
2609
-    /**
2610
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2611
-     * registration but also.
2612
-     * 1. Removing relations to EE_Attendee
2613
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2614
-     * ALSO trashed.
2615
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2616
-     * 4. Removing relationships between all tickets and the related registrations
2617
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2618
-     * 6. Deleting permanently any related Checkins.
2619
-     *
2620
-     * @return void
2621
-     * @throws EE_Error
2622
-     * @throws InvalidArgumentException
2623
-     * @throws InvalidDataTypeException
2624
-     * @throws InvalidInterfaceException
2625
-     * @throws ReflectionException
2626
-     */
2627
-    protected function _delete_registrations()
2628
-    {
2629
-        $REG_MDL = $this->getRegistrationModel();
2630
-        $success = 0;
2631
-        // Checkboxes
2632
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2633
-
2634
-        if (! empty($REG_IDs)) {
2635
-            // if array has more than one element than success message should be plural
2636
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2637
-            // cycle thru checkboxes
2638
-            foreach ($REG_IDs as $REG_ID) {
2639
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2640
-                if (! $REG instanceof EE_Registration) {
2641
-                    continue;
2642
-                }
2643
-                $deleted = $this->_delete_registration($REG);
2644
-                if (! $deleted) {
2645
-                    $success = 0;
2646
-                }
2647
-            }
2648
-        }
2649
-
2650
-        $what        = $success > 1
2651
-            ? esc_html__('Registrations', 'event_espresso')
2652
-            : esc_html__('Registration', 'event_espresso');
2653
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2654
-        $this->_redirect_after_action(
2655
-            $success,
2656
-            $what,
2657
-            $action_desc,
2658
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2659
-            true
2660
-        );
2661
-    }
2662
-
2663
-
2664
-    /**
2665
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2666
-     * models get affected.
2667
-     *
2668
-     * @param EE_Registration $REG registration to be deleted permanently
2669
-     * @return bool true = successful deletion, false = fail.
2670
-     * @throws EE_Error
2671
-     * @throws InvalidArgumentException
2672
-     * @throws InvalidDataTypeException
2673
-     * @throws InvalidInterfaceException
2674
-     * @throws ReflectionException
2675
-     */
2676
-    protected function _delete_registration(EE_Registration $REG)
2677
-    {
2678
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2679
-        // registrations on the transaction that are NOT trashed.
2680
-        $TXN = $REG->get_first_related('Transaction');
2681
-        if (! $TXN instanceof EE_Transaction) {
2682
-            EE_Error::add_error(
2683
-                sprintf(
2684
-                    esc_html__(
2685
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2686
-                        'event_espresso'
2687
-                    ),
2688
-                    $REG->id()
2689
-                ),
2690
-                __FILE__,
2691
-                __FUNCTION__,
2692
-                __LINE__
2693
-            );
2694
-            return false;
2695
-        }
2696
-        $REGS        = $TXN->get_many_related('Registration');
2697
-        $all_trashed = true;
2698
-        foreach ($REGS as $registration) {
2699
-            if (! $registration->get('REG_deleted')) {
2700
-                $all_trashed = false;
2701
-            }
2702
-        }
2703
-        if (! $all_trashed) {
2704
-            EE_Error::add_error(
2705
-                esc_html__(
2706
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2707
-                    'event_espresso'
2708
-                ),
2709
-                __FILE__,
2710
-                __FUNCTION__,
2711
-                __LINE__
2712
-            );
2713
-            return false;
2714
-        }
2715
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2716
-        // separately from THIS one).
2717
-        foreach ($REGS as $registration) {
2718
-            // delete related answers
2719
-            $registration->delete_related_permanently('Answer');
2720
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2721
-            $attendee = $registration->get_first_related('Attendee');
2722
-            if ($attendee instanceof EE_Attendee) {
2723
-                $registration->_remove_relation_to($attendee, 'Attendee');
2724
-            }
2725
-            // now remove relationships to tickets on this registration.
2726
-            $registration->_remove_relations('Ticket');
2727
-            // now delete permanently the checkins related to this registration.
2728
-            $registration->delete_related_permanently('Checkin');
2729
-            if ($registration->ID() === $REG->ID()) {
2730
-                continue;
2731
-            } //we don't want to delete permanently the existing registration just yet.
2732
-            // remove relation to transaction for these registrations if NOT the existing registrations
2733
-            $registration->_remove_relations('Transaction');
2734
-            // delete permanently any related messages.
2735
-            $registration->delete_related_permanently('Message');
2736
-            // now delete this registration permanently
2737
-            $registration->delete_permanently();
2738
-        }
2739
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2740
-        // (the transaction and line items should be all that's left).
2741
-        // delete the line items related to the transaction for this registration.
2742
-        $TXN->delete_related_permanently('Line_Item');
2743
-        // we need to remove all the relationships on the transaction
2744
-        $TXN->delete_related_permanently('Payment');
2745
-        $TXN->delete_related_permanently('Extra_Meta');
2746
-        $TXN->delete_related_permanently('Message');
2747
-        // now we can delete this REG permanently (and the transaction of course)
2748
-        $REG->delete_related_permanently('Transaction');
2749
-        return $REG->delete_permanently();
2750
-    }
2751
-
2752
-
2753
-    /**
2754
-     *    generates HTML for the Register New Attendee Admin page
2755
-     *
2756
-     * @throws DomainException
2757
-     * @throws EE_Error
2758
-     * @throws InvalidArgumentException
2759
-     * @throws InvalidDataTypeException
2760
-     * @throws InvalidInterfaceException
2761
-     * @throws ReflectionException
2762
-     */
2763
-    public function new_registration()
2764
-    {
2765
-        if (! $this->_set_reg_event()) {
2766
-            throw new EE_Error(
2767
-                esc_html__(
2768
-                    'Unable to continue with registering because there is no Event ID in the request',
2769
-                    'event_espresso'
2770
-                )
2771
-            );
2772
-        }
2773
-        /** @var CurrentPage $current_page */
2774
-        $current_page = $this->loader->getShared(CurrentPage::class);
2775
-        $current_page->setEspressoPage(true);
2776
-        // gotta start with a clean slate if we're not coming here via ajax
2777
-        if (
2778
-            ! $this->request->isAjax()
2779
-            && (
2780
-                ! $this->request->requestParamIsSet('processing_registration')
2781
-                || $this->request->requestParamIsSet('step_error')
2782
-            )
2783
-        ) {
2784
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2785
-        }
2786
-        $this->_template_args['event_name'] = '';
2787
-        // event name
2788
-        if ($this->_reg_event) {
2789
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2790
-            $edit_event_url                     = self::add_query_args_and_nonce(
2791
-                [
2792
-                    'action' => 'edit',
2793
-                    'post'   => $this->_reg_event->ID(),
2794
-                ],
2795
-                EVENTS_ADMIN_URL
2796
-            );
2797
-            $edit_event_lnk                     = '<a href="'
2798
-                                                  . $edit_event_url
2799
-                                                  . '" title="'
2800
-                                                  . esc_attr__('Edit ', 'event_espresso')
2801
-                                                  . $this->_reg_event->name()
2802
-                                                  . '">'
2803
-                                                  . esc_html__('Edit Event', 'event_espresso')
2804
-                                                  . '</a>';
2805
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2806
-                                                   . $edit_event_lnk
2807
-                                                   . '</span>';
2808
-        }
2809
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2810
-        if ($this->request->isAjax()) {
2811
-            $this->_return_json();
2812
-        }
2813
-        // grab header
2814
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2815
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2816
-            $template_path,
2817
-            $this->_template_args,
2818
-            true
2819
-        );
2820
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2821
-        // the details template wrapper
2822
-        $this->display_admin_page_with_sidebar();
2823
-    }
2824
-
2825
-
2826
-    /**
2827
-     * This returns the content for a registration step
2828
-     *
2829
-     * @return string html
2830
-     * @throws DomainException
2831
-     * @throws EE_Error
2832
-     * @throws InvalidArgumentException
2833
-     * @throws InvalidDataTypeException
2834
-     * @throws InvalidInterfaceException
2835
-     * @throws ReflectionException
2836
-     */
2837
-    protected function _get_registration_step_content()
2838
-    {
2839
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2840
-            $warning_msg = sprintf(
2841
-                esc_html__(
2842
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2843
-                    'event_espresso'
2844
-                ),
2845
-                '<br />',
2846
-                '<h3 class="important-notice">',
2847
-                '</h3>',
2848
-                '<div class="float-right">',
2849
-                '<span id="redirect_timer" class="important-notice">30</span>',
2850
-                '</div>',
2851
-                '<b>',
2852
-                '</b>'
2853
-            );
2854
-            return '
2275
+	}
2276
+
2277
+
2278
+	/**
2279
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2280
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2281
+	 * to display the page
2282
+	 *
2283
+	 * @return void
2284
+	 * @throws EE_Error
2285
+	 * @throws InvalidArgumentException
2286
+	 * @throws InvalidDataTypeException
2287
+	 * @throws InvalidInterfaceException
2288
+	 * @throws ReflectionException
2289
+	 */
2290
+	protected function _update_attendee_registration_form()
2291
+	{
2292
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2293
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2294
+			$REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2295
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2296
+			if ($success) {
2297
+				$what  = esc_html__('Registration Form', 'event_espresso');
2298
+				$route = $REG_ID
2299
+					? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2300
+					: ['action' => 'default'];
2301
+				$this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2302
+			}
2303
+		}
2304
+	}
2305
+
2306
+
2307
+	/**
2308
+	 * Gets the form for saving registrations custom questions (if done
2309
+	 * previously retrieves the cached form object, which may have validation errors in it)
2310
+	 *
2311
+	 * @param int $REG_ID
2312
+	 * @return EE_Registration_Custom_Questions_Form
2313
+	 * @throws EE_Error
2314
+	 * @throws InvalidArgumentException
2315
+	 * @throws InvalidDataTypeException
2316
+	 * @throws InvalidInterfaceException
2317
+	 * @throws ReflectionException
2318
+	 */
2319
+	protected function _get_reg_custom_questions_form($REG_ID)
2320
+	{
2321
+		if (! $this->_reg_custom_questions_form) {
2322
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2323
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2324
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2325
+			);
2326
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2327
+		}
2328
+		return $this->_reg_custom_questions_form;
2329
+	}
2330
+
2331
+
2332
+	/**
2333
+	 * Saves
2334
+	 *
2335
+	 * @param bool $REG_ID
2336
+	 * @return bool
2337
+	 * @throws EE_Error
2338
+	 * @throws InvalidArgumentException
2339
+	 * @throws InvalidDataTypeException
2340
+	 * @throws InvalidInterfaceException
2341
+	 * @throws ReflectionException
2342
+	 */
2343
+	private function _save_reg_custom_questions_form($REG_ID = 0)
2344
+	{
2345
+		if (! $REG_ID) {
2346
+			EE_Error::add_error(
2347
+				esc_html__(
2348
+					'An error occurred. No registration ID was received.',
2349
+					'event_espresso'
2350
+				),
2351
+				__FILE__,
2352
+				__FUNCTION__,
2353
+				__LINE__
2354
+			);
2355
+		}
2356
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2357
+		$form->receive_form_submission($this->request->requestParams());
2358
+		$success = false;
2359
+		if ($form->is_valid()) {
2360
+			foreach ($form->subforms() as $question_group_form) {
2361
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2362
+					$where_conditions    = [
2363
+						'QST_ID' => $question_id,
2364
+						'REG_ID' => $REG_ID,
2365
+					];
2366
+					$possibly_new_values = [
2367
+						'ANS_value' => $input->normalized_value(),
2368
+					];
2369
+					$answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2370
+					if ($answer instanceof EE_Answer) {
2371
+						$success = $answer->save($possibly_new_values);
2372
+					} else {
2373
+						// insert it then
2374
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2375
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2376
+						$success     = $answer->save();
2377
+					}
2378
+				}
2379
+			}
2380
+		} else {
2381
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2382
+		}
2383
+		return $success;
2384
+	}
2385
+
2386
+
2387
+	/**
2388
+	 * generates HTML for the Registration main meta box
2389
+	 *
2390
+	 * @return void
2391
+	 * @throws DomainException
2392
+	 * @throws EE_Error
2393
+	 * @throws InvalidArgumentException
2394
+	 * @throws InvalidDataTypeException
2395
+	 * @throws InvalidInterfaceException
2396
+	 * @throws ReflectionException
2397
+	 */
2398
+	public function _reg_attendees_meta_box()
2399
+	{
2400
+		$REG = $this->getRegistrationModel();
2401
+		// get all other registrations on this transaction, and cache
2402
+		// the attendees for them so we don't have to run another query using force_join
2403
+		$registrations                           = $REG->get_all(
2404
+			[
2405
+				[
2406
+					'TXN_ID' => $this->_registration->transaction_ID(),
2407
+					'REG_ID' => ['!=', $this->_registration->ID()],
2408
+				],
2409
+				'force_join'               => ['Attendee'],
2410
+				'default_where_conditions' => 'other_models_only',
2411
+			]
2412
+		);
2413
+		$this->_template_args['attendees']       = [];
2414
+		$this->_template_args['attendee_notice'] = '';
2415
+		if (
2416
+			empty($registrations)
2417
+			|| (is_array($registrations)
2418
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2419
+		) {
2420
+			EE_Error::add_error(
2421
+				esc_html__(
2422
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2423
+					'event_espresso'
2424
+				),
2425
+				__FILE__,
2426
+				__FUNCTION__,
2427
+				__LINE__
2428
+			);
2429
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2430
+		} else {
2431
+			$att_nmbr = 1;
2432
+			foreach ($registrations as $registration) {
2433
+				/* @var $registration EE_Registration */
2434
+				$attendee                                                      = $registration->attendee()
2435
+					? $registration->attendee()
2436
+					: $this->getAttendeeModel()->create_default_object();
2437
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2438
+				$this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2439
+				$this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2440
+				$this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2441
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2442
+				$this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2443
+					', ',
2444
+					$attendee->full_address_as_array()
2445
+				);
2446
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2447
+					[
2448
+						'action' => 'edit_attendee',
2449
+						'post'   => $attendee->ID(),
2450
+					],
2451
+					REG_ADMIN_URL
2452
+				);
2453
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2454
+					$registration->event_obj() instanceof EE_Event
2455
+						? $registration->event_obj()->name()
2456
+						: '';
2457
+				$att_nmbr++;
2458
+			}
2459
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2460
+		}
2461
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2462
+		EEH_Template::display_template($template_path, $this->_template_args);
2463
+	}
2464
+
2465
+
2466
+	/**
2467
+	 * generates HTML for the Edit Registration side meta box
2468
+	 *
2469
+	 * @return void
2470
+	 * @throws DomainException
2471
+	 * @throws EE_Error
2472
+	 * @throws InvalidArgumentException
2473
+	 * @throws InvalidDataTypeException
2474
+	 * @throws InvalidInterfaceException
2475
+	 * @throws ReflectionException
2476
+	 */
2477
+	public function _reg_registrant_side_meta_box()
2478
+	{
2479
+		/*@var $attendee EE_Attendee */
2480
+		$att_check = $this->_registration->attendee();
2481
+		$attendee  = $att_check instanceof EE_Attendee
2482
+			? $att_check
2483
+			: $this->getAttendeeModel()->create_default_object();
2484
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2485
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2486
+		// primary registration object (that way we know if we need to show create button or not)
2487
+		if (! $this->_registration->is_primary_registrant()) {
2488
+			$primary_registration = $this->_registration->get_primary_registration();
2489
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2490
+				: null;
2491
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2492
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2493
+				// custom attendee object so let's not worry about the primary reg.
2494
+				$primary_registration = null;
2495
+			}
2496
+		} else {
2497
+			$primary_registration = null;
2498
+		}
2499
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2500
+		$this->_template_args['fname']             = $attendee->fname();
2501
+		$this->_template_args['lname']             = $attendee->lname();
2502
+		$this->_template_args['email']             = $attendee->email();
2503
+		$this->_template_args['phone']             = $attendee->phone();
2504
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2505
+		// edit link
2506
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2507
+			[
2508
+				'action' => 'edit_attendee',
2509
+				'post'   => $attendee->ID(),
2510
+			],
2511
+			REG_ADMIN_URL
2512
+		);
2513
+		$this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2514
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2515
+		// create link
2516
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2517
+			? EE_Admin_Page::add_query_args_and_nonce(
2518
+				[
2519
+					'action'  => 'duplicate_attendee',
2520
+					'_REG_ID' => $this->_registration->ID(),
2521
+				],
2522
+				REG_ADMIN_URL
2523
+			) : '';
2524
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2525
+		$this->_template_args['att_check'] = $att_check;
2526
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2527
+		EEH_Template::display_template($template_path, $this->_template_args);
2528
+	}
2529
+
2530
+
2531
+	/**
2532
+	 * trash or restore registrations
2533
+	 *
2534
+	 * @param boolean $trash whether to archive or restore
2535
+	 * @return void
2536
+	 * @throws EE_Error
2537
+	 * @throws InvalidArgumentException
2538
+	 * @throws InvalidDataTypeException
2539
+	 * @throws InvalidInterfaceException
2540
+	 * @throws RuntimeException
2541
+	 */
2542
+	protected function _trash_or_restore_registrations($trash = true)
2543
+	{
2544
+		// if empty _REG_ID then get out because there's nothing to do
2545
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2546
+		if (empty($REG_IDs)) {
2547
+			EE_Error::add_error(
2548
+				sprintf(
2549
+					esc_html__(
2550
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2551
+						'event_espresso'
2552
+					),
2553
+					$trash ? 'trash' : 'restore'
2554
+				),
2555
+				__FILE__,
2556
+				__LINE__,
2557
+				__FUNCTION__
2558
+			);
2559
+			$this->_redirect_after_action(false, '', '', [], true);
2560
+		}
2561
+		$success        = 0;
2562
+		$overwrite_msgs = false;
2563
+		// Checkboxes
2564
+		$reg_count = count($REG_IDs);
2565
+		// cycle thru checkboxes
2566
+		foreach ($REG_IDs as $REG_ID) {
2567
+			/** @var EE_Registration $REG */
2568
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2569
+			$payments = $REG->registration_payments();
2570
+			if (! empty($payments)) {
2571
+				$name           = $REG->attendee() instanceof EE_Attendee
2572
+					? $REG->attendee()->full_name()
2573
+					: esc_html__('Unknown Attendee', 'event_espresso');
2574
+				$overwrite_msgs = true;
2575
+				EE_Error::add_error(
2576
+					sprintf(
2577
+						esc_html__(
2578
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2579
+							'event_espresso'
2580
+						),
2581
+						$name
2582
+					),
2583
+					__FILE__,
2584
+					__FUNCTION__,
2585
+					__LINE__
2586
+				);
2587
+				// can't trash this registration because it has payments.
2588
+				continue;
2589
+			}
2590
+			$updated = $trash ? $REG->delete() : $REG->restore();
2591
+			if ($updated) {
2592
+				$success++;
2593
+			}
2594
+		}
2595
+		$this->_redirect_after_action(
2596
+			$success === $reg_count, // were ALL registrations affected?
2597
+			$success > 1
2598
+				? esc_html__('Registrations', 'event_espresso')
2599
+				: esc_html__('Registration', 'event_espresso'),
2600
+			$trash
2601
+				? esc_html__('moved to the trash', 'event_espresso')
2602
+				: esc_html__('restored', 'event_espresso'),
2603
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2604
+			$overwrite_msgs
2605
+		);
2606
+	}
2607
+
2608
+
2609
+	/**
2610
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2611
+	 * registration but also.
2612
+	 * 1. Removing relations to EE_Attendee
2613
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2614
+	 * ALSO trashed.
2615
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2616
+	 * 4. Removing relationships between all tickets and the related registrations
2617
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2618
+	 * 6. Deleting permanently any related Checkins.
2619
+	 *
2620
+	 * @return void
2621
+	 * @throws EE_Error
2622
+	 * @throws InvalidArgumentException
2623
+	 * @throws InvalidDataTypeException
2624
+	 * @throws InvalidInterfaceException
2625
+	 * @throws ReflectionException
2626
+	 */
2627
+	protected function _delete_registrations()
2628
+	{
2629
+		$REG_MDL = $this->getRegistrationModel();
2630
+		$success = 0;
2631
+		// Checkboxes
2632
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2633
+
2634
+		if (! empty($REG_IDs)) {
2635
+			// if array has more than one element than success message should be plural
2636
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2637
+			// cycle thru checkboxes
2638
+			foreach ($REG_IDs as $REG_ID) {
2639
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2640
+				if (! $REG instanceof EE_Registration) {
2641
+					continue;
2642
+				}
2643
+				$deleted = $this->_delete_registration($REG);
2644
+				if (! $deleted) {
2645
+					$success = 0;
2646
+				}
2647
+			}
2648
+		}
2649
+
2650
+		$what        = $success > 1
2651
+			? esc_html__('Registrations', 'event_espresso')
2652
+			: esc_html__('Registration', 'event_espresso');
2653
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2654
+		$this->_redirect_after_action(
2655
+			$success,
2656
+			$what,
2657
+			$action_desc,
2658
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2659
+			true
2660
+		);
2661
+	}
2662
+
2663
+
2664
+	/**
2665
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2666
+	 * models get affected.
2667
+	 *
2668
+	 * @param EE_Registration $REG registration to be deleted permanently
2669
+	 * @return bool true = successful deletion, false = fail.
2670
+	 * @throws EE_Error
2671
+	 * @throws InvalidArgumentException
2672
+	 * @throws InvalidDataTypeException
2673
+	 * @throws InvalidInterfaceException
2674
+	 * @throws ReflectionException
2675
+	 */
2676
+	protected function _delete_registration(EE_Registration $REG)
2677
+	{
2678
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2679
+		// registrations on the transaction that are NOT trashed.
2680
+		$TXN = $REG->get_first_related('Transaction');
2681
+		if (! $TXN instanceof EE_Transaction) {
2682
+			EE_Error::add_error(
2683
+				sprintf(
2684
+					esc_html__(
2685
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2686
+						'event_espresso'
2687
+					),
2688
+					$REG->id()
2689
+				),
2690
+				__FILE__,
2691
+				__FUNCTION__,
2692
+				__LINE__
2693
+			);
2694
+			return false;
2695
+		}
2696
+		$REGS        = $TXN->get_many_related('Registration');
2697
+		$all_trashed = true;
2698
+		foreach ($REGS as $registration) {
2699
+			if (! $registration->get('REG_deleted')) {
2700
+				$all_trashed = false;
2701
+			}
2702
+		}
2703
+		if (! $all_trashed) {
2704
+			EE_Error::add_error(
2705
+				esc_html__(
2706
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2707
+					'event_espresso'
2708
+				),
2709
+				__FILE__,
2710
+				__FUNCTION__,
2711
+				__LINE__
2712
+			);
2713
+			return false;
2714
+		}
2715
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2716
+		// separately from THIS one).
2717
+		foreach ($REGS as $registration) {
2718
+			// delete related answers
2719
+			$registration->delete_related_permanently('Answer');
2720
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2721
+			$attendee = $registration->get_first_related('Attendee');
2722
+			if ($attendee instanceof EE_Attendee) {
2723
+				$registration->_remove_relation_to($attendee, 'Attendee');
2724
+			}
2725
+			// now remove relationships to tickets on this registration.
2726
+			$registration->_remove_relations('Ticket');
2727
+			// now delete permanently the checkins related to this registration.
2728
+			$registration->delete_related_permanently('Checkin');
2729
+			if ($registration->ID() === $REG->ID()) {
2730
+				continue;
2731
+			} //we don't want to delete permanently the existing registration just yet.
2732
+			// remove relation to transaction for these registrations if NOT the existing registrations
2733
+			$registration->_remove_relations('Transaction');
2734
+			// delete permanently any related messages.
2735
+			$registration->delete_related_permanently('Message');
2736
+			// now delete this registration permanently
2737
+			$registration->delete_permanently();
2738
+		}
2739
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2740
+		// (the transaction and line items should be all that's left).
2741
+		// delete the line items related to the transaction for this registration.
2742
+		$TXN->delete_related_permanently('Line_Item');
2743
+		// we need to remove all the relationships on the transaction
2744
+		$TXN->delete_related_permanently('Payment');
2745
+		$TXN->delete_related_permanently('Extra_Meta');
2746
+		$TXN->delete_related_permanently('Message');
2747
+		// now we can delete this REG permanently (and the transaction of course)
2748
+		$REG->delete_related_permanently('Transaction');
2749
+		return $REG->delete_permanently();
2750
+	}
2751
+
2752
+
2753
+	/**
2754
+	 *    generates HTML for the Register New Attendee Admin page
2755
+	 *
2756
+	 * @throws DomainException
2757
+	 * @throws EE_Error
2758
+	 * @throws InvalidArgumentException
2759
+	 * @throws InvalidDataTypeException
2760
+	 * @throws InvalidInterfaceException
2761
+	 * @throws ReflectionException
2762
+	 */
2763
+	public function new_registration()
2764
+	{
2765
+		if (! $this->_set_reg_event()) {
2766
+			throw new EE_Error(
2767
+				esc_html__(
2768
+					'Unable to continue with registering because there is no Event ID in the request',
2769
+					'event_espresso'
2770
+				)
2771
+			);
2772
+		}
2773
+		/** @var CurrentPage $current_page */
2774
+		$current_page = $this->loader->getShared(CurrentPage::class);
2775
+		$current_page->setEspressoPage(true);
2776
+		// gotta start with a clean slate if we're not coming here via ajax
2777
+		if (
2778
+			! $this->request->isAjax()
2779
+			&& (
2780
+				! $this->request->requestParamIsSet('processing_registration')
2781
+				|| $this->request->requestParamIsSet('step_error')
2782
+			)
2783
+		) {
2784
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2785
+		}
2786
+		$this->_template_args['event_name'] = '';
2787
+		// event name
2788
+		if ($this->_reg_event) {
2789
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2790
+			$edit_event_url                     = self::add_query_args_and_nonce(
2791
+				[
2792
+					'action' => 'edit',
2793
+					'post'   => $this->_reg_event->ID(),
2794
+				],
2795
+				EVENTS_ADMIN_URL
2796
+			);
2797
+			$edit_event_lnk                     = '<a href="'
2798
+												  . $edit_event_url
2799
+												  . '" title="'
2800
+												  . esc_attr__('Edit ', 'event_espresso')
2801
+												  . $this->_reg_event->name()
2802
+												  . '">'
2803
+												  . esc_html__('Edit Event', 'event_espresso')
2804
+												  . '</a>';
2805
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2806
+												   . $edit_event_lnk
2807
+												   . '</span>';
2808
+		}
2809
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2810
+		if ($this->request->isAjax()) {
2811
+			$this->_return_json();
2812
+		}
2813
+		// grab header
2814
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2815
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2816
+			$template_path,
2817
+			$this->_template_args,
2818
+			true
2819
+		);
2820
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2821
+		// the details template wrapper
2822
+		$this->display_admin_page_with_sidebar();
2823
+	}
2824
+
2825
+
2826
+	/**
2827
+	 * This returns the content for a registration step
2828
+	 *
2829
+	 * @return string html
2830
+	 * @throws DomainException
2831
+	 * @throws EE_Error
2832
+	 * @throws InvalidArgumentException
2833
+	 * @throws InvalidDataTypeException
2834
+	 * @throws InvalidInterfaceException
2835
+	 * @throws ReflectionException
2836
+	 */
2837
+	protected function _get_registration_step_content()
2838
+	{
2839
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2840
+			$warning_msg = sprintf(
2841
+				esc_html__(
2842
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2843
+					'event_espresso'
2844
+				),
2845
+				'<br />',
2846
+				'<h3 class="important-notice">',
2847
+				'</h3>',
2848
+				'<div class="float-right">',
2849
+				'<span id="redirect_timer" class="important-notice">30</span>',
2850
+				'</div>',
2851
+				'<b>',
2852
+				'</b>'
2853
+			);
2854
+			return '
2855 2855
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2856 2856
 	<script >
2857 2857
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2864,844 +2864,844 @@  discard block
 block discarded – undo
2864 2864
 	        }
2865 2865
 	    }, 800 );
2866 2866
 	</script >';
2867
-        }
2868
-        $template_args = [
2869
-            'title'                    => '',
2870
-            'content'                  => '',
2871
-            'step_button_text'         => '',
2872
-            'show_notification_toggle' => false,
2873
-        ];
2874
-        // to indicate we're processing a new registration
2875
-        $hidden_fields = [
2876
-            'processing_registration' => [
2877
-                'type'  => 'hidden',
2878
-                'value' => 0,
2879
-            ],
2880
-            'event_id'                => [
2881
-                'type'  => 'hidden',
2882
-                'value' => $this->_reg_event->ID(),
2883
-            ],
2884
-        ];
2885
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2886
-        $cart = EE_Registry::instance()->SSN->cart();
2887
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2888
-        switch ($step) {
2889
-            case 'ticket':
2890
-                $hidden_fields['processing_registration']['value'] = 1;
2891
-                $template_args['title']                            = esc_html__(
2892
-                    'Step One: Select the Ticket for this registration',
2893
-                    'event_espresso'
2894
-                );
2895
-                $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2896
-                $template_args['content'] .= '</div>';
2897
-                $template_args['step_button_text'] = esc_html__(
2898
-                    'Add Tickets and Continue to Registrant Details',
2899
-                    'event_espresso'
2900
-                );
2901
-                $template_args['show_notification_toggle']         = false;
2902
-                break;
2903
-            case 'questions':
2904
-                $hidden_fields['processing_registration']['value'] = 2;
2905
-                $template_args['title']                            = esc_html__(
2906
-                    'Step Two: Add Registrant Details for this Registration',
2907
-                    'event_espresso'
2908
-                );
2909
-                // in theory, we should be able to run EED_SPCO at this point
2910
-                // because the cart should have been set up properly by the first process_reg_step run.
2911
-                $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2912
-                $template_args['step_button_text'] = esc_html__(
2913
-                    'Save Registration and Continue to Details',
2914
-                    'event_espresso'
2915
-                );
2916
-                $template_args['show_notification_toggle'] = true;
2917
-                break;
2918
-        }
2919
-        // we come back to the process_registration_step route.
2920
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2921
-        return EEH_Template::display_template(
2922
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2923
-            $template_args,
2924
-            true
2925
-        );
2926
-    }
2927
-
2928
-
2929
-    /**
2930
-     * set_reg_event
2931
-     *
2932
-     * @return bool
2933
-     * @throws EE_Error
2934
-     * @throws InvalidArgumentException
2935
-     * @throws InvalidDataTypeException
2936
-     * @throws InvalidInterfaceException
2937
-     */
2938
-    private function _set_reg_event()
2939
-    {
2940
-        if (is_object($this->_reg_event)) {
2941
-            return true;
2942
-        }
2943
-
2944
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2945
-        if (! $EVT_ID) {
2946
-            return false;
2947
-        }
2948
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2949
-        return true;
2950
-    }
2951
-
2952
-
2953
-    /**
2954
-     * process_reg_step
2955
-     *
2956
-     * @return void
2957
-     * @throws DomainException
2958
-     * @throws EE_Error
2959
-     * @throws InvalidArgumentException
2960
-     * @throws InvalidDataTypeException
2961
-     * @throws InvalidInterfaceException
2962
-     * @throws ReflectionException
2963
-     * @throws RuntimeException
2964
-     */
2965
-    public function process_reg_step()
2966
-    {
2967
-        EE_System::do_not_cache();
2968
-        $this->_set_reg_event();
2969
-        /** @var CurrentPage $current_page */
2970
-        $current_page = $this->loader->getShared(CurrentPage::class);
2971
-        $current_page->setEspressoPage(true);
2972
-        $this->request->setRequestParam('uts', time());
2973
-        // what step are we on?
2974
-        $cart = EE_Registry::instance()->SSN->cart();
2975
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2976
-        // if doing ajax then we need to verify the nonce
2977
-        if ($this->request->isAjax()) {
2978
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
2979
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2980
-        }
2981
-        switch ($step) {
2982
-            case 'ticket':
2983
-                // process ticket selection
2984
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2985
-                if ($success) {
2986
-                    EE_Error::add_success(
2987
-                        esc_html__(
2988
-                            'Tickets Selected. Now complete the registration.',
2989
-                            'event_espresso'
2990
-                        )
2991
-                    );
2992
-                } else {
2993
-                    $this->request->setRequestParam('step_error', true);
2994
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
2995
-                }
2996
-                if ($this->request->isAjax()) {
2997
-                    $this->new_registration(); // display next step
2998
-                } else {
2999
-                    $query_args = [
3000
-                        'action'                  => 'new_registration',
3001
-                        'processing_registration' => 1,
3002
-                        'event_id'                => $this->_reg_event->ID(),
3003
-                        'uts'                     => time(),
3004
-                    ];
3005
-                    $this->_redirect_after_action(
3006
-                        false,
3007
-                        '',
3008
-                        '',
3009
-                        $query_args,
3010
-                        true
3011
-                    );
3012
-                }
3013
-                break;
3014
-            case 'questions':
3015
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3016
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3017
-                }
3018
-                // process registration
3019
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3020
-                if ($cart instanceof EE_Cart) {
3021
-                    $grand_total = $cart->get_grand_total();
3022
-                    if ($grand_total instanceof EE_Line_Item) {
3023
-                        $grand_total->save_this_and_descendants_to_txn();
3024
-                    }
3025
-                }
3026
-                if (! $transaction instanceof EE_Transaction) {
3027
-                    $query_args = [
3028
-                        'action'                  => 'new_registration',
3029
-                        'processing_registration' => 2,
3030
-                        'event_id'                => $this->_reg_event->ID(),
3031
-                        'uts'                     => time(),
3032
-                    ];
3033
-                    if ($this->request->isAjax()) {
3034
-                        // display registration form again because there are errors (maybe validation?)
3035
-                        $this->new_registration();
3036
-                        return;
3037
-                    }
3038
-                    $this->_redirect_after_action(
3039
-                        false,
3040
-                        '',
3041
-                        '',
3042
-                        $query_args,
3043
-                        true
3044
-                    );
3045
-                    return;
3046
-                }
3047
-                // maybe update status, and make sure to save transaction if not done already
3048
-                if (! $transaction->update_status_based_on_total_paid()) {
3049
-                    $transaction->save();
3050
-                }
3051
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3052
-                $query_args = [
3053
-                    'action'        => 'redirect_to_txn',
3054
-                    'TXN_ID'        => $transaction->ID(),
3055
-                    'EVT_ID'        => $this->_reg_event->ID(),
3056
-                    'event_name'    => urlencode($this->_reg_event->name()),
3057
-                    'redirect_from' => 'new_registration',
3058
-                ];
3059
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3060
-                break;
3061
-        }
3062
-        // what are you looking here for?  Should be nothing to do at this point.
3063
-    }
3064
-
3065
-
3066
-    /**
3067
-     * redirect_to_txn
3068
-     *
3069
-     * @return void
3070
-     * @throws EE_Error
3071
-     * @throws InvalidArgumentException
3072
-     * @throws InvalidDataTypeException
3073
-     * @throws InvalidInterfaceException
3074
-     * @throws ReflectionException
3075
-     */
3076
-    public function redirect_to_txn()
3077
-    {
3078
-        EE_System::do_not_cache();
3079
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3080
-        $query_args = [
3081
-            'action' => 'view_transaction',
3082
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3083
-            'page'   => 'espresso_transactions',
3084
-        ];
3085
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3086
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3087
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3088
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3089
-        }
3090
-        EE_Error::add_success(
3091
-            esc_html__(
3092
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3093
-                'event_espresso'
3094
-            )
3095
-        );
3096
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3097
-    }
3098
-
3099
-
3100
-    /**
3101
-     * generates HTML for the Attendee Contact List
3102
-     *
3103
-     * @return void
3104
-     * @throws DomainException
3105
-     * @throws EE_Error
3106
-     */
3107
-    protected function _attendee_contact_list_table()
3108
-    {
3109
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3110
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3111
-        $this->display_admin_list_table_page_with_no_sidebar();
3112
-    }
3113
-
3114
-
3115
-    /**
3116
-     * get_attendees
3117
-     *
3118
-     * @param      $per_page
3119
-     * @param bool $count whether to return count or data.
3120
-     * @param bool $trash
3121
-     * @return array|int
3122
-     * @throws EE_Error
3123
-     * @throws InvalidArgumentException
3124
-     * @throws InvalidDataTypeException
3125
-     * @throws InvalidInterfaceException
3126
-     */
3127
-    public function get_attendees($per_page, $count = false, $trash = false)
3128
-    {
3129
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3130
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3131
-        $orderby = $this->request->getRequestParam('orderby');
3132
-        switch ($orderby) {
3133
-            case 'ATT_ID':
3134
-            case 'ATT_fname':
3135
-            case 'ATT_email':
3136
-            case 'ATT_city':
3137
-            case 'STA_ID':
3138
-            case 'CNT_ID':
3139
-                break;
3140
-            case 'Registration_Count':
3141
-                $orderby = 'Registration_Count';
3142
-                break;
3143
-            default:
3144
-                $orderby = 'ATT_lname';
3145
-        }
3146
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3147
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3148
-        $per_page     = absint($per_page) ? $per_page : 10;
3149
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3150
-        $_where       = [];
3151
-        $search_term  = $this->request->getRequestParam('s');
3152
-        if ($search_term) {
3153
-            $search_term  = '%' . $search_term . '%';
3154
-            $_where['OR'] = [
3155
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3156
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3157
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3158
-                'ATT_fname'                         => ['LIKE', $search_term],
3159
-                'ATT_lname'                         => ['LIKE', $search_term],
3160
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3161
-                'ATT_email'                         => ['LIKE', $search_term],
3162
-                'ATT_address'                       => ['LIKE', $search_term],
3163
-                'ATT_address2'                      => ['LIKE', $search_term],
3164
-                'ATT_city'                          => ['LIKE', $search_term],
3165
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3166
-                'State.STA_name'                    => ['LIKE', $search_term],
3167
-                'ATT_phone'                         => ['LIKE', $search_term],
3168
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3169
-                'Registration.REG_code'             => ['LIKE', $search_term],
3170
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3171
-            ];
3172
-        }
3173
-        $offset     = ($current_page - 1) * $per_page;
3174
-        $limit      = $count ? null : [$offset, $per_page];
3175
-        $query_args = [
3176
-            $_where,
3177
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3178
-            'limit'         => $limit,
3179
-        ];
3180
-        if (! $count) {
3181
-            $query_args['order_by'] = [$orderby => $sort];
3182
-        }
3183
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3184
-        return $count
3185
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3186
-            : $this->getAttendeeModel()->get_all($query_args);
3187
-    }
3188
-
3189
-
3190
-    /**
3191
-     * This is just taking care of resending the registration confirmation
3192
-     *
3193
-     * @return void
3194
-     * @throws EE_Error
3195
-     * @throws InvalidArgumentException
3196
-     * @throws InvalidDataTypeException
3197
-     * @throws InvalidInterfaceException
3198
-     * @throws ReflectionException
3199
-     */
3200
-    protected function _resend_registration()
3201
-    {
3202
-        $this->_process_resend_registration();
3203
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3204
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3205
-        $query_args  = $redirect_to
3206
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3207
-            : ['action' => 'default'];
3208
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3209
-    }
3210
-
3211
-
3212
-    /**
3213
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3214
-     * to use when selecting registrations
3215
-     *
3216
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3217
-     *                                                     the query parameters from the request
3218
-     * @return void ends the request with a redirect or download
3219
-     */
3220
-    public function _registrations_report_base($method_name_for_getting_query_params)
3221
-    {
3222
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3223
-            ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3224
-            : null;
3225
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3226
-            $request_params = $this->request->requestParams();
3227
-            wp_redirect(
3228
-                EE_Admin_Page::add_query_args_and_nonce(
3229
-                    [
3230
-                        'page'        => EED_Batch::PAGE_SLUG,
2867
+		}
2868
+		$template_args = [
2869
+			'title'                    => '',
2870
+			'content'                  => '',
2871
+			'step_button_text'         => '',
2872
+			'show_notification_toggle' => false,
2873
+		];
2874
+		// to indicate we're processing a new registration
2875
+		$hidden_fields = [
2876
+			'processing_registration' => [
2877
+				'type'  => 'hidden',
2878
+				'value' => 0,
2879
+			],
2880
+			'event_id'                => [
2881
+				'type'  => 'hidden',
2882
+				'value' => $this->_reg_event->ID(),
2883
+			],
2884
+		];
2885
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2886
+		$cart = EE_Registry::instance()->SSN->cart();
2887
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2888
+		switch ($step) {
2889
+			case 'ticket':
2890
+				$hidden_fields['processing_registration']['value'] = 1;
2891
+				$template_args['title']                            = esc_html__(
2892
+					'Step One: Select the Ticket for this registration',
2893
+					'event_espresso'
2894
+				);
2895
+				$template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2896
+				$template_args['content'] .= '</div>';
2897
+				$template_args['step_button_text'] = esc_html__(
2898
+					'Add Tickets and Continue to Registrant Details',
2899
+					'event_espresso'
2900
+				);
2901
+				$template_args['show_notification_toggle']         = false;
2902
+				break;
2903
+			case 'questions':
2904
+				$hidden_fields['processing_registration']['value'] = 2;
2905
+				$template_args['title']                            = esc_html__(
2906
+					'Step Two: Add Registrant Details for this Registration',
2907
+					'event_espresso'
2908
+				);
2909
+				// in theory, we should be able to run EED_SPCO at this point
2910
+				// because the cart should have been set up properly by the first process_reg_step run.
2911
+				$template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2912
+				$template_args['step_button_text'] = esc_html__(
2913
+					'Save Registration and Continue to Details',
2914
+					'event_espresso'
2915
+				);
2916
+				$template_args['show_notification_toggle'] = true;
2917
+				break;
2918
+		}
2919
+		// we come back to the process_registration_step route.
2920
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2921
+		return EEH_Template::display_template(
2922
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2923
+			$template_args,
2924
+			true
2925
+		);
2926
+	}
2927
+
2928
+
2929
+	/**
2930
+	 * set_reg_event
2931
+	 *
2932
+	 * @return bool
2933
+	 * @throws EE_Error
2934
+	 * @throws InvalidArgumentException
2935
+	 * @throws InvalidDataTypeException
2936
+	 * @throws InvalidInterfaceException
2937
+	 */
2938
+	private function _set_reg_event()
2939
+	{
2940
+		if (is_object($this->_reg_event)) {
2941
+			return true;
2942
+		}
2943
+
2944
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2945
+		if (! $EVT_ID) {
2946
+			return false;
2947
+		}
2948
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2949
+		return true;
2950
+	}
2951
+
2952
+
2953
+	/**
2954
+	 * process_reg_step
2955
+	 *
2956
+	 * @return void
2957
+	 * @throws DomainException
2958
+	 * @throws EE_Error
2959
+	 * @throws InvalidArgumentException
2960
+	 * @throws InvalidDataTypeException
2961
+	 * @throws InvalidInterfaceException
2962
+	 * @throws ReflectionException
2963
+	 * @throws RuntimeException
2964
+	 */
2965
+	public function process_reg_step()
2966
+	{
2967
+		EE_System::do_not_cache();
2968
+		$this->_set_reg_event();
2969
+		/** @var CurrentPage $current_page */
2970
+		$current_page = $this->loader->getShared(CurrentPage::class);
2971
+		$current_page->setEspressoPage(true);
2972
+		$this->request->setRequestParam('uts', time());
2973
+		// what step are we on?
2974
+		$cart = EE_Registry::instance()->SSN->cart();
2975
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2976
+		// if doing ajax then we need to verify the nonce
2977
+		if ($this->request->isAjax()) {
2978
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
2979
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2980
+		}
2981
+		switch ($step) {
2982
+			case 'ticket':
2983
+				// process ticket selection
2984
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2985
+				if ($success) {
2986
+					EE_Error::add_success(
2987
+						esc_html__(
2988
+							'Tickets Selected. Now complete the registration.',
2989
+							'event_espresso'
2990
+						)
2991
+					);
2992
+				} else {
2993
+					$this->request->setRequestParam('step_error', true);
2994
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
2995
+				}
2996
+				if ($this->request->isAjax()) {
2997
+					$this->new_registration(); // display next step
2998
+				} else {
2999
+					$query_args = [
3000
+						'action'                  => 'new_registration',
3001
+						'processing_registration' => 1,
3002
+						'event_id'                => $this->_reg_event->ID(),
3003
+						'uts'                     => time(),
3004
+					];
3005
+					$this->_redirect_after_action(
3006
+						false,
3007
+						'',
3008
+						'',
3009
+						$query_args,
3010
+						true
3011
+					);
3012
+				}
3013
+				break;
3014
+			case 'questions':
3015
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3016
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3017
+				}
3018
+				// process registration
3019
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3020
+				if ($cart instanceof EE_Cart) {
3021
+					$grand_total = $cart->get_grand_total();
3022
+					if ($grand_total instanceof EE_Line_Item) {
3023
+						$grand_total->save_this_and_descendants_to_txn();
3024
+					}
3025
+				}
3026
+				if (! $transaction instanceof EE_Transaction) {
3027
+					$query_args = [
3028
+						'action'                  => 'new_registration',
3029
+						'processing_registration' => 2,
3030
+						'event_id'                => $this->_reg_event->ID(),
3031
+						'uts'                     => time(),
3032
+					];
3033
+					if ($this->request->isAjax()) {
3034
+						// display registration form again because there are errors (maybe validation?)
3035
+						$this->new_registration();
3036
+						return;
3037
+					}
3038
+					$this->_redirect_after_action(
3039
+						false,
3040
+						'',
3041
+						'',
3042
+						$query_args,
3043
+						true
3044
+					);
3045
+					return;
3046
+				}
3047
+				// maybe update status, and make sure to save transaction if not done already
3048
+				if (! $transaction->update_status_based_on_total_paid()) {
3049
+					$transaction->save();
3050
+				}
3051
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3052
+				$query_args = [
3053
+					'action'        => 'redirect_to_txn',
3054
+					'TXN_ID'        => $transaction->ID(),
3055
+					'EVT_ID'        => $this->_reg_event->ID(),
3056
+					'event_name'    => urlencode($this->_reg_event->name()),
3057
+					'redirect_from' => 'new_registration',
3058
+				];
3059
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3060
+				break;
3061
+		}
3062
+		// what are you looking here for?  Should be nothing to do at this point.
3063
+	}
3064
+
3065
+
3066
+	/**
3067
+	 * redirect_to_txn
3068
+	 *
3069
+	 * @return void
3070
+	 * @throws EE_Error
3071
+	 * @throws InvalidArgumentException
3072
+	 * @throws InvalidDataTypeException
3073
+	 * @throws InvalidInterfaceException
3074
+	 * @throws ReflectionException
3075
+	 */
3076
+	public function redirect_to_txn()
3077
+	{
3078
+		EE_System::do_not_cache();
3079
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3080
+		$query_args = [
3081
+			'action' => 'view_transaction',
3082
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3083
+			'page'   => 'espresso_transactions',
3084
+		];
3085
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3086
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3087
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3088
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3089
+		}
3090
+		EE_Error::add_success(
3091
+			esc_html__(
3092
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3093
+				'event_espresso'
3094
+			)
3095
+		);
3096
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3097
+	}
3098
+
3099
+
3100
+	/**
3101
+	 * generates HTML for the Attendee Contact List
3102
+	 *
3103
+	 * @return void
3104
+	 * @throws DomainException
3105
+	 * @throws EE_Error
3106
+	 */
3107
+	protected function _attendee_contact_list_table()
3108
+	{
3109
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3110
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3111
+		$this->display_admin_list_table_page_with_no_sidebar();
3112
+	}
3113
+
3114
+
3115
+	/**
3116
+	 * get_attendees
3117
+	 *
3118
+	 * @param      $per_page
3119
+	 * @param bool $count whether to return count or data.
3120
+	 * @param bool $trash
3121
+	 * @return array|int
3122
+	 * @throws EE_Error
3123
+	 * @throws InvalidArgumentException
3124
+	 * @throws InvalidDataTypeException
3125
+	 * @throws InvalidInterfaceException
3126
+	 */
3127
+	public function get_attendees($per_page, $count = false, $trash = false)
3128
+	{
3129
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3130
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3131
+		$orderby = $this->request->getRequestParam('orderby');
3132
+		switch ($orderby) {
3133
+			case 'ATT_ID':
3134
+			case 'ATT_fname':
3135
+			case 'ATT_email':
3136
+			case 'ATT_city':
3137
+			case 'STA_ID':
3138
+			case 'CNT_ID':
3139
+				break;
3140
+			case 'Registration_Count':
3141
+				$orderby = 'Registration_Count';
3142
+				break;
3143
+			default:
3144
+				$orderby = 'ATT_lname';
3145
+		}
3146
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3147
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3148
+		$per_page     = absint($per_page) ? $per_page : 10;
3149
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3150
+		$_where       = [];
3151
+		$search_term  = $this->request->getRequestParam('s');
3152
+		if ($search_term) {
3153
+			$search_term  = '%' . $search_term . '%';
3154
+			$_where['OR'] = [
3155
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3156
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3157
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3158
+				'ATT_fname'                         => ['LIKE', $search_term],
3159
+				'ATT_lname'                         => ['LIKE', $search_term],
3160
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3161
+				'ATT_email'                         => ['LIKE', $search_term],
3162
+				'ATT_address'                       => ['LIKE', $search_term],
3163
+				'ATT_address2'                      => ['LIKE', $search_term],
3164
+				'ATT_city'                          => ['LIKE', $search_term],
3165
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3166
+				'State.STA_name'                    => ['LIKE', $search_term],
3167
+				'ATT_phone'                         => ['LIKE', $search_term],
3168
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3169
+				'Registration.REG_code'             => ['LIKE', $search_term],
3170
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3171
+			];
3172
+		}
3173
+		$offset     = ($current_page - 1) * $per_page;
3174
+		$limit      = $count ? null : [$offset, $per_page];
3175
+		$query_args = [
3176
+			$_where,
3177
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3178
+			'limit'         => $limit,
3179
+		];
3180
+		if (! $count) {
3181
+			$query_args['order_by'] = [$orderby => $sort];
3182
+		}
3183
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3184
+		return $count
3185
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3186
+			: $this->getAttendeeModel()->get_all($query_args);
3187
+	}
3188
+
3189
+
3190
+	/**
3191
+	 * This is just taking care of resending the registration confirmation
3192
+	 *
3193
+	 * @return void
3194
+	 * @throws EE_Error
3195
+	 * @throws InvalidArgumentException
3196
+	 * @throws InvalidDataTypeException
3197
+	 * @throws InvalidInterfaceException
3198
+	 * @throws ReflectionException
3199
+	 */
3200
+	protected function _resend_registration()
3201
+	{
3202
+		$this->_process_resend_registration();
3203
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3204
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3205
+		$query_args  = $redirect_to
3206
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3207
+			: ['action' => 'default'];
3208
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3209
+	}
3210
+
3211
+
3212
+	/**
3213
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3214
+	 * to use when selecting registrations
3215
+	 *
3216
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3217
+	 *                                                     the query parameters from the request
3218
+	 * @return void ends the request with a redirect or download
3219
+	 */
3220
+	public function _registrations_report_base($method_name_for_getting_query_params)
3221
+	{
3222
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3223
+			? $this->request->getRequestParam('EVT_ID', 0, 'int')
3224
+			: null;
3225
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3226
+			$request_params = $this->request->requestParams();
3227
+			wp_redirect(
3228
+				EE_Admin_Page::add_query_args_and_nonce(
3229
+					[
3230
+						'page'        => EED_Batch::PAGE_SLUG,
3231 3231
 						'batch' 	  => EED_Batch::batch_file_job,
3232
-                        'EVT_ID'      => $EVT_ID,
3233
-                        'filters'     => urlencode(
3234
-                            serialize(
3235
-                                $this->$method_name_for_getting_query_params(
3236
-                                    EEH_Array::is_set($request_params, 'filters', [])
3237
-                                )
3238
-                            )
3239
-                        ),
3240
-                        'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3241
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3242
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3243
-                    ]
3244
-                )
3245
-            );
3246
-        } else {
3247
-            // Pull the current request params
3248
-            $request_args = $this->request->requestParams();
3249
-            // Set the required request_args to be passed to the export
3250
-            $required_request_args = [
3251
-                'export' => 'report',
3252
-                'action' => 'registrations_report_for_event',
3253
-                'EVT_ID' => $EVT_ID,
3254
-            ];
3255
-            // Merge required request args, overriding any currently set
3256
-            $request_args = array_merge($request_args, $required_request_args);
3257
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3258
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3259
-                $EE_Export = EE_Export::instance($request_args);
3260
-                $EE_Export->export();
3261
-            }
3262
-        }
3263
-    }
3264
-
3265
-
3266
-    /**
3267
-     * Creates a registration report using only query parameters in the request
3268
-     *
3269
-     * @return void
3270
-     */
3271
-    public function _registrations_report()
3272
-    {
3273
-        $this->_registrations_report_base('_get_registration_query_parameters');
3274
-    }
3275
-
3276
-
3277
-    public function _contact_list_export()
3278
-    {
3279
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3280
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3281
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3282
-            $EE_Export->export_attendees();
3283
-        }
3284
-    }
3285
-
3286
-
3287
-    public function _contact_list_report()
3288
-    {
3289
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3290
-            wp_redirect(
3291
-                EE_Admin_Page::add_query_args_and_nonce(
3292
-                    [
3293
-                        'page'        => EED_Batch::PAGE_SLUG,
3294
-                        'batch'       => EED_Batch::batch_file_job,
3295
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3296
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3297
-                    ]
3298
-                )
3299
-            );
3300
-        } else {
3301
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3302
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3303
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3304
-                $EE_Export->report_attendees();
3305
-            }
3306
-        }
3307
-    }
3308
-
3309
-
3310
-
3311
-
3312
-
3313
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3314
-    /**
3315
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3316
-     *
3317
-     * @return void
3318
-     * @throws EE_Error
3319
-     * @throws InvalidArgumentException
3320
-     * @throws InvalidDataTypeException
3321
-     * @throws InvalidInterfaceException
3322
-     * @throws ReflectionException
3323
-     */
3324
-    protected function _duplicate_attendee()
3325
-    {
3326
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3327
-        $action = $this->request->getRequestParam('return', 'default');
3328
-        // verify we have necessary info
3329
-        if (! $REG_ID) {
3330
-            EE_Error::add_error(
3331
-                esc_html__(
3332
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3333
-                    'event_espresso'
3334
-                ),
3335
-                __FILE__,
3336
-                __LINE__,
3337
-                __FUNCTION__
3338
-            );
3339
-            $query_args = ['action' => $action];
3340
-            $this->_redirect_after_action('', '', '', $query_args, true);
3341
-        }
3342
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3343
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3344
-        if (! $registration instanceof EE_Registration) {
3345
-            throw new RuntimeException(
3346
-                sprintf(
3347
-                    esc_html__(
3348
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3349
-                        'event_espresso'
3350
-                    ),
3351
-                    $REG_ID
3352
-                )
3353
-            );
3354
-        }
3355
-        $attendee = $registration->attendee();
3356
-        // remove relation of existing attendee on registration
3357
-        $registration->_remove_relation_to($attendee, 'Attendee');
3358
-        // new attendee
3359
-        $new_attendee = clone $attendee;
3360
-        $new_attendee->set('ATT_ID', 0);
3361
-        $new_attendee->save();
3362
-        // add new attendee to reg
3363
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3364
-        EE_Error::add_success(
3365
-            esc_html__(
3366
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3367
-                'event_espresso'
3368
-            )
3369
-        );
3370
-        // redirect to edit page for attendee
3371
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3372
-        $this->_redirect_after_action('', '', '', $query_args, true);
3373
-    }
3374
-
3375
-
3376
-    /**
3377
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3378
-     *
3379
-     * @param int     $post_id
3380
-     * @param WP_Post $post
3381
-     * @throws DomainException
3382
-     * @throws EE_Error
3383
-     * @throws InvalidArgumentException
3384
-     * @throws InvalidDataTypeException
3385
-     * @throws InvalidInterfaceException
3386
-     * @throws LogicException
3387
-     * @throws InvalidFormSubmissionException
3388
-     * @throws ReflectionException
3389
-     */
3390
-    protected function _insert_update_cpt_item($post_id, $post)
3391
-    {
3392
-        $success  = true;
3393
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3394
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3395
-            : null;
3396
-        // for attendee updates
3397
-        if ($attendee instanceof EE_Attendee) {
3398
-            // note we should only be UPDATING attendees at this point.
3399
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3400
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3401
-            $updated_fields = [
3402
-                'ATT_fname'     => $fname,
3403
-                'ATT_lname'     => $lname,
3404
-                'ATT_full_name' => "{$fname} {$lname}",
3405
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3406
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3407
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3408
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3409
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3410
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3411
-            ];
3412
-            foreach ($updated_fields as $field => $value) {
3413
-                $attendee->set($field, $value);
3414
-            }
3415
-
3416
-            // process contact details metabox form handler (which will also save the attendee)
3417
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3418
-            $success              = $contact_details_form->process($this->request->requestParams());
3419
-
3420
-            $attendee_update_callbacks = apply_filters(
3421
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3422
-                []
3423
-            );
3424
-            foreach ($attendee_update_callbacks as $a_callback) {
3425
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3426
-                    throw new EE_Error(
3427
-                        sprintf(
3428
-                            esc_html__(
3429
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3430
-                                'event_espresso'
3431
-                            ),
3432
-                            $a_callback
3433
-                        )
3434
-                    );
3435
-                }
3436
-            }
3437
-        }
3438
-
3439
-        if ($success === false) {
3440
-            EE_Error::add_error(
3441
-                esc_html__(
3442
-                    'Something went wrong with updating the meta table data for the registration.',
3443
-                    'event_espresso'
3444
-                ),
3445
-                __FILE__,
3446
-                __FUNCTION__,
3447
-                __LINE__
3448
-            );
3449
-        }
3450
-    }
3451
-
3452
-
3453
-    public function trash_cpt_item($post_id)
3454
-    {
3455
-    }
3456
-
3457
-
3458
-    public function delete_cpt_item($post_id)
3459
-    {
3460
-    }
3461
-
3462
-
3463
-    public function restore_cpt_item($post_id)
3464
-    {
3465
-    }
3466
-
3467
-
3468
-    protected function _restore_cpt_item($post_id, $revision_id)
3469
-    {
3470
-    }
3471
-
3472
-
3473
-    /**
3474
-     * @throws EE_Error
3475
-     * @throws ReflectionException
3476
-     * @since 4.10.2.p
3477
-     */
3478
-    public function attendee_editor_metaboxes()
3479
-    {
3480
-        $this->verify_cpt_object();
3481
-        remove_meta_box(
3482
-            'postexcerpt',
3483
-            $this->_cpt_routes[ $this->_req_action ],
3484
-            'normal'
3485
-        );
3486
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3487
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3488
-            $this->addMetaBox(
3489
-                'postexcerpt',
3490
-                esc_html__('Short Biography', 'event_espresso'),
3491
-                'post_excerpt_meta_box',
3492
-                $this->_cpt_routes[ $this->_req_action ]
3493
-            );
3494
-        }
3495
-        if (post_type_supports('espresso_attendees', 'comments')) {
3496
-            $this->addMetaBox(
3497
-                'commentsdiv',
3498
-                esc_html__('Notes on the Contact', 'event_espresso'),
3499
-                'post_comment_meta_box',
3500
-                $this->_cpt_routes[ $this->_req_action ],
3501
-                'normal',
3502
-                'core'
3503
-            );
3504
-        }
3505
-        $this->addMetaBox(
3506
-            'attendee_contact_info',
3507
-            esc_html__('Contact Info', 'event_espresso'),
3508
-            [$this, 'attendee_contact_info'],
3509
-            $this->_cpt_routes[ $this->_req_action ],
3510
-            'side',
3511
-            'core'
3512
-        );
3513
-        $this->addMetaBox(
3514
-            'attendee_details_address',
3515
-            esc_html__('Address Details', 'event_espresso'),
3516
-            [$this, 'attendee_address_details'],
3517
-            $this->_cpt_routes[ $this->_req_action ],
3518
-            'normal',
3519
-            'core'
3520
-        );
3521
-        $this->addMetaBox(
3522
-            'attendee_registrations',
3523
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3524
-            [$this, 'attendee_registrations_meta_box'],
3525
-            $this->_cpt_routes[ $this->_req_action ]
3526
-        );
3527
-    }
3528
-
3529
-
3530
-    /**
3531
-     * Metabox for attendee contact info
3532
-     *
3533
-     * @param WP_Post $post wp post object
3534
-     * @return void attendee contact info ( and form )
3535
-     * @throws EE_Error
3536
-     * @throws InvalidArgumentException
3537
-     * @throws InvalidDataTypeException
3538
-     * @throws InvalidInterfaceException
3539
-     * @throws LogicException
3540
-     * @throws DomainException
3541
-     */
3542
-    public function attendee_contact_info($post)
3543
-    {
3544
-        // get attendee object ( should already have it )
3545
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3546
-        $form->enqueueStylesAndScripts();
3547
-        echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3548
-    }
3549
-
3550
-
3551
-    /**
3552
-     * Return form handler for the contact details metabox
3553
-     *
3554
-     * @param EE_Attendee $attendee
3555
-     * @return AttendeeContactDetailsMetaboxFormHandler
3556
-     * @throws DomainException
3557
-     * @throws InvalidArgumentException
3558
-     * @throws InvalidDataTypeException
3559
-     * @throws InvalidInterfaceException
3560
-     */
3561
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3562
-    {
3563
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3564
-    }
3565
-
3566
-
3567
-    /**
3568
-     * Metabox for attendee details
3569
-     *
3570
-     * @param WP_Post $post wp post object
3571
-     * @throws EE_Error
3572
-     * @throws ReflectionException
3573
-     */
3574
-    public function attendee_address_details($post)
3575
-    {
3576
-        // get attendee object (should already have it)
3577
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3578
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3579
-            new EE_Question_Form_Input(
3580
-                EE_Question::new_instance(
3581
-                    [
3582
-                        'QST_ID'           => 0,
3583
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3584
-                        'QST_system'       => 'admin-state',
3585
-                    ]
3586
-                ),
3587
-                EE_Answer::new_instance(
3588
-                    [
3589
-                        'ANS_ID'    => 0,
3590
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3591
-                    ]
3592
-                ),
3593
-                [
3594
-                    'input_id'       => 'STA_ID',
3595
-                    'input_name'     => 'STA_ID',
3596
-                    'input_prefix'   => '',
3597
-                    'append_qstn_id' => false,
3598
-                ]
3599
-            )
3600
-        );
3601
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3602
-            new EE_Question_Form_Input(
3603
-                EE_Question::new_instance(
3604
-                    [
3605
-                        'QST_ID'           => 0,
3606
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3607
-                        'QST_system'       => 'admin-country',
3608
-                    ]
3609
-                ),
3610
-                EE_Answer::new_instance(
3611
-                    [
3612
-                        'ANS_ID'    => 0,
3613
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3614
-                    ]
3615
-                ),
3616
-                [
3617
-                    'input_id'       => 'CNT_ISO',
3618
-                    'input_name'     => 'CNT_ISO',
3619
-                    'input_prefix'   => '',
3620
-                    'append_qstn_id' => false,
3621
-                ]
3622
-            )
3623
-        );
3624
-        $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3625
-        EEH_Template::display_template($template, $this->_template_args);
3626
-    }
3627
-
3628
-
3629
-    /**
3630
-     * _attendee_details
3631
-     *
3632
-     * @param $post
3633
-     * @return void
3634
-     * @throws DomainException
3635
-     * @throws EE_Error
3636
-     * @throws InvalidArgumentException
3637
-     * @throws InvalidDataTypeException
3638
-     * @throws InvalidInterfaceException
3639
-     * @throws ReflectionException
3640
-     */
3641
-    public function attendee_registrations_meta_box($post)
3642
-    {
3643
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3644
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3645
-        $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3646
-        EEH_Template::display_template($template, $this->_template_args);
3647
-    }
3648
-
3649
-
3650
-    /**
3651
-     * add in the form fields for the attendee edit
3652
-     *
3653
-     * @param WP_Post $post wp post object
3654
-     * @return void echos html for new form.
3655
-     * @throws DomainException
3656
-     */
3657
-    public function after_title_form_fields($post)
3658
-    {
3659
-        if ($post->post_type === 'espresso_attendees') {
3660
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3661
-            $template_args['attendee'] = $this->_cpt_model_obj;
3662
-            EEH_Template::display_template($template, $template_args);
3663
-        }
3664
-    }
3665
-
3666
-
3667
-    /**
3668
-     * _trash_or_restore_attendee
3669
-     *
3670
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3671
-     * @return void
3672
-     * @throws EE_Error
3673
-     * @throws InvalidArgumentException
3674
-     * @throws InvalidDataTypeException
3675
-     * @throws InvalidInterfaceException
3676
-     */
3677
-    protected function _trash_or_restore_attendees($trash = true)
3678
-    {
3679
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3680
-        $status = $trash ? 'trash' : 'publish';
3681
-        // Checkboxes
3682
-        if ($this->request->requestParamIsSet('checkbox')) {
3683
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3684
-            // if array has more than one element than success message should be plural
3685
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3686
-            // cycle thru checkboxes
3687
-            foreach ($ATT_IDs as $ATT_ID) {
3688
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3689
-                if (! $updated) {
3690
-                    $success = 0;
3691
-                }
3692
-            }
3693
-        } else {
3694
-            // grab single id and delete
3695
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3696
-            // update attendee
3697
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3698
-        }
3699
-        $what        = $success > 1
3700
-            ? esc_html__('Contacts', 'event_espresso')
3701
-            : esc_html__('Contact', 'event_espresso');
3702
-        $action_desc = $trash
3703
-            ? esc_html__('moved to the trash', 'event_espresso')
3704
-            : esc_html__('restored', 'event_espresso');
3705
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3706
-    }
3232
+						'EVT_ID'      => $EVT_ID,
3233
+						'filters'     => urlencode(
3234
+							serialize(
3235
+								$this->$method_name_for_getting_query_params(
3236
+									EEH_Array::is_set($request_params, 'filters', [])
3237
+								)
3238
+							)
3239
+						),
3240
+						'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3241
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3242
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3243
+					]
3244
+				)
3245
+			);
3246
+		} else {
3247
+			// Pull the current request params
3248
+			$request_args = $this->request->requestParams();
3249
+			// Set the required request_args to be passed to the export
3250
+			$required_request_args = [
3251
+				'export' => 'report',
3252
+				'action' => 'registrations_report_for_event',
3253
+				'EVT_ID' => $EVT_ID,
3254
+			];
3255
+			// Merge required request args, overriding any currently set
3256
+			$request_args = array_merge($request_args, $required_request_args);
3257
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3258
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3259
+				$EE_Export = EE_Export::instance($request_args);
3260
+				$EE_Export->export();
3261
+			}
3262
+		}
3263
+	}
3264
+
3265
+
3266
+	/**
3267
+	 * Creates a registration report using only query parameters in the request
3268
+	 *
3269
+	 * @return void
3270
+	 */
3271
+	public function _registrations_report()
3272
+	{
3273
+		$this->_registrations_report_base('_get_registration_query_parameters');
3274
+	}
3275
+
3276
+
3277
+	public function _contact_list_export()
3278
+	{
3279
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3280
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3281
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3282
+			$EE_Export->export_attendees();
3283
+		}
3284
+	}
3285
+
3286
+
3287
+	public function _contact_list_report()
3288
+	{
3289
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3290
+			wp_redirect(
3291
+				EE_Admin_Page::add_query_args_and_nonce(
3292
+					[
3293
+						'page'        => EED_Batch::PAGE_SLUG,
3294
+						'batch'       => EED_Batch::batch_file_job,
3295
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3296
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3297
+					]
3298
+				)
3299
+			);
3300
+		} else {
3301
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3302
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3303
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3304
+				$EE_Export->report_attendees();
3305
+			}
3306
+		}
3307
+	}
3308
+
3309
+
3310
+
3311
+
3312
+
3313
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3314
+	/**
3315
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3316
+	 *
3317
+	 * @return void
3318
+	 * @throws EE_Error
3319
+	 * @throws InvalidArgumentException
3320
+	 * @throws InvalidDataTypeException
3321
+	 * @throws InvalidInterfaceException
3322
+	 * @throws ReflectionException
3323
+	 */
3324
+	protected function _duplicate_attendee()
3325
+	{
3326
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3327
+		$action = $this->request->getRequestParam('return', 'default');
3328
+		// verify we have necessary info
3329
+		if (! $REG_ID) {
3330
+			EE_Error::add_error(
3331
+				esc_html__(
3332
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3333
+					'event_espresso'
3334
+				),
3335
+				__FILE__,
3336
+				__LINE__,
3337
+				__FUNCTION__
3338
+			);
3339
+			$query_args = ['action' => $action];
3340
+			$this->_redirect_after_action('', '', '', $query_args, true);
3341
+		}
3342
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3343
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3344
+		if (! $registration instanceof EE_Registration) {
3345
+			throw new RuntimeException(
3346
+				sprintf(
3347
+					esc_html__(
3348
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3349
+						'event_espresso'
3350
+					),
3351
+					$REG_ID
3352
+				)
3353
+			);
3354
+		}
3355
+		$attendee = $registration->attendee();
3356
+		// remove relation of existing attendee on registration
3357
+		$registration->_remove_relation_to($attendee, 'Attendee');
3358
+		// new attendee
3359
+		$new_attendee = clone $attendee;
3360
+		$new_attendee->set('ATT_ID', 0);
3361
+		$new_attendee->save();
3362
+		// add new attendee to reg
3363
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3364
+		EE_Error::add_success(
3365
+			esc_html__(
3366
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3367
+				'event_espresso'
3368
+			)
3369
+		);
3370
+		// redirect to edit page for attendee
3371
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3372
+		$this->_redirect_after_action('', '', '', $query_args, true);
3373
+	}
3374
+
3375
+
3376
+	/**
3377
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3378
+	 *
3379
+	 * @param int     $post_id
3380
+	 * @param WP_Post $post
3381
+	 * @throws DomainException
3382
+	 * @throws EE_Error
3383
+	 * @throws InvalidArgumentException
3384
+	 * @throws InvalidDataTypeException
3385
+	 * @throws InvalidInterfaceException
3386
+	 * @throws LogicException
3387
+	 * @throws InvalidFormSubmissionException
3388
+	 * @throws ReflectionException
3389
+	 */
3390
+	protected function _insert_update_cpt_item($post_id, $post)
3391
+	{
3392
+		$success  = true;
3393
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3394
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3395
+			: null;
3396
+		// for attendee updates
3397
+		if ($attendee instanceof EE_Attendee) {
3398
+			// note we should only be UPDATING attendees at this point.
3399
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3400
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3401
+			$updated_fields = [
3402
+				'ATT_fname'     => $fname,
3403
+				'ATT_lname'     => $lname,
3404
+				'ATT_full_name' => "{$fname} {$lname}",
3405
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3406
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3407
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3408
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3409
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3410
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3411
+			];
3412
+			foreach ($updated_fields as $field => $value) {
3413
+				$attendee->set($field, $value);
3414
+			}
3415
+
3416
+			// process contact details metabox form handler (which will also save the attendee)
3417
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3418
+			$success              = $contact_details_form->process($this->request->requestParams());
3419
+
3420
+			$attendee_update_callbacks = apply_filters(
3421
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3422
+				[]
3423
+			);
3424
+			foreach ($attendee_update_callbacks as $a_callback) {
3425
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3426
+					throw new EE_Error(
3427
+						sprintf(
3428
+							esc_html__(
3429
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3430
+								'event_espresso'
3431
+							),
3432
+							$a_callback
3433
+						)
3434
+					);
3435
+				}
3436
+			}
3437
+		}
3438
+
3439
+		if ($success === false) {
3440
+			EE_Error::add_error(
3441
+				esc_html__(
3442
+					'Something went wrong with updating the meta table data for the registration.',
3443
+					'event_espresso'
3444
+				),
3445
+				__FILE__,
3446
+				__FUNCTION__,
3447
+				__LINE__
3448
+			);
3449
+		}
3450
+	}
3451
+
3452
+
3453
+	public function trash_cpt_item($post_id)
3454
+	{
3455
+	}
3456
+
3457
+
3458
+	public function delete_cpt_item($post_id)
3459
+	{
3460
+	}
3461
+
3462
+
3463
+	public function restore_cpt_item($post_id)
3464
+	{
3465
+	}
3466
+
3467
+
3468
+	protected function _restore_cpt_item($post_id, $revision_id)
3469
+	{
3470
+	}
3471
+
3472
+
3473
+	/**
3474
+	 * @throws EE_Error
3475
+	 * @throws ReflectionException
3476
+	 * @since 4.10.2.p
3477
+	 */
3478
+	public function attendee_editor_metaboxes()
3479
+	{
3480
+		$this->verify_cpt_object();
3481
+		remove_meta_box(
3482
+			'postexcerpt',
3483
+			$this->_cpt_routes[ $this->_req_action ],
3484
+			'normal'
3485
+		);
3486
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3487
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3488
+			$this->addMetaBox(
3489
+				'postexcerpt',
3490
+				esc_html__('Short Biography', 'event_espresso'),
3491
+				'post_excerpt_meta_box',
3492
+				$this->_cpt_routes[ $this->_req_action ]
3493
+			);
3494
+		}
3495
+		if (post_type_supports('espresso_attendees', 'comments')) {
3496
+			$this->addMetaBox(
3497
+				'commentsdiv',
3498
+				esc_html__('Notes on the Contact', 'event_espresso'),
3499
+				'post_comment_meta_box',
3500
+				$this->_cpt_routes[ $this->_req_action ],
3501
+				'normal',
3502
+				'core'
3503
+			);
3504
+		}
3505
+		$this->addMetaBox(
3506
+			'attendee_contact_info',
3507
+			esc_html__('Contact Info', 'event_espresso'),
3508
+			[$this, 'attendee_contact_info'],
3509
+			$this->_cpt_routes[ $this->_req_action ],
3510
+			'side',
3511
+			'core'
3512
+		);
3513
+		$this->addMetaBox(
3514
+			'attendee_details_address',
3515
+			esc_html__('Address Details', 'event_espresso'),
3516
+			[$this, 'attendee_address_details'],
3517
+			$this->_cpt_routes[ $this->_req_action ],
3518
+			'normal',
3519
+			'core'
3520
+		);
3521
+		$this->addMetaBox(
3522
+			'attendee_registrations',
3523
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3524
+			[$this, 'attendee_registrations_meta_box'],
3525
+			$this->_cpt_routes[ $this->_req_action ]
3526
+		);
3527
+	}
3528
+
3529
+
3530
+	/**
3531
+	 * Metabox for attendee contact info
3532
+	 *
3533
+	 * @param WP_Post $post wp post object
3534
+	 * @return void attendee contact info ( and form )
3535
+	 * @throws EE_Error
3536
+	 * @throws InvalidArgumentException
3537
+	 * @throws InvalidDataTypeException
3538
+	 * @throws InvalidInterfaceException
3539
+	 * @throws LogicException
3540
+	 * @throws DomainException
3541
+	 */
3542
+	public function attendee_contact_info($post)
3543
+	{
3544
+		// get attendee object ( should already have it )
3545
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3546
+		$form->enqueueStylesAndScripts();
3547
+		echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3548
+	}
3549
+
3550
+
3551
+	/**
3552
+	 * Return form handler for the contact details metabox
3553
+	 *
3554
+	 * @param EE_Attendee $attendee
3555
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3556
+	 * @throws DomainException
3557
+	 * @throws InvalidArgumentException
3558
+	 * @throws InvalidDataTypeException
3559
+	 * @throws InvalidInterfaceException
3560
+	 */
3561
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3562
+	{
3563
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3564
+	}
3565
+
3566
+
3567
+	/**
3568
+	 * Metabox for attendee details
3569
+	 *
3570
+	 * @param WP_Post $post wp post object
3571
+	 * @throws EE_Error
3572
+	 * @throws ReflectionException
3573
+	 */
3574
+	public function attendee_address_details($post)
3575
+	{
3576
+		// get attendee object (should already have it)
3577
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3578
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3579
+			new EE_Question_Form_Input(
3580
+				EE_Question::new_instance(
3581
+					[
3582
+						'QST_ID'           => 0,
3583
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3584
+						'QST_system'       => 'admin-state',
3585
+					]
3586
+				),
3587
+				EE_Answer::new_instance(
3588
+					[
3589
+						'ANS_ID'    => 0,
3590
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3591
+					]
3592
+				),
3593
+				[
3594
+					'input_id'       => 'STA_ID',
3595
+					'input_name'     => 'STA_ID',
3596
+					'input_prefix'   => '',
3597
+					'append_qstn_id' => false,
3598
+				]
3599
+			)
3600
+		);
3601
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3602
+			new EE_Question_Form_Input(
3603
+				EE_Question::new_instance(
3604
+					[
3605
+						'QST_ID'           => 0,
3606
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3607
+						'QST_system'       => 'admin-country',
3608
+					]
3609
+				),
3610
+				EE_Answer::new_instance(
3611
+					[
3612
+						'ANS_ID'    => 0,
3613
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3614
+					]
3615
+				),
3616
+				[
3617
+					'input_id'       => 'CNT_ISO',
3618
+					'input_name'     => 'CNT_ISO',
3619
+					'input_prefix'   => '',
3620
+					'append_qstn_id' => false,
3621
+				]
3622
+			)
3623
+		);
3624
+		$template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3625
+		EEH_Template::display_template($template, $this->_template_args);
3626
+	}
3627
+
3628
+
3629
+	/**
3630
+	 * _attendee_details
3631
+	 *
3632
+	 * @param $post
3633
+	 * @return void
3634
+	 * @throws DomainException
3635
+	 * @throws EE_Error
3636
+	 * @throws InvalidArgumentException
3637
+	 * @throws InvalidDataTypeException
3638
+	 * @throws InvalidInterfaceException
3639
+	 * @throws ReflectionException
3640
+	 */
3641
+	public function attendee_registrations_meta_box($post)
3642
+	{
3643
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3644
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3645
+		$template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3646
+		EEH_Template::display_template($template, $this->_template_args);
3647
+	}
3648
+
3649
+
3650
+	/**
3651
+	 * add in the form fields for the attendee edit
3652
+	 *
3653
+	 * @param WP_Post $post wp post object
3654
+	 * @return void echos html for new form.
3655
+	 * @throws DomainException
3656
+	 */
3657
+	public function after_title_form_fields($post)
3658
+	{
3659
+		if ($post->post_type === 'espresso_attendees') {
3660
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3661
+			$template_args['attendee'] = $this->_cpt_model_obj;
3662
+			EEH_Template::display_template($template, $template_args);
3663
+		}
3664
+	}
3665
+
3666
+
3667
+	/**
3668
+	 * _trash_or_restore_attendee
3669
+	 *
3670
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3671
+	 * @return void
3672
+	 * @throws EE_Error
3673
+	 * @throws InvalidArgumentException
3674
+	 * @throws InvalidDataTypeException
3675
+	 * @throws InvalidInterfaceException
3676
+	 */
3677
+	protected function _trash_or_restore_attendees($trash = true)
3678
+	{
3679
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3680
+		$status = $trash ? 'trash' : 'publish';
3681
+		// Checkboxes
3682
+		if ($this->request->requestParamIsSet('checkbox')) {
3683
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3684
+			// if array has more than one element than success message should be plural
3685
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3686
+			// cycle thru checkboxes
3687
+			foreach ($ATT_IDs as $ATT_ID) {
3688
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3689
+				if (! $updated) {
3690
+					$success = 0;
3691
+				}
3692
+			}
3693
+		} else {
3694
+			// grab single id and delete
3695
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3696
+			// update attendee
3697
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3698
+		}
3699
+		$what        = $success > 1
3700
+			? esc_html__('Contacts', 'event_espresso')
3701
+			: esc_html__('Contact', 'event_espresso');
3702
+		$action_desc = $trash
3703
+			? esc_html__('moved to the trash', 'event_espresso')
3704
+			: esc_html__('restored', 'event_espresso');
3705
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3706
+	}
3707 3707
 }
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 1 patch
Indentation   +947 added lines, -947 removed lines patch added patch discarded remove patch
@@ -14,952 +14,952 @@
 block discarded – undo
14 14
  */
15 15
 class Maintenance_Admin_Page extends EE_Admin_Page
16 16
 {
17
-    /**
18
-     * @var EE_Data_Migration_Manager
19
-     */
20
-    protected $migration_manager;
21
-
22
-    /**
23
-     * @var EE_Maintenance_Mode
24
-     */
25
-    protected $maintenance_mode;
26
-
27
-    /**
28
-     * @var EE_Form_Section_Proper
29
-     */
30
-    protected $datetime_fix_offset_form;
31
-
32
-
33
-    /**
34
-     * @param bool $routing
35
-     * @throws EE_Error
36
-     * @throws ReflectionException
37
-     */
38
-    public function __construct($routing = true)
39
-    {
40
-        $this->migration_manager = EE_Data_Migration_Manager::instance();
41
-        $this->maintenance_mode  = EE_Maintenance_Mode::instance();
42
-        parent::__construct($routing);
43
-    }
44
-
45
-
46
-    protected function _init_page_props()
47
-    {
48
-        $this->page_slug        = EE_MAINTENANCE_PG_SLUG;
49
-        $this->page_label       = EE_MAINTENANCE_LABEL;
50
-        $this->_admin_base_url  = EE_MAINTENANCE_ADMIN_URL;
51
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
52
-    }
53
-
54
-
55
-    protected function _ajax_hooks()
56
-    {
57
-        add_action('wp_ajax_migration_step', [$this, 'migration_step']);
58
-        add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']);
59
-    }
60
-
61
-
62
-    protected function _define_page_props()
63
-    {
64
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
65
-        $this->_labels           = [
66
-            'buttons' => [
67
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
68
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
69
-            ],
70
-        ];
71
-    }
72
-
73
-
74
-    protected function _set_page_routes()
75
-    {
76
-        $this->_page_routes = [
77
-            'default'                             => [
78
-                'func'       => '_maintenance',
79
-                'capability' => 'manage_options',
80
-            ],
81
-            'change_maintenance_level'            => [
82
-                'func'       => '_change_maintenance_level',
83
-                'capability' => 'manage_options',
84
-                'noheader'   => true,
85
-            ],
86
-            'system_status'                       => [
87
-                'func'       => '_system_status',
88
-                'capability' => 'manage_options',
89
-            ],
90
-            'download_system_status'              => [
91
-                'func'       => '_download_system_status',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ],
95
-            'send_migration_crash_report'         => [
96
-                'func'       => '_send_migration_crash_report',
97
-                'capability' => 'manage_options',
98
-                'noheader'   => true,
99
-            ],
100
-            'confirm_migration_crash_report_sent' => [
101
-                'func'       => '_confirm_migration_crash_report_sent',
102
-                'capability' => 'manage_options',
103
-            ],
104
-            'data_reset'                          => [
105
-                'func'       => '_data_reset_and_delete',
106
-                'capability' => 'manage_options',
107
-            ],
108
-            'reset_db'                            => [
109
-                'func'       => '_reset_db',
110
-                'capability' => 'manage_options',
111
-                'noheader'   => true,
112
-                'args'       => ['nuke_old_ee4_data' => true],
113
-            ],
114
-            'start_with_fresh_ee4_db'             => [
115
-                'func'       => '_reset_db',
116
-                'capability' => 'manage_options',
117
-                'noheader'   => true,
118
-                'args'       => ['nuke_old_ee4_data' => false],
119
-            ],
120
-            'delete_db'                           => [
121
-                'func'       => '_delete_db',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ],
125
-            'rerun_migration_from_ee3'            => [
126
-                'func'       => '_rerun_migration_from_ee3',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ],
130
-            'reset_reservations'                  => [
131
-                'func'       => '_reset_reservations',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ],
135
-            'reset_capabilities'                  => [
136
-                'func'       => '_reset_capabilities',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ],
140
-            'reattempt_migration'                 => [
141
-                'func'       => '_reattempt_migration',
142
-                'capability' => 'manage_options',
143
-                'noheader'   => true,
144
-            ],
145
-            'datetime_tools'                      => [
146
-                'func'       => '_datetime_tools',
147
-                'capability' => 'manage_options',
148
-            ],
149
-            'run_datetime_offset_fix'             => [
150
-                'func'               => '_apply_datetime_offset',
151
-                'noheader'           => true,
152
-                'headers_sent_route' => 'datetime_tools',
153
-                'capability'         => 'manage_options',
154
-            ],
155
-        ];
156
-    }
157
-
158
-
159
-    protected function _set_page_config()
160
-    {
161
-        $this->_page_config = [
162
-            'default'        => [
163
-                'nav'           => [
164
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
165
-                    'order' => 10,
166
-                ],
167
-                'require_nonce' => false,
168
-            ],
169
-            'data_reset'     => [
170
-                'nav'           => [
171
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
172
-                    'order' => 20,
173
-                ],
174
-                'require_nonce' => false,
175
-            ],
176
-            'datetime_tools' => [
177
-                'nav'           => [
178
-                    'label' => esc_html__('Datetime Utilities', 'event_espresso'),
179
-                    'order' => 25,
180
-                ],
181
-                'require_nonce' => false,
182
-            ],
183
-            'system_status'  => [
184
-                'nav'           => [
185
-                    'label' => esc_html__("System Information", "event_espresso"),
186
-                    'order' => 30,
187
-                ],
188
-                'require_nonce' => false,
189
-            ],
190
-        ];
191
-    }
192
-
193
-
194
-    /**
195
-     * default maintenance page.
196
-     * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI.
197
-     *
198
-     * @throws EE_Error
199
-     */
200
-    public function _maintenance()
201
-    {
202
-        $show_maintenance_switch         = true;
203
-        $show_backup_db_text             = false;
204
-        $show_migration_progress         = false;
205
-        $script_names                    = [];
206
-        $addons_should_be_upgraded_first = false;
207
-        // it all depends on if we're in maintenance model level 1 (frontend-only) or
208
-        // level 2 (everything except maintenance page)
209
-        try {
210
-            // get the current maintenance level and check if
211
-            // we are removed
212
-            $mMode_level  = $this->maintenance_mode->level();
213
-            $placed_in_mm = $this->maintenance_mode->set_maintenance_mode_if_db_old();
214
-            if ($mMode_level == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
215
-                // we just took the site out of maintenance mode, so notify the user.
216
-                // unfortunately this message appears to be echoed on the NEXT page load...
217
-                // oh well, we should really be checking for this on addon deactivation anyways
218
-                EE_Error::add_attention(
219
-                    esc_html__(
220
-                        'Site taken out of maintenance mode because no data migration scripts are required',
221
-                        'event_espresso'
222
-                    )
223
-                );
224
-                $this->_process_notices(['page' => 'espresso_maintenance_settings']);
225
-            }
226
-            // in case an exception is thrown while trying to handle migrations
227
-            if ($mMode_level === EE_Maintenance_Mode::level_2_complete_maintenance) {
228
-                $show_maintenance_switch = false;
229
-                $show_migration_progress = true;
230
-                if (isset($this->_req_data['continue_migration'])) {
231
-                    $show_backup_db_text = false;
232
-                } else {
233
-                    $show_backup_db_text = true;
234
-                }
235
-                $scripts_needing_to_run          =
236
-                    $this->migration_manager->check_for_applicable_data_migration_scripts();
237
-                $addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating();
238
-                $script_names                    = [];
239
-                $current_script                  = null;
240
-                foreach ($scripts_needing_to_run as $script) {
241
-                    if ($script instanceof EE_Data_Migration_Script_Base) {
242
-                        if (! $current_script) {
243
-                            $current_script = $script;
244
-                            $current_script->migration_page_hooks();
245
-                        }
246
-                        $script_names[] = $script->pretty_name();
247
-                    }
248
-                }
249
-            }
250
-            $most_recent_migration = $this->migration_manager->get_last_ran_script(true);
251
-            $exception_thrown      = false;
252
-        } catch (EE_Error $e) {
253
-            $this->migration_manager->add_error_to_migrations_ran($e->getMessage());
254
-            // now, just so we can display the page correctly, make an error migration script stage object
255
-            // and also put the error on it. It only persists for the duration of this request
256
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
257
-            $most_recent_migration->add_error($e->getMessage());
258
-            $exception_thrown = true;
259
-        }
260
-        $current_db_state = $this->migration_manager->ensure_current_database_state_is_set();
261
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
262
-        if (
263
-            $exception_thrown
264
-            || (
265
-                $most_recent_migration instanceof EE_Data_Migration_Script_Base
266
-                && $most_recent_migration->is_broken()
267
-            )
268
-        ) {
269
-            $this->_template_path                =
270
-                EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
271
-            $this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/';
272
-            $this->_template_args['next_url']    = EEH_URL::add_query_args_and_nonce(
273
-                [
274
-                    'action'  => 'confirm_migration_crash_report_sent',
275
-                    'success' => '0',
276
-                ],
277
-                EE_MAINTENANCE_ADMIN_URL
278
-            );
279
-        } elseif ($addons_should_be_upgraded_first) {
280
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
281
-        } else {
282
-            if (
283
-                $most_recent_migration instanceof EE_Data_Migration_Script_Base
284
-                && $most_recent_migration->can_continue()
285
-            ) {
286
-                $show_backup_db_text                    = false;
287
-                $show_continue_current_migration_script = true;
288
-                $show_most_recent_migration             = true;
289
-            } elseif (isset($this->_req_data['continue_migration'])) {
290
-                $show_most_recent_migration             = true;
291
-                $show_continue_current_migration_script = false;
292
-            } else {
293
-                $show_most_recent_migration             = false;
294
-                $show_continue_current_migration_script = false;
295
-            }
296
-            if (isset($current_script)) {
297
-                $migrates_to          = $current_script->migrates_to_version();
298
-                $plugin_slug          = $migrates_to['slug'];
299
-                $new_version          = $migrates_to['version'];
300
-                $this->_template_args = array_merge(
301
-                    $this->_template_args,
302
-                    [
303
-                        'current_db_state' => sprintf(
304
-                            esc_html__("EE%s (%s)", "event_espresso"),
305
-                            isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
306
-                            $plugin_slug
307
-                        ),
308
-                        'next_db_state'    => sprintf(
309
-                            esc_html__("EE%s (%s)", 'event_espresso'),
310
-                            $new_version,
311
-                            $plugin_slug
312
-                        ),
313
-                    ]
314
-                );
315
-            } else {
316
-                $this->_template_args['current_db_state'] = null;
317
-                $this->_template_args['next_db_state']    = null;
318
-            }
319
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
320
-            $this->_template_args = array_merge(
321
-                $this->_template_args,
322
-                [
323
-                    'show_most_recent_migration'             => $show_most_recent_migration,
324
-                    // flag for showing the most recent migration's status and/or errors
325
-                    'show_migration_progress'                => $show_migration_progress,
326
-                    // flag for showing the option to run migrations and see their progress
327
-                    'show_backup_db_text'                    => $show_backup_db_text,
328
-                    // flag for showing text telling the user to back up their DB
329
-                    'show_maintenance_switch'                => $show_maintenance_switch,
330
-                    // flag for showing the option to change maintenance mode between levels 0 and 1
331
-                    'script_names'                           => $script_names,
332
-                    // array of names of scripts that have run
333
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
334
-                    // flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
335
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
336
-                        ['action' => 'reset_db'],
337
-                        EE_MAINTENANCE_ADMIN_URL
338
-                    ),
339
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
340
-                        ['action' => 'data_reset'],
341
-                        EE_MAINTENANCE_ADMIN_URL
342
-                    ),
343
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
344
-                        ['action' => 'change_maintenance_level'],
345
-                        EE_MAINTENANCE_ADMIN_URL
346
-                    ),
347
-                    'ultimate_db_state'                      => sprintf(
348
-                        esc_html__("EE%s", 'event_espresso'),
349
-                        espresso_version()
350
-                    ),
351
-                ]
352
-            );
353
-        }
354
-        $this->_template_args['most_recent_migration'] =
355
-            $most_recent_migration;// the actual most recently ran migration
356
-        // now render the migration options part, and put it in a variable
357
-        $migration_options_template_file                = apply_filters(
358
-            'FHEE__ee_migration_page__migration_options_template',
359
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
360
-        );
361
-        $migration_options_html                         = EEH_Template::display_template(
362
-            $migration_options_template_file,
363
-            $this->_template_args,
364
-            true
365
-        );
366
-        $this->_template_args['migration_options_html'] = $migration_options_html;
367
-        $this->_template_args['admin_page_content']     = EEH_Template::display_template(
368
-            $this->_template_path,
369
-            $this->_template_args,
370
-            true
371
-        );
372
-        $this->display_admin_page_with_sidebar();
373
-    }
374
-
375
-
376
-    /**
377
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
378
-     *
379
-     * @throws EE_Error
380
-     */
381
-    public function migration_step()
382
-    {
383
-        $this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request();
384
-        $this->_return_json();
385
-    }
386
-
387
-
388
-    /**
389
-     * Can be used by js when it notices a response with HTML in it in order
390
-     * to log the malformed response
391
-     *
392
-     * @throws EE_Error
393
-     */
394
-    public function add_error_to_migrations_ran()
395
-    {
396
-        $this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']);
397
-        $this->_template_args['data'] = ['ok' => true];
398
-        $this->_return_json();
399
-    }
400
-
401
-
402
-    /**
403
-     * changes the maintenance level, provided there are still no migration scripts that should run
404
-     *
405
-     * @throws EE_Error
406
-     */
407
-    public function _change_maintenance_level()
408
-    {
409
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
410
-        if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) {
411
-            $this->maintenance_mode->set_maintenance_level($new_level);
412
-            $success = true;
413
-        } else {
414
-            $this->maintenance_mode->set_maintenance_mode_if_db_old();
415
-            $success = false;
416
-        }
417
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
418
-    }
419
-
420
-
421
-    /**
422
-     * a tab with options for resetting and/or deleting EE data
423
-     *
424
-     * @throws EE_Error
425
-     * @throws DomainException
426
-     */
427
-    public function _data_reset_and_delete()
428
-    {
429
-        $this->_template_path                              =
430
-            EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
431
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
432
-            'reset_reservations',
433
-            'reset_reservations',
434
-            [],
435
-            'button button--caution ee-confirm'
436
-        );
437
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
438
-            'reset_capabilities',
439
-            'reset_capabilities',
440
-            [],
441
-            'button button--caution ee-confirm'
442
-        );
443
-        $this->_template_args['delete_db_url']             = EE_Admin_Page::add_query_args_and_nonce(
444
-            ['action' => 'delete_db'],
445
-            EE_MAINTENANCE_ADMIN_URL
446
-        );
447
-        $this->_template_args['reset_db_url']              = EE_Admin_Page::add_query_args_and_nonce(
448
-            ['action' => 'reset_db'],
449
-            EE_MAINTENANCE_ADMIN_URL
450
-        );
451
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
452
-            $this->_template_path,
453
-            $this->_template_args,
454
-            true
455
-        );
456
-        $this->display_admin_page_with_no_sidebar();
457
-    }
458
-
459
-
460
-    /**
461
-     * @throws EE_Error
462
-     * @throws ReflectionException
463
-     */
464
-    protected function _reset_reservations()
465
-    {
466
-        if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
467
-            EE_Error::add_success(
468
-                esc_html__(
469
-                    'Ticket and datetime reserved counts have been successfully reset.',
470
-                    'event_espresso'
471
-                )
472
-            );
473
-        } else {
474
-            EE_Error::add_success(
475
-                esc_html__(
476
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
477
-                    'event_espresso'
478
-                )
479
-            );
480
-        }
481
-        $this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true);
482
-    }
483
-
484
-
485
-    /**
486
-     * @throws EE_Error
487
-     */
488
-    protected function _reset_capabilities()
489
-    {
490
-        EE_Registry::instance()->CAP->init_caps(true);
491
-        EE_Error::add_success(
492
-            esc_html__(
493
-                'Default Event Espresso capabilities have been restored for all current roles.',
494
-                'event_espresso'
495
-            )
496
-        );
497
-        $this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true);
498
-    }
499
-
500
-
501
-    /**
502
-     * resets the DMSs, so we can attempt to continue migrating after a fatal error
503
-     * (only a good idea when someone has somehow tried ot fix whatever caused
504
-     * the fatal error in teh first place)
505
-     *
506
-     * @throws EE_Error
507
-     */
508
-    protected function _reattempt_migration()
509
-    {
510
-        $this->migration_manager->reattempt();
511
-        $this->_redirect_after_action(false, '', '', ['action' => 'default'], true);
512
-    }
513
-
514
-
515
-    /**
516
-     * shows the big ol' System Information page
517
-     *
518
-     * @throws EE_Error
519
-     */
520
-    public function _system_status()
521
-    {
522
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
523
-        $this->_template_args['system_stati']               = EEM_System_Status::instance()->get_system_stati();
524
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
525
-            [
526
-                'action' => 'download_system_status',
527
-            ],
528
-            EE_MAINTENANCE_ADMIN_URL
529
-        );
530
-        $this->_template_args['admin_page_content']         = EEH_Template::display_template(
531
-            $this->_template_path,
532
-            $this->_template_args,
533
-            true
534
-        );
535
-        $this->display_admin_page_with_no_sidebar();
536
-    }
537
-
538
-
539
-    /**
540
-     * Downloads an HTML file of the system status that can be easily stored or emailed
541
-     */
542
-    public function _download_system_status()
543
-    {
544
-        $status_info = EEM_System_Status::instance()->get_system_stati();
545
-        header('Content-Disposition: attachment');
546
-        header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
547
-        $output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>';
548
-        $output .= '<h1>' . sprintf(
549
-            __('System Information for %1$s', 'event_espresso'),
550
-            esc_url_raw(site_url())
551
-        ) . '</h1>';
552
-        $output .= EEH_Template::layout_array_as_table($status_info);
553
-        echo esc_html($output);
554
-        die;
555
-    }
556
-
557
-
558
-    /**
559
-     * @throws EE_Error
560
-     */
561
-    public function _send_migration_crash_report()
562
-    {
563
-        $from      = $this->_req_data['from'];
564
-        $from_name = $this->_req_data['from_name'];
565
-        $body      = $this->_req_data['body'];
566
-        try {
567
-            $success = wp_mail(
568
-                EE_SUPPORT_EMAIL,
569
-                'Migration Crash Report',
570
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
571
-                [
572
-                    "from:$from_name<$from>",
573
-                ]
574
-            );
575
-        } catch (Exception $e) {
576
-            $success = false;
577
-        }
578
-        $this->_redirect_after_action(
579
-            $success,
580
-            esc_html__("Migration Crash Report", "event_espresso"),
581
-            esc_html__("sent", "event_espresso"),
582
-            ['success' => $success, 'action' => 'confirm_migration_crash_report_sent']
583
-        );
584
-    }
585
-
586
-
587
-    /**
588
-     * @throws EE_Error
589
-     */
590
-    public function _confirm_migration_crash_report_sent()
591
-    {
592
-        try {
593
-            $most_recent_migration = $this->migration_manager->get_last_ran_script(true);
594
-        } catch (EE_Error $e) {
595
-            $this->migration_manager->add_error_to_migrations_ran($e->getMessage());
596
-            // now, just so we can display the page correctly, make an error migration script stage object
597
-            // and also put the error on it. It only persists for the duration of this request
598
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
599
-            $most_recent_migration->add_error($e->getMessage());
600
-        }
601
-        $success                                       = $this->_req_data['success'] === '1';
602
-        $this->_template_args['success']               = $success;
603
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
604
-        $this->_template_args['reset_db_action_url']   = EE_Admin_Page::add_query_args_and_nonce(
605
-            ['action' => 'reset_db'],
606
-            EE_MAINTENANCE_ADMIN_URL
607
-        );
608
-        $this->_template_args['reset_db_page_url']     = EE_Admin_Page::add_query_args_and_nonce(
609
-            ['action' => 'data_reset'],
610
-            EE_MAINTENANCE_ADMIN_URL
611
-        );
612
-        $this->_template_args['reattempt_action_url']  = EE_Admin_Page::add_query_args_and_nonce(
613
-            ['action' => 'reattempt_migration'],
614
-            EE_MAINTENANCE_ADMIN_URL
615
-        );
616
-        $this->_template_path                          =
617
-            EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
618
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
619
-            $this->_template_path,
620
-            $this->_template_args,
621
-            true
622
-        );
623
-        $this->display_admin_page_with_sidebar();
624
-    }
625
-
626
-
627
-    /**
628
-     * Resets the entire EE4 database.
629
-     * only sets up ee4 database for a fresh install-
630
-     * doesn't actually clean out the old wp options, or cpts
631
-     * (although it does erase old ee table data)
632
-     *
633
-     * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data,
634
-     *                                   or just try initializing ee4 default data
635
-     * @throws EE_Error
636
-     * @throws ReflectionException
637
-     */
638
-    public function _reset_db($nuke_old_ee4_data = true)
639
-    {
640
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
641
-        if ($nuke_old_ee4_data) {
642
-            EEH_Activation::delete_all_espresso_cpt_data();
643
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
644
-            EEH_Activation::remove_cron_tasks();
645
-        }
646
-        // make sure when we reset the registry's config that it
647
-        // switches to using the new singleton
648
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
649
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
650
-        EE_System::instance()->redirect_to_about_ee();
651
-    }
652
-
653
-
654
-    /**
655
-     * Deletes ALL EE tables, Records, and Options from the database.
656
-     *
657
-     * @throws EE_Error
658
-     * @throws ReflectionException
659
-     */
660
-    public function _delete_db()
661
-    {
662
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
663
-        EEH_Activation::delete_all_espresso_cpt_data();
664
-        EEH_Activation::delete_all_espresso_tables_and_data();
665
-        EEH_Activation::remove_cron_tasks();
666
-        EEH_Activation::deactivate_event_espresso();
667
-        wp_safe_redirect(admin_url('plugins.php'));
668
-        exit;
669
-    }
670
-
671
-
672
-    /**
673
-     * sets up EE4 to rerun the migrations from ee3 to ee4
674
-     *
675
-     * @throws EE_Error
676
-     * @throws ReflectionException
677
-     */
678
-    public function _rerun_migration_from_ee3()
679
-    {
680
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
681
-        EEH_Activation::delete_all_espresso_cpt_data();
682
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
683
-        // set the db state to something that will require migrations
684
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
685
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
686
-        $this->_redirect_after_action(
687
-            true,
688
-            esc_html__("Database", 'event_espresso'),
689
-            esc_html__("reset", 'event_espresso')
690
-        );
691
-    }
692
-
693
-
694
-    // none of the below group are currently used for Gateway Settings
695
-    protected function _add_screen_options()
696
-    {
697
-    }
698
-
699
-
700
-    protected function _add_feature_pointers()
701
-    {
702
-    }
703
-
704
-
705
-    public function admin_init()
706
-    {
707
-    }
708
-
709
-
710
-    public function admin_notices()
711
-    {
712
-    }
713
-
714
-
715
-    public function admin_footer_scripts()
716
-    {
717
-    }
718
-
719
-
720
-    public function load_scripts_styles()
721
-    {
722
-        wp_enqueue_script('ee_admin_js');
723
-        wp_enqueue_script(
724
-            'ee-maintenance',
725
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
726
-            ['jquery'],
727
-            EVENT_ESPRESSO_VERSION,
728
-            true
729
-        );
730
-        wp_register_style(
731
-            'espresso_maintenance',
732
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
733
-            [],
734
-            EVENT_ESPRESSO_VERSION
735
-        );
736
-        wp_enqueue_style('espresso_maintenance');
737
-        // localize script stuff
738
-        wp_localize_script(
739
-            'ee-maintenance',
740
-            'ee_maintenance',
741
-            [
742
-                'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
743
-                'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
744
-                'fatal_error'                      => wp_strip_all_tags(__(
745
-                    "A Fatal Error Has Occurred",
746
-                    "event_espresso"
747
-                )),
748
-                'click_next_when_ready'            => wp_strip_all_tags(
749
-                    __(
750
-                        "The current Database Update has ended. Click 'next' when ready to proceed",
751
-                        "event_espresso"
752
-                    )
753
-                ),
754
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
755
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
756
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
757
-                'confirm'                          => wp_strip_all_tags(
758
-                    __(
759
-                        'Are you sure you want to do this? It CANNOT be undone!',
760
-                        'event_espresso'
761
-                    )
762
-                ),
763
-                'confirm_skip_migration'           => wp_strip_all_tags(
764
-                    __(
765
-                        'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
766
-                        'event_espresso'
767
-                    )
768
-                ),
769
-            ]
770
-        );
771
-    }
772
-
773
-
774
-    public function load_scripts_styles_default()
775
-    {
776
-    }
777
-
778
-
779
-    /**
780
-     * Enqueue scripts and styles for the datetime tools page.
781
-     */
782
-    public function load_scripts_styles_datetime_tools()
783
-    {
784
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
785
-    }
786
-
787
-
788
-    /**
789
-     * @throws EE_Error
790
-     */
791
-    protected function _datetime_tools()
792
-    {
793
-        $form_action                                = EE_Admin_Page::add_query_args_and_nonce(
794
-            [
795
-                'action'        => 'run_datetime_offset_fix',
796
-                'return_action' => $this->_req_action,
797
-            ],
798
-            EE_MAINTENANCE_ADMIN_URL
799
-        );
800
-        $form                                       = $this->_get_datetime_offset_fix_form();
801
-        $this->_admin_page_title                    = esc_html__('Datetime Utilities', 'event_espresso');
802
-        $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
803
-                                                      . $form->get_html_and_js()
804
-                                                      . $form->form_close();
805
-        $this->display_admin_page_with_sidebar();
806
-    }
807
-
808
-
809
-    /**
810
-     * @throws EE_Error
811
-     */
812
-    protected function _get_datetime_offset_fix_form()
813
-    {
814
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
815
-            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
816
-                [
817
-                    'name'            => 'datetime_offset_fix_option',
818
-                    'layout_strategy' => new EE_Admin_Two_Column_Layout(),
819
-                    'subsections'     => [
820
-                        'title'                  => new EE_Form_Section_HTML(
821
-                            EEH_HTML::h2(
822
-                                esc_html__('Datetime Offset Tool', 'event_espresso')
823
-                            )
824
-                        ),
825
-                        'explanation'            => new EE_Form_Section_HTML(
826
-                            EEH_HTML::p(
827
-                                esc_html__(
828
-                                    'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
829
-                                    'event_espresso'
830
-                                )
831
-                            )
832
-                            . EEH_HTML::p(
833
-                                esc_html__(
834
-                                    'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
835
-                                    'event_espresso'
836
-                                )
837
-                            )
838
-                        ),
839
-                        'offset_input'           => new EE_Float_Input(
840
-                            [
841
-                                'html_name'       => 'offset_for_datetimes',
842
-                                'html_label_text' => esc_html__(
843
-                                    'Offset to apply (in hours):',
844
-                                    'event_espresso'
845
-                                ),
846
-                                'min_value'       => '-12',
847
-                                'max_value'       => '14',
848
-                                'step_value'      => '.25',
849
-                                'default'         => DatetimeOffsetFix::getOffset(),
850
-                            ]
851
-                        ),
852
-                        'date_range_explanation' => new EE_Form_Section_HTML(
853
-                            EEH_HTML::p(
854
-                                esc_html__(
855
-                                    'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
856
-                                    'event_espresso'
857
-                                )
858
-                            )
859
-                            . EEH_HTML::p(
860
-                                EEH_HTML::strong(
861
-                                    sprintf(
862
-                                        esc_html__(
863
-                                            'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
864
-                                            'event_espresso'
865
-                                        ),
866
-                                        '<a href="https://www.timeanddate.com/worldclock/converter.html">',
867
-                                        '</a>'
868
-                                    )
869
-                                )
870
-                            )
871
-                        ),
872
-                        'date_range_start_date'  => new EE_Datepicker_Input(
873
-                            [
874
-                                'html_name'       => 'offset_date_start_range',
875
-                                'html_label_text' => esc_html__(
876
-                                    'Start Date for dates the offset applied to:',
877
-                                    'event_espresso'
878
-                                ),
879
-                            ]
880
-                        ),
881
-                        'date_range_end_date'    => new EE_Datepicker_Input(
882
-                            [
883
-                                'html_name'       => 'offset_date_end_range',
884
-                                'html_label_text' => esc_html__(
885
-                                    'End Date for dates the offset is applied to:',
886
-                                    'event_espresso'
887
-                                ),
888
-                            ]
889
-                        ),
890
-                        'submit'                 => new EE_Submit_Input(
891
-                            [
892
-                                'html_label_text' => '',
893
-                                'default'         => esc_html__('Apply Offset', 'event_espresso'),
894
-                            ]
895
-                        ),
896
-                    ],
897
-                ]
898
-            );
899
-        }
900
-        return $this->datetime_fix_offset_form;
901
-    }
902
-
903
-
904
-    /**
905
-     * Callback for the run_datetime_offset_fix route.
906
-     *
907
-     * @throws EE_Error
908
-     */
909
-    protected function _apply_datetime_offset()
910
-    {
911
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
912
-            $form = $this->_get_datetime_offset_fix_form();
913
-            $form->receive_form_submission($this->_req_data);
914
-            if ($form->is_valid()) {
915
-                // save offset data so batch processor can get it.
916
-                DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
917
-                $utc_timezone          = new DateTimeZone('UTC');
918
-                $date_range_start_date = DateTime::createFromFormat(
919
-                    'm/d/Y H:i:s',
920
-                    $form->get_input_value('date_range_start_date') . ' 00:00:00',
921
-                    $utc_timezone
922
-                );
923
-                $date_range_end_date   = DateTime::createFromFormat(
924
-                    'm/d/Y H:i:s',
925
-                    $form->get_input_value('date_range_end_date') . ' 23:59:59',
926
-                    $utc_timezone
927
-                );
928
-                if ($date_range_start_date instanceof DateTime) {
929
-                    DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
930
-                }
931
-                if ($date_range_end_date instanceof DateTime) {
932
-                    DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
933
-                }
934
-                // redirect to batch tool
935
-                wp_redirect(
936
-                    EE_Admin_Page::add_query_args_and_nonce(
937
-                        [
938
-                            'page'        => EED_Batch::PAGE_SLUG,
17
+	/**
18
+	 * @var EE_Data_Migration_Manager
19
+	 */
20
+	protected $migration_manager;
21
+
22
+	/**
23
+	 * @var EE_Maintenance_Mode
24
+	 */
25
+	protected $maintenance_mode;
26
+
27
+	/**
28
+	 * @var EE_Form_Section_Proper
29
+	 */
30
+	protected $datetime_fix_offset_form;
31
+
32
+
33
+	/**
34
+	 * @param bool $routing
35
+	 * @throws EE_Error
36
+	 * @throws ReflectionException
37
+	 */
38
+	public function __construct($routing = true)
39
+	{
40
+		$this->migration_manager = EE_Data_Migration_Manager::instance();
41
+		$this->maintenance_mode  = EE_Maintenance_Mode::instance();
42
+		parent::__construct($routing);
43
+	}
44
+
45
+
46
+	protected function _init_page_props()
47
+	{
48
+		$this->page_slug        = EE_MAINTENANCE_PG_SLUG;
49
+		$this->page_label       = EE_MAINTENANCE_LABEL;
50
+		$this->_admin_base_url  = EE_MAINTENANCE_ADMIN_URL;
51
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
52
+	}
53
+
54
+
55
+	protected function _ajax_hooks()
56
+	{
57
+		add_action('wp_ajax_migration_step', [$this, 'migration_step']);
58
+		add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']);
59
+	}
60
+
61
+
62
+	protected function _define_page_props()
63
+	{
64
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
65
+		$this->_labels           = [
66
+			'buttons' => [
67
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
68
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
69
+			],
70
+		];
71
+	}
72
+
73
+
74
+	protected function _set_page_routes()
75
+	{
76
+		$this->_page_routes = [
77
+			'default'                             => [
78
+				'func'       => '_maintenance',
79
+				'capability' => 'manage_options',
80
+			],
81
+			'change_maintenance_level'            => [
82
+				'func'       => '_change_maintenance_level',
83
+				'capability' => 'manage_options',
84
+				'noheader'   => true,
85
+			],
86
+			'system_status'                       => [
87
+				'func'       => '_system_status',
88
+				'capability' => 'manage_options',
89
+			],
90
+			'download_system_status'              => [
91
+				'func'       => '_download_system_status',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			],
95
+			'send_migration_crash_report'         => [
96
+				'func'       => '_send_migration_crash_report',
97
+				'capability' => 'manage_options',
98
+				'noheader'   => true,
99
+			],
100
+			'confirm_migration_crash_report_sent' => [
101
+				'func'       => '_confirm_migration_crash_report_sent',
102
+				'capability' => 'manage_options',
103
+			],
104
+			'data_reset'                          => [
105
+				'func'       => '_data_reset_and_delete',
106
+				'capability' => 'manage_options',
107
+			],
108
+			'reset_db'                            => [
109
+				'func'       => '_reset_db',
110
+				'capability' => 'manage_options',
111
+				'noheader'   => true,
112
+				'args'       => ['nuke_old_ee4_data' => true],
113
+			],
114
+			'start_with_fresh_ee4_db'             => [
115
+				'func'       => '_reset_db',
116
+				'capability' => 'manage_options',
117
+				'noheader'   => true,
118
+				'args'       => ['nuke_old_ee4_data' => false],
119
+			],
120
+			'delete_db'                           => [
121
+				'func'       => '_delete_db',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			],
125
+			'rerun_migration_from_ee3'            => [
126
+				'func'       => '_rerun_migration_from_ee3',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			],
130
+			'reset_reservations'                  => [
131
+				'func'       => '_reset_reservations',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			],
135
+			'reset_capabilities'                  => [
136
+				'func'       => '_reset_capabilities',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			],
140
+			'reattempt_migration'                 => [
141
+				'func'       => '_reattempt_migration',
142
+				'capability' => 'manage_options',
143
+				'noheader'   => true,
144
+			],
145
+			'datetime_tools'                      => [
146
+				'func'       => '_datetime_tools',
147
+				'capability' => 'manage_options',
148
+			],
149
+			'run_datetime_offset_fix'             => [
150
+				'func'               => '_apply_datetime_offset',
151
+				'noheader'           => true,
152
+				'headers_sent_route' => 'datetime_tools',
153
+				'capability'         => 'manage_options',
154
+			],
155
+		];
156
+	}
157
+
158
+
159
+	protected function _set_page_config()
160
+	{
161
+		$this->_page_config = [
162
+			'default'        => [
163
+				'nav'           => [
164
+					'label' => esc_html__('Maintenance', 'event_espresso'),
165
+					'order' => 10,
166
+				],
167
+				'require_nonce' => false,
168
+			],
169
+			'data_reset'     => [
170
+				'nav'           => [
171
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
172
+					'order' => 20,
173
+				],
174
+				'require_nonce' => false,
175
+			],
176
+			'datetime_tools' => [
177
+				'nav'           => [
178
+					'label' => esc_html__('Datetime Utilities', 'event_espresso'),
179
+					'order' => 25,
180
+				],
181
+				'require_nonce' => false,
182
+			],
183
+			'system_status'  => [
184
+				'nav'           => [
185
+					'label' => esc_html__("System Information", "event_espresso"),
186
+					'order' => 30,
187
+				],
188
+				'require_nonce' => false,
189
+			],
190
+		];
191
+	}
192
+
193
+
194
+	/**
195
+	 * default maintenance page.
196
+	 * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI.
197
+	 *
198
+	 * @throws EE_Error
199
+	 */
200
+	public function _maintenance()
201
+	{
202
+		$show_maintenance_switch         = true;
203
+		$show_backup_db_text             = false;
204
+		$show_migration_progress         = false;
205
+		$script_names                    = [];
206
+		$addons_should_be_upgraded_first = false;
207
+		// it all depends on if we're in maintenance model level 1 (frontend-only) or
208
+		// level 2 (everything except maintenance page)
209
+		try {
210
+			// get the current maintenance level and check if
211
+			// we are removed
212
+			$mMode_level  = $this->maintenance_mode->level();
213
+			$placed_in_mm = $this->maintenance_mode->set_maintenance_mode_if_db_old();
214
+			if ($mMode_level == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
215
+				// we just took the site out of maintenance mode, so notify the user.
216
+				// unfortunately this message appears to be echoed on the NEXT page load...
217
+				// oh well, we should really be checking for this on addon deactivation anyways
218
+				EE_Error::add_attention(
219
+					esc_html__(
220
+						'Site taken out of maintenance mode because no data migration scripts are required',
221
+						'event_espresso'
222
+					)
223
+				);
224
+				$this->_process_notices(['page' => 'espresso_maintenance_settings']);
225
+			}
226
+			// in case an exception is thrown while trying to handle migrations
227
+			if ($mMode_level === EE_Maintenance_Mode::level_2_complete_maintenance) {
228
+				$show_maintenance_switch = false;
229
+				$show_migration_progress = true;
230
+				if (isset($this->_req_data['continue_migration'])) {
231
+					$show_backup_db_text = false;
232
+				} else {
233
+					$show_backup_db_text = true;
234
+				}
235
+				$scripts_needing_to_run          =
236
+					$this->migration_manager->check_for_applicable_data_migration_scripts();
237
+				$addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating();
238
+				$script_names                    = [];
239
+				$current_script                  = null;
240
+				foreach ($scripts_needing_to_run as $script) {
241
+					if ($script instanceof EE_Data_Migration_Script_Base) {
242
+						if (! $current_script) {
243
+							$current_script = $script;
244
+							$current_script->migration_page_hooks();
245
+						}
246
+						$script_names[] = $script->pretty_name();
247
+					}
248
+				}
249
+			}
250
+			$most_recent_migration = $this->migration_manager->get_last_ran_script(true);
251
+			$exception_thrown      = false;
252
+		} catch (EE_Error $e) {
253
+			$this->migration_manager->add_error_to_migrations_ran($e->getMessage());
254
+			// now, just so we can display the page correctly, make an error migration script stage object
255
+			// and also put the error on it. It only persists for the duration of this request
256
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
257
+			$most_recent_migration->add_error($e->getMessage());
258
+			$exception_thrown = true;
259
+		}
260
+		$current_db_state = $this->migration_manager->ensure_current_database_state_is_set();
261
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
262
+		if (
263
+			$exception_thrown
264
+			|| (
265
+				$most_recent_migration instanceof EE_Data_Migration_Script_Base
266
+				&& $most_recent_migration->is_broken()
267
+			)
268
+		) {
269
+			$this->_template_path                =
270
+				EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
271
+			$this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/';
272
+			$this->_template_args['next_url']    = EEH_URL::add_query_args_and_nonce(
273
+				[
274
+					'action'  => 'confirm_migration_crash_report_sent',
275
+					'success' => '0',
276
+				],
277
+				EE_MAINTENANCE_ADMIN_URL
278
+			);
279
+		} elseif ($addons_should_be_upgraded_first) {
280
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
281
+		} else {
282
+			if (
283
+				$most_recent_migration instanceof EE_Data_Migration_Script_Base
284
+				&& $most_recent_migration->can_continue()
285
+			) {
286
+				$show_backup_db_text                    = false;
287
+				$show_continue_current_migration_script = true;
288
+				$show_most_recent_migration             = true;
289
+			} elseif (isset($this->_req_data['continue_migration'])) {
290
+				$show_most_recent_migration             = true;
291
+				$show_continue_current_migration_script = false;
292
+			} else {
293
+				$show_most_recent_migration             = false;
294
+				$show_continue_current_migration_script = false;
295
+			}
296
+			if (isset($current_script)) {
297
+				$migrates_to          = $current_script->migrates_to_version();
298
+				$plugin_slug          = $migrates_to['slug'];
299
+				$new_version          = $migrates_to['version'];
300
+				$this->_template_args = array_merge(
301
+					$this->_template_args,
302
+					[
303
+						'current_db_state' => sprintf(
304
+							esc_html__("EE%s (%s)", "event_espresso"),
305
+							isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
306
+							$plugin_slug
307
+						),
308
+						'next_db_state'    => sprintf(
309
+							esc_html__("EE%s (%s)", 'event_espresso'),
310
+							$new_version,
311
+							$plugin_slug
312
+						),
313
+					]
314
+				);
315
+			} else {
316
+				$this->_template_args['current_db_state'] = null;
317
+				$this->_template_args['next_db_state']    = null;
318
+			}
319
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
320
+			$this->_template_args = array_merge(
321
+				$this->_template_args,
322
+				[
323
+					'show_most_recent_migration'             => $show_most_recent_migration,
324
+					// flag for showing the most recent migration's status and/or errors
325
+					'show_migration_progress'                => $show_migration_progress,
326
+					// flag for showing the option to run migrations and see their progress
327
+					'show_backup_db_text'                    => $show_backup_db_text,
328
+					// flag for showing text telling the user to back up their DB
329
+					'show_maintenance_switch'                => $show_maintenance_switch,
330
+					// flag for showing the option to change maintenance mode between levels 0 and 1
331
+					'script_names'                           => $script_names,
332
+					// array of names of scripts that have run
333
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
334
+					// flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
335
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
336
+						['action' => 'reset_db'],
337
+						EE_MAINTENANCE_ADMIN_URL
338
+					),
339
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
340
+						['action' => 'data_reset'],
341
+						EE_MAINTENANCE_ADMIN_URL
342
+					),
343
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
344
+						['action' => 'change_maintenance_level'],
345
+						EE_MAINTENANCE_ADMIN_URL
346
+					),
347
+					'ultimate_db_state'                      => sprintf(
348
+						esc_html__("EE%s", 'event_espresso'),
349
+						espresso_version()
350
+					),
351
+				]
352
+			);
353
+		}
354
+		$this->_template_args['most_recent_migration'] =
355
+			$most_recent_migration;// the actual most recently ran migration
356
+		// now render the migration options part, and put it in a variable
357
+		$migration_options_template_file                = apply_filters(
358
+			'FHEE__ee_migration_page__migration_options_template',
359
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
360
+		);
361
+		$migration_options_html                         = EEH_Template::display_template(
362
+			$migration_options_template_file,
363
+			$this->_template_args,
364
+			true
365
+		);
366
+		$this->_template_args['migration_options_html'] = $migration_options_html;
367
+		$this->_template_args['admin_page_content']     = EEH_Template::display_template(
368
+			$this->_template_path,
369
+			$this->_template_args,
370
+			true
371
+		);
372
+		$this->display_admin_page_with_sidebar();
373
+	}
374
+
375
+
376
+	/**
377
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
378
+	 *
379
+	 * @throws EE_Error
380
+	 */
381
+	public function migration_step()
382
+	{
383
+		$this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request();
384
+		$this->_return_json();
385
+	}
386
+
387
+
388
+	/**
389
+	 * Can be used by js when it notices a response with HTML in it in order
390
+	 * to log the malformed response
391
+	 *
392
+	 * @throws EE_Error
393
+	 */
394
+	public function add_error_to_migrations_ran()
395
+	{
396
+		$this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']);
397
+		$this->_template_args['data'] = ['ok' => true];
398
+		$this->_return_json();
399
+	}
400
+
401
+
402
+	/**
403
+	 * changes the maintenance level, provided there are still no migration scripts that should run
404
+	 *
405
+	 * @throws EE_Error
406
+	 */
407
+	public function _change_maintenance_level()
408
+	{
409
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
410
+		if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) {
411
+			$this->maintenance_mode->set_maintenance_level($new_level);
412
+			$success = true;
413
+		} else {
414
+			$this->maintenance_mode->set_maintenance_mode_if_db_old();
415
+			$success = false;
416
+		}
417
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
418
+	}
419
+
420
+
421
+	/**
422
+	 * a tab with options for resetting and/or deleting EE data
423
+	 *
424
+	 * @throws EE_Error
425
+	 * @throws DomainException
426
+	 */
427
+	public function _data_reset_and_delete()
428
+	{
429
+		$this->_template_path                              =
430
+			EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
431
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
432
+			'reset_reservations',
433
+			'reset_reservations',
434
+			[],
435
+			'button button--caution ee-confirm'
436
+		);
437
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
438
+			'reset_capabilities',
439
+			'reset_capabilities',
440
+			[],
441
+			'button button--caution ee-confirm'
442
+		);
443
+		$this->_template_args['delete_db_url']             = EE_Admin_Page::add_query_args_and_nonce(
444
+			['action' => 'delete_db'],
445
+			EE_MAINTENANCE_ADMIN_URL
446
+		);
447
+		$this->_template_args['reset_db_url']              = EE_Admin_Page::add_query_args_and_nonce(
448
+			['action' => 'reset_db'],
449
+			EE_MAINTENANCE_ADMIN_URL
450
+		);
451
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
452
+			$this->_template_path,
453
+			$this->_template_args,
454
+			true
455
+		);
456
+		$this->display_admin_page_with_no_sidebar();
457
+	}
458
+
459
+
460
+	/**
461
+	 * @throws EE_Error
462
+	 * @throws ReflectionException
463
+	 */
464
+	protected function _reset_reservations()
465
+	{
466
+		if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
467
+			EE_Error::add_success(
468
+				esc_html__(
469
+					'Ticket and datetime reserved counts have been successfully reset.',
470
+					'event_espresso'
471
+				)
472
+			);
473
+		} else {
474
+			EE_Error::add_success(
475
+				esc_html__(
476
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
477
+					'event_espresso'
478
+				)
479
+			);
480
+		}
481
+		$this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true);
482
+	}
483
+
484
+
485
+	/**
486
+	 * @throws EE_Error
487
+	 */
488
+	protected function _reset_capabilities()
489
+	{
490
+		EE_Registry::instance()->CAP->init_caps(true);
491
+		EE_Error::add_success(
492
+			esc_html__(
493
+				'Default Event Espresso capabilities have been restored for all current roles.',
494
+				'event_espresso'
495
+			)
496
+		);
497
+		$this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true);
498
+	}
499
+
500
+
501
+	/**
502
+	 * resets the DMSs, so we can attempt to continue migrating after a fatal error
503
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
504
+	 * the fatal error in teh first place)
505
+	 *
506
+	 * @throws EE_Error
507
+	 */
508
+	protected function _reattempt_migration()
509
+	{
510
+		$this->migration_manager->reattempt();
511
+		$this->_redirect_after_action(false, '', '', ['action' => 'default'], true);
512
+	}
513
+
514
+
515
+	/**
516
+	 * shows the big ol' System Information page
517
+	 *
518
+	 * @throws EE_Error
519
+	 */
520
+	public function _system_status()
521
+	{
522
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
523
+		$this->_template_args['system_stati']               = EEM_System_Status::instance()->get_system_stati();
524
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
525
+			[
526
+				'action' => 'download_system_status',
527
+			],
528
+			EE_MAINTENANCE_ADMIN_URL
529
+		);
530
+		$this->_template_args['admin_page_content']         = EEH_Template::display_template(
531
+			$this->_template_path,
532
+			$this->_template_args,
533
+			true
534
+		);
535
+		$this->display_admin_page_with_no_sidebar();
536
+	}
537
+
538
+
539
+	/**
540
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
541
+	 */
542
+	public function _download_system_status()
543
+	{
544
+		$status_info = EEM_System_Status::instance()->get_system_stati();
545
+		header('Content-Disposition: attachment');
546
+		header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
547
+		$output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>';
548
+		$output .= '<h1>' . sprintf(
549
+			__('System Information for %1$s', 'event_espresso'),
550
+			esc_url_raw(site_url())
551
+		) . '</h1>';
552
+		$output .= EEH_Template::layout_array_as_table($status_info);
553
+		echo esc_html($output);
554
+		die;
555
+	}
556
+
557
+
558
+	/**
559
+	 * @throws EE_Error
560
+	 */
561
+	public function _send_migration_crash_report()
562
+	{
563
+		$from      = $this->_req_data['from'];
564
+		$from_name = $this->_req_data['from_name'];
565
+		$body      = $this->_req_data['body'];
566
+		try {
567
+			$success = wp_mail(
568
+				EE_SUPPORT_EMAIL,
569
+				'Migration Crash Report',
570
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
571
+				[
572
+					"from:$from_name<$from>",
573
+				]
574
+			);
575
+		} catch (Exception $e) {
576
+			$success = false;
577
+		}
578
+		$this->_redirect_after_action(
579
+			$success,
580
+			esc_html__("Migration Crash Report", "event_espresso"),
581
+			esc_html__("sent", "event_espresso"),
582
+			['success' => $success, 'action' => 'confirm_migration_crash_report_sent']
583
+		);
584
+	}
585
+
586
+
587
+	/**
588
+	 * @throws EE_Error
589
+	 */
590
+	public function _confirm_migration_crash_report_sent()
591
+	{
592
+		try {
593
+			$most_recent_migration = $this->migration_manager->get_last_ran_script(true);
594
+		} catch (EE_Error $e) {
595
+			$this->migration_manager->add_error_to_migrations_ran($e->getMessage());
596
+			// now, just so we can display the page correctly, make an error migration script stage object
597
+			// and also put the error on it. It only persists for the duration of this request
598
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
599
+			$most_recent_migration->add_error($e->getMessage());
600
+		}
601
+		$success                                       = $this->_req_data['success'] === '1';
602
+		$this->_template_args['success']               = $success;
603
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
604
+		$this->_template_args['reset_db_action_url']   = EE_Admin_Page::add_query_args_and_nonce(
605
+			['action' => 'reset_db'],
606
+			EE_MAINTENANCE_ADMIN_URL
607
+		);
608
+		$this->_template_args['reset_db_page_url']     = EE_Admin_Page::add_query_args_and_nonce(
609
+			['action' => 'data_reset'],
610
+			EE_MAINTENANCE_ADMIN_URL
611
+		);
612
+		$this->_template_args['reattempt_action_url']  = EE_Admin_Page::add_query_args_and_nonce(
613
+			['action' => 'reattempt_migration'],
614
+			EE_MAINTENANCE_ADMIN_URL
615
+		);
616
+		$this->_template_path                          =
617
+			EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
618
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
619
+			$this->_template_path,
620
+			$this->_template_args,
621
+			true
622
+		);
623
+		$this->display_admin_page_with_sidebar();
624
+	}
625
+
626
+
627
+	/**
628
+	 * Resets the entire EE4 database.
629
+	 * only sets up ee4 database for a fresh install-
630
+	 * doesn't actually clean out the old wp options, or cpts
631
+	 * (although it does erase old ee table data)
632
+	 *
633
+	 * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data,
634
+	 *                                   or just try initializing ee4 default data
635
+	 * @throws EE_Error
636
+	 * @throws ReflectionException
637
+	 */
638
+	public function _reset_db($nuke_old_ee4_data = true)
639
+	{
640
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
641
+		if ($nuke_old_ee4_data) {
642
+			EEH_Activation::delete_all_espresso_cpt_data();
643
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
644
+			EEH_Activation::remove_cron_tasks();
645
+		}
646
+		// make sure when we reset the registry's config that it
647
+		// switches to using the new singleton
648
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
649
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
650
+		EE_System::instance()->redirect_to_about_ee();
651
+	}
652
+
653
+
654
+	/**
655
+	 * Deletes ALL EE tables, Records, and Options from the database.
656
+	 *
657
+	 * @throws EE_Error
658
+	 * @throws ReflectionException
659
+	 */
660
+	public function _delete_db()
661
+	{
662
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
663
+		EEH_Activation::delete_all_espresso_cpt_data();
664
+		EEH_Activation::delete_all_espresso_tables_and_data();
665
+		EEH_Activation::remove_cron_tasks();
666
+		EEH_Activation::deactivate_event_espresso();
667
+		wp_safe_redirect(admin_url('plugins.php'));
668
+		exit;
669
+	}
670
+
671
+
672
+	/**
673
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
674
+	 *
675
+	 * @throws EE_Error
676
+	 * @throws ReflectionException
677
+	 */
678
+	public function _rerun_migration_from_ee3()
679
+	{
680
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
681
+		EEH_Activation::delete_all_espresso_cpt_data();
682
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
683
+		// set the db state to something that will require migrations
684
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
685
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
686
+		$this->_redirect_after_action(
687
+			true,
688
+			esc_html__("Database", 'event_espresso'),
689
+			esc_html__("reset", 'event_espresso')
690
+		);
691
+	}
692
+
693
+
694
+	// none of the below group are currently used for Gateway Settings
695
+	protected function _add_screen_options()
696
+	{
697
+	}
698
+
699
+
700
+	protected function _add_feature_pointers()
701
+	{
702
+	}
703
+
704
+
705
+	public function admin_init()
706
+	{
707
+	}
708
+
709
+
710
+	public function admin_notices()
711
+	{
712
+	}
713
+
714
+
715
+	public function admin_footer_scripts()
716
+	{
717
+	}
718
+
719
+
720
+	public function load_scripts_styles()
721
+	{
722
+		wp_enqueue_script('ee_admin_js');
723
+		wp_enqueue_script(
724
+			'ee-maintenance',
725
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
726
+			['jquery'],
727
+			EVENT_ESPRESSO_VERSION,
728
+			true
729
+		);
730
+		wp_register_style(
731
+			'espresso_maintenance',
732
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
733
+			[],
734
+			EVENT_ESPRESSO_VERSION
735
+		);
736
+		wp_enqueue_style('espresso_maintenance');
737
+		// localize script stuff
738
+		wp_localize_script(
739
+			'ee-maintenance',
740
+			'ee_maintenance',
741
+			[
742
+				'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
743
+				'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
744
+				'fatal_error'                      => wp_strip_all_tags(__(
745
+					"A Fatal Error Has Occurred",
746
+					"event_espresso"
747
+				)),
748
+				'click_next_when_ready'            => wp_strip_all_tags(
749
+					__(
750
+						"The current Database Update has ended. Click 'next' when ready to proceed",
751
+						"event_espresso"
752
+					)
753
+				),
754
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
755
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
756
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
757
+				'confirm'                          => wp_strip_all_tags(
758
+					__(
759
+						'Are you sure you want to do this? It CANNOT be undone!',
760
+						'event_espresso'
761
+					)
762
+				),
763
+				'confirm_skip_migration'           => wp_strip_all_tags(
764
+					__(
765
+						'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
766
+						'event_espresso'
767
+					)
768
+				),
769
+			]
770
+		);
771
+	}
772
+
773
+
774
+	public function load_scripts_styles_default()
775
+	{
776
+	}
777
+
778
+
779
+	/**
780
+	 * Enqueue scripts and styles for the datetime tools page.
781
+	 */
782
+	public function load_scripts_styles_datetime_tools()
783
+	{
784
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
785
+	}
786
+
787
+
788
+	/**
789
+	 * @throws EE_Error
790
+	 */
791
+	protected function _datetime_tools()
792
+	{
793
+		$form_action                                = EE_Admin_Page::add_query_args_and_nonce(
794
+			[
795
+				'action'        => 'run_datetime_offset_fix',
796
+				'return_action' => $this->_req_action,
797
+			],
798
+			EE_MAINTENANCE_ADMIN_URL
799
+		);
800
+		$form                                       = $this->_get_datetime_offset_fix_form();
801
+		$this->_admin_page_title                    = esc_html__('Datetime Utilities', 'event_espresso');
802
+		$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
803
+													  . $form->get_html_and_js()
804
+													  . $form->form_close();
805
+		$this->display_admin_page_with_sidebar();
806
+	}
807
+
808
+
809
+	/**
810
+	 * @throws EE_Error
811
+	 */
812
+	protected function _get_datetime_offset_fix_form()
813
+	{
814
+		if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
815
+			$this->datetime_fix_offset_form = new EE_Form_Section_Proper(
816
+				[
817
+					'name'            => 'datetime_offset_fix_option',
818
+					'layout_strategy' => new EE_Admin_Two_Column_Layout(),
819
+					'subsections'     => [
820
+						'title'                  => new EE_Form_Section_HTML(
821
+							EEH_HTML::h2(
822
+								esc_html__('Datetime Offset Tool', 'event_espresso')
823
+							)
824
+						),
825
+						'explanation'            => new EE_Form_Section_HTML(
826
+							EEH_HTML::p(
827
+								esc_html__(
828
+									'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
829
+									'event_espresso'
830
+								)
831
+							)
832
+							. EEH_HTML::p(
833
+								esc_html__(
834
+									'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
835
+									'event_espresso'
836
+								)
837
+							)
838
+						),
839
+						'offset_input'           => new EE_Float_Input(
840
+							[
841
+								'html_name'       => 'offset_for_datetimes',
842
+								'html_label_text' => esc_html__(
843
+									'Offset to apply (in hours):',
844
+									'event_espresso'
845
+								),
846
+								'min_value'       => '-12',
847
+								'max_value'       => '14',
848
+								'step_value'      => '.25',
849
+								'default'         => DatetimeOffsetFix::getOffset(),
850
+							]
851
+						),
852
+						'date_range_explanation' => new EE_Form_Section_HTML(
853
+							EEH_HTML::p(
854
+								esc_html__(
855
+									'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
856
+									'event_espresso'
857
+								)
858
+							)
859
+							. EEH_HTML::p(
860
+								EEH_HTML::strong(
861
+									sprintf(
862
+										esc_html__(
863
+											'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
864
+											'event_espresso'
865
+										),
866
+										'<a href="https://www.timeanddate.com/worldclock/converter.html">',
867
+										'</a>'
868
+									)
869
+								)
870
+							)
871
+						),
872
+						'date_range_start_date'  => new EE_Datepicker_Input(
873
+							[
874
+								'html_name'       => 'offset_date_start_range',
875
+								'html_label_text' => esc_html__(
876
+									'Start Date for dates the offset applied to:',
877
+									'event_espresso'
878
+								),
879
+							]
880
+						),
881
+						'date_range_end_date'    => new EE_Datepicker_Input(
882
+							[
883
+								'html_name'       => 'offset_date_end_range',
884
+								'html_label_text' => esc_html__(
885
+									'End Date for dates the offset is applied to:',
886
+									'event_espresso'
887
+								),
888
+							]
889
+						),
890
+						'submit'                 => new EE_Submit_Input(
891
+							[
892
+								'html_label_text' => '',
893
+								'default'         => esc_html__('Apply Offset', 'event_espresso'),
894
+							]
895
+						),
896
+					],
897
+				]
898
+			);
899
+		}
900
+		return $this->datetime_fix_offset_form;
901
+	}
902
+
903
+
904
+	/**
905
+	 * Callback for the run_datetime_offset_fix route.
906
+	 *
907
+	 * @throws EE_Error
908
+	 */
909
+	protected function _apply_datetime_offset()
910
+	{
911
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
912
+			$form = $this->_get_datetime_offset_fix_form();
913
+			$form->receive_form_submission($this->_req_data);
914
+			if ($form->is_valid()) {
915
+				// save offset data so batch processor can get it.
916
+				DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
917
+				$utc_timezone          = new DateTimeZone('UTC');
918
+				$date_range_start_date = DateTime::createFromFormat(
919
+					'm/d/Y H:i:s',
920
+					$form->get_input_value('date_range_start_date') . ' 00:00:00',
921
+					$utc_timezone
922
+				);
923
+				$date_range_end_date   = DateTime::createFromFormat(
924
+					'm/d/Y H:i:s',
925
+					$form->get_input_value('date_range_end_date') . ' 23:59:59',
926
+					$utc_timezone
927
+				);
928
+				if ($date_range_start_date instanceof DateTime) {
929
+					DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
930
+				}
931
+				if ($date_range_end_date instanceof DateTime) {
932
+					DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
933
+				}
934
+				// redirect to batch tool
935
+				wp_redirect(
936
+					EE_Admin_Page::add_query_args_and_nonce(
937
+						[
938
+							'page'        => EED_Batch::PAGE_SLUG,
939 939
 							'batch' 	  => EED_Batch::batch_job,
940
-                            'label'       => esc_html__('Applying Offset', 'event_espresso'),
941
-                            'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
942
-                            'return_url'  => urlencode(
943
-                                add_query_arg(
944
-                                    [
945
-                                        'action' => 'datetime_tools',
946
-                                    ],
947
-                                    EEH_URL::current_url_without_query_paramaters(
948
-                                        [
949
-                                            'return_action',
950
-                                            'run_datetime_offset_fix_nonce',
951
-                                            'return',
952
-                                            'datetime_tools_nonce',
953
-                                        ]
954
-                                    )
955
-                                )
956
-                            ),
957
-                        ],
958
-                        admin_url()
959
-                    )
960
-                );
961
-                exit;
962
-            }
963
-        }
964
-    }
940
+							'label'       => esc_html__('Applying Offset', 'event_espresso'),
941
+							'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
942
+							'return_url'  => urlencode(
943
+								add_query_arg(
944
+									[
945
+										'action' => 'datetime_tools',
946
+									],
947
+									EEH_URL::current_url_without_query_paramaters(
948
+										[
949
+											'return_action',
950
+											'run_datetime_offset_fix_nonce',
951
+											'return',
952
+											'datetime_tools_nonce',
953
+										]
954
+									)
955
+								)
956
+							),
957
+						],
958
+						admin_url()
959
+					)
960
+				);
961
+				exit;
962
+			}
963
+		}
964
+	}
965 965
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +4178 added lines, -4178 removed lines patch added patch discarded remove patch
@@ -21,4264 +21,4264 @@
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
23 23
 {
24
-    /**
25
-     * @var EE_Admin_Config
26
-     */
27
-    protected $admin_config;
24
+	/**
25
+	 * @var EE_Admin_Config
26
+	 */
27
+	protected $admin_config;
28 28
 
29
-    /**
30
-     * @var LoaderInterface
31
-     */
32
-    protected $loader;
29
+	/**
30
+	 * @var LoaderInterface
31
+	 */
32
+	protected $loader;
33 33
 
34
-    /**
35
-     * @var RequestInterface
36
-     */
37
-    protected $request;
34
+	/**
35
+	 * @var RequestInterface
36
+	 */
37
+	protected $request;
38 38
 
39
-    // set in _init_page_props()
40
-    public $page_slug;
39
+	// set in _init_page_props()
40
+	public $page_slug;
41 41
 
42
-    public $page_label;
42
+	public $page_label;
43 43
 
44
-    public $page_folder;
44
+	public $page_folder;
45 45
 
46
-    // set in define_page_props()
47
-    protected $_admin_base_url;
46
+	// set in define_page_props()
47
+	protected $_admin_base_url;
48 48
 
49
-    protected $_admin_base_path;
49
+	protected $_admin_base_path;
50 50
 
51
-    protected $_admin_page_title;
51
+	protected $_admin_page_title;
52 52
 
53
-    protected $_labels;
53
+	protected $_labels;
54 54
 
55 55
 
56
-    // set early within EE_Admin_Init
57
-    protected $_wp_page_slug;
56
+	// set early within EE_Admin_Init
57
+	protected $_wp_page_slug;
58 58
 
59
-    // nav tabs
60
-    protected $_nav_tabs;
59
+	// nav tabs
60
+	protected $_nav_tabs;
61 61
 
62
-    protected $_default_nav_tab_name;
62
+	protected $_default_nav_tab_name;
63 63
 
64 64
 
65
-    // template variables (used by templates)
66
-    protected $_template_path;
65
+	// template variables (used by templates)
66
+	protected $_template_path;
67 67
 
68
-    protected $_column_template_path;
68
+	protected $_column_template_path;
69 69
 
70
-    /**
71
-     * @var array $_template_args
72
-     */
73
-    protected $_template_args = [];
70
+	/**
71
+	 * @var array $_template_args
72
+	 */
73
+	protected $_template_args = [];
74 74
 
75
-    /**
76
-     * this will hold the list table object for a given view.
77
-     *
78
-     * @var EE_Admin_List_Table $_list_table_object
79
-     */
80
-    protected $_list_table_object;
75
+	/**
76
+	 * this will hold the list table object for a given view.
77
+	 *
78
+	 * @var EE_Admin_List_Table $_list_table_object
79
+	 */
80
+	protected $_list_table_object;
81 81
 
82
-    // boolean
83
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
82
+	// boolean
83
+	protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
84 84
 
85
-    protected $_routing;
85
+	protected $_routing;
86 86
 
87
-    // list table args
88
-    protected $_view;
87
+	// list table args
88
+	protected $_view;
89 89
 
90
-    protected $_views;
90
+	protected $_views;
91 91
 
92 92
 
93
-    // action => method pairs used for routing incoming requests
94
-    protected $_page_routes;
93
+	// action => method pairs used for routing incoming requests
94
+	protected $_page_routes;
95 95
 
96
-    /**
97
-     * @var array $_page_config
98
-     */
99
-    protected $_page_config;
96
+	/**
97
+	 * @var array $_page_config
98
+	 */
99
+	protected $_page_config;
100 100
 
101
-    /**
102
-     * the current page route and route config
103
-     *
104
-     * @var string $_route
105
-     */
106
-    protected $_route;
101
+	/**
102
+	 * the current page route and route config
103
+	 *
104
+	 * @var string $_route
105
+	 */
106
+	protected $_route;
107 107
 
108
-    /**
109
-     * @var string $_cpt_route
110
-     */
111
-    protected $_cpt_route;
108
+	/**
109
+	 * @var string $_cpt_route
110
+	 */
111
+	protected $_cpt_route;
112 112
 
113
-    /**
114
-     * @var array $_route_config
115
-     */
116
-    protected $_route_config;
113
+	/**
114
+	 * @var array $_route_config
115
+	 */
116
+	protected $_route_config;
117 117
 
118
-    /**
119
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
120
-     * actions.
121
-     *
122
-     * @since 4.6.x
123
-     * @var array.
124
-     */
125
-    protected $_default_route_query_args;
118
+	/**
119
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
120
+	 * actions.
121
+	 *
122
+	 * @since 4.6.x
123
+	 * @var array.
124
+	 */
125
+	protected $_default_route_query_args;
126 126
 
127
-    // set via request page and action args.
128
-    protected $_current_page;
127
+	// set via request page and action args.
128
+	protected $_current_page;
129 129
 
130
-    protected $_current_view;
130
+	protected $_current_view;
131 131
 
132
-    protected $_current_page_view_url;
132
+	protected $_current_page_view_url;
133 133
 
134
-    /**
135
-     * unprocessed value for the 'action' request param (default '')
136
-     *
137
-     * @var string
138
-     */
139
-    protected $raw_req_action = '';
134
+	/**
135
+	 * unprocessed value for the 'action' request param (default '')
136
+	 *
137
+	 * @var string
138
+	 */
139
+	protected $raw_req_action = '';
140 140
 
141
-    /**
142
-     * unprocessed value for the 'page' request param (default '')
143
-     *
144
-     * @var string
145
-     */
146
-    protected $raw_req_page = '';
147
-
148
-    /**
149
-     * sanitized request action (and nonce)
150
-     *
151
-     * @var string
152
-     */
153
-    protected $_req_action = '';
154
-
155
-    /**
156
-     * sanitized request action nonce
157
-     *
158
-     * @var string
159
-     */
160
-    protected $_req_nonce = '';
161
-
162
-    /**
163
-     * @var string
164
-     */
165
-    protected $_search_btn_label = '';
166
-
167
-    /**
168
-     * @var string
169
-     */
170
-    protected $_search_box_callback = '';
171
-
172
-    /**
173
-     * @var WP_Screen
174
-     */
175
-    protected $_current_screen;
176
-
177
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
178
-    protected $_hook_obj;
179
-
180
-    // for holding incoming request data
181
-    protected $_req_data = [];
182
-
183
-    // yes / no array for admin form fields
184
-    protected $_yes_no_values = [];
185
-
186
-    // some default things shared by all child classes
187
-    protected $_default_espresso_metaboxes = [
188
-        '_espresso_news_post_box',
189
-        '_espresso_links_post_box',
190
-        '_espresso_ratings_request',
191
-        '_espresso_sponsors_post_box',
192
-    ];
193
-
194
-    /**
195
-     * @var EE_Registry
196
-     */
197
-    protected $EE;
198
-
199
-
200
-    /**
201
-     * This is just a property that flags whether the given route is a caffeinated route or not.
202
-     *
203
-     * @var boolean
204
-     */
205
-    protected $_is_caf = false;
206
-
207
-    /**
208
-     * whether or not initializePage() has run
209
-     *
210
-     * @var boolean
211
-     */
212
-    protected $initialized = false;
213
-
214
-    /**
215
-     * @var FeatureFlags
216
-     */
217
-    protected $feature;
218
-
219
-
220
-    /**
221
-     * @var string
222
-     */
223
-    protected $class_name;
224
-
225
-    /**
226
-     * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
227
-     * then this would be the parent classname: Events_Admin_Page
228
-     *
229
-     * @var string
230
-     */
231
-    protected $base_class_name;
232
-
233
-
234
-    /**
235
-     * @Constructor
236
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
237
-     * @throws InvalidArgumentException
238
-     * @throws InvalidDataTypeException
239
-     * @throws InvalidInterfaceException
240
-     * @throws ReflectionException
241
-     */
242
-    public function __construct($routing = true)
243
-    {
244
-        $this->loader = LoaderFactory::getLoader();
245
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
246
-        $this->feature = $this->loader->getShared(FeatureFlags::class);
247
-        $this->request = $this->loader->getShared(RequestInterface::class);
248
-        // routing enabled?
249
-        $this->_routing = $routing;
250
-
251
-        $this->class_name = get_class($this);
252
-        $this->base_class_name = strpos($this->class_name, 'Extend_') === 0
253
-            ? str_replace('Extend_', '', $this->class_name)
254
-            : '';
255
-
256
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
257
-            $this->_is_caf = true;
258
-        }
259
-        $this->_yes_no_values = [
260
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
261
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
262
-        ];
263
-        // set the _req_data property.
264
-        $this->_req_data = $this->request->requestParams();
265
-    }
266
-
267
-
268
-    /**
269
-     * @return EE_Admin_Config
270
-     */
271
-    public function adminConfig(): EE_Admin_Config
272
-    {
273
-        return $this->admin_config;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return FeatureFlags
279
-     */
280
-    public function feature(): FeatureFlags
281
-    {
282
-        return $this->feature;
283
-    }
284
-
285
-
286
-    /**
287
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
288
-     * for child classes that needed to set properties prior to these methods getting called,
289
-     * but also needed the parent class to have its construction completed as well.
290
-     * Bottom line is that constructors should ONLY be used for setting initial properties
291
-     * and any complex initialization logic should only run after instantiation is complete.
292
-     *
293
-     * This method gets called immediately after construction from within
294
-     *      EE_Admin_Page_Init::_initialize_admin_page()
295
-     *
296
-     * @throws EE_Error
297
-     * @throws InvalidArgumentException
298
-     * @throws InvalidDataTypeException
299
-     * @throws InvalidInterfaceException
300
-     * @throws ReflectionException
301
-     * @since $VID:$
302
-     */
303
-    public function initializePage()
304
-    {
305
-        if ($this->initialized) {
306
-            return;
307
-        }
308
-        // set initial page props (child method)
309
-        $this->_init_page_props();
310
-        // set global defaults
311
-        $this->_set_defaults();
312
-        // set early because incoming requests could be ajax related and we need to register those hooks.
313
-        $this->_global_ajax_hooks();
314
-        $this->_ajax_hooks();
315
-        // other_page_hooks have to be early too.
316
-        $this->_do_other_page_hooks();
317
-        // set up page dependencies
318
-        $this->_before_page_setup();
319
-        $this->_page_setup();
320
-        $this->initialized = true;
321
-    }
322
-
323
-
324
-    /**
325
-     * _init_page_props
326
-     * Child classes use to set at least the following properties:
327
-     * $page_slug.
328
-     * $page_label.
329
-     *
330
-     * @abstract
331
-     * @return void
332
-     */
333
-    abstract protected function _init_page_props();
334
-
335
-
336
-    /**
337
-     * _ajax_hooks
338
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
339
-     * Note: within the ajax callback methods.
340
-     *
341
-     * @abstract
342
-     * @return void
343
-     */
344
-    abstract protected function _ajax_hooks();
345
-
346
-
347
-    /**
348
-     * _define_page_props
349
-     * child classes define page properties in here.  Must include at least:
350
-     * $_admin_base_url = base_url for all admin pages
351
-     * $_admin_page_title = default admin_page_title for admin pages
352
-     * $_labels = array of default labels for various automatically generated elements:
353
-     *    array(
354
-     *        'buttons' => array(
355
-     *            'add' => esc_html__('label for add new button'),
356
-     *            'edit' => esc_html__('label for edit button'),
357
-     *            'delete' => esc_html__('label for delete button')
358
-     *            )
359
-     *        )
360
-     *
361
-     * @abstract
362
-     * @return void
363
-     */
364
-    abstract protected function _define_page_props();
365
-
366
-
367
-    /**
368
-     * _set_page_routes
369
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
370
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
371
-     * have a 'default' route. Here's the format
372
-     * $this->_page_routes = array(
373
-     *        'default' => array(
374
-     *            'func' => '_default_method_handling_route',
375
-     *            'args' => array('array','of','args'),
376
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
377
-     *            ajax request, backend processing)
378
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
379
-     *            headers route after.  The string you enter here should match the defined route reference for a
380
-     *            headers sent route.
381
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
382
-     *            this route.
383
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
384
-     *            checks).
385
-     *        ),
386
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
387
-     *        handling method.
388
-     *        )
389
-     * )
390
-     *
391
-     * @abstract
392
-     * @return void
393
-     */
394
-    abstract protected function _set_page_routes();
395
-
396
-
397
-    /**
398
-     * _set_page_config
399
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
400
-     * array corresponds to the page_route for the loaded page. Format:
401
-     * $this->_page_config = array(
402
-     *        'default' => array(
403
-     *            'labels' => array(
404
-     *                'buttons' => array(
405
-     *                    'add' => esc_html__('label for adding item'),
406
-     *                    'edit' => esc_html__('label for editing item'),
407
-     *                    'delete' => esc_html__('label for deleting item')
408
-     *                ),
409
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
410
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
411
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
412
-     *            _define_page_props() method
413
-     *            'nav' => array(
414
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
415
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
416
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
417
-     *                'order' => 10, //required to indicate tab position.
418
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
419
-     *                displayed then add this parameter.
420
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
421
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
422
-     *            metaboxes set for eventespresso admin pages.
423
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
424
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
425
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
426
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
427
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
428
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
429
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
430
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
431
-     *            want to display.
432
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
433
-     *                'tab_id' => array(
434
-     *                    'title' => 'tab_title',
435
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
436
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
437
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
438
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
439
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
440
-     *                    attempt to use the callback which should match the name of a method in the class
441
-     *                    ),
442
-     *                'tab2_id' => array(
443
-     *                    'title' => 'tab2 title',
444
-     *                    'filename' => 'file_name_2'
445
-     *                    'callback' => 'callback_method_for_content',
446
-     *                 ),
447
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
448
-     *            help tab area on an admin page. @return void
449
-     *
450
-     * @abstract
451
-     */
452
-    abstract protected function _set_page_config();
453
-
454
-
455
-    /**
456
-     * _add_screen_options
457
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
458
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
459
-     * to a particular view.
460
-     *
461
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
462
-     *         see also WP_Screen object documents...
463
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
464
-     * @abstract
465
-     * @return void
466
-     */
467
-    abstract protected function _add_screen_options();
468
-
469
-
470
-    /**
471
-     * _add_feature_pointers
472
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
473
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
474
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
475
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
476
-     * extended) also see:
477
-     *
478
-     * @link   http://eamann.com/tech/wordpress-portland/
479
-     * @abstract
480
-     * @return void
481
-     */
482
-    abstract protected function _add_feature_pointers();
483
-
484
-
485
-    /**
486
-     * load_scripts_styles
487
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
488
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
489
-     * scripts/styles per view by putting them in a dynamic function in this format
490
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
491
-     *
492
-     * @abstract
493
-     * @return void
494
-     */
495
-    abstract public function load_scripts_styles();
496
-
497
-
498
-    /**
499
-     * admin_init
500
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
501
-     * all pages/views loaded by child class.
502
-     *
503
-     * @abstract
504
-     * @return void
505
-     */
506
-    abstract public function admin_init();
507
-
508
-
509
-    /**
510
-     * admin_notices
511
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
512
-     * all pages/views loaded by child class.
513
-     *
514
-     * @abstract
515
-     * @return void
516
-     */
517
-    abstract public function admin_notices();
518
-
519
-
520
-    /**
521
-     * admin_footer_scripts
522
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
523
-     * will apply to all pages/views loaded by child class.
524
-     *
525
-     * @return void
526
-     */
527
-    abstract public function admin_footer_scripts();
528
-
529
-
530
-    /**
531
-     * admin_footer
532
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
533
-     * apply to all pages/views loaded by child class.
534
-     *
535
-     * @return void
536
-     */
537
-    public function admin_footer()
538
-    {
539
-    }
540
-
541
-
542
-    /**
543
-     * _global_ajax_hooks
544
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
545
-     * Note: within the ajax callback methods.
546
-     *
547
-     * @abstract
548
-     * @return void
549
-     */
550
-    protected function _global_ajax_hooks()
551
-    {
552
-        // for lazy loading of metabox content
553
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
554
-
555
-        add_action(
556
-            'wp_ajax_espresso_hide_status_change_notice',
557
-            [$this, 'hideStatusChangeNotice']
558
-        );
559
-        add_action(
560
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
561
-            [$this, 'hideStatusChangeNotice']
562
-        );
563
-    }
564
-
565
-
566
-    public function ajax_metabox_content()
567
-    {
568
-        $content_id  = $this->request->getRequestParam('contentid', '');
569
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
570
-        EE_Admin_Page::cached_rss_display($content_id, $content_url);
571
-        wp_die();
572
-    }
573
-
574
-
575
-    public function hideStatusChangeNotice()
576
-    {
577
-        $response = [];
578
-        try {
579
-            /** @var StatusChangeNotice $status_change_notice */
580
-            $status_change_notice = $this->loader->getShared(
581
-                'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
582
-            );
583
-            $response['success'] = $status_change_notice->dismiss() > -1;
584
-        } catch (Exception $exception) {
585
-            $response['errors'] = $exception->getMessage();
586
-        }
587
-        echo wp_json_encode($response);
588
-        exit();
589
-    }
590
-
591
-
592
-    /**
593
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
594
-     *
595
-     * @return void
596
-     */
597
-    protected function _before_page_setup()
598
-    {
599
-        // default is to do nothing
600
-    }
601
-
602
-
603
-    /**
604
-     * Makes sure any things that need to be loaded early get handled.
605
-     * We also escape early here if the page requested doesn't match the object.
606
-     *
607
-     * @final
608
-     * @return void
609
-     * @throws EE_Error
610
-     * @throws InvalidArgumentException
611
-     * @throws ReflectionException
612
-     * @throws InvalidDataTypeException
613
-     * @throws InvalidInterfaceException
614
-     */
615
-    final protected function _page_setup()
616
-    {
617
-        // requires?
618
-        // admin_init stuff - global - we're setting this REALLY early
619
-        // so if EE_Admin pages have to hook into other WP pages they can.
620
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
621
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
622
-        // next verify if we need to load anything...
623
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
624
-        $this->page_folder   = strtolower(
625
-            str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
626
-        );
627
-        global $ee_menu_slugs;
628
-        $ee_menu_slugs = (array) $ee_menu_slugs;
629
-        if (
630
-            ! $this->request->isAjax()
631
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
632
-        ) {
633
-            return;
634
-        }
635
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
636
-        // we need to copy the action from the second to the first
637
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
638
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
639
-        $action     = $action !== '-1' ? $action : $action2;
640
-        $req_action = $action !== '-1' ? $action : 'default';
641
-
642
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
643
-        // then let's use the route as the action.
644
-        // This covers cases where we're coming in from a list table that isn't on the default route.
645
-        $route = $this->request->getRequestParam('route');
646
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
647
-            ? $route
648
-            : $req_action;
649
-
650
-        $this->_current_view = $this->_req_action;
651
-        $this->_req_nonce    = $this->_req_action . '_nonce';
652
-        $this->_define_page_props();
653
-        $this->_current_page_view_url = add_query_arg(
654
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
655
-            $this->_admin_base_url
656
-        );
657
-        // set page configs
658
-        $this->_set_page_routes();
659
-        $this->_set_page_config();
660
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
661
-        if ($this->request->requestParamIsSet('wp_referer')) {
662
-            $wp_referer = $this->request->getRequestParam('wp_referer');
663
-            if ($wp_referer) {
664
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
665
-            }
666
-        }
667
-        // for caffeinated and other extended functionality.
668
-        //  If there is a _extend_page_config method
669
-        // then let's run that to modify the all the various page configuration arrays
670
-        if (method_exists($this, '_extend_page_config')) {
671
-            $this->_extend_page_config();
672
-        }
673
-        // for CPT and other extended functionality.
674
-        // If there is an _extend_page_config_for_cpt
675
-        // then let's run that to modify all the various page configuration arrays.
676
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
677
-            $this->_extend_page_config_for_cpt();
678
-        }
679
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
680
-        $this->_page_routes = apply_filters(
681
-            'FHEE__' . $this->class_name . '__page_setup__page_routes',
682
-            $this->_page_routes,
683
-            $this
684
-        );
685
-        $this->_page_config = apply_filters(
686
-            'FHEE__' . $this->class_name . '__page_setup__page_config',
687
-            $this->_page_config,
688
-            $this
689
-        );
690
-        if ($this->base_class_name !== '') {
691
-            $this->_page_routes = apply_filters(
692
-                'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
693
-                $this->_page_routes,
694
-                $this
695
-            );
696
-            $this->_page_config = apply_filters(
697
-                'FHEE__' . $this->base_class_name . '__page_setup__page_config',
698
-                $this->_page_config,
699
-                $this
700
-            );
701
-        }
702
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
703
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
704
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
705
-            add_action(
706
-                'AHEE__EE_Admin_Page__route_admin_request',
707
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
708
-                10,
709
-                2
710
-            );
711
-        }
712
-        // next route only if routing enabled
713
-        if ($this->_routing && ! $this->request->isAjax()) {
714
-            $this->_verify_routes();
715
-            // next let's just check user_access and kill if no access
716
-            $this->check_user_access();
717
-            if ($this->_is_UI_request) {
718
-                // admin_init stuff - global, all views for this page class, specific view
719
-                add_action('admin_init', [$this, 'admin_init'], 10);
720
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
721
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
722
-                }
723
-            } else {
724
-                // hijack regular WP loading and route admin request immediately
725
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
726
-                $this->route_admin_request();
727
-            }
728
-        }
729
-    }
730
-
731
-
732
-    /**
733
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
734
-     *
735
-     * @return void
736
-     * @throws EE_Error
737
-     */
738
-    private function _do_other_page_hooks()
739
-    {
740
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
741
-        foreach ($registered_pages as $page) {
742
-            // now let's setup the file name and class that should be present
743
-            $classname = str_replace('.class.php', '', $page);
744
-            // autoloaders should take care of loading file
745
-            if (! class_exists($classname)) {
746
-                $error_msg[] = sprintf(
747
-                    esc_html__(
748
-                        'Something went wrong with loading the %s admin hooks page.',
749
-                        'event_espresso'
750
-                    ),
751
-                    $page
752
-                );
753
-                $error_msg[] = $error_msg[0]
754
-                               . "\r\n"
755
-                               . sprintf(
756
-                                   esc_html__(
757
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
758
-                                       'event_espresso'
759
-                                   ),
760
-                                   $page,
761
-                                   '<br />',
762
-                                   '<strong>' . $classname . '</strong>'
763
-                               );
764
-                throw new EE_Error(implode('||', $error_msg));
765
-            }
766
-            // notice we are passing the instance of this class to the hook object.
767
-            $this->loader->getShared($classname, [$this]);
768
-        }
769
-    }
770
-
771
-
772
-    /**
773
-     * @throws ReflectionException
774
-     * @throws EE_Error
775
-     */
776
-    public function load_page_dependencies()
777
-    {
778
-        try {
779
-            $this->_load_page_dependencies();
780
-        } catch (EE_Error $e) {
781
-            $e->get_error();
782
-        }
783
-    }
784
-
785
-
786
-    /**
787
-     * load_page_dependencies
788
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
789
-     *
790
-     * @return void
791
-     * @throws DomainException
792
-     * @throws EE_Error
793
-     * @throws InvalidArgumentException
794
-     * @throws InvalidDataTypeException
795
-     * @throws InvalidInterfaceException
796
-     */
797
-    protected function _load_page_dependencies()
798
-    {
799
-        // let's set the current_screen and screen options to override what WP set
800
-        $this->_current_screen = get_current_screen();
801
-        // load admin_notices - global, page class, and view specific
802
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
803
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
804
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
805
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
806
-        }
807
-        // load network admin_notices - global, page class, and view specific
808
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
809
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
810
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
811
-        }
812
-        // this will save any per_page screen options if they are present
813
-        $this->_set_per_page_screen_options();
814
-        // setup list table properties
815
-        $this->_set_list_table();
816
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
817
-        // However in some cases the metaboxes will need to be added within a route handling callback.
818
-        $this->_add_registered_meta_boxes();
819
-        $this->_add_screen_columns();
820
-        // add screen options - global, page child class, and view specific
821
-        $this->_add_global_screen_options();
822
-        $this->_add_screen_options();
823
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
824
-        if (method_exists($this, $add_screen_options)) {
825
-            $this->{$add_screen_options}();
826
-        }
827
-        // add help tab(s) - set via page_config and qtips.
828
-        $this->_add_help_tabs();
829
-        $this->_add_qtips();
830
-        // add feature_pointers - global, page child class, and view specific
831
-        $this->_add_feature_pointers();
832
-        $this->_add_global_feature_pointers();
833
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
834
-        if (method_exists($this, $add_feature_pointer)) {
835
-            $this->{$add_feature_pointer}();
836
-        }
837
-        // enqueue scripts/styles - global, page class, and view specific
838
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
839
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
840
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
841
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
842
-        }
843
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
844
-        // admin_print_footer_scripts - global, page child class, and view specific.
845
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
846
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
847
-        // is a good use case. Notice the late priority we're giving these
848
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
849
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
850
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
851
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
852
-        }
853
-        // admin footer scripts
854
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
855
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
856
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
857
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
858
-        }
859
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
860
-        // targeted hook
861
-        do_action(
862
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
863
-        );
864
-    }
865
-
866
-
867
-    /**
868
-     * _set_defaults
869
-     * This sets some global defaults for class properties.
870
-     */
871
-    private function _set_defaults()
872
-    {
873
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
874
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
875
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
876
-        $this->_page_config          = $this->_default_route_query_args = [];
877
-        $this->_default_nav_tab_name = 'overview';
878
-        // init template args
879
-        $this->_template_args = [
880
-            'admin_page_header'  => '',
881
-            'admin_page_content' => '',
882
-            'post_body_content'  => '',
883
-            'before_list_table'  => '',
884
-            'after_list_table'   => '',
885
-        ];
886
-    }
887
-
888
-
889
-    /**
890
-     * route_admin_request
891
-     *
892
-     * @return void
893
-     * @throws InvalidArgumentException
894
-     * @throws InvalidInterfaceException
895
-     * @throws InvalidDataTypeException
896
-     * @throws EE_Error
897
-     * @throws ReflectionException
898
-     * @see    _route_admin_request()
899
-     */
900
-    public function route_admin_request()
901
-    {
902
-        try {
903
-            $this->_route_admin_request();
904
-        } catch (EE_Error $e) {
905
-            $e->get_error();
906
-        }
907
-    }
908
-
909
-
910
-    public function set_wp_page_slug($wp_page_slug)
911
-    {
912
-        $this->_wp_page_slug = $wp_page_slug;
913
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
914
-        if (is_network_admin()) {
915
-            $this->_wp_page_slug .= '-network';
916
-        }
917
-    }
918
-
919
-
920
-    /**
921
-     * _verify_routes
922
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
923
-     * we know if we need to drop out.
924
-     *
925
-     * @return bool
926
-     * @throws EE_Error
927
-     */
928
-    protected function _verify_routes()
929
-    {
930
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
931
-        if (! $this->_current_page && ! $this->request->isAjax()) {
932
-            return false;
933
-        }
934
-        $this->_route = false;
935
-        // check that the page_routes array is not empty
936
-        if (empty($this->_page_routes)) {
937
-            // user error msg
938
-            $error_msg = sprintf(
939
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
940
-                $this->_admin_page_title
941
-            );
942
-            // developer error msg
943
-            $error_msg .= '||' . $error_msg
944
-                          . esc_html__(
945
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
946
-                              'event_espresso'
947
-                          );
948
-            throw new EE_Error($error_msg);
949
-        }
950
-        // and that the requested page route exists
951
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
952
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
953
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
954
-        } else {
955
-            // user error msg
956
-            $error_msg = sprintf(
957
-                esc_html__(
958
-                    'The requested page route does not exist for the %s admin page.',
959
-                    'event_espresso'
960
-                ),
961
-                $this->_admin_page_title
962
-            );
963
-            // developer error msg
964
-            $error_msg .= '||' . $error_msg
965
-                          . sprintf(
966
-                              esc_html__(
967
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
968
-                                  'event_espresso'
969
-                              ),
970
-                              $this->_req_action
971
-                          );
972
-            throw new EE_Error($error_msg);
973
-        }
974
-        // and that a default route exists
975
-        if (! array_key_exists('default', $this->_page_routes)) {
976
-            // user error msg
977
-            $error_msg = sprintf(
978
-                esc_html__(
979
-                    'A default page route has not been set for the % admin page.',
980
-                    'event_espresso'
981
-                ),
982
-                $this->_admin_page_title
983
-            );
984
-            // developer error msg
985
-            $error_msg .= '||' . $error_msg
986
-                          . esc_html__(
987
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
988
-                              'event_espresso'
989
-                          );
990
-            throw new EE_Error($error_msg);
991
-        }
992
-
993
-        // first lets' catch if the UI request has EVER been set.
994
-        if ($this->_is_UI_request === null) {
995
-            // lets set if this is a UI request or not.
996
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
997
-            // wait a minute... we might have a noheader in the route array
998
-            $this->_is_UI_request = ! (
999
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1000
-            )
1001
-                ? $this->_is_UI_request
1002
-                : false;
1003
-        }
1004
-        $this->_set_current_labels();
1005
-        return true;
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1011
-     *
1012
-     * @param string $route the route name we're verifying
1013
-     * @return bool we'll throw an exception if this isn't a valid route.
1014
-     * @throws EE_Error
1015
-     */
1016
-    protected function _verify_route($route)
1017
-    {
1018
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
1019
-            return true;
1020
-        }
1021
-        // user error msg
1022
-        $error_msg = sprintf(
1023
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1024
-            $this->_admin_page_title
1025
-        );
1026
-        // developer error msg
1027
-        $error_msg .= '||' . $error_msg
1028
-                      . sprintf(
1029
-                          esc_html__(
1030
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1031
-                              'event_espresso'
1032
-                          ),
1033
-                          $route
1034
-                      );
1035
-        throw new EE_Error($error_msg);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * perform nonce verification
1041
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1042
-     * using this method (and save retyping!)
1043
-     *
1044
-     * @param string $nonce     The nonce sent
1045
-     * @param string $nonce_ref The nonce reference string (name0)
1046
-     * @return void
1047
-     * @throws EE_Error
1048
-     * @throws InvalidArgumentException
1049
-     * @throws InvalidDataTypeException
1050
-     * @throws InvalidInterfaceException
1051
-     */
1052
-    protected function _verify_nonce($nonce, $nonce_ref)
1053
-    {
1054
-        // verify nonce against expected value
1055
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1056
-            // these are not the droids you are looking for !!!
1057
-            $msg = sprintf(
1058
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
1059
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1060
-                '</a>'
1061
-            );
1062
-            if (WP_DEBUG) {
1063
-                $msg .= "\n  ";
1064
-                $msg .= sprintf(
1065
-                    esc_html__(
1066
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1067
-                        'event_espresso'
1068
-                    ),
1069
-                    __CLASS__
1070
-                );
1071
-            }
1072
-            if (! $this->request->isAjax()) {
1073
-                wp_die($msg);
1074
-            }
1075
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1076
-            $this->_return_json();
1077
-        }
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * _route_admin_request()
1083
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1084
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1085
-     * in the page routes and then will try to load the corresponding method.
1086
-     *
1087
-     * @return void
1088
-     * @throws EE_Error
1089
-     * @throws InvalidArgumentException
1090
-     * @throws InvalidDataTypeException
1091
-     * @throws InvalidInterfaceException
1092
-     * @throws ReflectionException
1093
-     */
1094
-    protected function _route_admin_request()
1095
-    {
1096
-        if (! $this->_is_UI_request) {
1097
-            $this->_verify_routes();
1098
-        }
1099
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1100
-        if ($this->_req_action !== 'default' && $nonce_check) {
1101
-            // set nonce from post data
1102
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
1103
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1104
-        }
1105
-        // set the nav_tabs array but ONLY if this is  UI_request
1106
-        if ($this->_is_UI_request) {
1107
-            $this->_set_nav_tabs();
1108
-        }
1109
-        // grab callback function
1110
-        $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1111
-        // check if callback has args
1112
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1113
-        $error_msg = '';
1114
-        // action right before calling route
1115
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1116
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1117
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1118
-        }
1119
-        // strip _wp_http_referer from the server REQUEST_URI
1120
-        // else it grows in length on every submission due to recursion,
1121
-        // ultimately causing a "Request-URI Too Large" error
1122
-        $request_uri = remove_query_arg(
1123
-            '_wp_http_referer',
1124
-            wp_unslash($this->request->getServerParam('REQUEST_URI'))
1125
-        );
1126
-        // set new value in both our Request object and the super global
1127
-        $this->request->setServerParam('REQUEST_URI', $request_uri, true);
1128
-        if (! empty($func)) {
1129
-            if (is_array($func)) {
1130
-                [$class, $method] = $func;
1131
-            } elseif (strpos($func, '::') !== false) {
1132
-                [$class, $method] = explode('::', $func);
1133
-            } else {
1134
-                $class  = $this;
1135
-                $method = $func;
1136
-            }
1137
-            if (! (is_object($class) && $class === $this)) {
1138
-                // send along this admin page object for access by addons.
1139
-                $args['admin_page_object'] = $this;
1140
-            }
1141
-            if (
1142
-                // is it a method on a class that doesn't work?
1143
-                (
1144
-                    (
1145
-                        method_exists($class, $method)
1146
-                        && call_user_func_array([$class, $method], $args) === false
1147
-                    )
1148
-                    && (
1149
-                        // is it a standalone function that doesn't work?
1150
-                        function_exists($method)
1151
-                        && call_user_func_array(
1152
-                            $func,
1153
-                            array_merge(['admin_page_object' => $this], $args)
1154
-                        ) === false
1155
-                    )
1156
-                )
1157
-                || (
1158
-                    // is it neither a class method NOR a standalone function?
1159
-                    ! method_exists($class, $method)
1160
-                    && ! function_exists($method)
1161
-                )
1162
-            ) {
1163
-                // user error msg
1164
-                $error_msg = esc_html__(
1165
-                    'An error occurred. The  requested page route could not be found.',
1166
-                    'event_espresso'
1167
-                );
1168
-                // developer error msg
1169
-                $error_msg .= '||';
1170
-                $error_msg .= sprintf(
1171
-                    esc_html__(
1172
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1173
-                        'event_espresso'
1174
-                    ),
1175
-                    $method
1176
-                );
1177
-            }
1178
-            if (! empty($error_msg)) {
1179
-                throw new EE_Error($error_msg);
1180
-            }
1181
-        }
1182
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1183
-        // then we need to reset the routing properties to the new route.
1184
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1185
-        if (
1186
-            $this->_is_UI_request === false
1187
-            && is_array($this->_route)
1188
-            && ! empty($this->_route['headers_sent_route'])
1189
-        ) {
1190
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1191
-        }
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * This method just allows the resetting of page properties in the case where a no headers
1197
-     * route redirects to a headers route in its route config.
1198
-     *
1199
-     * @param string $new_route New (non header) route to redirect to.
1200
-     * @return   void
1201
-     * @throws ReflectionException
1202
-     * @throws InvalidArgumentException
1203
-     * @throws InvalidInterfaceException
1204
-     * @throws InvalidDataTypeException
1205
-     * @throws EE_Error
1206
-     * @since   4.3.0
1207
-     */
1208
-    protected function _reset_routing_properties($new_route)
1209
-    {
1210
-        $this->_is_UI_request = true;
1211
-        // now we set the current route to whatever the headers_sent_route is set at
1212
-        $this->request->setRequestParam('action', $new_route);
1213
-        // rerun page setup
1214
-        $this->_page_setup();
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * _add_query_arg
1220
-     * adds nonce to array of arguments then calls WP add_query_arg function
1221
-     *(internally just uses EEH_URL's function with the same name)
1222
-     *
1223
-     * @param array  $args
1224
-     * @param string $url
1225
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1226
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1227
-     *                                        Example usage: If the current page is:
1228
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1229
-     *                                        &action=default&event_id=20&month_range=March%202015
1230
-     *                                        &_wpnonce=5467821
1231
-     *                                        and you call:
1232
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1233
-     *                                        array(
1234
-     *                                        'action' => 'resend_something',
1235
-     *                                        'page=>espresso_registrations'
1236
-     *                                        ),
1237
-     *                                        $some_url,
1238
-     *                                        true
1239
-     *                                        );
1240
-     *                                        It will produce a url in this structure:
1241
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1242
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1243
-     *                                        month_range]=March%202015
1244
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1245
-     * @return string
1246
-     */
1247
-    public static function add_query_args_and_nonce(
1248
-        $args = [],
1249
-        $url = '',
1250
-        $sticky = false,
1251
-        $exclude_nonce = false
1252
-    ) {
1253
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1254
-        if ($sticky) {
1255
-            /** @var RequestInterface $request */
1256
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1257
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1258
-            $request->unSetServerParam('_wp_http_referer', true);
1259
-            foreach ($request->requestParams() as $key => $value) {
1260
-                // do not add nonces
1261
-                if (strpos($key, 'nonce') !== false) {
1262
-                    continue;
1263
-                }
1264
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1265
-            }
1266
-        }
1267
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     * This returns a generated link that will load the related help tab.
1273
-     *
1274
-     * @param string $help_tab_id the id for the connected help tab
1275
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1276
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1277
-     * @return string              generated link
1278
-     * @uses EEH_Template::get_help_tab_link()
1279
-     */
1280
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1281
-    {
1282
-        return EEH_Template::get_help_tab_link(
1283
-            $help_tab_id,
1284
-            $this->page_slug,
1285
-            $this->_req_action,
1286
-            $icon_style,
1287
-            $help_text
1288
-        );
1289
-    }
1290
-
1291
-
1292
-    /**
1293
-     * _add_help_tabs
1294
-     * Note child classes define their help tabs within the page_config array.
1295
-     *
1296
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1297
-     * @return void
1298
-     * @throws DomainException
1299
-     * @throws EE_Error
1300
-     * @throws ReflectionException
1301
-     */
1302
-    protected function _add_help_tabs()
1303
-    {
1304
-        if (isset($this->_page_config[ $this->_req_action ])) {
1305
-            $config = $this->_page_config[ $this->_req_action ];
1306
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1307
-            if (is_array($config) && isset($config['help_sidebar'])) {
1308
-                // check that the callback given is valid
1309
-                if (! method_exists($this, $config['help_sidebar'])) {
1310
-                    throw new EE_Error(
1311
-                        sprintf(
1312
-                            esc_html__(
1313
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1314
-                                'event_espresso'
1315
-                            ),
1316
-                            $config['help_sidebar'],
1317
-                            $this->class_name
1318
-                        )
1319
-                    );
1320
-                }
1321
-                $content = apply_filters(
1322
-                    'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1323
-                    $this->{$config['help_sidebar']}()
1324
-                );
1325
-                $this->_current_screen->set_help_sidebar($content);
1326
-            }
1327
-            if (! isset($config['help_tabs'])) {
1328
-                return;
1329
-            } //no help tabs for this route
1330
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1331
-                // we're here so there ARE help tabs!
1332
-                // make sure we've got what we need
1333
-                if (! isset($cfg['title'])) {
1334
-                    throw new EE_Error(
1335
-                        esc_html__(
1336
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1337
-                            'event_espresso'
1338
-                        )
1339
-                    );
1340
-                }
1341
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1342
-                    throw new EE_Error(
1343
-                        esc_html__(
1344
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1345
-                            'event_espresso'
1346
-                        )
1347
-                    );
1348
-                }
1349
-                // first priority goes to content.
1350
-                if (! empty($cfg['content'])) {
1351
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1352
-                    // second priority goes to filename
1353
-                } elseif (! empty($cfg['filename'])) {
1354
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1355
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1356
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1357
-                                                             . basename($this->_get_dir())
1358
-                                                             . '/help_tabs/'
1359
-                                                             . $cfg['filename']
1360
-                                                             . '.help_tab.php' : $file_path;
1361
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1362
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1363
-                        EE_Error::add_error(
1364
-                            sprintf(
1365
-                                esc_html__(
1366
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1367
-                                    'event_espresso'
1368
-                                ),
1369
-                                $tab_id,
1370
-                                key($config),
1371
-                                $file_path
1372
-                            ),
1373
-                            __FILE__,
1374
-                            __FUNCTION__,
1375
-                            __LINE__
1376
-                        );
1377
-                        return;
1378
-                    }
1379
-                    $template_args['admin_page_obj'] = $this;
1380
-                    $content                         = EEH_Template::display_template(
1381
-                        $file_path,
1382
-                        $template_args,
1383
-                        true
1384
-                    );
1385
-                } else {
1386
-                    $content = '';
1387
-                }
1388
-                // check if callback is valid
1389
-                if (
1390
-                    empty($content)
1391
-                    && (
1392
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1393
-                    )
1394
-                ) {
1395
-                    EE_Error::add_error(
1396
-                        sprintf(
1397
-                            esc_html__(
1398
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1399
-                                'event_espresso'
1400
-                            ),
1401
-                            $cfg['title']
1402
-                        ),
1403
-                        __FILE__,
1404
-                        __FUNCTION__,
1405
-                        __LINE__
1406
-                    );
1407
-                    return;
1408
-                }
1409
-                // setup config array for help tab method
1410
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1411
-                $_ht = [
1412
-                    'id'       => $id,
1413
-                    'title'    => $cfg['title'],
1414
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1415
-                    'content'  => $content,
1416
-                ];
1417
-                $this->_current_screen->add_help_tab($_ht);
1418
-            }
1419
-        }
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * This simply sets up any qtips that have been defined in the page config
1425
-     *
1426
-     * @return void
1427
-     * @throws ReflectionException
1428
-     * @throws EE_Error
1429
-     */
1430
-    protected function _add_qtips()
1431
-    {
1432
-        if (isset($this->_route_config['qtips'])) {
1433
-            $qtips = (array) $this->_route_config['qtips'];
1434
-            // load qtip loader
1435
-            $path = [
1436
-                $this->_get_dir() . '/qtips/',
1437
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1438
-            ];
1439
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1440
-        }
1441
-    }
1442
-
1443
-
1444
-    /**
1445
-     * _set_nav_tabs
1446
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1447
-     * wish to add additional tabs or modify accordingly.
1448
-     *
1449
-     * @return void
1450
-     * @throws InvalidArgumentException
1451
-     * @throws InvalidInterfaceException
1452
-     * @throws InvalidDataTypeException
1453
-     */
1454
-    protected function _set_nav_tabs()
1455
-    {
1456
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1457
-        $i = 0;
1458
-        foreach ($this->_page_config as $slug => $config) {
1459
-            if (! is_array($config) || empty($config['nav'])) {
1460
-                continue;
1461
-            }
1462
-            // no nav tab for this config
1463
-            // check for persistent flag
1464
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1465
-                // nav tab is only to appear when route requested.
1466
-                continue;
1467
-            }
1468
-            if (! $this->check_user_access($slug, true)) {
1469
-                // no nav tab because current user does not have access.
1470
-                continue;
1471
-            }
1472
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1473
-            $this->_nav_tabs[ $slug ] = [
1474
-                'url'       => isset($config['nav']['url'])
1475
-                    ? $config['nav']['url']
1476
-                    : EE_Admin_Page::add_query_args_and_nonce(
1477
-                        ['action' => $slug],
1478
-                        $this->_admin_base_url
1479
-                    ),
1480
-                'link_text' => isset($config['nav']['label'])
1481
-                    ? $config['nav']['label']
1482
-                    : ucwords(
1483
-                        str_replace('_', ' ', $slug)
1484
-                    ),
1485
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1486
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1487
-            ];
1488
-            $i++;
1489
-        }
1490
-        // if $this->_nav_tabs is empty then lets set the default
1491
-        if (empty($this->_nav_tabs)) {
1492
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1493
-                'url'       => $this->_admin_base_url,
1494
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1495
-                'css_class' => 'nav-tab-active',
1496
-                'order'     => 10,
1497
-            ];
1498
-        }
1499
-        // now let's sort the tabs according to order
1500
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * _set_current_labels
1506
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1507
-     * property array
1508
-     *
1509
-     * @return void
1510
-     */
1511
-    private function _set_current_labels()
1512
-    {
1513
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1514
-            foreach ($this->_route_config['labels'] as $label => $text) {
1515
-                if (is_array($text)) {
1516
-                    foreach ($text as $sublabel => $subtext) {
1517
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1518
-                    }
1519
-                } else {
1520
-                    $this->_labels[ $label ] = $text;
1521
-                }
1522
-            }
1523
-        }
1524
-    }
1525
-
1526
-
1527
-    /**
1528
-     *        verifies user access for this admin page
1529
-     *
1530
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1531
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1532
-     *                               return false if verify fail.
1533
-     * @return bool
1534
-     * @throws InvalidArgumentException
1535
-     * @throws InvalidDataTypeException
1536
-     * @throws InvalidInterfaceException
1537
-     */
1538
-    public function check_user_access($route_to_check = '', $verify_only = false)
1539
-    {
1540
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1541
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1542
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1543
-                          && is_array($this->_page_routes[ $route_to_check ])
1544
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1545
-            ? $this->_page_routes[ $route_to_check ]['capability']
141
+	/**
142
+	 * unprocessed value for the 'page' request param (default '')
143
+	 *
144
+	 * @var string
145
+	 */
146
+	protected $raw_req_page = '';
147
+
148
+	/**
149
+	 * sanitized request action (and nonce)
150
+	 *
151
+	 * @var string
152
+	 */
153
+	protected $_req_action = '';
154
+
155
+	/**
156
+	 * sanitized request action nonce
157
+	 *
158
+	 * @var string
159
+	 */
160
+	protected $_req_nonce = '';
161
+
162
+	/**
163
+	 * @var string
164
+	 */
165
+	protected $_search_btn_label = '';
166
+
167
+	/**
168
+	 * @var string
169
+	 */
170
+	protected $_search_box_callback = '';
171
+
172
+	/**
173
+	 * @var WP_Screen
174
+	 */
175
+	protected $_current_screen;
176
+
177
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
178
+	protected $_hook_obj;
179
+
180
+	// for holding incoming request data
181
+	protected $_req_data = [];
182
+
183
+	// yes / no array for admin form fields
184
+	protected $_yes_no_values = [];
185
+
186
+	// some default things shared by all child classes
187
+	protected $_default_espresso_metaboxes = [
188
+		'_espresso_news_post_box',
189
+		'_espresso_links_post_box',
190
+		'_espresso_ratings_request',
191
+		'_espresso_sponsors_post_box',
192
+	];
193
+
194
+	/**
195
+	 * @var EE_Registry
196
+	 */
197
+	protected $EE;
198
+
199
+
200
+	/**
201
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
202
+	 *
203
+	 * @var boolean
204
+	 */
205
+	protected $_is_caf = false;
206
+
207
+	/**
208
+	 * whether or not initializePage() has run
209
+	 *
210
+	 * @var boolean
211
+	 */
212
+	protected $initialized = false;
213
+
214
+	/**
215
+	 * @var FeatureFlags
216
+	 */
217
+	protected $feature;
218
+
219
+
220
+	/**
221
+	 * @var string
222
+	 */
223
+	protected $class_name;
224
+
225
+	/**
226
+	 * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
227
+	 * then this would be the parent classname: Events_Admin_Page
228
+	 *
229
+	 * @var string
230
+	 */
231
+	protected $base_class_name;
232
+
233
+
234
+	/**
235
+	 * @Constructor
236
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
237
+	 * @throws InvalidArgumentException
238
+	 * @throws InvalidDataTypeException
239
+	 * @throws InvalidInterfaceException
240
+	 * @throws ReflectionException
241
+	 */
242
+	public function __construct($routing = true)
243
+	{
244
+		$this->loader = LoaderFactory::getLoader();
245
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
246
+		$this->feature = $this->loader->getShared(FeatureFlags::class);
247
+		$this->request = $this->loader->getShared(RequestInterface::class);
248
+		// routing enabled?
249
+		$this->_routing = $routing;
250
+
251
+		$this->class_name = get_class($this);
252
+		$this->base_class_name = strpos($this->class_name, 'Extend_') === 0
253
+			? str_replace('Extend_', '', $this->class_name)
254
+			: '';
255
+
256
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
257
+			$this->_is_caf = true;
258
+		}
259
+		$this->_yes_no_values = [
260
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
261
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
262
+		];
263
+		// set the _req_data property.
264
+		$this->_req_data = $this->request->requestParams();
265
+	}
266
+
267
+
268
+	/**
269
+	 * @return EE_Admin_Config
270
+	 */
271
+	public function adminConfig(): EE_Admin_Config
272
+	{
273
+		return $this->admin_config;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return FeatureFlags
279
+	 */
280
+	public function feature(): FeatureFlags
281
+	{
282
+		return $this->feature;
283
+	}
284
+
285
+
286
+	/**
287
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
288
+	 * for child classes that needed to set properties prior to these methods getting called,
289
+	 * but also needed the parent class to have its construction completed as well.
290
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
291
+	 * and any complex initialization logic should only run after instantiation is complete.
292
+	 *
293
+	 * This method gets called immediately after construction from within
294
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
295
+	 *
296
+	 * @throws EE_Error
297
+	 * @throws InvalidArgumentException
298
+	 * @throws InvalidDataTypeException
299
+	 * @throws InvalidInterfaceException
300
+	 * @throws ReflectionException
301
+	 * @since $VID:$
302
+	 */
303
+	public function initializePage()
304
+	{
305
+		if ($this->initialized) {
306
+			return;
307
+		}
308
+		// set initial page props (child method)
309
+		$this->_init_page_props();
310
+		// set global defaults
311
+		$this->_set_defaults();
312
+		// set early because incoming requests could be ajax related and we need to register those hooks.
313
+		$this->_global_ajax_hooks();
314
+		$this->_ajax_hooks();
315
+		// other_page_hooks have to be early too.
316
+		$this->_do_other_page_hooks();
317
+		// set up page dependencies
318
+		$this->_before_page_setup();
319
+		$this->_page_setup();
320
+		$this->initialized = true;
321
+	}
322
+
323
+
324
+	/**
325
+	 * _init_page_props
326
+	 * Child classes use to set at least the following properties:
327
+	 * $page_slug.
328
+	 * $page_label.
329
+	 *
330
+	 * @abstract
331
+	 * @return void
332
+	 */
333
+	abstract protected function _init_page_props();
334
+
335
+
336
+	/**
337
+	 * _ajax_hooks
338
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
339
+	 * Note: within the ajax callback methods.
340
+	 *
341
+	 * @abstract
342
+	 * @return void
343
+	 */
344
+	abstract protected function _ajax_hooks();
345
+
346
+
347
+	/**
348
+	 * _define_page_props
349
+	 * child classes define page properties in here.  Must include at least:
350
+	 * $_admin_base_url = base_url for all admin pages
351
+	 * $_admin_page_title = default admin_page_title for admin pages
352
+	 * $_labels = array of default labels for various automatically generated elements:
353
+	 *    array(
354
+	 *        'buttons' => array(
355
+	 *            'add' => esc_html__('label for add new button'),
356
+	 *            'edit' => esc_html__('label for edit button'),
357
+	 *            'delete' => esc_html__('label for delete button')
358
+	 *            )
359
+	 *        )
360
+	 *
361
+	 * @abstract
362
+	 * @return void
363
+	 */
364
+	abstract protected function _define_page_props();
365
+
366
+
367
+	/**
368
+	 * _set_page_routes
369
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
370
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
371
+	 * have a 'default' route. Here's the format
372
+	 * $this->_page_routes = array(
373
+	 *        'default' => array(
374
+	 *            'func' => '_default_method_handling_route',
375
+	 *            'args' => array('array','of','args'),
376
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
377
+	 *            ajax request, backend processing)
378
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
379
+	 *            headers route after.  The string you enter here should match the defined route reference for a
380
+	 *            headers sent route.
381
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
382
+	 *            this route.
383
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
384
+	 *            checks).
385
+	 *        ),
386
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
387
+	 *        handling method.
388
+	 *        )
389
+	 * )
390
+	 *
391
+	 * @abstract
392
+	 * @return void
393
+	 */
394
+	abstract protected function _set_page_routes();
395
+
396
+
397
+	/**
398
+	 * _set_page_config
399
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
400
+	 * array corresponds to the page_route for the loaded page. Format:
401
+	 * $this->_page_config = array(
402
+	 *        'default' => array(
403
+	 *            'labels' => array(
404
+	 *                'buttons' => array(
405
+	 *                    'add' => esc_html__('label for adding item'),
406
+	 *                    'edit' => esc_html__('label for editing item'),
407
+	 *                    'delete' => esc_html__('label for deleting item')
408
+	 *                ),
409
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
410
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
411
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
412
+	 *            _define_page_props() method
413
+	 *            'nav' => array(
414
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
415
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
416
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
417
+	 *                'order' => 10, //required to indicate tab position.
418
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
419
+	 *                displayed then add this parameter.
420
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
421
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
422
+	 *            metaboxes set for eventespresso admin pages.
423
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
424
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
425
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
426
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
427
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
428
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
429
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
430
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
431
+	 *            want to display.
432
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
433
+	 *                'tab_id' => array(
434
+	 *                    'title' => 'tab_title',
435
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
436
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
437
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
438
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
439
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
440
+	 *                    attempt to use the callback which should match the name of a method in the class
441
+	 *                    ),
442
+	 *                'tab2_id' => array(
443
+	 *                    'title' => 'tab2 title',
444
+	 *                    'filename' => 'file_name_2'
445
+	 *                    'callback' => 'callback_method_for_content',
446
+	 *                 ),
447
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
448
+	 *            help tab area on an admin page. @return void
449
+	 *
450
+	 * @abstract
451
+	 */
452
+	abstract protected function _set_page_config();
453
+
454
+
455
+	/**
456
+	 * _add_screen_options
457
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
458
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
459
+	 * to a particular view.
460
+	 *
461
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
462
+	 *         see also WP_Screen object documents...
463
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
464
+	 * @abstract
465
+	 * @return void
466
+	 */
467
+	abstract protected function _add_screen_options();
468
+
469
+
470
+	/**
471
+	 * _add_feature_pointers
472
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
473
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
474
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
475
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
476
+	 * extended) also see:
477
+	 *
478
+	 * @link   http://eamann.com/tech/wordpress-portland/
479
+	 * @abstract
480
+	 * @return void
481
+	 */
482
+	abstract protected function _add_feature_pointers();
483
+
484
+
485
+	/**
486
+	 * load_scripts_styles
487
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
488
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
489
+	 * scripts/styles per view by putting them in a dynamic function in this format
490
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
491
+	 *
492
+	 * @abstract
493
+	 * @return void
494
+	 */
495
+	abstract public function load_scripts_styles();
496
+
497
+
498
+	/**
499
+	 * admin_init
500
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
501
+	 * all pages/views loaded by child class.
502
+	 *
503
+	 * @abstract
504
+	 * @return void
505
+	 */
506
+	abstract public function admin_init();
507
+
508
+
509
+	/**
510
+	 * admin_notices
511
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
512
+	 * all pages/views loaded by child class.
513
+	 *
514
+	 * @abstract
515
+	 * @return void
516
+	 */
517
+	abstract public function admin_notices();
518
+
519
+
520
+	/**
521
+	 * admin_footer_scripts
522
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
523
+	 * will apply to all pages/views loaded by child class.
524
+	 *
525
+	 * @return void
526
+	 */
527
+	abstract public function admin_footer_scripts();
528
+
529
+
530
+	/**
531
+	 * admin_footer
532
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
533
+	 * apply to all pages/views loaded by child class.
534
+	 *
535
+	 * @return void
536
+	 */
537
+	public function admin_footer()
538
+	{
539
+	}
540
+
541
+
542
+	/**
543
+	 * _global_ajax_hooks
544
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
545
+	 * Note: within the ajax callback methods.
546
+	 *
547
+	 * @abstract
548
+	 * @return void
549
+	 */
550
+	protected function _global_ajax_hooks()
551
+	{
552
+		// for lazy loading of metabox content
553
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
554
+
555
+		add_action(
556
+			'wp_ajax_espresso_hide_status_change_notice',
557
+			[$this, 'hideStatusChangeNotice']
558
+		);
559
+		add_action(
560
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
561
+			[$this, 'hideStatusChangeNotice']
562
+		);
563
+	}
564
+
565
+
566
+	public function ajax_metabox_content()
567
+	{
568
+		$content_id  = $this->request->getRequestParam('contentid', '');
569
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
570
+		EE_Admin_Page::cached_rss_display($content_id, $content_url);
571
+		wp_die();
572
+	}
573
+
574
+
575
+	public function hideStatusChangeNotice()
576
+	{
577
+		$response = [];
578
+		try {
579
+			/** @var StatusChangeNotice $status_change_notice */
580
+			$status_change_notice = $this->loader->getShared(
581
+				'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
582
+			);
583
+			$response['success'] = $status_change_notice->dismiss() > -1;
584
+		} catch (Exception $exception) {
585
+			$response['errors'] = $exception->getMessage();
586
+		}
587
+		echo wp_json_encode($response);
588
+		exit();
589
+	}
590
+
591
+
592
+	/**
593
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
594
+	 *
595
+	 * @return void
596
+	 */
597
+	protected function _before_page_setup()
598
+	{
599
+		// default is to do nothing
600
+	}
601
+
602
+
603
+	/**
604
+	 * Makes sure any things that need to be loaded early get handled.
605
+	 * We also escape early here if the page requested doesn't match the object.
606
+	 *
607
+	 * @final
608
+	 * @return void
609
+	 * @throws EE_Error
610
+	 * @throws InvalidArgumentException
611
+	 * @throws ReflectionException
612
+	 * @throws InvalidDataTypeException
613
+	 * @throws InvalidInterfaceException
614
+	 */
615
+	final protected function _page_setup()
616
+	{
617
+		// requires?
618
+		// admin_init stuff - global - we're setting this REALLY early
619
+		// so if EE_Admin pages have to hook into other WP pages they can.
620
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
621
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
622
+		// next verify if we need to load anything...
623
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
624
+		$this->page_folder   = strtolower(
625
+			str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
626
+		);
627
+		global $ee_menu_slugs;
628
+		$ee_menu_slugs = (array) $ee_menu_slugs;
629
+		if (
630
+			! $this->request->isAjax()
631
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
632
+		) {
633
+			return;
634
+		}
635
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
636
+		// we need to copy the action from the second to the first
637
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
638
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
639
+		$action     = $action !== '-1' ? $action : $action2;
640
+		$req_action = $action !== '-1' ? $action : 'default';
641
+
642
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
643
+		// then let's use the route as the action.
644
+		// This covers cases where we're coming in from a list table that isn't on the default route.
645
+		$route = $this->request->getRequestParam('route');
646
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
647
+			? $route
648
+			: $req_action;
649
+
650
+		$this->_current_view = $this->_req_action;
651
+		$this->_req_nonce    = $this->_req_action . '_nonce';
652
+		$this->_define_page_props();
653
+		$this->_current_page_view_url = add_query_arg(
654
+			['page' => $this->_current_page, 'action' => $this->_current_view],
655
+			$this->_admin_base_url
656
+		);
657
+		// set page configs
658
+		$this->_set_page_routes();
659
+		$this->_set_page_config();
660
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
661
+		if ($this->request->requestParamIsSet('wp_referer')) {
662
+			$wp_referer = $this->request->getRequestParam('wp_referer');
663
+			if ($wp_referer) {
664
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
665
+			}
666
+		}
667
+		// for caffeinated and other extended functionality.
668
+		//  If there is a _extend_page_config method
669
+		// then let's run that to modify the all the various page configuration arrays
670
+		if (method_exists($this, '_extend_page_config')) {
671
+			$this->_extend_page_config();
672
+		}
673
+		// for CPT and other extended functionality.
674
+		// If there is an _extend_page_config_for_cpt
675
+		// then let's run that to modify all the various page configuration arrays.
676
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
677
+			$this->_extend_page_config_for_cpt();
678
+		}
679
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
680
+		$this->_page_routes = apply_filters(
681
+			'FHEE__' . $this->class_name . '__page_setup__page_routes',
682
+			$this->_page_routes,
683
+			$this
684
+		);
685
+		$this->_page_config = apply_filters(
686
+			'FHEE__' . $this->class_name . '__page_setup__page_config',
687
+			$this->_page_config,
688
+			$this
689
+		);
690
+		if ($this->base_class_name !== '') {
691
+			$this->_page_routes = apply_filters(
692
+				'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
693
+				$this->_page_routes,
694
+				$this
695
+			);
696
+			$this->_page_config = apply_filters(
697
+				'FHEE__' . $this->base_class_name . '__page_setup__page_config',
698
+				$this->_page_config,
699
+				$this
700
+			);
701
+		}
702
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
703
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
704
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
705
+			add_action(
706
+				'AHEE__EE_Admin_Page__route_admin_request',
707
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
708
+				10,
709
+				2
710
+			);
711
+		}
712
+		// next route only if routing enabled
713
+		if ($this->_routing && ! $this->request->isAjax()) {
714
+			$this->_verify_routes();
715
+			// next let's just check user_access and kill if no access
716
+			$this->check_user_access();
717
+			if ($this->_is_UI_request) {
718
+				// admin_init stuff - global, all views for this page class, specific view
719
+				add_action('admin_init', [$this, 'admin_init'], 10);
720
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
721
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
722
+				}
723
+			} else {
724
+				// hijack regular WP loading and route admin request immediately
725
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
726
+				$this->route_admin_request();
727
+			}
728
+		}
729
+	}
730
+
731
+
732
+	/**
733
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
734
+	 *
735
+	 * @return void
736
+	 * @throws EE_Error
737
+	 */
738
+	private function _do_other_page_hooks()
739
+	{
740
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
741
+		foreach ($registered_pages as $page) {
742
+			// now let's setup the file name and class that should be present
743
+			$classname = str_replace('.class.php', '', $page);
744
+			// autoloaders should take care of loading file
745
+			if (! class_exists($classname)) {
746
+				$error_msg[] = sprintf(
747
+					esc_html__(
748
+						'Something went wrong with loading the %s admin hooks page.',
749
+						'event_espresso'
750
+					),
751
+					$page
752
+				);
753
+				$error_msg[] = $error_msg[0]
754
+							   . "\r\n"
755
+							   . sprintf(
756
+								   esc_html__(
757
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
758
+									   'event_espresso'
759
+								   ),
760
+								   $page,
761
+								   '<br />',
762
+								   '<strong>' . $classname . '</strong>'
763
+							   );
764
+				throw new EE_Error(implode('||', $error_msg));
765
+			}
766
+			// notice we are passing the instance of this class to the hook object.
767
+			$this->loader->getShared($classname, [$this]);
768
+		}
769
+	}
770
+
771
+
772
+	/**
773
+	 * @throws ReflectionException
774
+	 * @throws EE_Error
775
+	 */
776
+	public function load_page_dependencies()
777
+	{
778
+		try {
779
+			$this->_load_page_dependencies();
780
+		} catch (EE_Error $e) {
781
+			$e->get_error();
782
+		}
783
+	}
784
+
785
+
786
+	/**
787
+	 * load_page_dependencies
788
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
789
+	 *
790
+	 * @return void
791
+	 * @throws DomainException
792
+	 * @throws EE_Error
793
+	 * @throws InvalidArgumentException
794
+	 * @throws InvalidDataTypeException
795
+	 * @throws InvalidInterfaceException
796
+	 */
797
+	protected function _load_page_dependencies()
798
+	{
799
+		// let's set the current_screen and screen options to override what WP set
800
+		$this->_current_screen = get_current_screen();
801
+		// load admin_notices - global, page class, and view specific
802
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
803
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
804
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
805
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
806
+		}
807
+		// load network admin_notices - global, page class, and view specific
808
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
809
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
810
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
811
+		}
812
+		// this will save any per_page screen options if they are present
813
+		$this->_set_per_page_screen_options();
814
+		// setup list table properties
815
+		$this->_set_list_table();
816
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
817
+		// However in some cases the metaboxes will need to be added within a route handling callback.
818
+		$this->_add_registered_meta_boxes();
819
+		$this->_add_screen_columns();
820
+		// add screen options - global, page child class, and view specific
821
+		$this->_add_global_screen_options();
822
+		$this->_add_screen_options();
823
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
824
+		if (method_exists($this, $add_screen_options)) {
825
+			$this->{$add_screen_options}();
826
+		}
827
+		// add help tab(s) - set via page_config and qtips.
828
+		$this->_add_help_tabs();
829
+		$this->_add_qtips();
830
+		// add feature_pointers - global, page child class, and view specific
831
+		$this->_add_feature_pointers();
832
+		$this->_add_global_feature_pointers();
833
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
834
+		if (method_exists($this, $add_feature_pointer)) {
835
+			$this->{$add_feature_pointer}();
836
+		}
837
+		// enqueue scripts/styles - global, page class, and view specific
838
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
839
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
840
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
841
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
842
+		}
843
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
844
+		// admin_print_footer_scripts - global, page child class, and view specific.
845
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
846
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
847
+		// is a good use case. Notice the late priority we're giving these
848
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
849
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
850
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
851
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
852
+		}
853
+		// admin footer scripts
854
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
855
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
856
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
857
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
858
+		}
859
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
860
+		// targeted hook
861
+		do_action(
862
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
863
+		);
864
+	}
865
+
866
+
867
+	/**
868
+	 * _set_defaults
869
+	 * This sets some global defaults for class properties.
870
+	 */
871
+	private function _set_defaults()
872
+	{
873
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
874
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
875
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
876
+		$this->_page_config          = $this->_default_route_query_args = [];
877
+		$this->_default_nav_tab_name = 'overview';
878
+		// init template args
879
+		$this->_template_args = [
880
+			'admin_page_header'  => '',
881
+			'admin_page_content' => '',
882
+			'post_body_content'  => '',
883
+			'before_list_table'  => '',
884
+			'after_list_table'   => '',
885
+		];
886
+	}
887
+
888
+
889
+	/**
890
+	 * route_admin_request
891
+	 *
892
+	 * @return void
893
+	 * @throws InvalidArgumentException
894
+	 * @throws InvalidInterfaceException
895
+	 * @throws InvalidDataTypeException
896
+	 * @throws EE_Error
897
+	 * @throws ReflectionException
898
+	 * @see    _route_admin_request()
899
+	 */
900
+	public function route_admin_request()
901
+	{
902
+		try {
903
+			$this->_route_admin_request();
904
+		} catch (EE_Error $e) {
905
+			$e->get_error();
906
+		}
907
+	}
908
+
909
+
910
+	public function set_wp_page_slug($wp_page_slug)
911
+	{
912
+		$this->_wp_page_slug = $wp_page_slug;
913
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
914
+		if (is_network_admin()) {
915
+			$this->_wp_page_slug .= '-network';
916
+		}
917
+	}
918
+
919
+
920
+	/**
921
+	 * _verify_routes
922
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
923
+	 * we know if we need to drop out.
924
+	 *
925
+	 * @return bool
926
+	 * @throws EE_Error
927
+	 */
928
+	protected function _verify_routes()
929
+	{
930
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
931
+		if (! $this->_current_page && ! $this->request->isAjax()) {
932
+			return false;
933
+		}
934
+		$this->_route = false;
935
+		// check that the page_routes array is not empty
936
+		if (empty($this->_page_routes)) {
937
+			// user error msg
938
+			$error_msg = sprintf(
939
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
940
+				$this->_admin_page_title
941
+			);
942
+			// developer error msg
943
+			$error_msg .= '||' . $error_msg
944
+						  . esc_html__(
945
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
946
+							  'event_espresso'
947
+						  );
948
+			throw new EE_Error($error_msg);
949
+		}
950
+		// and that the requested page route exists
951
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
952
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
953
+			$this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
954
+		} else {
955
+			// user error msg
956
+			$error_msg = sprintf(
957
+				esc_html__(
958
+					'The requested page route does not exist for the %s admin page.',
959
+					'event_espresso'
960
+				),
961
+				$this->_admin_page_title
962
+			);
963
+			// developer error msg
964
+			$error_msg .= '||' . $error_msg
965
+						  . sprintf(
966
+							  esc_html__(
967
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
968
+								  'event_espresso'
969
+							  ),
970
+							  $this->_req_action
971
+						  );
972
+			throw new EE_Error($error_msg);
973
+		}
974
+		// and that a default route exists
975
+		if (! array_key_exists('default', $this->_page_routes)) {
976
+			// user error msg
977
+			$error_msg = sprintf(
978
+				esc_html__(
979
+					'A default page route has not been set for the % admin page.',
980
+					'event_espresso'
981
+				),
982
+				$this->_admin_page_title
983
+			);
984
+			// developer error msg
985
+			$error_msg .= '||' . $error_msg
986
+						  . esc_html__(
987
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
988
+							  'event_espresso'
989
+						  );
990
+			throw new EE_Error($error_msg);
991
+		}
992
+
993
+		// first lets' catch if the UI request has EVER been set.
994
+		if ($this->_is_UI_request === null) {
995
+			// lets set if this is a UI request or not.
996
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
997
+			// wait a minute... we might have a noheader in the route array
998
+			$this->_is_UI_request = ! (
999
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1000
+			)
1001
+				? $this->_is_UI_request
1002
+				: false;
1003
+		}
1004
+		$this->_set_current_labels();
1005
+		return true;
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1011
+	 *
1012
+	 * @param string $route the route name we're verifying
1013
+	 * @return bool we'll throw an exception if this isn't a valid route.
1014
+	 * @throws EE_Error
1015
+	 */
1016
+	protected function _verify_route($route)
1017
+	{
1018
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
1019
+			return true;
1020
+		}
1021
+		// user error msg
1022
+		$error_msg = sprintf(
1023
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1024
+			$this->_admin_page_title
1025
+		);
1026
+		// developer error msg
1027
+		$error_msg .= '||' . $error_msg
1028
+					  . sprintf(
1029
+						  esc_html__(
1030
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1031
+							  'event_espresso'
1032
+						  ),
1033
+						  $route
1034
+					  );
1035
+		throw new EE_Error($error_msg);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * perform nonce verification
1041
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1042
+	 * using this method (and save retyping!)
1043
+	 *
1044
+	 * @param string $nonce     The nonce sent
1045
+	 * @param string $nonce_ref The nonce reference string (name0)
1046
+	 * @return void
1047
+	 * @throws EE_Error
1048
+	 * @throws InvalidArgumentException
1049
+	 * @throws InvalidDataTypeException
1050
+	 * @throws InvalidInterfaceException
1051
+	 */
1052
+	protected function _verify_nonce($nonce, $nonce_ref)
1053
+	{
1054
+		// verify nonce against expected value
1055
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
1056
+			// these are not the droids you are looking for !!!
1057
+			$msg = sprintf(
1058
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
1059
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1060
+				'</a>'
1061
+			);
1062
+			if (WP_DEBUG) {
1063
+				$msg .= "\n  ";
1064
+				$msg .= sprintf(
1065
+					esc_html__(
1066
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1067
+						'event_espresso'
1068
+					),
1069
+					__CLASS__
1070
+				);
1071
+			}
1072
+			if (! $this->request->isAjax()) {
1073
+				wp_die($msg);
1074
+			}
1075
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1076
+			$this->_return_json();
1077
+		}
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * _route_admin_request()
1083
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1084
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1085
+	 * in the page routes and then will try to load the corresponding method.
1086
+	 *
1087
+	 * @return void
1088
+	 * @throws EE_Error
1089
+	 * @throws InvalidArgumentException
1090
+	 * @throws InvalidDataTypeException
1091
+	 * @throws InvalidInterfaceException
1092
+	 * @throws ReflectionException
1093
+	 */
1094
+	protected function _route_admin_request()
1095
+	{
1096
+		if (! $this->_is_UI_request) {
1097
+			$this->_verify_routes();
1098
+		}
1099
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1100
+		if ($this->_req_action !== 'default' && $nonce_check) {
1101
+			// set nonce from post data
1102
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
1103
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1104
+		}
1105
+		// set the nav_tabs array but ONLY if this is  UI_request
1106
+		if ($this->_is_UI_request) {
1107
+			$this->_set_nav_tabs();
1108
+		}
1109
+		// grab callback function
1110
+		$func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1111
+		// check if callback has args
1112
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1113
+		$error_msg = '';
1114
+		// action right before calling route
1115
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1116
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1117
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1118
+		}
1119
+		// strip _wp_http_referer from the server REQUEST_URI
1120
+		// else it grows in length on every submission due to recursion,
1121
+		// ultimately causing a "Request-URI Too Large" error
1122
+		$request_uri = remove_query_arg(
1123
+			'_wp_http_referer',
1124
+			wp_unslash($this->request->getServerParam('REQUEST_URI'))
1125
+		);
1126
+		// set new value in both our Request object and the super global
1127
+		$this->request->setServerParam('REQUEST_URI', $request_uri, true);
1128
+		if (! empty($func)) {
1129
+			if (is_array($func)) {
1130
+				[$class, $method] = $func;
1131
+			} elseif (strpos($func, '::') !== false) {
1132
+				[$class, $method] = explode('::', $func);
1133
+			} else {
1134
+				$class  = $this;
1135
+				$method = $func;
1136
+			}
1137
+			if (! (is_object($class) && $class === $this)) {
1138
+				// send along this admin page object for access by addons.
1139
+				$args['admin_page_object'] = $this;
1140
+			}
1141
+			if (
1142
+				// is it a method on a class that doesn't work?
1143
+				(
1144
+					(
1145
+						method_exists($class, $method)
1146
+						&& call_user_func_array([$class, $method], $args) === false
1147
+					)
1148
+					&& (
1149
+						// is it a standalone function that doesn't work?
1150
+						function_exists($method)
1151
+						&& call_user_func_array(
1152
+							$func,
1153
+							array_merge(['admin_page_object' => $this], $args)
1154
+						) === false
1155
+					)
1156
+				)
1157
+				|| (
1158
+					// is it neither a class method NOR a standalone function?
1159
+					! method_exists($class, $method)
1160
+					&& ! function_exists($method)
1161
+				)
1162
+			) {
1163
+				// user error msg
1164
+				$error_msg = esc_html__(
1165
+					'An error occurred. The  requested page route could not be found.',
1166
+					'event_espresso'
1167
+				);
1168
+				// developer error msg
1169
+				$error_msg .= '||';
1170
+				$error_msg .= sprintf(
1171
+					esc_html__(
1172
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1173
+						'event_espresso'
1174
+					),
1175
+					$method
1176
+				);
1177
+			}
1178
+			if (! empty($error_msg)) {
1179
+				throw new EE_Error($error_msg);
1180
+			}
1181
+		}
1182
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1183
+		// then we need to reset the routing properties to the new route.
1184
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1185
+		if (
1186
+			$this->_is_UI_request === false
1187
+			&& is_array($this->_route)
1188
+			&& ! empty($this->_route['headers_sent_route'])
1189
+		) {
1190
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1191
+		}
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * This method just allows the resetting of page properties in the case where a no headers
1197
+	 * route redirects to a headers route in its route config.
1198
+	 *
1199
+	 * @param string $new_route New (non header) route to redirect to.
1200
+	 * @return   void
1201
+	 * @throws ReflectionException
1202
+	 * @throws InvalidArgumentException
1203
+	 * @throws InvalidInterfaceException
1204
+	 * @throws InvalidDataTypeException
1205
+	 * @throws EE_Error
1206
+	 * @since   4.3.0
1207
+	 */
1208
+	protected function _reset_routing_properties($new_route)
1209
+	{
1210
+		$this->_is_UI_request = true;
1211
+		// now we set the current route to whatever the headers_sent_route is set at
1212
+		$this->request->setRequestParam('action', $new_route);
1213
+		// rerun page setup
1214
+		$this->_page_setup();
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * _add_query_arg
1220
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1221
+	 *(internally just uses EEH_URL's function with the same name)
1222
+	 *
1223
+	 * @param array  $args
1224
+	 * @param string $url
1225
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1226
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1227
+	 *                                        Example usage: If the current page is:
1228
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1229
+	 *                                        &action=default&event_id=20&month_range=March%202015
1230
+	 *                                        &_wpnonce=5467821
1231
+	 *                                        and you call:
1232
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1233
+	 *                                        array(
1234
+	 *                                        'action' => 'resend_something',
1235
+	 *                                        'page=>espresso_registrations'
1236
+	 *                                        ),
1237
+	 *                                        $some_url,
1238
+	 *                                        true
1239
+	 *                                        );
1240
+	 *                                        It will produce a url in this structure:
1241
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1242
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1243
+	 *                                        month_range]=March%202015
1244
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1245
+	 * @return string
1246
+	 */
1247
+	public static function add_query_args_and_nonce(
1248
+		$args = [],
1249
+		$url = '',
1250
+		$sticky = false,
1251
+		$exclude_nonce = false
1252
+	) {
1253
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1254
+		if ($sticky) {
1255
+			/** @var RequestInterface $request */
1256
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1257
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1258
+			$request->unSetServerParam('_wp_http_referer', true);
1259
+			foreach ($request->requestParams() as $key => $value) {
1260
+				// do not add nonces
1261
+				if (strpos($key, 'nonce') !== false) {
1262
+					continue;
1263
+				}
1264
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1265
+			}
1266
+		}
1267
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 * This returns a generated link that will load the related help tab.
1273
+	 *
1274
+	 * @param string $help_tab_id the id for the connected help tab
1275
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1276
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1277
+	 * @return string              generated link
1278
+	 * @uses EEH_Template::get_help_tab_link()
1279
+	 */
1280
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1281
+	{
1282
+		return EEH_Template::get_help_tab_link(
1283
+			$help_tab_id,
1284
+			$this->page_slug,
1285
+			$this->_req_action,
1286
+			$icon_style,
1287
+			$help_text
1288
+		);
1289
+	}
1290
+
1291
+
1292
+	/**
1293
+	 * _add_help_tabs
1294
+	 * Note child classes define their help tabs within the page_config array.
1295
+	 *
1296
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1297
+	 * @return void
1298
+	 * @throws DomainException
1299
+	 * @throws EE_Error
1300
+	 * @throws ReflectionException
1301
+	 */
1302
+	protected function _add_help_tabs()
1303
+	{
1304
+		if (isset($this->_page_config[ $this->_req_action ])) {
1305
+			$config = $this->_page_config[ $this->_req_action ];
1306
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1307
+			if (is_array($config) && isset($config['help_sidebar'])) {
1308
+				// check that the callback given is valid
1309
+				if (! method_exists($this, $config['help_sidebar'])) {
1310
+					throw new EE_Error(
1311
+						sprintf(
1312
+							esc_html__(
1313
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1314
+								'event_espresso'
1315
+							),
1316
+							$config['help_sidebar'],
1317
+							$this->class_name
1318
+						)
1319
+					);
1320
+				}
1321
+				$content = apply_filters(
1322
+					'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1323
+					$this->{$config['help_sidebar']}()
1324
+				);
1325
+				$this->_current_screen->set_help_sidebar($content);
1326
+			}
1327
+			if (! isset($config['help_tabs'])) {
1328
+				return;
1329
+			} //no help tabs for this route
1330
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1331
+				// we're here so there ARE help tabs!
1332
+				// make sure we've got what we need
1333
+				if (! isset($cfg['title'])) {
1334
+					throw new EE_Error(
1335
+						esc_html__(
1336
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1337
+							'event_espresso'
1338
+						)
1339
+					);
1340
+				}
1341
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1342
+					throw new EE_Error(
1343
+						esc_html__(
1344
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1345
+							'event_espresso'
1346
+						)
1347
+					);
1348
+				}
1349
+				// first priority goes to content.
1350
+				if (! empty($cfg['content'])) {
1351
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1352
+					// second priority goes to filename
1353
+				} elseif (! empty($cfg['filename'])) {
1354
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1355
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1356
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1357
+															 . basename($this->_get_dir())
1358
+															 . '/help_tabs/'
1359
+															 . $cfg['filename']
1360
+															 . '.help_tab.php' : $file_path;
1361
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1362
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1363
+						EE_Error::add_error(
1364
+							sprintf(
1365
+								esc_html__(
1366
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1367
+									'event_espresso'
1368
+								),
1369
+								$tab_id,
1370
+								key($config),
1371
+								$file_path
1372
+							),
1373
+							__FILE__,
1374
+							__FUNCTION__,
1375
+							__LINE__
1376
+						);
1377
+						return;
1378
+					}
1379
+					$template_args['admin_page_obj'] = $this;
1380
+					$content                         = EEH_Template::display_template(
1381
+						$file_path,
1382
+						$template_args,
1383
+						true
1384
+					);
1385
+				} else {
1386
+					$content = '';
1387
+				}
1388
+				// check if callback is valid
1389
+				if (
1390
+					empty($content)
1391
+					&& (
1392
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1393
+					)
1394
+				) {
1395
+					EE_Error::add_error(
1396
+						sprintf(
1397
+							esc_html__(
1398
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1399
+								'event_espresso'
1400
+							),
1401
+							$cfg['title']
1402
+						),
1403
+						__FILE__,
1404
+						__FUNCTION__,
1405
+						__LINE__
1406
+					);
1407
+					return;
1408
+				}
1409
+				// setup config array for help tab method
1410
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1411
+				$_ht = [
1412
+					'id'       => $id,
1413
+					'title'    => $cfg['title'],
1414
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1415
+					'content'  => $content,
1416
+				];
1417
+				$this->_current_screen->add_help_tab($_ht);
1418
+			}
1419
+		}
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * This simply sets up any qtips that have been defined in the page config
1425
+	 *
1426
+	 * @return void
1427
+	 * @throws ReflectionException
1428
+	 * @throws EE_Error
1429
+	 */
1430
+	protected function _add_qtips()
1431
+	{
1432
+		if (isset($this->_route_config['qtips'])) {
1433
+			$qtips = (array) $this->_route_config['qtips'];
1434
+			// load qtip loader
1435
+			$path = [
1436
+				$this->_get_dir() . '/qtips/',
1437
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1438
+			];
1439
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1440
+		}
1441
+	}
1442
+
1443
+
1444
+	/**
1445
+	 * _set_nav_tabs
1446
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1447
+	 * wish to add additional tabs or modify accordingly.
1448
+	 *
1449
+	 * @return void
1450
+	 * @throws InvalidArgumentException
1451
+	 * @throws InvalidInterfaceException
1452
+	 * @throws InvalidDataTypeException
1453
+	 */
1454
+	protected function _set_nav_tabs()
1455
+	{
1456
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1457
+		$i = 0;
1458
+		foreach ($this->_page_config as $slug => $config) {
1459
+			if (! is_array($config) || empty($config['nav'])) {
1460
+				continue;
1461
+			}
1462
+			// no nav tab for this config
1463
+			// check for persistent flag
1464
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1465
+				// nav tab is only to appear when route requested.
1466
+				continue;
1467
+			}
1468
+			if (! $this->check_user_access($slug, true)) {
1469
+				// no nav tab because current user does not have access.
1470
+				continue;
1471
+			}
1472
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1473
+			$this->_nav_tabs[ $slug ] = [
1474
+				'url'       => isset($config['nav']['url'])
1475
+					? $config['nav']['url']
1476
+					: EE_Admin_Page::add_query_args_and_nonce(
1477
+						['action' => $slug],
1478
+						$this->_admin_base_url
1479
+					),
1480
+				'link_text' => isset($config['nav']['label'])
1481
+					? $config['nav']['label']
1482
+					: ucwords(
1483
+						str_replace('_', ' ', $slug)
1484
+					),
1485
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1486
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1487
+			];
1488
+			$i++;
1489
+		}
1490
+		// if $this->_nav_tabs is empty then lets set the default
1491
+		if (empty($this->_nav_tabs)) {
1492
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1493
+				'url'       => $this->_admin_base_url,
1494
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1495
+				'css_class' => 'nav-tab-active',
1496
+				'order'     => 10,
1497
+			];
1498
+		}
1499
+		// now let's sort the tabs according to order
1500
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * _set_current_labels
1506
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1507
+	 * property array
1508
+	 *
1509
+	 * @return void
1510
+	 */
1511
+	private function _set_current_labels()
1512
+	{
1513
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1514
+			foreach ($this->_route_config['labels'] as $label => $text) {
1515
+				if (is_array($text)) {
1516
+					foreach ($text as $sublabel => $subtext) {
1517
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1518
+					}
1519
+				} else {
1520
+					$this->_labels[ $label ] = $text;
1521
+				}
1522
+			}
1523
+		}
1524
+	}
1525
+
1526
+
1527
+	/**
1528
+	 *        verifies user access for this admin page
1529
+	 *
1530
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1531
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1532
+	 *                               return false if verify fail.
1533
+	 * @return bool
1534
+	 * @throws InvalidArgumentException
1535
+	 * @throws InvalidDataTypeException
1536
+	 * @throws InvalidInterfaceException
1537
+	 */
1538
+	public function check_user_access($route_to_check = '', $verify_only = false)
1539
+	{
1540
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1541
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1542
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1543
+						  && is_array($this->_page_routes[ $route_to_check ])
1544
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1545
+			? $this->_page_routes[ $route_to_check ]['capability']
1546 1546
 			: null;
1547 1547
 
1548
-        if (empty($capability) && empty($route_to_check)) {
1549
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1550
-                : $this->_route['capability'];
1551
-        } else {
1552
-            $capability = empty($capability) ? 'manage_options' : $capability;
1553
-        }
1554
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1555
-        if (
1556
-            ! $this->request->isAjax()
1557
-            && (
1558
-                ! function_exists('is_admin')
1559
-                || ! EE_Registry::instance()->CAP->current_user_can(
1560
-                    $capability,
1561
-                    $this->page_slug
1562
-                    . '_'
1563
-                    . $route_to_check,
1564
-                    $id
1565
-                )
1566
-            )
1567
-        ) {
1568
-            if ($verify_only) {
1569
-                return false;
1570
-            }
1571
-            if (is_user_logged_in()) {
1572
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1573
-            } else {
1574
-                return false;
1575
-            }
1576
-        }
1577
-        return true;
1578
-    }
1579
-
1580
-
1581
-    /**
1582
-     * @param string                 $box_id
1583
-     * @param string                 $title
1584
-     * @param callable|string|null   $callback
1585
-     * @param string|array|WP_Screen $screen
1586
-     * @param string                 $context
1587
-     * @param string                 $priority
1588
-     * @param array|null             $callback_args
1589
-     */
1590
-    protected function addMetaBox(
1591
-        string $box_id,
1592
-        string $title,
1593
-        $callback,
1594
-        $screen,
1595
-        string $context = 'normal',
1596
-        string $priority = 'default',
1597
-        ?array $callback_args = null
1598
-    ) {
1599
-        if (! is_callable($callback)) {
1600
-            return;
1601
-        }
1602
-
1603
-        add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1604
-        add_filter(
1605
-            "postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1606
-            function ($classes) {
1607
-                array_push($classes, 'ee-admin-container');
1608
-                return $classes;
1609
-            }
1610
-        );
1611
-    }
1612
-
1613
-
1614
-    /**
1615
-     * admin_init_global
1616
-     * This runs all the code that we want executed within the WP admin_init hook.
1617
-     * This method executes for ALL EE Admin pages.
1618
-     *
1619
-     * @return void
1620
-     */
1621
-    public function admin_init_global()
1622
-    {
1623
-    }
1624
-
1625
-
1626
-    /**
1627
-     * wp_loaded_global
1628
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1629
-     * EE_Admin page and will execute on every EE Admin Page load
1630
-     *
1631
-     * @return void
1632
-     */
1633
-    public function wp_loaded()
1634
-    {
1635
-    }
1636
-
1637
-
1638
-    /**
1639
-     * admin_notices
1640
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1641
-     * ALL EE_Admin pages.
1642
-     *
1643
-     * @return void
1644
-     */
1645
-    public function admin_notices_global()
1646
-    {
1647
-        $this->_display_no_javascript_warning();
1648
-        $this->_display_espresso_notices();
1649
-    }
1650
-
1651
-
1652
-    public function network_admin_notices_global()
1653
-    {
1654
-        $this->_display_no_javascript_warning();
1655
-        $this->_display_espresso_notices();
1656
-    }
1657
-
1658
-
1659
-    /**
1660
-     * admin_footer_scripts_global
1661
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1662
-     * will apply on ALL EE_Admin pages.
1663
-     *
1664
-     * @return void
1665
-     */
1666
-    public function admin_footer_scripts_global()
1667
-    {
1668
-        $this->_add_admin_page_ajax_loading_img();
1669
-        $this->_add_admin_page_overlay();
1670
-        // if metaboxes are present we need to add the nonce field
1671
-        if (
1672
-            isset($this->_route_config['metaboxes'])
1673
-            || isset($this->_route_config['list_table'])
1674
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1675
-        ) {
1676
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1677
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1678
-        }
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * admin_footer_global
1684
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1685
-     * This particular method will apply on ALL EE_Admin Pages.
1686
-     *
1687
-     * @return void
1688
-     */
1689
-    public function admin_footer_global()
1690
-    {
1691
-        // dialog container for dialog helper
1692
-        echo '
1548
+		if (empty($capability) && empty($route_to_check)) {
1549
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1550
+				: $this->_route['capability'];
1551
+		} else {
1552
+			$capability = empty($capability) ? 'manage_options' : $capability;
1553
+		}
1554
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1555
+		if (
1556
+			! $this->request->isAjax()
1557
+			&& (
1558
+				! function_exists('is_admin')
1559
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1560
+					$capability,
1561
+					$this->page_slug
1562
+					. '_'
1563
+					. $route_to_check,
1564
+					$id
1565
+				)
1566
+			)
1567
+		) {
1568
+			if ($verify_only) {
1569
+				return false;
1570
+			}
1571
+			if (is_user_logged_in()) {
1572
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1573
+			} else {
1574
+				return false;
1575
+			}
1576
+		}
1577
+		return true;
1578
+	}
1579
+
1580
+
1581
+	/**
1582
+	 * @param string                 $box_id
1583
+	 * @param string                 $title
1584
+	 * @param callable|string|null   $callback
1585
+	 * @param string|array|WP_Screen $screen
1586
+	 * @param string                 $context
1587
+	 * @param string                 $priority
1588
+	 * @param array|null             $callback_args
1589
+	 */
1590
+	protected function addMetaBox(
1591
+		string $box_id,
1592
+		string $title,
1593
+		$callback,
1594
+		$screen,
1595
+		string $context = 'normal',
1596
+		string $priority = 'default',
1597
+		?array $callback_args = null
1598
+	) {
1599
+		if (! is_callable($callback)) {
1600
+			return;
1601
+		}
1602
+
1603
+		add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1604
+		add_filter(
1605
+			"postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1606
+			function ($classes) {
1607
+				array_push($classes, 'ee-admin-container');
1608
+				return $classes;
1609
+			}
1610
+		);
1611
+	}
1612
+
1613
+
1614
+	/**
1615
+	 * admin_init_global
1616
+	 * This runs all the code that we want executed within the WP admin_init hook.
1617
+	 * This method executes for ALL EE Admin pages.
1618
+	 *
1619
+	 * @return void
1620
+	 */
1621
+	public function admin_init_global()
1622
+	{
1623
+	}
1624
+
1625
+
1626
+	/**
1627
+	 * wp_loaded_global
1628
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1629
+	 * EE_Admin page and will execute on every EE Admin Page load
1630
+	 *
1631
+	 * @return void
1632
+	 */
1633
+	public function wp_loaded()
1634
+	{
1635
+	}
1636
+
1637
+
1638
+	/**
1639
+	 * admin_notices
1640
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1641
+	 * ALL EE_Admin pages.
1642
+	 *
1643
+	 * @return void
1644
+	 */
1645
+	public function admin_notices_global()
1646
+	{
1647
+		$this->_display_no_javascript_warning();
1648
+		$this->_display_espresso_notices();
1649
+	}
1650
+
1651
+
1652
+	public function network_admin_notices_global()
1653
+	{
1654
+		$this->_display_no_javascript_warning();
1655
+		$this->_display_espresso_notices();
1656
+	}
1657
+
1658
+
1659
+	/**
1660
+	 * admin_footer_scripts_global
1661
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1662
+	 * will apply on ALL EE_Admin pages.
1663
+	 *
1664
+	 * @return void
1665
+	 */
1666
+	public function admin_footer_scripts_global()
1667
+	{
1668
+		$this->_add_admin_page_ajax_loading_img();
1669
+		$this->_add_admin_page_overlay();
1670
+		// if metaboxes are present we need to add the nonce field
1671
+		if (
1672
+			isset($this->_route_config['metaboxes'])
1673
+			|| isset($this->_route_config['list_table'])
1674
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1675
+		) {
1676
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1677
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1678
+		}
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * admin_footer_global
1684
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1685
+	 * This particular method will apply on ALL EE_Admin Pages.
1686
+	 *
1687
+	 * @return void
1688
+	 */
1689
+	public function admin_footer_global()
1690
+	{
1691
+		// dialog container for dialog helper
1692
+		echo '
1693 1693
         <div class="ee-admin-dialog-container auto-hide hidden">
1694 1694
             <div class="ee-notices"></div>
1695 1695
             <div class="ee-admin-dialog-container-inner-content"></div>
1696 1696
         </div>
1697 1697
         ';
1698 1698
 
1699
-        // current set timezone for timezone js
1700
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1701
-    }
1702
-
1703
-
1704
-    /**
1705
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1706
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1707
-     * help popups then in your templates or your content you set "triggers" for the content using the
1708
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1709
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1710
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1711
-     * for the
1712
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1713
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1714
-     *    'help_trigger_id' => array(
1715
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1716
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1717
-     *    )
1718
-     * );
1719
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1720
-     *
1721
-     * @param array $help_array
1722
-     * @param bool  $display
1723
-     * @return string content
1724
-     * @throws DomainException
1725
-     * @throws EE_Error
1726
-     */
1727
-    protected function _set_help_popup_content($help_array = [], $display = false)
1728
-    {
1729
-        $content    = '';
1730
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1731
-        // loop through the array and setup content
1732
-        foreach ($help_array as $trigger => $help) {
1733
-            // make sure the array is setup properly
1734
-            if (! isset($help['title'], $help['content'])) {
1735
-                throw new EE_Error(
1736
-                    esc_html__(
1737
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1738
-                        'event_espresso'
1739
-                    )
1740
-                );
1741
-            }
1742
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1743
-            $template_args = [
1744
-                'help_popup_id'      => $trigger,
1745
-                'help_popup_title'   => $help['title'],
1746
-                'help_popup_content' => $help['content'],
1747
-            ];
1748
-            $content       .= EEH_Template::display_template(
1749
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1750
-                $template_args,
1751
-                true
1752
-            );
1753
-        }
1754
-        if ($display) {
1755
-            echo $content; // already escaped
1756
-            return '';
1757
-        }
1758
-        return $content;
1759
-    }
1760
-
1761
-
1762
-    /**
1763
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1764
-     *
1765
-     * @return array properly formatted array for help popup content
1766
-     * @throws EE_Error
1767
-     */
1768
-    private function _get_help_content()
1769
-    {
1770
-        // what is the method we're looking for?
1771
-        $method_name = '_help_popup_content_' . $this->_req_action;
1772
-        // if method doesn't exist let's get out.
1773
-        if (! method_exists($this, $method_name)) {
1774
-            return [];
1775
-        }
1776
-        // k we're good to go let's retrieve the help array
1777
-        $help_array = $this->{$method_name}();
1778
-        // make sure we've got an array!
1779
-        if (! is_array($help_array)) {
1780
-            throw new EE_Error(
1781
-                esc_html__(
1782
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1783
-                    'event_espresso'
1784
-                )
1785
-            );
1786
-        }
1787
-        return $help_array;
1788
-    }
1789
-
1790
-
1791
-    /**
1792
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1793
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1794
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1795
-     *
1796
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1797
-     * @param boolean $display    if false then we return the trigger string
1798
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1799
-     * @return string
1800
-     * @throws DomainException
1801
-     * @throws EE_Error
1802
-     */
1803
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1804
-    {
1805
-        if ($this->request->isAjax()) {
1806
-            return '';
1807
-        }
1808
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1809
-        $help_array   = $this->_get_help_content();
1810
-        $help_content = '';
1811
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1812
-            $help_array[ $trigger_id ] = [
1813
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1814
-                'content' => esc_html__(
1815
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1816
-                    'event_espresso'
1817
-                ),
1818
-            ];
1819
-            $help_content = $this->_set_help_popup_content($help_array);
1820
-        }
1821
-        // let's setup the trigger
1822
-        $content = '<a class="ee-dialog" href="?height='
1823
-                   . esc_attr($dimensions[0])
1824
-                   . '&width='
1825
-                   . esc_attr($dimensions[1])
1826
-                   . '&inlineId='
1827
-                   . esc_attr($trigger_id)
1828
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1829
-        $content .= $help_content;
1830
-        if ($display) {
1831
-            echo $content; // already escaped
1832
-            return '';
1833
-        }
1834
-        return $content;
1835
-    }
1836
-
1837
-
1838
-    /**
1839
-     * _add_global_screen_options
1840
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1841
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1842
-     *
1843
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1844
-     *         see also WP_Screen object documents...
1845
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1846
-     * @abstract
1847
-     * @return void
1848
-     */
1849
-    private function _add_global_screen_options()
1850
-    {
1851
-    }
1852
-
1853
-
1854
-    /**
1855
-     * _add_global_feature_pointers
1856
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1857
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1858
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1859
-     *
1860
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1861
-     *         extended) also see:
1862
-     * @link   http://eamann.com/tech/wordpress-portland/
1863
-     * @abstract
1864
-     * @return void
1865
-     */
1866
-    private function _add_global_feature_pointers()
1867
-    {
1868
-    }
1869
-
1870
-
1871
-    /**
1872
-     * load_global_scripts_styles
1873
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1874
-     *
1875
-     * @return void
1876
-     */
1877
-    public function load_global_scripts_styles()
1878
-    {
1879
-        // add debugging styles
1880
-        if (WP_DEBUG) {
1881
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1882
-        }
1883
-        // taking care of metaboxes
1884
-        if (
1885
-            empty($this->_cpt_route)
1886
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1887
-        ) {
1888
-            wp_enqueue_script('dashboard');
1889
-        }
1890
-
1891
-        wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1892
-        wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1893
-        // LOCALIZED DATA
1894
-        // localize script for ajax lazy loading
1895
-        wp_localize_script(
1896
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1897
-            'eeLazyLoadingContainers',
1898
-            apply_filters(
1899
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1900
-                ['espresso_news_post_box_content']
1901
-            )
1902
-        );
1903
-        StatusChangeNotice::loadAssets();
1904
-
1905
-        add_filter(
1906
-            'admin_body_class',
1907
-            function ($classes) {
1908
-                if (strpos($classes, 'espresso-admin') === false) {
1909
-                    $classes .= ' espresso-admin';
1910
-                }
1911
-                return $classes;
1912
-            }
1913
-        );
1914
-    }
1915
-
1916
-
1917
-    /**
1918
-     *        admin_footer_scripts_eei18n_js_strings
1919
-     *
1920
-     * @return        void
1921
-     */
1922
-    public function admin_footer_scripts_eei18n_js_strings()
1923
-    {
1924
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1925
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1926
-            __(
1927
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1928
-                'event_espresso'
1929
-            )
1930
-        );
1931
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1932
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1933
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1934
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1935
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1936
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1937
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1938
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1939
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1940
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1941
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1942
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1943
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1944
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1945
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1946
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1947
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1948
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1949
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1950
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1951
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1952
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1953
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1954
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1955
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1956
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1957
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1958
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1959
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1960
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1961
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1962
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1963
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1964
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1965
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1966
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1967
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1968
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1969
-    }
1970
-
1971
-
1972
-    /**
1973
-     *        load enhanced xdebug styles for ppl with failing eyesight
1974
-     *
1975
-     * @return        void
1976
-     */
1977
-    public function add_xdebug_style()
1978
-    {
1979
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1980
-    }
1981
-
1982
-
1983
-    /************************/
1984
-    /** LIST TABLE METHODS **/
1985
-    /************************/
1986
-    /**
1987
-     * this sets up the list table if the current view requires it.
1988
-     *
1989
-     * @return void
1990
-     * @throws EE_Error
1991
-     * @throws InvalidArgumentException
1992
-     * @throws InvalidDataTypeException
1993
-     * @throws InvalidInterfaceException
1994
-     */
1995
-    protected function _set_list_table()
1996
-    {
1997
-        // first is this a list_table view?
1998
-        if (! isset($this->_route_config['list_table'])) {
1999
-            return;
2000
-        } //not a list_table view so get out.
2001
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2002
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2003
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2004
-            // user error msg
2005
-            $error_msg = esc_html__(
2006
-                'An error occurred. The requested list table views could not be found.',
2007
-                'event_espresso'
2008
-            );
2009
-            // developer error msg
2010
-            $error_msg .= '||'
2011
-                          . sprintf(
2012
-                              esc_html__(
2013
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2014
-                                  'event_espresso'
2015
-                              ),
2016
-                              $this->_req_action,
2017
-                              $list_table_view
2018
-                          );
2019
-            throw new EE_Error($error_msg);
2020
-        }
2021
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2022
-        $this->_views = apply_filters(
2023
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2024
-            $this->_views
2025
-        );
2026
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2027
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2028
-        $this->_set_list_table_view();
2029
-        $this->_set_list_table_object();
2030
-    }
2031
-
2032
-
2033
-    /**
2034
-     * set current view for List Table
2035
-     *
2036
-     * @return void
2037
-     */
2038
-    protected function _set_list_table_view()
2039
-    {
2040
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2041
-        $status = $this->request->getRequestParam('status', null, 'key');
2042
-        $this->_view = $status && array_key_exists($status, $this->_views)
2043
-            ? $status
2044
-            : $this->_view;
2045
-    }
2046
-
2047
-
2048
-    /**
2049
-     * _set_list_table_object
2050
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2051
-     *
2052
-     * @throws InvalidInterfaceException
2053
-     * @throws InvalidArgumentException
2054
-     * @throws InvalidDataTypeException
2055
-     * @throws EE_Error
2056
-     * @throws InvalidInterfaceException
2057
-     */
2058
-    protected function _set_list_table_object()
2059
-    {
2060
-        if (isset($this->_route_config['list_table'])) {
2061
-            if (! class_exists($this->_route_config['list_table'])) {
2062
-                throw new EE_Error(
2063
-                    sprintf(
2064
-                        esc_html__(
2065
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2066
-                            'event_espresso'
2067
-                        ),
2068
-                        $this->_route_config['list_table'],
2069
-                        $this->class_name
2070
-                    )
2071
-                );
2072
-            }
2073
-            $this->_list_table_object = $this->loader->getShared(
2074
-                $this->_route_config['list_table'],
2075
-                [$this]
2076
-            );
2077
-        }
2078
-    }
2079
-
2080
-
2081
-    /**
2082
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2083
-     *
2084
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2085
-     *                                                    urls.  The array should be indexed by the view it is being
2086
-     *                                                    added to.
2087
-     * @return array
2088
-     */
2089
-    public function get_list_table_view_RLs($extra_query_args = [])
2090
-    {
2091
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2092
-        if (empty($this->_views)) {
2093
-            $this->_views = [];
2094
-        }
2095
-        // cycle thru views
2096
-        foreach ($this->_views as $key => $view) {
2097
-            $query_args = [];
2098
-            // check for current view
2099
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2100
-            $query_args['action']                        = $this->_req_action;
2101
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2102
-            $query_args['status']                        = $view['slug'];
2103
-            // merge any other arguments sent in.
2104
-            if (isset($extra_query_args[ $view['slug'] ])) {
2105
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2106
-                    $query_args[] = $extra_query_arg;
2107
-                }
2108
-            }
2109
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2110
-        }
2111
-        return $this->_views;
2112
-    }
2113
-
2114
-
2115
-    /**
2116
-     * _entries_per_page_dropdown
2117
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2118
-     *
2119
-     * @param int $max_entries total number of rows in the table
2120
-     * @return string
2121
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2122
-     *         WP does it.
2123
-     */
2124
-    protected function _entries_per_page_dropdown($max_entries = 0)
2125
-    {
2126
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2127
-        $values   = [10, 25, 50, 100];
2128
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2129
-        if ($max_entries) {
2130
-            $values[] = $max_entries;
2131
-            sort($values);
2132
-        }
2133
-        $entries_per_page_dropdown = '
1699
+		// current set timezone for timezone js
1700
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1701
+	}
1702
+
1703
+
1704
+	/**
1705
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1706
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1707
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1708
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1709
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1710
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1711
+	 * for the
1712
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1713
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1714
+	 *    'help_trigger_id' => array(
1715
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1716
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1717
+	 *    )
1718
+	 * );
1719
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1720
+	 *
1721
+	 * @param array $help_array
1722
+	 * @param bool  $display
1723
+	 * @return string content
1724
+	 * @throws DomainException
1725
+	 * @throws EE_Error
1726
+	 */
1727
+	protected function _set_help_popup_content($help_array = [], $display = false)
1728
+	{
1729
+		$content    = '';
1730
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1731
+		// loop through the array and setup content
1732
+		foreach ($help_array as $trigger => $help) {
1733
+			// make sure the array is setup properly
1734
+			if (! isset($help['title'], $help['content'])) {
1735
+				throw new EE_Error(
1736
+					esc_html__(
1737
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1738
+						'event_espresso'
1739
+					)
1740
+				);
1741
+			}
1742
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1743
+			$template_args = [
1744
+				'help_popup_id'      => $trigger,
1745
+				'help_popup_title'   => $help['title'],
1746
+				'help_popup_content' => $help['content'],
1747
+			];
1748
+			$content       .= EEH_Template::display_template(
1749
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1750
+				$template_args,
1751
+				true
1752
+			);
1753
+		}
1754
+		if ($display) {
1755
+			echo $content; // already escaped
1756
+			return '';
1757
+		}
1758
+		return $content;
1759
+	}
1760
+
1761
+
1762
+	/**
1763
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1764
+	 *
1765
+	 * @return array properly formatted array for help popup content
1766
+	 * @throws EE_Error
1767
+	 */
1768
+	private function _get_help_content()
1769
+	{
1770
+		// what is the method we're looking for?
1771
+		$method_name = '_help_popup_content_' . $this->_req_action;
1772
+		// if method doesn't exist let's get out.
1773
+		if (! method_exists($this, $method_name)) {
1774
+			return [];
1775
+		}
1776
+		// k we're good to go let's retrieve the help array
1777
+		$help_array = $this->{$method_name}();
1778
+		// make sure we've got an array!
1779
+		if (! is_array($help_array)) {
1780
+			throw new EE_Error(
1781
+				esc_html__(
1782
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1783
+					'event_espresso'
1784
+				)
1785
+			);
1786
+		}
1787
+		return $help_array;
1788
+	}
1789
+
1790
+
1791
+	/**
1792
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1793
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1794
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1795
+	 *
1796
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1797
+	 * @param boolean $display    if false then we return the trigger string
1798
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1799
+	 * @return string
1800
+	 * @throws DomainException
1801
+	 * @throws EE_Error
1802
+	 */
1803
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1804
+	{
1805
+		if ($this->request->isAjax()) {
1806
+			return '';
1807
+		}
1808
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1809
+		$help_array   = $this->_get_help_content();
1810
+		$help_content = '';
1811
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1812
+			$help_array[ $trigger_id ] = [
1813
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1814
+				'content' => esc_html__(
1815
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1816
+					'event_espresso'
1817
+				),
1818
+			];
1819
+			$help_content = $this->_set_help_popup_content($help_array);
1820
+		}
1821
+		// let's setup the trigger
1822
+		$content = '<a class="ee-dialog" href="?height='
1823
+				   . esc_attr($dimensions[0])
1824
+				   . '&width='
1825
+				   . esc_attr($dimensions[1])
1826
+				   . '&inlineId='
1827
+				   . esc_attr($trigger_id)
1828
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1829
+		$content .= $help_content;
1830
+		if ($display) {
1831
+			echo $content; // already escaped
1832
+			return '';
1833
+		}
1834
+		return $content;
1835
+	}
1836
+
1837
+
1838
+	/**
1839
+	 * _add_global_screen_options
1840
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1841
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1842
+	 *
1843
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1844
+	 *         see also WP_Screen object documents...
1845
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1846
+	 * @abstract
1847
+	 * @return void
1848
+	 */
1849
+	private function _add_global_screen_options()
1850
+	{
1851
+	}
1852
+
1853
+
1854
+	/**
1855
+	 * _add_global_feature_pointers
1856
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1857
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1858
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1859
+	 *
1860
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1861
+	 *         extended) also see:
1862
+	 * @link   http://eamann.com/tech/wordpress-portland/
1863
+	 * @abstract
1864
+	 * @return void
1865
+	 */
1866
+	private function _add_global_feature_pointers()
1867
+	{
1868
+	}
1869
+
1870
+
1871
+	/**
1872
+	 * load_global_scripts_styles
1873
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1874
+	 *
1875
+	 * @return void
1876
+	 */
1877
+	public function load_global_scripts_styles()
1878
+	{
1879
+		// add debugging styles
1880
+		if (WP_DEBUG) {
1881
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1882
+		}
1883
+		// taking care of metaboxes
1884
+		if (
1885
+			empty($this->_cpt_route)
1886
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1887
+		) {
1888
+			wp_enqueue_script('dashboard');
1889
+		}
1890
+
1891
+		wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1892
+		wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1893
+		// LOCALIZED DATA
1894
+		// localize script for ajax lazy loading
1895
+		wp_localize_script(
1896
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1897
+			'eeLazyLoadingContainers',
1898
+			apply_filters(
1899
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1900
+				['espresso_news_post_box_content']
1901
+			)
1902
+		);
1903
+		StatusChangeNotice::loadAssets();
1904
+
1905
+		add_filter(
1906
+			'admin_body_class',
1907
+			function ($classes) {
1908
+				if (strpos($classes, 'espresso-admin') === false) {
1909
+					$classes .= ' espresso-admin';
1910
+				}
1911
+				return $classes;
1912
+			}
1913
+		);
1914
+	}
1915
+
1916
+
1917
+	/**
1918
+	 *        admin_footer_scripts_eei18n_js_strings
1919
+	 *
1920
+	 * @return        void
1921
+	 */
1922
+	public function admin_footer_scripts_eei18n_js_strings()
1923
+	{
1924
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1925
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1926
+			__(
1927
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1928
+				'event_espresso'
1929
+			)
1930
+		);
1931
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1932
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1933
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1934
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1935
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1936
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1937
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1938
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1939
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1940
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1941
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1942
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1943
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1944
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1945
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1946
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1947
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1948
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1949
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1950
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1951
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1952
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1953
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1954
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1955
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1956
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1957
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1958
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1959
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1960
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1961
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1962
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1963
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1964
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1965
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1966
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1967
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1968
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1969
+	}
1970
+
1971
+
1972
+	/**
1973
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1974
+	 *
1975
+	 * @return        void
1976
+	 */
1977
+	public function add_xdebug_style()
1978
+	{
1979
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1980
+	}
1981
+
1982
+
1983
+	/************************/
1984
+	/** LIST TABLE METHODS **/
1985
+	/************************/
1986
+	/**
1987
+	 * this sets up the list table if the current view requires it.
1988
+	 *
1989
+	 * @return void
1990
+	 * @throws EE_Error
1991
+	 * @throws InvalidArgumentException
1992
+	 * @throws InvalidDataTypeException
1993
+	 * @throws InvalidInterfaceException
1994
+	 */
1995
+	protected function _set_list_table()
1996
+	{
1997
+		// first is this a list_table view?
1998
+		if (! isset($this->_route_config['list_table'])) {
1999
+			return;
2000
+		} //not a list_table view so get out.
2001
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2002
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2003
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2004
+			// user error msg
2005
+			$error_msg = esc_html__(
2006
+				'An error occurred. The requested list table views could not be found.',
2007
+				'event_espresso'
2008
+			);
2009
+			// developer error msg
2010
+			$error_msg .= '||'
2011
+						  . sprintf(
2012
+							  esc_html__(
2013
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2014
+								  'event_espresso'
2015
+							  ),
2016
+							  $this->_req_action,
2017
+							  $list_table_view
2018
+						  );
2019
+			throw new EE_Error($error_msg);
2020
+		}
2021
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2022
+		$this->_views = apply_filters(
2023
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2024
+			$this->_views
2025
+		);
2026
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2027
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2028
+		$this->_set_list_table_view();
2029
+		$this->_set_list_table_object();
2030
+	}
2031
+
2032
+
2033
+	/**
2034
+	 * set current view for List Table
2035
+	 *
2036
+	 * @return void
2037
+	 */
2038
+	protected function _set_list_table_view()
2039
+	{
2040
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2041
+		$status = $this->request->getRequestParam('status', null, 'key');
2042
+		$this->_view = $status && array_key_exists($status, $this->_views)
2043
+			? $status
2044
+			: $this->_view;
2045
+	}
2046
+
2047
+
2048
+	/**
2049
+	 * _set_list_table_object
2050
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2051
+	 *
2052
+	 * @throws InvalidInterfaceException
2053
+	 * @throws InvalidArgumentException
2054
+	 * @throws InvalidDataTypeException
2055
+	 * @throws EE_Error
2056
+	 * @throws InvalidInterfaceException
2057
+	 */
2058
+	protected function _set_list_table_object()
2059
+	{
2060
+		if (isset($this->_route_config['list_table'])) {
2061
+			if (! class_exists($this->_route_config['list_table'])) {
2062
+				throw new EE_Error(
2063
+					sprintf(
2064
+						esc_html__(
2065
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2066
+							'event_espresso'
2067
+						),
2068
+						$this->_route_config['list_table'],
2069
+						$this->class_name
2070
+					)
2071
+				);
2072
+			}
2073
+			$this->_list_table_object = $this->loader->getShared(
2074
+				$this->_route_config['list_table'],
2075
+				[$this]
2076
+			);
2077
+		}
2078
+	}
2079
+
2080
+
2081
+	/**
2082
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2083
+	 *
2084
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2085
+	 *                                                    urls.  The array should be indexed by the view it is being
2086
+	 *                                                    added to.
2087
+	 * @return array
2088
+	 */
2089
+	public function get_list_table_view_RLs($extra_query_args = [])
2090
+	{
2091
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2092
+		if (empty($this->_views)) {
2093
+			$this->_views = [];
2094
+		}
2095
+		// cycle thru views
2096
+		foreach ($this->_views as $key => $view) {
2097
+			$query_args = [];
2098
+			// check for current view
2099
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2100
+			$query_args['action']                        = $this->_req_action;
2101
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2102
+			$query_args['status']                        = $view['slug'];
2103
+			// merge any other arguments sent in.
2104
+			if (isset($extra_query_args[ $view['slug'] ])) {
2105
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2106
+					$query_args[] = $extra_query_arg;
2107
+				}
2108
+			}
2109
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2110
+		}
2111
+		return $this->_views;
2112
+	}
2113
+
2114
+
2115
+	/**
2116
+	 * _entries_per_page_dropdown
2117
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2118
+	 *
2119
+	 * @param int $max_entries total number of rows in the table
2120
+	 * @return string
2121
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2122
+	 *         WP does it.
2123
+	 */
2124
+	protected function _entries_per_page_dropdown($max_entries = 0)
2125
+	{
2126
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2127
+		$values   = [10, 25, 50, 100];
2128
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2129
+		if ($max_entries) {
2130
+			$values[] = $max_entries;
2131
+			sort($values);
2132
+		}
2133
+		$entries_per_page_dropdown = '
2134 2134
 			<div id="entries-per-page-dv" class="alignleft actions">
2135 2135
 				<label class="hide-if-no-js">
2136 2136
 					Show
2137 2137
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2138
-        foreach ($values as $value) {
2139
-            if ($value < $max_entries) {
2140
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2141
-                $entries_per_page_dropdown .= '
2138
+		foreach ($values as $value) {
2139
+			if ($value < $max_entries) {
2140
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2141
+				$entries_per_page_dropdown .= '
2142 2142
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2143
-            }
2144
-        }
2145
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2146
-        $entries_per_page_dropdown .= '
2143
+			}
2144
+		}
2145
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2146
+		$entries_per_page_dropdown .= '
2147 2147
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2148
-        $entries_per_page_dropdown .= '
2148
+		$entries_per_page_dropdown .= '
2149 2149
 					</select>
2150 2150
 					entries
2151 2151
 				</label>
2152 2152
 				<input id="entries-per-page-btn" class="button button--secondary" type="submit" value="Go" >
2153 2153
 			</div>
2154 2154
 		';
2155
-        return $entries_per_page_dropdown;
2156
-    }
2157
-
2158
-
2159
-    /**
2160
-     *        _set_search_attributes
2161
-     *
2162
-     * @return        void
2163
-     */
2164
-    public function _set_search_attributes()
2165
-    {
2166
-        $this->_template_args['search']['btn_label'] = sprintf(
2167
-            esc_html__('Search %s', 'event_espresso'),
2168
-            empty($this->_search_btn_label) ? $this->page_label
2169
-                : $this->_search_btn_label
2170
-        );
2171
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2172
-    }
2173
-
2174
-
2175
-
2176
-    /*** END LIST TABLE METHODS **/
2177
-
2178
-
2179
-    /**
2180
-     * _add_registered_metaboxes
2181
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2182
-     *
2183
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2184
-     * @return void
2185
-     * @throws EE_Error
2186
-     */
2187
-    private function _add_registered_meta_boxes()
2188
-    {
2189
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
-        // we only add meta boxes if the page_route calls for it
2191
-        if (
2192
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2193
-            && is_array(
2194
-                $this->_route_config['metaboxes']
2195
-            )
2196
-        ) {
2197
-            // this simply loops through the callbacks provided
2198
-            // and checks if there is a corresponding callback registered by the child
2199
-            // if there is then we go ahead and process the metabox loader.
2200
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2201
-                // first check for Closures
2202
-                if ($metabox_callback instanceof Closure) {
2203
-                    $result = $metabox_callback();
2204
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2205
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2206
-                } else {
2207
-                    $result = $this->{$metabox_callback}();
2208
-                }
2209
-                if ($result === false) {
2210
-                    // user error msg
2211
-                    $error_msg = esc_html__(
2212
-                        'An error occurred. The  requested metabox could not be found.',
2213
-                        'event_espresso'
2214
-                    );
2215
-                    // developer error msg
2216
-                    $error_msg .= '||'
2217
-                                  . sprintf(
2218
-                                      esc_html__(
2219
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2220
-                                          'event_espresso'
2221
-                                      ),
2222
-                                      $metabox_callback
2223
-                                  );
2224
-                    throw new EE_Error($error_msg);
2225
-                }
2226
-            }
2227
-        }
2228
-    }
2229
-
2230
-
2231
-    /**
2232
-     * _add_screen_columns
2233
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2234
-     * the dynamic column template and we'll setup the column options for the page.
2235
-     *
2236
-     * @return void
2237
-     */
2238
-    private function _add_screen_columns()
2239
-    {
2240
-        if (
2241
-            is_array($this->_route_config)
2242
-            && isset($this->_route_config['columns'])
2243
-            && is_array($this->_route_config['columns'])
2244
-            && count($this->_route_config['columns']) === 2
2245
-        ) {
2246
-            add_screen_option(
2247
-                'layout_columns',
2248
-                [
2249
-                    'max'     => (int) $this->_route_config['columns'][0],
2250
-                    'default' => (int) $this->_route_config['columns'][1],
2251
-                ]
2252
-            );
2253
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2254
-            $screen_id                                           = $this->_current_screen->id;
2255
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2256
-            $total_columns                                       = ! empty($screen_columns)
2257
-                ? $screen_columns
2258
-                : $this->_route_config['columns'][1];
2259
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2260
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2261
-            $this->_template_args['screen']                      = $this->_current_screen;
2262
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2263
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2264
-            // finally if we don't have has_metaboxes set in the route config
2265
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2266
-            $this->_route_config['has_metaboxes'] = true;
2267
-        }
2268
-    }
2269
-
2270
-
2271
-
2272
-    /** GLOBALLY AVAILABLE METABOXES **/
2273
-
2274
-
2275
-    /**
2276
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2277
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2278
-     * these get loaded on.
2279
-     */
2280
-    private function _espresso_news_post_box()
2281
-    {
2282
-        $news_box_title = apply_filters(
2283
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2284
-            esc_html__('New @ Event Espresso', 'event_espresso')
2285
-        );
2286
-        $this->addMetaBox(
2287
-            'espresso_news_post_box',
2288
-            $news_box_title,
2289
-            [
2290
-                $this,
2291
-                'espresso_news_post_box',
2292
-            ],
2293
-            $this->_wp_page_slug,
2294
-            'side',
2295
-            'low'
2296
-        );
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * Code for setting up espresso ratings request metabox.
2302
-     */
2303
-    protected function _espresso_ratings_request()
2304
-    {
2305
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2306
-            return;
2307
-        }
2308
-        $ratings_box_title = apply_filters(
2309
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2310
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2311
-        );
2312
-        $this->addMetaBox(
2313
-            'espresso_ratings_request',
2314
-            $ratings_box_title,
2315
-            [
2316
-                $this,
2317
-                'espresso_ratings_request',
2318
-            ],
2319
-            $this->_wp_page_slug,
2320
-            'side'
2321
-        );
2322
-    }
2323
-
2324
-
2325
-    /**
2326
-     * Code for setting up espresso ratings request metabox content.
2327
-     *
2328
-     * @throws DomainException
2329
-     */
2330
-    public function espresso_ratings_request()
2331
-    {
2332
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2333
-    }
2334
-
2335
-
2336
-    public static function cached_rss_display($rss_id, $url)
2337
-    {
2338
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2339
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2340
-                     . '</p><p class="hide-if-js">'
2341
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2342
-                     . '</p>';
2343
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2344
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2345
-        $post      = '</div>' . "\n";
2346
-        $cache_key = 'ee_rss_' . md5($rss_id);
2347
-        $output    = get_transient($cache_key);
2348
-        if ($output !== false) {
2349
-            echo $pre . $output . $post; // already escaped
2350
-            return true;
2351
-        }
2352
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
-            echo $pre . $loading . $post; // already escaped
2354
-            return false;
2355
-        }
2356
-        ob_start();
2357
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2358
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2359
-        return true;
2360
-    }
2361
-
2362
-
2363
-    public function espresso_news_post_box()
2364
-    {
2365
-        ?>
2155
+		return $entries_per_page_dropdown;
2156
+	}
2157
+
2158
+
2159
+	/**
2160
+	 *        _set_search_attributes
2161
+	 *
2162
+	 * @return        void
2163
+	 */
2164
+	public function _set_search_attributes()
2165
+	{
2166
+		$this->_template_args['search']['btn_label'] = sprintf(
2167
+			esc_html__('Search %s', 'event_espresso'),
2168
+			empty($this->_search_btn_label) ? $this->page_label
2169
+				: $this->_search_btn_label
2170
+		);
2171
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2172
+	}
2173
+
2174
+
2175
+
2176
+	/*** END LIST TABLE METHODS **/
2177
+
2178
+
2179
+	/**
2180
+	 * _add_registered_metaboxes
2181
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2182
+	 *
2183
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2184
+	 * @return void
2185
+	 * @throws EE_Error
2186
+	 */
2187
+	private function _add_registered_meta_boxes()
2188
+	{
2189
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
+		// we only add meta boxes if the page_route calls for it
2191
+		if (
2192
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2193
+			&& is_array(
2194
+				$this->_route_config['metaboxes']
2195
+			)
2196
+		) {
2197
+			// this simply loops through the callbacks provided
2198
+			// and checks if there is a corresponding callback registered by the child
2199
+			// if there is then we go ahead and process the metabox loader.
2200
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2201
+				// first check for Closures
2202
+				if ($metabox_callback instanceof Closure) {
2203
+					$result = $metabox_callback();
2204
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2205
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2206
+				} else {
2207
+					$result = $this->{$metabox_callback}();
2208
+				}
2209
+				if ($result === false) {
2210
+					// user error msg
2211
+					$error_msg = esc_html__(
2212
+						'An error occurred. The  requested metabox could not be found.',
2213
+						'event_espresso'
2214
+					);
2215
+					// developer error msg
2216
+					$error_msg .= '||'
2217
+								  . sprintf(
2218
+									  esc_html__(
2219
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2220
+										  'event_espresso'
2221
+									  ),
2222
+									  $metabox_callback
2223
+								  );
2224
+					throw new EE_Error($error_msg);
2225
+				}
2226
+			}
2227
+		}
2228
+	}
2229
+
2230
+
2231
+	/**
2232
+	 * _add_screen_columns
2233
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2234
+	 * the dynamic column template and we'll setup the column options for the page.
2235
+	 *
2236
+	 * @return void
2237
+	 */
2238
+	private function _add_screen_columns()
2239
+	{
2240
+		if (
2241
+			is_array($this->_route_config)
2242
+			&& isset($this->_route_config['columns'])
2243
+			&& is_array($this->_route_config['columns'])
2244
+			&& count($this->_route_config['columns']) === 2
2245
+		) {
2246
+			add_screen_option(
2247
+				'layout_columns',
2248
+				[
2249
+					'max'     => (int) $this->_route_config['columns'][0],
2250
+					'default' => (int) $this->_route_config['columns'][1],
2251
+				]
2252
+			);
2253
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2254
+			$screen_id                                           = $this->_current_screen->id;
2255
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2256
+			$total_columns                                       = ! empty($screen_columns)
2257
+				? $screen_columns
2258
+				: $this->_route_config['columns'][1];
2259
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2260
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2261
+			$this->_template_args['screen']                      = $this->_current_screen;
2262
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2263
+																   . 'admin_details_metabox_column_wrapper.template.php';
2264
+			// finally if we don't have has_metaboxes set in the route config
2265
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2266
+			$this->_route_config['has_metaboxes'] = true;
2267
+		}
2268
+	}
2269
+
2270
+
2271
+
2272
+	/** GLOBALLY AVAILABLE METABOXES **/
2273
+
2274
+
2275
+	/**
2276
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2277
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2278
+	 * these get loaded on.
2279
+	 */
2280
+	private function _espresso_news_post_box()
2281
+	{
2282
+		$news_box_title = apply_filters(
2283
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2284
+			esc_html__('New @ Event Espresso', 'event_espresso')
2285
+		);
2286
+		$this->addMetaBox(
2287
+			'espresso_news_post_box',
2288
+			$news_box_title,
2289
+			[
2290
+				$this,
2291
+				'espresso_news_post_box',
2292
+			],
2293
+			$this->_wp_page_slug,
2294
+			'side',
2295
+			'low'
2296
+		);
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * Code for setting up espresso ratings request metabox.
2302
+	 */
2303
+	protected function _espresso_ratings_request()
2304
+	{
2305
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2306
+			return;
2307
+		}
2308
+		$ratings_box_title = apply_filters(
2309
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2310
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2311
+		);
2312
+		$this->addMetaBox(
2313
+			'espresso_ratings_request',
2314
+			$ratings_box_title,
2315
+			[
2316
+				$this,
2317
+				'espresso_ratings_request',
2318
+			],
2319
+			$this->_wp_page_slug,
2320
+			'side'
2321
+		);
2322
+	}
2323
+
2324
+
2325
+	/**
2326
+	 * Code for setting up espresso ratings request metabox content.
2327
+	 *
2328
+	 * @throws DomainException
2329
+	 */
2330
+	public function espresso_ratings_request()
2331
+	{
2332
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2333
+	}
2334
+
2335
+
2336
+	public static function cached_rss_display($rss_id, $url)
2337
+	{
2338
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2339
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2340
+					 . '</p><p class="hide-if-js">'
2341
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2342
+					 . '</p>';
2343
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2344
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2345
+		$post      = '</div>' . "\n";
2346
+		$cache_key = 'ee_rss_' . md5($rss_id);
2347
+		$output    = get_transient($cache_key);
2348
+		if ($output !== false) {
2349
+			echo $pre . $output . $post; // already escaped
2350
+			return true;
2351
+		}
2352
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
+			echo $pre . $loading . $post; // already escaped
2354
+			return false;
2355
+		}
2356
+		ob_start();
2357
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2358
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2359
+		return true;
2360
+	}
2361
+
2362
+
2363
+	public function espresso_news_post_box()
2364
+	{
2365
+		?>
2366 2366
         <div class="padding">
2367 2367
             <div id="espresso_news_post_box_content" class="infolinks">
2368 2368
                 <?php
2369
-                // Get RSS Feed(s)
2370
-                EE_Admin_Page::cached_rss_display(
2371
-                    'espresso_news_post_box_content',
2372
-                    esc_url_raw(
2373
-                        apply_filters(
2374
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2375
-                            'https://eventespresso.com/feed/'
2376
-                        )
2377
-                    )
2378
-                );
2379
-                ?>
2369
+				// Get RSS Feed(s)
2370
+				EE_Admin_Page::cached_rss_display(
2371
+					'espresso_news_post_box_content',
2372
+					esc_url_raw(
2373
+						apply_filters(
2374
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2375
+							'https://eventespresso.com/feed/'
2376
+						)
2377
+					)
2378
+				);
2379
+				?>
2380 2380
             </div>
2381 2381
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2382 2382
         </div>
2383 2383
         <?php
2384
-    }
2385
-
2386
-
2387
-    private function _espresso_links_post_box()
2388
-    {
2389
-        // Hiding until we actually have content to put in here...
2390
-        // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2391
-    }
2392
-
2393
-
2394
-    public function espresso_links_post_box()
2395
-    {
2396
-        // Hiding until we actually have content to put in here...
2397
-        // EEH_Template::display_template(
2398
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2399
-        // );
2400
-    }
2401
-
2402
-
2403
-    protected function _espresso_sponsors_post_box()
2404
-    {
2405
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2406
-            $this->addMetaBox(
2407
-                'espresso_sponsors_post_box',
2408
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2409
-                [$this, 'espresso_sponsors_post_box'],
2410
-                $this->_wp_page_slug,
2411
-                'side'
2412
-            );
2413
-        }
2414
-    }
2415
-
2416
-
2417
-    public function espresso_sponsors_post_box()
2418
-    {
2419
-        EEH_Template::display_template(
2420
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2421
-        );
2422
-    }
2423
-
2424
-
2425
-    private function _publish_post_box()
2426
-    {
2427
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2428
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2429
-        // then we'll use that for the metabox label.
2430
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2431
-        if (! empty($this->_labels['publishbox'])) {
2432
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2433
-                : $this->_labels['publishbox'];
2434
-        } else {
2435
-            $box_label = esc_html__('Publish', 'event_espresso');
2436
-        }
2437
-        $box_label = apply_filters(
2438
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2439
-            $box_label,
2440
-            $this->_req_action,
2441
-            $this
2442
-        );
2443
-        $this->addMetaBox(
2444
-            $meta_box_ref,
2445
-            $box_label,
2446
-            [$this, 'editor_overview'],
2447
-            $this->_current_screen->id,
2448
-            'side',
2449
-            'high'
2450
-        );
2451
-    }
2452
-
2453
-
2454
-    public function editor_overview()
2455
-    {
2456
-        // if we have extra content set let's add it in if not make sure its empty
2457
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2458
-            ? $this->_template_args['publish_box_extra_content']
2459
-            : '';
2460
-        echo EEH_Template::display_template(
2461
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2462
-            $this->_template_args,
2463
-            true
2464
-        );
2465
-    }
2466
-
2467
-
2468
-    /** end of globally available metaboxes section **/
2469
-
2470
-
2471
-    /**
2472
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2473
-     * protected method.
2474
-     *
2475
-     * @param string $name
2476
-     * @param int    $id
2477
-     * @param bool   $delete
2478
-     * @param string $save_close_redirect_URL
2479
-     * @param bool   $both_btns
2480
-     * @throws EE_Error
2481
-     * @throws InvalidArgumentException
2482
-     * @throws InvalidDataTypeException
2483
-     * @throws InvalidInterfaceException
2484
-     * @see   $this->_set_publish_post_box_vars for param details
2485
-     * @since 4.6.0
2486
-     */
2487
-    public function set_publish_post_box_vars(
2488
-        $name = '',
2489
-        $id = 0,
2490
-        $delete = false,
2491
-        $save_close_redirect_URL = '',
2492
-        $both_btns = true
2493
-    ) {
2494
-        $this->_set_publish_post_box_vars(
2495
-            $name,
2496
-            $id,
2497
-            $delete,
2498
-            $save_close_redirect_URL,
2499
-            $both_btns
2500
-        );
2501
-    }
2502
-
2503
-
2504
-    /**
2505
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2506
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2507
-     * save, and save and close buttons to work properly, then you will want to include a
2508
-     * values for the name and id arguments.
2509
-     *
2510
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2511
-     * @param int     $id                         id attached to the item published
2512
-     * @param string  $delete                     page route callback for the delete action
2513
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2514
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2515
-     *                                            the Save button
2516
-     * @throws EE_Error
2517
-     * @throws InvalidArgumentException
2518
-     * @throws InvalidDataTypeException
2519
-     * @throws InvalidInterfaceException
2520
-     * @todo  Add in validation for name/id arguments.
2521
-     */
2522
-    protected function _set_publish_post_box_vars(
2523
-        $name = '',
2524
-        $id = 0,
2525
-        $delete = '',
2526
-        $save_close_redirect_URL = '',
2527
-        $both_btns = true
2528
-    ) {
2529
-        // if Save & Close, use a custom redirect URL or default to the main page?
2530
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2531
-            ? $save_close_redirect_URL
2532
-            : $this->_admin_base_url;
2533
-        // create the Save & Close and Save buttons
2534
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2535
-        // if we have extra content set let's add it in if not make sure its empty
2536
-        $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2537
-        $delete_link = '';
2538
-        if ($delete && ! empty($id)) {
2539
-            // make sure we have a default if just true is sent.
2540
-            $delete           = ! empty($delete) ? $delete : 'delete';
2541
-            $delete_link      = $this->get_action_link_or_button(
2542
-                $delete,
2543
-                $delete,
2544
-                [$name => $id],
2545
-                'submitdelete deletion button button--outline button--caution'
2546
-            );
2547
-        }
2548
-        $this->_template_args['publish_delete_link'] = $delete_link;
2549
-        if (! empty($name) && ! empty($id)) {
2550
-            $hidden_field_arr[ $name ] = [
2551
-                'type'  => 'hidden',
2552
-                'value' => $id,
2553
-            ];
2554
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2555
-        } else {
2556
-            $hf = '';
2557
-        }
2558
-        // add hidden field
2559
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2560
-            ? $hf[ $name ]['field']
2561
-            : $hf;
2562
-    }
2563
-
2564
-
2565
-    /**
2566
-     * displays an error message to ppl who have javascript disabled
2567
-     *
2568
-     * @return void
2569
-     */
2570
-    private function _display_no_javascript_warning()
2571
-    {
2572
-        ?>
2384
+	}
2385
+
2386
+
2387
+	private function _espresso_links_post_box()
2388
+	{
2389
+		// Hiding until we actually have content to put in here...
2390
+		// $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2391
+	}
2392
+
2393
+
2394
+	public function espresso_links_post_box()
2395
+	{
2396
+		// Hiding until we actually have content to put in here...
2397
+		// EEH_Template::display_template(
2398
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2399
+		// );
2400
+	}
2401
+
2402
+
2403
+	protected function _espresso_sponsors_post_box()
2404
+	{
2405
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2406
+			$this->addMetaBox(
2407
+				'espresso_sponsors_post_box',
2408
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2409
+				[$this, 'espresso_sponsors_post_box'],
2410
+				$this->_wp_page_slug,
2411
+				'side'
2412
+			);
2413
+		}
2414
+	}
2415
+
2416
+
2417
+	public function espresso_sponsors_post_box()
2418
+	{
2419
+		EEH_Template::display_template(
2420
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2421
+		);
2422
+	}
2423
+
2424
+
2425
+	private function _publish_post_box()
2426
+	{
2427
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2428
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2429
+		// then we'll use that for the metabox label.
2430
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2431
+		if (! empty($this->_labels['publishbox'])) {
2432
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2433
+				: $this->_labels['publishbox'];
2434
+		} else {
2435
+			$box_label = esc_html__('Publish', 'event_espresso');
2436
+		}
2437
+		$box_label = apply_filters(
2438
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2439
+			$box_label,
2440
+			$this->_req_action,
2441
+			$this
2442
+		);
2443
+		$this->addMetaBox(
2444
+			$meta_box_ref,
2445
+			$box_label,
2446
+			[$this, 'editor_overview'],
2447
+			$this->_current_screen->id,
2448
+			'side',
2449
+			'high'
2450
+		);
2451
+	}
2452
+
2453
+
2454
+	public function editor_overview()
2455
+	{
2456
+		// if we have extra content set let's add it in if not make sure its empty
2457
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2458
+			? $this->_template_args['publish_box_extra_content']
2459
+			: '';
2460
+		echo EEH_Template::display_template(
2461
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2462
+			$this->_template_args,
2463
+			true
2464
+		);
2465
+	}
2466
+
2467
+
2468
+	/** end of globally available metaboxes section **/
2469
+
2470
+
2471
+	/**
2472
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2473
+	 * protected method.
2474
+	 *
2475
+	 * @param string $name
2476
+	 * @param int    $id
2477
+	 * @param bool   $delete
2478
+	 * @param string $save_close_redirect_URL
2479
+	 * @param bool   $both_btns
2480
+	 * @throws EE_Error
2481
+	 * @throws InvalidArgumentException
2482
+	 * @throws InvalidDataTypeException
2483
+	 * @throws InvalidInterfaceException
2484
+	 * @see   $this->_set_publish_post_box_vars for param details
2485
+	 * @since 4.6.0
2486
+	 */
2487
+	public function set_publish_post_box_vars(
2488
+		$name = '',
2489
+		$id = 0,
2490
+		$delete = false,
2491
+		$save_close_redirect_URL = '',
2492
+		$both_btns = true
2493
+	) {
2494
+		$this->_set_publish_post_box_vars(
2495
+			$name,
2496
+			$id,
2497
+			$delete,
2498
+			$save_close_redirect_URL,
2499
+			$both_btns
2500
+		);
2501
+	}
2502
+
2503
+
2504
+	/**
2505
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2506
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2507
+	 * save, and save and close buttons to work properly, then you will want to include a
2508
+	 * values for the name and id arguments.
2509
+	 *
2510
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2511
+	 * @param int     $id                         id attached to the item published
2512
+	 * @param string  $delete                     page route callback for the delete action
2513
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2514
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2515
+	 *                                            the Save button
2516
+	 * @throws EE_Error
2517
+	 * @throws InvalidArgumentException
2518
+	 * @throws InvalidDataTypeException
2519
+	 * @throws InvalidInterfaceException
2520
+	 * @todo  Add in validation for name/id arguments.
2521
+	 */
2522
+	protected function _set_publish_post_box_vars(
2523
+		$name = '',
2524
+		$id = 0,
2525
+		$delete = '',
2526
+		$save_close_redirect_URL = '',
2527
+		$both_btns = true
2528
+	) {
2529
+		// if Save & Close, use a custom redirect URL or default to the main page?
2530
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2531
+			? $save_close_redirect_URL
2532
+			: $this->_admin_base_url;
2533
+		// create the Save & Close and Save buttons
2534
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2535
+		// if we have extra content set let's add it in if not make sure its empty
2536
+		$this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2537
+		$delete_link = '';
2538
+		if ($delete && ! empty($id)) {
2539
+			// make sure we have a default if just true is sent.
2540
+			$delete           = ! empty($delete) ? $delete : 'delete';
2541
+			$delete_link      = $this->get_action_link_or_button(
2542
+				$delete,
2543
+				$delete,
2544
+				[$name => $id],
2545
+				'submitdelete deletion button button--outline button--caution'
2546
+			);
2547
+		}
2548
+		$this->_template_args['publish_delete_link'] = $delete_link;
2549
+		if (! empty($name) && ! empty($id)) {
2550
+			$hidden_field_arr[ $name ] = [
2551
+				'type'  => 'hidden',
2552
+				'value' => $id,
2553
+			];
2554
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2555
+		} else {
2556
+			$hf = '';
2557
+		}
2558
+		// add hidden field
2559
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2560
+			? $hf[ $name ]['field']
2561
+			: $hf;
2562
+	}
2563
+
2564
+
2565
+	/**
2566
+	 * displays an error message to ppl who have javascript disabled
2567
+	 *
2568
+	 * @return void
2569
+	 */
2570
+	private function _display_no_javascript_warning()
2571
+	{
2572
+		?>
2573 2573
         <noscript>
2574 2574
             <div id="no-js-message" class="error">
2575 2575
                 <p style="font-size:1.3em;">
2576 2576
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2577 2577
                     <?php esc_html_e(
2578
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2579
-                        'event_espresso'
2580
-                    ); ?>
2578
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2579
+						'event_espresso'
2580
+					); ?>
2581 2581
                 </p>
2582 2582
             </div>
2583 2583
         </noscript>
2584 2584
         <?php
2585
-    }
2586
-
2587
-
2588
-    /**
2589
-     * displays espresso success and/or error notices
2590
-     *
2591
-     * @return void
2592
-     */
2593
-    protected function _display_espresso_notices()
2594
-    {
2595
-        $notices = $this->_get_transient(true);
2596
-        echo stripslashes($notices);
2597
-    }
2598
-
2599
-
2600
-    /**
2601
-     * spinny things pacify the masses
2602
-     *
2603
-     * @return void
2604
-     */
2605
-    protected function _add_admin_page_ajax_loading_img()
2606
-    {
2607
-        ?>
2585
+	}
2586
+
2587
+
2588
+	/**
2589
+	 * displays espresso success and/or error notices
2590
+	 *
2591
+	 * @return void
2592
+	 */
2593
+	protected function _display_espresso_notices()
2594
+	{
2595
+		$notices = $this->_get_transient(true);
2596
+		echo stripslashes($notices);
2597
+	}
2598
+
2599
+
2600
+	/**
2601
+	 * spinny things pacify the masses
2602
+	 *
2603
+	 * @return void
2604
+	 */
2605
+	protected function _add_admin_page_ajax_loading_img()
2606
+	{
2607
+		?>
2608 2608
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2609 2609
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2610
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2610
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2611 2611
         </div>
2612 2612
         <?php
2613
-    }
2613
+	}
2614 2614
 
2615 2615
 
2616
-    /**
2617
-     * add admin page overlay for modal boxes
2618
-     *
2619
-     * @return void
2620
-     */
2621
-    protected function _add_admin_page_overlay()
2622
-    {
2623
-        ?>
2616
+	/**
2617
+	 * add admin page overlay for modal boxes
2618
+	 *
2619
+	 * @return void
2620
+	 */
2621
+	protected function _add_admin_page_overlay()
2622
+	{
2623
+		?>
2624 2624
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2625 2625
         <?php
2626
-    }
2627
-
2628
-
2629
-    /**
2630
-     * facade for $this->addMetaBox()
2631
-     *
2632
-     * @param string  $action        where the metabox gets displayed
2633
-     * @param string  $title         Title of Metabox (output in metabox header)
2634
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2635
-     *                               instead of the one created in here.
2636
-     * @param array   $callback_args an array of args supplied for the metabox
2637
-     * @param string  $column        what metabox column
2638
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2639
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2640
-     *                               created but just set our own callback for wp's add_meta_box.
2641
-     * @throws DomainException
2642
-     */
2643
-    public function _add_admin_page_meta_box(
2644
-        $action,
2645
-        $title,
2646
-        $callback,
2647
-        $callback_args,
2648
-        $column = 'normal',
2649
-        $priority = 'high',
2650
-        $create_func = true
2651
-    ) {
2652
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2653
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2654
-        if (empty($callback_args) && $create_func) {
2655
-            $callback_args = [
2656
-                'template_path' => $this->_template_path,
2657
-                'template_args' => $this->_template_args,
2658
-            ];
2659
-        }
2660
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2661
-        $call_back_func = $create_func
2662
-            ? static function ($post, $metabox) {
2663
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2664
-                echo EEH_Template::display_template(
2665
-                    $metabox['args']['template_path'],
2666
-                    $metabox['args']['template_args'],
2667
-                    true
2668
-                );
2669
-            }
2670
-            : $callback;
2671
-        $this->addMetaBox(
2672
-            str_replace('_', '-', $action) . '-mbox',
2673
-            $title,
2674
-            $call_back_func,
2675
-            $this->_wp_page_slug,
2676
-            $column,
2677
-            $priority,
2678
-            $callback_args
2679
-        );
2680
-    }
2681
-
2682
-
2683
-    /**
2684
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2685
-     *
2686
-     * @throws DomainException
2687
-     * @throws EE_Error
2688
-     * @throws InvalidArgumentException
2689
-     * @throws InvalidDataTypeException
2690
-     * @throws InvalidInterfaceException
2691
-     */
2692
-    public function display_admin_page_with_metabox_columns()
2693
-    {
2694
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2695
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2696
-            $this->_column_template_path,
2697
-            $this->_template_args,
2698
-            true
2699
-        );
2700
-        // the final wrapper
2701
-        $this->admin_page_wrapper();
2702
-    }
2703
-
2704
-
2705
-    /**
2706
-     * generates  HTML wrapper for an admin details page
2707
-     *
2708
-     * @return void
2709
-     * @throws DomainException
2710
-     * @throws EE_Error
2711
-     * @throws InvalidArgumentException
2712
-     * @throws InvalidDataTypeException
2713
-     * @throws InvalidInterfaceException
2714
-     */
2715
-    public function display_admin_page_with_sidebar()
2716
-    {
2717
-        $this->_display_admin_page(true);
2718
-    }
2719
-
2720
-
2721
-    /**
2722
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2723
-     *
2724
-     * @return void
2725
-     * @throws DomainException
2726
-     * @throws EE_Error
2727
-     * @throws InvalidArgumentException
2728
-     * @throws InvalidDataTypeException
2729
-     * @throws InvalidInterfaceException
2730
-     */
2731
-    public function display_admin_page_with_no_sidebar()
2732
-    {
2733
-        $this->_display_admin_page();
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2739
-     *
2740
-     * @return void
2741
-     * @throws DomainException
2742
-     * @throws EE_Error
2743
-     * @throws InvalidArgumentException
2744
-     * @throws InvalidDataTypeException
2745
-     * @throws InvalidInterfaceException
2746
-     */
2747
-    public function display_about_admin_page()
2748
-    {
2749
-        $this->_display_admin_page(false, true);
2750
-    }
2751
-
2752
-
2753
-    /**
2754
-     * display_admin_page
2755
-     * contains the code for actually displaying an admin page
2756
-     *
2757
-     * @param boolean $sidebar true with sidebar, false without
2758
-     * @param boolean $about   use the about admin wrapper instead of the default.
2759
-     * @return void
2760
-     * @throws DomainException
2761
-     * @throws EE_Error
2762
-     * @throws InvalidArgumentException
2763
-     * @throws InvalidDataTypeException
2764
-     * @throws InvalidInterfaceException
2765
-     */
2766
-    private function _display_admin_page($sidebar = false, $about = false)
2767
-    {
2768
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2769
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2770
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2771
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2772
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2773
-
2774
-        $post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2775
-
2776
-        $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2777
-                                                 && $this->_req_action !== 'data_reset'
2778
-                                                 && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2779
-                                                 && strpos($post_body_content, 'wp-list-table') === false;
2780
-
2781
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2782
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2783
-            ? 'poststuff'
2784
-            : 'espresso-default-admin';
2785
-        $this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2786
-            'event-espresso_page_espresso_',
2787
-            '',
2788
-            $this->_wp_page_slug
2789
-        ) . ' ' . $this->_req_action . '-route';
2790
-
2791
-        $template_path = $sidebar
2792
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2793
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2794
-        if ($this->request->isAjax()) {
2795
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2796
-        }
2797
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2798
-
2799
-        $this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2800
-        $this->_template_args['before_admin_page_content'] = $post_body_content;
2801
-        $this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2802
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2803
-            $template_path,
2804
-            $this->_template_args,
2805
-            true
2806
-        );
2807
-        // the final template wrapper
2808
-        $this->admin_page_wrapper($about);
2809
-    }
2810
-
2811
-
2812
-    /**
2813
-     * This is used to display caf preview pages.
2814
-     *
2815
-     * @param string $utm_campaign_source what is the key used for google analytics link
2816
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2817
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2818
-     * @return void
2819
-     * @throws DomainException
2820
-     * @throws EE_Error
2821
-     * @throws InvalidArgumentException
2822
-     * @throws InvalidDataTypeException
2823
-     * @throws InvalidInterfaceException
2824
-     * @since 4.3.2
2825
-     */
2826
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2827
-    {
2828
-        // let's generate a default preview action button if there isn't one already present.
2829
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2830
-            'Upgrade to Event Espresso 4 Right Now',
2831
-            'event_espresso'
2832
-        );
2833
-        $buy_now_url                                   = add_query_arg(
2834
-            [
2835
-                'ee_ver'       => 'ee4',
2836
-                'utm_source'   => 'ee4_plugin_admin',
2837
-                'utm_medium'   => 'link',
2838
-                'utm_campaign' => $utm_campaign_source,
2839
-                'utm_content'  => 'buy_now_button',
2840
-            ],
2841
-            'https://eventespresso.com/pricing/'
2842
-        );
2843
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2844
-            ? $this->get_action_link_or_button(
2845
-                '',
2846
-                'buy_now',
2847
-                [],
2848
-                'button button--primary button--big',
2849
-                esc_url_raw($buy_now_url),
2850
-                true
2851
-            )
2852
-            : $this->_template_args['preview_action_button'];
2853
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2854
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2855
-            $this->_template_args,
2856
-            true
2857
-        );
2858
-        $this->_display_admin_page($display_sidebar);
2859
-    }
2860
-
2861
-
2862
-    /**
2863
-     * display_admin_list_table_page_with_sidebar
2864
-     * generates HTML wrapper for an admin_page with list_table
2865
-     *
2866
-     * @return void
2867
-     * @throws DomainException
2868
-     * @throws EE_Error
2869
-     * @throws InvalidArgumentException
2870
-     * @throws InvalidDataTypeException
2871
-     * @throws InvalidInterfaceException
2872
-     */
2873
-    public function display_admin_list_table_page_with_sidebar()
2874
-    {
2875
-        $this->_display_admin_list_table_page(true);
2876
-    }
2877
-
2878
-
2879
-    /**
2880
-     * display_admin_list_table_page_with_no_sidebar
2881
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2882
-     *
2883
-     * @return void
2884
-     * @throws DomainException
2885
-     * @throws EE_Error
2886
-     * @throws InvalidArgumentException
2887
-     * @throws InvalidDataTypeException
2888
-     * @throws InvalidInterfaceException
2889
-     */
2890
-    public function display_admin_list_table_page_with_no_sidebar()
2891
-    {
2892
-        $this->_display_admin_list_table_page();
2893
-    }
2894
-
2895
-
2896
-    /**
2897
-     * generates html wrapper for an admin_list_table page
2898
-     *
2899
-     * @param boolean $sidebar whether to display with sidebar or not.
2900
-     * @return void
2901
-     * @throws DomainException
2902
-     * @throws EE_Error
2903
-     * @throws InvalidArgumentException
2904
-     * @throws InvalidDataTypeException
2905
-     * @throws InvalidInterfaceException
2906
-     */
2907
-    private function _display_admin_list_table_page($sidebar = false)
2908
-    {
2909
-        // setup search attributes
2910
-        $this->_set_search_attributes();
2911
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2912
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2913
-        $this->_template_args['table_url']        = $this->request->isAjax()
2914
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2915
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2916
-        $this->_template_args['list_table']       = $this->_list_table_object;
2917
-        $this->_template_args['current_route']    = $this->_req_action;
2918
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2919
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2920
-        if (! empty($ajax_sorting_callback)) {
2921
-            $sortable_list_table_form_fields = wp_nonce_field(
2922
-                $ajax_sorting_callback . '_nonce',
2923
-                $ajax_sorting_callback . '_nonce',
2924
-                false,
2925
-                false
2926
-            );
2927
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2928
-                                                . $this->page_slug
2929
-                                                . '" />';
2930
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2931
-                                                . $ajax_sorting_callback
2932
-                                                . '" />';
2933
-        } else {
2934
-            $sortable_list_table_form_fields = '';
2935
-        }
2936
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2937
-
2938
-        $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
2939
-
2940
-        $nonce_ref          = $this->_req_action . '_nonce';
2941
-        $hidden_form_fields .= '
2626
+	}
2627
+
2628
+
2629
+	/**
2630
+	 * facade for $this->addMetaBox()
2631
+	 *
2632
+	 * @param string  $action        where the metabox gets displayed
2633
+	 * @param string  $title         Title of Metabox (output in metabox header)
2634
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2635
+	 *                               instead of the one created in here.
2636
+	 * @param array   $callback_args an array of args supplied for the metabox
2637
+	 * @param string  $column        what metabox column
2638
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2639
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2640
+	 *                               created but just set our own callback for wp's add_meta_box.
2641
+	 * @throws DomainException
2642
+	 */
2643
+	public function _add_admin_page_meta_box(
2644
+		$action,
2645
+		$title,
2646
+		$callback,
2647
+		$callback_args,
2648
+		$column = 'normal',
2649
+		$priority = 'high',
2650
+		$create_func = true
2651
+	) {
2652
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2653
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2654
+		if (empty($callback_args) && $create_func) {
2655
+			$callback_args = [
2656
+				'template_path' => $this->_template_path,
2657
+				'template_args' => $this->_template_args,
2658
+			];
2659
+		}
2660
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2661
+		$call_back_func = $create_func
2662
+			? static function ($post, $metabox) {
2663
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2664
+				echo EEH_Template::display_template(
2665
+					$metabox['args']['template_path'],
2666
+					$metabox['args']['template_args'],
2667
+					true
2668
+				);
2669
+			}
2670
+			: $callback;
2671
+		$this->addMetaBox(
2672
+			str_replace('_', '-', $action) . '-mbox',
2673
+			$title,
2674
+			$call_back_func,
2675
+			$this->_wp_page_slug,
2676
+			$column,
2677
+			$priority,
2678
+			$callback_args
2679
+		);
2680
+	}
2681
+
2682
+
2683
+	/**
2684
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2685
+	 *
2686
+	 * @throws DomainException
2687
+	 * @throws EE_Error
2688
+	 * @throws InvalidArgumentException
2689
+	 * @throws InvalidDataTypeException
2690
+	 * @throws InvalidInterfaceException
2691
+	 */
2692
+	public function display_admin_page_with_metabox_columns()
2693
+	{
2694
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2695
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2696
+			$this->_column_template_path,
2697
+			$this->_template_args,
2698
+			true
2699
+		);
2700
+		// the final wrapper
2701
+		$this->admin_page_wrapper();
2702
+	}
2703
+
2704
+
2705
+	/**
2706
+	 * generates  HTML wrapper for an admin details page
2707
+	 *
2708
+	 * @return void
2709
+	 * @throws DomainException
2710
+	 * @throws EE_Error
2711
+	 * @throws InvalidArgumentException
2712
+	 * @throws InvalidDataTypeException
2713
+	 * @throws InvalidInterfaceException
2714
+	 */
2715
+	public function display_admin_page_with_sidebar()
2716
+	{
2717
+		$this->_display_admin_page(true);
2718
+	}
2719
+
2720
+
2721
+	/**
2722
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2723
+	 *
2724
+	 * @return void
2725
+	 * @throws DomainException
2726
+	 * @throws EE_Error
2727
+	 * @throws InvalidArgumentException
2728
+	 * @throws InvalidDataTypeException
2729
+	 * @throws InvalidInterfaceException
2730
+	 */
2731
+	public function display_admin_page_with_no_sidebar()
2732
+	{
2733
+		$this->_display_admin_page();
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2739
+	 *
2740
+	 * @return void
2741
+	 * @throws DomainException
2742
+	 * @throws EE_Error
2743
+	 * @throws InvalidArgumentException
2744
+	 * @throws InvalidDataTypeException
2745
+	 * @throws InvalidInterfaceException
2746
+	 */
2747
+	public function display_about_admin_page()
2748
+	{
2749
+		$this->_display_admin_page(false, true);
2750
+	}
2751
+
2752
+
2753
+	/**
2754
+	 * display_admin_page
2755
+	 * contains the code for actually displaying an admin page
2756
+	 *
2757
+	 * @param boolean $sidebar true with sidebar, false without
2758
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2759
+	 * @return void
2760
+	 * @throws DomainException
2761
+	 * @throws EE_Error
2762
+	 * @throws InvalidArgumentException
2763
+	 * @throws InvalidDataTypeException
2764
+	 * @throws InvalidInterfaceException
2765
+	 */
2766
+	private function _display_admin_page($sidebar = false, $about = false)
2767
+	{
2768
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2769
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2770
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2771
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2772
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2773
+
2774
+		$post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2775
+
2776
+		$this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2777
+												 && $this->_req_action !== 'data_reset'
2778
+												 && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2779
+												 && strpos($post_body_content, 'wp-list-table') === false;
2780
+
2781
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2782
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2783
+			? 'poststuff'
2784
+			: 'espresso-default-admin';
2785
+		$this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2786
+			'event-espresso_page_espresso_',
2787
+			'',
2788
+			$this->_wp_page_slug
2789
+		) . ' ' . $this->_req_action . '-route';
2790
+
2791
+		$template_path = $sidebar
2792
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2793
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2794
+		if ($this->request->isAjax()) {
2795
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2796
+		}
2797
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2798
+
2799
+		$this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2800
+		$this->_template_args['before_admin_page_content'] = $post_body_content;
2801
+		$this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2802
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2803
+			$template_path,
2804
+			$this->_template_args,
2805
+			true
2806
+		);
2807
+		// the final template wrapper
2808
+		$this->admin_page_wrapper($about);
2809
+	}
2810
+
2811
+
2812
+	/**
2813
+	 * This is used to display caf preview pages.
2814
+	 *
2815
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2816
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2817
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2818
+	 * @return void
2819
+	 * @throws DomainException
2820
+	 * @throws EE_Error
2821
+	 * @throws InvalidArgumentException
2822
+	 * @throws InvalidDataTypeException
2823
+	 * @throws InvalidInterfaceException
2824
+	 * @since 4.3.2
2825
+	 */
2826
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2827
+	{
2828
+		// let's generate a default preview action button if there isn't one already present.
2829
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2830
+			'Upgrade to Event Espresso 4 Right Now',
2831
+			'event_espresso'
2832
+		);
2833
+		$buy_now_url                                   = add_query_arg(
2834
+			[
2835
+				'ee_ver'       => 'ee4',
2836
+				'utm_source'   => 'ee4_plugin_admin',
2837
+				'utm_medium'   => 'link',
2838
+				'utm_campaign' => $utm_campaign_source,
2839
+				'utm_content'  => 'buy_now_button',
2840
+			],
2841
+			'https://eventespresso.com/pricing/'
2842
+		);
2843
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2844
+			? $this->get_action_link_or_button(
2845
+				'',
2846
+				'buy_now',
2847
+				[],
2848
+				'button button--primary button--big',
2849
+				esc_url_raw($buy_now_url),
2850
+				true
2851
+			)
2852
+			: $this->_template_args['preview_action_button'];
2853
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2854
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2855
+			$this->_template_args,
2856
+			true
2857
+		);
2858
+		$this->_display_admin_page($display_sidebar);
2859
+	}
2860
+
2861
+
2862
+	/**
2863
+	 * display_admin_list_table_page_with_sidebar
2864
+	 * generates HTML wrapper for an admin_page with list_table
2865
+	 *
2866
+	 * @return void
2867
+	 * @throws DomainException
2868
+	 * @throws EE_Error
2869
+	 * @throws InvalidArgumentException
2870
+	 * @throws InvalidDataTypeException
2871
+	 * @throws InvalidInterfaceException
2872
+	 */
2873
+	public function display_admin_list_table_page_with_sidebar()
2874
+	{
2875
+		$this->_display_admin_list_table_page(true);
2876
+	}
2877
+
2878
+
2879
+	/**
2880
+	 * display_admin_list_table_page_with_no_sidebar
2881
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2882
+	 *
2883
+	 * @return void
2884
+	 * @throws DomainException
2885
+	 * @throws EE_Error
2886
+	 * @throws InvalidArgumentException
2887
+	 * @throws InvalidDataTypeException
2888
+	 * @throws InvalidInterfaceException
2889
+	 */
2890
+	public function display_admin_list_table_page_with_no_sidebar()
2891
+	{
2892
+		$this->_display_admin_list_table_page();
2893
+	}
2894
+
2895
+
2896
+	/**
2897
+	 * generates html wrapper for an admin_list_table page
2898
+	 *
2899
+	 * @param boolean $sidebar whether to display with sidebar or not.
2900
+	 * @return void
2901
+	 * @throws DomainException
2902
+	 * @throws EE_Error
2903
+	 * @throws InvalidArgumentException
2904
+	 * @throws InvalidDataTypeException
2905
+	 * @throws InvalidInterfaceException
2906
+	 */
2907
+	private function _display_admin_list_table_page($sidebar = false)
2908
+	{
2909
+		// setup search attributes
2910
+		$this->_set_search_attributes();
2911
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2912
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2913
+		$this->_template_args['table_url']        = $this->request->isAjax()
2914
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2915
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2916
+		$this->_template_args['list_table']       = $this->_list_table_object;
2917
+		$this->_template_args['current_route']    = $this->_req_action;
2918
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2919
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2920
+		if (! empty($ajax_sorting_callback)) {
2921
+			$sortable_list_table_form_fields = wp_nonce_field(
2922
+				$ajax_sorting_callback . '_nonce',
2923
+				$ajax_sorting_callback . '_nonce',
2924
+				false,
2925
+				false
2926
+			);
2927
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2928
+												. $this->page_slug
2929
+												. '" />';
2930
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2931
+												. $ajax_sorting_callback
2932
+												. '" />';
2933
+		} else {
2934
+			$sortable_list_table_form_fields = '';
2935
+		}
2936
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2937
+
2938
+		$hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
2939
+
2940
+		$nonce_ref          = $this->_req_action . '_nonce';
2941
+		$hidden_form_fields .= '
2942 2942
             <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2943 2943
 
2944
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2945
-        // display message about search results?
2946
-        $search = $this->request->getRequestParam('s');
2947
-        $this->_template_args['before_list_table'] .= ! empty($search)
2948
-            ? '<p class="ee-search-results">' . sprintf(
2949
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2950
-                trim($search, '%')
2951
-            ) . '</p>'
2952
-            : '';
2953
-        // filter before_list_table template arg
2954
-        $this->_template_args['before_list_table'] = apply_filters(
2955
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2956
-            $this->_template_args['before_list_table'],
2957
-            $this->page_slug,
2958
-            $this->request->requestParams(),
2959
-            $this->_req_action
2960
-        );
2961
-        // convert to array and filter again
2962
-        // arrays are easier to inject new items in a specific location,
2963
-        // but would not be backwards compatible, so we have to add a new filter
2964
-        $this->_template_args['before_list_table'] = implode(
2965
-            " \n",
2966
-            (array) apply_filters(
2967
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2968
-                (array) $this->_template_args['before_list_table'],
2969
-                $this->page_slug,
2970
-                $this->request->requestParams(),
2971
-                $this->_req_action
2972
-            )
2973
-        );
2974
-        // filter after_list_table template arg
2975
-        $this->_template_args['after_list_table'] = apply_filters(
2976
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2977
-            $this->_template_args['after_list_table'],
2978
-            $this->page_slug,
2979
-            $this->request->requestParams(),
2980
-            $this->_req_action
2981
-        );
2982
-        // convert to array and filter again
2983
-        // arrays are easier to inject new items in a specific location,
2984
-        // but would not be backwards compatible, so we have to add a new filter
2985
-        $this->_template_args['after_list_table']   = implode(
2986
-            " \n",
2987
-            (array) apply_filters(
2988
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2989
-                (array) $this->_template_args['after_list_table'],
2990
-                $this->page_slug,
2991
-                $this->request->requestParams(),
2992
-                $this->_req_action
2993
-            )
2994
-        );
2995
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2996
-            $template_path,
2997
-            $this->_template_args,
2998
-            true
2999
-        );
3000
-        // the final template wrapper
3001
-        if ($sidebar) {
3002
-            $this->display_admin_page_with_sidebar();
3003
-        } else {
3004
-            $this->display_admin_page_with_no_sidebar();
3005
-        }
3006
-    }
3007
-
3008
-
3009
-    /**
3010
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3011
-     * html string for the legend.
3012
-     * $items are expected in an array in the following format:
3013
-     * $legend_items = array(
3014
-     *        'item_id' => array(
3015
-     *            'icon' => 'http://url_to_icon_being_described.png',
3016
-     *            'desc' => esc_html__('localized description of item');
3017
-     *        )
3018
-     * );
3019
-     *
3020
-     * @param array $items see above for format of array
3021
-     * @return string html string of legend
3022
-     * @throws DomainException
3023
-     */
3024
-    protected function _display_legend($items)
3025
-    {
3026
-        $this->_template_args['items'] = apply_filters(
3027
-            'FHEE__EE_Admin_Page___display_legend__items',
3028
-            (array) $items,
3029
-            $this
3030
-        );
3031
-        /** @var StatusChangeNotice $status_change_notice */
3032
-        $status_change_notice = $this->loader->getShared(
3033
-            'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3034
-        );
3035
-        $this->_template_args['status_change_notice'] = $status_change_notice->display(
3036
-            '__admin-legend',
3037
-            $this->page_slug
3038
-        );
3039
-        return EEH_Template::display_template(
3040
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3041
-            $this->_template_args,
3042
-            true
3043
-        );
3044
-    }
3045
-
3046
-
3047
-    /**
3048
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3049
-     * The returned json object is created from an array in the following format:
3050
-     * array(
3051
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3052
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3053
-     *  'notices' => '', // - contains any EE_Error formatted notices
3054
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3055
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3056
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3057
-     *  that might be included in here)
3058
-     * )
3059
-     * The json object is populated by whatever is set in the $_template_args property.
3060
-     *
3061
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3062
-     *                                 instead of displayed.
3063
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3064
-     * @return void
3065
-     * @throws EE_Error
3066
-     * @throws InvalidArgumentException
3067
-     * @throws InvalidDataTypeException
3068
-     * @throws InvalidInterfaceException
3069
-     */
3070
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
3071
-    {
3072
-        // make sure any EE_Error notices have been handled.
3073
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3074
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3075
-        unset($this->_template_args['data']);
3076
-        $json = [
3077
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3078
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3079
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3080
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3081
-            'notices'   => EE_Error::get_notices(),
3082
-            'content'   => isset($this->_template_args['admin_page_content'])
3083
-                ? $this->_template_args['admin_page_content'] : '',
3084
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3085
-            'isEEajax'  => true
3086
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3087
-        ];
3088
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3089
-        if (null === error_get_last() || ! headers_sent()) {
3090
-            header('Content-Type: application/json; charset=UTF-8');
3091
-        }
3092
-        echo wp_json_encode($json);
3093
-        exit();
3094
-    }
3095
-
3096
-
3097
-    /**
3098
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3099
-     *
3100
-     * @return void
3101
-     * @throws EE_Error
3102
-     * @throws InvalidArgumentException
3103
-     * @throws InvalidDataTypeException
3104
-     * @throws InvalidInterfaceException
3105
-     */
3106
-    public function return_json()
3107
-    {
3108
-        if ($this->request->isAjax()) {
3109
-            $this->_return_json();
3110
-        } else {
3111
-            throw new EE_Error(
3112
-                sprintf(
3113
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3114
-                    __FUNCTION__
3115
-                )
3116
-            );
3117
-        }
3118
-    }
3119
-
3120
-
3121
-    /**
3122
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3123
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3124
-     *
3125
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3126
-     */
3127
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3128
-    {
3129
-        $this->_hook_obj = $hook_obj;
3130
-    }
3131
-
3132
-
3133
-    /**
3134
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3135
-     *
3136
-     * @param boolean $about whether to use the special about page wrapper or default.
3137
-     * @return void
3138
-     * @throws DomainException
3139
-     * @throws EE_Error
3140
-     * @throws InvalidArgumentException
3141
-     * @throws InvalidDataTypeException
3142
-     * @throws InvalidInterfaceException
3143
-     */
3144
-    public function admin_page_wrapper($about = false)
3145
-    {
3146
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3147
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3148
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3149
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3150
-
3151
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3152
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3153
-            $this->_template_args['before_admin_page_content'] ?? ''
3154
-        );
3155
-
3156
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3157
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3158
-            $this->_template_args['after_admin_page_content'] ?? ''
3159
-        );
3160
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3161
-
3162
-        if ($this->request->isAjax()) {
3163
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3164
-                // $template_path,
3165
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3166
-                $this->_template_args,
3167
-                true
3168
-            );
3169
-            $this->_return_json();
3170
-        }
3171
-        // load settings page wrapper template
3172
-        $template_path = $about
3173
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3174
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3175
-
3176
-        EEH_Template::display_template($template_path, $this->_template_args);
3177
-    }
3178
-
3179
-
3180
-    /**
3181
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3182
-     *
3183
-     * @return string html
3184
-     * @throws EE_Error
3185
-     */
3186
-    protected function _get_main_nav_tabs()
3187
-    {
3188
-        // let's generate the html using the EEH_Tabbed_Content helper.
3189
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3190
-        // (rather than setting in the page_routes array)
3191
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3192
-    }
3193
-
3194
-
3195
-    /**
3196
-     *        sort nav tabs
3197
-     *
3198
-     * @param $a
3199
-     * @param $b
3200
-     * @return int
3201
-     */
3202
-    private function _sort_nav_tabs($a, $b)
3203
-    {
3204
-        if ($a['order'] === $b['order']) {
3205
-            return 0;
3206
-        }
3207
-        return ($a['order'] < $b['order']) ? -1 : 1;
3208
-    }
3209
-
3210
-
3211
-    /**
3212
-     * generates HTML for the forms used on admin pages
3213
-     *
3214
-     * @param array  $input_vars - array of input field details
3215
-     * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3216
-     * @param bool   $id
3217
-     * @return array|string
3218
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3219
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3220
-     */
3221
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3222
-    {
3223
-        return $generator === 'string'
3224
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3225
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3226
-    }
3227
-
3228
-
3229
-    /**
3230
-     * generates the "Save" and "Save & Close" buttons for edit forms
3231
-     *
3232
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3233
-     *                                   Close" button.
3234
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3235
-     *                                   'Save', [1] => 'save & close')
3236
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3237
-     *                                   via the "name" value in the button).  We can also use this to just dump
3238
-     *                                   default actions by submitting some other value.
3239
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3240
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3241
-     *                                   close (normal form handling).
3242
-     */
3243
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3244
-    {
3245
-        // make sure $text and $actions are in an array
3246
-        $text          = (array) $text;
3247
-        $actions       = (array) $actions;
3248
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3249
-        $button_text   = ! empty($text)
3250
-            ? $text
3251
-            : [
3252
-                esc_html__('Save', 'event_espresso'),
3253
-                esc_html__('Save and Close', 'event_espresso'),
3254
-            ];
3255
-        $default_names = ['save', 'save_and_close'];
3256
-        $buttons = '';
3257
-        foreach ($button_text as $key => $button) {
3258
-            $ref     = $default_names[ $key ];
3259
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3260
-            $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3261
-                        . 'value="' . $button . '" name="' . $name . '" '
3262
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3263
-            if (! $both) {
3264
-                break;
3265
-            }
3266
-        }
3267
-        // add in a hidden index for the current page (so save and close redirects properly)
3268
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3269
-                   . $referrer_url
3270
-                   . '" />';
3271
-        $this->_template_args['save_buttons'] = $buttons;
3272
-    }
3273
-
3274
-
3275
-    /**
3276
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3277
-     *
3278
-     * @param string $route
3279
-     * @param array  $additional_hidden_fields
3280
-     * @see   $this->_set_add_edit_form_tags() for details on params
3281
-     * @since 4.6.0
3282
-     */
3283
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3284
-    {
3285
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3286
-    }
3287
-
3288
-
3289
-    /**
3290
-     * set form open and close tags on add/edit pages.
3291
-     *
3292
-     * @param string $route                    the route you want the form to direct to
3293
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3294
-     * @return void
3295
-     */
3296
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3297
-    {
3298
-        if (empty($route)) {
3299
-            $user_msg = esc_html__(
3300
-                'An error occurred. No action was set for this page\'s form.',
3301
-                'event_espresso'
3302
-            );
3303
-            $dev_msg  = $user_msg . "\n"
3304
-                        . sprintf(
3305
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3306
-                            __FUNCTION__,
3307
-                            __CLASS__
3308
-                        );
3309
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3310
-        }
3311
-        // open form
3312
-        $action = $this->_admin_base_url;
3313
-        $this->_template_args['before_admin_page_content'] = "
2944
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2945
+		// display message about search results?
2946
+		$search = $this->request->getRequestParam('s');
2947
+		$this->_template_args['before_list_table'] .= ! empty($search)
2948
+			? '<p class="ee-search-results">' . sprintf(
2949
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2950
+				trim($search, '%')
2951
+			) . '</p>'
2952
+			: '';
2953
+		// filter before_list_table template arg
2954
+		$this->_template_args['before_list_table'] = apply_filters(
2955
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2956
+			$this->_template_args['before_list_table'],
2957
+			$this->page_slug,
2958
+			$this->request->requestParams(),
2959
+			$this->_req_action
2960
+		);
2961
+		// convert to array and filter again
2962
+		// arrays are easier to inject new items in a specific location,
2963
+		// but would not be backwards compatible, so we have to add a new filter
2964
+		$this->_template_args['before_list_table'] = implode(
2965
+			" \n",
2966
+			(array) apply_filters(
2967
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2968
+				(array) $this->_template_args['before_list_table'],
2969
+				$this->page_slug,
2970
+				$this->request->requestParams(),
2971
+				$this->_req_action
2972
+			)
2973
+		);
2974
+		// filter after_list_table template arg
2975
+		$this->_template_args['after_list_table'] = apply_filters(
2976
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2977
+			$this->_template_args['after_list_table'],
2978
+			$this->page_slug,
2979
+			$this->request->requestParams(),
2980
+			$this->_req_action
2981
+		);
2982
+		// convert to array and filter again
2983
+		// arrays are easier to inject new items in a specific location,
2984
+		// but would not be backwards compatible, so we have to add a new filter
2985
+		$this->_template_args['after_list_table']   = implode(
2986
+			" \n",
2987
+			(array) apply_filters(
2988
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2989
+				(array) $this->_template_args['after_list_table'],
2990
+				$this->page_slug,
2991
+				$this->request->requestParams(),
2992
+				$this->_req_action
2993
+			)
2994
+		);
2995
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2996
+			$template_path,
2997
+			$this->_template_args,
2998
+			true
2999
+		);
3000
+		// the final template wrapper
3001
+		if ($sidebar) {
3002
+			$this->display_admin_page_with_sidebar();
3003
+		} else {
3004
+			$this->display_admin_page_with_no_sidebar();
3005
+		}
3006
+	}
3007
+
3008
+
3009
+	/**
3010
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3011
+	 * html string for the legend.
3012
+	 * $items are expected in an array in the following format:
3013
+	 * $legend_items = array(
3014
+	 *        'item_id' => array(
3015
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3016
+	 *            'desc' => esc_html__('localized description of item');
3017
+	 *        )
3018
+	 * );
3019
+	 *
3020
+	 * @param array $items see above for format of array
3021
+	 * @return string html string of legend
3022
+	 * @throws DomainException
3023
+	 */
3024
+	protected function _display_legend($items)
3025
+	{
3026
+		$this->_template_args['items'] = apply_filters(
3027
+			'FHEE__EE_Admin_Page___display_legend__items',
3028
+			(array) $items,
3029
+			$this
3030
+		);
3031
+		/** @var StatusChangeNotice $status_change_notice */
3032
+		$status_change_notice = $this->loader->getShared(
3033
+			'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3034
+		);
3035
+		$this->_template_args['status_change_notice'] = $status_change_notice->display(
3036
+			'__admin-legend',
3037
+			$this->page_slug
3038
+		);
3039
+		return EEH_Template::display_template(
3040
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3041
+			$this->_template_args,
3042
+			true
3043
+		);
3044
+	}
3045
+
3046
+
3047
+	/**
3048
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3049
+	 * The returned json object is created from an array in the following format:
3050
+	 * array(
3051
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3052
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3053
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3054
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3055
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3056
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3057
+	 *  that might be included in here)
3058
+	 * )
3059
+	 * The json object is populated by whatever is set in the $_template_args property.
3060
+	 *
3061
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3062
+	 *                                 instead of displayed.
3063
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3064
+	 * @return void
3065
+	 * @throws EE_Error
3066
+	 * @throws InvalidArgumentException
3067
+	 * @throws InvalidDataTypeException
3068
+	 * @throws InvalidInterfaceException
3069
+	 */
3070
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
3071
+	{
3072
+		// make sure any EE_Error notices have been handled.
3073
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3074
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3075
+		unset($this->_template_args['data']);
3076
+		$json = [
3077
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3078
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3079
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3080
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3081
+			'notices'   => EE_Error::get_notices(),
3082
+			'content'   => isset($this->_template_args['admin_page_content'])
3083
+				? $this->_template_args['admin_page_content'] : '',
3084
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3085
+			'isEEajax'  => true
3086
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3087
+		];
3088
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3089
+		if (null === error_get_last() || ! headers_sent()) {
3090
+			header('Content-Type: application/json; charset=UTF-8');
3091
+		}
3092
+		echo wp_json_encode($json);
3093
+		exit();
3094
+	}
3095
+
3096
+
3097
+	/**
3098
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3099
+	 *
3100
+	 * @return void
3101
+	 * @throws EE_Error
3102
+	 * @throws InvalidArgumentException
3103
+	 * @throws InvalidDataTypeException
3104
+	 * @throws InvalidInterfaceException
3105
+	 */
3106
+	public function return_json()
3107
+	{
3108
+		if ($this->request->isAjax()) {
3109
+			$this->_return_json();
3110
+		} else {
3111
+			throw new EE_Error(
3112
+				sprintf(
3113
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3114
+					__FUNCTION__
3115
+				)
3116
+			);
3117
+		}
3118
+	}
3119
+
3120
+
3121
+	/**
3122
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3123
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3124
+	 *
3125
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3126
+	 */
3127
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3128
+	{
3129
+		$this->_hook_obj = $hook_obj;
3130
+	}
3131
+
3132
+
3133
+	/**
3134
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3135
+	 *
3136
+	 * @param boolean $about whether to use the special about page wrapper or default.
3137
+	 * @return void
3138
+	 * @throws DomainException
3139
+	 * @throws EE_Error
3140
+	 * @throws InvalidArgumentException
3141
+	 * @throws InvalidDataTypeException
3142
+	 * @throws InvalidInterfaceException
3143
+	 */
3144
+	public function admin_page_wrapper($about = false)
3145
+	{
3146
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3147
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3148
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3149
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3150
+
3151
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3152
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3153
+			$this->_template_args['before_admin_page_content'] ?? ''
3154
+		);
3155
+
3156
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3157
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3158
+			$this->_template_args['after_admin_page_content'] ?? ''
3159
+		);
3160
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3161
+
3162
+		if ($this->request->isAjax()) {
3163
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3164
+				// $template_path,
3165
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3166
+				$this->_template_args,
3167
+				true
3168
+			);
3169
+			$this->_return_json();
3170
+		}
3171
+		// load settings page wrapper template
3172
+		$template_path = $about
3173
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3174
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3175
+
3176
+		EEH_Template::display_template($template_path, $this->_template_args);
3177
+	}
3178
+
3179
+
3180
+	/**
3181
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3182
+	 *
3183
+	 * @return string html
3184
+	 * @throws EE_Error
3185
+	 */
3186
+	protected function _get_main_nav_tabs()
3187
+	{
3188
+		// let's generate the html using the EEH_Tabbed_Content helper.
3189
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3190
+		// (rather than setting in the page_routes array)
3191
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3192
+	}
3193
+
3194
+
3195
+	/**
3196
+	 *        sort nav tabs
3197
+	 *
3198
+	 * @param $a
3199
+	 * @param $b
3200
+	 * @return int
3201
+	 */
3202
+	private function _sort_nav_tabs($a, $b)
3203
+	{
3204
+		if ($a['order'] === $b['order']) {
3205
+			return 0;
3206
+		}
3207
+		return ($a['order'] < $b['order']) ? -1 : 1;
3208
+	}
3209
+
3210
+
3211
+	/**
3212
+	 * generates HTML for the forms used on admin pages
3213
+	 *
3214
+	 * @param array  $input_vars - array of input field details
3215
+	 * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3216
+	 * @param bool   $id
3217
+	 * @return array|string
3218
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3219
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3220
+	 */
3221
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3222
+	{
3223
+		return $generator === 'string'
3224
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3225
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3226
+	}
3227
+
3228
+
3229
+	/**
3230
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3231
+	 *
3232
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3233
+	 *                                   Close" button.
3234
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3235
+	 *                                   'Save', [1] => 'save & close')
3236
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3237
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3238
+	 *                                   default actions by submitting some other value.
3239
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3240
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3241
+	 *                                   close (normal form handling).
3242
+	 */
3243
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3244
+	{
3245
+		// make sure $text and $actions are in an array
3246
+		$text          = (array) $text;
3247
+		$actions       = (array) $actions;
3248
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3249
+		$button_text   = ! empty($text)
3250
+			? $text
3251
+			: [
3252
+				esc_html__('Save', 'event_espresso'),
3253
+				esc_html__('Save and Close', 'event_espresso'),
3254
+			];
3255
+		$default_names = ['save', 'save_and_close'];
3256
+		$buttons = '';
3257
+		foreach ($button_text as $key => $button) {
3258
+			$ref     = $default_names[ $key ];
3259
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3260
+			$buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3261
+						. 'value="' . $button . '" name="' . $name . '" '
3262
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3263
+			if (! $both) {
3264
+				break;
3265
+			}
3266
+		}
3267
+		// add in a hidden index for the current page (so save and close redirects properly)
3268
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3269
+				   . $referrer_url
3270
+				   . '" />';
3271
+		$this->_template_args['save_buttons'] = $buttons;
3272
+	}
3273
+
3274
+
3275
+	/**
3276
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3277
+	 *
3278
+	 * @param string $route
3279
+	 * @param array  $additional_hidden_fields
3280
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3281
+	 * @since 4.6.0
3282
+	 */
3283
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3284
+	{
3285
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3286
+	}
3287
+
3288
+
3289
+	/**
3290
+	 * set form open and close tags on add/edit pages.
3291
+	 *
3292
+	 * @param string $route                    the route you want the form to direct to
3293
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3294
+	 * @return void
3295
+	 */
3296
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3297
+	{
3298
+		if (empty($route)) {
3299
+			$user_msg = esc_html__(
3300
+				'An error occurred. No action was set for this page\'s form.',
3301
+				'event_espresso'
3302
+			);
3303
+			$dev_msg  = $user_msg . "\n"
3304
+						. sprintf(
3305
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3306
+							__FUNCTION__,
3307
+							__CLASS__
3308
+						);
3309
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3310
+		}
3311
+		// open form
3312
+		$action = $this->_admin_base_url;
3313
+		$this->_template_args['before_admin_page_content'] = "
3314 3314
             <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' >
3315 3315
             ";
3316
-        // add nonce
3317
-        $nonce                                             =
3318
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3319
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3320
-        // add REQUIRED form action
3321
-        $hidden_fields = [
3322
-            'action' => ['type' => 'hidden', 'value' => $route],
3323
-        ];
3324
-        // merge arrays
3325
-        $hidden_fields = is_array($additional_hidden_fields)
3326
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3327
-            : $hidden_fields;
3328
-        // generate form fields
3329
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3330
-        // add fields to form
3331
-        foreach ((array) $form_fields as $form_field) {
3332
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3333
-        }
3334
-        // close form
3335
-        $this->_template_args['after_admin_page_content'] = '</form>';
3336
-    }
3337
-
3338
-
3339
-    /**
3340
-     * Public Wrapper for _redirect_after_action() method since its
3341
-     * discovered it would be useful for external code to have access.
3342
-     *
3343
-     * @param bool   $success
3344
-     * @param string $what
3345
-     * @param string $action_desc
3346
-     * @param array  $query_args
3347
-     * @param bool   $override_overwrite
3348
-     * @throws EE_Error
3349
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3350
-     * @since 4.5.0
3351
-     */
3352
-    public function redirect_after_action(
3353
-        $success = false,
3354
-        $what = 'item',
3355
-        $action_desc = 'processed',
3356
-        $query_args = [],
3357
-        $override_overwrite = false
3358
-    ) {
3359
-        $this->_redirect_after_action(
3360
-            $success,
3361
-            $what,
3362
-            $action_desc,
3363
-            $query_args,
3364
-            $override_overwrite
3365
-        );
3366
-    }
3367
-
3368
-
3369
-    /**
3370
-     * Helper method for merging existing request data with the returned redirect url.
3371
-     *
3372
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3373
-     * filters are still applied.
3374
-     *
3375
-     * @param array $new_route_data
3376
-     * @return array
3377
-     */
3378
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3379
-    {
3380
-        foreach ($this->request->requestParams() as $ref => $value) {
3381
-            // unset nonces
3382
-            if (strpos($ref, 'nonce') !== false) {
3383
-                $this->request->unSetRequestParam($ref);
3384
-                continue;
3385
-            }
3386
-            // urlencode values.
3387
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3388
-            $this->request->setRequestParam($ref, $value);
3389
-        }
3390
-        return array_merge($this->request->requestParams(), $new_route_data);
3391
-    }
3392
-
3393
-
3394
-    /**
3395
-     * @param int|float|string $success      - whether success was for two or more records, or just one, or none
3396
-     * @param string           $what         - what the action was performed on
3397
-     * @param string           $action_desc  - what was done ie: updated, deleted, etc
3398
-     * @param array $query_args              - an array of query_args to be added to the URL to redirect to
3399
-     * @param BOOL $override_overwrite       - by default all EE_Error::success messages are overwritten,
3400
-     *                                         this allows you to override this so that they show.
3401
-     * @return void
3402
-     * @throws EE_Error
3403
-     * @throws InvalidArgumentException
3404
-     * @throws InvalidDataTypeException
3405
-     * @throws InvalidInterfaceException
3406
-     */
3407
-    protected function _redirect_after_action(
3408
-        $success = 0,
3409
-        string $what = 'item',
3410
-        string $action_desc = 'processed',
3411
-        array $query_args = [],
3412
-        bool $override_overwrite = false
3413
-    ) {
3414
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3415
-        $notices      = EE_Error::get_notices(false);
3416
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3417
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3418
-            EE_Error::overwrite_success();
3419
-        }
3420
-        if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3421
-            // how many records affected ? more than one record ? or just one ?
3422
-            EE_Error::add_success(
3423
-                sprintf(
3424
-                    esc_html(
3425
-                        _n(
3426
-                            'The "%1$s" has been successfully %2$s.',
3427
-                            'The "%1$s" have been successfully %2$s.',
3428
-                            $success,
3429
-                            'event_espresso'
3430
-                        )
3431
-                    ),
3432
-                    $what,
3433
-                    $action_desc
3434
-                ),
3435
-                __FILE__,
3436
-                __FUNCTION__,
3437
-                __LINE__
3438
-            );
3439
-        }
3440
-        // check that $query_args isn't something crazy
3441
-        if (! is_array($query_args)) {
3442
-            $query_args = [];
3443
-        }
3444
-        /**
3445
-         * Allow injecting actions before the query_args are modified for possible different
3446
-         * redirections on save and close actions
3447
-         *
3448
-         * @param array $query_args       The original query_args array coming into the
3449
-         *                                method.
3450
-         * @since 4.2.0
3451
-         */
3452
-        do_action(
3453
-            "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3454
-            $query_args
3455
-        );
3456
-        // set redirect url.
3457
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3458
-        // otherwise we go with whatever is set as the _admin_base_url
3459
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3460
-        // calculate where we're going (if we have a "save and close" button pushed)
3461
-        if (
3462
-            $this->request->requestParamIsSet('save_and_close')
3463
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3464
-        ) {
3465
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3466
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3467
-            // regenerate query args array from referrer URL
3468
-            parse_str($parsed_url['query'], $query_args);
3469
-            // correct page and action will be in the query args now
3470
-            $redirect_url = admin_url('admin.php');
3471
-        }
3472
-        // merge any default query_args set in _default_route_query_args property
3473
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3474
-            $args_to_merge = [];
3475
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3476
-                // is there a wp_referer array in our _default_route_query_args property?
3477
-                if ($query_param === 'wp_referer') {
3478
-                    $query_value = (array) $query_value;
3479
-                    foreach ($query_value as $reference => $value) {
3480
-                        if (strpos($reference, 'nonce') !== false) {
3481
-                            continue;
3482
-                        }
3483
-                        // finally we will override any arguments in the referer with
3484
-                        // what might be set on the _default_route_query_args array.
3485
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3486
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3487
-                        } else {
3488
-                            $args_to_merge[ $reference ] = urlencode($value);
3489
-                        }
3490
-                    }
3491
-                    continue;
3492
-                }
3493
-                $args_to_merge[ $query_param ] = $query_value;
3494
-            }
3495
-            // now let's merge these arguments but override with what was specifically sent in to the
3496
-            // redirect.
3497
-            $query_args = array_merge($args_to_merge, $query_args);
3498
-        }
3499
-        $this->_process_notices($query_args);
3500
-        // generate redirect url
3501
-        // if redirecting to anything other than the main page, add a nonce
3502
-        if (isset($query_args['action'])) {
3503
-            // manually generate wp_nonce and merge that with the query vars
3504
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3505
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3506
-        }
3507
-        // we're adding some hooks and filters in here for processing any things just before redirects
3508
-        // (example: an admin page has done an insert or update and we want to run something after that).
3509
-        do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3510
-        $redirect_url = apply_filters(
3511
-            'FHEE_redirect_' . $this->class_name . $this->_req_action,
3512
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3513
-            $query_args
3514
-        );
3515
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3516
-        if ($this->request->isAjax()) {
3517
-            $default_data                    = [
3518
-                'close'        => true,
3519
-                'redirect_url' => $redirect_url,
3520
-                'where'        => 'main',
3521
-                'what'         => 'append',
3522
-            ];
3523
-            $this->_template_args['success'] = $success;
3524
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3525
-                $default_data,
3526
-                $this->_template_args['data']
3527
-            ) : $default_data;
3528
-            $this->_return_json();
3529
-        }
3530
-        wp_safe_redirect($redirect_url);
3531
-        exit();
3532
-    }
3533
-
3534
-
3535
-    /**
3536
-     * process any notices before redirecting (or returning ajax request)
3537
-     * This method sets the $this->_template_args['notices'] attribute;
3538
-     *
3539
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3540
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3541
-     *                                  page_routes haven't been defined yet.
3542
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3543
-     *                                  still save a transient for the notice.
3544
-     * @return void
3545
-     * @throws EE_Error
3546
-     * @throws InvalidArgumentException
3547
-     * @throws InvalidDataTypeException
3548
-     * @throws InvalidInterfaceException
3549
-     */
3550
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3551
-    {
3552
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3553
-        if ($this->request->isAjax()) {
3554
-            $notices = EE_Error::get_notices(false);
3555
-            if (empty($this->_template_args['success'])) {
3556
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3557
-            }
3558
-            if (empty($this->_template_args['errors'])) {
3559
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3560
-            }
3561
-            if (empty($this->_template_args['attention'])) {
3562
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3563
-            }
3564
-        }
3565
-        $this->_template_args['notices'] = EE_Error::get_notices();
3566
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3567
-        if (! $this->request->isAjax() || $sticky_notices) {
3568
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3569
-            $this->_add_transient(
3570
-                $route,
3571
-                $this->_template_args['notices'],
3572
-                true,
3573
-                $skip_route_verify
3574
-            );
3575
-        }
3576
-    }
3577
-
3578
-
3579
-    /**
3580
-     * get_action_link_or_button
3581
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3582
-     *
3583
-     * @param string $action        use this to indicate which action the url is generated with.
3584
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3585
-     *                              property.
3586
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3587
-     * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3588
-     * @param string $base_url      If this is not provided
3589
-     *                              the _admin_base_url will be used as the default for the button base_url.
3590
-     *                              Otherwise this value will be used.
3591
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3592
-     * @return string
3593
-     * @throws InvalidArgumentException
3594
-     * @throws InvalidInterfaceException
3595
-     * @throws InvalidDataTypeException
3596
-     * @throws EE_Error
3597
-     */
3598
-    public function get_action_link_or_button(
3599
-        $action,
3600
-        $type = 'add',
3601
-        $extra_request = [],
3602
-        $class = 'button--primary',
3603
-        $base_url = '',
3604
-        $exclude_nonce = false
3605
-    ) {
3606
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3607
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3608
-            throw new EE_Error(
3609
-                sprintf(
3610
-                    esc_html__(
3611
-                        'There is no page route for given action for the button.  This action was given: %s',
3612
-                        'event_espresso'
3613
-                    ),
3614
-                    $action
3615
-                )
3616
-            );
3617
-        }
3618
-        if (! isset($this->_labels['buttons'][ $type ])) {
3619
-            throw new EE_Error(
3620
-                sprintf(
3621
-                    esc_html__(
3622
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3623
-                        'event_espresso'
3624
-                    ),
3625
-                    $type
3626
-                )
3627
-            );
3628
-        }
3629
-        // finally check user access for this button.
3630
-        $has_access = $this->check_user_access($action, true);
3631
-        if (! $has_access) {
3632
-            return '';
3633
-        }
3634
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3635
-        $query_args = [
3636
-            'action' => $action,
3637
-        ];
3638
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3639
-        if (! empty($extra_request)) {
3640
-            $query_args = array_merge($extra_request, $query_args);
3641
-        }
3642
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3643
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3644
-    }
3645
-
3646
-
3647
-    /**
3648
-     * _per_page_screen_option
3649
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3650
-     *
3651
-     * @return void
3652
-     * @throws InvalidArgumentException
3653
-     * @throws InvalidInterfaceException
3654
-     * @throws InvalidDataTypeException
3655
-     */
3656
-    protected function _per_page_screen_option()
3657
-    {
3658
-        $option = 'per_page';
3659
-        $args   = [
3660
-            'label'   => apply_filters(
3661
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3662
-                $this->_admin_page_title,
3663
-                $this
3664
-            ),
3665
-            'default' => (int) apply_filters(
3666
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3667
-                20
3668
-            ),
3669
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3670
-        ];
3671
-        // ONLY add the screen option if the user has access to it.
3672
-        if ($this->check_user_access($this->_current_view, true)) {
3673
-            add_screen_option($option, $args);
3674
-        }
3675
-    }
3676
-
3677
-
3678
-    /**
3679
-     * set_per_page_screen_option
3680
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3681
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3682
-     * admin_menu.
3683
-     *
3684
-     * @return void
3685
-     */
3686
-    private function _set_per_page_screen_options()
3687
-    {
3688
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3689
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3690
-            if (! $user = wp_get_current_user()) {
3691
-                return;
3692
-            }
3693
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3694
-            if (! $option) {
3695
-                return;
3696
-            }
3697
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3698
-            $map_option = $option;
3699
-            $option     = str_replace('-', '_', $option);
3700
-            switch ($map_option) {
3701
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3702
-                    $max_value = apply_filters(
3703
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3704
-                        999,
3705
-                        $this->_current_page,
3706
-                        $this->_current_view
3707
-                    );
3708
-                    if ($value < 1) {
3709
-                        return;
3710
-                    }
3711
-                    $value = min($value, $max_value);
3712
-                    break;
3713
-                default:
3714
-                    $value = apply_filters(
3715
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3716
-                        false,
3717
-                        $option,
3718
-                        $value
3719
-                    );
3720
-                    if (false === $value) {
3721
-                        return;
3722
-                    }
3723
-                    break;
3724
-            }
3725
-            update_user_meta($user->ID, $option, $value);
3726
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3727
-            exit;
3728
-        }
3729
-    }
3730
-
3731
-
3732
-    /**
3733
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3734
-     *
3735
-     * @param array $data array that will be assigned to template args.
3736
-     */
3737
-    public function set_template_args($data)
3738
-    {
3739
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3740
-    }
3741
-
3742
-
3743
-    /**
3744
-     * This makes available the WP transient system for temporarily moving data between routes
3745
-     *
3746
-     * @param string $route             the route that should receive the transient
3747
-     * @param array  $data              the data that gets sent
3748
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3749
-     *                                  normal route transient.
3750
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3751
-     *                                  when we are adding a transient before page_routes have been defined.
3752
-     * @return void
3753
-     * @throws EE_Error
3754
-     */
3755
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3756
-    {
3757
-        $user_id = get_current_user_id();
3758
-        if (! $skip_route_verify) {
3759
-            $this->_verify_route($route);
3760
-        }
3761
-        // now let's set the string for what kind of transient we're setting
3762
-        $transient = $notices
3763
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3764
-            : 'rte_tx_' . $route . '_' . $user_id;
3765
-        $data      = $notices ? ['notices' => $data] : $data;
3766
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3767
-        $existing = is_multisite() && is_network_admin()
3768
-            ? get_site_transient($transient)
3769
-            : get_transient($transient);
3770
-        if ($existing) {
3771
-            $data = array_merge((array) $data, (array) $existing);
3772
-        }
3773
-        if (is_multisite() && is_network_admin()) {
3774
-            set_site_transient($transient, $data, 8);
3775
-        } else {
3776
-            set_transient($transient, $data, 8);
3777
-        }
3778
-    }
3779
-
3780
-
3781
-    /**
3782
-     * this retrieves the temporary transient that has been set for moving data between routes.
3783
-     *
3784
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3785
-     * @param string $route
3786
-     * @return mixed data
3787
-     */
3788
-    protected function _get_transient($notices = false, $route = '')
3789
-    {
3790
-        $user_id   = get_current_user_id();
3791
-        $route     = ! $route ? $this->_req_action : $route;
3792
-        $transient = $notices
3793
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3794
-            : 'rte_tx_' . $route . '_' . $user_id;
3795
-        $data      = is_multisite() && is_network_admin()
3796
-            ? get_site_transient($transient)
3797
-            : get_transient($transient);
3798
-        // delete transient after retrieval (just in case it hasn't expired);
3799
-        if (is_multisite() && is_network_admin()) {
3800
-            delete_site_transient($transient);
3801
-        } else {
3802
-            delete_transient($transient);
3803
-        }
3804
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3805
-    }
3806
-
3807
-
3808
-    /**
3809
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3810
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3811
-     * default route callback on the EE_Admin page you want it run.)
3812
-     *
3813
-     * @return void
3814
-     */
3815
-    protected function _transient_garbage_collection()
3816
-    {
3817
-        global $wpdb;
3818
-        // retrieve all existing transients
3819
-        $query =
3820
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3821
-        if ($results = $wpdb->get_results($query)) {
3822
-            foreach ($results as $result) {
3823
-                $transient = str_replace('_transient_', '', $result->option_name);
3824
-                get_transient($transient);
3825
-                if (is_multisite() && is_network_admin()) {
3826
-                    get_site_transient($transient);
3827
-                }
3828
-            }
3829
-        }
3830
-    }
3831
-
3832
-
3833
-    /**
3834
-     * get_view
3835
-     *
3836
-     * @return string content of _view property
3837
-     */
3838
-    public function get_view()
3839
-    {
3840
-        return $this->_view;
3841
-    }
3842
-
3843
-
3844
-    /**
3845
-     * getter for the protected $_views property
3846
-     *
3847
-     * @return array
3848
-     */
3849
-    public function get_views()
3850
-    {
3851
-        return $this->_views;
3852
-    }
3853
-
3854
-
3855
-    /**
3856
-     * get_current_page
3857
-     *
3858
-     * @return string _current_page property value
3859
-     */
3860
-    public function get_current_page()
3861
-    {
3862
-        return $this->_current_page;
3863
-    }
3864
-
3865
-
3866
-    /**
3867
-     * get_current_view
3868
-     *
3869
-     * @return string _current_view property value
3870
-     */
3871
-    public function get_current_view()
3872
-    {
3873
-        return $this->_current_view;
3874
-    }
3875
-
3876
-
3877
-    /**
3878
-     * get_current_screen
3879
-     *
3880
-     * @return object The current WP_Screen object
3881
-     */
3882
-    public function get_current_screen()
3883
-    {
3884
-        return $this->_current_screen;
3885
-    }
3886
-
3887
-
3888
-    /**
3889
-     * get_current_page_view_url
3890
-     *
3891
-     * @return string This returns the url for the current_page_view.
3892
-     */
3893
-    public function get_current_page_view_url()
3894
-    {
3895
-        return $this->_current_page_view_url;
3896
-    }
3897
-
3898
-
3899
-    /**
3900
-     * just returns the Request
3901
-     *
3902
-     * @return RequestInterface
3903
-     */
3904
-    public function get_request()
3905
-    {
3906
-        return $this->request;
3907
-    }
3908
-
3909
-
3910
-    /**
3911
-     * just returns the _req_data property
3912
-     *
3913
-     * @return array
3914
-     */
3915
-    public function get_request_data()
3916
-    {
3917
-        return $this->request->requestParams();
3918
-    }
3919
-
3920
-
3921
-    /**
3922
-     * returns the _req_data protected property
3923
-     *
3924
-     * @return string
3925
-     */
3926
-    public function get_req_action()
3927
-    {
3928
-        return $this->_req_action;
3929
-    }
3930
-
3931
-
3932
-    /**
3933
-     * @return bool  value of $_is_caf property
3934
-     */
3935
-    public function is_caf()
3936
-    {
3937
-        return $this->_is_caf;
3938
-    }
3939
-
3940
-
3941
-    /**
3942
-     * @return mixed
3943
-     */
3944
-    public function default_espresso_metaboxes()
3945
-    {
3946
-        return $this->_default_espresso_metaboxes;
3947
-    }
3948
-
3949
-
3950
-    /**
3951
-     * @return mixed
3952
-     */
3953
-    public function admin_base_url()
3954
-    {
3955
-        return $this->_admin_base_url;
3956
-    }
3957
-
3958
-
3959
-    /**
3960
-     * @return mixed
3961
-     */
3962
-    public function wp_page_slug()
3963
-    {
3964
-        return $this->_wp_page_slug;
3965
-    }
3966
-
3967
-
3968
-    /**
3969
-     * updates  espresso configuration settings
3970
-     *
3971
-     * @param string                   $tab
3972
-     * @param EE_Config_Base|EE_Config $config
3973
-     * @param string                   $file file where error occurred
3974
-     * @param string                   $func function  where error occurred
3975
-     * @param string                   $line line no where error occurred
3976
-     * @return boolean
3977
-     */
3978
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3979
-    {
3980
-        // remove any options that are NOT going to be saved with the config settings.
3981
-        if (isset($config->core->ee_ueip_optin)) {
3982
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3983
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3984
-            update_option('ee_ueip_has_notified', true);
3985
-        }
3986
-        // and save it (note we're also doing the network save here)
3987
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3988
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3989
-        if ($config_saved && $net_saved) {
3990
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3991
-            return true;
3992
-        }
3993
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3994
-        return false;
3995
-    }
3996
-
3997
-
3998
-    /**
3999
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4000
-     *
4001
-     * @return array
4002
-     */
4003
-    public function get_yes_no_values()
4004
-    {
4005
-        return $this->_yes_no_values;
4006
-    }
4007
-
4008
-
4009
-    /**
4010
-     * @return string
4011
-     * @throws ReflectionException
4012
-     * @since $VID:$
4013
-     */
4014
-    protected function _get_dir()
4015
-    {
4016
-        $reflector = new ReflectionClass($this->class_name);
4017
-        return dirname($reflector->getFileName());
4018
-    }
4019
-
4020
-
4021
-    /**
4022
-     * A helper for getting a "next link".
4023
-     *
4024
-     * @param string $url   The url to link to
4025
-     * @param string $class The class to use.
4026
-     * @return string
4027
-     */
4028
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4029
-    {
4030
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4031
-    }
4032
-
4033
-
4034
-    /**
4035
-     * A helper for getting a "previous link".
4036
-     *
4037
-     * @param string $url   The url to link to
4038
-     * @param string $class The class to use.
4039
-     * @return string
4040
-     */
4041
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4042
-    {
4043
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4044
-    }
4045
-
4046
-
4047
-
4048
-
4049
-
4050
-
4051
-
4052
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4053
-
4054
-
4055
-    /**
4056
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4057
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4058
-     * _req_data array.
4059
-     *
4060
-     * @return bool success/fail
4061
-     * @throws EE_Error
4062
-     * @throws InvalidArgumentException
4063
-     * @throws ReflectionException
4064
-     * @throws InvalidDataTypeException
4065
-     * @throws InvalidInterfaceException
4066
-     */
4067
-    protected function _process_resend_registration()
4068
-    {
4069
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4070
-        do_action(
4071
-            'AHEE__EE_Admin_Page___process_resend_registration',
4072
-            $this->_template_args['success'],
4073
-            $this->request->requestParams()
4074
-        );
4075
-        return $this->_template_args['success'];
4076
-    }
4077
-
4078
-
4079
-    /**
4080
-     * This automatically processes any payment message notifications when manual payment has been applied.
4081
-     *
4082
-     * @param EE_Payment $payment
4083
-     * @return bool success/fail
4084
-     */
4085
-    protected function _process_payment_notification(EE_Payment $payment)
4086
-    {
4087
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4088
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4089
-        $this->_template_args['success'] = apply_filters(
4090
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4091
-            false,
4092
-            $payment
4093
-        );
4094
-        return $this->_template_args['success'];
4095
-    }
4096
-
4097
-
4098
-    /**
4099
-     * @param EEM_Base      $entity_model
4100
-     * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4101
-     * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4102
-     * @param string        $delete_column  name of the field that denotes whether entity is trashed
4103
-     * @param callable|null $callback       called after entity is trashed, restored, or deleted
4104
-     * @return int|float
4105
-     * @throws EE_Error
4106
-     */
4107
-    protected function trashRestoreDeleteEntities(
4108
-        EEM_Base $entity_model,
4109
-        string $entity_PK_name,
4110
-        string $action = EE_Admin_List_Table::ACTION_DELETE,
4111
-        string $delete_column = '',
4112
-        callable $callback = null
4113
-    ) {
4114
-        $entity_PK      = $entity_model->get_primary_key_field();
4115
-        $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4116
-        $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4117
-        // grab ID if deleting a single entity
4118
-        if ($this->request->requestParamIsSet($entity_PK_name)) {
4119
-            $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4120
-            return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4121
-        }
4122
-        // or grab checkbox array if bulk deleting
4123
-        $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4124
-        if (empty($checkboxes)) {
4125
-            return 0;
4126
-        }
4127
-        $success = 0;
4128
-        $IDs     = array_keys($checkboxes);
4129
-        // cycle thru bulk action checkboxes
4130
-        foreach ($IDs as $ID) {
4131
-            // increment $success
4132
-            if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4133
-                $success++;
4134
-            }
4135
-        }
4136
-        $count = (int) count($checkboxes);
4137
-        // if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4138
-        // otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4139
-        return $success === $count ? $count : $success / $count;
4140
-    }
4141
-
4142
-
4143
-    /**
4144
-     * @param EE_Primary_Key_Field_Base $entity_PK
4145
-     * @return string
4146
-     * @throws EE_Error
4147
-     * @since   $VID:$
4148
-     */
4149
-    private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string
4150
-    {
4151
-        $entity_PK_type = $entity_PK->getSchemaType();
4152
-        switch ($entity_PK_type) {
4153
-            case 'boolean':
4154
-                return 'bool';
4155
-            case 'integer':
4156
-                return 'int';
4157
-            case 'number':
4158
-                return 'float';
4159
-            case 'string':
4160
-                return 'string';
4161
-        }
4162
-        throw new RuntimeException(
4163
-            sprintf(
4164
-                esc_html__(
4165
-                    '"%1$s" is an invalid schema type for the %2$s primary key.',
4166
-                    'event_espresso'
4167
-                ),
4168
-                $entity_PK_type,
4169
-                $entity_PK->get_name()
4170
-            )
4171
-        );
4172
-    }
4173
-
4174
-
4175
-    /**
4176
-     * @param EEM_Base      $entity_model
4177
-     * @param int|string    $entity_ID
4178
-     * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4179
-     * @param string        $delete_column name of the field that denotes whether entity is trashed
4180
-     * @param callable|null $callback      called after entity is trashed, restored, or deleted
4181
-     * @return bool
4182
-     */
4183
-    protected function trashRestoreDeleteEntity(
4184
-        EEM_Base $entity_model,
4185
-        $entity_ID,
4186
-        string $action,
4187
-        string $delete_column,
4188
-        ?callable $callback = null
4189
-    ): bool {
4190
-        $entity_ID = absint($entity_ID);
4191
-        if (! $entity_ID) {
4192
-            $this->trashRestoreDeleteError($action, $entity_model);
4193
-        }
4194
-        $result = 0;
4195
-        try {
4196
-            switch ($action) {
4197
-                case EE_Admin_List_Table::ACTION_DELETE:
4198
-                    $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID);
4199
-                    break;
4200
-                case EE_Admin_List_Table::ACTION_RESTORE:
4201
-                    $this->validateDeleteColumn($entity_model, $delete_column);
4202
-                    $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID);
4203
-                    break;
4204
-                case EE_Admin_List_Table::ACTION_TRASH:
4205
-                    $this->validateDeleteColumn($entity_model, $delete_column);
4206
-                    $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID);
4207
-                    break;
4208
-            }
4209
-        } catch (Exception $exception) {
4210
-            $this->trashRestoreDeleteError($action, $entity_model, $exception);
4211
-        }
4212
-        if (is_callable($callback)) {
4213
-            call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4214
-        }
4215
-        return $result;
4216
-    }
4217
-
4218
-
4219
-    /**
4220
-     * @param EEM_Base $entity_model
4221
-     * @param string   $delete_column
4222
-     * @since $VID:$
4223
-     */
4224
-    private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column)
4225
-    {
4226
-        if (empty($delete_column)) {
4227
-            throw new DomainException(
4228
-                sprintf(
4229
-                    esc_html__(
4230
-                        'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4231
-                        'event_espresso'
4232
-                    ),
4233
-                    $entity_model->get_this_model_name()
4234
-                )
4235
-            );
4236
-        }
4237
-        if (! $entity_model->has_field($delete_column)) {
4238
-            throw new DomainException(
4239
-                sprintf(
4240
-                    esc_html__(
4241
-                        'The %1$s field does not exist on the %2$s model.',
4242
-                        'event_espresso'
4243
-                    ),
4244
-                    $delete_column,
4245
-                    $entity_model->get_this_model_name()
4246
-                )
4247
-            );
4248
-        }
4249
-    }
4250
-
4251
-
4252
-    /**
4253
-     * @param EEM_Base       $entity_model
4254
-     * @param Exception|null $exception
4255
-     * @param string         $action
4256
-     * @since $VID:$
4257
-     */
4258
-    private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null)
4259
-    {
4260
-        if ($exception instanceof Exception) {
4261
-            throw new RuntimeException(
4262
-                sprintf(
4263
-                    esc_html__(
4264
-                        'Could not %1$s the %2$s because the following error occurred: %3$s',
4265
-                        'event_espresso'
4266
-                    ),
4267
-                    $action,
4268
-                    $entity_model->get_this_model_name(),
4269
-                    $exception->getMessage()
4270
-                )
4271
-            );
4272
-        }
4273
-        throw new RuntimeException(
4274
-            sprintf(
4275
-                esc_html__(
4276
-                    'Could not %1$s the %2$s because an invalid ID was received.',
4277
-                    'event_espresso'
4278
-                ),
4279
-                $action,
4280
-                $entity_model->get_this_model_name()
4281
-            )
4282
-        );
4283
-    }
3316
+		// add nonce
3317
+		$nonce                                             =
3318
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3319
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3320
+		// add REQUIRED form action
3321
+		$hidden_fields = [
3322
+			'action' => ['type' => 'hidden', 'value' => $route],
3323
+		];
3324
+		// merge arrays
3325
+		$hidden_fields = is_array($additional_hidden_fields)
3326
+			? array_merge($hidden_fields, $additional_hidden_fields)
3327
+			: $hidden_fields;
3328
+		// generate form fields
3329
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3330
+		// add fields to form
3331
+		foreach ((array) $form_fields as $form_field) {
3332
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3333
+		}
3334
+		// close form
3335
+		$this->_template_args['after_admin_page_content'] = '</form>';
3336
+	}
3337
+
3338
+
3339
+	/**
3340
+	 * Public Wrapper for _redirect_after_action() method since its
3341
+	 * discovered it would be useful for external code to have access.
3342
+	 *
3343
+	 * @param bool   $success
3344
+	 * @param string $what
3345
+	 * @param string $action_desc
3346
+	 * @param array  $query_args
3347
+	 * @param bool   $override_overwrite
3348
+	 * @throws EE_Error
3349
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3350
+	 * @since 4.5.0
3351
+	 */
3352
+	public function redirect_after_action(
3353
+		$success = false,
3354
+		$what = 'item',
3355
+		$action_desc = 'processed',
3356
+		$query_args = [],
3357
+		$override_overwrite = false
3358
+	) {
3359
+		$this->_redirect_after_action(
3360
+			$success,
3361
+			$what,
3362
+			$action_desc,
3363
+			$query_args,
3364
+			$override_overwrite
3365
+		);
3366
+	}
3367
+
3368
+
3369
+	/**
3370
+	 * Helper method for merging existing request data with the returned redirect url.
3371
+	 *
3372
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3373
+	 * filters are still applied.
3374
+	 *
3375
+	 * @param array $new_route_data
3376
+	 * @return array
3377
+	 */
3378
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3379
+	{
3380
+		foreach ($this->request->requestParams() as $ref => $value) {
3381
+			// unset nonces
3382
+			if (strpos($ref, 'nonce') !== false) {
3383
+				$this->request->unSetRequestParam($ref);
3384
+				continue;
3385
+			}
3386
+			// urlencode values.
3387
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3388
+			$this->request->setRequestParam($ref, $value);
3389
+		}
3390
+		return array_merge($this->request->requestParams(), $new_route_data);
3391
+	}
3392
+
3393
+
3394
+	/**
3395
+	 * @param int|float|string $success      - whether success was for two or more records, or just one, or none
3396
+	 * @param string           $what         - what the action was performed on
3397
+	 * @param string           $action_desc  - what was done ie: updated, deleted, etc
3398
+	 * @param array $query_args              - an array of query_args to be added to the URL to redirect to
3399
+	 * @param BOOL $override_overwrite       - by default all EE_Error::success messages are overwritten,
3400
+	 *                                         this allows you to override this so that they show.
3401
+	 * @return void
3402
+	 * @throws EE_Error
3403
+	 * @throws InvalidArgumentException
3404
+	 * @throws InvalidDataTypeException
3405
+	 * @throws InvalidInterfaceException
3406
+	 */
3407
+	protected function _redirect_after_action(
3408
+		$success = 0,
3409
+		string $what = 'item',
3410
+		string $action_desc = 'processed',
3411
+		array $query_args = [],
3412
+		bool $override_overwrite = false
3413
+	) {
3414
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3415
+		$notices      = EE_Error::get_notices(false);
3416
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3417
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3418
+			EE_Error::overwrite_success();
3419
+		}
3420
+		if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3421
+			// how many records affected ? more than one record ? or just one ?
3422
+			EE_Error::add_success(
3423
+				sprintf(
3424
+					esc_html(
3425
+						_n(
3426
+							'The "%1$s" has been successfully %2$s.',
3427
+							'The "%1$s" have been successfully %2$s.',
3428
+							$success,
3429
+							'event_espresso'
3430
+						)
3431
+					),
3432
+					$what,
3433
+					$action_desc
3434
+				),
3435
+				__FILE__,
3436
+				__FUNCTION__,
3437
+				__LINE__
3438
+			);
3439
+		}
3440
+		// check that $query_args isn't something crazy
3441
+		if (! is_array($query_args)) {
3442
+			$query_args = [];
3443
+		}
3444
+		/**
3445
+		 * Allow injecting actions before the query_args are modified for possible different
3446
+		 * redirections on save and close actions
3447
+		 *
3448
+		 * @param array $query_args       The original query_args array coming into the
3449
+		 *                                method.
3450
+		 * @since 4.2.0
3451
+		 */
3452
+		do_action(
3453
+			"AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3454
+			$query_args
3455
+		);
3456
+		// set redirect url.
3457
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3458
+		// otherwise we go with whatever is set as the _admin_base_url
3459
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3460
+		// calculate where we're going (if we have a "save and close" button pushed)
3461
+		if (
3462
+			$this->request->requestParamIsSet('save_and_close')
3463
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3464
+		) {
3465
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3466
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3467
+			// regenerate query args array from referrer URL
3468
+			parse_str($parsed_url['query'], $query_args);
3469
+			// correct page and action will be in the query args now
3470
+			$redirect_url = admin_url('admin.php');
3471
+		}
3472
+		// merge any default query_args set in _default_route_query_args property
3473
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3474
+			$args_to_merge = [];
3475
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3476
+				// is there a wp_referer array in our _default_route_query_args property?
3477
+				if ($query_param === 'wp_referer') {
3478
+					$query_value = (array) $query_value;
3479
+					foreach ($query_value as $reference => $value) {
3480
+						if (strpos($reference, 'nonce') !== false) {
3481
+							continue;
3482
+						}
3483
+						// finally we will override any arguments in the referer with
3484
+						// what might be set on the _default_route_query_args array.
3485
+						if (isset($this->_default_route_query_args[ $reference ])) {
3486
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3487
+						} else {
3488
+							$args_to_merge[ $reference ] = urlencode($value);
3489
+						}
3490
+					}
3491
+					continue;
3492
+				}
3493
+				$args_to_merge[ $query_param ] = $query_value;
3494
+			}
3495
+			// now let's merge these arguments but override with what was specifically sent in to the
3496
+			// redirect.
3497
+			$query_args = array_merge($args_to_merge, $query_args);
3498
+		}
3499
+		$this->_process_notices($query_args);
3500
+		// generate redirect url
3501
+		// if redirecting to anything other than the main page, add a nonce
3502
+		if (isset($query_args['action'])) {
3503
+			// manually generate wp_nonce and merge that with the query vars
3504
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3505
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3506
+		}
3507
+		// we're adding some hooks and filters in here for processing any things just before redirects
3508
+		// (example: an admin page has done an insert or update and we want to run something after that).
3509
+		do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3510
+		$redirect_url = apply_filters(
3511
+			'FHEE_redirect_' . $this->class_name . $this->_req_action,
3512
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3513
+			$query_args
3514
+		);
3515
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3516
+		if ($this->request->isAjax()) {
3517
+			$default_data                    = [
3518
+				'close'        => true,
3519
+				'redirect_url' => $redirect_url,
3520
+				'where'        => 'main',
3521
+				'what'         => 'append',
3522
+			];
3523
+			$this->_template_args['success'] = $success;
3524
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3525
+				$default_data,
3526
+				$this->_template_args['data']
3527
+			) : $default_data;
3528
+			$this->_return_json();
3529
+		}
3530
+		wp_safe_redirect($redirect_url);
3531
+		exit();
3532
+	}
3533
+
3534
+
3535
+	/**
3536
+	 * process any notices before redirecting (or returning ajax request)
3537
+	 * This method sets the $this->_template_args['notices'] attribute;
3538
+	 *
3539
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3540
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3541
+	 *                                  page_routes haven't been defined yet.
3542
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3543
+	 *                                  still save a transient for the notice.
3544
+	 * @return void
3545
+	 * @throws EE_Error
3546
+	 * @throws InvalidArgumentException
3547
+	 * @throws InvalidDataTypeException
3548
+	 * @throws InvalidInterfaceException
3549
+	 */
3550
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3551
+	{
3552
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3553
+		if ($this->request->isAjax()) {
3554
+			$notices = EE_Error::get_notices(false);
3555
+			if (empty($this->_template_args['success'])) {
3556
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3557
+			}
3558
+			if (empty($this->_template_args['errors'])) {
3559
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3560
+			}
3561
+			if (empty($this->_template_args['attention'])) {
3562
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3563
+			}
3564
+		}
3565
+		$this->_template_args['notices'] = EE_Error::get_notices();
3566
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3567
+		if (! $this->request->isAjax() || $sticky_notices) {
3568
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3569
+			$this->_add_transient(
3570
+				$route,
3571
+				$this->_template_args['notices'],
3572
+				true,
3573
+				$skip_route_verify
3574
+			);
3575
+		}
3576
+	}
3577
+
3578
+
3579
+	/**
3580
+	 * get_action_link_or_button
3581
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3582
+	 *
3583
+	 * @param string $action        use this to indicate which action the url is generated with.
3584
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3585
+	 *                              property.
3586
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3587
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3588
+	 * @param string $base_url      If this is not provided
3589
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3590
+	 *                              Otherwise this value will be used.
3591
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3592
+	 * @return string
3593
+	 * @throws InvalidArgumentException
3594
+	 * @throws InvalidInterfaceException
3595
+	 * @throws InvalidDataTypeException
3596
+	 * @throws EE_Error
3597
+	 */
3598
+	public function get_action_link_or_button(
3599
+		$action,
3600
+		$type = 'add',
3601
+		$extra_request = [],
3602
+		$class = 'button--primary',
3603
+		$base_url = '',
3604
+		$exclude_nonce = false
3605
+	) {
3606
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3607
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3608
+			throw new EE_Error(
3609
+				sprintf(
3610
+					esc_html__(
3611
+						'There is no page route for given action for the button.  This action was given: %s',
3612
+						'event_espresso'
3613
+					),
3614
+					$action
3615
+				)
3616
+			);
3617
+		}
3618
+		if (! isset($this->_labels['buttons'][ $type ])) {
3619
+			throw new EE_Error(
3620
+				sprintf(
3621
+					esc_html__(
3622
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3623
+						'event_espresso'
3624
+					),
3625
+					$type
3626
+				)
3627
+			);
3628
+		}
3629
+		// finally check user access for this button.
3630
+		$has_access = $this->check_user_access($action, true);
3631
+		if (! $has_access) {
3632
+			return '';
3633
+		}
3634
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3635
+		$query_args = [
3636
+			'action' => $action,
3637
+		];
3638
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3639
+		if (! empty($extra_request)) {
3640
+			$query_args = array_merge($extra_request, $query_args);
3641
+		}
3642
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3643
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3644
+	}
3645
+
3646
+
3647
+	/**
3648
+	 * _per_page_screen_option
3649
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3650
+	 *
3651
+	 * @return void
3652
+	 * @throws InvalidArgumentException
3653
+	 * @throws InvalidInterfaceException
3654
+	 * @throws InvalidDataTypeException
3655
+	 */
3656
+	protected function _per_page_screen_option()
3657
+	{
3658
+		$option = 'per_page';
3659
+		$args   = [
3660
+			'label'   => apply_filters(
3661
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3662
+				$this->_admin_page_title,
3663
+				$this
3664
+			),
3665
+			'default' => (int) apply_filters(
3666
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3667
+				20
3668
+			),
3669
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3670
+		];
3671
+		// ONLY add the screen option if the user has access to it.
3672
+		if ($this->check_user_access($this->_current_view, true)) {
3673
+			add_screen_option($option, $args);
3674
+		}
3675
+	}
3676
+
3677
+
3678
+	/**
3679
+	 * set_per_page_screen_option
3680
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3681
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3682
+	 * admin_menu.
3683
+	 *
3684
+	 * @return void
3685
+	 */
3686
+	private function _set_per_page_screen_options()
3687
+	{
3688
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3689
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3690
+			if (! $user = wp_get_current_user()) {
3691
+				return;
3692
+			}
3693
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3694
+			if (! $option) {
3695
+				return;
3696
+			}
3697
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3698
+			$map_option = $option;
3699
+			$option     = str_replace('-', '_', $option);
3700
+			switch ($map_option) {
3701
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3702
+					$max_value = apply_filters(
3703
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3704
+						999,
3705
+						$this->_current_page,
3706
+						$this->_current_view
3707
+					);
3708
+					if ($value < 1) {
3709
+						return;
3710
+					}
3711
+					$value = min($value, $max_value);
3712
+					break;
3713
+				default:
3714
+					$value = apply_filters(
3715
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3716
+						false,
3717
+						$option,
3718
+						$value
3719
+					);
3720
+					if (false === $value) {
3721
+						return;
3722
+					}
3723
+					break;
3724
+			}
3725
+			update_user_meta($user->ID, $option, $value);
3726
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3727
+			exit;
3728
+		}
3729
+	}
3730
+
3731
+
3732
+	/**
3733
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3734
+	 *
3735
+	 * @param array $data array that will be assigned to template args.
3736
+	 */
3737
+	public function set_template_args($data)
3738
+	{
3739
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3740
+	}
3741
+
3742
+
3743
+	/**
3744
+	 * This makes available the WP transient system for temporarily moving data between routes
3745
+	 *
3746
+	 * @param string $route             the route that should receive the transient
3747
+	 * @param array  $data              the data that gets sent
3748
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3749
+	 *                                  normal route transient.
3750
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3751
+	 *                                  when we are adding a transient before page_routes have been defined.
3752
+	 * @return void
3753
+	 * @throws EE_Error
3754
+	 */
3755
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3756
+	{
3757
+		$user_id = get_current_user_id();
3758
+		if (! $skip_route_verify) {
3759
+			$this->_verify_route($route);
3760
+		}
3761
+		// now let's set the string for what kind of transient we're setting
3762
+		$transient = $notices
3763
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3764
+			: 'rte_tx_' . $route . '_' . $user_id;
3765
+		$data      = $notices ? ['notices' => $data] : $data;
3766
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3767
+		$existing = is_multisite() && is_network_admin()
3768
+			? get_site_transient($transient)
3769
+			: get_transient($transient);
3770
+		if ($existing) {
3771
+			$data = array_merge((array) $data, (array) $existing);
3772
+		}
3773
+		if (is_multisite() && is_network_admin()) {
3774
+			set_site_transient($transient, $data, 8);
3775
+		} else {
3776
+			set_transient($transient, $data, 8);
3777
+		}
3778
+	}
3779
+
3780
+
3781
+	/**
3782
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3783
+	 *
3784
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3785
+	 * @param string $route
3786
+	 * @return mixed data
3787
+	 */
3788
+	protected function _get_transient($notices = false, $route = '')
3789
+	{
3790
+		$user_id   = get_current_user_id();
3791
+		$route     = ! $route ? $this->_req_action : $route;
3792
+		$transient = $notices
3793
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3794
+			: 'rte_tx_' . $route . '_' . $user_id;
3795
+		$data      = is_multisite() && is_network_admin()
3796
+			? get_site_transient($transient)
3797
+			: get_transient($transient);
3798
+		// delete transient after retrieval (just in case it hasn't expired);
3799
+		if (is_multisite() && is_network_admin()) {
3800
+			delete_site_transient($transient);
3801
+		} else {
3802
+			delete_transient($transient);
3803
+		}
3804
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3805
+	}
3806
+
3807
+
3808
+	/**
3809
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3810
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3811
+	 * default route callback on the EE_Admin page you want it run.)
3812
+	 *
3813
+	 * @return void
3814
+	 */
3815
+	protected function _transient_garbage_collection()
3816
+	{
3817
+		global $wpdb;
3818
+		// retrieve all existing transients
3819
+		$query =
3820
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3821
+		if ($results = $wpdb->get_results($query)) {
3822
+			foreach ($results as $result) {
3823
+				$transient = str_replace('_transient_', '', $result->option_name);
3824
+				get_transient($transient);
3825
+				if (is_multisite() && is_network_admin()) {
3826
+					get_site_transient($transient);
3827
+				}
3828
+			}
3829
+		}
3830
+	}
3831
+
3832
+
3833
+	/**
3834
+	 * get_view
3835
+	 *
3836
+	 * @return string content of _view property
3837
+	 */
3838
+	public function get_view()
3839
+	{
3840
+		return $this->_view;
3841
+	}
3842
+
3843
+
3844
+	/**
3845
+	 * getter for the protected $_views property
3846
+	 *
3847
+	 * @return array
3848
+	 */
3849
+	public function get_views()
3850
+	{
3851
+		return $this->_views;
3852
+	}
3853
+
3854
+
3855
+	/**
3856
+	 * get_current_page
3857
+	 *
3858
+	 * @return string _current_page property value
3859
+	 */
3860
+	public function get_current_page()
3861
+	{
3862
+		return $this->_current_page;
3863
+	}
3864
+
3865
+
3866
+	/**
3867
+	 * get_current_view
3868
+	 *
3869
+	 * @return string _current_view property value
3870
+	 */
3871
+	public function get_current_view()
3872
+	{
3873
+		return $this->_current_view;
3874
+	}
3875
+
3876
+
3877
+	/**
3878
+	 * get_current_screen
3879
+	 *
3880
+	 * @return object The current WP_Screen object
3881
+	 */
3882
+	public function get_current_screen()
3883
+	{
3884
+		return $this->_current_screen;
3885
+	}
3886
+
3887
+
3888
+	/**
3889
+	 * get_current_page_view_url
3890
+	 *
3891
+	 * @return string This returns the url for the current_page_view.
3892
+	 */
3893
+	public function get_current_page_view_url()
3894
+	{
3895
+		return $this->_current_page_view_url;
3896
+	}
3897
+
3898
+
3899
+	/**
3900
+	 * just returns the Request
3901
+	 *
3902
+	 * @return RequestInterface
3903
+	 */
3904
+	public function get_request()
3905
+	{
3906
+		return $this->request;
3907
+	}
3908
+
3909
+
3910
+	/**
3911
+	 * just returns the _req_data property
3912
+	 *
3913
+	 * @return array
3914
+	 */
3915
+	public function get_request_data()
3916
+	{
3917
+		return $this->request->requestParams();
3918
+	}
3919
+
3920
+
3921
+	/**
3922
+	 * returns the _req_data protected property
3923
+	 *
3924
+	 * @return string
3925
+	 */
3926
+	public function get_req_action()
3927
+	{
3928
+		return $this->_req_action;
3929
+	}
3930
+
3931
+
3932
+	/**
3933
+	 * @return bool  value of $_is_caf property
3934
+	 */
3935
+	public function is_caf()
3936
+	{
3937
+		return $this->_is_caf;
3938
+	}
3939
+
3940
+
3941
+	/**
3942
+	 * @return mixed
3943
+	 */
3944
+	public function default_espresso_metaboxes()
3945
+	{
3946
+		return $this->_default_espresso_metaboxes;
3947
+	}
3948
+
3949
+
3950
+	/**
3951
+	 * @return mixed
3952
+	 */
3953
+	public function admin_base_url()
3954
+	{
3955
+		return $this->_admin_base_url;
3956
+	}
3957
+
3958
+
3959
+	/**
3960
+	 * @return mixed
3961
+	 */
3962
+	public function wp_page_slug()
3963
+	{
3964
+		return $this->_wp_page_slug;
3965
+	}
3966
+
3967
+
3968
+	/**
3969
+	 * updates  espresso configuration settings
3970
+	 *
3971
+	 * @param string                   $tab
3972
+	 * @param EE_Config_Base|EE_Config $config
3973
+	 * @param string                   $file file where error occurred
3974
+	 * @param string                   $func function  where error occurred
3975
+	 * @param string                   $line line no where error occurred
3976
+	 * @return boolean
3977
+	 */
3978
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3979
+	{
3980
+		// remove any options that are NOT going to be saved with the config settings.
3981
+		if (isset($config->core->ee_ueip_optin)) {
3982
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3983
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3984
+			update_option('ee_ueip_has_notified', true);
3985
+		}
3986
+		// and save it (note we're also doing the network save here)
3987
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3988
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3989
+		if ($config_saved && $net_saved) {
3990
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3991
+			return true;
3992
+		}
3993
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3994
+		return false;
3995
+	}
3996
+
3997
+
3998
+	/**
3999
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4000
+	 *
4001
+	 * @return array
4002
+	 */
4003
+	public function get_yes_no_values()
4004
+	{
4005
+		return $this->_yes_no_values;
4006
+	}
4007
+
4008
+
4009
+	/**
4010
+	 * @return string
4011
+	 * @throws ReflectionException
4012
+	 * @since $VID:$
4013
+	 */
4014
+	protected function _get_dir()
4015
+	{
4016
+		$reflector = new ReflectionClass($this->class_name);
4017
+		return dirname($reflector->getFileName());
4018
+	}
4019
+
4020
+
4021
+	/**
4022
+	 * A helper for getting a "next link".
4023
+	 *
4024
+	 * @param string $url   The url to link to
4025
+	 * @param string $class The class to use.
4026
+	 * @return string
4027
+	 */
4028
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4029
+	{
4030
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4031
+	}
4032
+
4033
+
4034
+	/**
4035
+	 * A helper for getting a "previous link".
4036
+	 *
4037
+	 * @param string $url   The url to link to
4038
+	 * @param string $class The class to use.
4039
+	 * @return string
4040
+	 */
4041
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4042
+	{
4043
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4044
+	}
4045
+
4046
+
4047
+
4048
+
4049
+
4050
+
4051
+
4052
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4053
+
4054
+
4055
+	/**
4056
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4057
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4058
+	 * _req_data array.
4059
+	 *
4060
+	 * @return bool success/fail
4061
+	 * @throws EE_Error
4062
+	 * @throws InvalidArgumentException
4063
+	 * @throws ReflectionException
4064
+	 * @throws InvalidDataTypeException
4065
+	 * @throws InvalidInterfaceException
4066
+	 */
4067
+	protected function _process_resend_registration()
4068
+	{
4069
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4070
+		do_action(
4071
+			'AHEE__EE_Admin_Page___process_resend_registration',
4072
+			$this->_template_args['success'],
4073
+			$this->request->requestParams()
4074
+		);
4075
+		return $this->_template_args['success'];
4076
+	}
4077
+
4078
+
4079
+	/**
4080
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4081
+	 *
4082
+	 * @param EE_Payment $payment
4083
+	 * @return bool success/fail
4084
+	 */
4085
+	protected function _process_payment_notification(EE_Payment $payment)
4086
+	{
4087
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4088
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4089
+		$this->_template_args['success'] = apply_filters(
4090
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4091
+			false,
4092
+			$payment
4093
+		);
4094
+		return $this->_template_args['success'];
4095
+	}
4096
+
4097
+
4098
+	/**
4099
+	 * @param EEM_Base      $entity_model
4100
+	 * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4101
+	 * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4102
+	 * @param string        $delete_column  name of the field that denotes whether entity is trashed
4103
+	 * @param callable|null $callback       called after entity is trashed, restored, or deleted
4104
+	 * @return int|float
4105
+	 * @throws EE_Error
4106
+	 */
4107
+	protected function trashRestoreDeleteEntities(
4108
+		EEM_Base $entity_model,
4109
+		string $entity_PK_name,
4110
+		string $action = EE_Admin_List_Table::ACTION_DELETE,
4111
+		string $delete_column = '',
4112
+		callable $callback = null
4113
+	) {
4114
+		$entity_PK      = $entity_model->get_primary_key_field();
4115
+		$entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4116
+		$entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4117
+		// grab ID if deleting a single entity
4118
+		if ($this->request->requestParamIsSet($entity_PK_name)) {
4119
+			$ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4120
+			return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4121
+		}
4122
+		// or grab checkbox array if bulk deleting
4123
+		$checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4124
+		if (empty($checkboxes)) {
4125
+			return 0;
4126
+		}
4127
+		$success = 0;
4128
+		$IDs     = array_keys($checkboxes);
4129
+		// cycle thru bulk action checkboxes
4130
+		foreach ($IDs as $ID) {
4131
+			// increment $success
4132
+			if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4133
+				$success++;
4134
+			}
4135
+		}
4136
+		$count = (int) count($checkboxes);
4137
+		// if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4138
+		// otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4139
+		return $success === $count ? $count : $success / $count;
4140
+	}
4141
+
4142
+
4143
+	/**
4144
+	 * @param EE_Primary_Key_Field_Base $entity_PK
4145
+	 * @return string
4146
+	 * @throws EE_Error
4147
+	 * @since   $VID:$
4148
+	 */
4149
+	private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string
4150
+	{
4151
+		$entity_PK_type = $entity_PK->getSchemaType();
4152
+		switch ($entity_PK_type) {
4153
+			case 'boolean':
4154
+				return 'bool';
4155
+			case 'integer':
4156
+				return 'int';
4157
+			case 'number':
4158
+				return 'float';
4159
+			case 'string':
4160
+				return 'string';
4161
+		}
4162
+		throw new RuntimeException(
4163
+			sprintf(
4164
+				esc_html__(
4165
+					'"%1$s" is an invalid schema type for the %2$s primary key.',
4166
+					'event_espresso'
4167
+				),
4168
+				$entity_PK_type,
4169
+				$entity_PK->get_name()
4170
+			)
4171
+		);
4172
+	}
4173
+
4174
+
4175
+	/**
4176
+	 * @param EEM_Base      $entity_model
4177
+	 * @param int|string    $entity_ID
4178
+	 * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4179
+	 * @param string        $delete_column name of the field that denotes whether entity is trashed
4180
+	 * @param callable|null $callback      called after entity is trashed, restored, or deleted
4181
+	 * @return bool
4182
+	 */
4183
+	protected function trashRestoreDeleteEntity(
4184
+		EEM_Base $entity_model,
4185
+		$entity_ID,
4186
+		string $action,
4187
+		string $delete_column,
4188
+		?callable $callback = null
4189
+	): bool {
4190
+		$entity_ID = absint($entity_ID);
4191
+		if (! $entity_ID) {
4192
+			$this->trashRestoreDeleteError($action, $entity_model);
4193
+		}
4194
+		$result = 0;
4195
+		try {
4196
+			switch ($action) {
4197
+				case EE_Admin_List_Table::ACTION_DELETE:
4198
+					$result = (bool) $entity_model->delete_permanently_by_ID($entity_ID);
4199
+					break;
4200
+				case EE_Admin_List_Table::ACTION_RESTORE:
4201
+					$this->validateDeleteColumn($entity_model, $delete_column);
4202
+					$result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID);
4203
+					break;
4204
+				case EE_Admin_List_Table::ACTION_TRASH:
4205
+					$this->validateDeleteColumn($entity_model, $delete_column);
4206
+					$result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID);
4207
+					break;
4208
+			}
4209
+		} catch (Exception $exception) {
4210
+			$this->trashRestoreDeleteError($action, $entity_model, $exception);
4211
+		}
4212
+		if (is_callable($callback)) {
4213
+			call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4214
+		}
4215
+		return $result;
4216
+	}
4217
+
4218
+
4219
+	/**
4220
+	 * @param EEM_Base $entity_model
4221
+	 * @param string   $delete_column
4222
+	 * @since $VID:$
4223
+	 */
4224
+	private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column)
4225
+	{
4226
+		if (empty($delete_column)) {
4227
+			throw new DomainException(
4228
+				sprintf(
4229
+					esc_html__(
4230
+						'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4231
+						'event_espresso'
4232
+					),
4233
+					$entity_model->get_this_model_name()
4234
+				)
4235
+			);
4236
+		}
4237
+		if (! $entity_model->has_field($delete_column)) {
4238
+			throw new DomainException(
4239
+				sprintf(
4240
+					esc_html__(
4241
+						'The %1$s field does not exist on the %2$s model.',
4242
+						'event_espresso'
4243
+					),
4244
+					$delete_column,
4245
+					$entity_model->get_this_model_name()
4246
+				)
4247
+			);
4248
+		}
4249
+	}
4250
+
4251
+
4252
+	/**
4253
+	 * @param EEM_Base       $entity_model
4254
+	 * @param Exception|null $exception
4255
+	 * @param string         $action
4256
+	 * @since $VID:$
4257
+	 */
4258
+	private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null)
4259
+	{
4260
+		if ($exception instanceof Exception) {
4261
+			throw new RuntimeException(
4262
+				sprintf(
4263
+					esc_html__(
4264
+						'Could not %1$s the %2$s because the following error occurred: %3$s',
4265
+						'event_espresso'
4266
+					),
4267
+					$action,
4268
+					$entity_model->get_this_model_name(),
4269
+					$exception->getMessage()
4270
+				)
4271
+			);
4272
+		}
4273
+		throw new RuntimeException(
4274
+			sprintf(
4275
+				esc_html__(
4276
+					'Could not %1$s the %2$s because an invalid ID was received.',
4277
+					'event_espresso'
4278
+				),
4279
+				$action,
4280
+				$entity_model->get_this_model_name()
4281
+			)
4282
+		);
4283
+	}
4284 4284
 }
Please login to merge, or discard this patch.
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
         $ee_menu_slugs = (array) $ee_menu_slugs;
629 629
         if (
630 630
             ! $this->request->isAjax()
631
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
631
+            && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))
632 632
         ) {
633 633
             return;
634 634
         }
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
             : $req_action;
649 649
 
650 650
         $this->_current_view = $this->_req_action;
651
-        $this->_req_nonce    = $this->_req_action . '_nonce';
651
+        $this->_req_nonce    = $this->_req_action.'_nonce';
652 652
         $this->_define_page_props();
653 653
         $this->_current_page_view_url = add_query_arg(
654 654
             ['page' => $this->_current_page, 'action' => $this->_current_view],
@@ -678,33 +678,33 @@  discard block
 block discarded – undo
678 678
         }
679 679
         // filter routes and page_config so addons can add their stuff. Filtering done per class
680 680
         $this->_page_routes = apply_filters(
681
-            'FHEE__' . $this->class_name . '__page_setup__page_routes',
681
+            'FHEE__'.$this->class_name.'__page_setup__page_routes',
682 682
             $this->_page_routes,
683 683
             $this
684 684
         );
685 685
         $this->_page_config = apply_filters(
686
-            'FHEE__' . $this->class_name . '__page_setup__page_config',
686
+            'FHEE__'.$this->class_name.'__page_setup__page_config',
687 687
             $this->_page_config,
688 688
             $this
689 689
         );
690 690
         if ($this->base_class_name !== '') {
691 691
             $this->_page_routes = apply_filters(
692
-                'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
692
+                'FHEE__'.$this->base_class_name.'__page_setup__page_routes',
693 693
                 $this->_page_routes,
694 694
                 $this
695 695
             );
696 696
             $this->_page_config = apply_filters(
697
-                'FHEE__' . $this->base_class_name . '__page_setup__page_config',
697
+                'FHEE__'.$this->base_class_name.'__page_setup__page_config',
698 698
                 $this->_page_config,
699 699
                 $this
700 700
             );
701 701
         }
702 702
         // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
703 703
         // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
704
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
704
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
705 705
             add_action(
706 706
                 'AHEE__EE_Admin_Page__route_admin_request',
707
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
707
+                [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view],
708 708
                 10,
709 709
                 2
710 710
             );
@@ -717,8 +717,8 @@  discard block
 block discarded – undo
717 717
             if ($this->_is_UI_request) {
718 718
                 // admin_init stuff - global, all views for this page class, specific view
719 719
                 add_action('admin_init', [$this, 'admin_init'], 10);
720
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
721
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
720
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
721
+                    add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15);
722 722
                 }
723 723
             } else {
724 724
                 // hijack regular WP loading and route admin request immediately
@@ -737,12 +737,12 @@  discard block
 block discarded – undo
737 737
      */
738 738
     private function _do_other_page_hooks()
739 739
     {
740
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
740
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []);
741 741
         foreach ($registered_pages as $page) {
742 742
             // now let's setup the file name and class that should be present
743 743
             $classname = str_replace('.class.php', '', $page);
744 744
             // autoloaders should take care of loading file
745
-            if (! class_exists($classname)) {
745
+            if ( ! class_exists($classname)) {
746 746
                 $error_msg[] = sprintf(
747 747
                     esc_html__(
748 748
                         'Something went wrong with loading the %s admin hooks page.',
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
                                    ),
760 760
                                    $page,
761 761
                                    '<br />',
762
-                                   '<strong>' . $classname . '</strong>'
762
+                                   '<strong>'.$classname.'</strong>'
763 763
                                );
764 764
                 throw new EE_Error(implode('||', $error_msg));
765 765
             }
@@ -801,13 +801,13 @@  discard block
 block discarded – undo
801 801
         // load admin_notices - global, page class, and view specific
802 802
         add_action('admin_notices', [$this, 'admin_notices_global'], 5);
803 803
         add_action('admin_notices', [$this, 'admin_notices'], 10);
804
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
805
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
804
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
805
+            add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15);
806 806
         }
807 807
         // load network admin_notices - global, page class, and view specific
808 808
         add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
809
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
810
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
809
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
810
+            add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]);
811 811
         }
812 812
         // this will save any per_page screen options if they are present
813 813
         $this->_set_per_page_screen_options();
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
     protected function _verify_routes()
929 929
     {
930 930
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
931
-        if (! $this->_current_page && ! $this->request->isAjax()) {
931
+        if ( ! $this->_current_page && ! $this->request->isAjax()) {
932 932
             return false;
933 933
         }
934 934
         $this->_route = false;
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
                 $this->_admin_page_title
941 941
             );
942 942
             // developer error msg
943
-            $error_msg .= '||' . $error_msg
943
+            $error_msg .= '||'.$error_msg
944 944
                           . esc_html__(
945 945
                               ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
946 946
                               'event_espresso'
@@ -949,8 +949,8 @@  discard block
 block discarded – undo
949 949
         }
950 950
         // and that the requested page route exists
951 951
         if (array_key_exists($this->_req_action, $this->_page_routes)) {
952
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
953
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
952
+            $this->_route        = $this->_page_routes[$this->_req_action];
953
+            $this->_route_config = $this->_page_config[$this->_req_action] ?? [];
954 954
         } else {
955 955
             // user error msg
956 956
             $error_msg = sprintf(
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
                 $this->_admin_page_title
962 962
             );
963 963
             // developer error msg
964
-            $error_msg .= '||' . $error_msg
964
+            $error_msg .= '||'.$error_msg
965 965
                           . sprintf(
966 966
                               esc_html__(
967 967
                                   ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
             throw new EE_Error($error_msg);
973 973
         }
974 974
         // and that a default route exists
975
-        if (! array_key_exists('default', $this->_page_routes)) {
975
+        if ( ! array_key_exists('default', $this->_page_routes)) {
976 976
             // user error msg
977 977
             $error_msg = sprintf(
978 978
                 esc_html__(
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 $this->_admin_page_title
983 983
             );
984 984
             // developer error msg
985
-            $error_msg .= '||' . $error_msg
985
+            $error_msg .= '||'.$error_msg
986 986
                           . esc_html__(
987 987
                               ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
988 988
                               'event_espresso'
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
             $this->_admin_page_title
1025 1025
         );
1026 1026
         // developer error msg
1027
-        $error_msg .= '||' . $error_msg
1027
+        $error_msg .= '||'.$error_msg
1028 1028
                       . sprintf(
1029 1029
                           esc_html__(
1030 1030
                               ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
     protected function _verify_nonce($nonce, $nonce_ref)
1053 1053
     {
1054 1054
         // verify nonce against expected value
1055
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1055
+        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
1056 1056
             // these are not the droids you are looking for !!!
1057 1057
             $msg = sprintf(
1058 1058
                 esc_html__('%sNonce Fail.%s', 'event_espresso'),
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
                     __CLASS__
1070 1070
                 );
1071 1071
             }
1072
-            if (! $this->request->isAjax()) {
1072
+            if ( ! $this->request->isAjax()) {
1073 1073
                 wp_die($msg);
1074 1074
             }
1075 1075
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
      */
1094 1094
     protected function _route_admin_request()
1095 1095
     {
1096
-        if (! $this->_is_UI_request) {
1096
+        if ( ! $this->_is_UI_request) {
1097 1097
             $this->_verify_routes();
1098 1098
         }
1099 1099
         $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
         $error_msg = '';
1114 1114
         // action right before calling route
1115 1115
         // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1116
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1116
+        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1117 1117
             do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1118 1118
         }
1119 1119
         // strip _wp_http_referer from the server REQUEST_URI
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
         );
1126 1126
         // set new value in both our Request object and the super global
1127 1127
         $this->request->setServerParam('REQUEST_URI', $request_uri, true);
1128
-        if (! empty($func)) {
1128
+        if ( ! empty($func)) {
1129 1129
             if (is_array($func)) {
1130 1130
                 [$class, $method] = $func;
1131 1131
             } elseif (strpos($func, '::') !== false) {
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
                 $class  = $this;
1135 1135
                 $method = $func;
1136 1136
             }
1137
-            if (! (is_object($class) && $class === $this)) {
1137
+            if ( ! (is_object($class) && $class === $this)) {
1138 1138
                 // send along this admin page object for access by addons.
1139 1139
                 $args['admin_page_object'] = $this;
1140 1140
             }
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
                     $method
1176 1176
                 );
1177 1177
             }
1178
-            if (! empty($error_msg)) {
1178
+            if ( ! empty($error_msg)) {
1179 1179
                 throw new EE_Error($error_msg);
1180 1180
             }
1181 1181
         }
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
                 if (strpos($key, 'nonce') !== false) {
1262 1262
                     continue;
1263 1263
                 }
1264
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1264
+                $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value;
1265 1265
             }
1266 1266
         }
1267 1267
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1301,12 +1301,12 @@  discard block
 block discarded – undo
1301 1301
      */
1302 1302
     protected function _add_help_tabs()
1303 1303
     {
1304
-        if (isset($this->_page_config[ $this->_req_action ])) {
1305
-            $config = $this->_page_config[ $this->_req_action ];
1304
+        if (isset($this->_page_config[$this->_req_action])) {
1305
+            $config = $this->_page_config[$this->_req_action];
1306 1306
             // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1307 1307
             if (is_array($config) && isset($config['help_sidebar'])) {
1308 1308
                 // check that the callback given is valid
1309
-                if (! method_exists($this, $config['help_sidebar'])) {
1309
+                if ( ! method_exists($this, $config['help_sidebar'])) {
1310 1310
                     throw new EE_Error(
1311 1311
                         sprintf(
1312 1312
                             esc_html__(
@@ -1319,18 +1319,18 @@  discard block
 block discarded – undo
1319 1319
                     );
1320 1320
                 }
1321 1321
                 $content = apply_filters(
1322
-                    'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1322
+                    'FHEE__'.$this->class_name.'__add_help_tabs__help_sidebar',
1323 1323
                     $this->{$config['help_sidebar']}()
1324 1324
                 );
1325 1325
                 $this->_current_screen->set_help_sidebar($content);
1326 1326
             }
1327
-            if (! isset($config['help_tabs'])) {
1327
+            if ( ! isset($config['help_tabs'])) {
1328 1328
                 return;
1329 1329
             } //no help tabs for this route
1330 1330
             foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1331 1331
                 // we're here so there ARE help tabs!
1332 1332
                 // make sure we've got what we need
1333
-                if (! isset($cfg['title'])) {
1333
+                if ( ! isset($cfg['title'])) {
1334 1334
                     throw new EE_Error(
1335 1335
                         esc_html__(
1336 1336
                             'The _page_config array is not set up properly for help tabs.  It is missing a title',
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
                         )
1339 1339
                     );
1340 1340
                 }
1341
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1341
+                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1342 1342
                     throw new EE_Error(
1343 1343
                         esc_html__(
1344 1344
                             'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
@@ -1347,11 +1347,11 @@  discard block
 block discarded – undo
1347 1347
                     );
1348 1348
                 }
1349 1349
                 // first priority goes to content.
1350
-                if (! empty($cfg['content'])) {
1350
+                if ( ! empty($cfg['content'])) {
1351 1351
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1352 1352
                     // second priority goes to filename
1353
-                } elseif (! empty($cfg['filename'])) {
1354
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1353
+                } elseif ( ! empty($cfg['filename'])) {
1354
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1355 1355
                     // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1356 1356
                     $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1357 1357
                                                              . basename($this->_get_dir())
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
                                                              . $cfg['filename']
1360 1360
                                                              . '.help_tab.php' : $file_path;
1361 1361
                     // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1362
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1362
+                    if ( ! isset($cfg['callback']) && ! is_readable($file_path)) {
1363 1363
                         EE_Error::add_error(
1364 1364
                             sprintf(
1365 1365
                                 esc_html__(
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
                     return;
1408 1408
                 }
1409 1409
                 // setup config array for help tab method
1410
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1410
+                $id  = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1411 1411
                 $_ht = [
1412 1412
                     'id'       => $id,
1413 1413
                     'title'    => $cfg['title'],
@@ -1433,8 +1433,8 @@  discard block
 block discarded – undo
1433 1433
             $qtips = (array) $this->_route_config['qtips'];
1434 1434
             // load qtip loader
1435 1435
             $path = [
1436
-                $this->_get_dir() . '/qtips/',
1437
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1436
+                $this->_get_dir().'/qtips/',
1437
+                EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1438 1438
             ];
1439 1439
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1440 1440
         }
@@ -1456,7 +1456,7 @@  discard block
 block discarded – undo
1456 1456
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1457 1457
         $i = 0;
1458 1458
         foreach ($this->_page_config as $slug => $config) {
1459
-            if (! is_array($config) || empty($config['nav'])) {
1459
+            if ( ! is_array($config) || empty($config['nav'])) {
1460 1460
                 continue;
1461 1461
             }
1462 1462
             // no nav tab for this config
@@ -1465,12 +1465,12 @@  discard block
 block discarded – undo
1465 1465
                 // nav tab is only to appear when route requested.
1466 1466
                 continue;
1467 1467
             }
1468
-            if (! $this->check_user_access($slug, true)) {
1468
+            if ( ! $this->check_user_access($slug, true)) {
1469 1469
                 // no nav tab because current user does not have access.
1470 1470
                 continue;
1471 1471
             }
1472
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1473
-            $this->_nav_tabs[ $slug ] = [
1472
+            $css_class                = isset($config['css_class']) ? $config['css_class'].' ' : '';
1473
+            $this->_nav_tabs[$slug] = [
1474 1474
                 'url'       => isset($config['nav']['url'])
1475 1475
                     ? $config['nav']['url']
1476 1476
                     : EE_Admin_Page::add_query_args_and_nonce(
@@ -1482,14 +1482,14 @@  discard block
 block discarded – undo
1482 1482
                     : ucwords(
1483 1483
                         str_replace('_', ' ', $slug)
1484 1484
                     ),
1485
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1485
+                'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class,
1486 1486
                 'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1487 1487
             ];
1488 1488
             $i++;
1489 1489
         }
1490 1490
         // if $this->_nav_tabs is empty then lets set the default
1491 1491
         if (empty($this->_nav_tabs)) {
1492
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1492
+            $this->_nav_tabs[$this->_default_nav_tab_name] = [
1493 1493
                 'url'       => $this->_admin_base_url,
1494 1494
                 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1495 1495
                 'css_class' => 'nav-tab-active',
@@ -1514,10 +1514,10 @@  discard block
 block discarded – undo
1514 1514
             foreach ($this->_route_config['labels'] as $label => $text) {
1515 1515
                 if (is_array($text)) {
1516 1516
                     foreach ($text as $sublabel => $subtext) {
1517
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1517
+                        $this->_labels[$label][$sublabel] = $subtext;
1518 1518
                     }
1519 1519
                 } else {
1520
-                    $this->_labels[ $label ] = $text;
1520
+                    $this->_labels[$label] = $text;
1521 1521
                 }
1522 1522
             }
1523 1523
         }
@@ -1539,10 +1539,10 @@  discard block
 block discarded – undo
1539 1539
     {
1540 1540
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1541 1541
         $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1542
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1543
-                          && is_array($this->_page_routes[ $route_to_check ])
1544
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1545
-            ? $this->_page_routes[ $route_to_check ]['capability']
1542
+        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1543
+                          && is_array($this->_page_routes[$route_to_check])
1544
+                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1545
+            ? $this->_page_routes[$route_to_check]['capability']
1546 1546
 			: null;
1547 1547
 
1548 1548
         if (empty($capability) && empty($route_to_check)) {
@@ -1596,14 +1596,14 @@  discard block
 block discarded – undo
1596 1596
         string $priority = 'default',
1597 1597
         ?array $callback_args = null
1598 1598
     ) {
1599
-        if (! is_callable($callback)) {
1599
+        if ( ! is_callable($callback)) {
1600 1600
             return;
1601 1601
         }
1602 1602
 
1603 1603
         add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1604 1604
         add_filter(
1605 1605
             "postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1606
-            function ($classes) {
1606
+            function($classes) {
1607 1607
                 array_push($classes, 'ee-admin-container');
1608 1608
                 return $classes;
1609 1609
             }
@@ -1697,7 +1697,7 @@  discard block
 block discarded – undo
1697 1697
         ';
1698 1698
 
1699 1699
         // current set timezone for timezone js
1700
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1700
+        echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>';
1701 1701
     }
1702 1702
 
1703 1703
 
@@ -1731,7 +1731,7 @@  discard block
 block discarded – undo
1731 1731
         // loop through the array and setup content
1732 1732
         foreach ($help_array as $trigger => $help) {
1733 1733
             // make sure the array is setup properly
1734
-            if (! isset($help['title'], $help['content'])) {
1734
+            if ( ! isset($help['title'], $help['content'])) {
1735 1735
                 throw new EE_Error(
1736 1736
                     esc_html__(
1737 1737
                         'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
@@ -1745,8 +1745,8 @@  discard block
 block discarded – undo
1745 1745
                 'help_popup_title'   => $help['title'],
1746 1746
                 'help_popup_content' => $help['content'],
1747 1747
             ];
1748
-            $content       .= EEH_Template::display_template(
1749
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1748
+            $content .= EEH_Template::display_template(
1749
+                EE_ADMIN_TEMPLATE.'admin_help_popup.template.php',
1750 1750
                 $template_args,
1751 1751
                 true
1752 1752
             );
@@ -1768,15 +1768,15 @@  discard block
 block discarded – undo
1768 1768
     private function _get_help_content()
1769 1769
     {
1770 1770
         // what is the method we're looking for?
1771
-        $method_name = '_help_popup_content_' . $this->_req_action;
1771
+        $method_name = '_help_popup_content_'.$this->_req_action;
1772 1772
         // if method doesn't exist let's get out.
1773
-        if (! method_exists($this, $method_name)) {
1773
+        if ( ! method_exists($this, $method_name)) {
1774 1774
             return [];
1775 1775
         }
1776 1776
         // k we're good to go let's retrieve the help array
1777 1777
         $help_array = $this->{$method_name}();
1778 1778
         // make sure we've got an array!
1779
-        if (! is_array($help_array)) {
1779
+        if ( ! is_array($help_array)) {
1780 1780
             throw new EE_Error(
1781 1781
                 esc_html__(
1782 1782
                     'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
@@ -1808,8 +1808,8 @@  discard block
 block discarded – undo
1808 1808
         // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1809 1809
         $help_array   = $this->_get_help_content();
1810 1810
         $help_content = '';
1811
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1812
-            $help_array[ $trigger_id ] = [
1811
+        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1812
+            $help_array[$trigger_id] = [
1813 1813
                 'title'   => esc_html__('Missing Content', 'event_espresso'),
1814 1814
                 'content' => esc_html__(
1815 1815
                     'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
@@ -1904,7 +1904,7 @@  discard block
 block discarded – undo
1904 1904
 
1905 1905
         add_filter(
1906 1906
             'admin_body_class',
1907
-            function ($classes) {
1907
+            function($classes) {
1908 1908
                 if (strpos($classes, 'espresso-admin') === false) {
1909 1909
                     $classes .= ' espresso-admin';
1910 1910
                 }
@@ -1995,12 +1995,12 @@  discard block
 block discarded – undo
1995 1995
     protected function _set_list_table()
1996 1996
     {
1997 1997
         // first is this a list_table view?
1998
-        if (! isset($this->_route_config['list_table'])) {
1998
+        if ( ! isset($this->_route_config['list_table'])) {
1999 1999
             return;
2000 2000
         } //not a list_table view so get out.
2001 2001
         // list table functions are per view specific (because some admin pages might have more than one list table!)
2002
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2003
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2002
+        $list_table_view = '_set_list_table_views_'.$this->_req_action;
2003
+        if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2004 2004
             // user error msg
2005 2005
             $error_msg = esc_html__(
2006 2006
                 'An error occurred. The requested list table views could not be found.',
@@ -2020,10 +2020,10 @@  discard block
 block discarded – undo
2020 2020
         }
2021 2021
         // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2022 2022
         $this->_views = apply_filters(
2023
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2023
+            'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action,
2024 2024
             $this->_views
2025 2025
         );
2026
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2026
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
2027 2027
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2028 2028
         $this->_set_list_table_view();
2029 2029
         $this->_set_list_table_object();
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
     protected function _set_list_table_object()
2059 2059
     {
2060 2060
         if (isset($this->_route_config['list_table'])) {
2061
-            if (! class_exists($this->_route_config['list_table'])) {
2061
+            if ( ! class_exists($this->_route_config['list_table'])) {
2062 2062
                 throw new EE_Error(
2063 2063
                     sprintf(
2064 2064
                         esc_html__(
@@ -2096,17 +2096,17 @@  discard block
 block discarded – undo
2096 2096
         foreach ($this->_views as $key => $view) {
2097 2097
             $query_args = [];
2098 2098
             // check for current view
2099
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2099
+            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2100 2100
             $query_args['action']                        = $this->_req_action;
2101
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2101
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
2102 2102
             $query_args['status']                        = $view['slug'];
2103 2103
             // merge any other arguments sent in.
2104
-            if (isset($extra_query_args[ $view['slug'] ])) {
2105
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2104
+            if (isset($extra_query_args[$view['slug']])) {
2105
+                foreach ($extra_query_args[$view['slug']] as $extra_query_arg) {
2106 2106
                     $query_args[] = $extra_query_arg;
2107 2107
                 }
2108 2108
             }
2109
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2109
+            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2110 2110
         }
2111 2111
         return $this->_views;
2112 2112
     }
@@ -2137,14 +2137,14 @@  discard block
 block discarded – undo
2137 2137
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2138 2138
         foreach ($values as $value) {
2139 2139
             if ($value < $max_entries) {
2140
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2140
+                $selected = $value === $per_page ? ' selected="'.$per_page.'"' : '';
2141 2141
                 $entries_per_page_dropdown .= '
2142
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2142
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
2143 2143
             }
2144 2144
         }
2145
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2145
+        $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : '';
2146 2146
         $entries_per_page_dropdown .= '
2147
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2147
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
2148 2148
         $entries_per_page_dropdown .= '
2149 2149
 					</select>
2150 2150
 					entries
@@ -2168,7 +2168,7 @@  discard block
 block discarded – undo
2168 2168
             empty($this->_search_btn_label) ? $this->page_label
2169 2169
                 : $this->_search_btn_label
2170 2170
         );
2171
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2171
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
2172 2172
     }
2173 2173
 
2174 2174
 
@@ -2256,7 +2256,7 @@  discard block
 block discarded – undo
2256 2256
             $total_columns                                       = ! empty($screen_columns)
2257 2257
                 ? $screen_columns
2258 2258
                 : $this->_route_config['columns'][1];
2259
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2259
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
2260 2260
             $this->_template_args['current_page']                = $this->_wp_page_slug;
2261 2261
             $this->_template_args['screen']                      = $this->_current_screen;
2262 2262
             $this->_column_template_path                         = EE_ADMIN_TEMPLATE
@@ -2302,7 +2302,7 @@  discard block
 block discarded – undo
2302 2302
      */
2303 2303
     protected function _espresso_ratings_request()
2304 2304
     {
2305
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2305
+        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2306 2306
             return;
2307 2307
         }
2308 2308
         $ratings_box_title = apply_filters(
@@ -2329,28 +2329,28 @@  discard block
 block discarded – undo
2329 2329
      */
2330 2330
     public function espresso_ratings_request()
2331 2331
     {
2332
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2332
+        EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php');
2333 2333
     }
2334 2334
 
2335 2335
 
2336 2336
     public static function cached_rss_display($rss_id, $url)
2337 2337
     {
2338
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2338
+        $loading = '<p class="widget-loading hide-if-no-js">'
2339 2339
                      . esc_html__('Loading&#8230;', 'event_espresso')
2340 2340
                      . '</p><p class="hide-if-js">'
2341 2341
                      . esc_html__('This widget requires JavaScript.', 'event_espresso')
2342 2342
                      . '</p>';
2343
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2344
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2345
-        $post      = '</div>' . "\n";
2346
-        $cache_key = 'ee_rss_' . md5($rss_id);
2343
+        $pre       = '<div class="espresso-rss-display">'."\n\t";
2344
+        $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>';
2345
+        $post      = '</div>'."\n";
2346
+        $cache_key = 'ee_rss_'.md5($rss_id);
2347 2347
         $output    = get_transient($cache_key);
2348 2348
         if ($output !== false) {
2349
-            echo $pre . $output . $post; // already escaped
2349
+            echo $pre.$output.$post; // already escaped
2350 2350
             return true;
2351 2351
         }
2352
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
-            echo $pre . $loading . $post; // already escaped
2352
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
+            echo $pre.$loading.$post; // already escaped
2354 2354
             return false;
2355 2355
         }
2356 2356
         ob_start();
@@ -2417,19 +2417,19 @@  discard block
 block discarded – undo
2417 2417
     public function espresso_sponsors_post_box()
2418 2418
     {
2419 2419
         EEH_Template::display_template(
2420
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2420
+            EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'
2421 2421
         );
2422 2422
     }
2423 2423
 
2424 2424
 
2425 2425
     private function _publish_post_box()
2426 2426
     {
2427
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2427
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2428 2428
         // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2429 2429
         // then we'll use that for the metabox label.
2430 2430
         // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2431
-        if (! empty($this->_labels['publishbox'])) {
2432
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2431
+        if ( ! empty($this->_labels['publishbox'])) {
2432
+            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2433 2433
                 : $this->_labels['publishbox'];
2434 2434
         } else {
2435 2435
             $box_label = esc_html__('Publish', 'event_espresso');
@@ -2458,7 +2458,7 @@  discard block
 block discarded – undo
2458 2458
             ? $this->_template_args['publish_box_extra_content']
2459 2459
             : '';
2460 2460
         echo EEH_Template::display_template(
2461
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2461
+            EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php',
2462 2462
             $this->_template_args,
2463 2463
             true
2464 2464
         );
@@ -2546,18 +2546,18 @@  discard block
 block discarded – undo
2546 2546
             );
2547 2547
         }
2548 2548
         $this->_template_args['publish_delete_link'] = $delete_link;
2549
-        if (! empty($name) && ! empty($id)) {
2550
-            $hidden_field_arr[ $name ] = [
2549
+        if ( ! empty($name) && ! empty($id)) {
2550
+            $hidden_field_arr[$name] = [
2551 2551
                 'type'  => 'hidden',
2552 2552
                 'value' => $id,
2553 2553
             ];
2554
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2554
+            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2555 2555
         } else {
2556 2556
             $hf = '';
2557 2557
         }
2558 2558
         // add hidden field
2559 2559
         $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2560
-            ? $hf[ $name ]['field']
2560
+            ? $hf[$name]['field']
2561 2561
             : $hf;
2562 2562
     }
2563 2563
 
@@ -2659,7 +2659,7 @@  discard block
 block discarded – undo
2659 2659
         }
2660 2660
         // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2661 2661
         $call_back_func = $create_func
2662
-            ? static function ($post, $metabox) {
2662
+            ? static function($post, $metabox) {
2663 2663
                 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2664 2664
                 echo EEH_Template::display_template(
2665 2665
                     $metabox['args']['template_path'],
@@ -2669,7 +2669,7 @@  discard block
 block discarded – undo
2669 2669
             }
2670 2670
             : $callback;
2671 2671
         $this->addMetaBox(
2672
-            str_replace('_', '-', $action) . '-mbox',
2672
+            str_replace('_', '-', $action).'-mbox',
2673 2673
             $title,
2674 2674
             $call_back_func,
2675 2675
             $this->_wp_page_slug,
@@ -2786,13 +2786,13 @@  discard block
 block discarded – undo
2786 2786
             'event-espresso_page_espresso_',
2787 2787
             '',
2788 2788
             $this->_wp_page_slug
2789
-        ) . ' ' . $this->_req_action . '-route';
2789
+        ).' '.$this->_req_action.'-route';
2790 2790
 
2791 2791
         $template_path = $sidebar
2792 2792
             ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2793
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2793
+            : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2794 2794
         if ($this->request->isAjax()) {
2795
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2795
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2796 2796
         }
2797 2797
         $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2798 2798
 
@@ -2826,11 +2826,11 @@  discard block
 block discarded – undo
2826 2826
     public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2827 2827
     {
2828 2828
         // let's generate a default preview action button if there isn't one already present.
2829
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2829
+        $this->_labels['buttons']['buy_now'] = esc_html__(
2830 2830
             'Upgrade to Event Espresso 4 Right Now',
2831 2831
             'event_espresso'
2832 2832
         );
2833
-        $buy_now_url                                   = add_query_arg(
2833
+        $buy_now_url = add_query_arg(
2834 2834
             [
2835 2835
                 'ee_ver'       => 'ee4',
2836 2836
                 'utm_source'   => 'ee4_plugin_admin',
@@ -2850,8 +2850,8 @@  discard block
 block discarded – undo
2850 2850
                 true
2851 2851
             )
2852 2852
             : $this->_template_args['preview_action_button'];
2853
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2854
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2853
+        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2854
+            EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php',
2855 2855
             $this->_template_args,
2856 2856
             true
2857 2857
         );
@@ -2909,7 +2909,7 @@  discard block
 block discarded – undo
2909 2909
         // setup search attributes
2910 2910
         $this->_set_search_attributes();
2911 2911
         $this->_template_args['current_page']     = $this->_wp_page_slug;
2912
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2912
+        $template_path                            = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2913 2913
         $this->_template_args['table_url']        = $this->request->isAjax()
2914 2914
             ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2915 2915
             : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
@@ -2917,10 +2917,10 @@  discard block
 block discarded – undo
2917 2917
         $this->_template_args['current_route']    = $this->_req_action;
2918 2918
         $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2919 2919
         $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2920
-        if (! empty($ajax_sorting_callback)) {
2920
+        if ( ! empty($ajax_sorting_callback)) {
2921 2921
             $sortable_list_table_form_fields = wp_nonce_field(
2922
-                $ajax_sorting_callback . '_nonce',
2923
-                $ajax_sorting_callback . '_nonce',
2922
+                $ajax_sorting_callback.'_nonce',
2923
+                $ajax_sorting_callback.'_nonce',
2924 2924
                 false,
2925 2925
                 false
2926 2926
             );
@@ -2937,18 +2937,18 @@  discard block
 block discarded – undo
2937 2937
 
2938 2938
         $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
2939 2939
 
2940
-        $nonce_ref          = $this->_req_action . '_nonce';
2940
+        $nonce_ref          = $this->_req_action.'_nonce';
2941 2941
         $hidden_form_fields .= '
2942
-            <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2942
+            <input type="hidden" name="' . $nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2943 2943
 
2944
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2944
+        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2945 2945
         // display message about search results?
2946 2946
         $search = $this->request->getRequestParam('s');
2947 2947
         $this->_template_args['before_list_table'] .= ! empty($search)
2948
-            ? '<p class="ee-search-results">' . sprintf(
2948
+            ? '<p class="ee-search-results">'.sprintf(
2949 2949
                 esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2950 2950
                 trim($search, '%')
2951
-            ) . '</p>'
2951
+            ).'</p>'
2952 2952
             : '';
2953 2953
         // filter before_list_table template arg
2954 2954
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2982,7 +2982,7 @@  discard block
 block discarded – undo
2982 2982
         // convert to array and filter again
2983 2983
         // arrays are easier to inject new items in a specific location,
2984 2984
         // but would not be backwards compatible, so we have to add a new filter
2985
-        $this->_template_args['after_list_table']   = implode(
2985
+        $this->_template_args['after_list_table'] = implode(
2986 2986
             " \n",
2987 2987
             (array) apply_filters(
2988 2988
                 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
@@ -3037,7 +3037,7 @@  discard block
 block discarded – undo
3037 3037
             $this->page_slug
3038 3038
         );
3039 3039
         return EEH_Template::display_template(
3040
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3040
+            EE_ADMIN_TEMPLATE.'admin_details_legend.template.php',
3041 3041
             $this->_template_args,
3042 3042
             true
3043 3043
         );
@@ -3153,16 +3153,16 @@  discard block
 block discarded – undo
3153 3153
             $this->_template_args['before_admin_page_content'] ?? ''
3154 3154
         );
3155 3155
 
3156
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3156
+        $this->_template_args['after_admin_page_content'] = apply_filters(
3157 3157
             "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3158 3158
             $this->_template_args['after_admin_page_content'] ?? ''
3159 3159
         );
3160
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3160
+        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3161 3161
 
3162 3162
         if ($this->request->isAjax()) {
3163 3163
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3164 3164
                 // $template_path,
3165
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3165
+                EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php',
3166 3166
                 $this->_template_args,
3167 3167
                 true
3168 3168
             );
@@ -3171,7 +3171,7 @@  discard block
 block discarded – undo
3171 3171
         // load settings page wrapper template
3172 3172
         $template_path = $about
3173 3173
             ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3174
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3174
+            : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php';
3175 3175
 
3176 3176
         EEH_Template::display_template($template_path, $this->_template_args);
3177 3177
     }
@@ -3255,12 +3255,12 @@  discard block
 block discarded – undo
3255 3255
         $default_names = ['save', 'save_and_close'];
3256 3256
         $buttons = '';
3257 3257
         foreach ($button_text as $key => $button) {
3258
-            $ref     = $default_names[ $key ];
3259
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3260
-            $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3261
-                        . 'value="' . $button . '" name="' . $name . '" '
3262
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3263
-            if (! $both) {
3258
+            $ref     = $default_names[$key];
3259
+            $name    = ! empty($actions) ? $actions[$key] : $ref;
3260
+            $buttons .= '<input type="submit" class="button button--primary '.$ref.'" '
3261
+                        . 'value="'.$button.'" name="'.$name.'" '
3262
+                        . 'id="'.$this->_current_view.'_'.$ref.'" />';
3263
+            if ( ! $both) {
3264 3264
                 break;
3265 3265
             }
3266 3266
         }
@@ -3300,13 +3300,13 @@  discard block
 block discarded – undo
3300 3300
                 'An error occurred. No action was set for this page\'s form.',
3301 3301
                 'event_espresso'
3302 3302
             );
3303
-            $dev_msg  = $user_msg . "\n"
3303
+            $dev_msg = $user_msg."\n"
3304 3304
                         . sprintf(
3305 3305
                             esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3306 3306
                             __FUNCTION__,
3307 3307
                             __CLASS__
3308 3308
                         );
3309
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3309
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
3310 3310
         }
3311 3311
         // open form
3312 3312
         $action = $this->_admin_base_url;
@@ -3314,9 +3314,9 @@  discard block
 block discarded – undo
3314 3314
             <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' >
3315 3315
             ";
3316 3316
         // add nonce
3317
-        $nonce                                             =
3318
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3319
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3317
+        $nonce =
3318
+            wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
3319
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
3320 3320
         // add REQUIRED form action
3321 3321
         $hidden_fields = [
3322 3322
             'action' => ['type' => 'hidden', 'value' => $route],
@@ -3329,7 +3329,7 @@  discard block
 block discarded – undo
3329 3329
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3330 3330
         // add fields to form
3331 3331
         foreach ((array) $form_fields as $form_field) {
3332
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3332
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
3333 3333
         }
3334 3334
         // close form
3335 3335
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -3412,12 +3412,12 @@  discard block
 block discarded – undo
3412 3412
         bool $override_overwrite = false
3413 3413
     ) {
3414 3414
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3415
-        $notices      = EE_Error::get_notices(false);
3415
+        $notices = EE_Error::get_notices(false);
3416 3416
         // overwrite default success messages //BUT ONLY if overwrite not overridden
3417
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3417
+        if ( ! $override_overwrite || ! empty($notices['errors'])) {
3418 3418
             EE_Error::overwrite_success();
3419 3419
         }
3420
-        if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3420
+        if ( ! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3421 3421
             // how many records affected ? more than one record ? or just one ?
3422 3422
             EE_Error::add_success(
3423 3423
                 sprintf(
@@ -3438,7 +3438,7 @@  discard block
 block discarded – undo
3438 3438
             );
3439 3439
         }
3440 3440
         // check that $query_args isn't something crazy
3441
-        if (! is_array($query_args)) {
3441
+        if ( ! is_array($query_args)) {
3442 3442
             $query_args = [];
3443 3443
         }
3444 3444
         /**
@@ -3470,7 +3470,7 @@  discard block
 block discarded – undo
3470 3470
             $redirect_url = admin_url('admin.php');
3471 3471
         }
3472 3472
         // merge any default query_args set in _default_route_query_args property
3473
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3473
+        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3474 3474
             $args_to_merge = [];
3475 3475
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
3476 3476
                 // is there a wp_referer array in our _default_route_query_args property?
@@ -3482,15 +3482,15 @@  discard block
 block discarded – undo
3482 3482
                         }
3483 3483
                         // finally we will override any arguments in the referer with
3484 3484
                         // what might be set on the _default_route_query_args array.
3485
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3486
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3485
+                        if (isset($this->_default_route_query_args[$reference])) {
3486
+                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3487 3487
                         } else {
3488
-                            $args_to_merge[ $reference ] = urlencode($value);
3488
+                            $args_to_merge[$reference] = urlencode($value);
3489 3489
                         }
3490 3490
                     }
3491 3491
                     continue;
3492 3492
                 }
3493
-                $args_to_merge[ $query_param ] = $query_value;
3493
+                $args_to_merge[$query_param] = $query_value;
3494 3494
             }
3495 3495
             // now let's merge these arguments but override with what was specifically sent in to the
3496 3496
             // redirect.
@@ -3502,19 +3502,19 @@  discard block
 block discarded – undo
3502 3502
         if (isset($query_args['action'])) {
3503 3503
             // manually generate wp_nonce and merge that with the query vars
3504 3504
             // becuz the wp_nonce_url function wrecks havoc on some vars
3505
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3505
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
3506 3506
         }
3507 3507
         // we're adding some hooks and filters in here for processing any things just before redirects
3508 3508
         // (example: an admin page has done an insert or update and we want to run something after that).
3509
-        do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3509
+        do_action('AHEE_redirect_'.$this->class_name.$this->_req_action, $query_args);
3510 3510
         $redirect_url = apply_filters(
3511
-            'FHEE_redirect_' . $this->class_name . $this->_req_action,
3511
+            'FHEE_redirect_'.$this->class_name.$this->_req_action,
3512 3512
             EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3513 3513
             $query_args
3514 3514
         );
3515 3515
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3516 3516
         if ($this->request->isAjax()) {
3517
-            $default_data                    = [
3517
+            $default_data = [
3518 3518
                 'close'        => true,
3519 3519
                 'redirect_url' => $redirect_url,
3520 3520
                 'where'        => 'main',
@@ -3564,7 +3564,7 @@  discard block
 block discarded – undo
3564 3564
         }
3565 3565
         $this->_template_args['notices'] = EE_Error::get_notices();
3566 3566
         // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3567
-        if (! $this->request->isAjax() || $sticky_notices) {
3567
+        if ( ! $this->request->isAjax() || $sticky_notices) {
3568 3568
             $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3569 3569
             $this->_add_transient(
3570 3570
                 $route,
@@ -3604,7 +3604,7 @@  discard block
 block discarded – undo
3604 3604
         $exclude_nonce = false
3605 3605
     ) {
3606 3606
         // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3607
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3607
+        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3608 3608
             throw new EE_Error(
3609 3609
                 sprintf(
3610 3610
                     esc_html__(
@@ -3615,7 +3615,7 @@  discard block
 block discarded – undo
3615 3615
                 )
3616 3616
             );
3617 3617
         }
3618
-        if (! isset($this->_labels['buttons'][ $type ])) {
3618
+        if ( ! isset($this->_labels['buttons'][$type])) {
3619 3619
             throw new EE_Error(
3620 3620
                 sprintf(
3621 3621
                     esc_html__(
@@ -3628,7 +3628,7 @@  discard block
 block discarded – undo
3628 3628
         }
3629 3629
         // finally check user access for this button.
3630 3630
         $has_access = $this->check_user_access($action, true);
3631
-        if (! $has_access) {
3631
+        if ( ! $has_access) {
3632 3632
             return '';
3633 3633
         }
3634 3634
         $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
@@ -3636,11 +3636,11 @@  discard block
 block discarded – undo
3636 3636
             'action' => $action,
3637 3637
         ];
3638 3638
         // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3639
-        if (! empty($extra_request)) {
3639
+        if ( ! empty($extra_request)) {
3640 3640
             $query_args = array_merge($extra_request, $query_args);
3641 3641
         }
3642 3642
         $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3643
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3643
+        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3644 3644
     }
3645 3645
 
3646 3646
 
@@ -3666,7 +3666,7 @@  discard block
 block discarded – undo
3666 3666
                 'FHEE__EE_Admin_Page___per_page_screen_options__default',
3667 3667
                 20
3668 3668
             ),
3669
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3669
+            'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3670 3670
         ];
3671 3671
         // ONLY add the screen option if the user has access to it.
3672 3672
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3687,18 +3687,18 @@  discard block
 block discarded – undo
3687 3687
     {
3688 3688
         if ($this->request->requestParamIsSet('wp_screen_options')) {
3689 3689
             check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3690
-            if (! $user = wp_get_current_user()) {
3690
+            if ( ! $user = wp_get_current_user()) {
3691 3691
                 return;
3692 3692
             }
3693 3693
             $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3694
-            if (! $option) {
3694
+            if ( ! $option) {
3695 3695
                 return;
3696 3696
             }
3697
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3697
+            $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3698 3698
             $map_option = $option;
3699 3699
             $option     = str_replace('-', '_', $option);
3700 3700
             switch ($map_option) {
3701
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3701
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3702 3702
                     $max_value = apply_filters(
3703 3703
                         'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3704 3704
                         999,
@@ -3755,13 +3755,13 @@  discard block
 block discarded – undo
3755 3755
     protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3756 3756
     {
3757 3757
         $user_id = get_current_user_id();
3758
-        if (! $skip_route_verify) {
3758
+        if ( ! $skip_route_verify) {
3759 3759
             $this->_verify_route($route);
3760 3760
         }
3761 3761
         // now let's set the string for what kind of transient we're setting
3762 3762
         $transient = $notices
3763
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3764
-            : 'rte_tx_' . $route . '_' . $user_id;
3763
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3764
+            : 'rte_tx_'.$route.'_'.$user_id;
3765 3765
         $data      = $notices ? ['notices' => $data] : $data;
3766 3766
         // is there already a transient for this route?  If there is then let's ADD to that transient
3767 3767
         $existing = is_multisite() && is_network_admin()
@@ -3790,8 +3790,8 @@  discard block
 block discarded – undo
3790 3790
         $user_id   = get_current_user_id();
3791 3791
         $route     = ! $route ? $this->_req_action : $route;
3792 3792
         $transient = $notices
3793
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3794
-            : 'rte_tx_' . $route . '_' . $user_id;
3793
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3794
+            : 'rte_tx_'.$route.'_'.$user_id;
3795 3795
         $data      = is_multisite() && is_network_admin()
3796 3796
             ? get_site_transient($transient)
3797 3797
             : get_transient($transient);
@@ -4027,7 +4027,7 @@  discard block
 block discarded – undo
4027 4027
      */
4028 4028
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4029 4029
     {
4030
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4030
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4031 4031
     }
4032 4032
 
4033 4033
 
@@ -4040,7 +4040,7 @@  discard block
 block discarded – undo
4040 4040
      */
4041 4041
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4042 4042
     {
4043
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4043
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4044 4044
     }
4045 4045
 
4046 4046
 
@@ -4188,7 +4188,7 @@  discard block
 block discarded – undo
4188 4188
         ?callable $callback = null
4189 4189
     ): bool {
4190 4190
         $entity_ID = absint($entity_ID);
4191
-        if (! $entity_ID) {
4191
+        if ( ! $entity_ID) {
4192 4192
             $this->trashRestoreDeleteError($action, $entity_model);
4193 4193
         }
4194 4194
         $result = 0;
@@ -4234,7 +4234,7 @@  discard block
 block discarded – undo
4234 4234
                 )
4235 4235
             );
4236 4236
         }
4237
-        if (! $entity_model->has_field($delete_column)) {
4237
+        if ( ! $entity_model->has_field($delete_column)) {
4238 4238
             throw new DomainException(
4239 4239
                 sprintf(
4240 4240
                     esc_html__(
Please login to merge, or discard this patch.