Completed
Branch FET-10416-autoload-b4-bootstra... (9a39f6)
by
unknown
119:38 queued 108:09
created
core/services/Benchmark.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     {
127 127
         add_action(
128 128
             'shutdown',
129
-            function () use ($formatted) {
129
+            function() use ($formatted) {
130 130
                 Benchmark::displayResults(true, $formatted);
131 131
             }
132 132
         );
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     {
147 147
         add_action(
148 148
             'shutdown',
149
-            function () use ($filepath, $formatted, $append) {
149
+            function() use ($filepath, $formatted, $append) {
150 150
                 Benchmark::writeResultsToFile($filepath, $formatted, $append);
151 151
             }
152 152
         );
@@ -164,17 +164,17 @@  discard block
 block discarded – undo
164 164
             return '';
165 165
         }
166 166
         $output = '';
167
-        if (! empty(Benchmark::$times)) {
167
+        if ( ! empty(Benchmark::$times)) {
168 168
             $total = 0;
169 169
             $output .= $formatted
170 170
                 ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
171 171
                 : '';
172 172
             foreach (Benchmark::$times as $timer_name => $total_time) {
173 173
                 $output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
174
-                $output .= $formatted ? '<br />'  : "\n";
174
+                $output .= $formatted ? '<br />' : "\n";
175 175
                 $total += $total_time;
176 176
             }
177
-            if($formatted) {
177
+            if ($formatted) {
178 178
                 $output .= '<br />';
179 179
                 $output .= '<h4>TOTAL TIME</h4>';
180 180
                 $output .= Benchmark::formatTime('', $total, $formatted);
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
                 $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
190 190
             }
191 191
         }
192
-        if (! empty(Benchmark::$memory_usage)) {
192
+        if ( ! empty(Benchmark::$memory_usage)) {
193 193
             $output .= $formatted
194
-                ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage)
194
+                ? '<h5>Memory</h5>'.implode('<br />', Benchmark::$memory_usage)
195 195
                 : implode("\n", Benchmark::$memory_usage);
196 196
         }
197 197
         if (empty($output)) {
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
         $filepath = ! empty($filepath) && is_readable(dirname($filepath))
240 240
             ? $filepath
241 241
             : '';
242
-        if( empty($filepath)) {
243
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
242
+        if (empty($filepath)) {
243
+            $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html';
244 244
         }
245 245
         file_put_contents(
246 246
             $filepath,
247
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
247
+            "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted),
248 248
             $append ? FILE_APPEND | LOCK_EX : LOCK_EX
249 249
         );
250 250
     }
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
         return round(
264 264
             $size / pow(1024, $i = floor(log($size, 1024))),
265 265
             2
266
-        ) . ' ' . $unit[absint($i)];
266
+        ).' '.$unit[absint($i)];
267 267
     }
268 268
 
269 269
 
Please login to merge, or discard this patch.
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -17,303 +17,303 @@
 block discarded – undo
17 17
 class Benchmark
18 18
 {
19 19
 
20
-    /**
21
-     * array containing the start time for the timers
22
-     */
23
-    private static $start_times;
24
-
25
-    /**
26
-     * array containing all the timer'd times, which can be outputted via show_times()
27
-     */
28
-    private static $times = array();
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    protected static $memory_usage = array();
34
-
35
-
36
-
37
-    /**
38
-     * whether to benchmark code or not
39
-     */
40
-    public static function doNotRun()
41
-    {
42
-        return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * resetTimes
49
-     */
50
-    public static function resetTimes()
51
-    {
52
-        Benchmark::$times = array();
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
-     *
60
-     * @param null $timer_name
61
-     */
62
-    public static function startTimer($timer_name = null)
63
-    {
64
-        if (Benchmark::doNotRun()) {
65
-            return;
66
-        }
67
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
-        Benchmark::$start_times[$timer_name] = microtime(true);
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
-     *
76
-     * @param string $timer_name
77
-     */
78
-    public static function stopTimer($timer_name = '')
79
-    {
80
-        if (Benchmark::doNotRun()) {
81
-            return;
82
-        }
83
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
-        if (isset(Benchmark::$start_times[$timer_name])) {
85
-            $start_time = Benchmark::$start_times[$timer_name];
86
-            unset(Benchmark::$start_times[$timer_name]);
87
-        } else {
88
-            $start_time = array_pop(Benchmark::$start_times);
89
-        }
90
-        Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * Measure the memory usage by PHP so far.
97
-     *
98
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
-     * @param bool    $formatted
101
-     * @return void
102
-     */
103
-    public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
104
-    {
105
-        if (Benchmark::doNotRun()) {
106
-            return;
107
-        }
108
-        $memory_used = Benchmark::convert(memory_get_usage(true));
109
-        Benchmark::$memory_usage[$label] = $memory_used;
110
-        if ($output_now) {
111
-            echo $formatted
112
-                ? "<br>{$label} : {$memory_used}"
113
-                : "\n {$label} : {$memory_used}";
114
-        }
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * will display the benchmarking results at shutdown
121
-     *
122
-     * @param bool $formatted
123
-     * @return void
124
-     */
125
-    public static function displayResultsAtShutdown($formatted = true)
126
-    {
127
-        add_action(
128
-            'shutdown',
129
-            function () use ($formatted) {
130
-                Benchmark::displayResults(true, $formatted);
131
-            }
132
-        );
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     * will display the benchmarking results at shutdown
139
-     *
140
-     * @param string $filepath
141
-     * @param bool   $formatted
142
-     * @param bool   $append
143
-     * @return void
144
-     */
145
-    public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
146
-    {
147
-        add_action(
148
-            'shutdown',
149
-            function () use ($filepath, $formatted, $append) {
150
-                Benchmark::writeResultsToFile($filepath, $formatted, $append);
151
-            }
152
-        );
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * @param bool $formatted
159
-     * @return string
160
-     */
161
-    private static function generateResults($formatted = true)
162
-    {
163
-        if (Benchmark::doNotRun()) {
164
-            return '';
165
-        }
166
-        $output = '';
167
-        if (! empty(Benchmark::$times)) {
168
-            $total = 0;
169
-            $output .= $formatted
170
-                ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
171
-                : '';
172
-            foreach (Benchmark::$times as $timer_name => $total_time) {
173
-                $output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
174
-                $output .= $formatted ? '<br />'  : "\n";
175
-                $total += $total_time;
176
-            }
177
-            if($formatted) {
178
-                $output .= '<br />';
179
-                $output .= '<h4>TOTAL TIME</h4>';
180
-                $output .= Benchmark::formatTime('', $total, $formatted);
181
-                $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
182
-                $output .= '<br />';
183
-                $output .= '<h5>Performance scale (from best to worse)</h5>';
184
-                $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
185
-                $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
186
-                $output .= '<span style="color:limegreen">Like...groovy!</span><br />';
187
-                $output .= '<span style="color:gold">Ruh Oh</span><br />';
188
-                $output .= '<span style="color:darkorange">Zoinks!</span><br />';
189
-                $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
190
-            }
191
-        }
192
-        if (! empty(Benchmark::$memory_usage)) {
193
-            $output .= $formatted
194
-                ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage)
195
-                : implode("\n", Benchmark::$memory_usage);
196
-        }
197
-        if (empty($output)) {
198
-            return '';
199
-        }
200
-        $output = $formatted
201
-            ? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
202
-              . (is_admin()
203
-                ? ' margin:2em 2em 2em 180px;'
204
-                : ' margin:2em;')
205
-              . ' padding:2em;">'
206
-              . '<h4>BENCHMARKING</h4>'
207
-              . $output
208
-              . '</div>'
209
-            : $output;
210
-        return $output;
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * @param bool $echo
217
-     * @param bool $formatted
218
-     * @return string
219
-     */
220
-    public static function displayResults($echo = true, $formatted = true)
221
-    {
222
-        $results = Benchmark::generateResults($formatted);
223
-        if ($echo) {
224
-            echo $results;
225
-            $results = '';
226
-        }
227
-        return $results;
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * @param string $filepath
234
-     * @param bool   $formatted
235
-     * @param bool   $append
236
-     */
237
-    public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
238
-    {
239
-        $filepath = ! empty($filepath) && is_readable(dirname($filepath))
240
-            ? $filepath
241
-            : '';
242
-        if( empty($filepath)) {
243
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
244
-        }
245
-        file_put_contents(
246
-            $filepath,
247
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
248
-            $append ? FILE_APPEND | LOCK_EX : LOCK_EX
249
-        );
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
256
-     *
257
-     * @param int $size
258
-     * @return string
259
-     */
260
-    public static function convert($size)
261
-    {
262
-        $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
263
-        return round(
264
-            $size / pow(1024, $i = floor(log($size, 1024))),
265
-            2
266
-        ) . ' ' . $unit[absint($i)];
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * @param string $timer_name
273
-     * @param float  $total_time
274
-     * @param bool   $formatted
275
-     * @return string
276
-     */
277
-    public static function formatTime($timer_name, $total_time, $formatted = true)
278
-    {
279
-        $total_time *= 1000;
280
-        switch ($total_time) {
281
-            case $total_time > 12500 :
282
-                $color = 'red';
283
-                $bold = 'bold';
284
-                break;
285
-            case $total_time > 2500 :
286
-                $color = 'darkorange';
287
-                $bold = 'bold';
288
-                break;
289
-            case $total_time > 500 :
290
-                $color = 'gold';
291
-                $bold = 'bold';
292
-                break;
293
-            case $total_time > 100 :
294
-                $color = 'limegreen';
295
-                $bold = 'normal';
296
-                break;
297
-            case $total_time > 20 :
298
-                $color = 'deepskyblue';
299
-                $bold = 'normal';
300
-                break;
301
-            default :
302
-                $color = 'mediumpurple';
303
-                $bold = 'normal';
304
-                break;
305
-        }
306
-        return $formatted
307
-            ? '<span style="min-width: 10px; margin:0 1em; color:'
308
-               . $color
309
-               . '; font-weight:'
310
-               . $bold
311
-               . '; font-size:1.2em;">'
312
-               . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
313
-               . '</span> '
314
-               . $timer_name
315
-            :  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
316
-    }
20
+	/**
21
+	 * array containing the start time for the timers
22
+	 */
23
+	private static $start_times;
24
+
25
+	/**
26
+	 * array containing all the timer'd times, which can be outputted via show_times()
27
+	 */
28
+	private static $times = array();
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	protected static $memory_usage = array();
34
+
35
+
36
+
37
+	/**
38
+	 * whether to benchmark code or not
39
+	 */
40
+	public static function doNotRun()
41
+	{
42
+		return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * resetTimes
49
+	 */
50
+	public static function resetTimes()
51
+	{
52
+		Benchmark::$times = array();
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
+	 *
60
+	 * @param null $timer_name
61
+	 */
62
+	public static function startTimer($timer_name = null)
63
+	{
64
+		if (Benchmark::doNotRun()) {
65
+			return;
66
+		}
67
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
+		Benchmark::$start_times[$timer_name] = microtime(true);
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
+	 *
76
+	 * @param string $timer_name
77
+	 */
78
+	public static function stopTimer($timer_name = '')
79
+	{
80
+		if (Benchmark::doNotRun()) {
81
+			return;
82
+		}
83
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
+		if (isset(Benchmark::$start_times[$timer_name])) {
85
+			$start_time = Benchmark::$start_times[$timer_name];
86
+			unset(Benchmark::$start_times[$timer_name]);
87
+		} else {
88
+			$start_time = array_pop(Benchmark::$start_times);
89
+		}
90
+		Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * Measure the memory usage by PHP so far.
97
+	 *
98
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
+	 * @param bool    $formatted
101
+	 * @return void
102
+	 */
103
+	public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
104
+	{
105
+		if (Benchmark::doNotRun()) {
106
+			return;
107
+		}
108
+		$memory_used = Benchmark::convert(memory_get_usage(true));
109
+		Benchmark::$memory_usage[$label] = $memory_used;
110
+		if ($output_now) {
111
+			echo $formatted
112
+				? "<br>{$label} : {$memory_used}"
113
+				: "\n {$label} : {$memory_used}";
114
+		}
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * will display the benchmarking results at shutdown
121
+	 *
122
+	 * @param bool $formatted
123
+	 * @return void
124
+	 */
125
+	public static function displayResultsAtShutdown($formatted = true)
126
+	{
127
+		add_action(
128
+			'shutdown',
129
+			function () use ($formatted) {
130
+				Benchmark::displayResults(true, $formatted);
131
+			}
132
+		);
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 * will display the benchmarking results at shutdown
139
+	 *
140
+	 * @param string $filepath
141
+	 * @param bool   $formatted
142
+	 * @param bool   $append
143
+	 * @return void
144
+	 */
145
+	public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
146
+	{
147
+		add_action(
148
+			'shutdown',
149
+			function () use ($filepath, $formatted, $append) {
150
+				Benchmark::writeResultsToFile($filepath, $formatted, $append);
151
+			}
152
+		);
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * @param bool $formatted
159
+	 * @return string
160
+	 */
161
+	private static function generateResults($formatted = true)
162
+	{
163
+		if (Benchmark::doNotRun()) {
164
+			return '';
165
+		}
166
+		$output = '';
167
+		if (! empty(Benchmark::$times)) {
168
+			$total = 0;
169
+			$output .= $formatted
170
+				? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
171
+				: '';
172
+			foreach (Benchmark::$times as $timer_name => $total_time) {
173
+				$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
174
+				$output .= $formatted ? '<br />'  : "\n";
175
+				$total += $total_time;
176
+			}
177
+			if($formatted) {
178
+				$output .= '<br />';
179
+				$output .= '<h4>TOTAL TIME</h4>';
180
+				$output .= Benchmark::formatTime('', $total, $formatted);
181
+				$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
182
+				$output .= '<br />';
183
+				$output .= '<h5>Performance scale (from best to worse)</h5>';
184
+				$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
185
+				$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
186
+				$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
187
+				$output .= '<span style="color:gold">Ruh Oh</span><br />';
188
+				$output .= '<span style="color:darkorange">Zoinks!</span><br />';
189
+				$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
190
+			}
191
+		}
192
+		if (! empty(Benchmark::$memory_usage)) {
193
+			$output .= $formatted
194
+				? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage)
195
+				: implode("\n", Benchmark::$memory_usage);
196
+		}
197
+		if (empty($output)) {
198
+			return '';
199
+		}
200
+		$output = $formatted
201
+			? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
202
+			  . (is_admin()
203
+				? ' margin:2em 2em 2em 180px;'
204
+				: ' margin:2em;')
205
+			  . ' padding:2em;">'
206
+			  . '<h4>BENCHMARKING</h4>'
207
+			  . $output
208
+			  . '</div>'
209
+			: $output;
210
+		return $output;
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * @param bool $echo
217
+	 * @param bool $formatted
218
+	 * @return string
219
+	 */
220
+	public static function displayResults($echo = true, $formatted = true)
221
+	{
222
+		$results = Benchmark::generateResults($formatted);
223
+		if ($echo) {
224
+			echo $results;
225
+			$results = '';
226
+		}
227
+		return $results;
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * @param string $filepath
234
+	 * @param bool   $formatted
235
+	 * @param bool   $append
236
+	 */
237
+	public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
238
+	{
239
+		$filepath = ! empty($filepath) && is_readable(dirname($filepath))
240
+			? $filepath
241
+			: '';
242
+		if( empty($filepath)) {
243
+			$filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
244
+		}
245
+		file_put_contents(
246
+			$filepath,
247
+			"\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
248
+			$append ? FILE_APPEND | LOCK_EX : LOCK_EX
249
+		);
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
256
+	 *
257
+	 * @param int $size
258
+	 * @return string
259
+	 */
260
+	public static function convert($size)
261
+	{
262
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
263
+		return round(
264
+			$size / pow(1024, $i = floor(log($size, 1024))),
265
+			2
266
+		) . ' ' . $unit[absint($i)];
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * @param string $timer_name
273
+	 * @param float  $total_time
274
+	 * @param bool   $formatted
275
+	 * @return string
276
+	 */
277
+	public static function formatTime($timer_name, $total_time, $formatted = true)
278
+	{
279
+		$total_time *= 1000;
280
+		switch ($total_time) {
281
+			case $total_time > 12500 :
282
+				$color = 'red';
283
+				$bold = 'bold';
284
+				break;
285
+			case $total_time > 2500 :
286
+				$color = 'darkorange';
287
+				$bold = 'bold';
288
+				break;
289
+			case $total_time > 500 :
290
+				$color = 'gold';
291
+				$bold = 'bold';
292
+				break;
293
+			case $total_time > 100 :
294
+				$color = 'limegreen';
295
+				$bold = 'normal';
296
+				break;
297
+			case $total_time > 20 :
298
+				$color = 'deepskyblue';
299
+				$bold = 'normal';
300
+				break;
301
+			default :
302
+				$color = 'mediumpurple';
303
+				$bold = 'normal';
304
+				break;
305
+		}
306
+		return $formatted
307
+			? '<span style="min-width: 10px; margin:0 1em; color:'
308
+			   . $color
309
+			   . '; font-weight:'
310
+			   . $bold
311
+			   . '; font-size:1.2em;">'
312
+			   . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
313
+			   . '</span> '
314
+			   . $timer_name
315
+			:  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
316
+	}
317 317
 
318 318
 
319 319
 
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
                 && $most_recent_migration->is_broken()
262 262
             )
263 263
         ) {
264
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
264
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php';
265 265
             $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266 266
             $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267 267
                                                                                         'success' => '0',
268 268
             ), EE_MAINTENANCE_ADMIN_URL);
269 269
         } elseif ($addons_should_be_upgraded_first) {
270
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
270
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php';
271 271
         } else {
272 272
             if ($most_recent_migration
273 273
                 && $most_recent_migration instanceof EE_Data_Migration_Script_Base
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                 $this->_template_args['current_db_state'] = null;
298 298
                 $this->_template_args['next_db_state'] = null;
299 299
             }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
300
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php';
301 301
             $this->_template_args = array_merge(
302 302
                 $this->_template_args,
303 303
                 array(
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
                 'status_completed'                 => EE_Data_Migration_Manager::status_completed,
337 337
             ));
338 338
         }
339
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
339
+        $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration
340 340
         //now render the migration options part, and put it in a variable
341 341
         $migration_options_template_file = apply_filters(
342 342
             'FHEE__ee_migration_page__migration_options_template',
343
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
343
+            EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php'
344 344
         );
345
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
345
+        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true);
346 346
         $this->_template_args['migration_options_html'] = $migration_options_html;
347 347
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
348 348
             $this->_template_args, true);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
      */
402 402
     public function _data_reset_and_delete()
403 403
     {
404
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
404
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php';
405 405
         $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406 406
             'reset_reservations',
407 407
             'reset_reservations',
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 
439 439
     protected function _reset_reservations()
440 440
     {
441
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
441
+        if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
442 442
             EE_Error::add_success(
443 443
                 __(
444 444
                     'Ticket and datetime reserved counts have been successfully reset.',
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
      */
487 487
     public function _system_status()
488 488
     {
489
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
489
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php';
490 490
         $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491 491
         $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492 492
             array(
@@ -505,11 +505,11 @@  discard block
 block discarded – undo
505 505
     public function _download_system_status()
506 506
     {
507 507
         $status_info = EEM_System_Status::instance()->get_system_stati();
508
-        header( 'Content-Disposition: attachment' );
509
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
508
+        header('Content-Disposition: attachment');
509
+        header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html");
510 510
         echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
511
-        echo "<h1>System Information for " . site_url() . "</h1>";
512
-        echo EEH_Template::layout_array_as_table( $status_info );
511
+        echo "<h1>System Information for ".site_url()."</h1>";
512
+        echo EEH_Template::layout_array_as_table($status_info);
513 513
         die;
514 514
     }
515 515
 
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         try {
524 524
             $success = wp_mail(EE_SUPPORT_EMAIL,
525 525
                 'Migration Crash Report',
526
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
526
+                $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true),
527 527
                 array(
528 528
                     "from:$from_name<$from>",
529 529
                     //					'content-type:text/html charset=UTF-8'
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
             EE_MAINTENANCE_ADMIN_URL);
559 559
         $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
560 560
             EE_MAINTENANCE_ADMIN_URL);
561
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
561
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php';
562 562
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
563 563
             $this->_template_args, true);
564 564
         $this->display_admin_page_with_sidebar();
@@ -659,9 +659,9 @@  discard block
 block discarded – undo
659 659
         wp_enqueue_script('ee_admin_js');
660 660
 //		wp_enqueue_media();
661 661
 //		wp_enqueue_script('media-upload');
662
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
662
+        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'),
663 663
             EVENT_ESPRESSO_VERSION, true);
664
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
664
+        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(),
665 665
             EVENT_ESPRESSO_VERSION);
666 666
         wp_enqueue_style('espresso_maintenance');
667 667
     }
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
 
699 699
     protected function _get_datetime_offset_fix_form()
700 700
     {
701
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
-            $this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
701
+        if ( ! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
+            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
703 703
                 array(
704 704
                     'name' => 'datetime_offset_fix_option',
705 705
                     'layout_strategy' => new EE_Admin_Two_Column_Layout(),
Please login to merge, or discard this patch.
Indentation   +736 added lines, -736 removed lines patch added patch discarded remove patch
@@ -28,755 +28,755 @@
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * @var EE_Datetime_Offset_Fix_Form
33
-     */
34
-    protected $datetime_fix_offset_form;
35
-
36
-
37
-
38
-    protected function _init_page_props()
39
-    {
40
-        $this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
-        $this->page_label = EE_MAINTENANCE_LABEL;
42
-        $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
-    }
45
-
46
-
47
-
48
-    protected function _ajax_hooks()
49
-    {
50
-        add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
-        add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
-    }
53
-
54
-
55
-
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
-        $this->_labels = array(
60
-            'buttons' => array(
61
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
-            ),
64
-        );
65
-    }
66
-
67
-
68
-
69
-    protected function _set_page_routes()
70
-    {
71
-        $this->_page_routes = array(
72
-            'default'                             => array(
73
-                'func'       => '_maintenance',
74
-                'capability' => 'manage_options',
75
-            ),
76
-            'change_maintenance_level'            => array(
77
-                'func'       => '_change_maintenance_level',
78
-                'capability' => 'manage_options',
79
-                'noheader'   => true,
80
-            ),
81
-            'system_status'                       => array(
82
-                'func'       => '_system_status',
83
-                'capability' => 'manage_options',
84
-            ),
85
-            'download_system_status' => array(
86
-                'func'       => '_download_system_status',
87
-                'capability' => 'manage_options',
88
-                'noheader'   => true,
89
-            ),
90
-            'send_migration_crash_report'         => array(
91
-                'func'       => '_send_migration_crash_report',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ),
95
-            'confirm_migration_crash_report_sent' => array(
96
-                'func'       => '_confirm_migration_crash_report_sent',
97
-                'capability' => 'manage_options',
98
-            ),
99
-            'data_reset'                          => array(
100
-                'func'       => '_data_reset_and_delete',
101
-                'capability' => 'manage_options',
102
-            ),
103
-            'reset_db'                            => array(
104
-                'func'       => '_reset_db',
105
-                'capability' => 'manage_options',
106
-                'noheader'   => true,
107
-                'args'       => array('nuke_old_ee4_data' => true),
108
-            ),
109
-            'start_with_fresh_ee4_db'             => array(
110
-                'func'       => '_reset_db',
111
-                'capability' => 'manage_options',
112
-                'noheader'   => true,
113
-                'args'       => array('nuke_old_ee4_data' => false),
114
-            ),
115
-            'delete_db'                           => array(
116
-                'func'       => '_delete_db',
117
-                'capability' => 'manage_options',
118
-                'noheader'   => true,
119
-            ),
120
-            'rerun_migration_from_ee3'            => array(
121
-                'func'       => '_rerun_migration_from_ee3',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ),
125
-            'reset_reservations'                  => array(
126
-                'func'       => '_reset_reservations',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ),
130
-            'reset_capabilities'                  => array(
131
-                'func'       => '_reset_capabilities',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-            'reattempt_migration'                 => array(
136
-                'func'       => '_reattempt_migration',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ),
140
-            'datetime_tools' => array(
141
-                'func' => '_datetime_tools',
142
-                'capability' => 'manage_options'
143
-            ),
144
-            'run_datetime_offset_fix' => array(
145
-                'func' => '_apply_datetime_offset',
146
-                'noheader' => true,
147
-                'headers_sent_route' => 'datetime_tools',
148
-                'capability' => 'manage_options'
149
-            )
150
-        );
151
-    }
152
-
153
-
154
-
155
-    protected function _set_page_config()
156
-    {
157
-        $this->_page_config = array(
158
-            'default'       => array(
159
-                'nav'           => array(
160
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
161
-                    'order' => 10,
162
-                ),
163
-                'require_nonce' => false,
164
-            ),
165
-            'data_reset'    => array(
166
-                'nav'           => array(
167
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
168
-                    'order' => 20,
169
-                ),
170
-                'require_nonce' => false,
171
-            ),
172
-            'datetime_tools' => array(
173
-                'nav' => array(
174
-                    'label' => esc_html__('Datetime Utilities', 'event_espresso'),
175
-                    'order' => 25
176
-                ),
177
-                'require_nonce' => false,
178
-            ),
179
-            'system_status' => array(
180
-                'nav'           => array(
181
-                    'label' => esc_html__("System Information", "event_espresso"),
182
-                    'order' => 30,
183
-                ),
184
-                'require_nonce' => false,
185
-            ),
186
-        );
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * default maintenance page. If we're in maintenance mode level 2, then we need to show
193
-     * the migration scripts and all that UI.
194
-     */
195
-    public function _maintenance()
196
-    {
197
-        //it all depends if we're in maintenance model level 1 (frontend-only) or
198
-        //level 2 (everything except maintenance page)
199
-        try {
200
-            //get the current maintenance level and check if
201
-            //we are removed
202
-            $mm = EE_Maintenance_Mode::instance()->level();
203
-            $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
204
-            if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
205
-                //we just took the site out of maintenance mode, so notify the user.
206
-                //unfortunately this message appears to be echoed on the NEXT page load...
207
-                //oh well, we should really be checking for this on addon deactivation anyways
208
-                EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
209
-                    'event_espresso'));
210
-                $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
211
-            }
212
-            //in case an exception is thrown while trying to handle migrations
213
-            switch (EE_Maintenance_Mode::instance()->level()) {
214
-                case EE_Maintenance_Mode::level_0_not_in_maintenance:
215
-                case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
216
-                    $show_maintenance_switch = true;
217
-                    $show_backup_db_text = false;
218
-                    $show_migration_progress = false;
219
-                    $script_names = array();
220
-                    $addons_should_be_upgraded_first = false;
221
-                    break;
222
-                case EE_Maintenance_Mode::level_2_complete_maintenance:
223
-                    $show_maintenance_switch = false;
224
-                    $show_migration_progress = true;
225
-                    if (isset($this->_req_data['continue_migration'])) {
226
-                        $show_backup_db_text = false;
227
-                    } else {
228
-                        $show_backup_db_text = true;
229
-                    }
230
-                    $scripts_needing_to_run = EE_Data_Migration_Manager::instance()
231
-                                                                       ->check_for_applicable_data_migration_scripts();
232
-                    $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
233
-                    $script_names = array();
234
-                    $current_script = null;
235
-                    foreach ($scripts_needing_to_run as $script) {
236
-                        if ($script instanceof EE_Data_Migration_Script_Base) {
237
-                            if ( ! $current_script) {
238
-                                $current_script = $script;
239
-                                $current_script->migration_page_hooks();
240
-                            }
241
-                            $script_names[] = $script->pretty_name();
242
-                        }
243
-                    }
244
-                    break;
245
-            }
246
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
247
-            $exception_thrown = false;
248
-        } catch (EE_Error $e) {
249
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
250
-            //now, just so we can display the page correctly, make a error migration script stage object
251
-            //and also put the error on it. It only persists for the duration of this request
252
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
253
-            $most_recent_migration->add_error($e->getMessage());
254
-            $exception_thrown = true;
255
-        }
256
-        $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
257
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
258
-        if ($exception_thrown
259
-            || ($most_recent_migration
260
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
261
-                && $most_recent_migration->is_broken()
262
-            )
263
-        ) {
264
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
265
-            $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266
-            $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267
-                                                                                        'success' => '0',
268
-            ), EE_MAINTENANCE_ADMIN_URL);
269
-        } elseif ($addons_should_be_upgraded_first) {
270
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
271
-        } else {
272
-            if ($most_recent_migration
273
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
274
-                && $most_recent_migration->can_continue()
275
-            ) {
276
-                $show_backup_db_text = false;
277
-                $show_continue_current_migration_script = true;
278
-                $show_most_recent_migration = true;
279
-            } elseif (isset($this->_req_data['continue_migration'])) {
280
-                $show_most_recent_migration = true;
281
-                $show_continue_current_migration_script = false;
282
-            } else {
283
-                $show_most_recent_migration = false;
284
-                $show_continue_current_migration_script = false;
285
-            }
286
-            if (isset($current_script)) {
287
-                $migrates_to = $current_script->migrates_to_version();
288
-                $plugin_slug = $migrates_to['slug'];
289
-                $new_version = $migrates_to['version'];
290
-                $this->_template_args = array_merge($this->_template_args, array(
291
-                    'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
292
-                        isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
293
-                    'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
294
-                        $new_version, $plugin_slug) : null,
295
-                ));
296
-            } else {
297
-                $this->_template_args['current_db_state'] = null;
298
-                $this->_template_args['next_db_state'] = null;
299
-            }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
-            $this->_template_args = array_merge(
302
-                $this->_template_args,
303
-                array(
304
-                    'show_most_recent_migration'             => $show_most_recent_migration,
305
-                    //flag for showing the most recent migration's status and/or errors
306
-                    'show_migration_progress'                => $show_migration_progress,
307
-                    //flag for showing the option to run migrations and see their progress
308
-                    'show_backup_db_text'                    => $show_backup_db_text,
309
-                    //flag for showing text telling the user to backup their DB
310
-                    'show_maintenance_switch'                => $show_maintenance_switch,
311
-                    //flag for showing the option to change maintenance mode between levels 0 and 1
312
-                    'script_names'                           => $script_names,
313
-                    //array of names of scripts that have run
314
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
-                    //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
317
-                        EE_MAINTENANCE_ADMIN_URL),
318
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
319
-                        EE_MAINTENANCE_ADMIN_URL),
320
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
321
-                        EE_MAINTENANCE_ADMIN_URL),
322
-                    'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
323
-                        espresso_version()),
324
-                )
325
-            );
326
-            //make sure we have the form fields helper available. It usually is, but sometimes it isn't
327
-            //localize script stuff
328
-            wp_localize_script('ee-maintenance', 'ee_maintenance', array(
329
-                'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
330
-                'next'                             => esc_html__("Next", "event_espresso"),
331
-                'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
332
-                'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
333
-                    "event_espresso"),
334
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
335
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
336
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
337
-            ));
338
-        }
339
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
340
-        //now render the migration options part, and put it in a variable
341
-        $migration_options_template_file = apply_filters(
342
-            'FHEE__ee_migration_page__migration_options_template',
343
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
344
-        );
345
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
346
-        $this->_template_args['migration_options_html'] = $migration_options_html;
347
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
348
-            $this->_template_args, true);
349
-        $this->display_admin_page_with_sidebar();
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
356
-     */
357
-    public function migration_step()
358
-    {
359
-        $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
360
-        $this->_return_json();
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * Can be used by js when it notices a response with HTML in it in order
367
-     * to log the malformed response
368
-     */
369
-    public function add_error_to_migrations_ran()
370
-    {
371
-        EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
372
-        $this->_template_args['data'] = array('ok' => true);
373
-        $this->_return_json();
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * changes the maintenance level, provided there are still no migration scripts that should run
380
-     */
381
-    public function _change_maintenance_level()
382
-    {
383
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
384
-        if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
385
-            EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
386
-            $success = true;
387
-        } else {
388
-            EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
389
-            $success = false;
390
-        }
391
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * a tab with options for resetting and/or deleting EE data
398
-     *
399
-     * @throws \EE_Error
400
-     * @throws \DomainException
401
-     */
402
-    public function _data_reset_and_delete()
403
-    {
404
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
405
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406
-            'reset_reservations',
407
-            'reset_reservations',
408
-            array(),
409
-            'button button-primary',
410
-            '',
411
-            false
412
-        );
413
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
414
-            'reset_capabilities',
415
-            'reset_capabilities',
416
-            array(),
417
-            'button button-primary',
418
-            '',
419
-            false
420
-        );
421
-        $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
422
-            array('action' => 'delete_db'),
423
-            EE_MAINTENANCE_ADMIN_URL
424
-        );
425
-        $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
426
-            array('action' => 'reset_db'),
427
-            EE_MAINTENANCE_ADMIN_URL
428
-        );
429
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
430
-            $this->_template_path,
431
-            $this->_template_args,
432
-            true
433
-        );
434
-        $this->display_admin_page_with_sidebar();
435
-    }
436
-
437
-
438
-
439
-    protected function _reset_reservations()
440
-    {
441
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
442
-            EE_Error::add_success(
443
-                __(
444
-                    'Ticket and datetime reserved counts have been successfully reset.',
445
-                    'event_espresso'
446
-                )
447
-            );
448
-        } else {
449
-            EE_Error::add_success(
450
-                __(
451
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
452
-                    'event_espresso'
453
-                )
454
-            );
455
-        }
456
-        $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
457
-    }
458
-
459
-
460
-
461
-    protected function _reset_capabilities()
462
-    {
463
-        EE_Registry::instance()->CAP->init_caps(true);
464
-        EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
465
-            'event_espresso'));
466
-        $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
467
-    }
468
-
469
-
470
-
471
-    /**
472
-     * resets the DMSs so we can attempt to continue migrating after a fatal error
473
-     * (only a good idea when someone has somehow tried ot fix whatever caused
474
-     * the fatal error in teh first place)
475
-     */
476
-    protected function _reattempt_migration()
477
-    {
478
-        EE_Data_Migration_Manager::instance()->reattempt();
479
-        $this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * shows the big ol' System Information page
486
-     */
487
-    public function _system_status()
488
-    {
489
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
490
-        $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492
-            array(
493
-                'action' => 'download_system_status',
494
-            ),
495
-            EE_MAINTENANCE_ADMIN_URL
496
-        );
497
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
498
-            $this->_template_args, true);
499
-        $this->display_admin_page_with_sidebar();
500
-    }
501
-
502
-    /**
503
-     * Downloads an HTML file of the system status that can be easily stored or emailed
504
-     */
505
-    public function _download_system_status()
506
-    {
507
-        $status_info = EEM_System_Status::instance()->get_system_stati();
508
-        header( 'Content-Disposition: attachment' );
509
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
510
-        echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
511
-        echo "<h1>System Information for " . site_url() . "</h1>";
512
-        echo EEH_Template::layout_array_as_table( $status_info );
513
-        die;
514
-    }
515
-
516
-
517
-
518
-    public function _send_migration_crash_report()
519
-    {
520
-        $from = $this->_req_data['from'];
521
-        $from_name = $this->_req_data['from_name'];
522
-        $body = $this->_req_data['body'];
523
-        try {
524
-            $success = wp_mail(EE_SUPPORT_EMAIL,
525
-                'Migration Crash Report',
526
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
527
-                array(
528
-                    "from:$from_name<$from>",
529
-                    //					'content-type:text/html charset=UTF-8'
530
-                ));
531
-        } catch (Exception $e) {
532
-            $success = false;
533
-        }
534
-        $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
535
-            esc_html__("sent", "event_espresso"),
536
-            array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
537
-    }
538
-
539
-
540
-
541
-    public function _confirm_migration_crash_report_sent()
542
-    {
543
-        try {
544
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
545
-        } catch (EE_Error $e) {
546
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
547
-            //now, just so we can display the page correctly, make a error migration script stage object
548
-            //and also put the error on it. It only persists for the duration of this request
549
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
550
-            $most_recent_migration->add_error($e->getMessage());
551
-        }
552
-        $success = $this->_req_data['success'] == '1' ? true : false;
553
-        $this->_template_args['success'] = $success;
554
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
555
-        $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
556
-            EE_MAINTENANCE_ADMIN_URL);
557
-        $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
558
-            EE_MAINTENANCE_ADMIN_URL);
559
-        $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
560
-            EE_MAINTENANCE_ADMIN_URL);
561
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
562
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
563
-            $this->_template_args, true);
564
-        $this->display_admin_page_with_sidebar();
565
-    }
566
-
567
-
568
-
569
-    /**
570
-     * Resets the entire EE4 database.
571
-     * Currently basically only sets up ee4 database for a fresh install- doesn't
572
-     * actually clean out the old wp options, or cpts (although does erase old ee table data)
573
-     *
574
-     * @param boolean $nuke_old_ee4_data controls whether or not we
575
-     *                                   destroy the old ee4 data, or just try initializing ee4 default data
576
-     */
577
-    public function _reset_db($nuke_old_ee4_data = true)
578
-    {
579
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
580
-        if ($nuke_old_ee4_data) {
581
-            EEH_Activation::delete_all_espresso_cpt_data();
582
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
583
-            EEH_Activation::remove_cron_tasks();
584
-        }
585
-        //make sure when we reset the registry's config that it
586
-        //switches to using the new singleton
587
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
588
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
589
-        EE_System::instance()->redirect_to_about_ee();
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * Deletes ALL EE tables, Records, and Options from the database.
596
-     */
597
-    public function _delete_db()
598
-    {
599
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
600
-        EEH_Activation::delete_all_espresso_cpt_data();
601
-        EEH_Activation::delete_all_espresso_tables_and_data();
602
-        EEH_Activation::remove_cron_tasks();
603
-        EEH_Activation::deactivate_event_espresso();
604
-        wp_safe_redirect(admin_url('plugins.php'));
605
-        exit;
606
-    }
607
-
608
-
609
-
610
-    /**
611
-     * sets up EE4 to rerun the migrations from ee3 to ee4
612
-     */
613
-    public function _rerun_migration_from_ee3()
614
-    {
615
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
616
-        EEH_Activation::delete_all_espresso_cpt_data();
617
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
618
-        //set the db state to something that will require migrations
619
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
620
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
621
-        $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
622
-    }
623
-
624
-
625
-
626
-    //none of the below group are currently used for Gateway Settings
627
-    protected function _add_screen_options()
628
-    {
629
-    }
630
-
631
-
632
-
633
-    protected function _add_feature_pointers()
634
-    {
635
-    }
636
-
31
+	/**
32
+	 * @var EE_Datetime_Offset_Fix_Form
33
+	 */
34
+	protected $datetime_fix_offset_form;
35
+
36
+
37
+
38
+	protected function _init_page_props()
39
+	{
40
+		$this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
+		$this->page_label = EE_MAINTENANCE_LABEL;
42
+		$this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
+	}
45
+
46
+
47
+
48
+	protected function _ajax_hooks()
49
+	{
50
+		add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
+		add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
+	}
53
+
54
+
55
+
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
+		$this->_labels = array(
60
+			'buttons' => array(
61
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
+			),
64
+		);
65
+	}
66
+
67
+
68
+
69
+	protected function _set_page_routes()
70
+	{
71
+		$this->_page_routes = array(
72
+			'default'                             => array(
73
+				'func'       => '_maintenance',
74
+				'capability' => 'manage_options',
75
+			),
76
+			'change_maintenance_level'            => array(
77
+				'func'       => '_change_maintenance_level',
78
+				'capability' => 'manage_options',
79
+				'noheader'   => true,
80
+			),
81
+			'system_status'                       => array(
82
+				'func'       => '_system_status',
83
+				'capability' => 'manage_options',
84
+			),
85
+			'download_system_status' => array(
86
+				'func'       => '_download_system_status',
87
+				'capability' => 'manage_options',
88
+				'noheader'   => true,
89
+			),
90
+			'send_migration_crash_report'         => array(
91
+				'func'       => '_send_migration_crash_report',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			),
95
+			'confirm_migration_crash_report_sent' => array(
96
+				'func'       => '_confirm_migration_crash_report_sent',
97
+				'capability' => 'manage_options',
98
+			),
99
+			'data_reset'                          => array(
100
+				'func'       => '_data_reset_and_delete',
101
+				'capability' => 'manage_options',
102
+			),
103
+			'reset_db'                            => array(
104
+				'func'       => '_reset_db',
105
+				'capability' => 'manage_options',
106
+				'noheader'   => true,
107
+				'args'       => array('nuke_old_ee4_data' => true),
108
+			),
109
+			'start_with_fresh_ee4_db'             => array(
110
+				'func'       => '_reset_db',
111
+				'capability' => 'manage_options',
112
+				'noheader'   => true,
113
+				'args'       => array('nuke_old_ee4_data' => false),
114
+			),
115
+			'delete_db'                           => array(
116
+				'func'       => '_delete_db',
117
+				'capability' => 'manage_options',
118
+				'noheader'   => true,
119
+			),
120
+			'rerun_migration_from_ee3'            => array(
121
+				'func'       => '_rerun_migration_from_ee3',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			),
125
+			'reset_reservations'                  => array(
126
+				'func'       => '_reset_reservations',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			),
130
+			'reset_capabilities'                  => array(
131
+				'func'       => '_reset_capabilities',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+			'reattempt_migration'                 => array(
136
+				'func'       => '_reattempt_migration',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			),
140
+			'datetime_tools' => array(
141
+				'func' => '_datetime_tools',
142
+				'capability' => 'manage_options'
143
+			),
144
+			'run_datetime_offset_fix' => array(
145
+				'func' => '_apply_datetime_offset',
146
+				'noheader' => true,
147
+				'headers_sent_route' => 'datetime_tools',
148
+				'capability' => 'manage_options'
149
+			)
150
+		);
151
+	}
152
+
153
+
154
+
155
+	protected function _set_page_config()
156
+	{
157
+		$this->_page_config = array(
158
+			'default'       => array(
159
+				'nav'           => array(
160
+					'label' => esc_html__('Maintenance', 'event_espresso'),
161
+					'order' => 10,
162
+				),
163
+				'require_nonce' => false,
164
+			),
165
+			'data_reset'    => array(
166
+				'nav'           => array(
167
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
168
+					'order' => 20,
169
+				),
170
+				'require_nonce' => false,
171
+			),
172
+			'datetime_tools' => array(
173
+				'nav' => array(
174
+					'label' => esc_html__('Datetime Utilities', 'event_espresso'),
175
+					'order' => 25
176
+				),
177
+				'require_nonce' => false,
178
+			),
179
+			'system_status' => array(
180
+				'nav'           => array(
181
+					'label' => esc_html__("System Information", "event_espresso"),
182
+					'order' => 30,
183
+				),
184
+				'require_nonce' => false,
185
+			),
186
+		);
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * default maintenance page. If we're in maintenance mode level 2, then we need to show
193
+	 * the migration scripts and all that UI.
194
+	 */
195
+	public function _maintenance()
196
+	{
197
+		//it all depends if we're in maintenance model level 1 (frontend-only) or
198
+		//level 2 (everything except maintenance page)
199
+		try {
200
+			//get the current maintenance level and check if
201
+			//we are removed
202
+			$mm = EE_Maintenance_Mode::instance()->level();
203
+			$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
204
+			if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
205
+				//we just took the site out of maintenance mode, so notify the user.
206
+				//unfortunately this message appears to be echoed on the NEXT page load...
207
+				//oh well, we should really be checking for this on addon deactivation anyways
208
+				EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
209
+					'event_espresso'));
210
+				$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
211
+			}
212
+			//in case an exception is thrown while trying to handle migrations
213
+			switch (EE_Maintenance_Mode::instance()->level()) {
214
+				case EE_Maintenance_Mode::level_0_not_in_maintenance:
215
+				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
216
+					$show_maintenance_switch = true;
217
+					$show_backup_db_text = false;
218
+					$show_migration_progress = false;
219
+					$script_names = array();
220
+					$addons_should_be_upgraded_first = false;
221
+					break;
222
+				case EE_Maintenance_Mode::level_2_complete_maintenance:
223
+					$show_maintenance_switch = false;
224
+					$show_migration_progress = true;
225
+					if (isset($this->_req_data['continue_migration'])) {
226
+						$show_backup_db_text = false;
227
+					} else {
228
+						$show_backup_db_text = true;
229
+					}
230
+					$scripts_needing_to_run = EE_Data_Migration_Manager::instance()
231
+																	   ->check_for_applicable_data_migration_scripts();
232
+					$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
233
+					$script_names = array();
234
+					$current_script = null;
235
+					foreach ($scripts_needing_to_run as $script) {
236
+						if ($script instanceof EE_Data_Migration_Script_Base) {
237
+							if ( ! $current_script) {
238
+								$current_script = $script;
239
+								$current_script->migration_page_hooks();
240
+							}
241
+							$script_names[] = $script->pretty_name();
242
+						}
243
+					}
244
+					break;
245
+			}
246
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
247
+			$exception_thrown = false;
248
+		} catch (EE_Error $e) {
249
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
250
+			//now, just so we can display the page correctly, make a error migration script stage object
251
+			//and also put the error on it. It only persists for the duration of this request
252
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
253
+			$most_recent_migration->add_error($e->getMessage());
254
+			$exception_thrown = true;
255
+		}
256
+		$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
257
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
258
+		if ($exception_thrown
259
+			|| ($most_recent_migration
260
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
261
+				&& $most_recent_migration->is_broken()
262
+			)
263
+		) {
264
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
265
+			$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266
+			$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267
+																						'success' => '0',
268
+			), EE_MAINTENANCE_ADMIN_URL);
269
+		} elseif ($addons_should_be_upgraded_first) {
270
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
271
+		} else {
272
+			if ($most_recent_migration
273
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
274
+				&& $most_recent_migration->can_continue()
275
+			) {
276
+				$show_backup_db_text = false;
277
+				$show_continue_current_migration_script = true;
278
+				$show_most_recent_migration = true;
279
+			} elseif (isset($this->_req_data['continue_migration'])) {
280
+				$show_most_recent_migration = true;
281
+				$show_continue_current_migration_script = false;
282
+			} else {
283
+				$show_most_recent_migration = false;
284
+				$show_continue_current_migration_script = false;
285
+			}
286
+			if (isset($current_script)) {
287
+				$migrates_to = $current_script->migrates_to_version();
288
+				$plugin_slug = $migrates_to['slug'];
289
+				$new_version = $migrates_to['version'];
290
+				$this->_template_args = array_merge($this->_template_args, array(
291
+					'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
292
+						isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
293
+					'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
294
+						$new_version, $plugin_slug) : null,
295
+				));
296
+			} else {
297
+				$this->_template_args['current_db_state'] = null;
298
+				$this->_template_args['next_db_state'] = null;
299
+			}
300
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
+			$this->_template_args = array_merge(
302
+				$this->_template_args,
303
+				array(
304
+					'show_most_recent_migration'             => $show_most_recent_migration,
305
+					//flag for showing the most recent migration's status and/or errors
306
+					'show_migration_progress'                => $show_migration_progress,
307
+					//flag for showing the option to run migrations and see their progress
308
+					'show_backup_db_text'                    => $show_backup_db_text,
309
+					//flag for showing text telling the user to backup their DB
310
+					'show_maintenance_switch'                => $show_maintenance_switch,
311
+					//flag for showing the option to change maintenance mode between levels 0 and 1
312
+					'script_names'                           => $script_names,
313
+					//array of names of scripts that have run
314
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
+					//flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
317
+						EE_MAINTENANCE_ADMIN_URL),
318
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
319
+						EE_MAINTENANCE_ADMIN_URL),
320
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
321
+						EE_MAINTENANCE_ADMIN_URL),
322
+					'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
323
+						espresso_version()),
324
+				)
325
+			);
326
+			//make sure we have the form fields helper available. It usually is, but sometimes it isn't
327
+			//localize script stuff
328
+			wp_localize_script('ee-maintenance', 'ee_maintenance', array(
329
+				'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
330
+				'next'                             => esc_html__("Next", "event_espresso"),
331
+				'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
332
+				'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
333
+					"event_espresso"),
334
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
335
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
336
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
337
+			));
338
+		}
339
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
340
+		//now render the migration options part, and put it in a variable
341
+		$migration_options_template_file = apply_filters(
342
+			'FHEE__ee_migration_page__migration_options_template',
343
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
344
+		);
345
+		$migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
346
+		$this->_template_args['migration_options_html'] = $migration_options_html;
347
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
348
+			$this->_template_args, true);
349
+		$this->display_admin_page_with_sidebar();
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
356
+	 */
357
+	public function migration_step()
358
+	{
359
+		$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
360
+		$this->_return_json();
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * Can be used by js when it notices a response with HTML in it in order
367
+	 * to log the malformed response
368
+	 */
369
+	public function add_error_to_migrations_ran()
370
+	{
371
+		EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
372
+		$this->_template_args['data'] = array('ok' => true);
373
+		$this->_return_json();
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * changes the maintenance level, provided there are still no migration scripts that should run
380
+	 */
381
+	public function _change_maintenance_level()
382
+	{
383
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
384
+		if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
385
+			EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
386
+			$success = true;
387
+		} else {
388
+			EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
389
+			$success = false;
390
+		}
391
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * a tab with options for resetting and/or deleting EE data
398
+	 *
399
+	 * @throws \EE_Error
400
+	 * @throws \DomainException
401
+	 */
402
+	public function _data_reset_and_delete()
403
+	{
404
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
405
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406
+			'reset_reservations',
407
+			'reset_reservations',
408
+			array(),
409
+			'button button-primary',
410
+			'',
411
+			false
412
+		);
413
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
414
+			'reset_capabilities',
415
+			'reset_capabilities',
416
+			array(),
417
+			'button button-primary',
418
+			'',
419
+			false
420
+		);
421
+		$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
422
+			array('action' => 'delete_db'),
423
+			EE_MAINTENANCE_ADMIN_URL
424
+		);
425
+		$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
426
+			array('action' => 'reset_db'),
427
+			EE_MAINTENANCE_ADMIN_URL
428
+		);
429
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
430
+			$this->_template_path,
431
+			$this->_template_args,
432
+			true
433
+		);
434
+		$this->display_admin_page_with_sidebar();
435
+	}
436
+
437
+
438
+
439
+	protected function _reset_reservations()
440
+	{
441
+		if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
442
+			EE_Error::add_success(
443
+				__(
444
+					'Ticket and datetime reserved counts have been successfully reset.',
445
+					'event_espresso'
446
+				)
447
+			);
448
+		} else {
449
+			EE_Error::add_success(
450
+				__(
451
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
452
+					'event_espresso'
453
+				)
454
+			);
455
+		}
456
+		$this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
457
+	}
458
+
459
+
460
+
461
+	protected function _reset_capabilities()
462
+	{
463
+		EE_Registry::instance()->CAP->init_caps(true);
464
+		EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
465
+			'event_espresso'));
466
+		$this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
467
+	}
468
+
469
+
470
+
471
+	/**
472
+	 * resets the DMSs so we can attempt to continue migrating after a fatal error
473
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
474
+	 * the fatal error in teh first place)
475
+	 */
476
+	protected function _reattempt_migration()
477
+	{
478
+		EE_Data_Migration_Manager::instance()->reattempt();
479
+		$this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * shows the big ol' System Information page
486
+	 */
487
+	public function _system_status()
488
+	{
489
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
490
+		$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492
+			array(
493
+				'action' => 'download_system_status',
494
+			),
495
+			EE_MAINTENANCE_ADMIN_URL
496
+		);
497
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
498
+			$this->_template_args, true);
499
+		$this->display_admin_page_with_sidebar();
500
+	}
501
+
502
+	/**
503
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
504
+	 */
505
+	public function _download_system_status()
506
+	{
507
+		$status_info = EEM_System_Status::instance()->get_system_stati();
508
+		header( 'Content-Disposition: attachment' );
509
+		header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
510
+		echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
511
+		echo "<h1>System Information for " . site_url() . "</h1>";
512
+		echo EEH_Template::layout_array_as_table( $status_info );
513
+		die;
514
+	}
515
+
516
+
517
+
518
+	public function _send_migration_crash_report()
519
+	{
520
+		$from = $this->_req_data['from'];
521
+		$from_name = $this->_req_data['from_name'];
522
+		$body = $this->_req_data['body'];
523
+		try {
524
+			$success = wp_mail(EE_SUPPORT_EMAIL,
525
+				'Migration Crash Report',
526
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
527
+				array(
528
+					"from:$from_name<$from>",
529
+					//					'content-type:text/html charset=UTF-8'
530
+				));
531
+		} catch (Exception $e) {
532
+			$success = false;
533
+		}
534
+		$this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
535
+			esc_html__("sent", "event_espresso"),
536
+			array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
537
+	}
538
+
539
+
540
+
541
+	public function _confirm_migration_crash_report_sent()
542
+	{
543
+		try {
544
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
545
+		} catch (EE_Error $e) {
546
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
547
+			//now, just so we can display the page correctly, make a error migration script stage object
548
+			//and also put the error on it. It only persists for the duration of this request
549
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
550
+			$most_recent_migration->add_error($e->getMessage());
551
+		}
552
+		$success = $this->_req_data['success'] == '1' ? true : false;
553
+		$this->_template_args['success'] = $success;
554
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
555
+		$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
556
+			EE_MAINTENANCE_ADMIN_URL);
557
+		$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
558
+			EE_MAINTENANCE_ADMIN_URL);
559
+		$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
560
+			EE_MAINTENANCE_ADMIN_URL);
561
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
562
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
563
+			$this->_template_args, true);
564
+		$this->display_admin_page_with_sidebar();
565
+	}
566
+
567
+
568
+
569
+	/**
570
+	 * Resets the entire EE4 database.
571
+	 * Currently basically only sets up ee4 database for a fresh install- doesn't
572
+	 * actually clean out the old wp options, or cpts (although does erase old ee table data)
573
+	 *
574
+	 * @param boolean $nuke_old_ee4_data controls whether or not we
575
+	 *                                   destroy the old ee4 data, or just try initializing ee4 default data
576
+	 */
577
+	public function _reset_db($nuke_old_ee4_data = true)
578
+	{
579
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
580
+		if ($nuke_old_ee4_data) {
581
+			EEH_Activation::delete_all_espresso_cpt_data();
582
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
583
+			EEH_Activation::remove_cron_tasks();
584
+		}
585
+		//make sure when we reset the registry's config that it
586
+		//switches to using the new singleton
587
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
588
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
589
+		EE_System::instance()->redirect_to_about_ee();
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * Deletes ALL EE tables, Records, and Options from the database.
596
+	 */
597
+	public function _delete_db()
598
+	{
599
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
600
+		EEH_Activation::delete_all_espresso_cpt_data();
601
+		EEH_Activation::delete_all_espresso_tables_and_data();
602
+		EEH_Activation::remove_cron_tasks();
603
+		EEH_Activation::deactivate_event_espresso();
604
+		wp_safe_redirect(admin_url('plugins.php'));
605
+		exit;
606
+	}
607
+
608
+
609
+
610
+	/**
611
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
612
+	 */
613
+	public function _rerun_migration_from_ee3()
614
+	{
615
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
616
+		EEH_Activation::delete_all_espresso_cpt_data();
617
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
618
+		//set the db state to something that will require migrations
619
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
620
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
621
+		$this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
622
+	}
623
+
624
+
625
+
626
+	//none of the below group are currently used for Gateway Settings
627
+	protected function _add_screen_options()
628
+	{
629
+	}
630
+
631
+
632
+
633
+	protected function _add_feature_pointers()
634
+	{
635
+	}
636
+
637 637
 
638 638
 
639
-    public function admin_init()
640
-    {
641
-    }
642
-
643
-
644
-
645
-    public function admin_notices()
646
-    {
647
-    }
648
-
639
+	public function admin_init()
640
+	{
641
+	}
642
+
643
+
644
+
645
+	public function admin_notices()
646
+	{
647
+	}
648
+
649 649
 
650 650
 
651
-    public function admin_footer_scripts()
652
-    {
653
-    }
651
+	public function admin_footer_scripts()
652
+	{
653
+	}
654 654
 
655 655
 
656 656
 
657
-    public function load_scripts_styles()
658
-    {
659
-        wp_enqueue_script('ee_admin_js');
657
+	public function load_scripts_styles()
658
+	{
659
+		wp_enqueue_script('ee_admin_js');
660 660
 //		wp_enqueue_media();
661 661
 //		wp_enqueue_script('media-upload');
662
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
663
-            EVENT_ESPRESSO_VERSION, true);
664
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
665
-            EVENT_ESPRESSO_VERSION);
666
-        wp_enqueue_style('espresso_maintenance');
667
-    }
662
+		wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
663
+			EVENT_ESPRESSO_VERSION, true);
664
+		wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
665
+			EVENT_ESPRESSO_VERSION);
666
+		wp_enqueue_style('espresso_maintenance');
667
+	}
668 668
 
669 669
 
670 670
 
671
-    public function load_scripts_styles_default()
672
-    {
673
-        //styles
671
+	public function load_scripts_styles_default()
672
+	{
673
+		//styles
674 674
 //		wp_enqueue_style('ee-text-links');
675 675
 //		//scripts
676 676
 //		wp_enqueue_script('ee-text-links');
677
-    }
678
-
679
-
680
-    protected function _datetime_tools()
681
-    {
682
-        $form_action = EE_Admin_Page::add_query_args_and_nonce(
683
-            array(
684
-                'action' => 'run_datetime_offset_fix',
685
-                'return_action' => $this->_req_action
686
-            ),
687
-            EE_MAINTENANCE_ADMIN_URL
688
-        );
689
-        $form = $this->_get_datetime_offset_fix_form();
690
-        $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
691
-        $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
692
-                                                      . $form->get_html_and_js()
693
-                                                      . $form->form_close();
694
-        $this->display_admin_page_with_no_sidebar();
695
-    }
696
-
697
-
698
-
699
-    protected function _get_datetime_offset_fix_form()
700
-    {
701
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
-            $this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
703
-                array(
704
-                    'name' => 'datetime_offset_fix_option',
705
-                    'layout_strategy' => new EE_Admin_Two_Column_Layout(),
706
-                    'subsections' => array(
707
-                        'title' => new EE_Form_Section_HTML(
708
-                            EEH_HTML::h2(
709
-                                esc_html__('Datetime Offset Tool', 'event_espresso')
710
-                            )
711
-                        ),
712
-                        'explanation' => new EE_Form_Section_HTML(
713
-                            EEH_HTML::p(
714
-                                esc_html__(
715
-                                    'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
716
-                                    'event_espresso'
717
-                                )
718
-                            )
719
-                            . EEH_HTML::p(
720
-                                esc_html__(
721
-                                    '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.',
722
-                                    'event_espresso'
723
-                                )
724
-                            )
725
-                        ),
726
-                        'offset_input' => new EE_Float_Input(
727
-                            array(
728
-                                'html_name' => 'offset_for_datetimes',
729
-                                'html_label_text' => esc_html__(
730
-                                    'Offset to apply (in hours):',
731
-                                    'event_espresso'
732
-                                ),
733
-                                'min_value' => '-12',
734
-                                'max_value' => '14',
735
-                                'step_value' => '.25',
736
-                                'default' => DatetimeOffsetFix::getOffset()
737
-                            )
738
-                        ),
739
-                        'submit' => new EE_Submit_Input(
740
-                            array(
741
-                                'html_label_text' => '',
742
-                                'default' => esc_html__('Apply Offset', 'event_espresso')
743
-                            )
744
-                        )
745
-                    )
746
-                )
747
-            );
748
-        }
749
-        return $this->datetime_fix_offset_form;
750
-    }
751
-
752
-
753
-    /**
754
-     * Callback for the run_datetime_offset_fix route.
755
-     * @throws EE_Error
756
-     */
757
-    protected function _apply_datetime_offset()
758
-    {
759
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
760
-            $form = $this->_get_datetime_offset_fix_form();
761
-            $form->receive_form_submission($this->_req_data);
762
-            if ($form->is_valid()) {
763
-                //save offset so batch processor can get it.
764
-                DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
765
-                //redirect to batch tool
766
-                wp_redirect(
767
-                    EE_Admin_Page::add_query_args_and_nonce(
768
-                        array(
769
-                            'page' => 'espresso_batch',
770
-                            'batch' => 'job',
771
-                            'label' => esc_html__('Applying Offset', 'event_espresso'),
772
-                            'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
773
-                            'return_url' => urlencode(home_url(add_query_arg(null, null))),
774
-                        ),
775
-                        admin_url()
776
-                    )
777
-                );
778
-                exit;
779
-            }
780
-        }
781
-    }
677
+	}
678
+
679
+
680
+	protected function _datetime_tools()
681
+	{
682
+		$form_action = EE_Admin_Page::add_query_args_and_nonce(
683
+			array(
684
+				'action' => 'run_datetime_offset_fix',
685
+				'return_action' => $this->_req_action
686
+			),
687
+			EE_MAINTENANCE_ADMIN_URL
688
+		);
689
+		$form = $this->_get_datetime_offset_fix_form();
690
+		$this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
691
+		$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
692
+													  . $form->get_html_and_js()
693
+													  . $form->form_close();
694
+		$this->display_admin_page_with_no_sidebar();
695
+	}
696
+
697
+
698
+
699
+	protected function _get_datetime_offset_fix_form()
700
+	{
701
+		if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
+			$this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
703
+				array(
704
+					'name' => 'datetime_offset_fix_option',
705
+					'layout_strategy' => new EE_Admin_Two_Column_Layout(),
706
+					'subsections' => array(
707
+						'title' => new EE_Form_Section_HTML(
708
+							EEH_HTML::h2(
709
+								esc_html__('Datetime Offset Tool', 'event_espresso')
710
+							)
711
+						),
712
+						'explanation' => new EE_Form_Section_HTML(
713
+							EEH_HTML::p(
714
+								esc_html__(
715
+									'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
716
+									'event_espresso'
717
+								)
718
+							)
719
+							. EEH_HTML::p(
720
+								esc_html__(
721
+									'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.',
722
+									'event_espresso'
723
+								)
724
+							)
725
+						),
726
+						'offset_input' => new EE_Float_Input(
727
+							array(
728
+								'html_name' => 'offset_for_datetimes',
729
+								'html_label_text' => esc_html__(
730
+									'Offset to apply (in hours):',
731
+									'event_espresso'
732
+								),
733
+								'min_value' => '-12',
734
+								'max_value' => '14',
735
+								'step_value' => '.25',
736
+								'default' => DatetimeOffsetFix::getOffset()
737
+							)
738
+						),
739
+						'submit' => new EE_Submit_Input(
740
+							array(
741
+								'html_label_text' => '',
742
+								'default' => esc_html__('Apply Offset', 'event_espresso')
743
+							)
744
+						)
745
+					)
746
+				)
747
+			);
748
+		}
749
+		return $this->datetime_fix_offset_form;
750
+	}
751
+
752
+
753
+	/**
754
+	 * Callback for the run_datetime_offset_fix route.
755
+	 * @throws EE_Error
756
+	 */
757
+	protected function _apply_datetime_offset()
758
+	{
759
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
760
+			$form = $this->_get_datetime_offset_fix_form();
761
+			$form->receive_form_submission($this->_req_data);
762
+			if ($form->is_valid()) {
763
+				//save offset so batch processor can get it.
764
+				DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
765
+				//redirect to batch tool
766
+				wp_redirect(
767
+					EE_Admin_Page::add_query_args_and_nonce(
768
+						array(
769
+							'page' => 'espresso_batch',
770
+							'batch' => 'job',
771
+							'label' => esc_html__('Applying Offset', 'event_espresso'),
772
+							'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
773
+							'return_url' => urlencode(home_url(add_query_arg(null, null))),
774
+						),
775
+						admin_url()
776
+					)
777
+				);
778
+				exit;
779
+			}
780
+		}
781
+	}
782 782
 } //end Maintenance_Admin_Page class
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     public static function instance()
33 33
     {
34 34
         // check if class object is instantiated
35
-        if (! self::$_instance instanceof EE_Admin) {
35
+        if ( ! self::$_instance instanceof EE_Admin) {
36 36
             self::$_instance = new self();
37 37
         }
38 38
         return self::$_instance;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function _define_all_constants()
93 93
     {
94
-        if (! defined('EE_ADMIN_URL')) {
95
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
94
+        if ( ! defined('EE_ADMIN_URL')) {
95
+            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
96
+            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
97
+            define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS);
98
+            define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
99 99
             define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100 100
         }
101 101
     }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         // set $main_file in stone
115 115
         static $main_file;
116 116
         // if $main_file is not set yet
117
-        if (! $main_file) {
117
+        if ( ! $main_file) {
118 118
             $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119 119
         }
120 120
         if ($plugin === $main_file) {
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
     public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166 166
     {
167 167
         return array(
168
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
168
+            'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS,
169
+            'about'       => EE_ADMIN_PAGES.'about'.DS,
170
+            'support'     => EE_ADMIN_PAGES.'support'.DS,
171 171
         );
172 172
     }
173 173
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
             add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196 196
         }
197 197
         // run the admin page factory but ONLY if we are doing an ee admin ajax request
198
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
198
+        if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199 199
             try {
200 200
                 //this loads the controller for the admin pages which will setup routing etc
201 201
                 EE_Registry::instance()->load_core('Admin_Page_Loader');
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function enable_hidden_ee_nav_menu_metaboxes()
248 248
     {
249 249
         global $wp_meta_boxes, $pagenow;
250
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
250
+        if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251 251
             return;
252 252
         }
253 253
         $user = wp_get_current_user();
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      */
319 319
     public function modify_edit_post_link($link, $id)
320 320
     {
321
-        if (! $post = get_post($id)) {
321
+        if ( ! $post = get_post($id)) {
322 322
             return $link;
323 323
         }
324 324
         if ($post->post_type === 'espresso_attendees') {
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 
545 545
         //loop through to remove any critical pages from the array.
546 546
         foreach ($critical_pages as $page_id) {
547
-            $needle = 'value="' . $page_id . '"';
547
+            $needle = 'value="'.$page_id.'"';
548 548
             foreach ($split_output as $key => $haystack) {
549 549
                 if (strpos($haystack, $needle) !== false) {
550 550
                     unset($split_output[$key]);
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         // calls.
571 571
         wp_enqueue_script(
572 572
             'ee-inject-wp',
573
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
573
+            EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js',
574 574
             array('jquery'),
575 575
             EVENT_ESPRESSO_VERSION,
576 576
             true
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
         // register cookie script for future dependencies
579 579
         wp_register_script(
580 580
             'jquery-cookie',
581
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
581
+            EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js',
582 582
             array('jquery'),
583 583
             '2.1',
584 584
             true
@@ -587,16 +587,16 @@  discard block
 block discarded – undo
587 587
         // via: add_filter('FHEE_load_joyride', '__return_true' );
588 588
         if (apply_filters('FHEE_load_joyride', false)) {
589 589
             //joyride style
590
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
590
+            wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1');
591 591
             wp_register_style(
592 592
                 'ee-joyride-css',
593
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
593
+                EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css',
594 594
                 array('joyride-css'),
595 595
                 EVENT_ESPRESSO_VERSION
596 596
             );
597 597
             wp_register_script(
598 598
                 'joyride-modernizr',
599
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
599
+                EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js',
600 600
                 array(),
601 601
                 '2.1',
602 602
                 true
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
             //joyride JS
605 605
             wp_register_script(
606 606
                 'jquery-joyride',
607
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
607
+                EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js',
608 608
                 array('jquery-cookie', 'joyride-modernizr'),
609 609
                 '2.1',
610 610
                 true
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
     public function get_persistent_admin_notices()
658 658
     {
659 659
         // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
660
-        $args       = array(
660
+        $args = array(
661 661
             'page'   => EE_Registry::instance()->REQ->is_set('page')
662 662
                 ? EE_Registry::instance()->REQ->get('page')
663 663
                 : '',
@@ -704,21 +704,21 @@  discard block
 block discarded – undo
704 704
                 ),
705 705
             )
706 706
         );
707
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
707
+        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
708 708
             array('page' => 'espresso_registrations'),
709 709
             admin_url('admin.php')
710 710
         );
711
-        $items['registrations']['text']  = sprintf(
711
+        $items['registrations']['text'] = sprintf(
712 712
             _n('%s Registration', '%s Registrations', $registrations),
713 713
             number_format_i18n($registrations)
714 714
         );
715 715
         $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
716 716
 
717
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
717
+        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
718 718
 
719 719
         foreach ($items as $type => $item_properties) {
720 720
             $elements[] = sprintf(
721
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
721
+                '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>',
722 722
                 $item_properties['url'],
723 723
                 $item_properties['title'],
724 724
                 $item_properties['text']
@@ -744,10 +744,10 @@  discard block
 block discarded – undo
744 744
         // check for date_format or time_format
745 745
         switch ($option) {
746 746
             case 'date_format':
747
-                $date_time_format = $value . ' ' . get_option('time_format');
747
+                $date_time_format = $value.' '.get_option('time_format');
748 748
                 break;
749 749
             case 'time_format':
750
-                $date_time_format = get_option('date_format') . ' ' . $value;
750
+                $date_time_format = get_option('date_format').' '.$value;
751 751
                 break;
752 752
             default:
753 753
                 $date_time_format = false;
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 
771 771
 
772 772
                 foreach ($error_msg as $error) {
773
-                    $msg .= '<li>' . $error . '</li>';
773
+                    $msg .= '<li>'.$error.'</li>';
774 774
                 }
775 775
 
776 776
                 $msg .= '</ul></p><p>'
Please login to merge, or discard this patch.
Indentation   +848 added lines, -848 removed lines patch added patch discarded remove patch
@@ -15,395 +15,395 @@  discard block
 block discarded – undo
15 15
 final class EE_Admin implements InterminableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @access private
20
-     * @var EE_Admin $_instance
21
-     */
22
-    private static $_instance;
23
-
24
-
25
-    /**
26
-     *@ singleton method used to instantiate class object
27
-     *@ access public
28
-     *@ return class instance
29
-     *
30
-     * @throws \EE_Error
31
-     */
32
-    public static function instance()
33
-    {
34
-        // check if class object is instantiated
35
-        if (! self::$_instance instanceof EE_Admin) {
36
-            self::$_instance = new self();
37
-        }
38
-        return self::$_instance;
39
-    }
40
-
41
-
42
-    /**
43
-     * @return EE_Admin
44
-     * @throws EE_Error
45
-     */
46
-    public static function reset()
47
-    {
48
-        self::$_instance = null;
49
-        return self::instance();
50
-    }
51
-
52
-
53
-    /**
54
-     * class constructor
55
-     *
56
-     * @throws \EE_Error
57
-     */
58
-    protected function __construct()
59
-    {
60
-        // define global EE_Admin constants
61
-        $this->_define_all_constants();
62
-        // set autoloaders for our admin page classes based on included path information
63
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
64
-        // admin hooks
65
-        add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
66
-        // load EE_Request_Handler early
67
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
68
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
69
-        add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'), 100);
71
-        add_action('admin_init', array($this, 'admin_init'), 100);
72
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
73
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
74
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
75
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
76
-        add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
77
-
78
-        //reset Environment config (we only do this on admin page loads);
79
-        EE_Registry::instance()->CFG->environment->recheck_values();
80
-
81
-        do_action('AHEE__EE_Admin__loaded');
82
-    }
83
-
84
-
85
-    /**
86
-     * _define_all_constants
87
-     * define constants that are set globally for all admin pages
88
-     *
89
-     * @access private
90
-     * @return void
91
-     */
92
-    private function _define_all_constants()
93
-    {
94
-        if (! defined('EE_ADMIN_URL')) {
95
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
99
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     *    filter_plugin_actions - adds links to the Plugins page listing
106
-     *
107
-     * @access    public
108
-     * @param    array  $links
109
-     * @param    string $plugin
110
-     * @return    array
111
-     */
112
-    public function filter_plugin_actions($links, $plugin)
113
-    {
114
-        // set $main_file in stone
115
-        static $main_file;
116
-        // if $main_file is not set yet
117
-        if (! $main_file) {
118
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119
-        }
120
-        if ($plugin === $main_file) {
121
-            // compare current plugin to this one
122
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
123
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
124
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
125
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
126
-                                    . '</a>';
127
-                array_unshift($links, $maintenance_link);
128
-            } else {
129
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
130
-                                     . esc_html__('Settings', 'event_espresso')
131
-                                     . '</a>';
132
-                $events_link       = '<a href="admin.php?page=espresso_events">'
133
-                                     . esc_html__('Events', 'event_espresso')
134
-                                     . '</a>';
135
-                // add before other links
136
-                array_unshift($links, $org_settings_link, $events_link);
137
-            }
138
-        }
139
-        return $links;
140
-    }
141
-
142
-
143
-    /**
144
-     *    _get_request
145
-     *
146
-     * @access public
147
-     * @return void
148
-     * @throws EE_Error
149
-     * @throws ReflectionException
150
-     */
151
-    public function get_request()
152
-    {
153
-        EE_Registry::instance()->load_core('Request_Handler');
154
-        EE_Registry::instance()->load_core('CPT_Strategy');
155
-    }
156
-
157
-
158
-    /**
159
-     *    hide_admin_pages_except_maintenance_mode
160
-     *
161
-     * @access public
162
-     * @param array $admin_page_folder_names
163
-     * @return array
164
-     */
165
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166
-    {
167
-        return array(
168
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
171
-        );
172
-    }
173
-
174
-
175
-    /**
176
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
177
-     * EE_Front_Controller's init phases have run
178
-     *
179
-     * @access public
180
-     * @return void
181
-     * @throws EE_Error
182
-     * @throws ReflectionException
183
-     */
184
-    public function init()
185
-    {
186
-        //only enable most of the EE_Admin IF we're not in full maintenance mode
187
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
188
-            //ok so we want to enable the entire admin
189
-            add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
190
-            add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
191
-            add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
192
-            //at a glance dashboard widget
193
-            add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
194
-            //filter for get_edit_post_link used on comments for custom post types
195
-            add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196
-        }
197
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
198
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199
-            try {
200
-                //this loads the controller for the admin pages which will setup routing etc
201
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
202
-            } catch (EE_Error $e) {
203
-                $e->get_error();
204
-            }
205
-        }
206
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
207
-        //make sure our CPTs and custom taxonomy metaboxes get shown for first time users
208
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
209
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
210
-        //exclude EE critical pages from all nav menus and wp_list_pages
211
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
212
-    }
213
-
214
-
215
-    /**
216
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
217
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
218
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
219
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
220
-     * normal property on the post_type object.  It's found ONLY in this particular context.
221
-     *
222
-     * @param  object $post_type WP post type object
223
-     * @return object            WP post type object
224
-     */
225
-    public function remove_pages_from_nav_menu($post_type)
226
-    {
227
-        //if this isn't the "pages" post type let's get out
228
-        if ($post_type->name !== 'page') {
229
-            return $post_type;
230
-        }
231
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
232
-
233
-        $post_type->_default_query = array(
234
-            'post__not_in' => $critical_pages,
235
-        );
236
-        return $post_type;
237
-    }
238
-
239
-
240
-    /**
241
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
242
-     * metaboxes get shown as well
243
-     *
244
-     * @access public
245
-     * @return void
246
-     */
247
-    public function enable_hidden_ee_nav_menu_metaboxes()
248
-    {
249
-        global $wp_meta_boxes, $pagenow;
250
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251
-            return;
252
-        }
253
-        $user = wp_get_current_user();
254
-        //has this been done yet?
255
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
256
-            return;
257
-        }
258
-
259
-        $hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
260
-        $initial_meta_boxes = apply_filters(
261
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
262
-            array(
263
-                'nav-menu-theme-locations',
264
-                'add-page',
265
-                'add-custom-links',
266
-                'add-category',
267
-                'add-espresso_events',
268
-                'add-espresso_venues',
269
-                'add-espresso_event_categories',
270
-                'add-espresso_venue_categories',
271
-                'add-post-type-post',
272
-                'add-post-type-page',
273
-            )
274
-        );
275
-
276
-        if (is_array($hidden_meta_boxes)) {
277
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
278
-                if (in_array($meta_box_id, $initial_meta_boxes)) {
279
-                    unset($hidden_meta_boxes[$key]);
280
-                }
281
-            }
282
-        }
283
-
284
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
285
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
286
-    }
287
-
288
-
289
-    /**
290
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
291
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
292
-     *
293
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
294
-     *         addons etc.
295
-     * @access public
296
-     * @return void
297
-     */
298
-    public function register_custom_nav_menu_boxes()
299
-    {
300
-        add_meta_box(
301
-            'add-extra-nav-menu-pages',
302
-            esc_html__('Event Espresso Pages', 'event_espresso'),
303
-            array($this, 'ee_cpt_archive_pages'),
304
-            'nav-menus',
305
-            'side',
306
-            'core'
307
-        );
308
-    }
309
-
310
-
311
-    /**
312
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
313
-     *
314
-     * @since   4.3.0
315
-     * @param string $link the original link generated by wp
316
-     * @param int    $id   post id
317
-     * @return string  the (maybe) modified link
318
-     */
319
-    public function modify_edit_post_link($link, $id)
320
-    {
321
-        if (! $post = get_post($id)) {
322
-            return $link;
323
-        }
324
-        if ($post->post_type === 'espresso_attendees') {
325
-            $query_args = array(
326
-                'action' => 'edit_attendee',
327
-                'post'   => $id,
328
-            );
329
-            return EEH_URL::add_query_args_and_nonce(
330
-                $query_args,
331
-                admin_url('admin.php?page=espresso_registrations')
332
-            );
333
-        }
334
-        return $link;
335
-    }
336
-
337
-
338
-    public function ee_cpt_archive_pages()
339
-    {
340
-        global $nav_menu_selected_id;
341
-
342
-        $db_fields   = false;
343
-        $walker      = new Walker_Nav_Menu_Checklist($db_fields);
344
-        $current_tab = 'event-archives';
345
-
346
-        /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
18
+	/**
19
+	 * @access private
20
+	 * @var EE_Admin $_instance
21
+	 */
22
+	private static $_instance;
23
+
24
+
25
+	/**
26
+	 *@ singleton method used to instantiate class object
27
+	 *@ access public
28
+	 *@ return class instance
29
+	 *
30
+	 * @throws \EE_Error
31
+	 */
32
+	public static function instance()
33
+	{
34
+		// check if class object is instantiated
35
+		if (! self::$_instance instanceof EE_Admin) {
36
+			self::$_instance = new self();
37
+		}
38
+		return self::$_instance;
39
+	}
40
+
41
+
42
+	/**
43
+	 * @return EE_Admin
44
+	 * @throws EE_Error
45
+	 */
46
+	public static function reset()
47
+	{
48
+		self::$_instance = null;
49
+		return self::instance();
50
+	}
51
+
52
+
53
+	/**
54
+	 * class constructor
55
+	 *
56
+	 * @throws \EE_Error
57
+	 */
58
+	protected function __construct()
59
+	{
60
+		// define global EE_Admin constants
61
+		$this->_define_all_constants();
62
+		// set autoloaders for our admin page classes based on included path information
63
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
64
+		// admin hooks
65
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
66
+		// load EE_Request_Handler early
67
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
68
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
69
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
71
+		add_action('admin_init', array($this, 'admin_init'), 100);
72
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
73
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
74
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
75
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
76
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
77
+
78
+		//reset Environment config (we only do this on admin page loads);
79
+		EE_Registry::instance()->CFG->environment->recheck_values();
80
+
81
+		do_action('AHEE__EE_Admin__loaded');
82
+	}
83
+
84
+
85
+	/**
86
+	 * _define_all_constants
87
+	 * define constants that are set globally for all admin pages
88
+	 *
89
+	 * @access private
90
+	 * @return void
91
+	 */
92
+	private function _define_all_constants()
93
+	{
94
+		if (! defined('EE_ADMIN_URL')) {
95
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
99
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 *    filter_plugin_actions - adds links to the Plugins page listing
106
+	 *
107
+	 * @access    public
108
+	 * @param    array  $links
109
+	 * @param    string $plugin
110
+	 * @return    array
111
+	 */
112
+	public function filter_plugin_actions($links, $plugin)
113
+	{
114
+		// set $main_file in stone
115
+		static $main_file;
116
+		// if $main_file is not set yet
117
+		if (! $main_file) {
118
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119
+		}
120
+		if ($plugin === $main_file) {
121
+			// compare current plugin to this one
122
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
123
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
124
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
125
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
126
+									. '</a>';
127
+				array_unshift($links, $maintenance_link);
128
+			} else {
129
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
130
+									 . esc_html__('Settings', 'event_espresso')
131
+									 . '</a>';
132
+				$events_link       = '<a href="admin.php?page=espresso_events">'
133
+									 . esc_html__('Events', 'event_espresso')
134
+									 . '</a>';
135
+				// add before other links
136
+				array_unshift($links, $org_settings_link, $events_link);
137
+			}
138
+		}
139
+		return $links;
140
+	}
141
+
142
+
143
+	/**
144
+	 *    _get_request
145
+	 *
146
+	 * @access public
147
+	 * @return void
148
+	 * @throws EE_Error
149
+	 * @throws ReflectionException
150
+	 */
151
+	public function get_request()
152
+	{
153
+		EE_Registry::instance()->load_core('Request_Handler');
154
+		EE_Registry::instance()->load_core('CPT_Strategy');
155
+	}
156
+
157
+
158
+	/**
159
+	 *    hide_admin_pages_except_maintenance_mode
160
+	 *
161
+	 * @access public
162
+	 * @param array $admin_page_folder_names
163
+	 * @return array
164
+	 */
165
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166
+	{
167
+		return array(
168
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
+			'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
+			'support'     => EE_ADMIN_PAGES . 'support' . DS,
171
+		);
172
+	}
173
+
174
+
175
+	/**
176
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
177
+	 * EE_Front_Controller's init phases have run
178
+	 *
179
+	 * @access public
180
+	 * @return void
181
+	 * @throws EE_Error
182
+	 * @throws ReflectionException
183
+	 */
184
+	public function init()
185
+	{
186
+		//only enable most of the EE_Admin IF we're not in full maintenance mode
187
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
188
+			//ok so we want to enable the entire admin
189
+			add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
190
+			add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
191
+			add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
192
+			//at a glance dashboard widget
193
+			add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
194
+			//filter for get_edit_post_link used on comments for custom post types
195
+			add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196
+		}
197
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
198
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199
+			try {
200
+				//this loads the controller for the admin pages which will setup routing etc
201
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
202
+			} catch (EE_Error $e) {
203
+				$e->get_error();
204
+			}
205
+		}
206
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
207
+		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
208
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
209
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
210
+		//exclude EE critical pages from all nav menus and wp_list_pages
211
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
212
+	}
213
+
214
+
215
+	/**
216
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
217
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
218
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
219
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
220
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
221
+	 *
222
+	 * @param  object $post_type WP post type object
223
+	 * @return object            WP post type object
224
+	 */
225
+	public function remove_pages_from_nav_menu($post_type)
226
+	{
227
+		//if this isn't the "pages" post type let's get out
228
+		if ($post_type->name !== 'page') {
229
+			return $post_type;
230
+		}
231
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
232
+
233
+		$post_type->_default_query = array(
234
+			'post__not_in' => $critical_pages,
235
+		);
236
+		return $post_type;
237
+	}
238
+
239
+
240
+	/**
241
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
242
+	 * metaboxes get shown as well
243
+	 *
244
+	 * @access public
245
+	 * @return void
246
+	 */
247
+	public function enable_hidden_ee_nav_menu_metaboxes()
248
+	{
249
+		global $wp_meta_boxes, $pagenow;
250
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251
+			return;
252
+		}
253
+		$user = wp_get_current_user();
254
+		//has this been done yet?
255
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
256
+			return;
257
+		}
258
+
259
+		$hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
260
+		$initial_meta_boxes = apply_filters(
261
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
262
+			array(
263
+				'nav-menu-theme-locations',
264
+				'add-page',
265
+				'add-custom-links',
266
+				'add-category',
267
+				'add-espresso_events',
268
+				'add-espresso_venues',
269
+				'add-espresso_event_categories',
270
+				'add-espresso_venue_categories',
271
+				'add-post-type-post',
272
+				'add-post-type-page',
273
+			)
274
+		);
275
+
276
+		if (is_array($hidden_meta_boxes)) {
277
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
278
+				if (in_array($meta_box_id, $initial_meta_boxes)) {
279
+					unset($hidden_meta_boxes[$key]);
280
+				}
281
+			}
282
+		}
283
+
284
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
285
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
286
+	}
287
+
288
+
289
+	/**
290
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
291
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
292
+	 *
293
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
294
+	 *         addons etc.
295
+	 * @access public
296
+	 * @return void
297
+	 */
298
+	public function register_custom_nav_menu_boxes()
299
+	{
300
+		add_meta_box(
301
+			'add-extra-nav-menu-pages',
302
+			esc_html__('Event Espresso Pages', 'event_espresso'),
303
+			array($this, 'ee_cpt_archive_pages'),
304
+			'nav-menus',
305
+			'side',
306
+			'core'
307
+		);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
313
+	 *
314
+	 * @since   4.3.0
315
+	 * @param string $link the original link generated by wp
316
+	 * @param int    $id   post id
317
+	 * @return string  the (maybe) modified link
318
+	 */
319
+	public function modify_edit_post_link($link, $id)
320
+	{
321
+		if (! $post = get_post($id)) {
322
+			return $link;
323
+		}
324
+		if ($post->post_type === 'espresso_attendees') {
325
+			$query_args = array(
326
+				'action' => 'edit_attendee',
327
+				'post'   => $id,
328
+			);
329
+			return EEH_URL::add_query_args_and_nonce(
330
+				$query_args,
331
+				admin_url('admin.php?page=espresso_registrations')
332
+			);
333
+		}
334
+		return $link;
335
+	}
336
+
337
+
338
+	public function ee_cpt_archive_pages()
339
+	{
340
+		global $nav_menu_selected_id;
341
+
342
+		$db_fields   = false;
343
+		$walker      = new Walker_Nav_Menu_Checklist($db_fields);
344
+		$current_tab = 'event-archives';
345
+
346
+		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
347 347
             $current_tab = 'search';
348 348
         }/**/
349 349
 
350
-        $removed_args = array(
351
-            'action',
352
-            'customlink-tab',
353
-            'edit-menu-item',
354
-            'menu-item',
355
-            'page-tab',
356
-            '_wpnonce',
357
-        );
350
+		$removed_args = array(
351
+			'action',
352
+			'customlink-tab',
353
+			'edit-menu-item',
354
+			'menu-item',
355
+			'page-tab',
356
+			'_wpnonce',
357
+		);
358 358
 
359
-        ?>
359
+		?>
360 360
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
361 361
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
362 362
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
363 363
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
364 364
                        href="<?php if ($nav_menu_selected_id) {
365
-                            echo esc_url(
366
-                                add_query_arg(
367
-                                    'extra-nav-menu-pages-tab',
368
-                                    'event-archives',
369
-                                    remove_query_arg($removed_args)
370
-                                )
371
-                            );
372
-                       } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
365
+							echo esc_url(
366
+								add_query_arg(
367
+									'extra-nav-menu-pages-tab',
368
+									'event-archives',
369
+									remove_query_arg($removed_args)
370
+								)
371
+							);
372
+					   } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
373 373
                         <?php _e('Event Archive Pages', 'event_espresso'); ?>
374 374
                     </a>
375 375
                 </li>
376 376
 
377 377
                 <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
378
-                echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
379
-                ?>">
378
+				echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
379
+				?>">
380 380
                     <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
381 381
                         <?php
382
-                        $pages          = $this->_get_extra_nav_menu_pages_items();
383
-                        $args['walker'] = $walker;
384
-                        echo walk_nav_menu_tree(
385
-                            array_map(
386
-                                array($this, '_setup_extra_nav_menu_pages_items'),
387
-                                $pages
388
-                            ),
389
-                            0,
390
-                            (object) $args
391
-                        );
392
-                        ?>
382
+						$pages          = $this->_get_extra_nav_menu_pages_items();
383
+						$args['walker'] = $walker;
384
+						echo walk_nav_menu_tree(
385
+							array_map(
386
+								array($this, '_setup_extra_nav_menu_pages_items'),
387
+								$pages
388
+							),
389
+							0,
390
+							(object) $args
391
+						);
392
+						?>
393 393
                     </ul>
394 394
                 </div><!-- /.tabs-panel -->
395 395
 
396 396
                 <p class="button-controls">
397 397
                 <span class="list-controls">
398 398
                     <a href="<?php
399
-                    echo esc_url(add_query_arg(
400
-                        array(
401
-                            'extra-nav-menu-pages-tab' => 'event-archives',
402
-                            'selectall'                => 1,
403
-                        ),
404
-                        remove_query_arg($removed_args)
405
-                    ));
406
-                    ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
399
+					echo esc_url(add_query_arg(
400
+						array(
401
+							'extra-nav-menu-pages-tab' => 'event-archives',
402
+							'selectall'                => 1,
403
+						),
404
+						remove_query_arg($removed_args)
405
+					));
406
+					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
407 407
                 </span>
408 408
                 <span class="add-to-menu">
409 409
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -416,485 +416,485 @@  discard block
 block discarded – undo
416 416
 
417 417
         </div><!-- /.posttypediv -->
418 418
         <?php
419
-    }
420
-
421
-
422
-    /**
423
-     * Returns an array of event archive nav items.
424
-     *
425
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
426
-     *        method we use for getting the extra nav menu items
427
-     * @return array
428
-     */
429
-    private function _get_extra_nav_menu_pages_items()
430
-    {
431
-        $menuitems[] = array(
432
-            'title'       => esc_html__('Event List', 'event_espresso'),
433
-            'url'         => get_post_type_archive_link('espresso_events'),
434
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
435
-        );
436
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
437
-    }
438
-
439
-
440
-    /**
441
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
442
-     * the properties and converts it to the menu item object.
443
-     *
444
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
445
-     * @param $menu_item_values
446
-     * @return stdClass
447
-     */
448
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
449
-    {
450
-        $menu_item = new stdClass();
451
-        $keys      = array(
452
-            'ID'               => 0,
453
-            'db_id'            => 0,
454
-            'menu_item_parent' => 0,
455
-            'object_id'        => -1,
456
-            'post_parent'      => 0,
457
-            'type'             => 'custom',
458
-            'object'           => '',
459
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
460
-            'title'            => '',
461
-            'url'              => '',
462
-            'target'           => '',
463
-            'attr_title'       => '',
464
-            'description'      => '',
465
-            'classes'          => array(),
466
-            'xfn'              => '',
467
-        );
468
-
469
-        foreach ($keys as $key => $value) {
470
-            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
471
-        }
472
-        return $menu_item;
473
-    }
474
-
475
-
476
-    /**
477
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
478
-     * EE_Admin_Page route is called.
479
-     *
480
-     * @return void
481
-     */
482
-    public function route_admin_request()
483
-    {
484
-    }
485
-
486
-
487
-    /**
488
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
489
-     *
490
-     * @return void
491
-     */
492
-    public function wp_loaded()
493
-    {
494
-    }
495
-
496
-
497
-    /**
498
-     * admin_init
499
-     *
500
-     * @access public
501
-     * @return void
502
-     * @throws EE_Error
503
-     * @throws ReflectionException
504
-     */
505
-    public function admin_init()
506
-    {
507
-
508
-        /**
509
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
510
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
511
-         * - check if doing post processing.
512
-         * - check if doing post processing of one of EE CPTs
513
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
514
-         */
515
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
516
-            EE_Registry::instance()->load_core('Register_CPTs');
517
-            EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
518
-        }
519
-
520
-
521
-        /**
522
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
523
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
524
-         * Pages" tab in the EE General Settings Admin page.
525
-         * This is for user-proofing.
526
-         */
527
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
528
-    }
529
-
530
-
531
-    /**
532
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
533
-     *
534
-     * @param string $output Current output.
535
-     * @return string
536
-     */
537
-    public function modify_dropdown_pages($output)
538
-    {
539
-        //get critical pages
540
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
541
-
542
-        //split current output by line break for easier parsing.
543
-        $split_output = explode("\n", $output);
544
-
545
-        //loop through to remove any critical pages from the array.
546
-        foreach ($critical_pages as $page_id) {
547
-            $needle = 'value="' . $page_id . '"';
548
-            foreach ($split_output as $key => $haystack) {
549
-                if (strpos($haystack, $needle) !== false) {
550
-                    unset($split_output[$key]);
551
-                }
552
-            }
553
-        }
554
-
555
-        //replace output with the new contents
556
-        return implode("\n", $split_output);
557
-    }
558
-
559
-
560
-    /**
561
-     * enqueue all admin scripts that need loaded for admin pages
562
-     *
563
-     * @access public
564
-     * @return void
565
-     */
566
-    public function enqueue_admin_scripts()
567
-    {
568
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
569
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
570
-        // calls.
571
-        wp_enqueue_script(
572
-            'ee-inject-wp',
573
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
574
-            array('jquery'),
575
-            EVENT_ESPRESSO_VERSION,
576
-            true
577
-        );
578
-        // register cookie script for future dependencies
579
-        wp_register_script(
580
-            'jquery-cookie',
581
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
582
-            array('jquery'),
583
-            '2.1',
584
-            true
585
-        );
586
-        //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
587
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
588
-        if (apply_filters('FHEE_load_joyride', false)) {
589
-            //joyride style
590
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
591
-            wp_register_style(
592
-                'ee-joyride-css',
593
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
594
-                array('joyride-css'),
595
-                EVENT_ESPRESSO_VERSION
596
-            );
597
-            wp_register_script(
598
-                'joyride-modernizr',
599
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
600
-                array(),
601
-                '2.1',
602
-                true
603
-            );
604
-            //joyride JS
605
-            wp_register_script(
606
-                'jquery-joyride',
607
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
608
-                array('jquery-cookie', 'joyride-modernizr'),
609
-                '2.1',
610
-                true
611
-            );
612
-            // wanna go for a joyride?
613
-            wp_enqueue_style('ee-joyride-css');
614
-            wp_enqueue_script('jquery-joyride');
615
-        }
616
-    }
617
-
618
-
619
-    /**
620
-     *    display_admin_notices
621
-     *
622
-     * @access    public
623
-     * @return    string
624
-     */
625
-    public function display_admin_notices()
626
-    {
627
-        //add non-dismissable notice for datetime changes.  Only valid if EE version is greater than 4.9.46.p and the
628
-        // site does not have a timezone_string set.
629
-        if (EE_Register_Addon::_meets_min_core_version_requirement(
630
-                '4.9.46.p'
631
-            )
632
-            && ! get_option('timezone_string')
633
-        ) {
634
-            EE_Error::add_attention(
635
-                sprintf(
636
-                    esc_html__(
637
-                        '%1$sImportant%2$s: Please note some upcoming changes to dates and times in Event Espresso that may affect your website.  Read more about it %3$shere%4$s.',
638
-                        'event_espresso'
639
-                    ),
640
-                    '<strong>',
641
-                    '</strong>',
642
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
643
-                    '</a>'
644
-                )
645
-            );
646
-        }
647
-        echo EE_Error::get_notices();
648
-    }
649
-
650
-
651
-    /**
652
-     *    get_persistent_admin_notices
653
-     *
654
-     * @access    public
655
-     * @return        void
656
-     */
657
-    public function get_persistent_admin_notices()
658
-    {
659
-        // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
660
-        $args       = array(
661
-            'page'   => EE_Registry::instance()->REQ->is_set('page')
662
-                ? EE_Registry::instance()->REQ->get('page')
663
-                : '',
664
-            'action' => EE_Registry::instance()->REQ->is_set('action')
665
-                ? EE_Registry::instance()->REQ->get('action')
666
-                : '',
667
-        );
668
-        $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL);
669
-        echo EE_Error::get_persistent_admin_notices($return_url);
670
-    }
671
-
672
-
673
-    /**
674
-     *    dismiss_persistent_admin_notice
675
-     *
676
-     * @access    public
677
-     * @return        void
678
-     */
679
-    public function dismiss_ee_nag_notice_callback()
680
-    {
681
-        EE_Error::dismiss_persistent_admin_notice();
682
-    }
683
-
684
-
685
-    /**
686
-     * @param array $elements
687
-     * @return array
688
-     * @throws \EE_Error
689
-     */
690
-    public function dashboard_glance_items($elements)
691
-    {
692
-        $elements                        = is_array($elements) ? $elements : array($elements);
693
-        $events                          = EEM_Event::instance()->count();
694
-        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
695
-            array('page' => 'espresso_events'),
696
-            admin_url('admin.php')
697
-        );
698
-        $items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
699
-        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
700
-        $registrations                   = EEM_Registration::instance()->count(
701
-            array(
702
-                array(
703
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
704
-                ),
705
-            )
706
-        );
707
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
708
-            array('page' => 'espresso_registrations'),
709
-            admin_url('admin.php')
710
-        );
711
-        $items['registrations']['text']  = sprintf(
712
-            _n('%s Registration', '%s Registrations', $registrations),
713
-            number_format_i18n($registrations)
714
-        );
715
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
716
-
717
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
718
-
719
-        foreach ($items as $type => $item_properties) {
720
-            $elements[] = sprintf(
721
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
722
-                $item_properties['url'],
723
-                $item_properties['title'],
724
-                $item_properties['text']
725
-            );
726
-        }
727
-        return $elements;
728
-    }
729
-
730
-
731
-    /**
732
-     *    check_for_invalid_datetime_formats
733
-     *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
734
-     *    their selected format can be parsed by PHP
735
-     *
736
-     * @access    public
737
-     * @param    $value
738
-     * @param    $option
739
-     * @throws EE_Error
740
-     * @return    string
741
-     */
742
-    public function check_for_invalid_datetime_formats($value, $option)
743
-    {
744
-        // check for date_format or time_format
745
-        switch ($option) {
746
-            case 'date_format':
747
-                $date_time_format = $value . ' ' . get_option('time_format');
748
-                break;
749
-            case 'time_format':
750
-                $date_time_format = get_option('date_format') . ' ' . $value;
751
-                break;
752
-            default:
753
-                $date_time_format = false;
754
-        }
755
-        // do we have a date_time format to check ?
756
-        if ($date_time_format) {
757
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
758
-
759
-            if (is_array($error_msg)) {
760
-                $msg = '<p>'
761
-                       . sprintf(
762
-                           esc_html__(
763
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
764
-                               'event_espresso'
765
-                           ),
766
-                           date($date_time_format),
767
-                           $date_time_format
768
-                       )
769
-                       . '</p><p><ul>';
770
-
771
-
772
-                foreach ($error_msg as $error) {
773
-                    $msg .= '<li>' . $error . '</li>';
774
-                }
775
-
776
-                $msg .= '</ul></p><p>'
777
-                        . sprintf(
778
-                            esc_html__(
779
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
780
-                                'event_espresso'
781
-                            ),
782
-                            '<span style="color:#D54E21;">',
783
-                            '</span>'
784
-                        )
785
-                        . '</p>';
786
-
787
-                // trigger WP settings error
788
-                add_settings_error(
789
-                    'date_format',
790
-                    'date_format',
791
-                    $msg
792
-                );
793
-
794
-                // set format to something valid
795
-                switch ($option) {
796
-                    case 'date_format':
797
-                        $value = 'F j, Y';
798
-                        break;
799
-                    case 'time_format':
800
-                        $value = 'g:i a';
801
-                        break;
802
-                }
803
-            }
804
-        }
805
-        return $value;
806
-    }
807
-
808
-
809
-    /**
810
-     *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
811
-     *
812
-     * @access    public
813
-     * @param $content
814
-     * @return    string
815
-     */
816
-    public function its_eSpresso($content)
817
-    {
818
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
819
-    }
820
-
821
-
822
-    /**
823
-     *    espresso_admin_footer
824
-     *
825
-     * @access    public
826
-     * @return    string
827
-     */
828
-    public function espresso_admin_footer()
829
-    {
830
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
831
-    }
832
-
833
-
834
-    /**
835
-     * static method for registering ee admin page.
836
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
837
-     *
838
-     * @since      4.3.0
839
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
840
-     * @see        EE_Register_Admin_Page::register()
841
-     * @param       $page_basename
842
-     * @param       $page_path
843
-     * @param array $config
844
-     * @return void
845
-     * @throws EE_Error
846
-     */
847
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
848
-    {
849
-        EE_Error::doing_it_wrong(
850
-            __METHOD__,
851
-            sprintf(
852
-                esc_html__(
853
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
854
-                    'event_espresso'
855
-                ),
856
-                $page_basename
857
-            ),
858
-            '4.3'
859
-        );
860
-        if (class_exists('EE_Register_Admin_Page')) {
861
-            $config['page_path'] = $page_path;
862
-        }
863
-        EE_Register_Admin_Page::register($page_basename, $config);
864
-    }
865
-
866
-
867
-    /**
868
-     * @deprecated 4.8.41
869
-     * @access     public
870
-     * @param  int      $post_ID
871
-     * @param  \WP_Post $post
872
-     * @return void
873
-     */
874
-    public static function parse_post_content_on_save($post_ID, $post)
875
-    {
876
-        EE_Error::doing_it_wrong(
877
-            __METHOD__,
878
-            esc_html__('Usage is deprecated', 'event_espresso'),
879
-            '4.8.41'
880
-        );
881
-    }
882
-
883
-
884
-    /**
885
-     * @deprecated 4.8.41
886
-     * @access     public
887
-     * @param  $option
888
-     * @param  $old_value
889
-     * @param  $value
890
-     * @return void
891
-     */
892
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
893
-    {
894
-        EE_Error::doing_it_wrong(
895
-            __METHOD__,
896
-            esc_html__('Usage is deprecated', 'event_espresso'),
897
-            '4.8.41'
898
-        );
899
-    }
419
+	}
420
+
421
+
422
+	/**
423
+	 * Returns an array of event archive nav items.
424
+	 *
425
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
426
+	 *        method we use for getting the extra nav menu items
427
+	 * @return array
428
+	 */
429
+	private function _get_extra_nav_menu_pages_items()
430
+	{
431
+		$menuitems[] = array(
432
+			'title'       => esc_html__('Event List', 'event_espresso'),
433
+			'url'         => get_post_type_archive_link('espresso_events'),
434
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
435
+		);
436
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
437
+	}
438
+
439
+
440
+	/**
441
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
442
+	 * the properties and converts it to the menu item object.
443
+	 *
444
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
445
+	 * @param $menu_item_values
446
+	 * @return stdClass
447
+	 */
448
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
449
+	{
450
+		$menu_item = new stdClass();
451
+		$keys      = array(
452
+			'ID'               => 0,
453
+			'db_id'            => 0,
454
+			'menu_item_parent' => 0,
455
+			'object_id'        => -1,
456
+			'post_parent'      => 0,
457
+			'type'             => 'custom',
458
+			'object'           => '',
459
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
460
+			'title'            => '',
461
+			'url'              => '',
462
+			'target'           => '',
463
+			'attr_title'       => '',
464
+			'description'      => '',
465
+			'classes'          => array(),
466
+			'xfn'              => '',
467
+		);
468
+
469
+		foreach ($keys as $key => $value) {
470
+			$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
471
+		}
472
+		return $menu_item;
473
+	}
474
+
475
+
476
+	/**
477
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
478
+	 * EE_Admin_Page route is called.
479
+	 *
480
+	 * @return void
481
+	 */
482
+	public function route_admin_request()
483
+	{
484
+	}
485
+
486
+
487
+	/**
488
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
489
+	 *
490
+	 * @return void
491
+	 */
492
+	public function wp_loaded()
493
+	{
494
+	}
495
+
496
+
497
+	/**
498
+	 * admin_init
499
+	 *
500
+	 * @access public
501
+	 * @return void
502
+	 * @throws EE_Error
503
+	 * @throws ReflectionException
504
+	 */
505
+	public function admin_init()
506
+	{
507
+
508
+		/**
509
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
510
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
511
+		 * - check if doing post processing.
512
+		 * - check if doing post processing of one of EE CPTs
513
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
514
+		 */
515
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
516
+			EE_Registry::instance()->load_core('Register_CPTs');
517
+			EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
518
+		}
519
+
520
+
521
+		/**
522
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
523
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
524
+		 * Pages" tab in the EE General Settings Admin page.
525
+		 * This is for user-proofing.
526
+		 */
527
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
528
+	}
529
+
530
+
531
+	/**
532
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
533
+	 *
534
+	 * @param string $output Current output.
535
+	 * @return string
536
+	 */
537
+	public function modify_dropdown_pages($output)
538
+	{
539
+		//get critical pages
540
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
541
+
542
+		//split current output by line break for easier parsing.
543
+		$split_output = explode("\n", $output);
544
+
545
+		//loop through to remove any critical pages from the array.
546
+		foreach ($critical_pages as $page_id) {
547
+			$needle = 'value="' . $page_id . '"';
548
+			foreach ($split_output as $key => $haystack) {
549
+				if (strpos($haystack, $needle) !== false) {
550
+					unset($split_output[$key]);
551
+				}
552
+			}
553
+		}
554
+
555
+		//replace output with the new contents
556
+		return implode("\n", $split_output);
557
+	}
558
+
559
+
560
+	/**
561
+	 * enqueue all admin scripts that need loaded for admin pages
562
+	 *
563
+	 * @access public
564
+	 * @return void
565
+	 */
566
+	public function enqueue_admin_scripts()
567
+	{
568
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
569
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
570
+		// calls.
571
+		wp_enqueue_script(
572
+			'ee-inject-wp',
573
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
574
+			array('jquery'),
575
+			EVENT_ESPRESSO_VERSION,
576
+			true
577
+		);
578
+		// register cookie script for future dependencies
579
+		wp_register_script(
580
+			'jquery-cookie',
581
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
582
+			array('jquery'),
583
+			'2.1',
584
+			true
585
+		);
586
+		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
587
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
588
+		if (apply_filters('FHEE_load_joyride', false)) {
589
+			//joyride style
590
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
591
+			wp_register_style(
592
+				'ee-joyride-css',
593
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
594
+				array('joyride-css'),
595
+				EVENT_ESPRESSO_VERSION
596
+			);
597
+			wp_register_script(
598
+				'joyride-modernizr',
599
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
600
+				array(),
601
+				'2.1',
602
+				true
603
+			);
604
+			//joyride JS
605
+			wp_register_script(
606
+				'jquery-joyride',
607
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
608
+				array('jquery-cookie', 'joyride-modernizr'),
609
+				'2.1',
610
+				true
611
+			);
612
+			// wanna go for a joyride?
613
+			wp_enqueue_style('ee-joyride-css');
614
+			wp_enqueue_script('jquery-joyride');
615
+		}
616
+	}
617
+
618
+
619
+	/**
620
+	 *    display_admin_notices
621
+	 *
622
+	 * @access    public
623
+	 * @return    string
624
+	 */
625
+	public function display_admin_notices()
626
+	{
627
+		//add non-dismissable notice for datetime changes.  Only valid if EE version is greater than 4.9.46.p and the
628
+		// site does not have a timezone_string set.
629
+		if (EE_Register_Addon::_meets_min_core_version_requirement(
630
+				'4.9.46.p'
631
+			)
632
+			&& ! get_option('timezone_string')
633
+		) {
634
+			EE_Error::add_attention(
635
+				sprintf(
636
+					esc_html__(
637
+						'%1$sImportant%2$s: Please note some upcoming changes to dates and times in Event Espresso that may affect your website.  Read more about it %3$shere%4$s.',
638
+						'event_espresso'
639
+					),
640
+					'<strong>',
641
+					'</strong>',
642
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
643
+					'</a>'
644
+				)
645
+			);
646
+		}
647
+		echo EE_Error::get_notices();
648
+	}
649
+
650
+
651
+	/**
652
+	 *    get_persistent_admin_notices
653
+	 *
654
+	 * @access    public
655
+	 * @return        void
656
+	 */
657
+	public function get_persistent_admin_notices()
658
+	{
659
+		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
660
+		$args       = array(
661
+			'page'   => EE_Registry::instance()->REQ->is_set('page')
662
+				? EE_Registry::instance()->REQ->get('page')
663
+				: '',
664
+			'action' => EE_Registry::instance()->REQ->is_set('action')
665
+				? EE_Registry::instance()->REQ->get('action')
666
+				: '',
667
+		);
668
+		$return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL);
669
+		echo EE_Error::get_persistent_admin_notices($return_url);
670
+	}
671
+
672
+
673
+	/**
674
+	 *    dismiss_persistent_admin_notice
675
+	 *
676
+	 * @access    public
677
+	 * @return        void
678
+	 */
679
+	public function dismiss_ee_nag_notice_callback()
680
+	{
681
+		EE_Error::dismiss_persistent_admin_notice();
682
+	}
683
+
684
+
685
+	/**
686
+	 * @param array $elements
687
+	 * @return array
688
+	 * @throws \EE_Error
689
+	 */
690
+	public function dashboard_glance_items($elements)
691
+	{
692
+		$elements                        = is_array($elements) ? $elements : array($elements);
693
+		$events                          = EEM_Event::instance()->count();
694
+		$items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
695
+			array('page' => 'espresso_events'),
696
+			admin_url('admin.php')
697
+		);
698
+		$items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
699
+		$items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
700
+		$registrations                   = EEM_Registration::instance()->count(
701
+			array(
702
+				array(
703
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
704
+				),
705
+			)
706
+		);
707
+		$items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
708
+			array('page' => 'espresso_registrations'),
709
+			admin_url('admin.php')
710
+		);
711
+		$items['registrations']['text']  = sprintf(
712
+			_n('%s Registration', '%s Registrations', $registrations),
713
+			number_format_i18n($registrations)
714
+		);
715
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
716
+
717
+		$items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
718
+
719
+		foreach ($items as $type => $item_properties) {
720
+			$elements[] = sprintf(
721
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
722
+				$item_properties['url'],
723
+				$item_properties['title'],
724
+				$item_properties['text']
725
+			);
726
+		}
727
+		return $elements;
728
+	}
729
+
730
+
731
+	/**
732
+	 *    check_for_invalid_datetime_formats
733
+	 *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
734
+	 *    their selected format can be parsed by PHP
735
+	 *
736
+	 * @access    public
737
+	 * @param    $value
738
+	 * @param    $option
739
+	 * @throws EE_Error
740
+	 * @return    string
741
+	 */
742
+	public function check_for_invalid_datetime_formats($value, $option)
743
+	{
744
+		// check for date_format or time_format
745
+		switch ($option) {
746
+			case 'date_format':
747
+				$date_time_format = $value . ' ' . get_option('time_format');
748
+				break;
749
+			case 'time_format':
750
+				$date_time_format = get_option('date_format') . ' ' . $value;
751
+				break;
752
+			default:
753
+				$date_time_format = false;
754
+		}
755
+		// do we have a date_time format to check ?
756
+		if ($date_time_format) {
757
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
758
+
759
+			if (is_array($error_msg)) {
760
+				$msg = '<p>'
761
+					   . sprintf(
762
+						   esc_html__(
763
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
764
+							   'event_espresso'
765
+						   ),
766
+						   date($date_time_format),
767
+						   $date_time_format
768
+					   )
769
+					   . '</p><p><ul>';
770
+
771
+
772
+				foreach ($error_msg as $error) {
773
+					$msg .= '<li>' . $error . '</li>';
774
+				}
775
+
776
+				$msg .= '</ul></p><p>'
777
+						. sprintf(
778
+							esc_html__(
779
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
780
+								'event_espresso'
781
+							),
782
+							'<span style="color:#D54E21;">',
783
+							'</span>'
784
+						)
785
+						. '</p>';
786
+
787
+				// trigger WP settings error
788
+				add_settings_error(
789
+					'date_format',
790
+					'date_format',
791
+					$msg
792
+				);
793
+
794
+				// set format to something valid
795
+				switch ($option) {
796
+					case 'date_format':
797
+						$value = 'F j, Y';
798
+						break;
799
+					case 'time_format':
800
+						$value = 'g:i a';
801
+						break;
802
+				}
803
+			}
804
+		}
805
+		return $value;
806
+	}
807
+
808
+
809
+	/**
810
+	 *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
811
+	 *
812
+	 * @access    public
813
+	 * @param $content
814
+	 * @return    string
815
+	 */
816
+	public function its_eSpresso($content)
817
+	{
818
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
819
+	}
820
+
821
+
822
+	/**
823
+	 *    espresso_admin_footer
824
+	 *
825
+	 * @access    public
826
+	 * @return    string
827
+	 */
828
+	public function espresso_admin_footer()
829
+	{
830
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
831
+	}
832
+
833
+
834
+	/**
835
+	 * static method for registering ee admin page.
836
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
837
+	 *
838
+	 * @since      4.3.0
839
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
840
+	 * @see        EE_Register_Admin_Page::register()
841
+	 * @param       $page_basename
842
+	 * @param       $page_path
843
+	 * @param array $config
844
+	 * @return void
845
+	 * @throws EE_Error
846
+	 */
847
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
848
+	{
849
+		EE_Error::doing_it_wrong(
850
+			__METHOD__,
851
+			sprintf(
852
+				esc_html__(
853
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
854
+					'event_espresso'
855
+				),
856
+				$page_basename
857
+			),
858
+			'4.3'
859
+		);
860
+		if (class_exists('EE_Register_Admin_Page')) {
861
+			$config['page_path'] = $page_path;
862
+		}
863
+		EE_Register_Admin_Page::register($page_basename, $config);
864
+	}
865
+
866
+
867
+	/**
868
+	 * @deprecated 4.8.41
869
+	 * @access     public
870
+	 * @param  int      $post_ID
871
+	 * @param  \WP_Post $post
872
+	 * @return void
873
+	 */
874
+	public static function parse_post_content_on_save($post_ID, $post)
875
+	{
876
+		EE_Error::doing_it_wrong(
877
+			__METHOD__,
878
+			esc_html__('Usage is deprecated', 'event_espresso'),
879
+			'4.8.41'
880
+		);
881
+	}
882
+
883
+
884
+	/**
885
+	 * @deprecated 4.8.41
886
+	 * @access     public
887
+	 * @param  $option
888
+	 * @param  $old_value
889
+	 * @param  $value
890
+	 * @return void
891
+	 */
892
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
893
+	{
894
+		EE_Error::doing_it_wrong(
895
+			__METHOD__,
896
+			esc_html__('Usage is deprecated', 'event_espresso'),
897
+			'4.8.41'
898
+		);
899
+	}
900 900
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Venue_Shortcodes.lib.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -157,7 +157,7 @@
 block discarded – undo
157 157
     /**
158 158
      * This retrieves the EE_Venue from the available data object.
159 159
      *
160
-     * @return EE_Venue|null
160
+     * @return EE_Base_Class|null
161 161
      */
162 162
     private function _get_venue() {
163 163
 
Please login to merge, or discard this patch.
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -16,288 +16,288 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Will hold the EE_Event if available
21
-     *
22
-     * @var EE_Event
23
-     */
24
-    protected $_event;
25
-
26
-    /**
27
-     * Will hold the EE_Venue if available
28
-     *
29
-     * @var EE_Venue
30
-     */
31
-    protected $_venue;
32
-
33
-
34
-    /**
35
-     * Initialize properties
36
-     */
37
-    protected function _init_props()
38
-    {
39
-        $this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
40
-        $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
41
-        $this->_shortcodes = array(
42
-            '[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
43
-            '[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
44
-            '[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
45
-            '[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
46
-            '[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
47
-            '[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
48
-            '[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
49
-            '[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
50
-            '[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
51
-            '[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
52
-            '[VENUE_FORMATTED_ADDRESS]' => esc_html__(
53
-                'This just outputs the venue address in a semantic address format.',
54
-                'event_espresso'
55
-            ),
56
-            '[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
57
-            '[VENUE_META_*]'            => esc_html__(
58
-                'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', 
59
-                'event_espresso'
60
-            ),
61
-            '[GOOGLE_MAP_URL]'          => esc_html__(
62
-                'URL for the google map associated with the venue.', 
63
-                'event_espresso'
64
-            ),
65
-            '[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
66
-            '[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
67
-        );
68
-    }
69
-
70
-
71
-    /**
72
-     * Parse incoming shortcode
73
-     * @param string $shortcode
74
-     * @return string
75
-     */
76
-    protected function _parser($shortcode)
77
-    {
78
-        $this->_venue = $this->_get_venue();
79
-        //If there is no venue object by now then get out.
80
-        if ( ! $this->_venue instanceof EE_Venue )
81
-            return '';
82
-
83
-        switch ($shortcode) {
84
-            case '[VENUE_TITLE]':
85
-                return $this->_venue('title');
86
-                break;
87
-
88
-            case '[VENUE_DESCRIPTION]':
89
-                return $this->_venue('description');
90
-                break;
91
-
92
-            case '[VENUE_URL]':
93
-                return $this->_venue('url');
94
-                break;
95
-
96
-            case '[VENUE_IMAGE]':
97
-                return $this->_venue('image');
98
-                break;
99
-
100
-            case '[VENUE_PHONE]':
101
-                return $this->_venue('phone');
102
-                break;
103
-
104
-            case '[VENUE_ADDRESS]':
105
-                return $this->_venue('address');
106
-                break;
107
-
108
-            case '[VENUE_ADDRESS2]':
109
-                return $this->_venue('address2');
110
-                break;
111
-
112
-            case '[VENUE_CITY]':
113
-                return $this->_venue('city');
114
-                break;
115
-
116
-            case '[VENUE_COUNTRY]':
117
-                return $this->_venue('country');
118
-                break;
119
-
120
-            case '[VENUE_STATE]':
121
-                return $this->_venue('state');
122
-                break;
123
-
124
-            case '[VENUE_ZIP]':
125
-                return $this->_venue('zip');
126
-                break;
127
-
128
-            case '[VENUE_FORMATTED_ADDRESS]':
129
-                return $this->_venue('formatted_address');
130
-                break;
131
-
132
-            case '[GOOGLE_MAP_URL]':
133
-                return $this->_venue('gmap_url');
134
-                break;
135
-
136
-            case '[GOOGLE_MAP_LINK]':
137
-                return $this->_venue('gmap_link');
138
-                break;
139
-
140
-            case '[GOOGLE_MAP_IMAGE]':
141
-                return $this->_venue('gmap_link_img');
142
-                break;
143
-
144
-        }
145
-
146
-        if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) {
147
-            $shortcode = str_replace( '[VENUE_META_*', '', $shortcode );
148
-            $shortcode = trim( str_replace( ']', '', $shortcode ) );
149
-
150
-            //pull the meta value from the venue post
151
-            $venue_meta = $this->_venue->get_post_meta( $shortcode, true );
152
-
153
-            return ! empty( $venue_meta ) ? $venue_meta : '';
154
-
155
-        }
156
-    }
157
-    /**
158
-     * This retrieves the EE_Venue from the available data object.
159
-     *
160
-     * @return EE_Venue|null
161
-     */
162
-    private function _get_venue() {
163
-
164
-        //we need the EE_Event object to get the venue.
165
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
166
-
167
-        //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
168
-        if (empty($this->_event)) {
169
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
170
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
171
-
172
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null;
173
-
174
-            //if still empty do we have a ticket data item?
175
-            $this->_event = empty($this->_event)
176
-                            && $this->_data instanceof EE_Ticket
177
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
178
-                ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
179
-                : $this->_event;
180
-
181
-            //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that.
182
-            $event        = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array();
183
-            $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event;
184
-        }
185
-
186
-        //If we have an event object use it to pull the venue.
187
-        if ($this->_event instanceof EE_Event) {
188
-            return $this->_event->get_first_related('Venue');
189
-        } 
190
-
191
-        return null;
192
-    }
193
-
194
-    /**
195
-     * This retrieves the specified venue information
196
-     *
197
-     * @param string $field  What Venue field to retrieve
198
-     * @return string What was retrieved!
199
-     * @throws EE_Error
200
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
201
-     */
202
-    private function _venue($field)
203
-    {
204
-
205
-        if (empty($this->_venue)) {
206
-            return '';
207
-        } //no venue so get out.
208
-
209
-        switch ($field) {
210
-            case 'title':
211
-                return $this->_venue->get('VNU_name');
212
-                break;
213
-
214
-            case 'description':
215
-                return $this->_venue->get('VNU_desc');
216
-                break;
217
-
218
-            case 'url':
219
-                $url = $this->_venue->get('VNU_url');
220
-                return empty($url) ? $this->_venue->get_permalink() : $url;
221
-                break;
222
-
223
-            case 'image':
224
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
225
-                       . '" alt="' . sprintf(
226
-                           esc_attr__('%s Feature Image', 'event_espresso'),
227
-                           $this->_venue->get('VNU_name')
228
-                       ) . '" />';
229
-                break;
230
-
231
-            case 'phone':
232
-                return $this->_venue->get('VNU_phone');
233
-                break;
234
-
235
-            case 'address':
236
-                return $this->_venue->get('VNU_address');
237
-                break;
238
-
239
-            case 'address2':
240
-                return $this->_venue->get('VNU_address2');
241
-                break;
242
-
243
-            case 'city':
244
-                return $this->_venue->get('VNU_city');
245
-                break;
246
-
247
-            case 'state':
248
-                $state = $this->_venue->state_obj();
249
-                return is_object($state) ? $state->get('STA_name') : '';
250
-                break;
251
-
252
-            case 'country':
253
-                $country = $this->_venue->country_obj();
254
-                return is_object($country) ? $country->get('CNT_name') : '';
255
-                break;
256
-
257
-            case 'zip':
258
-                return $this->_venue->get('VNU_zip');
259
-                break;
260
-
261
-            case 'formatted_address':
262
-                return EEH_Address::format($this->_venue);
263
-                break;
264
-
265
-            case 'gmap_link':
266
-            case 'gmap_url':
267
-            case 'gmap_link_img':
268
-                $atts = $this->get_map_attributes($this->_venue, $field);
269
-                return EEH_Maps::google_map_link($atts);
270
-                break;
271
-        }
272
-        return '';
273
-    }
274
-
275
-
276
-    /**
277
-     * Generates the attributes for retrieving a google_map artifact.
278
-     * @param EE_Venue $venue
279
-     * @param string   $field
280
-     * @return array
281
-     * @throws EE_Error
282
-     */
283
-    protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
284
-    {
285
-        $state   = $venue->state_obj();
286
-        $country = $venue->country_obj();
287
-        $atts    = array(
288
-            'id'      => $venue->ID(),
289
-            'address' => $venue->get('VNU_address'),
290
-            'city'    => $venue->get('VNU_city'),
291
-            'state'   => is_object($state) ? $state->get('STA_name') : '',
292
-            'zip'     => $venue->get('VNU_zip'),
293
-            'country' => is_object($country) ? $country->get('CNT_name') : '',
294
-            'type'    => $field === 'gmap_link' ? 'url' : 'map',
295
-            'map_w'   => 200,
296
-            'map_h'   => 200,
297
-        );
298
-        if ($field === 'gmap_url') {
299
-            $atts['type'] = 'url_only';
300
-        }
301
-        return $atts;
302
-    }
19
+	/**
20
+	 * Will hold the EE_Event if available
21
+	 *
22
+	 * @var EE_Event
23
+	 */
24
+	protected $_event;
25
+
26
+	/**
27
+	 * Will hold the EE_Venue if available
28
+	 *
29
+	 * @var EE_Venue
30
+	 */
31
+	protected $_venue;
32
+
33
+
34
+	/**
35
+	 * Initialize properties
36
+	 */
37
+	protected function _init_props()
38
+	{
39
+		$this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
40
+		$this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
41
+		$this->_shortcodes = array(
42
+			'[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
43
+			'[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
44
+			'[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
45
+			'[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
46
+			'[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
47
+			'[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
48
+			'[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
49
+			'[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
50
+			'[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
51
+			'[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
52
+			'[VENUE_FORMATTED_ADDRESS]' => esc_html__(
53
+				'This just outputs the venue address in a semantic address format.',
54
+				'event_espresso'
55
+			),
56
+			'[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
57
+			'[VENUE_META_*]'            => esc_html__(
58
+				'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', 
59
+				'event_espresso'
60
+			),
61
+			'[GOOGLE_MAP_URL]'          => esc_html__(
62
+				'URL for the google map associated with the venue.', 
63
+				'event_espresso'
64
+			),
65
+			'[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
66
+			'[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
67
+		);
68
+	}
69
+
70
+
71
+	/**
72
+	 * Parse incoming shortcode
73
+	 * @param string $shortcode
74
+	 * @return string
75
+	 */
76
+	protected function _parser($shortcode)
77
+	{
78
+		$this->_venue = $this->_get_venue();
79
+		//If there is no venue object by now then get out.
80
+		if ( ! $this->_venue instanceof EE_Venue )
81
+			return '';
82
+
83
+		switch ($shortcode) {
84
+			case '[VENUE_TITLE]':
85
+				return $this->_venue('title');
86
+				break;
87
+
88
+			case '[VENUE_DESCRIPTION]':
89
+				return $this->_venue('description');
90
+				break;
91
+
92
+			case '[VENUE_URL]':
93
+				return $this->_venue('url');
94
+				break;
95
+
96
+			case '[VENUE_IMAGE]':
97
+				return $this->_venue('image');
98
+				break;
99
+
100
+			case '[VENUE_PHONE]':
101
+				return $this->_venue('phone');
102
+				break;
103
+
104
+			case '[VENUE_ADDRESS]':
105
+				return $this->_venue('address');
106
+				break;
107
+
108
+			case '[VENUE_ADDRESS2]':
109
+				return $this->_venue('address2');
110
+				break;
111
+
112
+			case '[VENUE_CITY]':
113
+				return $this->_venue('city');
114
+				break;
115
+
116
+			case '[VENUE_COUNTRY]':
117
+				return $this->_venue('country');
118
+				break;
119
+
120
+			case '[VENUE_STATE]':
121
+				return $this->_venue('state');
122
+				break;
123
+
124
+			case '[VENUE_ZIP]':
125
+				return $this->_venue('zip');
126
+				break;
127
+
128
+			case '[VENUE_FORMATTED_ADDRESS]':
129
+				return $this->_venue('formatted_address');
130
+				break;
131
+
132
+			case '[GOOGLE_MAP_URL]':
133
+				return $this->_venue('gmap_url');
134
+				break;
135
+
136
+			case '[GOOGLE_MAP_LINK]':
137
+				return $this->_venue('gmap_link');
138
+				break;
139
+
140
+			case '[GOOGLE_MAP_IMAGE]':
141
+				return $this->_venue('gmap_link_img');
142
+				break;
143
+
144
+		}
145
+
146
+		if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) {
147
+			$shortcode = str_replace( '[VENUE_META_*', '', $shortcode );
148
+			$shortcode = trim( str_replace( ']', '', $shortcode ) );
149
+
150
+			//pull the meta value from the venue post
151
+			$venue_meta = $this->_venue->get_post_meta( $shortcode, true );
152
+
153
+			return ! empty( $venue_meta ) ? $venue_meta : '';
154
+
155
+		}
156
+	}
157
+	/**
158
+	 * This retrieves the EE_Venue from the available data object.
159
+	 *
160
+	 * @return EE_Venue|null
161
+	 */
162
+	private function _get_venue() {
163
+
164
+		//we need the EE_Event object to get the venue.
165
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
166
+
167
+		//if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
168
+		if (empty($this->_event)) {
169
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
170
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
171
+
172
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null;
173
+
174
+			//if still empty do we have a ticket data item?
175
+			$this->_event = empty($this->_event)
176
+							&& $this->_data instanceof EE_Ticket
177
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
178
+				? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
179
+				: $this->_event;
180
+
181
+			//if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that.
182
+			$event        = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array();
183
+			$this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event;
184
+		}
185
+
186
+		//If we have an event object use it to pull the venue.
187
+		if ($this->_event instanceof EE_Event) {
188
+			return $this->_event->get_first_related('Venue');
189
+		} 
190
+
191
+		return null;
192
+	}
193
+
194
+	/**
195
+	 * This retrieves the specified venue information
196
+	 *
197
+	 * @param string $field  What Venue field to retrieve
198
+	 * @return string What was retrieved!
199
+	 * @throws EE_Error
200
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
201
+	 */
202
+	private function _venue($field)
203
+	{
204
+
205
+		if (empty($this->_venue)) {
206
+			return '';
207
+		} //no venue so get out.
208
+
209
+		switch ($field) {
210
+			case 'title':
211
+				return $this->_venue->get('VNU_name');
212
+				break;
213
+
214
+			case 'description':
215
+				return $this->_venue->get('VNU_desc');
216
+				break;
217
+
218
+			case 'url':
219
+				$url = $this->_venue->get('VNU_url');
220
+				return empty($url) ? $this->_venue->get_permalink() : $url;
221
+				break;
222
+
223
+			case 'image':
224
+				return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
225
+					   . '" alt="' . sprintf(
226
+						   esc_attr__('%s Feature Image', 'event_espresso'),
227
+						   $this->_venue->get('VNU_name')
228
+					   ) . '" />';
229
+				break;
230
+
231
+			case 'phone':
232
+				return $this->_venue->get('VNU_phone');
233
+				break;
234
+
235
+			case 'address':
236
+				return $this->_venue->get('VNU_address');
237
+				break;
238
+
239
+			case 'address2':
240
+				return $this->_venue->get('VNU_address2');
241
+				break;
242
+
243
+			case 'city':
244
+				return $this->_venue->get('VNU_city');
245
+				break;
246
+
247
+			case 'state':
248
+				$state = $this->_venue->state_obj();
249
+				return is_object($state) ? $state->get('STA_name') : '';
250
+				break;
251
+
252
+			case 'country':
253
+				$country = $this->_venue->country_obj();
254
+				return is_object($country) ? $country->get('CNT_name') : '';
255
+				break;
256
+
257
+			case 'zip':
258
+				return $this->_venue->get('VNU_zip');
259
+				break;
260
+
261
+			case 'formatted_address':
262
+				return EEH_Address::format($this->_venue);
263
+				break;
264
+
265
+			case 'gmap_link':
266
+			case 'gmap_url':
267
+			case 'gmap_link_img':
268
+				$atts = $this->get_map_attributes($this->_venue, $field);
269
+				return EEH_Maps::google_map_link($atts);
270
+				break;
271
+		}
272
+		return '';
273
+	}
274
+
275
+
276
+	/**
277
+	 * Generates the attributes for retrieving a google_map artifact.
278
+	 * @param EE_Venue $venue
279
+	 * @param string   $field
280
+	 * @return array
281
+	 * @throws EE_Error
282
+	 */
283
+	protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
284
+	{
285
+		$state   = $venue->state_obj();
286
+		$country = $venue->country_obj();
287
+		$atts    = array(
288
+			'id'      => $venue->ID(),
289
+			'address' => $venue->get('VNU_address'),
290
+			'city'    => $venue->get('VNU_city'),
291
+			'state'   => is_object($state) ? $state->get('STA_name') : '',
292
+			'zip'     => $venue->get('VNU_zip'),
293
+			'country' => is_object($country) ? $country->get('CNT_name') : '',
294
+			'type'    => $field === 'gmap_link' ? 'url' : 'map',
295
+			'map_w'   => 200,
296
+			'map_h'   => 200,
297
+		);
298
+		if ($field === 'gmap_url') {
299
+			$atts['type'] = 'url_only';
300
+		}
301
+		return $atts;
302
+	}
303 303
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $this->_venue = $this->_get_venue();
79 79
         //If there is no venue object by now then get out.
80
-        if ( ! $this->_venue instanceof EE_Venue )
80
+        if ( ! $this->_venue instanceof EE_Venue)
81 81
             return '';
82 82
 
83 83
         switch ($shortcode) {
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 
144 144
         }
145 145
 
146
-        if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) {
147
-            $shortcode = str_replace( '[VENUE_META_*', '', $shortcode );
148
-            $shortcode = trim( str_replace( ']', '', $shortcode ) );
146
+        if (strpos($shortcode, '[VENUE_META_*') !== false) {
147
+            $shortcode = str_replace('[VENUE_META_*', '', $shortcode);
148
+            $shortcode = trim(str_replace(']', '', $shortcode));
149 149
 
150 150
             //pull the meta value from the venue post
151
-            $venue_meta = $this->_venue->get_post_meta( $shortcode, true );
151
+            $venue_meta = $this->_venue->get_post_meta($shortcode, true);
152 152
 
153
-            return ! empty( $venue_meta ) ? $venue_meta : '';
153
+            return ! empty($venue_meta) ? $venue_meta : '';
154 154
 
155 155
         }
156 156
     }
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
                 break;
222 222
 
223 223
             case 'image':
224
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
225
-                       . '" alt="' . sprintf(
224
+                return '<img src="'.$this->_venue->feature_image_url(array(200, 200,))
225
+                       . '" alt="'.sprintf(
226 226
                            esc_attr__('%s Feature Image', 'event_espresso'),
227 227
                            $this->_venue->get('VNU_name')
228
-                       ) . '" />';
228
+                       ).'" />';
229 229
                 break;
230 230
 
231 231
             case 'phone':
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,8 +77,9 @@
 block discarded – undo
77 77
     {
78 78
         $this->_venue = $this->_get_venue();
79 79
         //If there is no venue object by now then get out.
80
-        if ( ! $this->_venue instanceof EE_Venue )
81
-            return '';
80
+        if ( ! $this->_venue instanceof EE_Venue ) {
81
+                    return '';
82
+        }
82 83
 
83 84
         switch ($shortcode) {
84 85
             case '[VENUE_TITLE]':
Please login to merge, or discard this patch.
core/services/loaders/LoaderDecoratorInterface.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -9,20 +9,20 @@
 block discarded – undo
9 9
 interface LoaderDecoratorInterface
10 10
 {
11 11
 
12
-    /**
13
-     * @param string $fqcn
14
-     * @param array  $arguments
15
-     * @param bool   $shared
16
-     * @return mixed
17
-     */
18
-    public function load($fqcn, $arguments = array(), $shared = true);
12
+	/**
13
+	 * @param string $fqcn
14
+	 * @param array  $arguments
15
+	 * @param bool   $shared
16
+	 * @return mixed
17
+	 */
18
+	public function load($fqcn, $arguments = array(), $shared = true);
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     * calls reset() on loader if method exists
24
-     */
25
-    public function reset();
22
+	/**
23
+	 * calls reset() on loader if method exists
24
+	 */
25
+	public function reset();
26 26
 
27 27
 }
28 28
 // End of file LoaderInterface.php
Please login to merge, or discard this patch.
core/db_models/EEM_WP_User.model.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\services\orm\ModelFieldFactory;
4 4
 
5 5
 if (! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('No direct script access allowed');
6
+	exit('No direct script access allowed');
7 7
 }
8 8
 
9 9
 
@@ -19,128 +19,128 @@  discard block
 block discarded – undo
19 19
 class EEM_WP_User extends EEM_Base
20 20
 {
21 21
 
22
-    /**
23
-     * private instance of the EEM_WP_User object
24
-     *
25
-     * @type EEM_WP_User
26
-     */
27
-    protected static $_instance;
28
-
29
-
30
-
31
-    /**
32
-     *    constructor
33
-     *
34
-     * @param null              $timezone
35
-     * @param ModelFieldFactory $model_field_factory
36
-     * @throws EE_Error
37
-     * @throws InvalidArgumentException
38
-     */
39
-    protected function __construct($timezone = null, ModelFieldFactory $model_field_factory)
40
-    {
41
-        $this->singular_item = __('WP_User', 'event_espresso');
42
-        $this->plural_item = __('WP_Users', 'event_espresso');
43
-        global $wpdb;
44
-        $this->_tables = array(
45
-            'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
46
-        );
47
-        $this->_fields = array(
48
-            'WP_User' => array(
49
-                'ID'                  => $model_field_factory->createPrimaryKeyIntField(
50
-                    'ID',
51
-                    __('WP_User ID', 'event_espresso')
52
-                ),
53
-                'user_login'          => $model_field_factory->createPlainTextField(
54
-                    'user_login',
55
-                    __('User Login', 'event_espresso'),
56
-                    false
57
-                ),
58
-                'user_pass'           => $model_field_factory->createPlainTextField(
59
-                    'user_pass',
60
-                    __('User Password', 'event_espresso'),
61
-                    false
62
-                ),
63
-                'user_nicename'       => $model_field_factory->createPlainTextField(
64
-                    'user_nicename',
65
-                    __(' User Nice Name', 'event_espresso'),
66
-                    false
67
-                ),
68
-                'user_email'          => $model_field_factory->createEmailField(
69
-                    'user_email',
70
-                    __('User Email', 'event_espresso'),
71
-                    false,
72
-                    null
73
-                ),
74
-                'user_registered'     => $model_field_factory->createDatetimeField(
75
-                    'user_registered',
76
-                    __('Date User Registered', 'event_espresso'),
77
-                    $timezone
78
-                ),
79
-                'user_activation_key' => $model_field_factory->createPlainTextField(
80
-                    'user_activation_key',
81
-                    __('User Activation Key', 'event_espresso'),
82
-                    false
83
-                ),
84
-                'user_status'         => $model_field_factory->createIntegerField(
85
-                    'user_status',
86
-                    __('User Status', 'event_espresso')
87
-                ),
88
-                'display_name'        => $model_field_factory->createPlainTextField(
89
-                    'display_name',
90
-                    __('Display Name', 'event_espresso'),
91
-                    false
92
-                ),
93
-            ),
94
-        );
95
-        $this->_model_relations = array(
96
-            'Attendee'       => new EE_Has_Many_Relation(),
97
-            // all models are related to the change log
98
-            // 'Change_Log'     => new EE_Has_Many_Relation(),
99
-            'Event'          => new EE_Has_Many_Relation(),
100
-            'Payment_Method' => new EE_Has_Many_Relation(),
101
-            'Price'          => new EE_Has_Many_Relation(),
102
-            'Price_Type'     => new EE_Has_Many_Relation(),
103
-            'Question'       => new EE_Has_Many_Relation(),
104
-            'Question_Group' => new EE_Has_Many_Relation(),
105
-            'Ticket'         => new EE_Has_Many_Relation(),
106
-            'Venue'          => new EE_Has_Many_Relation(),
107
-            'Message'        => new EE_Has_Many_Relation(),
108
-        );
109
-        $this->_wp_core_model = true;
110
-        $this->_caps_slug = 'users';
111
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
112
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
113
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
114
-            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
115
-        }
116
-        //@todo: account for create_users controls whether they can create users at all
117
-        parent::__construct($timezone);
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * We don't need a foreign key to the WP_User model, we just need its primary key
124
-     *
125
-     * @return string
126
-     * @throws EE_Error
127
-     */
128
-    public function wp_user_field_name()
129
-    {
130
-        return $this->primary_key_name();
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * This WP_User model IS owned, even though it doesn't have a foreign key to itself
137
-     *
138
-     * @return boolean
139
-     */
140
-    public function is_owned()
141
-    {
142
-        return true;
143
-    }
22
+	/**
23
+	 * private instance of the EEM_WP_User object
24
+	 *
25
+	 * @type EEM_WP_User
26
+	 */
27
+	protected static $_instance;
28
+
29
+
30
+
31
+	/**
32
+	 *    constructor
33
+	 *
34
+	 * @param null              $timezone
35
+	 * @param ModelFieldFactory $model_field_factory
36
+	 * @throws EE_Error
37
+	 * @throws InvalidArgumentException
38
+	 */
39
+	protected function __construct($timezone = null, ModelFieldFactory $model_field_factory)
40
+	{
41
+		$this->singular_item = __('WP_User', 'event_espresso');
42
+		$this->plural_item = __('WP_Users', 'event_espresso');
43
+		global $wpdb;
44
+		$this->_tables = array(
45
+			'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
46
+		);
47
+		$this->_fields = array(
48
+			'WP_User' => array(
49
+				'ID'                  => $model_field_factory->createPrimaryKeyIntField(
50
+					'ID',
51
+					__('WP_User ID', 'event_espresso')
52
+				),
53
+				'user_login'          => $model_field_factory->createPlainTextField(
54
+					'user_login',
55
+					__('User Login', 'event_espresso'),
56
+					false
57
+				),
58
+				'user_pass'           => $model_field_factory->createPlainTextField(
59
+					'user_pass',
60
+					__('User Password', 'event_espresso'),
61
+					false
62
+				),
63
+				'user_nicename'       => $model_field_factory->createPlainTextField(
64
+					'user_nicename',
65
+					__(' User Nice Name', 'event_espresso'),
66
+					false
67
+				),
68
+				'user_email'          => $model_field_factory->createEmailField(
69
+					'user_email',
70
+					__('User Email', 'event_espresso'),
71
+					false,
72
+					null
73
+				),
74
+				'user_registered'     => $model_field_factory->createDatetimeField(
75
+					'user_registered',
76
+					__('Date User Registered', 'event_espresso'),
77
+					$timezone
78
+				),
79
+				'user_activation_key' => $model_field_factory->createPlainTextField(
80
+					'user_activation_key',
81
+					__('User Activation Key', 'event_espresso'),
82
+					false
83
+				),
84
+				'user_status'         => $model_field_factory->createIntegerField(
85
+					'user_status',
86
+					__('User Status', 'event_espresso')
87
+				),
88
+				'display_name'        => $model_field_factory->createPlainTextField(
89
+					'display_name',
90
+					__('Display Name', 'event_espresso'),
91
+					false
92
+				),
93
+			),
94
+		);
95
+		$this->_model_relations = array(
96
+			'Attendee'       => new EE_Has_Many_Relation(),
97
+			// all models are related to the change log
98
+			// 'Change_Log'     => new EE_Has_Many_Relation(),
99
+			'Event'          => new EE_Has_Many_Relation(),
100
+			'Payment_Method' => new EE_Has_Many_Relation(),
101
+			'Price'          => new EE_Has_Many_Relation(),
102
+			'Price_Type'     => new EE_Has_Many_Relation(),
103
+			'Question'       => new EE_Has_Many_Relation(),
104
+			'Question_Group' => new EE_Has_Many_Relation(),
105
+			'Ticket'         => new EE_Has_Many_Relation(),
106
+			'Venue'          => new EE_Has_Many_Relation(),
107
+			'Message'        => new EE_Has_Many_Relation(),
108
+		);
109
+		$this->_wp_core_model = true;
110
+		$this->_caps_slug = 'users';
111
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
112
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
113
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
114
+			$this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
115
+		}
116
+		//@todo: account for create_users controls whether they can create users at all
117
+		parent::__construct($timezone);
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * We don't need a foreign key to the WP_User model, we just need its primary key
124
+	 *
125
+	 * @return string
126
+	 * @throws EE_Error
127
+	 */
128
+	public function wp_user_field_name()
129
+	{
130
+		return $this->primary_key_name();
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * This WP_User model IS owned, even though it doesn't have a foreign key to itself
137
+	 *
138
+	 * @return boolean
139
+	 */
140
+	public function is_owned()
141
+	{
142
+		return true;
143
+	}
144 144
 
145 145
 
146 146
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 use EventEspresso\core\services\orm\ModelFieldFactory;
4 4
 
5
-if (! defined('EVENT_ESPRESSO_VERSION')) {
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6 6
     exit('No direct script access allowed');
7 7
 }
8 8
 
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 1 patch
Indentation   +464 added lines, -464 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,480 +19,480 @@  discard block
 block discarded – undo
19 19
 abstract class EE_Form_Section_Base
20 20
 {
21 21
 
22
-    /**
23
-     * the URL the form is submitted to
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_action;
28
-
29
-    /**
30
-     * POST (default) or GET
31
-     *
32
-     * @var string
33
-     */
34
-    protected $_method;
35
-
36
-    /**
37
-     * html_id and html_name are derived from this by default
38
-     *
39
-     * @var string
40
-     */
41
-    protected $_name;
42
-
43
-    /**
44
-     * $_html_id
45
-     * @var string
46
-     */
47
-    protected $_html_id;
48
-
49
-    /**
50
-     * $_html_class
51
-     * @var string
52
-     */
53
-    protected $_html_class;
54
-
55
-    /**
56
-     * $_html_style
57
-     * @var string
58
-     */
59
-    protected $_html_style;
60
-
61
-    /**
62
-     * $_other_html_attributes
63
-     * @var string
64
-     */
65
-    protected $_other_html_attributes;
66
-
67
-    /**
68
-     * The form section of which this form section is a part
69
-     *
70
-     * @var EE_Form_Section_Proper
71
-     */
72
-    protected $_parent_section;
73
-
74
-    /**
75
-     * flag indicating that _construct_finalize has been called.
76
-     * If it has not been called and we try to use functions which require it, we call it
77
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
-     *
79
-     * @var boolean
80
-     */
81
-    protected $_construction_finalized;
82
-
83
-    /**
84
-     * Strategy for parsing the form HTML upon display
85
-     *
86
-     * @var FormHtmlFilter
87
-     */
88
-    protected $_form_html_filter;
89
-
90
-
91
-
92
-    /**
93
-     * @param array $options_array {
94
-     * @type        $name          string the name for this form section, if you want to explicitly define it
95
-     *                             }
96
-     */
97
-    public function __construct($options_array = array())
98
-    {
99
-        // used by display strategies
100
-        // assign incoming values to properties
101
-        foreach ($options_array as $key => $value) {
102
-            $key = '_' . $key;
103
-            if (property_exists($this, $key) && empty($this->{$key})) {
104
-                $this->{$key} = $value;
105
-            }
106
-        }
107
-        // set parser which allows the form section's rendered HTML to be filtered
108
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
-            $this->_form_html_filter = $options_array['form_html_filter'];
110
-        }
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param $parent_form_section
117
-     * @param $name
118
-     * @throws \EE_Error
119
-     */
120
-    protected function _construct_finalize($parent_form_section, $name)
121
-    {
122
-        $this->_construction_finalized = true;
123
-        $this->_parent_section = $parent_form_section;
124
-        if ($name !== null) {
125
-            $this->_name = $name;
126
-        }
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * make sure construction finalized was called, otherwise children might not be ready
133
-     *
134
-     * @return void
135
-     * @throws \EE_Error
136
-     */
137
-    public function ensure_construct_finalized_called()
138
-    {
139
-        if (! $this->_construction_finalized) {
140
-            $this->_construct_finalize($this->_parent_section, $this->_name);
141
-        }
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public function action()
150
-    {
151
-        return $this->_action;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @param string $action
158
-     */
159
-    public function set_action($action)
160
-    {
161
-        $this->_action = $action;
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * @return string
168
-     */
169
-    public function method()
170
-    {
171
-        return ! empty($this->_method) ? $this->_method : 'POST';
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * @param string $method
178
-     */
179
-    public function set_method($method)
180
-    {
181
-        switch ($method) {
182
-            case 'get' :
183
-            case 'GET' :
184
-                $this->_method = 'GET';
185
-                break;
186
-            default :
187
-                $this->_method = 'POST';
188
-        }
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * Sets the html_id to its default value, if none was specified in the constructor.
195
-     * Calculation involves using the name and the parent's html id
196
-     * return void
197
-     *
198
-     * @throws \EE_Error
199
-     */
200
-    protected function _set_default_html_id_if_empty()
201
-    {
202
-        if (! $this->_html_id) {
203
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
-                $this->_html_id = $this->_parent_section->html_id()
205
-                                  . '-'
206
-                                  . $this->_prep_name_for_html_id($this->name());
207
-            } else {
208
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
209
-            }
210
-        }
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * _prep_name_for_html_id
217
-     *
218
-     * @param $name
219
-     * @return string
220
-     */
221
-    private function _prep_name_for_html_id($name)
222
-    {
223
-        return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
224
-    }
22
+	/**
23
+	 * the URL the form is submitted to
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_action;
28
+
29
+	/**
30
+	 * POST (default) or GET
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $_method;
35
+
36
+	/**
37
+	 * html_id and html_name are derived from this by default
38
+	 *
39
+	 * @var string
40
+	 */
41
+	protected $_name;
42
+
43
+	/**
44
+	 * $_html_id
45
+	 * @var string
46
+	 */
47
+	protected $_html_id;
48
+
49
+	/**
50
+	 * $_html_class
51
+	 * @var string
52
+	 */
53
+	protected $_html_class;
54
+
55
+	/**
56
+	 * $_html_style
57
+	 * @var string
58
+	 */
59
+	protected $_html_style;
60
+
61
+	/**
62
+	 * $_other_html_attributes
63
+	 * @var string
64
+	 */
65
+	protected $_other_html_attributes;
66
+
67
+	/**
68
+	 * The form section of which this form section is a part
69
+	 *
70
+	 * @var EE_Form_Section_Proper
71
+	 */
72
+	protected $_parent_section;
73
+
74
+	/**
75
+	 * flag indicating that _construct_finalize has been called.
76
+	 * If it has not been called and we try to use functions which require it, we call it
77
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
+	 *
79
+	 * @var boolean
80
+	 */
81
+	protected $_construction_finalized;
82
+
83
+	/**
84
+	 * Strategy for parsing the form HTML upon display
85
+	 *
86
+	 * @var FormHtmlFilter
87
+	 */
88
+	protected $_form_html_filter;
89
+
90
+
91
+
92
+	/**
93
+	 * @param array $options_array {
94
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
95
+	 *                             }
96
+	 */
97
+	public function __construct($options_array = array())
98
+	{
99
+		// used by display strategies
100
+		// assign incoming values to properties
101
+		foreach ($options_array as $key => $value) {
102
+			$key = '_' . $key;
103
+			if (property_exists($this, $key) && empty($this->{$key})) {
104
+				$this->{$key} = $value;
105
+			}
106
+		}
107
+		// set parser which allows the form section's rendered HTML to be filtered
108
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
+			$this->_form_html_filter = $options_array['form_html_filter'];
110
+		}
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param $parent_form_section
117
+	 * @param $name
118
+	 * @throws \EE_Error
119
+	 */
120
+	protected function _construct_finalize($parent_form_section, $name)
121
+	{
122
+		$this->_construction_finalized = true;
123
+		$this->_parent_section = $parent_form_section;
124
+		if ($name !== null) {
125
+			$this->_name = $name;
126
+		}
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * make sure construction finalized was called, otherwise children might not be ready
133
+	 *
134
+	 * @return void
135
+	 * @throws \EE_Error
136
+	 */
137
+	public function ensure_construct_finalized_called()
138
+	{
139
+		if (! $this->_construction_finalized) {
140
+			$this->_construct_finalize($this->_parent_section, $this->_name);
141
+		}
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public function action()
150
+	{
151
+		return $this->_action;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @param string $action
158
+	 */
159
+	public function set_action($action)
160
+	{
161
+		$this->_action = $action;
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * @return string
168
+	 */
169
+	public function method()
170
+	{
171
+		return ! empty($this->_method) ? $this->_method : 'POST';
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * @param string $method
178
+	 */
179
+	public function set_method($method)
180
+	{
181
+		switch ($method) {
182
+			case 'get' :
183
+			case 'GET' :
184
+				$this->_method = 'GET';
185
+				break;
186
+			default :
187
+				$this->_method = 'POST';
188
+		}
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * Sets the html_id to its default value, if none was specified in the constructor.
195
+	 * Calculation involves using the name and the parent's html id
196
+	 * return void
197
+	 *
198
+	 * @throws \EE_Error
199
+	 */
200
+	protected function _set_default_html_id_if_empty()
201
+	{
202
+		if (! $this->_html_id) {
203
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
+				$this->_html_id = $this->_parent_section->html_id()
205
+								  . '-'
206
+								  . $this->_prep_name_for_html_id($this->name());
207
+			} else {
208
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
209
+			}
210
+		}
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * _prep_name_for_html_id
217
+	 *
218
+	 * @param $name
219
+	 * @return string
220
+	 */
221
+	private function _prep_name_for_html_id($name)
222
+	{
223
+		return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
224
+	}
225 225
 
226 226
 
227 227
 
228
-    /**
229
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
-     * and call get_html when you want to output the html. Calling get_html_and_js after
232
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
-     * and so might stop working anytime.
235
-     *
236
-     * @return string
237
-     */
238
-    public function get_html_and_js()
239
-    {
240
-        return $this->get_html();
241
-    }
228
+	/**
229
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
232
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
+	 * and so might stop working anytime.
235
+	 *
236
+	 * @return string
237
+	 */
238
+	public function get_html_and_js()
239
+	{
240
+		return $this->get_html();
241
+	}
242 242
 
243 243
 
244 244
 
245
-    /**
246
-     * Gets the HTML for displaying this form section
247
-     *
248
-     * @return string
249
-     */
250
-    public abstract function get_html();
245
+	/**
246
+	 * Gets the HTML for displaying this form section
247
+	 *
248
+	 * @return string
249
+	 */
250
+	public abstract function get_html();
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * @param bool $add_pound_sign
256
-     * @return string
257
-     */
258
-    public function html_id($add_pound_sign = false)
259
-    {
260
-        $this->_set_default_html_id_if_empty();
261
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
-    }
254
+	/**
255
+	 * @param bool $add_pound_sign
256
+	 * @return string
257
+	 */
258
+	public function html_id($add_pound_sign = false)
259
+	{
260
+		$this->_set_default_html_id_if_empty();
261
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
+	}
263 263
 
264 264
 
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function html_class()
270
-    {
271
-        return $this->_html_class;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @return string
278
-     */
279
-    public function html_style()
280
-    {
281
-        return $this->_html_style;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param mixed $html_class
288
-     */
289
-    public function set_html_class($html_class)
290
-    {
291
-        $this->_html_class = $html_class;
292
-    }
293
-
294
-
295
-
296
-    /**
297
-     * @param mixed $html_id
298
-     */
299
-    public function set_html_id($html_id)
300
-    {
301
-        $this->_html_id = $html_id;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param mixed $html_style
308
-     */
309
-    public function set_html_style($html_style)
310
-    {
311
-        $this->_html_style = $html_style;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * @param string $other_html_attributes
318
-     */
319
-    public function set_other_html_attributes($other_html_attributes)
320
-    {
321
-        $this->_other_html_attributes = $other_html_attributes;
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * @return string
328
-     */
329
-    public function other_html_attributes()
330
-    {
331
-        return $this->_other_html_attributes;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * Gets the name of the form section. This is not the same as the HTML name.
338
-     *
339
-     * @throws EE_Error
340
-     * @return string
341
-     */
342
-    public function name()
343
-    {
344
-        if (! $this->_construction_finalized) {
345
-            throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
-                'event_espresso'), get_class($this)));
347
-        }
348
-        return $this->_name;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * Gets the parent section
355
-     *
356
-     * @return EE_Form_Section_Proper
357
-     */
358
-    public function parent_section()
359
-    {
360
-        return $this->_parent_section;
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * returns HTML for generating the opening form HTML tag (<form>)
367
-     *
368
-     * @param string $action           the URL the form is submitted to
369
-     * @param string $method           POST (default) or GET
370
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
-     * @return string
372
-     */
373
-    public function form_open($action = '', $method = '', $other_attributes = '')
374
-    {
375
-        if (! empty($action)) {
376
-            $this->set_action($action);
377
-        }
378
-        if (! empty($method)) {
379
-            $this->set_method($method);
380
-        }
381
-        $html = EEH_HTML::nl(1, 'form') . '<form';
382
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
383
-        $html .= ' action="' . $this->action() . '"';
384
-        $html .= ' method="' . $this->method() . '"';
385
-        $html .= $other_attributes . '>';
386
-        return $html;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * ensures that html id for form either ends in "-form" or "-frm"
393
-     * so that id doesn't conflict/collide with other elements
394
-     *
395
-     * @param string $html_id
396
-     * @return string
397
-     */
398
-    protected function get_html_id_for_form($html_id)
399
-    {
400
-        $strlen = strlen($html_id);
401
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
402
-            ? $html_id
403
-            : $html_id . '-frm';
404
-        return $html_id;
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * returns HTML for generating the closing form HTML tag (</form>)
411
-     *
412
-     * @return string
413
-     */
414
-    public function form_close()
415
-    {
416
-        return EEH_HTML::nl(-1, 'form')
417
-               . '</form>'
418
-               . EEH_HTML::nl()
419
-               . '<!-- end of ee-'
420
-               . $this->html_id()
421
-               . '-form -->'
422
-               . EEH_HTML::nl();
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
429
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
430
-     * Default does nothing, but child classes can override
431
-     *
432
-     * @return void
433
-     */
434
-    public function enqueue_js()
435
-    {
436
-        //defaults to enqueue NO js or css
437
-    }
438
-
439
-
440
-
441
-    /**
442
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
443
-     * with it, and it will be on each form section's 'other_data' property.
444
-     * By default nothing is added, but child classes can extend this method to add something.
445
-     * Eg, if you have an input that will cause a modal dialog to appear,
446
-     * here you could add an entry like 'modal_dialog_inputs' to this array
447
-     * to map between the input's html ID and the modal dialogue's ID, so that
448
-     * your JS code will know where to find the modal dialog when the input is pressed.
449
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
450
-     *
451
-     * @param array $form_other_js_data
452
-     * @return array
453
-     */
454
-    public function get_other_js_data($form_other_js_data = array())
455
-    {
456
-        return $form_other_js_data;
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * This isn't just the name of an input, it's a path pointing to an input. The
463
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
464
-     * dot-dot-slash (../) means to ascend into the parent section.
465
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
466
-     * which will be returned.
467
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
468
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
469
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
470
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
471
-     * Etc
472
-     *
473
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
474
-     * @return EE_Form_Section_Base
475
-     */
476
-    public function find_section_from_path($form_section_path)
477
-    {
478
-        if (strpos($form_section_path, '/') === 0) {
479
-            $form_section_path = substr($form_section_path, strlen('/'));
480
-        }
481
-        if (empty($form_section_path)) {
482
-            return $this;
483
-        }
484
-        if (strpos($form_section_path, '../') === 0) {
485
-            $parent = $this->parent_section();
486
-            $form_section_path = substr($form_section_path, strlen('../'));
487
-            if ($parent instanceof EE_Form_Section_Base) {
488
-                return $parent->find_section_from_path($form_section_path);
489
-            } elseif (empty($form_section_path)) {
490
-                return $this;
491
-            }
492
-        }
493
-        //couldn't find it using simple parent following
494
-        return null;
495
-    }
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function html_class()
270
+	{
271
+		return $this->_html_class;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @return string
278
+	 */
279
+	public function html_style()
280
+	{
281
+		return $this->_html_style;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param mixed $html_class
288
+	 */
289
+	public function set_html_class($html_class)
290
+	{
291
+		$this->_html_class = $html_class;
292
+	}
293
+
294
+
295
+
296
+	/**
297
+	 * @param mixed $html_id
298
+	 */
299
+	public function set_html_id($html_id)
300
+	{
301
+		$this->_html_id = $html_id;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param mixed $html_style
308
+	 */
309
+	public function set_html_style($html_style)
310
+	{
311
+		$this->_html_style = $html_style;
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @param string $other_html_attributes
318
+	 */
319
+	public function set_other_html_attributes($other_html_attributes)
320
+	{
321
+		$this->_other_html_attributes = $other_html_attributes;
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * @return string
328
+	 */
329
+	public function other_html_attributes()
330
+	{
331
+		return $this->_other_html_attributes;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * Gets the name of the form section. This is not the same as the HTML name.
338
+	 *
339
+	 * @throws EE_Error
340
+	 * @return string
341
+	 */
342
+	public function name()
343
+	{
344
+		if (! $this->_construction_finalized) {
345
+			throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
+				'event_espresso'), get_class($this)));
347
+		}
348
+		return $this->_name;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * Gets the parent section
355
+	 *
356
+	 * @return EE_Form_Section_Proper
357
+	 */
358
+	public function parent_section()
359
+	{
360
+		return $this->_parent_section;
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * returns HTML for generating the opening form HTML tag (<form>)
367
+	 *
368
+	 * @param string $action           the URL the form is submitted to
369
+	 * @param string $method           POST (default) or GET
370
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
+	 * @return string
372
+	 */
373
+	public function form_open($action = '', $method = '', $other_attributes = '')
374
+	{
375
+		if (! empty($action)) {
376
+			$this->set_action($action);
377
+		}
378
+		if (! empty($method)) {
379
+			$this->set_method($method);
380
+		}
381
+		$html = EEH_HTML::nl(1, 'form') . '<form';
382
+		$html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
383
+		$html .= ' action="' . $this->action() . '"';
384
+		$html .= ' method="' . $this->method() . '"';
385
+		$html .= $other_attributes . '>';
386
+		return $html;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * ensures that html id for form either ends in "-form" or "-frm"
393
+	 * so that id doesn't conflict/collide with other elements
394
+	 *
395
+	 * @param string $html_id
396
+	 * @return string
397
+	 */
398
+	protected function get_html_id_for_form($html_id)
399
+	{
400
+		$strlen = strlen($html_id);
401
+		$html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
402
+			? $html_id
403
+			: $html_id . '-frm';
404
+		return $html_id;
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * returns HTML for generating the closing form HTML tag (</form>)
411
+	 *
412
+	 * @return string
413
+	 */
414
+	public function form_close()
415
+	{
416
+		return EEH_HTML::nl(-1, 'form')
417
+			   . '</form>'
418
+			   . EEH_HTML::nl()
419
+			   . '<!-- end of ee-'
420
+			   . $this->html_id()
421
+			   . '-form -->'
422
+			   . EEH_HTML::nl();
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
429
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
430
+	 * Default does nothing, but child classes can override
431
+	 *
432
+	 * @return void
433
+	 */
434
+	public function enqueue_js()
435
+	{
436
+		//defaults to enqueue NO js or css
437
+	}
438
+
439
+
440
+
441
+	/**
442
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
443
+	 * with it, and it will be on each form section's 'other_data' property.
444
+	 * By default nothing is added, but child classes can extend this method to add something.
445
+	 * Eg, if you have an input that will cause a modal dialog to appear,
446
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
447
+	 * to map between the input's html ID and the modal dialogue's ID, so that
448
+	 * your JS code will know where to find the modal dialog when the input is pressed.
449
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
450
+	 *
451
+	 * @param array $form_other_js_data
452
+	 * @return array
453
+	 */
454
+	public function get_other_js_data($form_other_js_data = array())
455
+	{
456
+		return $form_other_js_data;
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * This isn't just the name of an input, it's a path pointing to an input. The
463
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
464
+	 * dot-dot-slash (../) means to ascend into the parent section.
465
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
466
+	 * which will be returned.
467
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
468
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
469
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
470
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
471
+	 * Etc
472
+	 *
473
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
474
+	 * @return EE_Form_Section_Base
475
+	 */
476
+	public function find_section_from_path($form_section_path)
477
+	{
478
+		if (strpos($form_section_path, '/') === 0) {
479
+			$form_section_path = substr($form_section_path, strlen('/'));
480
+		}
481
+		if (empty($form_section_path)) {
482
+			return $this;
483
+		}
484
+		if (strpos($form_section_path, '../') === 0) {
485
+			$parent = $this->parent_section();
486
+			$form_section_path = substr($form_section_path, strlen('../'));
487
+			if ($parent instanceof EE_Form_Section_Base) {
488
+				return $parent->find_section_from_path($form_section_path);
489
+			} elseif (empty($form_section_path)) {
490
+				return $this;
491
+			}
492
+		}
493
+		//couldn't find it using simple parent following
494
+		return null;
495
+	}
496 496
 
497 497
 
498 498
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 patches
Indentation   +1169 added lines, -1169 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,1173 +17,1173 @@  discard block
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * This is used to hold the reports template data which is setup early in the request.
22
-     *
23
-     * @type array
24
-     */
25
-    protected $_reports_template_data = array();
26
-
27
-
28
-
29
-    /**
30
-     * Extend_Registrations_Admin_Page constructor.
31
-     *
32
-     * @param bool $routing
33
-     */
34
-    public function __construct($routing = true)
35
-    {
36
-        parent::__construct($routing);
37
-        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
41
-        }
42
-    }
43
-
44
-
45
-
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
-        // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
54
-        // 	? $this->_req_data['post'] : $att_id;
55
-        $new_page_routes = array(
56
-            'reports'                  => array(
57
-                'func'       => '_registration_reports',
58
-                'capability' => 'ee_read_registrations',
59
-            ),
60
-            'registration_checkins'    => array(
61
-                'func'       => '_registration_checkin_list_table',
62
-                'capability' => 'ee_read_checkins',
63
-            ),
64
-            'newsletter_selected_send' => array(
65
-                'func'       => '_newsletter_selected_send',
66
-                'noheader'   => true,
67
-                'capability' => 'ee_send_message',
68
-            ),
69
-            'delete_checkin_rows'      => array(
70
-                'func'       => '_delete_checkin_rows',
71
-                'noheader'   => true,
72
-                'capability' => 'ee_delete_checkins',
73
-            ),
74
-            'delete_checkin_row'       => array(
75
-                'func'       => '_delete_checkin_row',
76
-                'noheader'   => true,
77
-                'capability' => 'ee_delete_checkin',
78
-                'obj_id'     => $reg_id,
79
-            ),
80
-            'toggle_checkin_status'    => array(
81
-                'func'       => '_toggle_checkin_status',
82
-                'noheader'   => true,
83
-                'capability' => 'ee_edit_checkin',
84
-                'obj_id'     => $reg_id,
85
-            ),
86
-            'event_registrations'      => array(
87
-                'func'       => '_event_registrations_list_table',
88
-                'capability' => 'ee_read_checkins',
89
-            ),
90
-            'registrations_checkin_report' => array(
91
-                'func'       => '_registrations_checkin_report',
92
-                'noheader'   => true,
93
-                'capability' => 'ee_read_registrations',
94
-            ),
95
-        );
96
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
97
-        $new_page_config = array(
98
-            'reports'               => array(
99
-                'nav'           => array(
100
-                    'label' => __('Reports', 'event_espresso'),
101
-                    'order' => 30,
102
-                ),
103
-                'help_tabs'     => array(
104
-                    'registrations_reports_help_tab' => array(
105
-                        'title'    => __('Registration Reports', 'event_espresso'),
106
-                        'filename' => 'registrations_reports',
107
-                    ),
108
-                ),
109
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
110
-                'require_nonce' => false,
111
-            ),
112
-            'event_registrations'   => array(
113
-                'nav'           => array(
114
-                    'label'      => __('Event Check-In', 'event_espresso'),
115
-                    'order'      => 10,
116
-                    'persistent' => true,
117
-                ),
118
-                'help_tabs'     => array(
119
-                    'registrations_event_checkin_help_tab'                       => array(
120
-                        'title'    => __('Registrations Event Check-In', 'event_espresso'),
121
-                        'filename' => 'registrations_event_checkin',
122
-                    ),
123
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
124
-                        'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
125
-                        'filename' => 'registrations_event_checkin_table_column_headings',
126
-                    ),
127
-                    'registrations_event_checkin_filters_help_tab'               => array(
128
-                        'title'    => __('Event Check-In Filters', 'event_espresso'),
129
-                        'filename' => 'registrations_event_checkin_filters',
130
-                    ),
131
-                    'registrations_event_checkin_views_help_tab'                 => array(
132
-                        'title'    => __('Event Check-In Views', 'event_espresso'),
133
-                        'filename' => 'registrations_event_checkin_views',
134
-                    ),
135
-                    'registrations_event_checkin_other_help_tab'                 => array(
136
-                        'title'    => __('Event Check-In Other', 'event_espresso'),
137
-                        'filename' => 'registrations_event_checkin_other',
138
-                    ),
139
-                ),
140
-                'help_tour'     => array('Event_Checkin_Help_Tour'),
141
-                'qtips'         => array('Registration_List_Table_Tips'),
142
-                'list_table'    => 'EE_Event_Registrations_List_Table',
143
-                'metaboxes'     => array(),
144
-                'require_nonce' => false,
145
-            ),
146
-            'registration_checkins' => array(
147
-                'nav'           => array(
148
-                    'label'      => __('Check-In Records', 'event_espresso'),
149
-                    'order'      => 15,
150
-                    'persistent' => false,
151
-                ),
152
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
153
-                //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
154
-                'metaboxes'     => array(),
155
-                'require_nonce' => false,
156
-            ),
157
-        );
158
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
159
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
-    }
162
-
163
-
164
-
165
-    protected function _ajax_hooks()
166
-    {
167
-        parent::_ajax_hooks();
168
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
169
-    }
170
-
171
-
172
-
173
-    public function load_scripts_styles()
174
-    {
175
-        parent::load_scripts_styles();
176
-        //if newsletter message type is active then let's add filter and load js for it.
177
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
178
-            //enqueue newsletter js
179
-            wp_enqueue_script(
180
-                'ee-newsletter-trigger',
181
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
182
-                array('ee-dialog'),
183
-                EVENT_ESPRESSO_VERSION,
184
-                true
185
-            );
186
-            wp_enqueue_style(
187
-                'ee-newsletter-trigger-css',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
189
-                array(),
190
-                EVENT_ESPRESSO_VERSION
191
-            );
192
-            //hook in buttons for newsletter message type trigger.
193
-            add_action(
194
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
195
-                array($this, 'add_newsletter_action_buttons'),
196
-                10
197
-            );
198
-        }
199
-    }
200
-
201
-
202
-
203
-    public function load_scripts_styles_reports()
204
-    {
205
-        wp_register_script(
206
-            'ee-reg-reports-js',
207
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
208
-            array('google-charts'),
209
-            EVENT_ESPRESSO_VERSION,
210
-            true
211
-        );
212
-        wp_enqueue_script('ee-reg-reports-js');
213
-        $this->_registration_reports_js_setup();
214
-    }
215
-
216
-
217
-
218
-    protected function _add_screen_options_event_registrations()
219
-    {
220
-        $this->_per_page_screen_option();
221
-    }
222
-
223
-
224
-
225
-    protected function _add_screen_options_registration_checkins()
226
-    {
227
-        $page_title = $this->_admin_page_title;
228
-        $this->_admin_page_title = __('Check-In Records', 'event_espresso');
229
-        $this->_per_page_screen_option();
230
-        $this->_admin_page_title = $page_title;
231
-    }
232
-
233
-
234
-
235
-    protected function _set_list_table_views_event_registrations()
236
-    {
237
-        $this->_views = array(
238
-            'all' => array(
239
-                'slug'        => 'all',
240
-                'label'       => __('All', 'event_espresso'),
241
-                'count'       => 0,
242
-                'bulk_action' => ! isset($this->_req_data['event_id'])
243
-                    ? array()
244
-                    : array(
245
-                        'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
246
-                        //'trash_registrations' => __('Trash Registrations', 'event_espresso')
247
-                    ),
248
-            ),
249
-        );
250
-    }
251
-
252
-
253
-
254
-    protected function _set_list_table_views_registration_checkins()
255
-    {
256
-        $this->_views = array(
257
-            'all' => array(
258
-                'slug'        => 'all',
259
-                'label'       => __('All', 'event_espresso'),
260
-                'count'       => 0,
261
-                'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
262
-            ),
263
-        );
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * callback for ajax action.
270
-     *
271
-     * @since 4.3.0
272
-     * @return void (JSON)
273
-     * @throws \EE_Error
274
-     */
275
-    public function get_newsletter_form_content()
276
-    {
277
-        //do a nonce check cause we're not coming in from an normal route here.
278
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
279
-            $this->_req_data['get_newsletter_form_content_nonce']
280
-        ) : '';
281
-        $nonce_ref = 'get_newsletter_form_content_nonce';
282
-        $this->_verify_nonce($nonce, $nonce_ref);
283
-        //let's get the mtp for the incoming MTP_ ID
284
-        if ( ! isset($this->_req_data['GRP_ID'])) {
285
-            EE_Error::add_error(
286
-                __(
287
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
288
-                    'event_espresso'
289
-                ),
290
-                __FILE__,
291
-                __FUNCTION__,
292
-                __LINE__
293
-            );
294
-            $this->_template_args['success'] = false;
295
-            $this->_template_args['error'] = true;
296
-            $this->_return_json();
297
-        }
298
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
299
-        if ( ! $MTPG instanceof EE_Message_Template_Group) {
300
-            EE_Error::add_error(
301
-                sprintf(
302
-                    __(
303
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
304
-                        'event_espresso'
305
-                    ),
306
-                    $this->_req_data['GRP_ID']
307
-                ),
308
-                __FILE__,
309
-                __FUNCTION__,
310
-                __LINE__
311
-            );
312
-            $this->_template_args['success'] = false;
313
-            $this->_template_args['error'] = true;
314
-            $this->_return_json();
315
-        }
316
-        $MTPs = $MTPG->context_templates();
317
-        $MTPs = $MTPs['attendee'];
318
-        $template_fields = array();
319
-        /** @var EE_Message_Template $MTP */
320
-        foreach ($MTPs as $MTP) {
321
-            $field = $MTP->get('MTP_template_field');
322
-            if ($field === 'content') {
323
-                $content = $MTP->get('MTP_content');
324
-                if ( ! empty($content['newsletter_content'])) {
325
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
326
-                }
327
-                continue;
328
-            }
329
-            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
330
-        }
331
-        $this->_template_args['success'] = true;
332
-        $this->_template_args['error'] = false;
333
-        $this->_template_args['data'] = array(
334
-            'batch_message_from'    => isset($template_fields['from'])
335
-                ? $template_fields['from']
336
-                : '',
337
-            'batch_message_subject' => isset($template_fields['subject'])
338
-                ? $template_fields['subject']
339
-                : '',
340
-            'batch_message_content' => isset($template_fields['newsletter_content'])
341
-                ? $template_fields['newsletter_content']
342
-                : '',
343
-        );
344
-        $this->_return_json();
345
-    }
346
-
347
-
348
-
349
-    /**
350
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
351
-     *
352
-     * @since 4.3.0
353
-     * @param EE_Admin_List_Table $list_table
354
-     * @return void
355
-     */
356
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
357
-    {
358
-        if ( ! EE_Registry::instance()->CAP->current_user_can(
359
-            'ee_send_message',
360
-            'espresso_registrations_newsletter_selected_send'
361
-        )
362
-        ) {
363
-            return;
364
-        }
365
-        $routes_to_add_to = array(
366
-            'contact_list',
367
-            'event_registrations',
368
-            'default',
369
-        );
370
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
371
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
372
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
373
-            ) {
374
-                echo '';
375
-            } else {
376
-                $button_text = sprintf(
377
-                    __('Send Batch Message (%s selected)', 'event_espresso'),
378
-                    '<span class="send-selected-newsletter-count">0</span>'
379
-                );
380
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
381
-                     . $button_text
382
-                     . '</button>';
383
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
384
-            }
385
-        }
386
-    }
387
-
388
-
389
-
390
-    public function newsletter_send_form_skeleton()
391
-    {
392
-        $list_table = $this->_list_table_object;
393
-        $codes = array();
394
-        //need to templates for the newsletter message type for the template selector.
395
-        $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
396
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
397
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
398
-        );
399
-        foreach ($mtps as $mtp) {
400
-            $name = $mtp->name();
401
-            $values[] = array(
402
-                'text' => empty($name) ? __('Global', 'event_espresso') : $name,
403
-                'id'   => $mtp->ID(),
404
-            );
405
-        }
406
-        //need to get a list of shortcodes that are available for the newsletter message type.
407
-        $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
408
-        foreach ($shortcodes as $field => $shortcode_array) {
409
-            $codes[$field] = implode(', ', array_keys($shortcode_array));
410
-        }
411
-        $shortcodes = $codes;
412
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
413
-        $form_template_args = array(
414
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415
-            'form_route'        => 'newsletter_selected_send',
416
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
417
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
418
-            'redirect_back_to'  => $this->_req_action,
419
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
420
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
421
-            'shortcodes'        => $shortcodes,
422
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
423
-        );
424
-        EEH_Template::display_template($form_template, $form_template_args);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Handles sending selected registrations/contacts a newsletter.
431
-     *
432
-     * @since  4.3.0
433
-     * @return void
434
-     * @throws \EE_Error
435
-     */
436
-    protected function _newsletter_selected_send()
437
-    {
438
-        $success = true;
439
-        //first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
440
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
441
-            EE_Error::add_error(
442
-                __(
443
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
444
-                    'event_espresso'
445
-                ),
446
-                __FILE__,
447
-                __FUNCTION__,
448
-                __LINE__
449
-            );
450
-            $success = false;
451
-        }
452
-        if ($success) {
453
-            //update Message template in case there are any changes
454
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
455
-                $this->_req_data['newsletter_mtp_selected']
456
-            );
457
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
458
-                ? $Message_Template_Group->context_templates()
459
-                : array();
460
-            if (empty($Message_Templates)) {
461
-                EE_Error::add_error(
462
-                    __(
463
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
464
-                        'event_espresso'
465
-                    ),
466
-                    __FILE__,
467
-                    __FUNCTION__,
468
-                    __LINE__
469
-                );
470
-            }
471
-            //let's just update the specific fields
472
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
473
-                if ($Message_Template instanceof EE_Message_Template) {
474
-                    $field = $Message_Template->get('MTP_template_field');
475
-                    $content = $Message_Template->get('MTP_content');
476
-                    $new_content = $content;
477
-                    switch ($field) {
478
-                        case 'from' :
479
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
480
-                                ? $this->_req_data['batch_message']['from']
481
-                                : $content;
482
-                            break;
483
-                        case 'subject' :
484
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
485
-                                ? $this->_req_data['batch_message']['subject']
486
-                                : $content;
487
-                            break;
488
-                        case 'content' :
489
-                            $new_content = $content;
490
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
491
-                                ? $this->_req_data['batch_message']['content']
492
-                                : $content['newsletter_content'];
493
-                            break;
494
-                        default :
495
-                            //continue the foreach loop, we don't want to set $new_content nor save.
496
-                            continue 2;
497
-                    }
498
-                    $Message_Template->set('MTP_content', $new_content);
499
-                    $Message_Template->save();
500
-                }
501
-            }
502
-            //great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
503
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
504
-                ? $this->_req_data['batch_message']['id_type']
505
-                : 'registration';
506
-            //id_type will affect how we assemble the ids.
507
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
508
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
509
-                : array();
510
-            $registrations_used_for_contact_data = array();
511
-            //using switch because eventually we'll have other contexts that will be used for generating messages.
512
-            switch ($id_type) {
513
-                case 'registration' :
514
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
515
-                        array(
516
-                            array(
517
-                                'REG_ID' => array('IN', $ids),
518
-                            ),
519
-                        )
520
-                    );
521
-                    break;
522
-                case 'contact' :
523
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
524
-                                                                           ->get_latest_registration_for_each_of_given_contacts($ids);
525
-                    break;
526
-            }
527
-            do_action(
528
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
529
-                $registrations_used_for_contact_data,
530
-                $Message_Template_Group->ID()
531
-            );
532
-            //kept for backward compat, internally we no longer use this action.
533
-            //@deprecated 4.8.36.rc.002
534
-            $contacts = $id_type === 'registration'
535
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
536
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
537
-            do_action(
538
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
539
-                $contacts,
540
-                $Message_Template_Group->ID()
541
-            );
542
-        }
543
-        $query_args = array(
544
-            'action' => ! empty($this->_req_data['redirect_back_to'])
545
-                ? $this->_req_data['redirect_back_to']
546
-                : 'default',
547
-        );
548
-        $this->_redirect_after_action(false, '', '', $query_args, true);
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
555
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
556
-     */
557
-    protected function _registration_reports_js_setup()
558
-    {
559
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
560
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     *        generates Business Reports regarding Registrations
567
-     *
568
-     * @access protected
569
-     * @return void
570
-     */
571
-    protected function _registration_reports()
572
-    {
573
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
574
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
575
-            $template_path,
576
-            $this->_reports_template_data,
577
-            true
578
-        );
579
-        // the final template wrapper
580
-        $this->display_admin_page_with_no_sidebar();
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * Generates Business Report showing total registrations per day.
587
-     *
588
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
589
-     * @return string
590
-     */
591
-    private function _registrations_per_day_report($period = '-1 month')
592
-    {
593
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
594
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
-        $results = (array)$results;
596
-        $regs = array();
597
-        $subtitle = '';
598
-        if ($results) {
599
-            $column_titles = array();
600
-            $tracker = 0;
601
-            foreach ($results as $result) {
602
-                $report_column_values = array();
603
-                foreach ($result as $property_name => $property_value) {
604
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
605
-                        : (int)$property_value;
606
-                    $report_column_values[] = $property_value;
607
-                    if ($tracker === 0) {
608
-                        if ($property_name === 'Registration_REG_date') {
609
-                            $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
610
-                        } else {
611
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
612
-                        }
613
-                    }
614
-                }
615
-                $tracker++;
616
-                $regs[] = $report_column_values;
617
-            }
618
-            //make sure the column_titles is pushed to the beginning of the array
619
-            array_unshift($regs, $column_titles);
620
-            //setup the date range.
621
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
623
-            $ending_date = new DateTime("now", $DateTimeZone);
624
-            $subtitle = sprintf(
625
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
626
-                $beginning_date->format('Y-m-d'),
627
-                $ending_date->format('Y-m-d')
628
-            );
629
-        }
630
-        $report_title = __('Total Registrations per Day', 'event_espresso');
631
-        $report_params = array(
632
-            'title'     => $report_title,
633
-            'subtitle'  => $subtitle,
634
-            'id'        => $report_ID,
635
-            'regs'      => $regs,
636
-            'noResults' => empty($regs),
637
-            'noRegsMsg' => sprintf(
638
-                __(
639
-                    '%sThere are currently no registration records in the last month for this report.%s',
640
-                    'event_espresso'
641
-                ),
642
-                '<h2>' . $report_title . '</h2><p>',
643
-                '</p>'
644
-            ),
645
-        );
646
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
647
-        return $report_ID;
648
-    }
649
-
650
-
651
-
652
-    /**
653
-     * Generates Business Report showing total registrations per event.
654
-     *
655
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
656
-     * @return string
657
-     */
658
-    private function _registrations_per_event_report($period = '-1 month')
659
-    {
660
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
661
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
-        $results = (array)$results;
663
-        $regs = array();
664
-        $subtitle = '';
665
-        if ($results) {
666
-            $column_titles = array();
667
-            $tracker = 0;
668
-            foreach ($results as $result) {
669
-                $report_column_values = array();
670
-                foreach ($result as $property_name => $property_value) {
671
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
672
-                        $property_value,
673
-                        4,
674
-                        '...'
675
-                    ) : (int)$property_value;
676
-                    $report_column_values[] = $property_value;
677
-                    if ($tracker === 0) {
678
-                        if ($property_name === 'Registration_Event') {
679
-                            $column_titles[] = __('Event', 'event_espresso');
680
-                        } else {
681
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
682
-                        }
683
-                    }
684
-                }
685
-                $tracker++;
686
-                $regs[] = $report_column_values;
687
-            }
688
-            //make sure the column_titles is pushed to the beginning of the array
689
-            array_unshift($regs, $column_titles);
690
-            //setup the date range.
691
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
693
-            $ending_date = new DateTime("now", $DateTimeZone);
694
-            $subtitle = sprintf(
695
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
696
-                $beginning_date->format('Y-m-d'),
697
-                $ending_date->format('Y-m-d')
698
-            );
699
-        }
700
-        $report_title = __('Total Registrations per Event', 'event_espresso');
701
-        $report_params = array(
702
-            'title'     => $report_title,
703
-            'subtitle'  => $subtitle,
704
-            'id'        => $report_ID,
705
-            'regs'      => $regs,
706
-            'noResults' => empty($regs),
707
-            'noRegsMsg' => sprintf(
708
-                __(
709
-                    '%sThere are currently no registration records in the last month for this report.%s',
710
-                    'event_espresso'
711
-                ),
712
-                '<h2>' . $report_title . '</h2><p>',
713
-                '</p>'
714
-            ),
715
-        );
716
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
717
-        return $report_ID;
718
-    }
719
-
720
-
721
-
722
-    /**
723
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
724
-     *
725
-     * @access protected
726
-     * @return void
727
-     * @throws \EE_Error
728
-     */
729
-    protected function _registration_checkin_list_table()
730
-    {
731
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
732
-        $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
733
-        /** @var EE_Registration $registration */
734
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
735
-        $attendee = $registration->attendee();
736
-        $this->_admin_page_title .= $this->get_action_link_or_button(
737
-            'new_registration',
738
-            'add-registrant',
739
-            array('event_id' => $registration->event_ID()),
740
-            'add-new-h2'
741
-        );
742
-        $legend_items = array(
743
-            'checkin'  => array(
744
-                'class' => 'ee-icon ee-icon-check-in',
745
-                'desc'  => __('This indicates the attendee has been checked in', 'event_espresso'),
746
-            ),
747
-            'checkout' => array(
748
-                'class' => 'ee-icon ee-icon-check-out',
749
-                'desc'  => __('This indicates the attendee has been checked out', 'event_espresso'),
750
-            ),
751
-        );
752
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
753
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
754
-        /** @var EE_Datetime $datetime */
755
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
756
-        $datetime_label = '';
757
-        if ($datetime instanceof EE_Datetime) {
758
-            $datetime_label = $datetime->get_dtt_display_name(true);
759
-            $datetime_label .= ! empty($datetime_label)
760
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
761
-                : $datetime->get_dtt_display_name();
762
-        }
763
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
764
-            ? EE_Admin_Page::add_query_args_and_nonce(
765
-                array(
766
-                    'action'   => 'event_registrations',
767
-                    'event_id' => $registration->event_ID(),
768
-                    'DTT_ID'   => $dtt_id,
769
-                ),
770
-                $this->_admin_base_url
771
-            )
772
-            : '';
773
-        $datetime_link = ! empty($datetime_link)
774
-            ? '<a href="' . $datetime_link . '">'
775
-              . '<span id="checkin-dtt">'
776
-              . $datetime_label
777
-              . '</span></a>'
778
-            : $datetime_label;
779
-        $attendee_name = $attendee instanceof EE_Attendee
780
-            ? $attendee->full_name()
781
-            : '';
782
-        $attendee_link = $attendee instanceof EE_Attendee
783
-            ? $attendee->get_admin_details_link()
784
-            : '';
785
-        $attendee_link = ! empty($attendee_link)
786
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
787
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
788
-              . '<span id="checkin-attendee-name">'
789
-              . $attendee_name
790
-              . '</span></a>'
791
-            : '';
792
-        $event_link = $registration->event() instanceof EE_Event
793
-            ? $registration->event()->get_admin_details_link()
794
-            : '';
795
-        $event_link = ! empty($event_link)
796
-            ? '<a href="' . $event_link . '"'
797
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
798
-              . '<span id="checkin-event-name">'
799
-              . $registration->event_name()
800
-              . '</span>'
801
-              . '</a>'
802
-            : '';
803
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
-            ? '<h2>' . sprintf(
805
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806
-                $attendee_link,
807
-                $datetime_link,
808
-                $event_link
809
-            ) . '</h2>'
810
-            : '';
811
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
813
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
815
-        $this->display_admin_list_table_page_with_no_sidebar();
816
-    }
817
-
818
-
819
-
820
-    /**
821
-     * toggle the Check-in status for the given registration (coming from ajax)
822
-     *
823
-     * @return void (JSON)
824
-     */
825
-    public function toggle_checkin_status()
826
-    {
827
-        //first make sure we have the necessary data
828
-        if ( ! isset($this->_req_data['_regid'])) {
829
-            EE_Error::add_error(
830
-                __(
831
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
832
-                    'event_espresso'
833
-                ),
834
-                __FILE__,
835
-                __FUNCTION__,
836
-                __LINE__
837
-            );
838
-            $this->_template_args['success'] = false;
839
-            $this->_template_args['error'] = true;
840
-            $this->_return_json();
841
-        };
842
-        //do a nonce check cause we're not coming in from an normal route here.
843
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
844
-            : '';
845
-        $nonce_ref = 'checkin_nonce';
846
-        $this->_verify_nonce($nonce, $nonce_ref);
847
-        //beautiful! Made it this far so let's get the status.
848
-        $new_status = $this->_toggle_checkin_status();
849
-        //setup new class to return via ajax
850
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-'
851
-                                                      . $new_status;
852
-        $this->_template_args['success'] = true;
853
-        $this->_return_json();
854
-    }
855
-
856
-
857
-
858
-    /**
859
-     * handles toggling the checkin status for the registration,
860
-     *
861
-     * @access protected
862
-     * @return int|void
863
-     */
864
-    protected function _toggle_checkin_status()
865
-    {
866
-        //first let's get the query args out of the way for the redirect
867
-        $query_args = array(
868
-            'action'   => 'event_registrations',
869
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
870
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
871
-        );
872
-        $new_status = false;
873
-        // bulk action check in toggle
874
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
-            // cycle thru checkboxes
876
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
877
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
878
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
879
-            }
880
-        } elseif (isset($this->_req_data['_regid'])) {
881
-            //coming from ajax request
882
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
883
-            $query_args['DTT_ID'] = $DTT_ID;
884
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
885
-        } else {
886
-            EE_Error::add_error(
887
-                __('Missing some required data to toggle the Check-in', 'event_espresso'),
888
-                __FILE__,
889
-                __FUNCTION__,
890
-                __LINE__
891
-            );
892
-        }
893
-        if (defined('DOING_AJAX')) {
894
-            return $new_status;
895
-        }
896
-        $this->_redirect_after_action(false, '', '', $query_args, true);
897
-    }
898
-
899
-
900
-
901
-    /**
902
-     * This is toggles a single Check-in for the given registration and datetime.
903
-     *
904
-     * @param  int $REG_ID The registration we're toggling
905
-     * @param  int $DTT_ID The datetime we're toggling
906
-     * @return int            The new status toggled to.
907
-     * @throws \EE_Error
908
-     */
909
-    private function _toggle_checkin($REG_ID, $DTT_ID)
910
-    {
911
-        /** @var EE_Registration $REG */
912
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
913
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
914
-        if ($new_status !== false) {
915
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
916
-        } else {
917
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
918
-            $new_status = false;
919
-        }
920
-        return $new_status;
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     * Takes care of deleting multiple EE_Checkin table rows
927
-     *
928
-     * @access protected
929
-     * @return void
930
-     * @throws \EE_Error
931
-     */
932
-    protected function _delete_checkin_rows()
933
-    {
934
-        $query_args = array(
935
-            'action' => 'registration_checkins',
936
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
937
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
938
-        );
939
-        $errors = 0;
940
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
941
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
942
-                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
943
-                    $errors++;
944
-                }
945
-            }
946
-        } else {
947
-            EE_Error::add_error(
948
-                __(
949
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
950
-                    'event_espresso'
951
-                ),
952
-                __FILE__,
953
-                __FUNCTION__,
954
-                __LINE__
955
-            );
956
-            $this->_redirect_after_action(false, '', '', $query_args, true);
957
-        }
958
-        if ($errors > 0) {
959
-            EE_Error::add_error(
960
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
961
-                __FILE__,
962
-                __FUNCTION__,
963
-                __LINE__
964
-            );
965
-        } else {
966
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
967
-        }
968
-        $this->_redirect_after_action(false, '', '', $query_args, true);
969
-    }
970
-
971
-
972
-
973
-    /**
974
-     * Deletes a single EE_Checkin row
975
-     *
976
-     * @return void
977
-     * @throws \EE_Error
978
-     */
979
-    protected function _delete_checkin_row()
980
-    {
981
-        $query_args = array(
982
-            'action' => 'registration_checkins',
983
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
984
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
985
-        );
986
-        if ( ! empty($this->_req_data['CHK_ID'])) {
987
-            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
988
-                EE_Error::add_error(
989
-                    __('Something went wrong and this check-in record was not deleted', 'event_espresso'),
990
-                    __FILE__,
991
-                    __FUNCTION__,
992
-                    __LINE__
993
-                );
994
-            } else {
995
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
996
-            }
997
-        } else {
998
-            EE_Error::add_error(
999
-                __(
1000
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1001
-                    'event_espresso'
1002
-                ),
1003
-                __FILE__,
1004
-                __FUNCTION__,
1005
-                __LINE__
1006
-            );
1007
-        }
1008
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     *        generates HTML for the Event Registrations List Table
1015
-     *
1016
-     * @access protected
1017
-     * @return void
1018
-     * @throws \EE_Error
1019
-     */
1020
-    protected function _event_registrations_list_table()
1021
-    {
1022
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1023
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1024
-            ? $this->get_action_link_or_button(
1025
-                'new_registration',
1026
-                'add-registrant',
1027
-                array('event_id' => $this->_req_data['event_id']),
1028
-                'add-new-h2',
1029
-                '',
1030
-                false
1031
-            )
1032
-            : '';
1033
-        $legend_items = array(
1034
-            'star-icon'        => array(
1035
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
-                'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1037
-            ),
1038
-            'checkin'          => array(
1039
-                'class' => 'ee-icon ee-icon-check-in',
1040
-                'desc'  => __('This Registrant has been Checked In', 'event_espresso'),
1041
-            ),
1042
-            'checkout'         => array(
1043
-                'class' => 'ee-icon ee-icon-check-out',
1044
-                'desc'  => __('This Registrant has been Checked Out', 'event_espresso'),
1045
-            ),
1046
-            'nocheckinrecord'  => array(
1047
-                'class' => 'dashicons dashicons-no',
1048
-                'desc'  => __('No Check-in Record has been Created for this Registrant', 'event_espresso'),
1049
-            ),
1050
-            'view_details'     => array(
1051
-                'class' => 'dashicons dashicons-search',
1052
-                'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053
-            ),
1054
-            'approved_status'  => array(
1055
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1056
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057
-            ),
1058
-            'cancelled_status' => array(
1059
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1060
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061
-            ),
1062
-            'declined_status'  => array(
1063
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1064
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065
-            ),
1066
-            'not_approved'     => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1068
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069
-            ),
1070
-            'pending_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1072
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073
-            ),
1074
-            'wait_list'        => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1076
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077
-            ),
1078
-        );
1079
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081
-        $this->_template_args['before_list_table'] = ! empty($event_id)
1082
-            ? '<h2>' . sprintf(
1083
-                __('Viewing Registrations for Event: %s', 'event_espresso'),
1084
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
-            ) . '</h2>'
1086
-            : '';
1087
-        //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088
-        /** @var EE_Event $event */
1089
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1090
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1091
-        $datetime = null;
1092
-        if ($event instanceof EE_Event) {
1093
-            $datetimes_on_event = $event->datetimes();
1094
-            if (count($datetimes_on_event) === 1) {
1095
-                $datetime = reset($datetimes_on_event);
1096
-            }
1097
-        }
1098
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1099
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1100
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1101
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103
-            $this->_template_args['before_list_table'] .= $datetime->name();
1104
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1105
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1106
-        }
1107
-        //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1108
-        //represents
1109
-        if ( ! $datetime instanceof EE_Datetime) {
1110
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1111
-                                                          . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1112
-                    'event_espresso')
1113
-                                                          . '</p>';
1114
-        }
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-    /**
1119
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1120
-     * conditions)
1121
-     *
1122
-     * @return void ends the request by a redirect or download
1123
-     */
1124
-    public function _registrations_checkin_report()
1125
-    {
1126
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1127
-    }
1128
-
1129
-    /**
1130
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1131
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1132
-     *
1133
-     * @param array     $request
1134
-     * @param int  $per_page
1135
-     * @param bool $count
1136
-     * @return array
1137
-     */
1138
-    protected function _get_checkin_query_params_from_request(
1139
-        $request,
1140
-        $per_page = 10,
1141
-        $count = false
1142
-    ) {
1143
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1144
-        //unlike the regular registrations list table,
1145
-        $status_ids_array = apply_filters(
1146
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1147
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1148
-        );
1149
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1150
-        return $query_params;
1151
-    }
1152
-
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * Gets registrations for an event
1158
-     *
1159
-     * @param int    $per_page
1160
-     * @param bool   $count whether to return count or data.
1161
-     * @param bool   $trash
1162
-     * @param string $orderby
1163
-     * @return EE_Registration[]|int
1164
-     * @throws \EE_Error
1165
-     */
1166
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1167
-    {
1168
-        //normalize some request params that get setup by the parent `get_registrations` method.
1169
-        $request = $this->_req_data;
1170
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
-        if($trash){
1173
-            $request['status'] = 'trash';
1174
-        }
1175
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1176
-        /**
1177
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1179
-         * @see EEM_Base::get_all()
1180
-         */
1181
-        $query_params['group_by'] = '';
1182
-
1183
-        return $count
1184
-            ? EEM_Registration::instance()->count($query_params)
1185
-            /** @type EE_Registration[] */
1186
-            : EEM_Registration::instance()->get_all($query_params);
1187
-    }
20
+	/**
21
+	 * This is used to hold the reports template data which is setup early in the request.
22
+	 *
23
+	 * @type array
24
+	 */
25
+	protected $_reports_template_data = array();
26
+
27
+
28
+
29
+	/**
30
+	 * Extend_Registrations_Admin_Page constructor.
31
+	 *
32
+	 * @param bool $routing
33
+	 */
34
+	public function __construct($routing = true)
35
+	{
36
+		parent::__construct($routing);
37
+		if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
41
+		}
42
+	}
43
+
44
+
45
+
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		// $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
+		// $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
54
+		// 	? $this->_req_data['post'] : $att_id;
55
+		$new_page_routes = array(
56
+			'reports'                  => array(
57
+				'func'       => '_registration_reports',
58
+				'capability' => 'ee_read_registrations',
59
+			),
60
+			'registration_checkins'    => array(
61
+				'func'       => '_registration_checkin_list_table',
62
+				'capability' => 'ee_read_checkins',
63
+			),
64
+			'newsletter_selected_send' => array(
65
+				'func'       => '_newsletter_selected_send',
66
+				'noheader'   => true,
67
+				'capability' => 'ee_send_message',
68
+			),
69
+			'delete_checkin_rows'      => array(
70
+				'func'       => '_delete_checkin_rows',
71
+				'noheader'   => true,
72
+				'capability' => 'ee_delete_checkins',
73
+			),
74
+			'delete_checkin_row'       => array(
75
+				'func'       => '_delete_checkin_row',
76
+				'noheader'   => true,
77
+				'capability' => 'ee_delete_checkin',
78
+				'obj_id'     => $reg_id,
79
+			),
80
+			'toggle_checkin_status'    => array(
81
+				'func'       => '_toggle_checkin_status',
82
+				'noheader'   => true,
83
+				'capability' => 'ee_edit_checkin',
84
+				'obj_id'     => $reg_id,
85
+			),
86
+			'event_registrations'      => array(
87
+				'func'       => '_event_registrations_list_table',
88
+				'capability' => 'ee_read_checkins',
89
+			),
90
+			'registrations_checkin_report' => array(
91
+				'func'       => '_registrations_checkin_report',
92
+				'noheader'   => true,
93
+				'capability' => 'ee_read_registrations',
94
+			),
95
+		);
96
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
97
+		$new_page_config = array(
98
+			'reports'               => array(
99
+				'nav'           => array(
100
+					'label' => __('Reports', 'event_espresso'),
101
+					'order' => 30,
102
+				),
103
+				'help_tabs'     => array(
104
+					'registrations_reports_help_tab' => array(
105
+						'title'    => __('Registration Reports', 'event_espresso'),
106
+						'filename' => 'registrations_reports',
107
+					),
108
+				),
109
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
110
+				'require_nonce' => false,
111
+			),
112
+			'event_registrations'   => array(
113
+				'nav'           => array(
114
+					'label'      => __('Event Check-In', 'event_espresso'),
115
+					'order'      => 10,
116
+					'persistent' => true,
117
+				),
118
+				'help_tabs'     => array(
119
+					'registrations_event_checkin_help_tab'                       => array(
120
+						'title'    => __('Registrations Event Check-In', 'event_espresso'),
121
+						'filename' => 'registrations_event_checkin',
122
+					),
123
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
124
+						'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
125
+						'filename' => 'registrations_event_checkin_table_column_headings',
126
+					),
127
+					'registrations_event_checkin_filters_help_tab'               => array(
128
+						'title'    => __('Event Check-In Filters', 'event_espresso'),
129
+						'filename' => 'registrations_event_checkin_filters',
130
+					),
131
+					'registrations_event_checkin_views_help_tab'                 => array(
132
+						'title'    => __('Event Check-In Views', 'event_espresso'),
133
+						'filename' => 'registrations_event_checkin_views',
134
+					),
135
+					'registrations_event_checkin_other_help_tab'                 => array(
136
+						'title'    => __('Event Check-In Other', 'event_espresso'),
137
+						'filename' => 'registrations_event_checkin_other',
138
+					),
139
+				),
140
+				'help_tour'     => array('Event_Checkin_Help_Tour'),
141
+				'qtips'         => array('Registration_List_Table_Tips'),
142
+				'list_table'    => 'EE_Event_Registrations_List_Table',
143
+				'metaboxes'     => array(),
144
+				'require_nonce' => false,
145
+			),
146
+			'registration_checkins' => array(
147
+				'nav'           => array(
148
+					'label'      => __('Check-In Records', 'event_espresso'),
149
+					'order'      => 15,
150
+					'persistent' => false,
151
+				),
152
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
153
+				//'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
154
+				'metaboxes'     => array(),
155
+				'require_nonce' => false,
156
+			),
157
+		);
158
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
159
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
+	}
162
+
163
+
164
+
165
+	protected function _ajax_hooks()
166
+	{
167
+		parent::_ajax_hooks();
168
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
169
+	}
170
+
171
+
172
+
173
+	public function load_scripts_styles()
174
+	{
175
+		parent::load_scripts_styles();
176
+		//if newsletter message type is active then let's add filter and load js for it.
177
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
178
+			//enqueue newsletter js
179
+			wp_enqueue_script(
180
+				'ee-newsletter-trigger',
181
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
182
+				array('ee-dialog'),
183
+				EVENT_ESPRESSO_VERSION,
184
+				true
185
+			);
186
+			wp_enqueue_style(
187
+				'ee-newsletter-trigger-css',
188
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
189
+				array(),
190
+				EVENT_ESPRESSO_VERSION
191
+			);
192
+			//hook in buttons for newsletter message type trigger.
193
+			add_action(
194
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
195
+				array($this, 'add_newsletter_action_buttons'),
196
+				10
197
+			);
198
+		}
199
+	}
200
+
201
+
202
+
203
+	public function load_scripts_styles_reports()
204
+	{
205
+		wp_register_script(
206
+			'ee-reg-reports-js',
207
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
208
+			array('google-charts'),
209
+			EVENT_ESPRESSO_VERSION,
210
+			true
211
+		);
212
+		wp_enqueue_script('ee-reg-reports-js');
213
+		$this->_registration_reports_js_setup();
214
+	}
215
+
216
+
217
+
218
+	protected function _add_screen_options_event_registrations()
219
+	{
220
+		$this->_per_page_screen_option();
221
+	}
222
+
223
+
224
+
225
+	protected function _add_screen_options_registration_checkins()
226
+	{
227
+		$page_title = $this->_admin_page_title;
228
+		$this->_admin_page_title = __('Check-In Records', 'event_espresso');
229
+		$this->_per_page_screen_option();
230
+		$this->_admin_page_title = $page_title;
231
+	}
232
+
233
+
234
+
235
+	protected function _set_list_table_views_event_registrations()
236
+	{
237
+		$this->_views = array(
238
+			'all' => array(
239
+				'slug'        => 'all',
240
+				'label'       => __('All', 'event_espresso'),
241
+				'count'       => 0,
242
+				'bulk_action' => ! isset($this->_req_data['event_id'])
243
+					? array()
244
+					: array(
245
+						'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
246
+						//'trash_registrations' => __('Trash Registrations', 'event_espresso')
247
+					),
248
+			),
249
+		);
250
+	}
251
+
252
+
253
+
254
+	protected function _set_list_table_views_registration_checkins()
255
+	{
256
+		$this->_views = array(
257
+			'all' => array(
258
+				'slug'        => 'all',
259
+				'label'       => __('All', 'event_espresso'),
260
+				'count'       => 0,
261
+				'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
262
+			),
263
+		);
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * callback for ajax action.
270
+	 *
271
+	 * @since 4.3.0
272
+	 * @return void (JSON)
273
+	 * @throws \EE_Error
274
+	 */
275
+	public function get_newsletter_form_content()
276
+	{
277
+		//do a nonce check cause we're not coming in from an normal route here.
278
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
279
+			$this->_req_data['get_newsletter_form_content_nonce']
280
+		) : '';
281
+		$nonce_ref = 'get_newsletter_form_content_nonce';
282
+		$this->_verify_nonce($nonce, $nonce_ref);
283
+		//let's get the mtp for the incoming MTP_ ID
284
+		if ( ! isset($this->_req_data['GRP_ID'])) {
285
+			EE_Error::add_error(
286
+				__(
287
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
288
+					'event_espresso'
289
+				),
290
+				__FILE__,
291
+				__FUNCTION__,
292
+				__LINE__
293
+			);
294
+			$this->_template_args['success'] = false;
295
+			$this->_template_args['error'] = true;
296
+			$this->_return_json();
297
+		}
298
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
299
+		if ( ! $MTPG instanceof EE_Message_Template_Group) {
300
+			EE_Error::add_error(
301
+				sprintf(
302
+					__(
303
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
304
+						'event_espresso'
305
+					),
306
+					$this->_req_data['GRP_ID']
307
+				),
308
+				__FILE__,
309
+				__FUNCTION__,
310
+				__LINE__
311
+			);
312
+			$this->_template_args['success'] = false;
313
+			$this->_template_args['error'] = true;
314
+			$this->_return_json();
315
+		}
316
+		$MTPs = $MTPG->context_templates();
317
+		$MTPs = $MTPs['attendee'];
318
+		$template_fields = array();
319
+		/** @var EE_Message_Template $MTP */
320
+		foreach ($MTPs as $MTP) {
321
+			$field = $MTP->get('MTP_template_field');
322
+			if ($field === 'content') {
323
+				$content = $MTP->get('MTP_content');
324
+				if ( ! empty($content['newsletter_content'])) {
325
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
326
+				}
327
+				continue;
328
+			}
329
+			$template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
330
+		}
331
+		$this->_template_args['success'] = true;
332
+		$this->_template_args['error'] = false;
333
+		$this->_template_args['data'] = array(
334
+			'batch_message_from'    => isset($template_fields['from'])
335
+				? $template_fields['from']
336
+				: '',
337
+			'batch_message_subject' => isset($template_fields['subject'])
338
+				? $template_fields['subject']
339
+				: '',
340
+			'batch_message_content' => isset($template_fields['newsletter_content'])
341
+				? $template_fields['newsletter_content']
342
+				: '',
343
+		);
344
+		$this->_return_json();
345
+	}
346
+
347
+
348
+
349
+	/**
350
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
351
+	 *
352
+	 * @since 4.3.0
353
+	 * @param EE_Admin_List_Table $list_table
354
+	 * @return void
355
+	 */
356
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
357
+	{
358
+		if ( ! EE_Registry::instance()->CAP->current_user_can(
359
+			'ee_send_message',
360
+			'espresso_registrations_newsletter_selected_send'
361
+		)
362
+		) {
363
+			return;
364
+		}
365
+		$routes_to_add_to = array(
366
+			'contact_list',
367
+			'event_registrations',
368
+			'default',
369
+		);
370
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
371
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
372
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
373
+			) {
374
+				echo '';
375
+			} else {
376
+				$button_text = sprintf(
377
+					__('Send Batch Message (%s selected)', 'event_espresso'),
378
+					'<span class="send-selected-newsletter-count">0</span>'
379
+				);
380
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
381
+					 . $button_text
382
+					 . '</button>';
383
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
384
+			}
385
+		}
386
+	}
387
+
388
+
389
+
390
+	public function newsletter_send_form_skeleton()
391
+	{
392
+		$list_table = $this->_list_table_object;
393
+		$codes = array();
394
+		//need to templates for the newsletter message type for the template selector.
395
+		$values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
396
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
397
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
398
+		);
399
+		foreach ($mtps as $mtp) {
400
+			$name = $mtp->name();
401
+			$values[] = array(
402
+				'text' => empty($name) ? __('Global', 'event_espresso') : $name,
403
+				'id'   => $mtp->ID(),
404
+			);
405
+		}
406
+		//need to get a list of shortcodes that are available for the newsletter message type.
407
+		$shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
408
+		foreach ($shortcodes as $field => $shortcode_array) {
409
+			$codes[$field] = implode(', ', array_keys($shortcode_array));
410
+		}
411
+		$shortcodes = $codes;
412
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
413
+		$form_template_args = array(
414
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415
+			'form_route'        => 'newsletter_selected_send',
416
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
417
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
418
+			'redirect_back_to'  => $this->_req_action,
419
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
420
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
421
+			'shortcodes'        => $shortcodes,
422
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
423
+		);
424
+		EEH_Template::display_template($form_template, $form_template_args);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Handles sending selected registrations/contacts a newsletter.
431
+	 *
432
+	 * @since  4.3.0
433
+	 * @return void
434
+	 * @throws \EE_Error
435
+	 */
436
+	protected function _newsletter_selected_send()
437
+	{
438
+		$success = true;
439
+		//first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
440
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
441
+			EE_Error::add_error(
442
+				__(
443
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
444
+					'event_espresso'
445
+				),
446
+				__FILE__,
447
+				__FUNCTION__,
448
+				__LINE__
449
+			);
450
+			$success = false;
451
+		}
452
+		if ($success) {
453
+			//update Message template in case there are any changes
454
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
455
+				$this->_req_data['newsletter_mtp_selected']
456
+			);
457
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
458
+				? $Message_Template_Group->context_templates()
459
+				: array();
460
+			if (empty($Message_Templates)) {
461
+				EE_Error::add_error(
462
+					__(
463
+						'Unable to retrieve message template fields from the db. Messages not sent.',
464
+						'event_espresso'
465
+					),
466
+					__FILE__,
467
+					__FUNCTION__,
468
+					__LINE__
469
+				);
470
+			}
471
+			//let's just update the specific fields
472
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
473
+				if ($Message_Template instanceof EE_Message_Template) {
474
+					$field = $Message_Template->get('MTP_template_field');
475
+					$content = $Message_Template->get('MTP_content');
476
+					$new_content = $content;
477
+					switch ($field) {
478
+						case 'from' :
479
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
480
+								? $this->_req_data['batch_message']['from']
481
+								: $content;
482
+							break;
483
+						case 'subject' :
484
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
485
+								? $this->_req_data['batch_message']['subject']
486
+								: $content;
487
+							break;
488
+						case 'content' :
489
+							$new_content = $content;
490
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
491
+								? $this->_req_data['batch_message']['content']
492
+								: $content['newsletter_content'];
493
+							break;
494
+						default :
495
+							//continue the foreach loop, we don't want to set $new_content nor save.
496
+							continue 2;
497
+					}
498
+					$Message_Template->set('MTP_content', $new_content);
499
+					$Message_Template->save();
500
+				}
501
+			}
502
+			//great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
503
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
504
+				? $this->_req_data['batch_message']['id_type']
505
+				: 'registration';
506
+			//id_type will affect how we assemble the ids.
507
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
508
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
509
+				: array();
510
+			$registrations_used_for_contact_data = array();
511
+			//using switch because eventually we'll have other contexts that will be used for generating messages.
512
+			switch ($id_type) {
513
+				case 'registration' :
514
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
515
+						array(
516
+							array(
517
+								'REG_ID' => array('IN', $ids),
518
+							),
519
+						)
520
+					);
521
+					break;
522
+				case 'contact' :
523
+					$registrations_used_for_contact_data = EEM_Registration::instance()
524
+																		   ->get_latest_registration_for_each_of_given_contacts($ids);
525
+					break;
526
+			}
527
+			do_action(
528
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
529
+				$registrations_used_for_contact_data,
530
+				$Message_Template_Group->ID()
531
+			);
532
+			//kept for backward compat, internally we no longer use this action.
533
+			//@deprecated 4.8.36.rc.002
534
+			$contacts = $id_type === 'registration'
535
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
536
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
537
+			do_action(
538
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
539
+				$contacts,
540
+				$Message_Template_Group->ID()
541
+			);
542
+		}
543
+		$query_args = array(
544
+			'action' => ! empty($this->_req_data['redirect_back_to'])
545
+				? $this->_req_data['redirect_back_to']
546
+				: 'default',
547
+		);
548
+		$this->_redirect_after_action(false, '', '', $query_args, true);
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
555
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
556
+	 */
557
+	protected function _registration_reports_js_setup()
558
+	{
559
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
560
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 *        generates Business Reports regarding Registrations
567
+	 *
568
+	 * @access protected
569
+	 * @return void
570
+	 */
571
+	protected function _registration_reports()
572
+	{
573
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
574
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
575
+			$template_path,
576
+			$this->_reports_template_data,
577
+			true
578
+		);
579
+		// the final template wrapper
580
+		$this->display_admin_page_with_no_sidebar();
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * Generates Business Report showing total registrations per day.
587
+	 *
588
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
589
+	 * @return string
590
+	 */
591
+	private function _registrations_per_day_report($period = '-1 month')
592
+	{
593
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
594
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
+		$results = (array)$results;
596
+		$regs = array();
597
+		$subtitle = '';
598
+		if ($results) {
599
+			$column_titles = array();
600
+			$tracker = 0;
601
+			foreach ($results as $result) {
602
+				$report_column_values = array();
603
+				foreach ($result as $property_name => $property_value) {
604
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
605
+						: (int)$property_value;
606
+					$report_column_values[] = $property_value;
607
+					if ($tracker === 0) {
608
+						if ($property_name === 'Registration_REG_date') {
609
+							$column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
610
+						} else {
611
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
612
+						}
613
+					}
614
+				}
615
+				$tracker++;
616
+				$regs[] = $report_column_values;
617
+			}
618
+			//make sure the column_titles is pushed to the beginning of the array
619
+			array_unshift($regs, $column_titles);
620
+			//setup the date range.
621
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
623
+			$ending_date = new DateTime("now", $DateTimeZone);
624
+			$subtitle = sprintf(
625
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
626
+				$beginning_date->format('Y-m-d'),
627
+				$ending_date->format('Y-m-d')
628
+			);
629
+		}
630
+		$report_title = __('Total Registrations per Day', 'event_espresso');
631
+		$report_params = array(
632
+			'title'     => $report_title,
633
+			'subtitle'  => $subtitle,
634
+			'id'        => $report_ID,
635
+			'regs'      => $regs,
636
+			'noResults' => empty($regs),
637
+			'noRegsMsg' => sprintf(
638
+				__(
639
+					'%sThere are currently no registration records in the last month for this report.%s',
640
+					'event_espresso'
641
+				),
642
+				'<h2>' . $report_title . '</h2><p>',
643
+				'</p>'
644
+			),
645
+		);
646
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
647
+		return $report_ID;
648
+	}
649
+
650
+
651
+
652
+	/**
653
+	 * Generates Business Report showing total registrations per event.
654
+	 *
655
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
656
+	 * @return string
657
+	 */
658
+	private function _registrations_per_event_report($period = '-1 month')
659
+	{
660
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
661
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
+		$results = (array)$results;
663
+		$regs = array();
664
+		$subtitle = '';
665
+		if ($results) {
666
+			$column_titles = array();
667
+			$tracker = 0;
668
+			foreach ($results as $result) {
669
+				$report_column_values = array();
670
+				foreach ($result as $property_name => $property_value) {
671
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
672
+						$property_value,
673
+						4,
674
+						'...'
675
+					) : (int)$property_value;
676
+					$report_column_values[] = $property_value;
677
+					if ($tracker === 0) {
678
+						if ($property_name === 'Registration_Event') {
679
+							$column_titles[] = __('Event', 'event_espresso');
680
+						} else {
681
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
682
+						}
683
+					}
684
+				}
685
+				$tracker++;
686
+				$regs[] = $report_column_values;
687
+			}
688
+			//make sure the column_titles is pushed to the beginning of the array
689
+			array_unshift($regs, $column_titles);
690
+			//setup the date range.
691
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
693
+			$ending_date = new DateTime("now", $DateTimeZone);
694
+			$subtitle = sprintf(
695
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
696
+				$beginning_date->format('Y-m-d'),
697
+				$ending_date->format('Y-m-d')
698
+			);
699
+		}
700
+		$report_title = __('Total Registrations per Event', 'event_espresso');
701
+		$report_params = array(
702
+			'title'     => $report_title,
703
+			'subtitle'  => $subtitle,
704
+			'id'        => $report_ID,
705
+			'regs'      => $regs,
706
+			'noResults' => empty($regs),
707
+			'noRegsMsg' => sprintf(
708
+				__(
709
+					'%sThere are currently no registration records in the last month for this report.%s',
710
+					'event_espresso'
711
+				),
712
+				'<h2>' . $report_title . '</h2><p>',
713
+				'</p>'
714
+			),
715
+		);
716
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
717
+		return $report_ID;
718
+	}
719
+
720
+
721
+
722
+	/**
723
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
724
+	 *
725
+	 * @access protected
726
+	 * @return void
727
+	 * @throws \EE_Error
728
+	 */
729
+	protected function _registration_checkin_list_table()
730
+	{
731
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
732
+		$reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
733
+		/** @var EE_Registration $registration */
734
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
735
+		$attendee = $registration->attendee();
736
+		$this->_admin_page_title .= $this->get_action_link_or_button(
737
+			'new_registration',
738
+			'add-registrant',
739
+			array('event_id' => $registration->event_ID()),
740
+			'add-new-h2'
741
+		);
742
+		$legend_items = array(
743
+			'checkin'  => array(
744
+				'class' => 'ee-icon ee-icon-check-in',
745
+				'desc'  => __('This indicates the attendee has been checked in', 'event_espresso'),
746
+			),
747
+			'checkout' => array(
748
+				'class' => 'ee-icon ee-icon-check-out',
749
+				'desc'  => __('This indicates the attendee has been checked out', 'event_espresso'),
750
+			),
751
+		);
752
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
753
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
754
+		/** @var EE_Datetime $datetime */
755
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
756
+		$datetime_label = '';
757
+		if ($datetime instanceof EE_Datetime) {
758
+			$datetime_label = $datetime->get_dtt_display_name(true);
759
+			$datetime_label .= ! empty($datetime_label)
760
+				? ' (' . $datetime->get_dtt_display_name() . ')'
761
+				: $datetime->get_dtt_display_name();
762
+		}
763
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
764
+			? EE_Admin_Page::add_query_args_and_nonce(
765
+				array(
766
+					'action'   => 'event_registrations',
767
+					'event_id' => $registration->event_ID(),
768
+					'DTT_ID'   => $dtt_id,
769
+				),
770
+				$this->_admin_base_url
771
+			)
772
+			: '';
773
+		$datetime_link = ! empty($datetime_link)
774
+			? '<a href="' . $datetime_link . '">'
775
+			  . '<span id="checkin-dtt">'
776
+			  . $datetime_label
777
+			  . '</span></a>'
778
+			: $datetime_label;
779
+		$attendee_name = $attendee instanceof EE_Attendee
780
+			? $attendee->full_name()
781
+			: '';
782
+		$attendee_link = $attendee instanceof EE_Attendee
783
+			? $attendee->get_admin_details_link()
784
+			: '';
785
+		$attendee_link = ! empty($attendee_link)
786
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
787
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
788
+			  . '<span id="checkin-attendee-name">'
789
+			  . $attendee_name
790
+			  . '</span></a>'
791
+			: '';
792
+		$event_link = $registration->event() instanceof EE_Event
793
+			? $registration->event()->get_admin_details_link()
794
+			: '';
795
+		$event_link = ! empty($event_link)
796
+			? '<a href="' . $event_link . '"'
797
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
798
+			  . '<span id="checkin-event-name">'
799
+			  . $registration->event_name()
800
+			  . '</span>'
801
+			  . '</a>'
802
+			: '';
803
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
+			? '<h2>' . sprintf(
805
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806
+				$attendee_link,
807
+				$datetime_link,
808
+				$event_link
809
+			) . '</h2>'
810
+			: '';
811
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
+			? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
813
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
815
+		$this->display_admin_list_table_page_with_no_sidebar();
816
+	}
817
+
818
+
819
+
820
+	/**
821
+	 * toggle the Check-in status for the given registration (coming from ajax)
822
+	 *
823
+	 * @return void (JSON)
824
+	 */
825
+	public function toggle_checkin_status()
826
+	{
827
+		//first make sure we have the necessary data
828
+		if ( ! isset($this->_req_data['_regid'])) {
829
+			EE_Error::add_error(
830
+				__(
831
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
832
+					'event_espresso'
833
+				),
834
+				__FILE__,
835
+				__FUNCTION__,
836
+				__LINE__
837
+			);
838
+			$this->_template_args['success'] = false;
839
+			$this->_template_args['error'] = true;
840
+			$this->_return_json();
841
+		};
842
+		//do a nonce check cause we're not coming in from an normal route here.
843
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
844
+			: '';
845
+		$nonce_ref = 'checkin_nonce';
846
+		$this->_verify_nonce($nonce, $nonce_ref);
847
+		//beautiful! Made it this far so let's get the status.
848
+		$new_status = $this->_toggle_checkin_status();
849
+		//setup new class to return via ajax
850
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-'
851
+													  . $new_status;
852
+		$this->_template_args['success'] = true;
853
+		$this->_return_json();
854
+	}
855
+
856
+
857
+
858
+	/**
859
+	 * handles toggling the checkin status for the registration,
860
+	 *
861
+	 * @access protected
862
+	 * @return int|void
863
+	 */
864
+	protected function _toggle_checkin_status()
865
+	{
866
+		//first let's get the query args out of the way for the redirect
867
+		$query_args = array(
868
+			'action'   => 'event_registrations',
869
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
870
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
871
+		);
872
+		$new_status = false;
873
+		// bulk action check in toggle
874
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
+			// cycle thru checkboxes
876
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
877
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
878
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
879
+			}
880
+		} elseif (isset($this->_req_data['_regid'])) {
881
+			//coming from ajax request
882
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
883
+			$query_args['DTT_ID'] = $DTT_ID;
884
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
885
+		} else {
886
+			EE_Error::add_error(
887
+				__('Missing some required data to toggle the Check-in', 'event_espresso'),
888
+				__FILE__,
889
+				__FUNCTION__,
890
+				__LINE__
891
+			);
892
+		}
893
+		if (defined('DOING_AJAX')) {
894
+			return $new_status;
895
+		}
896
+		$this->_redirect_after_action(false, '', '', $query_args, true);
897
+	}
898
+
899
+
900
+
901
+	/**
902
+	 * This is toggles a single Check-in for the given registration and datetime.
903
+	 *
904
+	 * @param  int $REG_ID The registration we're toggling
905
+	 * @param  int $DTT_ID The datetime we're toggling
906
+	 * @return int            The new status toggled to.
907
+	 * @throws \EE_Error
908
+	 */
909
+	private function _toggle_checkin($REG_ID, $DTT_ID)
910
+	{
911
+		/** @var EE_Registration $REG */
912
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
913
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
914
+		if ($new_status !== false) {
915
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
916
+		} else {
917
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
918
+			$new_status = false;
919
+		}
920
+		return $new_status;
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 * Takes care of deleting multiple EE_Checkin table rows
927
+	 *
928
+	 * @access protected
929
+	 * @return void
930
+	 * @throws \EE_Error
931
+	 */
932
+	protected function _delete_checkin_rows()
933
+	{
934
+		$query_args = array(
935
+			'action' => 'registration_checkins',
936
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
937
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
938
+		);
939
+		$errors = 0;
940
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
941
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
942
+				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
943
+					$errors++;
944
+				}
945
+			}
946
+		} else {
947
+			EE_Error::add_error(
948
+				__(
949
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
950
+					'event_espresso'
951
+				),
952
+				__FILE__,
953
+				__FUNCTION__,
954
+				__LINE__
955
+			);
956
+			$this->_redirect_after_action(false, '', '', $query_args, true);
957
+		}
958
+		if ($errors > 0) {
959
+			EE_Error::add_error(
960
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
961
+				__FILE__,
962
+				__FUNCTION__,
963
+				__LINE__
964
+			);
965
+		} else {
966
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
967
+		}
968
+		$this->_redirect_after_action(false, '', '', $query_args, true);
969
+	}
970
+
971
+
972
+
973
+	/**
974
+	 * Deletes a single EE_Checkin row
975
+	 *
976
+	 * @return void
977
+	 * @throws \EE_Error
978
+	 */
979
+	protected function _delete_checkin_row()
980
+	{
981
+		$query_args = array(
982
+			'action' => 'registration_checkins',
983
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
984
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
985
+		);
986
+		if ( ! empty($this->_req_data['CHK_ID'])) {
987
+			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
988
+				EE_Error::add_error(
989
+					__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
990
+					__FILE__,
991
+					__FUNCTION__,
992
+					__LINE__
993
+				);
994
+			} else {
995
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
996
+			}
997
+		} else {
998
+			EE_Error::add_error(
999
+				__(
1000
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1001
+					'event_espresso'
1002
+				),
1003
+				__FILE__,
1004
+				__FUNCTION__,
1005
+				__LINE__
1006
+			);
1007
+		}
1008
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 *        generates HTML for the Event Registrations List Table
1015
+	 *
1016
+	 * @access protected
1017
+	 * @return void
1018
+	 * @throws \EE_Error
1019
+	 */
1020
+	protected function _event_registrations_list_table()
1021
+	{
1022
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1023
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1024
+			? $this->get_action_link_or_button(
1025
+				'new_registration',
1026
+				'add-registrant',
1027
+				array('event_id' => $this->_req_data['event_id']),
1028
+				'add-new-h2',
1029
+				'',
1030
+				false
1031
+			)
1032
+			: '';
1033
+		$legend_items = array(
1034
+			'star-icon'        => array(
1035
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
+				'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1037
+			),
1038
+			'checkin'          => array(
1039
+				'class' => 'ee-icon ee-icon-check-in',
1040
+				'desc'  => __('This Registrant has been Checked In', 'event_espresso'),
1041
+			),
1042
+			'checkout'         => array(
1043
+				'class' => 'ee-icon ee-icon-check-out',
1044
+				'desc'  => __('This Registrant has been Checked Out', 'event_espresso'),
1045
+			),
1046
+			'nocheckinrecord'  => array(
1047
+				'class' => 'dashicons dashicons-no',
1048
+				'desc'  => __('No Check-in Record has been Created for this Registrant', 'event_espresso'),
1049
+			),
1050
+			'view_details'     => array(
1051
+				'class' => 'dashicons dashicons-search',
1052
+				'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053
+			),
1054
+			'approved_status'  => array(
1055
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1056
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057
+			),
1058
+			'cancelled_status' => array(
1059
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1060
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061
+			),
1062
+			'declined_status'  => array(
1063
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1064
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065
+			),
1066
+			'not_approved'     => array(
1067
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1068
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069
+			),
1070
+			'pending_status'   => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1072
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073
+			),
1074
+			'wait_list'        => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1076
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077
+			),
1078
+		);
1079
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081
+		$this->_template_args['before_list_table'] = ! empty($event_id)
1082
+			? '<h2>' . sprintf(
1083
+				__('Viewing Registrations for Event: %s', 'event_espresso'),
1084
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
+			) . '</h2>'
1086
+			: '';
1087
+		//need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088
+		/** @var EE_Event $event */
1089
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1090
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1091
+		$datetime = null;
1092
+		if ($event instanceof EE_Event) {
1093
+			$datetimes_on_event = $event->datetimes();
1094
+			if (count($datetimes_on_event) === 1) {
1095
+				$datetime = reset($datetimes_on_event);
1096
+			}
1097
+		}
1098
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1099
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1100
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1101
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103
+			$this->_template_args['before_list_table'] .= $datetime->name();
1104
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1105
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1106
+		}
1107
+		//if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1108
+		//represents
1109
+		if ( ! $datetime instanceof EE_Datetime) {
1110
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1111
+														  . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1112
+					'event_espresso')
1113
+														  . '</p>';
1114
+		}
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+	/**
1119
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1120
+	 * conditions)
1121
+	 *
1122
+	 * @return void ends the request by a redirect or download
1123
+	 */
1124
+	public function _registrations_checkin_report()
1125
+	{
1126
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1127
+	}
1128
+
1129
+	/**
1130
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1131
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1132
+	 *
1133
+	 * @param array     $request
1134
+	 * @param int  $per_page
1135
+	 * @param bool $count
1136
+	 * @return array
1137
+	 */
1138
+	protected function _get_checkin_query_params_from_request(
1139
+		$request,
1140
+		$per_page = 10,
1141
+		$count = false
1142
+	) {
1143
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1144
+		//unlike the regular registrations list table,
1145
+		$status_ids_array = apply_filters(
1146
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1147
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1148
+		);
1149
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1150
+		return $query_params;
1151
+	}
1152
+
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * Gets registrations for an event
1158
+	 *
1159
+	 * @param int    $per_page
1160
+	 * @param bool   $count whether to return count or data.
1161
+	 * @param bool   $trash
1162
+	 * @param string $orderby
1163
+	 * @return EE_Registration[]|int
1164
+	 * @throws \EE_Error
1165
+	 */
1166
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1167
+	{
1168
+		//normalize some request params that get setup by the parent `get_registrations` method.
1169
+		$request = $this->_req_data;
1170
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
+		$request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
+		if($trash){
1173
+			$request['status'] = 'trash';
1174
+		}
1175
+		$query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1176
+		/**
1177
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1179
+		 * @see EEM_Base::get_all()
1180
+		 */
1181
+		$query_params['group_by'] = '';
1182
+
1183
+		return $count
1184
+			? EEM_Registration::instance()->count($query_params)
1185
+			/** @type EE_Registration[] */
1186
+			: EEM_Registration::instance()->get_all($query_params);
1187
+	}
1188 1188
 
1189 1189
 } //end class Registrations Admin Page
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
     {
36 36
         parent::__construct($routing);
37 37
         if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
38
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
39
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
40
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
41 41
         }
42 42
     }
43 43
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -178,14 +178,14 @@  discard block
 block discarded – undo
178 178
             //enqueue newsletter js
179 179
             wp_enqueue_script(
180 180
                 'ee-newsletter-trigger',
181
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
181
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
182 182
                 array('ee-dialog'),
183 183
                 EVENT_ESPRESSO_VERSION,
184 184
                 true
185 185
             );
186 186
             wp_enqueue_style(
187 187
                 'ee-newsletter-trigger-css',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
188
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
189 189
                 array(),
190 190
                 EVENT_ESPRESSO_VERSION
191 191
             );
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     {
205 205
         wp_register_script(
206 206
             'ee-reg-reports-js',
207
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
207
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
208 208
             array('google-charts'),
209 209
             EVENT_ESPRESSO_VERSION,
210 210
             true
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
             $codes[$field] = implode(', ', array_keys($shortcode_array));
410 410
         }
411 411
         $shortcodes = $codes;
412
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
412
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
413 413
         $form_template_args = array(
414 414
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415 415
             'form_route'        => 'newsletter_selected_send',
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
      */
571 571
     protected function _registration_reports()
572 572
     {
573
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
573
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
574 574
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
575 575
             $template_path,
576 576
             $this->_reports_template_data,
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
     {
593 593
         $report_ID = 'reg-admin-registrations-per-day-report-dv';
594 594
         $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
-        $results = (array)$results;
595
+        $results = (array) $results;
596 596
         $regs = array();
597 597
         $subtitle = '';
598 598
         if ($results) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                 $report_column_values = array();
603 603
                 foreach ($result as $property_name => $property_value) {
604 604
                     $property_value = $property_name === 'Registration_REG_date' ? $property_value
605
-                        : (int)$property_value;
605
+                        : (int) $property_value;
606 606
                     $report_column_values[] = $property_value;
607 607
                     if ($tracker === 0) {
608 608
                         if ($property_name === 'Registration_REG_date') {
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
             array_unshift($regs, $column_titles);
620 620
             //setup the date range.
621 621
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
622
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
623 623
             $ending_date = new DateTime("now", $DateTimeZone);
624 624
             $subtitle = sprintf(
625 625
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                     '%sThere are currently no registration records in the last month for this report.%s',
640 640
                     'event_espresso'
641 641
                 ),
642
-                '<h2>' . $report_title . '</h2><p>',
642
+                '<h2>'.$report_title.'</h2><p>',
643 643
                 '</p>'
644 644
             ),
645 645
         );
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
     {
660 660
         $report_ID = 'reg-admin-registrations-per-event-report-dv';
661 661
         $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
-        $results = (array)$results;
662
+        $results = (array) $results;
663 663
         $regs = array();
664 664
         $subtitle = '';
665 665
         if ($results) {
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
                         $property_value,
673 673
                         4,
674 674
                         '...'
675
-                    ) : (int)$property_value;
675
+                    ) : (int) $property_value;
676 676
                     $report_column_values[] = $property_value;
677 677
                     if ($tracker === 0) {
678 678
                         if ($property_name === 'Registration_Event') {
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
             array_unshift($regs, $column_titles);
690 690
             //setup the date range.
691 691
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
692
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
693 693
             $ending_date = new DateTime("now", $DateTimeZone);
694 694
             $subtitle = sprintf(
695 695
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
                     '%sThere are currently no registration records in the last month for this report.%s',
710 710
                     'event_espresso'
711 711
                 ),
712
-                '<h2>' . $report_title . '</h2><p>',
712
+                '<h2>'.$report_title.'</h2><p>',
713 713
                 '</p>'
714 714
             ),
715 715
         );
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
         if ($datetime instanceof EE_Datetime) {
758 758
             $datetime_label = $datetime->get_dtt_display_name(true);
759 759
             $datetime_label .= ! empty($datetime_label)
760
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
760
+                ? ' ('.$datetime->get_dtt_display_name().')'
761 761
                 : $datetime->get_dtt_display_name();
762 762
         }
763 763
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
             )
772 772
             : '';
773 773
         $datetime_link = ! empty($datetime_link)
774
-            ? '<a href="' . $datetime_link . '">'
774
+            ? '<a href="'.$datetime_link.'">'
775 775
               . '<span id="checkin-dtt">'
776 776
               . $datetime_label
777 777
               . '</span></a>'
@@ -783,8 +783,8 @@  discard block
 block discarded – undo
783 783
             ? $attendee->get_admin_details_link()
784 784
             : '';
785 785
         $attendee_link = ! empty($attendee_link)
786
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
787
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
786
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
787
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
788 788
               . '<span id="checkin-attendee-name">'
789 789
               . $attendee_name
790 790
               . '</span></a>'
@@ -793,25 +793,25 @@  discard block
 block discarded – undo
793 793
             ? $registration->event()->get_admin_details_link()
794 794
             : '';
795 795
         $event_link = ! empty($event_link)
796
-            ? '<a href="' . $event_link . '"'
797
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
796
+            ? '<a href="'.$event_link.'"'
797
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
798 798
               . '<span id="checkin-event-name">'
799 799
               . $registration->event_name()
800 800
               . '</span>'
801 801
               . '</a>'
802 802
             : '';
803 803
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
-            ? '<h2>' . sprintf(
804
+            ? '<h2>'.sprintf(
805 805
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806 806
                 $attendee_link,
807 807
                 $datetime_link,
808 808
                 $event_link
809
-            ) . '</h2>'
809
+            ).'</h2>'
810 810
             : '';
811 811
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
812
+            ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : '';
813 813
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
814
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
815 815
         $this->display_admin_list_table_page_with_no_sidebar();
816 816
     }
817 817
 
@@ -1052,37 +1052,37 @@  discard block
 block discarded – undo
1052 1052
                 'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053 1053
             ),
1054 1054
             'approved_status'  => array(
1055
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1055
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1056 1056
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057 1057
             ),
1058 1058
             'cancelled_status' => array(
1059
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1059
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1060 1060
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061 1061
             ),
1062 1062
             'declined_status'  => array(
1063
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1063
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1064 1064
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065 1065
             ),
1066 1066
             'not_approved'     => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1067
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1068 1068
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069 1069
             ),
1070 1070
             'pending_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1071
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1072 1072
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073 1073
             ),
1074 1074
             'wait_list'        => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1075
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1076 1076
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077 1077
             ),
1078 1078
         );
1079 1079
         $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080 1080
         $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081 1081
         $this->_template_args['before_list_table'] = ! empty($event_id)
1082
-            ? '<h2>' . sprintf(
1082
+            ? '<h2>'.sprintf(
1083 1083
                 __('Viewing Registrations for Event: %s', 'event_espresso'),
1084 1084
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
-            ) . '</h2>'
1085
+            ).'</h2>'
1086 1086
             : '';
1087 1087
         //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088 1088
         /** @var EE_Event $event */
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102 1102
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103 1103
             $this->_template_args['before_list_table'] .= $datetime->name();
1104
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1104
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1105 1105
             $this->_template_args['before_list_table'] .= '</span></h2>';
1106 1106
         }
1107 1107
         //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
@@ -1168,11 +1168,11 @@  discard block
 block discarded – undo
1168 1168
         //normalize some request params that get setup by the parent `get_registrations` method.
1169 1169
         $request = $this->_req_data;
1170 1170
         $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
-        if($trash){
1171
+        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
+        if ($trash) {
1173 1173
             $request['status'] = 'trash';
1174 1174
         }
1175
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1175
+        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1176 1176
         /**
1177 1177
          * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178 1178
          * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
Please login to merge, or discard this patch.
core/EE_Request_Handler.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 
277 277
     /**
278
-     * @param $string
278
+     * @param string $string
279 279
      * @return void
280 280
      */
281 281
     public function add_output($string)
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
 
329 329
     /**
330
-     * @return    mixed
330
+     * @return    boolean
331 331
      */
332 332
     public function is_espresso_page()
333 333
     {
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
     /**
390 390
      * remove param
391 391
      *
392
-     * @param $key
392
+     * @param string $key
393 393
      * @return    void
394 394
      */
395 395
     public function un_set($key)
Please login to merge, or discard this patch.
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -13,389 +13,389 @@
 block discarded – undo
13 13
 final class EE_Request_Handler implements InterminableInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @var EE_Request $request
18
-     */
19
-    private $request;
20
-
21
-    /**
22
-     * @var array $_notice
23
-     */
24
-    private $_notice = array();
25
-
26
-    /**
27
-     * rendered output to be returned to WP
28
-     *
29
-     * @var string $_output
30
-     */
31
-    private $_output = '';
32
-
33
-    /**
34
-     * whether current request is via AJAX
35
-     *
36
-     * @var boolean $ajax
37
-     */
38
-    public $ajax = false;
39
-
40
-    /**
41
-     * whether current request is via AJAX from the frontend of the site
42
-     *
43
-     * @var boolean $front_ajax
44
-     */
45
-    public $front_ajax = false;
46
-
47
-
48
-
49
-    /**
50
-     * @param  EE_Request $request
51
-     */
52
-    public function __construct(EE_Request $request)
53
-    {
54
-        $this->request = $request;
55
-        $this->ajax = $this->request->ajax;
56
-        $this->front_ajax = $this->request->front_ajax;
57
-        do_action('AHEE__EE_Request_Handler__construct__complete');
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @param WP $wp
64
-     * @return void
65
-     * @throws EE_Error
66
-     * @throws ReflectionException
67
-     */
68
-    public function parse_request($wp = null)
69
-    {
70
-        //if somebody forgot to provide us with WP, that's ok because its global
71
-        if (! $wp instanceof WP) {
72
-            global $wp;
73
-        }
74
-        $this->set_request_vars($wp);
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @param WP $wp
81
-     * @return void
82
-     * @throws EE_Error
83
-     * @throws ReflectionException
84
-     */
85
-    public function set_request_vars($wp = null)
86
-    {
87
-        if (! is_admin()) {
88
-            // set request post_id
89
-            $this->request->set('post_id', $this->get_post_id_from_request($wp));
90
-            // set request post name
91
-            $this->request->set('post_name', $this->get_post_name_from_request($wp));
92
-            // set request post_type
93
-            $this->request->set('post_type', $this->get_post_type_from_request($wp));
94
-            // true or false ? is this page being used by EE ?
95
-            $this->set_espresso_page();
96
-        }
97
-    }
98
-
99
-
100
-
101
-    /**
102
-     * @param WP $wp
103
-     * @return int
104
-     */
105
-    public function get_post_id_from_request($wp = null)
106
-    {
107
-        if (! $wp instanceof WP) {
108
-            global $wp;
109
-        }
110
-        $post_id = null;
111
-        if (isset($wp->query_vars['p'])) {
112
-            $post_id = $wp->query_vars['p'];
113
-        }
114
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
115
-            $post_id = $wp->query_vars['page_id'];
116
-        }
117
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118
-            $post_id = basename($wp->request);
119
-        }
120
-        return $post_id;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @param WP $wp
127
-     * @return string
128
-     */
129
-    public function get_post_name_from_request($wp = null)
130
-    {
131
-        if (! $wp instanceof WP) {
132
-            global $wp;
133
-        }
134
-        $post_name = null;
135
-        if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136
-            $post_name = $wp->query_vars['name'];
137
-        }
138
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139
-            $post_name = $wp->query_vars['pagename'];
140
-        }
141
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
142
-            $possible_post_name = basename($wp->request);
143
-            if (! is_numeric($possible_post_name)) {
144
-                /** @type WPDB $wpdb */
145
-                global $wpdb;
146
-                $SQL =
147
-                    "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
148
-                $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
149
-                if ($possible_post_name) {
150
-                    $post_name = $possible_post_name;
151
-                }
152
-            }
153
-        }
154
-        if (! $post_name && $this->get('post_id')) {
155
-            /** @type WPDB $wpdb */
156
-            global $wpdb;
157
-            $SQL =
158
-                "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
159
-            $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
160
-            if ($possible_post_name) {
161
-                $post_name = $possible_post_name;
162
-            }
163
-        }
164
-        return $post_name;
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * @param WP $wp
171
-     * @return mixed
172
-     */
173
-    public function get_post_type_from_request($wp = null)
174
-    {
175
-        if (! $wp instanceof WP) {
176
-            global $wp;
177
-        }
178
-        return isset($wp->query_vars['post_type'])
179
-            ? $wp->query_vars['post_type']
180
-            : null;
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * Just a helper method for getting the url for the displayed page.
187
-     *
188
-     * @param  WP $wp
189
-     * @return string
190
-     */
191
-    public function get_current_page_permalink($wp = null)
192
-    {
193
-        $post_id = $this->get_post_id_from_request($wp);
194
-        if ($post_id) {
195
-            $current_page_permalink = get_permalink($post_id);
196
-        } else {
197
-            if (! $wp instanceof WP) {
198
-                global $wp;
199
-            }
200
-            if ($wp->request) {
201
-                $current_page_permalink = site_url($wp->request);
202
-            } else {
203
-                $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
204
-            }
205
-        }
206
-        return $current_page_permalink;
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * @return bool
213
-     * @throws EE_Error
214
-     * @throws ReflectionException
215
-     */
216
-    public function test_for_espresso_page()
217
-    {
218
-        global $wp;
219
-        /** @type EE_CPT_Strategy $EE_CPT_Strategy */
220
-        $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
221
-        $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
222
-        if (is_array($espresso_CPT_taxonomies)) {
223
-            foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
224
-                if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
225
-                    return true;
226
-                }
227
-            }
228
-        }
229
-        // load espresso CPT endpoints
230
-        $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231
-        $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
-        $post_types = (array)$this->get('post_type');
233
-        foreach ($post_types as $post_type) {
234
-            // was a post name passed ?
235
-            if (isset($post_type_CPT_endpoints[$post_type])) {
236
-                // kk we know this is an espresso page, but is it a specific post ?
237
-                if (! $this->get('post_name')) {
238
-                    // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239
-                    $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240
-                        ? $post_type_CPT_endpoints[$this->get('post_type')]
241
-                        : '';
242
-                    // if the post type matches on of our then set the endpoint
243
-                    if ($post_name) {
244
-                        $this->set('post_name', $post_name);
245
-                    }
246
-                }
247
-                return true;
248
-            }
249
-        }
250
-        return false;
251
-    }
252
-    /**
253
-     * @param $key
254
-     * @param $value
255
-     * @return    void
256
-     */
257
-    public function set_notice($key, $value)
258
-    {
259
-        $this->_notice[$key] = $value;
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     * @param $key
266
-     * @return    mixed
267
-     */
268
-    public function get_notice($key)
269
-    {
270
-        return isset($this->_notice[$key])
271
-            ? $this->_notice[$key]
272
-            : null;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * @param $string
279
-     * @return void
280
-     */
281
-    public function add_output($string)
282
-    {
283
-        $this->_output .= $string;
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * @return string
290
-     */
291
-    public function get_output()
292
-    {
293
-        return $this->_output;
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @param $item
300
-     * @param $key
301
-     */
302
-    public function sanitize_text_field_for_array_walk(&$item, &$key)
303
-    {
304
-        $item = strpos($item, 'email') !== false
305
-            ? sanitize_email($item)
306
-            : sanitize_text_field($item);
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * @param null|bool $value
313
-     * @return void
314
-     * @throws EE_Error
315
-     * @throws ReflectionException
316
-     */
317
-    public function set_espresso_page($value = null)
318
-    {
319
-        $this->request->set(
320
-            'is_espresso_page',
321
-            ! empty($value)
322
-                ? $value
323
-                : $this->test_for_espresso_page()
324
-        );
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * @return    mixed
331
-     */
332
-    public function is_espresso_page()
333
-    {
334
-        return $this->request->is_set('is_espresso_page');
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * returns contents of $_REQUEST
341
-     *
342
-     * @return array
343
-     */
344
-    public function params()
345
-    {
346
-        return $this->request->params();
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * @param      $key
353
-     * @param      $value
354
-     * @param bool $override_ee
355
-     * @return    void
356
-     */
357
-    public function set($key, $value, $override_ee = false)
358
-    {
359
-        $this->request->set($key, $value, $override_ee);
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * @param      $key
366
-     * @param null $default
367
-     * @return    mixed
368
-     */
369
-    public function get($key, $default = null)
370
-    {
371
-        return $this->request->get($key, $default);
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * check if param exists
378
-     *
379
-     * @param $key
380
-     * @return    boolean
381
-     */
382
-    public function is_set($key)
383
-    {
384
-        return $this->request->is_set($key);
385
-    }
386
-
387
-
388
-
389
-    /**
390
-     * remove param
391
-     *
392
-     * @param $key
393
-     * @return    void
394
-     */
395
-    public function un_set($key)
396
-    {
397
-        $this->request->un_set($key);
398
-    }
16
+	/**
17
+	 * @var EE_Request $request
18
+	 */
19
+	private $request;
20
+
21
+	/**
22
+	 * @var array $_notice
23
+	 */
24
+	private $_notice = array();
25
+
26
+	/**
27
+	 * rendered output to be returned to WP
28
+	 *
29
+	 * @var string $_output
30
+	 */
31
+	private $_output = '';
32
+
33
+	/**
34
+	 * whether current request is via AJAX
35
+	 *
36
+	 * @var boolean $ajax
37
+	 */
38
+	public $ajax = false;
39
+
40
+	/**
41
+	 * whether current request is via AJAX from the frontend of the site
42
+	 *
43
+	 * @var boolean $front_ajax
44
+	 */
45
+	public $front_ajax = false;
46
+
47
+
48
+
49
+	/**
50
+	 * @param  EE_Request $request
51
+	 */
52
+	public function __construct(EE_Request $request)
53
+	{
54
+		$this->request = $request;
55
+		$this->ajax = $this->request->ajax;
56
+		$this->front_ajax = $this->request->front_ajax;
57
+		do_action('AHEE__EE_Request_Handler__construct__complete');
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @param WP $wp
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 * @throws ReflectionException
67
+	 */
68
+	public function parse_request($wp = null)
69
+	{
70
+		//if somebody forgot to provide us with WP, that's ok because its global
71
+		if (! $wp instanceof WP) {
72
+			global $wp;
73
+		}
74
+		$this->set_request_vars($wp);
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @param WP $wp
81
+	 * @return void
82
+	 * @throws EE_Error
83
+	 * @throws ReflectionException
84
+	 */
85
+	public function set_request_vars($wp = null)
86
+	{
87
+		if (! is_admin()) {
88
+			// set request post_id
89
+			$this->request->set('post_id', $this->get_post_id_from_request($wp));
90
+			// set request post name
91
+			$this->request->set('post_name', $this->get_post_name_from_request($wp));
92
+			// set request post_type
93
+			$this->request->set('post_type', $this->get_post_type_from_request($wp));
94
+			// true or false ? is this page being used by EE ?
95
+			$this->set_espresso_page();
96
+		}
97
+	}
98
+
99
+
100
+
101
+	/**
102
+	 * @param WP $wp
103
+	 * @return int
104
+	 */
105
+	public function get_post_id_from_request($wp = null)
106
+	{
107
+		if (! $wp instanceof WP) {
108
+			global $wp;
109
+		}
110
+		$post_id = null;
111
+		if (isset($wp->query_vars['p'])) {
112
+			$post_id = $wp->query_vars['p'];
113
+		}
114
+		if (! $post_id && isset($wp->query_vars['page_id'])) {
115
+			$post_id = $wp->query_vars['page_id'];
116
+		}
117
+		if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118
+			$post_id = basename($wp->request);
119
+		}
120
+		return $post_id;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @param WP $wp
127
+	 * @return string
128
+	 */
129
+	public function get_post_name_from_request($wp = null)
130
+	{
131
+		if (! $wp instanceof WP) {
132
+			global $wp;
133
+		}
134
+		$post_name = null;
135
+		if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136
+			$post_name = $wp->query_vars['name'];
137
+		}
138
+		if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139
+			$post_name = $wp->query_vars['pagename'];
140
+		}
141
+		if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
142
+			$possible_post_name = basename($wp->request);
143
+			if (! is_numeric($possible_post_name)) {
144
+				/** @type WPDB $wpdb */
145
+				global $wpdb;
146
+				$SQL =
147
+					"SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
148
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
149
+				if ($possible_post_name) {
150
+					$post_name = $possible_post_name;
151
+				}
152
+			}
153
+		}
154
+		if (! $post_name && $this->get('post_id')) {
155
+			/** @type WPDB $wpdb */
156
+			global $wpdb;
157
+			$SQL =
158
+				"SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
159
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
160
+			if ($possible_post_name) {
161
+				$post_name = $possible_post_name;
162
+			}
163
+		}
164
+		return $post_name;
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * @param WP $wp
171
+	 * @return mixed
172
+	 */
173
+	public function get_post_type_from_request($wp = null)
174
+	{
175
+		if (! $wp instanceof WP) {
176
+			global $wp;
177
+		}
178
+		return isset($wp->query_vars['post_type'])
179
+			? $wp->query_vars['post_type']
180
+			: null;
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Just a helper method for getting the url for the displayed page.
187
+	 *
188
+	 * @param  WP $wp
189
+	 * @return string
190
+	 */
191
+	public function get_current_page_permalink($wp = null)
192
+	{
193
+		$post_id = $this->get_post_id_from_request($wp);
194
+		if ($post_id) {
195
+			$current_page_permalink = get_permalink($post_id);
196
+		} else {
197
+			if (! $wp instanceof WP) {
198
+				global $wp;
199
+			}
200
+			if ($wp->request) {
201
+				$current_page_permalink = site_url($wp->request);
202
+			} else {
203
+				$current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
204
+			}
205
+		}
206
+		return $current_page_permalink;
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * @return bool
213
+	 * @throws EE_Error
214
+	 * @throws ReflectionException
215
+	 */
216
+	public function test_for_espresso_page()
217
+	{
218
+		global $wp;
219
+		/** @type EE_CPT_Strategy $EE_CPT_Strategy */
220
+		$EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
221
+		$espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
222
+		if (is_array($espresso_CPT_taxonomies)) {
223
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
224
+				if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
225
+					return true;
226
+				}
227
+			}
228
+		}
229
+		// load espresso CPT endpoints
230
+		$espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
+		$post_types = (array)$this->get('post_type');
233
+		foreach ($post_types as $post_type) {
234
+			// was a post name passed ?
235
+			if (isset($post_type_CPT_endpoints[$post_type])) {
236
+				// kk we know this is an espresso page, but is it a specific post ?
237
+				if (! $this->get('post_name')) {
238
+					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239
+					$post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240
+						? $post_type_CPT_endpoints[$this->get('post_type')]
241
+						: '';
242
+					// if the post type matches on of our then set the endpoint
243
+					if ($post_name) {
244
+						$this->set('post_name', $post_name);
245
+					}
246
+				}
247
+				return true;
248
+			}
249
+		}
250
+		return false;
251
+	}
252
+	/**
253
+	 * @param $key
254
+	 * @param $value
255
+	 * @return    void
256
+	 */
257
+	public function set_notice($key, $value)
258
+	{
259
+		$this->_notice[$key] = $value;
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 * @param $key
266
+	 * @return    mixed
267
+	 */
268
+	public function get_notice($key)
269
+	{
270
+		return isset($this->_notice[$key])
271
+			? $this->_notice[$key]
272
+			: null;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * @param $string
279
+	 * @return void
280
+	 */
281
+	public function add_output($string)
282
+	{
283
+		$this->_output .= $string;
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * @return string
290
+	 */
291
+	public function get_output()
292
+	{
293
+		return $this->_output;
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @param $item
300
+	 * @param $key
301
+	 */
302
+	public function sanitize_text_field_for_array_walk(&$item, &$key)
303
+	{
304
+		$item = strpos($item, 'email') !== false
305
+			? sanitize_email($item)
306
+			: sanitize_text_field($item);
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * @param null|bool $value
313
+	 * @return void
314
+	 * @throws EE_Error
315
+	 * @throws ReflectionException
316
+	 */
317
+	public function set_espresso_page($value = null)
318
+	{
319
+		$this->request->set(
320
+			'is_espresso_page',
321
+			! empty($value)
322
+				? $value
323
+				: $this->test_for_espresso_page()
324
+		);
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * @return    mixed
331
+	 */
332
+	public function is_espresso_page()
333
+	{
334
+		return $this->request->is_set('is_espresso_page');
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * returns contents of $_REQUEST
341
+	 *
342
+	 * @return array
343
+	 */
344
+	public function params()
345
+	{
346
+		return $this->request->params();
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * @param      $key
353
+	 * @param      $value
354
+	 * @param bool $override_ee
355
+	 * @return    void
356
+	 */
357
+	public function set($key, $value, $override_ee = false)
358
+	{
359
+		$this->request->set($key, $value, $override_ee);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * @param      $key
366
+	 * @param null $default
367
+	 * @return    mixed
368
+	 */
369
+	public function get($key, $default = null)
370
+	{
371
+		return $this->request->get($key, $default);
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * check if param exists
378
+	 *
379
+	 * @param $key
380
+	 * @return    boolean
381
+	 */
382
+	public function is_set($key)
383
+	{
384
+		return $this->request->is_set($key);
385
+	}
386
+
387
+
388
+
389
+	/**
390
+	 * remove param
391
+	 *
392
+	 * @param $key
393
+	 * @return    void
394
+	 */
395
+	public function un_set($key)
396
+	{
397
+		$this->request->un_set($key);
398
+	}
399 399
 
400 400
 
401 401
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public function parse_request($wp = null)
69 69
     {
70 70
         //if somebody forgot to provide us with WP, that's ok because its global
71
-        if (! $wp instanceof WP) {
71
+        if ( ! $wp instanceof WP) {
72 72
             global $wp;
73 73
         }
74 74
         $this->set_request_vars($wp);
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function set_request_vars($wp = null)
86 86
     {
87
-        if (! is_admin()) {
87
+        if ( ! is_admin()) {
88 88
             // set request post_id
89 89
             $this->request->set('post_id', $this->get_post_id_from_request($wp));
90 90
             // set request post name
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function get_post_id_from_request($wp = null)
106 106
     {
107
-        if (! $wp instanceof WP) {
107
+        if ( ! $wp instanceof WP) {
108 108
             global $wp;
109 109
         }
110 110
         $post_id = null;
111 111
         if (isset($wp->query_vars['p'])) {
112 112
             $post_id = $wp->query_vars['p'];
113 113
         }
114
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
114
+        if ( ! $post_id && isset($wp->query_vars['page_id'])) {
115 115
             $post_id = $wp->query_vars['page_id'];
116 116
         }
117
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
117
+        if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118 118
             $post_id = basename($wp->request);
119 119
         }
120 120
         return $post_id;
@@ -128,19 +128,19 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function get_post_name_from_request($wp = null)
130 130
     {
131
-        if (! $wp instanceof WP) {
131
+        if ( ! $wp instanceof WP) {
132 132
             global $wp;
133 133
         }
134 134
         $post_name = null;
135 135
         if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136 136
             $post_name = $wp->query_vars['name'];
137 137
         }
138
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
138
+        if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139 139
             $post_name = $wp->query_vars['pagename'];
140 140
         }
141
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
141
+        if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) {
142 142
             $possible_post_name = basename($wp->request);
143
-            if (! is_numeric($possible_post_name)) {
143
+            if ( ! is_numeric($possible_post_name)) {
144 144
                 /** @type WPDB $wpdb */
145 145
                 global $wpdb;
146 146
                 $SQL =
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                 }
152 152
             }
153 153
         }
154
-        if (! $post_name && $this->get('post_id')) {
154
+        if ( ! $post_name && $this->get('post_id')) {
155 155
             /** @type WPDB $wpdb */
156 156
             global $wpdb;
157 157
             $SQL =
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function get_post_type_from_request($wp = null)
174 174
     {
175
-        if (! $wp instanceof WP) {
175
+        if ( ! $wp instanceof WP) {
176 176
             global $wp;
177 177
         }
178 178
         return isset($wp->query_vars['post_type'])
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         if ($post_id) {
195 195
             $current_page_permalink = get_permalink($post_id);
196 196
         } else {
197
-            if (! $wp instanceof WP) {
197
+            if ( ! $wp instanceof WP) {
198 198
                 global $wp;
199 199
             }
200 200
             if ($wp->request) {
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
         // load espresso CPT endpoints
230 230
         $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231 231
         $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
-        $post_types = (array)$this->get('post_type');
232
+        $post_types = (array) $this->get('post_type');
233 233
         foreach ($post_types as $post_type) {
234 234
             // was a post name passed ?
235 235
             if (isset($post_type_CPT_endpoints[$post_type])) {
236 236
                 // kk we know this is an espresso page, but is it a specific post ?
237
-                if (! $this->get('post_name')) {
237
+                if ( ! $this->get('post_name')) {
238 238
                     // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239 239
                     $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240 240
                         ? $post_type_CPT_endpoints[$this->get('post_type')]
Please login to merge, or discard this patch.