Completed
Branch FET-Wait-List (8e9360)
by
unknown
103:16 queued 91:24
created
core/EE_Maintenance_Mode.core.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -17,362 +17,362 @@
 block discarded – undo
17 17
 class EE_Maintenance_Mode implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
22
-     * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
23
-     */
24
-    const level_0_not_in_maintenance = 0;
25
-
26
-    /**
27
-     * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
28
-     * but the admin backend should be running as normal. Maybe an admin can view the frontend though
29
-     */
30
-    const level_1_frontend_only_maintenance = 1;
31
-
32
-    /**
33
-     * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
34
-     * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
35
-     * migration scripts before taking the site out of maintenance mode
36
-     */
37
-    const level_2_complete_maintenance = 2;
38
-
39
-    /**
40
-     * the name of the option which stores the current level of maintenance mode
41
-     */
42
-    const option_name_maintenance_mode = 'ee_maintenance_mode';
43
-
44
-
45
-    /**
46
-     * @var EE_Maintenance_Mode $_instance
47
-     */
48
-    private static $_instance;
49
-
50
-    /**
51
-     * @var EE_Registry $EE
52
-     */
53
-    protected $EE;
54
-
55
-
56
-
57
-    /**
58
-     * @singleton method used to instantiate class object
59
-     * @return EE_Maintenance_Mode
60
-     */
61
-    public static function instance()
62
-    {
63
-        // check if class object is instantiated
64
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
65
-            self::$_instance = new self();
66
-        }
67
-        return self::$_instance;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
74
-     *
75
-     * @return EE_Maintenance_Mode
76
-     */
77
-    public static function reset()
78
-    {
79
-        self::instance()->set_maintenance_mode_if_db_old();
80
-        return self::instance();
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     *private constructor to prevent direct creation
87
-     */
88
-    private function __construct()
89
-    {
90
-        // if M-Mode level 2 is engaged, we still need basic assets loaded
91
-        add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
92
-        // shut 'er down down for maintenance ?
93
-        add_filter('the_content', array($this, 'the_content'), 2);
94
-        // add powered by EE msg
95
-        add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * retrieves the maintenance mode option value from the db
102
-     *
103
-     * @return int
104
-     */
105
-    public function real_level()
106
-    {
107
-        return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Returns whether or not the models reportedly are able to run queries or not
114
-     * (ie, if the system thinks their tables are present and up-to-date).
115
-     *
116
-     * @return boolean
117
-     */
118
-    public function models_can_query()
119
-    {
120
-        return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * Determines whether or not we're in maintenance mode and what level. However, while the site
127
-     * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
128
-     * to them as if teh site isn't in maintenance mode.
129
-     * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
130
-     * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
131
-     * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
132
-     *
133
-     * @return int
134
-     */
135
-    public function level()
136
-    {
137
-        $maintenance_mode_level = $this->real_level();
138
-        // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
139
-        if (
140
-            $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
141
-            && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
142
-            && current_user_can('administrator') // when the user is an admin
143
-        ) {
144
-            $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
145
-        }
146
-        return $maintenance_mode_level;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * Determines if we need to put EE in maintenance mode because the database needs updating
153
-     *
154
-     * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
155
-     */
156
-    public function set_maintenance_mode_if_db_old()
157
-    {
158
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
159
-        if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
160
-            update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
161
-            return true;
162
-        }
163
-        if ($this->level() === self::level_2_complete_maintenance) {
164
-            //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
165
-            //then we shouldn't be in mm2. (Maybe an addon got deactivated?)
166
-            update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
167
-            return false;
168
-        }
169
-        return false;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Updates the maintenance level on the site
176
-     *
177
-     * @param int $level
178
-     * @return void
179
-     */
180
-    public function set_maintenance_level($level)
181
-    {
182
-        do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
183
-        update_option(self::option_name_maintenance_mode, (int)$level);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * returns TRUE if M-Mode is engaged and the current request is not for the admin
190
-     *
191
-     * @return    string
192
-     */
193
-    public static function disable_frontend_for_maintenance()
194
-    {
195
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @return void
202
-     */
203
-    public function load_assets_required_for_m_mode()
204
-    {
205
-        if (
206
-            $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
207
-            && ! wp_script_is('espresso_core')
208
-        ) {
209
-            wp_register_style(
210
-                'espresso_default',
211
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
212
-                array('dashicons'),
213
-                EVENT_ESPRESSO_VERSION
214
-            );
215
-            wp_enqueue_style('espresso_default');
216
-            wp_register_script(
217
-                'espresso_core',
218
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
219
-                array('jquery'),
220
-                EVENT_ESPRESSO_VERSION,
221
-                true
222
-            );
223
-            wp_enqueue_script('espresso_core');
224
-        }
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * replacement EE CPT template that displays message notifying site visitors
231
-     * that EE has been temporarily placed into maintenance mode
232
-     * does NOT get called on non-EE-CPT requests
233
-     *
234
-     * @return    string
235
-     */
236
-    public static function template_include()
237
-    {
238
-        // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
239
-        return get_template_directory() . '/index.php';
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * displays message notifying site visitors that EE has been temporarily
246
-     * placed into maintenance mode when post_type != EE CPT
247
-     *
248
-     * @param string $the_content
249
-     * @return string
250
-     */
251
-    public function the_content($the_content)
252
-    {
253
-        // check if M-mode is engaged and for EE shortcode
254
-        if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
255
-            // this can eventually be moved to a template, or edited via admin. But for now...
256
-            $the_content = sprintf(
257
-                esc_html__(
258
-                    '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
259
-                    'event_espresso'
260
-                ),
261
-                '<h3>',
262
-                '</h3><p>',
263
-                '</p>'
264
-            );
265
-        }
266
-        return $the_content;
267
-    }
20
+	/**
21
+	 * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
22
+	 * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
23
+	 */
24
+	const level_0_not_in_maintenance = 0;
25
+
26
+	/**
27
+	 * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
28
+	 * but the admin backend should be running as normal. Maybe an admin can view the frontend though
29
+	 */
30
+	const level_1_frontend_only_maintenance = 1;
31
+
32
+	/**
33
+	 * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
34
+	 * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
35
+	 * migration scripts before taking the site out of maintenance mode
36
+	 */
37
+	const level_2_complete_maintenance = 2;
38
+
39
+	/**
40
+	 * the name of the option which stores the current level of maintenance mode
41
+	 */
42
+	const option_name_maintenance_mode = 'ee_maintenance_mode';
43
+
44
+
45
+	/**
46
+	 * @var EE_Maintenance_Mode $_instance
47
+	 */
48
+	private static $_instance;
49
+
50
+	/**
51
+	 * @var EE_Registry $EE
52
+	 */
53
+	protected $EE;
54
+
55
+
56
+
57
+	/**
58
+	 * @singleton method used to instantiate class object
59
+	 * @return EE_Maintenance_Mode
60
+	 */
61
+	public static function instance()
62
+	{
63
+		// check if class object is instantiated
64
+		if (! self::$_instance instanceof EE_Maintenance_Mode) {
65
+			self::$_instance = new self();
66
+		}
67
+		return self::$_instance;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
74
+	 *
75
+	 * @return EE_Maintenance_Mode
76
+	 */
77
+	public static function reset()
78
+	{
79
+		self::instance()->set_maintenance_mode_if_db_old();
80
+		return self::instance();
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 *private constructor to prevent direct creation
87
+	 */
88
+	private function __construct()
89
+	{
90
+		// if M-Mode level 2 is engaged, we still need basic assets loaded
91
+		add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
92
+		// shut 'er down down for maintenance ?
93
+		add_filter('the_content', array($this, 'the_content'), 2);
94
+		// add powered by EE msg
95
+		add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * retrieves the maintenance mode option value from the db
102
+	 *
103
+	 * @return int
104
+	 */
105
+	public function real_level()
106
+	{
107
+		return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Returns whether or not the models reportedly are able to run queries or not
114
+	 * (ie, if the system thinks their tables are present and up-to-date).
115
+	 *
116
+	 * @return boolean
117
+	 */
118
+	public function models_can_query()
119
+	{
120
+		return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * Determines whether or not we're in maintenance mode and what level. However, while the site
127
+	 * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
128
+	 * to them as if teh site isn't in maintenance mode.
129
+	 * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
130
+	 * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
131
+	 * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
132
+	 *
133
+	 * @return int
134
+	 */
135
+	public function level()
136
+	{
137
+		$maintenance_mode_level = $this->real_level();
138
+		// if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
139
+		if (
140
+			$maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
141
+			&& ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
142
+			&& current_user_can('administrator') // when the user is an admin
143
+		) {
144
+			$maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
145
+		}
146
+		return $maintenance_mode_level;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * Determines if we need to put EE in maintenance mode because the database needs updating
153
+	 *
154
+	 * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
155
+	 */
156
+	public function set_maintenance_mode_if_db_old()
157
+	{
158
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
159
+		if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
160
+			update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
161
+			return true;
162
+		}
163
+		if ($this->level() === self::level_2_complete_maintenance) {
164
+			//we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
165
+			//then we shouldn't be in mm2. (Maybe an addon got deactivated?)
166
+			update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
167
+			return false;
168
+		}
169
+		return false;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Updates the maintenance level on the site
176
+	 *
177
+	 * @param int $level
178
+	 * @return void
179
+	 */
180
+	public function set_maintenance_level($level)
181
+	{
182
+		do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
183
+		update_option(self::option_name_maintenance_mode, (int)$level);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * returns TRUE if M-Mode is engaged and the current request is not for the admin
190
+	 *
191
+	 * @return    string
192
+	 */
193
+	public static function disable_frontend_for_maintenance()
194
+	{
195
+		return (! is_admin() && EE_Maintenance_Mode::instance()->level());
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @return void
202
+	 */
203
+	public function load_assets_required_for_m_mode()
204
+	{
205
+		if (
206
+			$this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
207
+			&& ! wp_script_is('espresso_core')
208
+		) {
209
+			wp_register_style(
210
+				'espresso_default',
211
+				EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
212
+				array('dashicons'),
213
+				EVENT_ESPRESSO_VERSION
214
+			);
215
+			wp_enqueue_style('espresso_default');
216
+			wp_register_script(
217
+				'espresso_core',
218
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
219
+				array('jquery'),
220
+				EVENT_ESPRESSO_VERSION,
221
+				true
222
+			);
223
+			wp_enqueue_script('espresso_core');
224
+		}
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * replacement EE CPT template that displays message notifying site visitors
231
+	 * that EE has been temporarily placed into maintenance mode
232
+	 * does NOT get called on non-EE-CPT requests
233
+	 *
234
+	 * @return    string
235
+	 */
236
+	public static function template_include()
237
+	{
238
+		// shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
239
+		return get_template_directory() . '/index.php';
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * displays message notifying site visitors that EE has been temporarily
246
+	 * placed into maintenance mode when post_type != EE CPT
247
+	 *
248
+	 * @param string $the_content
249
+	 * @return string
250
+	 */
251
+	public function the_content($the_content)
252
+	{
253
+		// check if M-mode is engaged and for EE shortcode
254
+		if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
255
+			// this can eventually be moved to a template, or edited via admin. But for now...
256
+			$the_content = sprintf(
257
+				esc_html__(
258
+					'%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
259
+					'event_espresso'
260
+				),
261
+				'<h3>',
262
+				'</h3><p>',
263
+				'</p>'
264
+			);
265
+		}
266
+		return $the_content;
267
+	}
268 268
 
269 269
 
270 270
 
271
-    /**
272
-     * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
273
-     */
274
-    public function display_maintenance_mode_notice()
275
-    {
276
-        // check if M-mode is engaged and for EE shortcode
277
-        if (
278
-            ! (defined('DOING_AJAX') && DOING_AJAX)
279
-            && $this->real_level()
280
-            && ! is_admin()
281
-            && current_user_can('administrator')
282
-            && EE_Registry::instance()->REQ->is_espresso_page()
283
-        ) {
284
-            printf(
285
-                esc_html__(
286
-                    '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
287
-                    'event_espresso'
288
-                ),
289
-                '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
290
-                '"><span class="dashicons dashicons-no"></span></a><p>',
291
-                ' &raquo; <a href="' . add_query_arg(
292
-                    array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')
293
-                ) . '">',
294
-                '</a></p></div>'
295
-            );
296
-        }
297
-    }
298
-    // espresso-notices important-notice ee-attention
271
+	/**
272
+	 * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
273
+	 */
274
+	public function display_maintenance_mode_notice()
275
+	{
276
+		// check if M-mode is engaged and for EE shortcode
277
+		if (
278
+			! (defined('DOING_AJAX') && DOING_AJAX)
279
+			&& $this->real_level()
280
+			&& ! is_admin()
281
+			&& current_user_can('administrator')
282
+			&& EE_Registry::instance()->REQ->is_espresso_page()
283
+		) {
284
+			printf(
285
+				esc_html__(
286
+					'%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
287
+					'event_espresso'
288
+				),
289
+				'<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
290
+				'"><span class="dashicons dashicons-no"></span></a><p>',
291
+				' &raquo; <a href="' . add_query_arg(
292
+					array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')
293
+				) . '">',
294
+				'</a></p></div>'
295
+			);
296
+		}
297
+	}
298
+	// espresso-notices important-notice ee-attention
299 299
 
300 300
 
301 301
 
302
-    /**
303
-     * override magic methods
304
-     */
305
-    final public function __destruct()
306
-    {
307
-    }
302
+	/**
303
+	 * override magic methods
304
+	 */
305
+	final public function __destruct()
306
+	{
307
+	}
308 308
 
309 309
 
310 310
 
311
-    final public function __call($a, $b)
312
-    {
313
-    }
311
+	final public function __call($a, $b)
312
+	{
313
+	}
314 314
 
315 315
 
316 316
 
317
-    final public function __get($a)
318
-    {
319
-    }
317
+	final public function __get($a)
318
+	{
319
+	}
320 320
 
321 321
 
322 322
 
323
-    final public function __set($a, $b)
324
-    {
325
-    }
323
+	final public function __set($a, $b)
324
+	{
325
+	}
326 326
 
327 327
 
328 328
 
329
-    final public function __isset($a)
330
-    {
331
-    }
329
+	final public function __isset($a)
330
+	{
331
+	}
332 332
 
333 333
 
334 334
 
335
-    final public function __unset($a)
336
-    {
337
-    }
335
+	final public function __unset($a)
336
+	{
337
+	}
338 338
 
339 339
 
340 340
 
341
-    final public function __sleep()
342
-    {
343
-        return array();
344
-    }
341
+	final public function __sleep()
342
+	{
343
+		return array();
344
+	}
345 345
 
346 346
 
347 347
 
348
-    final public function __wakeup()
349
-    {
350
-    }
348
+	final public function __wakeup()
349
+	{
350
+	}
351 351
 
352 352
 
353 353
 
354
-    final public function __invoke()
355
-    {
356
-    }
354
+	final public function __invoke()
355
+	{
356
+	}
357 357
 
358 358
 
359 359
 
360
-    final public static function __set_state($a = null)
361
-    {
362
-        return EE_Maintenance_Mode::instance();
363
-    }
360
+	final public static function __set_state($a = null)
361
+	{
362
+		return EE_Maintenance_Mode::instance();
363
+	}
364 364
 
365 365
 
366 366
 
367
-    final public function __clone()
368
-    {
369
-    }
367
+	final public function __clone()
368
+	{
369
+	}
370 370
 
371 371
 
372 372
 
373
-    final public static function __callStatic($a, $b)
374
-    {
375
-    }
373
+	final public static function __callStatic($a, $b)
374
+	{
375
+	}
376 376
 
377 377
 }
378 378
 // End of file EE_Maintenance_Mode.core.php
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -698,7 +698,7 @@
 block discarded – undo
698 698
 
699 699
     /**
700 700
      * @param EE_State[] $state_options
701
-     * @return array
701
+     * @return EE_State[]
702 702
      * @throws EE_Error
703 703
      * @throws InvalidArgumentException
704 704
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +724 added lines, -724 removed lines patch added patch discarded remove patch
@@ -19,730 +19,730 @@
 block discarded – undo
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     * @return EED_Module|EED_Add_New_State
24
-     */
25
-    public static function instance()
26
-    {
27
-        return parent::get_instance(__CLASS__);
28
-    }
29
-
30
-
31
-
32
-    /**
33
-     * set_hooks - for hooking into EE Core, other modules, etc
34
-     *
35
-     * @return void
36
-     */
37
-    public static function set_hooks()
38
-    {
39
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
40
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
41
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
42
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
44
-        add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
45
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
46
-        add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
47
-            array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
48
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
49
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
50
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
51
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
52
-        add_filter('FHEE__EE_State_Select_Input____construct__state_options',
53
-            array('EED_Add_New_State', 'state_options'), 10, 1);
54
-        add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
55
-            array('EED_Add_New_State', 'country_options'), 10, 1);
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
62
-     *
63
-     * @return void
64
-     */
65
-    public static function set_hooks_admin()
66
-    {
67
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
68
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
69
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
70
-        add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
71
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
72
-        add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
73
-        add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
74
-        add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
75
-            array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
76
-        add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
77
-            array('EED_Add_New_State', 'update_country_settings'), 10, 3);
78
-        add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
79
-            array('EED_Add_New_State', 'update_country_settings'), 10, 3);
80
-        add_filter('FHEE__EE_State_Select_Input____construct__state_options',
81
-            array('EED_Add_New_State', 'state_options'), 10, 1);
82
-        add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
83
-            array('EED_Add_New_State', 'country_options'), 10, 1);
84
-        add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
85
-            array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1);
86
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
87
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
88
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
89
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * @return void
96
-     */
97
-    public static function set_definitions()
98
-    {
99
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
100
-        define('ANS_TEMPLATES_PATH', str_replace(
101
-                                         '\\',
102
-                                         DS,
103
-                                         plugin_dir_path(__FILE__)) . 'templates' . DS
104
-        );
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @param WP $WP
111
-     * @return void
112
-     */
113
-    public function run($WP)
114
-    {
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * @return void
121
-     */
122
-    public static function translate_js_strings()
123
-    {
124
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
125
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
126
-            'event_espresso'
127
-        );
128
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
129
-            'In order to proceed, you need to enter the name of your State/Province.',
130
-            'event_espresso'
131
-        );
132
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
133
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
134
-            'event_espresso'
135
-        );
136
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
137
-            'The new state was successfully saved to the database.',
138
-            'event_espresso'
139
-        );
140
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
141
-            'An unknown error has occurred on the server while saving the new state to the database.',
142
-            'event_espresso'
143
-        );
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @return void
150
-     */
151
-    public static function wp_enqueue_scripts()
152
-    {
153
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
154
-            wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
155
-                array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
156
-            wp_enqueue_script('add_new_state');
157
-        }
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * display_add_new_state_micro_form
164
-     *
165
-     * @param EE_Form_Section_Proper $question_group_reg_form
166
-     * @return string
167
-     * @throws EE_Error
168
-     * @throws InvalidArgumentException
169
-     * @throws InvalidDataTypeException
170
-     * @throws InvalidInterfaceException
171
-     */
172
-    //	public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){
173
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
174
-    {
175
-        // only add the 'new_state_micro_form' when displaying reg forms,
176
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
177
-        $action = EE_Registry::instance()->REQ->get('action', '');
178
-        // is the "state" question in this form section?
179
-        $input = $question_group_reg_form->get_subsection('state');
180
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
181
-            //ok then all we need to do is make sure the input's HTML name is consistent
182
-            //by forcing it to set it now, like it did while getting the form for display
183
-            if ($input instanceof EE_State_Select_Input) {
184
-                $input->html_name();
185
-            }
186
-            return $question_group_reg_form;
187
-        }
188
-        // we're only doing this for state select inputs
189
-        if ($input instanceof EE_State_Select_Input) {
190
-            // grab any set values from the request
191
-            $country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
192
-            $state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
193
-            $abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
194
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
195
-            $country_options     = array();
196
-            $countries           = EEM_Country::instance()->get_all_countries();
197
-            if (! empty($countries)) {
198
-                foreach ($countries as $country) {
199
-                    if ($country instanceof EE_Country) {
200
-                        $country_options[$country->ID()] = $country->name();
201
-                    }
202
-                }
203
-            }
204
-            $new_state_micro_form = new EE_Form_Section_Proper(
205
-                array(
206
-                    'name'            => 'new_state_micro_form',
207
-                    'html_id'         => 'new_state_micro_form',
208
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
209
-                    'subsections'     => array(
210
-                        // add hidden input to indicate that a new state is being added
211
-                        'add_new_state'               => new EE_Hidden_Input(
212
-                            array(
213
-                                'html_name' => str_replace(
214
-                                    'state',
215
-                                    'nsmf_add_new_state',
216
-                                    $input->html_name()
217
-                                ),
218
-                                'html_id'   => str_replace(
219
-                                    'state',
220
-                                    'nsmf_add_new_state',
221
-                                    $input->html_id()
222
-                                ),
223
-                                'default'   => 0,
224
-                            )
225
-                        ),
226
-                        // add link for displaying hidden container
227
-                        'click_here_link'             => new EE_Form_Section_HTML(
228
-                            apply_filters(
229
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
230
-                                EEH_HTML::link(
231
-                                    '',
232
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
233
-                                    '',
234
-                                    'display-' . $input->html_id(),
235
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
236
-                                    '',
237
-                                    'data-target="' . $input->html_id() . '"'
238
-                                )
239
-                            )
240
-                        ),
241
-                        // add initial html for hidden container
242
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
243
-                            apply_filters(
244
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
245
-                                EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
246
-                                    'display: none;') .
247
-                                EEH_HTML::h6(
248
-                                    esc_html__(
249
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
250
-                                        'event_espresso'
251
-                                    )
252
-                                ) .
253
-                                EEH_HTML::ul() .
254
-                                EEH_HTML::li(
255
-                                    esc_html__(
256
-                                        'first select the Country that your State/Province belongs to',
257
-                                        'event_espresso'
258
-                                    )
259
-                                ) .
260
-                                EEH_HTML::li(
261
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
262
-                                ) .
263
-                                EEH_HTML::li(
264
-                                    esc_html__(
265
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
266
-                                        'event_espresso'
267
-                                    )
268
-                                ) .
269
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
270
-                                EEH_HTML::ulx()
271
-                            )
272
-                        ),
273
-                        // NEW STATE COUNTRY
274
-                        'new_state_country'           => new EE_Country_Select_Input(
275
-                            $country_options,
276
-                            array(
277
-                                'html_name'       => $country_name,
278
-                                'html_id'         => str_replace(
279
-                                    'state',
280
-                                    'nsmf_new_state_country', $input->html_id()
281
-                                ),
282
-                                'html_class'      => $input->html_class() . ' new-state-country',
283
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
284
-                                'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
285
-                                'required'        => false,
286
-                            )
287
-                        ),
288
-                        // NEW STATE NAME
289
-                        'new_state_name'              => new EE_Text_Input(
290
-                            array(
291
-                                'html_name'       => $state_name,
292
-                                'html_id'         => str_replace(
293
-                                    'state',
294
-                                    'nsmf_new_state_name', $input->html_id()
295
-                                ),
296
-                                'html_class'      => $input->html_class() . ' new-state-state',
297
-                                'html_label_text' => esc_html__('New State/Province Name',
298
-                                    'event_espresso'),
299
-                                'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
300
-                                'required'        => false,
301
-                            )
302
-                        ),
303
-                        'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
304
-                        // NEW STATE NAME
305
-                        'new_state_abbrv'             => new EE_Text_Input(
306
-                            array(
307
-                                'html_name'             => $abbrv_name,
308
-                                'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
309
-                                    $input->html_id()),
310
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
311
-                                'html_label_text'       => esc_html__(
312
-                                                               'New State/Province Abbreviation',
313
-                                                               'event_espresso'
314
-                                                           ) . ' *',
315
-                                'html_other_attributes' => 'size="24"',
316
-                                'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
317
-                                'required'              => false,
318
-                            )
319
-                        ),
320
-                        // "submit" button
321
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
322
-                            apply_filters(
323
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
324
-                                EEH_HTML::nbsp(3) .
325
-                                EEH_HTML::link(
326
-                                    '',
327
-                                    esc_html__('ADD', 'event_espresso'),
328
-                                    '',
329
-                                    'submit-' . $new_state_submit_id,
330
-                                    'ee-form-add-new-state-submit button button-secondary',
331
-                                    '',
332
-                                    'data-target="' . $new_state_submit_id . '"'
333
-                                )
334
-                            )
335
-                        ),
336
-                        // extra info
337
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
338
-                            apply_filters(
339
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
340
-                                EEH_HTML::br(2)
341
-                                .
342
-                                EEH_HTML::div('', '', 'small-text')
343
-                                .
344
-                                EEH_HTML::strong(
345
-                                    '* ' .
346
-                                    esc_html__(
347
-                                        'Don\'t know your State/Province Abbreviation?',
348
-                                        'event_espresso'
349
-                                    )
350
-                                )
351
-                                .
352
-                                EEH_HTML::br()
353
-                                .
354
-                                sprintf(
355
-                                    esc_html__(
356
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
357
-                                        'event_espresso'
358
-                                    ),
359
-                                    EEH_HTML::link(
360
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
361
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
362
-                                        '',
363
-                                        '',
364
-                                        'ee-form-add-new-state-wiki-lnk',
365
-                                        '',
366
-                                        'target="_blank"'
367
-                                    )
368
-                                )
369
-                                .
370
-                                EEH_HTML::divx()
371
-                                .
372
-                                EEH_HTML::br()
373
-                                .
374
-                                EEH_HTML::link(
375
-                                    '',
376
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
377
-                                    '',
378
-                                    'hide-' . $input->html_id(),
379
-                                    'ee-form-cancel-new-state-lnk smaller-text',
380
-                                    '',
381
-                                    'data-target="' . $input->html_id() . '"'
382
-                                )
383
-                                .
384
-                                EEH_HTML::divx()
385
-                                .
386
-                                EEH_HTML::br()
387
-                            )
388
-                        ),
389
-                    ),
390
-                )
391
-            );
392
-            $question_group_reg_form->add_subsections(
393
-                array('new_state_micro_form' => $new_state_micro_form),
394
-                'state',
395
-                false
396
-            );
397
-        }
398
-        return $question_group_reg_form;
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * set_new_state_input_width
405
-     *
406
-     * @return int|string
407
-     * @throws EE_Error
408
-     * @throws InvalidArgumentException
409
-     * @throws InvalidDataTypeException
410
-     * @throws InvalidInterfaceException
411
-     * @throws ReflectionException
412
-     */
413
-    public static function add_new_state()
414
-    {
415
-        $REQ = EE_Registry::instance()->load_core('Request_Handler');
416
-        if (absint($REQ->get('nsmf_add_new_state')) === 1) {
417
-            EE_Registry::instance()->load_model('State');
418
-            // grab country ISO code, new state name, and new state abbreviation
419
-            $state_country = $REQ->is_set('nsmf_new_state_country')
420
-                ? sanitize_text_field($REQ->get('nsmf_new_state_country'))
421
-                : false;
422
-            $state_name    = $REQ->is_set('nsmf_new_state_name')
423
-                ? sanitize_text_field($REQ->get('nsmf_new_state_name'))
424
-                : false;
425
-            $state_abbr    = $REQ->is_set('nsmf_new_state_abbrv')
426
-                ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
427
-                : false;
428
-            if ($state_country && $state_name && $state_abbr) {
429
-                $new_state = EED_Add_New_State::save_new_state_to_db(array(
430
-                    'CNT_ISO'    => strtoupper($state_country),
431
-                    'STA_abbrev' => strtoupper($state_abbr),
432
-                    'STA_name'   => ucwords($state_name),
433
-                    'STA_active' => false,
434
-                ));
435
-                if ($new_state instanceof EE_State) {
436
-                    // clean house
437
-                    EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
438
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
439
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
440
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
441
-                    // get any existing new states
442
-                    $new_states                   = EE_Registry::instance()->SSN->get_session_data(
443
-                        'nsmf_new_states'
444
-                    );
445
-                    $new_states[$new_state->ID()] = $new_state;
446
-                    EE_Registry::instance()->SSN->set_session_data(
447
-                        array('nsmf_new_states' => $new_states)
448
-                    );
449
-                    if (EE_Registry::instance()->REQ->ajax) {
450
-                        echo wp_json_encode(array(
451
-                            'success'      => true,
452
-                            'id'           => $new_state->ID(),
453
-                            'name'         => $new_state->name(),
454
-                            'abbrev'       => $new_state->abbrev(),
455
-                            'country_iso'  => $new_state->country_iso(),
456
-                            'country_name' => $new_state->country()->name(),
457
-                        ));
458
-                        exit();
459
-                    }
460
-                    return $new_state->ID();
461
-                }
462
-            } else {
463
-                $error = esc_html__(
464
-                    'A new State/Province could not be added because invalid or missing data was received.',
465
-                    'event_espresso'
466
-                );
467
-                if (EE_Registry::instance()->REQ->ajax) {
468
-                    echo wp_json_encode(array('error' => $error));
469
-                    exit();
470
-                }
471
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
472
-            }
473
-        }
474
-        return false;
475
-    }
476
-
477
-
478
-
479
-    /**
480
-     * recursively drills down through request params to remove any that were added by this module
481
-     *
482
-     * @param array $request_params
483
-     * @return array
484
-     */
485
-    public static function filter_checkout_request_params($request_params)
486
-    {
487
-        foreach ($request_params as $form_section) {
488
-            if (is_array($form_section)) {
489
-                EED_Add_New_State::unset_new_state_request_params($form_section);
490
-                EED_Add_New_State::filter_checkout_request_params($form_section);
491
-            }
492
-        }
493
-        return $request_params;
494
-    }
495
-
496
-
497
-
498
-    /**
499
-     * @param array $request_params
500
-     * @return array
501
-     */
502
-    public static function unset_new_state_request_params($request_params)
503
-    {
504
-        unset(
505
-            $request_params['new_state_micro_form'],
506
-            $request_params['new_state_micro_add_new_state'],
507
-            $request_params['new_state_micro_new_state_country'],
508
-            $request_params['new_state_micro_new_state_name'],
509
-            $request_params['new_state_micro_new_state_abbrv']
510
-        );
511
-        return $request_params;
512
-    }
513
-
514
-
515
-
516
-    /**
517
-     * @param array $props_n_values
518
-     * @return bool
519
-     * @throws EE_Error
520
-     * @throws InvalidArgumentException
521
-     * @throws InvalidDataTypeException
522
-     * @throws InvalidInterfaceException
523
-     */
524
-    public static function save_new_state_to_db($props_n_values = array())
525
-    {
526
-        $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
527
-        if (! empty($existing_state)) {
528
-            return array_pop($existing_state);
529
-        }
530
-        $new_state = EE_State::new_instance($props_n_values);
531
-        if ($new_state instanceof EE_State) {
532
-            // if not non-ajax admin
533
-            $new_state_key    = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
534
-            $new_state_notice = sprintf(
535
-                esc_html__(
536
-                    'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
537
-                    'event_espresso'
538
-                ),
539
-                '<b>' . $new_state->name() . '</b>',
540
-                '<b>' . $new_state->abbrev() . '</b>',
541
-                '<b>' . $new_state->country()->name() . '</b>',
542
-                '<a href="' . add_query_arg(array(
543
-                    'page'    => 'espresso_general_settings',
544
-                    'action'  => 'country_settings',
545
-                    'country' => $new_state->country_iso(),
546
-                ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
547
-                    'event_espresso') . '</a>',
548
-                '<br />'
549
-            );
550
-            EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
551
-            $new_state->save();
552
-            EEM_State::instance()->reset_cached_states();
553
-            return $new_state;
554
-        }
555
-        return false;
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     * @param string $CNT_ISO
562
-     * @param string $STA_ID
563
-     * @param array  $cols_n_values
564
-     * @return void
565
-     * @throws EE_Error
566
-     * @throws InvalidArgumentException
567
-     * @throws InvalidDataTypeException
568
-     * @throws InvalidInterfaceException
569
-     */
570
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
571
-    {
572
-        if (! $CNT_ISO) {
573
-            EE_Error::add_error(
574
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
575
-                __FILE__,
576
-                __FUNCTION__,
577
-                __LINE__
578
-            );
579
-        }
580
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
581
-            : false;
582
-        if (! $STA_abbrev && ! empty($STA_ID)) {
583
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
584
-            if ($state instanceof EE_State) {
585
-                $STA_abbrev = $state->abbrev();
586
-            }
587
-        }
588
-        if (! $STA_abbrev) {
589
-            EE_Error::add_error(
590
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
591
-                __FILE__,
592
-                __FUNCTION__,
593
-                __LINE__
594
-            );
595
-        }
596
-        EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
597
-    }
598
-
599
-
600
-
601
-    /**
602
-     * @param EE_State[]                            $state_options
603
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
604
-     * @param EE_Registration                       $registration
605
-     * @param EE_Question                           $question
606
-     * @param                                       $answer
607
-     * @return array
608
-     * @throws EE_Error
609
-     * @throws InvalidArgumentException
610
-     * @throws InvalidDataTypeException
611
-     * @throws InvalidInterfaceException
612
-     */
613
-    public static function inject_new_reg_state_into_options(
614
-        $state_options = array(),
615
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
616
-        EE_Registration $registration,
617
-        EE_Question $question,
618
-        $answer
619
-    ) {
620
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
621
-            && $question->type() === EEM_Question::QST_type_state
622
-        ) {
623
-            $STA_ID = $answer->value();
624
-            if (! empty($STA_ID)) {
625
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
626
-                if ($state instanceof EE_State) {
627
-                    $country = $state->country();
628
-                    if ($country instanceof EE_Country) {
629
-                        if (! isset($state_options[$country->name()])) {
630
-                            $state_options[$country->name()] = array();
631
-                        }
632
-                        if (! isset($state_options[$country->name()][$STA_ID])) {
633
-                            $state_options[$country->name()][$STA_ID] = $state->name();
634
-                        }
635
-                    }
636
-                }
637
-            }
638
-        }
639
-        return $state_options;
640
-    }
641
-
642
-
643
-
644
-    /**
645
-     * @param EE_Country[]                          $country_options
646
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
647
-     * @param EE_Registration                       $registration
648
-     * @param EE_Question                           $question
649
-     * @param                                       $answer
650
-     * @return array
651
-     * @throws EE_Error
652
-     * @throws InvalidArgumentException
653
-     * @throws InvalidDataTypeException
654
-     * @throws InvalidInterfaceException
655
-     */
656
-    public static function inject_new_reg_country_into_options(
657
-        $country_options = array(),
658
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
659
-        EE_Registration $registration,
660
-        EE_Question $question,
661
-        $answer
662
-    ) {
663
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
664
-            && $question->type()
665
-               === EEM_Question::QST_type_country
666
-        ) {
667
-            $CNT_ISO = $answer->value();
668
-            if (! empty($CNT_ISO)) {
669
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
670
-                if ($country instanceof EE_Country) {
671
-                    if (! isset($country_options[$CNT_ISO])) {
672
-                        $country_options[$CNT_ISO] = $country->name();
673
-                    }
674
-                }
675
-            }
676
-        }
677
-        return $country_options;
678
-    }
679
-
680
-
681
-
682
-    /**
683
-     * @param EE_State[] $state_options
684
-     * @return array
685
-     * @throws EE_Error
686
-     * @throws InvalidArgumentException
687
-     * @throws InvalidDataTypeException
688
-     * @throws InvalidInterfaceException
689
-     */
690
-    public static function state_options($state_options = array())
691
-    {
692
-        $new_states = EED_Add_New_State::_get_new_states();
693
-        foreach ($new_states as $new_state) {
694
-            if (
695
-                $new_state instanceof EE_State
696
-                && $new_state->country() instanceof EE_Country
697
-            ) {
698
-                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
699
-            }
700
-        }
701
-        return $state_options;
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     * @return array
708
-     * @throws InvalidArgumentException
709
-     * @throws InvalidDataTypeException
710
-     * @throws InvalidInterfaceException
711
-     */
712
-    protected static function _get_new_states()
713
-    {
714
-        $new_states = array();
715
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
716
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
717
-                'nsmf_new_states'
718
-            );
719
-        }
720
-        return is_array($new_states) ? $new_states : array();
721
-    }
722
-
723
-
724
-
725
-    /**
726
-     * @param EE_Country[] $country_options
727
-     * @return array
728
-     * @throws EE_Error
729
-     * @throws InvalidArgumentException
730
-     * @throws InvalidDataTypeException
731
-     * @throws InvalidInterfaceException
732
-     */
733
-    public static function country_options($country_options = array())
734
-    {
735
-        $new_states = EED_Add_New_State::_get_new_states();
736
-        foreach ($new_states as $new_state) {
737
-            if (
738
-                $new_state instanceof EE_State
739
-                && $new_state->country() instanceof EE_Country
740
-            ) {
741
-                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
742
-            }
743
-        }
744
-        return $country_options;
745
-    }
22
+	/**
23
+	 * @return EED_Module|EED_Add_New_State
24
+	 */
25
+	public static function instance()
26
+	{
27
+		return parent::get_instance(__CLASS__);
28
+	}
29
+
30
+
31
+
32
+	/**
33
+	 * set_hooks - for hooking into EE Core, other modules, etc
34
+	 *
35
+	 * @return void
36
+	 */
37
+	public static function set_hooks()
38
+	{
39
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
40
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
41
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
42
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
44
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
45
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
46
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
47
+			array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
48
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
49
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
50
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
51
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
52
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options',
53
+			array('EED_Add_New_State', 'state_options'), 10, 1);
54
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
55
+			array('EED_Add_New_State', 'country_options'), 10, 1);
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
62
+	 *
63
+	 * @return void
64
+	 */
65
+	public static function set_hooks_admin()
66
+	{
67
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
68
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
69
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
70
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
71
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
72
+		add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
73
+		add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
74
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
75
+			array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
76
+		add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
77
+			array('EED_Add_New_State', 'update_country_settings'), 10, 3);
78
+		add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
79
+			array('EED_Add_New_State', 'update_country_settings'), 10, 3);
80
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options',
81
+			array('EED_Add_New_State', 'state_options'), 10, 1);
82
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
83
+			array('EED_Add_New_State', 'country_options'), 10, 1);
84
+		add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
85
+			array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1);
86
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
87
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
88
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
89
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * @return void
96
+	 */
97
+	public static function set_definitions()
98
+	{
99
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
100
+		define('ANS_TEMPLATES_PATH', str_replace(
101
+										 '\\',
102
+										 DS,
103
+										 plugin_dir_path(__FILE__)) . 'templates' . DS
104
+		);
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @param WP $WP
111
+	 * @return void
112
+	 */
113
+	public function run($WP)
114
+	{
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * @return void
121
+	 */
122
+	public static function translate_js_strings()
123
+	{
124
+		EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
125
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
126
+			'event_espresso'
127
+		);
128
+		EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
129
+			'In order to proceed, you need to enter the name of your State/Province.',
130
+			'event_espresso'
131
+		);
132
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
133
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
134
+			'event_espresso'
135
+		);
136
+		EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
137
+			'The new state was successfully saved to the database.',
138
+			'event_espresso'
139
+		);
140
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
141
+			'An unknown error has occurred on the server while saving the new state to the database.',
142
+			'event_espresso'
143
+		);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @return void
150
+	 */
151
+	public static function wp_enqueue_scripts()
152
+	{
153
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
154
+			wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
155
+				array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
156
+			wp_enqueue_script('add_new_state');
157
+		}
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * display_add_new_state_micro_form
164
+	 *
165
+	 * @param EE_Form_Section_Proper $question_group_reg_form
166
+	 * @return string
167
+	 * @throws EE_Error
168
+	 * @throws InvalidArgumentException
169
+	 * @throws InvalidDataTypeException
170
+	 * @throws InvalidInterfaceException
171
+	 */
172
+	//	public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){
173
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
174
+	{
175
+		// only add the 'new_state_micro_form' when displaying reg forms,
176
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
177
+		$action = EE_Registry::instance()->REQ->get('action', '');
178
+		// is the "state" question in this form section?
179
+		$input = $question_group_reg_form->get_subsection('state');
180
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
181
+			//ok then all we need to do is make sure the input's HTML name is consistent
182
+			//by forcing it to set it now, like it did while getting the form for display
183
+			if ($input instanceof EE_State_Select_Input) {
184
+				$input->html_name();
185
+			}
186
+			return $question_group_reg_form;
187
+		}
188
+		// we're only doing this for state select inputs
189
+		if ($input instanceof EE_State_Select_Input) {
190
+			// grab any set values from the request
191
+			$country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
192
+			$state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
193
+			$abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
194
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
195
+			$country_options     = array();
196
+			$countries           = EEM_Country::instance()->get_all_countries();
197
+			if (! empty($countries)) {
198
+				foreach ($countries as $country) {
199
+					if ($country instanceof EE_Country) {
200
+						$country_options[$country->ID()] = $country->name();
201
+					}
202
+				}
203
+			}
204
+			$new_state_micro_form = new EE_Form_Section_Proper(
205
+				array(
206
+					'name'            => 'new_state_micro_form',
207
+					'html_id'         => 'new_state_micro_form',
208
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
209
+					'subsections'     => array(
210
+						// add hidden input to indicate that a new state is being added
211
+						'add_new_state'               => new EE_Hidden_Input(
212
+							array(
213
+								'html_name' => str_replace(
214
+									'state',
215
+									'nsmf_add_new_state',
216
+									$input->html_name()
217
+								),
218
+								'html_id'   => str_replace(
219
+									'state',
220
+									'nsmf_add_new_state',
221
+									$input->html_id()
222
+								),
223
+								'default'   => 0,
224
+							)
225
+						),
226
+						// add link for displaying hidden container
227
+						'click_here_link'             => new EE_Form_Section_HTML(
228
+							apply_filters(
229
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
230
+								EEH_HTML::link(
231
+									'',
232
+									esc_html__('click here to add a new state/province', 'event_espresso'),
233
+									'',
234
+									'display-' . $input->html_id(),
235
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
236
+									'',
237
+									'data-target="' . $input->html_id() . '"'
238
+								)
239
+							)
240
+						),
241
+						// add initial html for hidden container
242
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
243
+							apply_filters(
244
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
245
+								EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
246
+									'display: none;') .
247
+								EEH_HTML::h6(
248
+									esc_html__(
249
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
250
+										'event_espresso'
251
+									)
252
+								) .
253
+								EEH_HTML::ul() .
254
+								EEH_HTML::li(
255
+									esc_html__(
256
+										'first select the Country that your State/Province belongs to',
257
+										'event_espresso'
258
+									)
259
+								) .
260
+								EEH_HTML::li(
261
+									esc_html__('enter the name of your State/Province', 'event_espresso')
262
+								) .
263
+								EEH_HTML::li(
264
+									esc_html__(
265
+										'enter a two to six letter abbreviation for the name of your State/Province',
266
+										'event_espresso'
267
+									)
268
+								) .
269
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
270
+								EEH_HTML::ulx()
271
+							)
272
+						),
273
+						// NEW STATE COUNTRY
274
+						'new_state_country'           => new EE_Country_Select_Input(
275
+							$country_options,
276
+							array(
277
+								'html_name'       => $country_name,
278
+								'html_id'         => str_replace(
279
+									'state',
280
+									'nsmf_new_state_country', $input->html_id()
281
+								),
282
+								'html_class'      => $input->html_class() . ' new-state-country',
283
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
284
+								'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
285
+								'required'        => false,
286
+							)
287
+						),
288
+						// NEW STATE NAME
289
+						'new_state_name'              => new EE_Text_Input(
290
+							array(
291
+								'html_name'       => $state_name,
292
+								'html_id'         => str_replace(
293
+									'state',
294
+									'nsmf_new_state_name', $input->html_id()
295
+								),
296
+								'html_class'      => $input->html_class() . ' new-state-state',
297
+								'html_label_text' => esc_html__('New State/Province Name',
298
+									'event_espresso'),
299
+								'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
300
+								'required'        => false,
301
+							)
302
+						),
303
+						'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
304
+						// NEW STATE NAME
305
+						'new_state_abbrv'             => new EE_Text_Input(
306
+							array(
307
+								'html_name'             => $abbrv_name,
308
+								'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
309
+									$input->html_id()),
310
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
311
+								'html_label_text'       => esc_html__(
312
+															   'New State/Province Abbreviation',
313
+															   'event_espresso'
314
+														   ) . ' *',
315
+								'html_other_attributes' => 'size="24"',
316
+								'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
317
+								'required'              => false,
318
+							)
319
+						),
320
+						// "submit" button
321
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
322
+							apply_filters(
323
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
324
+								EEH_HTML::nbsp(3) .
325
+								EEH_HTML::link(
326
+									'',
327
+									esc_html__('ADD', 'event_espresso'),
328
+									'',
329
+									'submit-' . $new_state_submit_id,
330
+									'ee-form-add-new-state-submit button button-secondary',
331
+									'',
332
+									'data-target="' . $new_state_submit_id . '"'
333
+								)
334
+							)
335
+						),
336
+						// extra info
337
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
338
+							apply_filters(
339
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
340
+								EEH_HTML::br(2)
341
+								.
342
+								EEH_HTML::div('', '', 'small-text')
343
+								.
344
+								EEH_HTML::strong(
345
+									'* ' .
346
+									esc_html__(
347
+										'Don\'t know your State/Province Abbreviation?',
348
+										'event_espresso'
349
+									)
350
+								)
351
+								.
352
+								EEH_HTML::br()
353
+								.
354
+								sprintf(
355
+									esc_html__(
356
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
357
+										'event_espresso'
358
+									),
359
+									EEH_HTML::link(
360
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
361
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
362
+										'',
363
+										'',
364
+										'ee-form-add-new-state-wiki-lnk',
365
+										'',
366
+										'target="_blank"'
367
+									)
368
+								)
369
+								.
370
+								EEH_HTML::divx()
371
+								.
372
+								EEH_HTML::br()
373
+								.
374
+								EEH_HTML::link(
375
+									'',
376
+									esc_html__('cancel new State/Province', 'event_espresso'),
377
+									'',
378
+									'hide-' . $input->html_id(),
379
+									'ee-form-cancel-new-state-lnk smaller-text',
380
+									'',
381
+									'data-target="' . $input->html_id() . '"'
382
+								)
383
+								.
384
+								EEH_HTML::divx()
385
+								.
386
+								EEH_HTML::br()
387
+							)
388
+						),
389
+					),
390
+				)
391
+			);
392
+			$question_group_reg_form->add_subsections(
393
+				array('new_state_micro_form' => $new_state_micro_form),
394
+				'state',
395
+				false
396
+			);
397
+		}
398
+		return $question_group_reg_form;
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * set_new_state_input_width
405
+	 *
406
+	 * @return int|string
407
+	 * @throws EE_Error
408
+	 * @throws InvalidArgumentException
409
+	 * @throws InvalidDataTypeException
410
+	 * @throws InvalidInterfaceException
411
+	 * @throws ReflectionException
412
+	 */
413
+	public static function add_new_state()
414
+	{
415
+		$REQ = EE_Registry::instance()->load_core('Request_Handler');
416
+		if (absint($REQ->get('nsmf_add_new_state')) === 1) {
417
+			EE_Registry::instance()->load_model('State');
418
+			// grab country ISO code, new state name, and new state abbreviation
419
+			$state_country = $REQ->is_set('nsmf_new_state_country')
420
+				? sanitize_text_field($REQ->get('nsmf_new_state_country'))
421
+				: false;
422
+			$state_name    = $REQ->is_set('nsmf_new_state_name')
423
+				? sanitize_text_field($REQ->get('nsmf_new_state_name'))
424
+				: false;
425
+			$state_abbr    = $REQ->is_set('nsmf_new_state_abbrv')
426
+				? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
427
+				: false;
428
+			if ($state_country && $state_name && $state_abbr) {
429
+				$new_state = EED_Add_New_State::save_new_state_to_db(array(
430
+					'CNT_ISO'    => strtoupper($state_country),
431
+					'STA_abbrev' => strtoupper($state_abbr),
432
+					'STA_name'   => ucwords($state_name),
433
+					'STA_active' => false,
434
+				));
435
+				if ($new_state instanceof EE_State) {
436
+					// clean house
437
+					EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
438
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
439
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
440
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
441
+					// get any existing new states
442
+					$new_states                   = EE_Registry::instance()->SSN->get_session_data(
443
+						'nsmf_new_states'
444
+					);
445
+					$new_states[$new_state->ID()] = $new_state;
446
+					EE_Registry::instance()->SSN->set_session_data(
447
+						array('nsmf_new_states' => $new_states)
448
+					);
449
+					if (EE_Registry::instance()->REQ->ajax) {
450
+						echo wp_json_encode(array(
451
+							'success'      => true,
452
+							'id'           => $new_state->ID(),
453
+							'name'         => $new_state->name(),
454
+							'abbrev'       => $new_state->abbrev(),
455
+							'country_iso'  => $new_state->country_iso(),
456
+							'country_name' => $new_state->country()->name(),
457
+						));
458
+						exit();
459
+					}
460
+					return $new_state->ID();
461
+				}
462
+			} else {
463
+				$error = esc_html__(
464
+					'A new State/Province could not be added because invalid or missing data was received.',
465
+					'event_espresso'
466
+				);
467
+				if (EE_Registry::instance()->REQ->ajax) {
468
+					echo wp_json_encode(array('error' => $error));
469
+					exit();
470
+				}
471
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
472
+			}
473
+		}
474
+		return false;
475
+	}
476
+
477
+
478
+
479
+	/**
480
+	 * recursively drills down through request params to remove any that were added by this module
481
+	 *
482
+	 * @param array $request_params
483
+	 * @return array
484
+	 */
485
+	public static function filter_checkout_request_params($request_params)
486
+	{
487
+		foreach ($request_params as $form_section) {
488
+			if (is_array($form_section)) {
489
+				EED_Add_New_State::unset_new_state_request_params($form_section);
490
+				EED_Add_New_State::filter_checkout_request_params($form_section);
491
+			}
492
+		}
493
+		return $request_params;
494
+	}
495
+
496
+
497
+
498
+	/**
499
+	 * @param array $request_params
500
+	 * @return array
501
+	 */
502
+	public static function unset_new_state_request_params($request_params)
503
+	{
504
+		unset(
505
+			$request_params['new_state_micro_form'],
506
+			$request_params['new_state_micro_add_new_state'],
507
+			$request_params['new_state_micro_new_state_country'],
508
+			$request_params['new_state_micro_new_state_name'],
509
+			$request_params['new_state_micro_new_state_abbrv']
510
+		);
511
+		return $request_params;
512
+	}
513
+
514
+
515
+
516
+	/**
517
+	 * @param array $props_n_values
518
+	 * @return bool
519
+	 * @throws EE_Error
520
+	 * @throws InvalidArgumentException
521
+	 * @throws InvalidDataTypeException
522
+	 * @throws InvalidInterfaceException
523
+	 */
524
+	public static function save_new_state_to_db($props_n_values = array())
525
+	{
526
+		$existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
527
+		if (! empty($existing_state)) {
528
+			return array_pop($existing_state);
529
+		}
530
+		$new_state = EE_State::new_instance($props_n_values);
531
+		if ($new_state instanceof EE_State) {
532
+			// if not non-ajax admin
533
+			$new_state_key    = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
534
+			$new_state_notice = sprintf(
535
+				esc_html__(
536
+					'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
537
+					'event_espresso'
538
+				),
539
+				'<b>' . $new_state->name() . '</b>',
540
+				'<b>' . $new_state->abbrev() . '</b>',
541
+				'<b>' . $new_state->country()->name() . '</b>',
542
+				'<a href="' . add_query_arg(array(
543
+					'page'    => 'espresso_general_settings',
544
+					'action'  => 'country_settings',
545
+					'country' => $new_state->country_iso(),
546
+				), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
547
+					'event_espresso') . '</a>',
548
+				'<br />'
549
+			);
550
+			EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
551
+			$new_state->save();
552
+			EEM_State::instance()->reset_cached_states();
553
+			return $new_state;
554
+		}
555
+		return false;
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 * @param string $CNT_ISO
562
+	 * @param string $STA_ID
563
+	 * @param array  $cols_n_values
564
+	 * @return void
565
+	 * @throws EE_Error
566
+	 * @throws InvalidArgumentException
567
+	 * @throws InvalidDataTypeException
568
+	 * @throws InvalidInterfaceException
569
+	 */
570
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
571
+	{
572
+		if (! $CNT_ISO) {
573
+			EE_Error::add_error(
574
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
575
+				__FILE__,
576
+				__FUNCTION__,
577
+				__LINE__
578
+			);
579
+		}
580
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
581
+			: false;
582
+		if (! $STA_abbrev && ! empty($STA_ID)) {
583
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
584
+			if ($state instanceof EE_State) {
585
+				$STA_abbrev = $state->abbrev();
586
+			}
587
+		}
588
+		if (! $STA_abbrev) {
589
+			EE_Error::add_error(
590
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
591
+				__FILE__,
592
+				__FUNCTION__,
593
+				__LINE__
594
+			);
595
+		}
596
+		EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
597
+	}
598
+
599
+
600
+
601
+	/**
602
+	 * @param EE_State[]                            $state_options
603
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
604
+	 * @param EE_Registration                       $registration
605
+	 * @param EE_Question                           $question
606
+	 * @param                                       $answer
607
+	 * @return array
608
+	 * @throws EE_Error
609
+	 * @throws InvalidArgumentException
610
+	 * @throws InvalidDataTypeException
611
+	 * @throws InvalidInterfaceException
612
+	 */
613
+	public static function inject_new_reg_state_into_options(
614
+		$state_options = array(),
615
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
616
+		EE_Registration $registration,
617
+		EE_Question $question,
618
+		$answer
619
+	) {
620
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
621
+			&& $question->type() === EEM_Question::QST_type_state
622
+		) {
623
+			$STA_ID = $answer->value();
624
+			if (! empty($STA_ID)) {
625
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
626
+				if ($state instanceof EE_State) {
627
+					$country = $state->country();
628
+					if ($country instanceof EE_Country) {
629
+						if (! isset($state_options[$country->name()])) {
630
+							$state_options[$country->name()] = array();
631
+						}
632
+						if (! isset($state_options[$country->name()][$STA_ID])) {
633
+							$state_options[$country->name()][$STA_ID] = $state->name();
634
+						}
635
+					}
636
+				}
637
+			}
638
+		}
639
+		return $state_options;
640
+	}
641
+
642
+
643
+
644
+	/**
645
+	 * @param EE_Country[]                          $country_options
646
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
647
+	 * @param EE_Registration                       $registration
648
+	 * @param EE_Question                           $question
649
+	 * @param                                       $answer
650
+	 * @return array
651
+	 * @throws EE_Error
652
+	 * @throws InvalidArgumentException
653
+	 * @throws InvalidDataTypeException
654
+	 * @throws InvalidInterfaceException
655
+	 */
656
+	public static function inject_new_reg_country_into_options(
657
+		$country_options = array(),
658
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
659
+		EE_Registration $registration,
660
+		EE_Question $question,
661
+		$answer
662
+	) {
663
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
664
+			&& $question->type()
665
+			   === EEM_Question::QST_type_country
666
+		) {
667
+			$CNT_ISO = $answer->value();
668
+			if (! empty($CNT_ISO)) {
669
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
670
+				if ($country instanceof EE_Country) {
671
+					if (! isset($country_options[$CNT_ISO])) {
672
+						$country_options[$CNT_ISO] = $country->name();
673
+					}
674
+				}
675
+			}
676
+		}
677
+		return $country_options;
678
+	}
679
+
680
+
681
+
682
+	/**
683
+	 * @param EE_State[] $state_options
684
+	 * @return array
685
+	 * @throws EE_Error
686
+	 * @throws InvalidArgumentException
687
+	 * @throws InvalidDataTypeException
688
+	 * @throws InvalidInterfaceException
689
+	 */
690
+	public static function state_options($state_options = array())
691
+	{
692
+		$new_states = EED_Add_New_State::_get_new_states();
693
+		foreach ($new_states as $new_state) {
694
+			if (
695
+				$new_state instanceof EE_State
696
+				&& $new_state->country() instanceof EE_Country
697
+			) {
698
+				$state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
699
+			}
700
+		}
701
+		return $state_options;
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 * @return array
708
+	 * @throws InvalidArgumentException
709
+	 * @throws InvalidDataTypeException
710
+	 * @throws InvalidInterfaceException
711
+	 */
712
+	protected static function _get_new_states()
713
+	{
714
+		$new_states = array();
715
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
716
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
717
+				'nsmf_new_states'
718
+			);
719
+		}
720
+		return is_array($new_states) ? $new_states : array();
721
+	}
722
+
723
+
724
+
725
+	/**
726
+	 * @param EE_Country[] $country_options
727
+	 * @return array
728
+	 * @throws EE_Error
729
+	 * @throws InvalidArgumentException
730
+	 * @throws InvalidDataTypeException
731
+	 * @throws InvalidInterfaceException
732
+	 */
733
+	public static function country_options($country_options = array())
734
+	{
735
+		$new_states = EED_Add_New_State::_get_new_states();
736
+		foreach ($new_states as $new_state) {
737
+			if (
738
+				$new_state instanceof EE_State
739
+				&& $new_state->country() instanceof EE_Country
740
+			) {
741
+				$country_options[$new_state->country()->ID()] = $new_state->country()->name();
742
+			}
743
+		}
744
+		return $country_options;
745
+	}
746 746
 
747 747
 
748 748
 
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public static function set_definitions()
98 98
     {
99
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
99
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
100 100
         define('ANS_TEMPLATES_PATH', str_replace(
101 101
                                          '\\',
102 102
                                          DS,
103
-                                         plugin_dir_path(__FILE__)) . 'templates' . DS
103
+                                         plugin_dir_path(__FILE__)).'templates'.DS
104 104
         );
105 105
     }
106 106
 
@@ -121,19 +121,19 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public static function translate_js_strings()
123 123
     {
124
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
124
+        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
125 125
             'In order to proceed, you need to select the Country that your State/Province belongs to.',
126 126
             'event_espresso'
127 127
         );
128
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
128
+        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
129 129
             'In order to proceed, you need to enter the name of your State/Province.',
130 130
             'event_espresso'
131 131
         );
132
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
132
+        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
133 133
             'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
134 134
             'event_espresso'
135 135
         );
136
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
136
+        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
137 137
             'The new state was successfully saved to the database.',
138 138
             'event_espresso'
139 139
         );
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     public static function wp_enqueue_scripts()
152 152
     {
153 153
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
154
-            wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
154
+            wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js',
155 155
                 array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
156 156
             wp_enqueue_script('add_new_state');
157 157
         }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
195 195
             $country_options     = array();
196 196
             $countries           = EEM_Country::instance()->get_all_countries();
197
-            if (! empty($countries)) {
197
+            if ( ! empty($countries)) {
198 198
                 foreach ($countries as $country) {
199 199
                     if ($country instanceof EE_Country) {
200 200
                         $country_options[$country->ID()] = $country->name();
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
                                     '',
232 232
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
233 233
                                     '',
234
-                                    'display-' . $input->html_id(),
234
+                                    'display-'.$input->html_id(),
235 235
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
236 236
                                     '',
237
-                                    'data-target="' . $input->html_id() . '"'
237
+                                    'data-target="'.$input->html_id().'"'
238 238
                                 )
239 239
                             )
240 240
                         ),
@@ -242,31 +242,31 @@  discard block
 block discarded – undo
242 242
                         'add_new_state_micro_form'    => new EE_Form_Section_HTML(
243 243
                             apply_filters(
244 244
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
245
-                                EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
246
-                                    'display: none;') .
245
+                                EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv',
246
+                                    'display: none;').
247 247
                                 EEH_HTML::h6(
248 248
                                     esc_html__(
249 249
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
250 250
                                         'event_espresso'
251 251
                                     )
252
-                                ) .
253
-                                EEH_HTML::ul() .
252
+                                ).
253
+                                EEH_HTML::ul().
254 254
                                 EEH_HTML::li(
255 255
                                     esc_html__(
256 256
                                         'first select the Country that your State/Province belongs to',
257 257
                                         'event_espresso'
258 258
                                     )
259
-                                ) .
259
+                                ).
260 260
                                 EEH_HTML::li(
261 261
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
262
-                                ) .
262
+                                ).
263 263
                                 EEH_HTML::li(
264 264
                                     esc_html__(
265 265
                                         'enter a two to six letter abbreviation for the name of your State/Province',
266 266
                                         'event_espresso'
267 267
                                     )
268
-                                ) .
269
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
268
+                                ).
269
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
270 270
                                 EEH_HTML::ulx()
271 271
                             )
272 272
                         ),
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                                     'state',
280 280
                                     'nsmf_new_state_country', $input->html_id()
281 281
                                 ),
282
-                                'html_class'      => $input->html_class() . ' new-state-country',
282
+                                'html_class'      => $input->html_class().' new-state-country',
283 283
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
284 284
                                 'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
285 285
                                 'required'        => false,
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
                                     'state',
294 294
                                     'nsmf_new_state_name', $input->html_id()
295 295
                                 ),
296
-                                'html_class'      => $input->html_class() . ' new-state-state',
296
+                                'html_class'      => $input->html_class().' new-state-state',
297 297
                                 'html_label_text' => esc_html__('New State/Province Name',
298 298
                                     'event_espresso'),
299 299
                                 'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
@@ -307,11 +307,11 @@  discard block
 block discarded – undo
307 307
                                 'html_name'             => $abbrv_name,
308 308
                                 'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
309 309
                                     $input->html_id()),
310
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
310
+                                'html_class'            => $input->html_class().' new-state-abbrv',
311 311
                                 'html_label_text'       => esc_html__(
312 312
                                                                'New State/Province Abbreviation',
313 313
                                                                'event_espresso'
314
-                                                           ) . ' *',
314
+                                                           ).' *',
315 315
                                 'html_other_attributes' => 'size="24"',
316 316
                                 'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
317 317
                                 'required'              => false,
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
                         'add_new_state_submit_button' => new EE_Form_Section_HTML(
322 322
                             apply_filters(
323 323
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
324
-                                EEH_HTML::nbsp(3) .
324
+                                EEH_HTML::nbsp(3).
325 325
                                 EEH_HTML::link(
326 326
                                     '',
327 327
                                     esc_html__('ADD', 'event_espresso'),
328 328
                                     '',
329
-                                    'submit-' . $new_state_submit_id,
329
+                                    'submit-'.$new_state_submit_id,
330 330
                                     'ee-form-add-new-state-submit button button-secondary',
331 331
                                     '',
332
-                                    'data-target="' . $new_state_submit_id . '"'
332
+                                    'data-target="'.$new_state_submit_id.'"'
333 333
                                 )
334 334
                             )
335 335
                         ),
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                                 EEH_HTML::div('', '', 'small-text')
343 343
                                 .
344 344
                                 EEH_HTML::strong(
345
-                                    '* ' .
345
+                                    '* '.
346 346
                                     esc_html__(
347 347
                                         'Don\'t know your State/Province Abbreviation?',
348 348
                                         'event_espresso'
@@ -375,10 +375,10 @@  discard block
 block discarded – undo
375 375
                                     '',
376 376
                                     esc_html__('cancel new State/Province', 'event_espresso'),
377 377
                                     '',
378
-                                    'hide-' . $input->html_id(),
378
+                                    'hide-'.$input->html_id(),
379 379
                                     'ee-form-cancel-new-state-lnk smaller-text',
380 380
                                     '',
381
-                                    'data-target="' . $input->html_id() . '"'
381
+                                    'data-target="'.$input->html_id().'"'
382 382
                                 )
383 383
                                 .
384 384
                                 EEH_HTML::divx()
@@ -524,27 +524,27 @@  discard block
 block discarded – undo
524 524
     public static function save_new_state_to_db($props_n_values = array())
525 525
     {
526 526
         $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
527
-        if (! empty($existing_state)) {
527
+        if ( ! empty($existing_state)) {
528 528
             return array_pop($existing_state);
529 529
         }
530 530
         $new_state = EE_State::new_instance($props_n_values);
531 531
         if ($new_state instanceof EE_State) {
532 532
             // if not non-ajax admin
533
-            $new_state_key    = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
533
+            $new_state_key    = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev();
534 534
             $new_state_notice = sprintf(
535 535
                 esc_html__(
536 536
                     'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
537 537
                     'event_espresso'
538 538
                 ),
539
-                '<b>' . $new_state->name() . '</b>',
540
-                '<b>' . $new_state->abbrev() . '</b>',
541
-                '<b>' . $new_state->country()->name() . '</b>',
542
-                '<a href="' . add_query_arg(array(
539
+                '<b>'.$new_state->name().'</b>',
540
+                '<b>'.$new_state->abbrev().'</b>',
541
+                '<b>'.$new_state->country()->name().'</b>',
542
+                '<a href="'.add_query_arg(array(
543 543
                     'page'    => 'espresso_general_settings',
544 544
                     'action'  => 'country_settings',
545 545
                     'country' => $new_state->country_iso(),
546
-                ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
547
-                    'event_espresso') . '</a>',
546
+                ), admin_url('admin.php')).'">'.esc_html__('Event Espresso - General Settings > Countries Tab',
547
+                    'event_espresso').'</a>',
548 548
                 '<br />'
549 549
             );
550 550
             EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
      */
570 570
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
571 571
     {
572
-        if (! $CNT_ISO) {
572
+        if ( ! $CNT_ISO) {
573 573
             EE_Error::add_error(
574 574
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
575 575
                 __FILE__,
@@ -579,13 +579,13 @@  discard block
 block discarded – undo
579 579
         }
580 580
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
581 581
             : false;
582
-        if (! $STA_abbrev && ! empty($STA_ID)) {
582
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
583 583
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
584 584
             if ($state instanceof EE_State) {
585 585
                 $STA_abbrev = $state->abbrev();
586 586
             }
587 587
         }
588
-        if (! $STA_abbrev) {
588
+        if ( ! $STA_abbrev) {
589 589
             EE_Error::add_error(
590 590
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
591 591
                 __FILE__,
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
                 __LINE__
594 594
             );
595 595
         }
596
-        EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
596
+        EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true);
597 597
     }
598 598
 
599 599
 
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
             && $question->type() === EEM_Question::QST_type_state
622 622
         ) {
623 623
             $STA_ID = $answer->value();
624
-            if (! empty($STA_ID)) {
624
+            if ( ! empty($STA_ID)) {
625 625
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
626 626
                 if ($state instanceof EE_State) {
627 627
                     $country = $state->country();
628 628
                     if ($country instanceof EE_Country) {
629
-                        if (! isset($state_options[$country->name()])) {
629
+                        if ( ! isset($state_options[$country->name()])) {
630 630
                             $state_options[$country->name()] = array();
631 631
                         }
632
-                        if (! isset($state_options[$country->name()][$STA_ID])) {
632
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
633 633
                             $state_options[$country->name()][$STA_ID] = $state->name();
634 634
                         }
635 635
                     }
@@ -665,10 +665,10 @@  discard block
 block discarded – undo
665 665
                === EEM_Question::QST_type_country
666 666
         ) {
667 667
             $CNT_ISO = $answer->value();
668
-            if (! empty($CNT_ISO)) {
668
+            if ( ! empty($CNT_ISO)) {
669 669
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
670 670
                 if ($country instanceof EE_Country) {
671
-                    if (! isset($country_options[$CNT_ISO])) {
671
+                    if ( ! isset($country_options[$CNT_ISO])) {
672 672
                         $country_options[$CNT_ISO] = $country->name();
673 673
                     }
674 674
                 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Event.php 2 patches
Indentation   +401 added lines, -401 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  * @since                 $VID:$
20 20
  */
21 21
 if (! defined('EVENT_ESPRESSO_VERSION')) {
22
-    exit('No direct script access allowed');
22
+	exit('No direct script access allowed');
23 23
 }
24 24
 
25 25
 
@@ -27,404 +27,404 @@  discard block
 block discarded – undo
27 27
 class Event extends Calculations_Base
28 28
 {
29 29
 
30
-    /**
31
-     * Calculates the total spaces on the event (not subtracting sales, but taking
32
-     * sales into account; so this is the optimum sales that CAN still be achieved)
33
-     * See EE_Event::total_available_spaces( true );
34
-     *
35
-     * @param array            $wpdb_row
36
-     * @param \WP_REST_Request $request
37
-     * @param Base             $controller
38
-     * @return int
39
-     * @throws EE_Error
40
-     */
41
-    public static function optimumSalesAtStart($wpdb_row, $request, $controller)
42
-    {
43
-        $event_obj = null;
44
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
45
-            $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
46
-        }
47
-        if ($event_obj instanceof EE_Event) {
48
-            return $event_obj->total_available_spaces();
49
-        }
50
-        throw new EE_Error(
51
-            sprintf(
52
-                __(
53
-                    // @codingStandardsIgnoreStart
54
-                    'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
55
-                    // @codingStandardsIgnoreEnd
56
-                    'event_espresso'
57
-                ),
58
-                $wpdb_row['Event_CPT.ID'],
59
-                print_r($wpdb_row, true)
60
-            )
61
-        );
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
68
-     * sales that COULD have been achieved)
69
-     * See EE_Event::total_available_spaces( true );
70
-     *
71
-     * @param array            $wpdb_row
72
-     * @param \WP_REST_Request $request
73
-     * @param Base             $controller
74
-     * @return int
75
-     * @throws EE_Error
76
-     */
77
-    public static function optimumSalesNow($wpdb_row, $request, $controller)
78
-    {
79
-        $event_obj = null;
80
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
81
-            $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
82
-        }
83
-        if ($event_obj instanceof EE_Event) {
84
-            return $event_obj->total_available_spaces(true);
85
-        }
86
-        throw new EE_Error(
87
-            sprintf(
88
-                __(
89
-                    // @codingStandardsIgnoreStart
90
-                    'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
91
-                    // @codingStandardsIgnoreEnd
92
-                    'event_espresso'
93
-                ),
94
-                $wpdb_row['Event_CPT.ID'],
95
-                print_r($wpdb_row, true)
96
-            )
97
-        );
98
-    }
99
-
100
-
101
-
102
-    /**
103
-     * Like optimum_sales_now, but minus total sales so far.
104
-     * See EE_Event::spaces_remaining_for_sale( true );
105
-     *
106
-     * @param array            $wpdb_row
107
-     * @param \WP_REST_Request $request
108
-     * @param Base             $controller
109
-     * @return int
110
-     * @throws EE_Error
111
-     */
112
-    public static function spacesRemaining($wpdb_row, $request, $controller)
113
-    {
114
-        $event_obj = null;
115
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
116
-            $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
117
-        }
118
-        if ($event_obj instanceof EE_Event) {
119
-            return $event_obj->spaces_remaining_for_sale();
120
-        }
121
-        throw new EE_Error(
122
-            sprintf(
123
-                __(
124
-                    // @codingStandardsIgnoreStart
125
-                    'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
126
-                    // @codingStandardsIgnoreEnd
127
-                    'event_espresso'
128
-                ),
129
-                $wpdb_row['Event_CPT.ID'],
130
-                print_r($wpdb_row, true)
131
-            )
132
-        );
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     * Counts the number of approved registrations for this event (regardless
139
-     * of how many datetimes each registrations' ticket purchase is for)
140
-     *
141
-     * @param array            $wpdb_row
142
-     * @param \WP_REST_Request $request
143
-     * @param Base             $controller
144
-     * @return int
145
-     * @throws EE_Error
146
-     */
147
-    public static function spotsTaken($wpdb_row, $request, $controller)
148
-    {
149
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
150
-            throw new EE_Error(
151
-                sprintf(
152
-                    __(
153
-                        // @codingStandardsIgnoreStart
154
-                        'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
155
-                        // @codingStandardsIgnoreEnd
156
-                        'event_espresso'
157
-                    ),
158
-                    print_r($wpdb_row, true)
159
-                )
160
-            );
161
-        }
162
-        return EEM_Registration::instance()->count(
163
-            array(
164
-                array(
165
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
166
-                    'STS_ID' => EEM_Registration::status_id_approved,
167
-                ),
168
-            ),
169
-            'REG_ID',
170
-            true
171
-        );
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * Counts the number of pending-payment registrations for this event (regardless
178
-     * of how many datetimes each registrations' ticket purchase is for)
179
-     *
180
-     * @param array            $wpdb_row
181
-     * @param \WP_REST_Request $request
182
-     * @param Base             $controller
183
-     * @return int
184
-     * @throws EE_Error
185
-     * @throws RestException
186
-     */
187
-    public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
188
-    {
189
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
190
-            throw new EE_Error(
191
-                sprintf(
192
-                    __(
193
-                        // @codingStandardsIgnoreStart
194
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
195
-                        // @codingStandardsIgnoreEnd
196
-                        'event_espresso'
197
-                    ),
198
-                    print_r($wpdb_row, true)
199
-                )
200
-            );
201
-        }
202
-        self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
203
-        return EEM_Registration::instance()->count(
204
-            array(
205
-                array(
206
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
207
-                    'STS_ID' => EEM_Registration::status_id_pending_payment,
208
-                ),
209
-            ),
210
-            'REG_ID',
211
-            true
212
-        );
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * Counts all the registrations who have checked into one of this events' datetimes
219
-     * See EE_Event::total_available_spaces( false );
220
-     *
221
-     * @param array            $wpdb_row
222
-     * @param \WP_REST_Request $request
223
-     * @param Base             $controller
224
-     * @return int|null if permission denied
225
-     * @throws EE_Error
226
-     * @throws RestException
227
-     */
228
-    public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
229
-    {
230
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
231
-            throw new EE_Error(
232
-                sprintf(
233
-                    __(
234
-                        // @codingStandardsIgnoreStart
235
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
236
-                        // @codingStandardsIgnoreEnd
237
-                        'event_espresso'
238
-                    ),
239
-                    print_r($wpdb_row, true)
240
-                )
241
-            );
242
-        }
243
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
244
-        return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * Counts all the registrations who have checked out of one of this events' datetimes
251
-     * See EE_Event::total_available_spaces( false );
252
-     *
253
-     * @param array            $wpdb_row
254
-     * @param \WP_REST_Request $request
255
-     * @param Base             $controller
256
-     * @return int
257
-     * @throws EE_Error
258
-     * @throws RestException
259
-     */
260
-    public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
261
-    {
262
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
263
-            throw new EE_Error(
264
-                sprintf(
265
-                    __(
266
-                        // @codingStandardsIgnoreStart
267
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
268
-                        // @codingStandardsIgnoreEnd
269
-                        'event_espresso'
270
-                    ),
271
-                    print_r($wpdb_row, true)
272
-                )
273
-            );
274
-        }
275
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
276
-        return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * Gets the thumbnail image
283
-     *
284
-     * @param array            $wpdb_row
285
-     * @param \WP_REST_Request $request
286
-     * @param Base             $controller
287
-     * @return array
288
-     * @throws EE_Error
289
-     */
290
-    public static function imageThumbnail($wpdb_row, $request, $controller)
291
-    {
292
-        return self::calculateImageData($wpdb_row, 'thumbnail');
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * Gets the medium image
299
-     *
300
-     * @param array            $wpdb_row
301
-     * @param \WP_REST_Request $request
302
-     * @param Base             $controller
303
-     * @return array
304
-     * @throws EE_Error
305
-     */
306
-    public static function imageMedium($wpdb_row, $request, $controller)
307
-    {
308
-        return self::calculateImageData($wpdb_row, 'medium');
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * Gets the medium-large image
315
-     *
316
-     * @param array            $wpdb_row
317
-     * @param \WP_REST_Request $request
318
-     * @param Base             $controller
319
-     * @return array
320
-     * @throws EE_Error
321
-     */
322
-    public static function imageMediumLarge($wpdb_row, $request, $controller)
323
-    {
324
-        return self::calculateImageData($wpdb_row, 'medium_large');
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * Gets the large image
331
-     *
332
-     * @param array            $wpdb_row
333
-     * @param \WP_REST_Request $request
334
-     * @param Base             $controller
335
-     * @return array
336
-     * @throws EE_Error
337
-     */
338
-    public static function imageLarge($wpdb_row, $request, $controller)
339
-    {
340
-        return self::calculateImageData($wpdb_row, 'large');
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * Gets the post-thumbnail image
347
-     *
348
-     * @param array            $wpdb_row
349
-     * @param \WP_REST_Request $request
350
-     * @param Base             $controller
351
-     * @return array
352
-     * @throws EE_Error
353
-     */
354
-    public static function imagePostThumbnail($wpdb_row, $request, $controller)
355
-    {
356
-        return self::calculateImageData($wpdb_row, 'post-thumbnail');
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     * Gets the full size image
363
-     *
364
-     * @param array            $wpdb_row
365
-     * @param \WP_REST_Request $request
366
-     * @param Base             $controller
367
-     * @return array
368
-     * @throws EE_Error
369
-     */
370
-    public static function imageFull($wpdb_row, $request, $controller)
371
-    {
372
-        return self::calculateImageData($wpdb_row, 'full');
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * Gets image specs and formats them for the display in the API,
379
-     * according to the image size requested
380
-     *
381
-     * @param array    $wpdb_row
382
-     * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
383
-     * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
384
-     * @throws EE_Error
385
-     */
386
-    protected static function calculateImageData($wpdb_row, $image_size)
387
-    {
388
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
389
-            throw new EE_Error(
390
-                sprintf(
391
-                    __(
392
-                    // @codingStandardsIgnoreStart
393
-                        'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
394
-                        // @codingStandardsIgnoreEnd
395
-                        'event_espresso'
396
-                    ),
397
-                    print_r($wpdb_row, true)
398
-                )
399
-            );
400
-        }
401
-        $EVT_ID = $wpdb_row['Event_CPT.ID'];
402
-        $attachment_id = get_post_thumbnail_id($EVT_ID);
403
-        $data = wp_get_attachment_image_src($attachment_id, $image_size);
404
-        if (! $data) {
405
-            return null;
406
-        }
407
-        $generated = true;
408
-        if (isset($data[3])) {
409
-            $generated = $data[3];
410
-        }
411
-        return array(
412
-            'url'       => $data[0],
413
-            'width'     => $data[1],
414
-            'height'    => $data[2],
415
-            'generated' => $generated,
416
-        );
417
-    }
418
-
419
-
420
-
421
-    /**
422
-     * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
423
-     * @param array $wpdb_row
424
-     * @return bool
425
-     */
426
-    protected static function wpdbRowHasEventId($wpdb_row)
427
-    {
428
-        return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
429
-    }
30
+	/**
31
+	 * Calculates the total spaces on the event (not subtracting sales, but taking
32
+	 * sales into account; so this is the optimum sales that CAN still be achieved)
33
+	 * See EE_Event::total_available_spaces( true );
34
+	 *
35
+	 * @param array            $wpdb_row
36
+	 * @param \WP_REST_Request $request
37
+	 * @param Base             $controller
38
+	 * @return int
39
+	 * @throws EE_Error
40
+	 */
41
+	public static function optimumSalesAtStart($wpdb_row, $request, $controller)
42
+	{
43
+		$event_obj = null;
44
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
45
+			$event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
46
+		}
47
+		if ($event_obj instanceof EE_Event) {
48
+			return $event_obj->total_available_spaces();
49
+		}
50
+		throw new EE_Error(
51
+			sprintf(
52
+				__(
53
+					// @codingStandardsIgnoreStart
54
+					'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
55
+					// @codingStandardsIgnoreEnd
56
+					'event_espresso'
57
+				),
58
+				$wpdb_row['Event_CPT.ID'],
59
+				print_r($wpdb_row, true)
60
+			)
61
+		);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
68
+	 * sales that COULD have been achieved)
69
+	 * See EE_Event::total_available_spaces( true );
70
+	 *
71
+	 * @param array            $wpdb_row
72
+	 * @param \WP_REST_Request $request
73
+	 * @param Base             $controller
74
+	 * @return int
75
+	 * @throws EE_Error
76
+	 */
77
+	public static function optimumSalesNow($wpdb_row, $request, $controller)
78
+	{
79
+		$event_obj = null;
80
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
81
+			$event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
82
+		}
83
+		if ($event_obj instanceof EE_Event) {
84
+			return $event_obj->total_available_spaces(true);
85
+		}
86
+		throw new EE_Error(
87
+			sprintf(
88
+				__(
89
+					// @codingStandardsIgnoreStart
90
+					'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
91
+					// @codingStandardsIgnoreEnd
92
+					'event_espresso'
93
+				),
94
+				$wpdb_row['Event_CPT.ID'],
95
+				print_r($wpdb_row, true)
96
+			)
97
+		);
98
+	}
99
+
100
+
101
+
102
+	/**
103
+	 * Like optimum_sales_now, but minus total sales so far.
104
+	 * See EE_Event::spaces_remaining_for_sale( true );
105
+	 *
106
+	 * @param array            $wpdb_row
107
+	 * @param \WP_REST_Request $request
108
+	 * @param Base             $controller
109
+	 * @return int
110
+	 * @throws EE_Error
111
+	 */
112
+	public static function spacesRemaining($wpdb_row, $request, $controller)
113
+	{
114
+		$event_obj = null;
115
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
116
+			$event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']);
117
+		}
118
+		if ($event_obj instanceof EE_Event) {
119
+			return $event_obj->spaces_remaining_for_sale();
120
+		}
121
+		throw new EE_Error(
122
+			sprintf(
123
+				__(
124
+					// @codingStandardsIgnoreStart
125
+					'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
126
+					// @codingStandardsIgnoreEnd
127
+					'event_espresso'
128
+				),
129
+				$wpdb_row['Event_CPT.ID'],
130
+				print_r($wpdb_row, true)
131
+			)
132
+		);
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 * Counts the number of approved registrations for this event (regardless
139
+	 * of how many datetimes each registrations' ticket purchase is for)
140
+	 *
141
+	 * @param array            $wpdb_row
142
+	 * @param \WP_REST_Request $request
143
+	 * @param Base             $controller
144
+	 * @return int
145
+	 * @throws EE_Error
146
+	 */
147
+	public static function spotsTaken($wpdb_row, $request, $controller)
148
+	{
149
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
150
+			throw new EE_Error(
151
+				sprintf(
152
+					__(
153
+						// @codingStandardsIgnoreStart
154
+						'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
155
+						// @codingStandardsIgnoreEnd
156
+						'event_espresso'
157
+					),
158
+					print_r($wpdb_row, true)
159
+				)
160
+			);
161
+		}
162
+		return EEM_Registration::instance()->count(
163
+			array(
164
+				array(
165
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
166
+					'STS_ID' => EEM_Registration::status_id_approved,
167
+				),
168
+			),
169
+			'REG_ID',
170
+			true
171
+		);
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * Counts the number of pending-payment registrations for this event (regardless
178
+	 * of how many datetimes each registrations' ticket purchase is for)
179
+	 *
180
+	 * @param array            $wpdb_row
181
+	 * @param \WP_REST_Request $request
182
+	 * @param Base             $controller
183
+	 * @return int
184
+	 * @throws EE_Error
185
+	 * @throws RestException
186
+	 */
187
+	public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
188
+	{
189
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
190
+			throw new EE_Error(
191
+				sprintf(
192
+					__(
193
+						// @codingStandardsIgnoreStart
194
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
195
+						// @codingStandardsIgnoreEnd
196
+						'event_espresso'
197
+					),
198
+					print_r($wpdb_row, true)
199
+				)
200
+			);
201
+		}
202
+		self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
203
+		return EEM_Registration::instance()->count(
204
+			array(
205
+				array(
206
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
207
+					'STS_ID' => EEM_Registration::status_id_pending_payment,
208
+				),
209
+			),
210
+			'REG_ID',
211
+			true
212
+		);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * Counts all the registrations who have checked into one of this events' datetimes
219
+	 * See EE_Event::total_available_spaces( false );
220
+	 *
221
+	 * @param array            $wpdb_row
222
+	 * @param \WP_REST_Request $request
223
+	 * @param Base             $controller
224
+	 * @return int|null if permission denied
225
+	 * @throws EE_Error
226
+	 * @throws RestException
227
+	 */
228
+	public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
229
+	{
230
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
231
+			throw new EE_Error(
232
+				sprintf(
233
+					__(
234
+						// @codingStandardsIgnoreStart
235
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
236
+						// @codingStandardsIgnoreEnd
237
+						'event_espresso'
238
+					),
239
+					print_r($wpdb_row, true)
240
+				)
241
+			);
242
+		}
243
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
244
+		return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * Counts all the registrations who have checked out of one of this events' datetimes
251
+	 * See EE_Event::total_available_spaces( false );
252
+	 *
253
+	 * @param array            $wpdb_row
254
+	 * @param \WP_REST_Request $request
255
+	 * @param Base             $controller
256
+	 * @return int
257
+	 * @throws EE_Error
258
+	 * @throws RestException
259
+	 */
260
+	public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
261
+	{
262
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
263
+			throw new EE_Error(
264
+				sprintf(
265
+					__(
266
+						// @codingStandardsIgnoreStart
267
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
268
+						// @codingStandardsIgnoreEnd
269
+						'event_espresso'
270
+					),
271
+					print_r($wpdb_row, true)
272
+				)
273
+			);
274
+		}
275
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
276
+		return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * Gets the thumbnail image
283
+	 *
284
+	 * @param array            $wpdb_row
285
+	 * @param \WP_REST_Request $request
286
+	 * @param Base             $controller
287
+	 * @return array
288
+	 * @throws EE_Error
289
+	 */
290
+	public static function imageThumbnail($wpdb_row, $request, $controller)
291
+	{
292
+		return self::calculateImageData($wpdb_row, 'thumbnail');
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * Gets the medium image
299
+	 *
300
+	 * @param array            $wpdb_row
301
+	 * @param \WP_REST_Request $request
302
+	 * @param Base             $controller
303
+	 * @return array
304
+	 * @throws EE_Error
305
+	 */
306
+	public static function imageMedium($wpdb_row, $request, $controller)
307
+	{
308
+		return self::calculateImageData($wpdb_row, 'medium');
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * Gets the medium-large image
315
+	 *
316
+	 * @param array            $wpdb_row
317
+	 * @param \WP_REST_Request $request
318
+	 * @param Base             $controller
319
+	 * @return array
320
+	 * @throws EE_Error
321
+	 */
322
+	public static function imageMediumLarge($wpdb_row, $request, $controller)
323
+	{
324
+		return self::calculateImageData($wpdb_row, 'medium_large');
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * Gets the large image
331
+	 *
332
+	 * @param array            $wpdb_row
333
+	 * @param \WP_REST_Request $request
334
+	 * @param Base             $controller
335
+	 * @return array
336
+	 * @throws EE_Error
337
+	 */
338
+	public static function imageLarge($wpdb_row, $request, $controller)
339
+	{
340
+		return self::calculateImageData($wpdb_row, 'large');
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * Gets the post-thumbnail image
347
+	 *
348
+	 * @param array            $wpdb_row
349
+	 * @param \WP_REST_Request $request
350
+	 * @param Base             $controller
351
+	 * @return array
352
+	 * @throws EE_Error
353
+	 */
354
+	public static function imagePostThumbnail($wpdb_row, $request, $controller)
355
+	{
356
+		return self::calculateImageData($wpdb_row, 'post-thumbnail');
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 * Gets the full size image
363
+	 *
364
+	 * @param array            $wpdb_row
365
+	 * @param \WP_REST_Request $request
366
+	 * @param Base             $controller
367
+	 * @return array
368
+	 * @throws EE_Error
369
+	 */
370
+	public static function imageFull($wpdb_row, $request, $controller)
371
+	{
372
+		return self::calculateImageData($wpdb_row, 'full');
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * Gets image specs and formats them for the display in the API,
379
+	 * according to the image size requested
380
+	 *
381
+	 * @param array    $wpdb_row
382
+	 * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
383
+	 * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
384
+	 * @throws EE_Error
385
+	 */
386
+	protected static function calculateImageData($wpdb_row, $image_size)
387
+	{
388
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
389
+			throw new EE_Error(
390
+				sprintf(
391
+					__(
392
+					// @codingStandardsIgnoreStart
393
+						'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
394
+						// @codingStandardsIgnoreEnd
395
+						'event_espresso'
396
+					),
397
+					print_r($wpdb_row, true)
398
+				)
399
+			);
400
+		}
401
+		$EVT_ID = $wpdb_row['Event_CPT.ID'];
402
+		$attachment_id = get_post_thumbnail_id($EVT_ID);
403
+		$data = wp_get_attachment_image_src($attachment_id, $image_size);
404
+		if (! $data) {
405
+			return null;
406
+		}
407
+		$generated = true;
408
+		if (isset($data[3])) {
409
+			$generated = $data[3];
410
+		}
411
+		return array(
412
+			'url'       => $data[0],
413
+			'width'     => $data[1],
414
+			'height'    => $data[2],
415
+			'generated' => $generated,
416
+		);
417
+	}
418
+
419
+
420
+
421
+	/**
422
+	 * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
423
+	 * @param array $wpdb_row
424
+	 * @return bool
425
+	 */
426
+	protected static function wpdbRowHasEventId($wpdb_row)
427
+	{
428
+		return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
429
+	}
430 430
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * @author                Mike Nelson
19 19
  * @since                 $VID:$
20 20
  */
21
-if (! defined('EVENT_ESPRESSO_VERSION')) {
21
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
22 22
     exit('No direct script access allowed');
23 23
 }
24 24
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      */
147 147
     public static function spotsTaken($wpdb_row, $request, $controller)
148 148
     {
149
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
149
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
150 150
             throw new EE_Error(
151 151
                 sprintf(
152 152
                     __(
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
188 188
     {
189
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
189
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
190 190
             throw new EE_Error(
191 191
                 sprintf(
192 192
                     __(
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      */
228 228
     public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
229 229
     {
230
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
230
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
231 231
             throw new EE_Error(
232 232
                 sprintf(
233 233
                     __(
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
261 261
     {
262
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
262
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
263 263
             throw new EE_Error(
264 264
                 sprintf(
265 265
                     __(
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      */
386 386
     protected static function calculateImageData($wpdb_row, $image_size)
387 387
     {
388
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
388
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
389 389
             throw new EE_Error(
390 390
                 sprintf(
391 391
                     __(
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         $EVT_ID = $wpdb_row['Event_CPT.ID'];
402 402
         $attachment_id = get_post_thumbnail_id($EVT_ID);
403 403
         $data = wp_get_attachment_image_src($attachment_id, $image_size);
404
-        if (! $data) {
404
+        if ( ! $data) {
405 405
             return null;
406 406
         }
407 407
         $generated = true;
Please login to merge, or discard this patch.
core/EE_Addon.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@
 block discarded – undo
140 140
      * Sets addon_name
141 141
      *
142 142
      * @param string $addon_name
143
-     * @return boolean
143
+     * @return string
144 144
      */
145 145
     public function set_name($addon_name)
146 146
     {
Please login to merge, or discard this patch.
Indentation   +714 added lines, -714 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,702 +25,702 @@  discard block
 block discarded – undo
25 25
 {
26 26
 
27 27
 
28
-    /**
29
-     * prefix to be added onto an addon's plugin slug to make a wp option name
30
-     * which will be used to store the plugin's activation history
31
-     */
32
-    const ee_addon_version_history_option_prefix = 'ee_version_history_';
33
-
34
-    /**
35
-     * @var $_version
36
-     * @type string
37
-     */
38
-    protected $_version = '';
39
-
40
-    /**
41
-     * @var $_min_core_version
42
-     * @type string
43
-     */
44
-    protected $_min_core_version = '';
45
-
46
-    /**
47
-     * derived from plugin 'main_file_path using plugin_basename()
48
-     *
49
-     * @type string $_plugin_basename
50
-     */
51
-    protected $_plugin_basename = '';
52
-
53
-    /**
54
-     * A non-internationalized name to identify this addon for use in URLs, etc
55
-     *
56
-     * @type string $_plugin_slug
57
-     */
58
-    protected $_plugin_slug = '';
59
-
60
-    /**
61
-     * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
62
-     *
63
-     * @type string _addon_name
64
-     */
65
-    protected $_addon_name = '';
66
-
67
-    /**
68
-     * one of the EE_System::req_type_* constants
69
-     *
70
-     * @type int $_req_type
71
-     */
72
-    protected $_req_type;
73
-
74
-    /**
75
-     * page slug to be used when generating the "Settings" link on the WP plugin page
76
-     *
77
-     * @type string $_plugin_action_slug
78
-     */
79
-    protected $_plugin_action_slug = '';
80
-
81
-    /**
82
-     * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
83
-     * that can be used for adding upgrading/marketing info
84
-     *
85
-     * @type array $_plugins_page_row
86
-     */
87
-    protected $_plugins_page_row = array();
88
-
89
-
90
-    /**
91
-     *    class constructor
92
-     */
93
-    public function __construct()
94
-    {
95
-        add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
96
-    }
97
-
98
-
99
-    /**
100
-     * @param mixed $version
101
-     */
102
-    public function set_version($version = null)
103
-    {
104
-        $this->_version = $version;
105
-    }
106
-
107
-
108
-    /**
109
-     * get__version
110
-     *
111
-     * @return string
112
-     */
113
-    public function version()
114
-    {
115
-        return $this->_version;
116
-    }
117
-
118
-
119
-    /**
120
-     * @param mixed $min_core_version
121
-     */
122
-    public function set_min_core_version($min_core_version = null)
123
-    {
124
-        $this->_min_core_version = $min_core_version;
125
-    }
126
-
127
-
128
-    /**
129
-     * get__min_core_version
130
-     *
131
-     * @return string
132
-     */
133
-    public function min_core_version()
134
-    {
135
-        return $this->_min_core_version;
136
-    }
137
-
138
-
139
-    /**
140
-     * Sets addon_name
141
-     *
142
-     * @param string $addon_name
143
-     * @return boolean
144
-     */
145
-    public function set_name($addon_name)
146
-    {
147
-        return $this->_addon_name = $addon_name;
148
-    }
149
-
150
-
151
-    /**
152
-     * Gets addon_name
153
-     *
154
-     * @return string
155
-     */
156
-    public function name()
157
-    {
158
-        return $this->_addon_name;
159
-    }
160
-
161
-
162
-    /**
163
-     * @return string
164
-     */
165
-    public function plugin_basename()
166
-    {
167
-
168
-        return $this->_plugin_basename;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param string $plugin_basename
174
-     */
175
-    public function set_plugin_basename($plugin_basename)
176
-    {
177
-
178
-        $this->_plugin_basename = $plugin_basename;
179
-    }
180
-
181
-
182
-    /**
183
-     * @return string
184
-     */
185
-    public function plugin_slug()
186
-    {
187
-
188
-        return $this->_plugin_slug;
189
-    }
190
-
191
-
192
-    /**
193
-     * @param string $plugin_slug
194
-     */
195
-    public function set_plugin_slug($plugin_slug)
196
-    {
197
-
198
-        $this->_plugin_slug = $plugin_slug;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return string
204
-     */
205
-    public function plugin_action_slug()
206
-    {
207
-
208
-        return $this->_plugin_action_slug;
209
-    }
210
-
211
-
212
-    /**
213
-     * @param string $plugin_action_slug
214
-     */
215
-    public function set_plugin_action_slug($plugin_action_slug)
216
-    {
217
-
218
-        $this->_plugin_action_slug = $plugin_action_slug;
219
-    }
220
-
221
-
222
-    /**
223
-     * @return array
224
-     */
225
-    public function get_plugins_page_row()
226
-    {
227
-
228
-        return $this->_plugins_page_row;
229
-    }
230
-
231
-
232
-    /**
233
-     * @param array $plugins_page_row
234
-     */
235
-    public function set_plugins_page_row($plugins_page_row = array())
236
-    {
237
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
238
-        if (! is_array($plugins_page_row) && strpos($plugins_page_row,
239
-                '<h3>Promotions Addon Upsell Info</h3>') !== false) {
240
-            $plugins_page_row = '';
241
-        }
242
-        $this->_plugins_page_row = $plugins_page_row;
243
-    }
244
-
245
-
246
-    /**
247
-     * Called when EE core detects this addon has been activated for the first time.
248
-     * If the site isn't in maintenance mode, should setup the addon's database
249
-     *
250
-     * @return void
251
-     */
252
-    public function new_install()
253
-    {
254
-        $classname = get_class($this);
255
-        do_action("AHEE__{$classname}__new_install");
256
-        do_action('AHEE__EE_Addon__new_install', $this);
257
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
258
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
259
-            array($this, 'initialize_db_if_no_migrations_required'));
260
-    }
261
-
262
-
263
-    /**
264
-     * Called when EE core detects this addon has been reactivated. When this happens,
265
-     * it's good to just check that your data is still intact
266
-     *
267
-     * @return void
268
-     */
269
-    public function reactivation()
270
-    {
271
-        $classname = get_class($this);
272
-        do_action("AHEE__{$classname}__reactivation");
273
-        do_action('AHEE__EE_Addon__reactivation', $this);
274
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
275
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
276
-            array($this, 'initialize_db_if_no_migrations_required'));
277
-    }
278
-
279
-
280
-    public function deactivation()
281
-    {
282
-        $classname = get_class($this);
28
+	/**
29
+	 * prefix to be added onto an addon's plugin slug to make a wp option name
30
+	 * which will be used to store the plugin's activation history
31
+	 */
32
+	const ee_addon_version_history_option_prefix = 'ee_version_history_';
33
+
34
+	/**
35
+	 * @var $_version
36
+	 * @type string
37
+	 */
38
+	protected $_version = '';
39
+
40
+	/**
41
+	 * @var $_min_core_version
42
+	 * @type string
43
+	 */
44
+	protected $_min_core_version = '';
45
+
46
+	/**
47
+	 * derived from plugin 'main_file_path using plugin_basename()
48
+	 *
49
+	 * @type string $_plugin_basename
50
+	 */
51
+	protected $_plugin_basename = '';
52
+
53
+	/**
54
+	 * A non-internationalized name to identify this addon for use in URLs, etc
55
+	 *
56
+	 * @type string $_plugin_slug
57
+	 */
58
+	protected $_plugin_slug = '';
59
+
60
+	/**
61
+	 * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
62
+	 *
63
+	 * @type string _addon_name
64
+	 */
65
+	protected $_addon_name = '';
66
+
67
+	/**
68
+	 * one of the EE_System::req_type_* constants
69
+	 *
70
+	 * @type int $_req_type
71
+	 */
72
+	protected $_req_type;
73
+
74
+	/**
75
+	 * page slug to be used when generating the "Settings" link on the WP plugin page
76
+	 *
77
+	 * @type string $_plugin_action_slug
78
+	 */
79
+	protected $_plugin_action_slug = '';
80
+
81
+	/**
82
+	 * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
83
+	 * that can be used for adding upgrading/marketing info
84
+	 *
85
+	 * @type array $_plugins_page_row
86
+	 */
87
+	protected $_plugins_page_row = array();
88
+
89
+
90
+	/**
91
+	 *    class constructor
92
+	 */
93
+	public function __construct()
94
+	{
95
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param mixed $version
101
+	 */
102
+	public function set_version($version = null)
103
+	{
104
+		$this->_version = $version;
105
+	}
106
+
107
+
108
+	/**
109
+	 * get__version
110
+	 *
111
+	 * @return string
112
+	 */
113
+	public function version()
114
+	{
115
+		return $this->_version;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param mixed $min_core_version
121
+	 */
122
+	public function set_min_core_version($min_core_version = null)
123
+	{
124
+		$this->_min_core_version = $min_core_version;
125
+	}
126
+
127
+
128
+	/**
129
+	 * get__min_core_version
130
+	 *
131
+	 * @return string
132
+	 */
133
+	public function min_core_version()
134
+	{
135
+		return $this->_min_core_version;
136
+	}
137
+
138
+
139
+	/**
140
+	 * Sets addon_name
141
+	 *
142
+	 * @param string $addon_name
143
+	 * @return boolean
144
+	 */
145
+	public function set_name($addon_name)
146
+	{
147
+		return $this->_addon_name = $addon_name;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Gets addon_name
153
+	 *
154
+	 * @return string
155
+	 */
156
+	public function name()
157
+	{
158
+		return $this->_addon_name;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @return string
164
+	 */
165
+	public function plugin_basename()
166
+	{
167
+
168
+		return $this->_plugin_basename;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param string $plugin_basename
174
+	 */
175
+	public function set_plugin_basename($plugin_basename)
176
+	{
177
+
178
+		$this->_plugin_basename = $plugin_basename;
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return string
184
+	 */
185
+	public function plugin_slug()
186
+	{
187
+
188
+		return $this->_plugin_slug;
189
+	}
190
+
191
+
192
+	/**
193
+	 * @param string $plugin_slug
194
+	 */
195
+	public function set_plugin_slug($plugin_slug)
196
+	{
197
+
198
+		$this->_plugin_slug = $plugin_slug;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return string
204
+	 */
205
+	public function plugin_action_slug()
206
+	{
207
+
208
+		return $this->_plugin_action_slug;
209
+	}
210
+
211
+
212
+	/**
213
+	 * @param string $plugin_action_slug
214
+	 */
215
+	public function set_plugin_action_slug($plugin_action_slug)
216
+	{
217
+
218
+		$this->_plugin_action_slug = $plugin_action_slug;
219
+	}
220
+
221
+
222
+	/**
223
+	 * @return array
224
+	 */
225
+	public function get_plugins_page_row()
226
+	{
227
+
228
+		return $this->_plugins_page_row;
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param array $plugins_page_row
234
+	 */
235
+	public function set_plugins_page_row($plugins_page_row = array())
236
+	{
237
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
238
+		if (! is_array($plugins_page_row) && strpos($plugins_page_row,
239
+				'<h3>Promotions Addon Upsell Info</h3>') !== false) {
240
+			$plugins_page_row = '';
241
+		}
242
+		$this->_plugins_page_row = $plugins_page_row;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Called when EE core detects this addon has been activated for the first time.
248
+	 * If the site isn't in maintenance mode, should setup the addon's database
249
+	 *
250
+	 * @return void
251
+	 */
252
+	public function new_install()
253
+	{
254
+		$classname = get_class($this);
255
+		do_action("AHEE__{$classname}__new_install");
256
+		do_action('AHEE__EE_Addon__new_install', $this);
257
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
258
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
259
+			array($this, 'initialize_db_if_no_migrations_required'));
260
+	}
261
+
262
+
263
+	/**
264
+	 * Called when EE core detects this addon has been reactivated. When this happens,
265
+	 * it's good to just check that your data is still intact
266
+	 *
267
+	 * @return void
268
+	 */
269
+	public function reactivation()
270
+	{
271
+		$classname = get_class($this);
272
+		do_action("AHEE__{$classname}__reactivation");
273
+		do_action('AHEE__EE_Addon__reactivation', $this);
274
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
275
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
276
+			array($this, 'initialize_db_if_no_migrations_required'));
277
+	}
278
+
279
+
280
+	public function deactivation()
281
+	{
282
+		$classname = get_class($this);
283 283
 //		echo "Deactivating $classname";die;
284
-        do_action("AHEE__{$classname}__deactivation");
285
-        do_action('AHEE__EE_Addon__deactivation', $this);
286
-        //check if the site no longer needs to be in maintenance mode
287
-        EE_Register_Addon::deregister($this->name());
288
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
289
-    }
290
-
291
-
292
-    /**
293
-     * Takes care of double-checking that we're not in maintenance mode, and then
294
-     * initializing this addon's necessary initial data. This is called by default on new activations
295
-     * and reactivations
296
-     *
297
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
298
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
299
-     * @return void
300
-     * @throws \EE_Error
301
-     */
302
-    public function initialize_db_if_no_migrations_required($verify_schema = true)
303
-    {
304
-        if ($verify_schema === '') {
305
-            //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
306
-            //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
307
-            //calls them with an argument of an empty string (ie ""), which evaluates to false
308
-            //so we need to treat the empty string as if nothing had been passed, and should instead use the default
309
-            $verify_schema = true;
310
-        }
311
-        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
312
-            if ($verify_schema) {
313
-                $this->initialize_db();
314
-            }
315
-            $this->initialize_default_data();
316
-            //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
317
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to(
318
-                array(
319
-                    'slug'    => $this->name(),
320
-                    'version' => $this->version(),
321
-                )
322
-            );
323
-            /* make sure core's data is a-ok
284
+		do_action("AHEE__{$classname}__deactivation");
285
+		do_action('AHEE__EE_Addon__deactivation', $this);
286
+		//check if the site no longer needs to be in maintenance mode
287
+		EE_Register_Addon::deregister($this->name());
288
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
289
+	}
290
+
291
+
292
+	/**
293
+	 * Takes care of double-checking that we're not in maintenance mode, and then
294
+	 * initializing this addon's necessary initial data. This is called by default on new activations
295
+	 * and reactivations
296
+	 *
297
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
298
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
299
+	 * @return void
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function initialize_db_if_no_migrations_required($verify_schema = true)
303
+	{
304
+		if ($verify_schema === '') {
305
+			//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
306
+			//(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
307
+			//calls them with an argument of an empty string (ie ""), which evaluates to false
308
+			//so we need to treat the empty string as if nothing had been passed, and should instead use the default
309
+			$verify_schema = true;
310
+		}
311
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
312
+			if ($verify_schema) {
313
+				$this->initialize_db();
314
+			}
315
+			$this->initialize_default_data();
316
+			//@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
317
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
318
+				array(
319
+					'slug'    => $this->name(),
320
+					'version' => $this->version(),
321
+				)
322
+			);
323
+			/* make sure core's data is a-ok
324 324
              * (at the time of writing, we especially want to verify all the caps are present
325 325
              * because payment method type capabilities are added dynamically, and it's
326 326
              * possible this addon added a payment method. But it's also possible
327 327
              * other data needs to be verified)
328 328
              */
329
-            EEH_Activation::initialize_db_content();
330
-            update_option('ee_flush_rewrite_rules', true);
331
-            //in case there are lots of addons being activated at once, let's force garbage collection
332
-            //to help avoid memory limit errors
333
-            //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
334
-            gc_collect_cycles();
335
-        } else {
336
-            //ask the data migration manager to init this addon's data
337
-            //when migrations are finished because we can't do it now
338
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
339
-        }
340
-    }
341
-
342
-
343
-    /**
344
-     * Used to setup this addon's database tables, but not necessarily any default
345
-     * data in them. The default is to actually use the most up-to-date data migration script
346
-     * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
347
-     * methods to setup the db.
348
-     */
349
-    public function initialize_db()
350
-    {
351
-        //find the migration script that sets the database to be compatible with the code
352
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
353
-        if ($current_dms_name) {
354
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
355
-            $current_data_migration_script->set_migrating(false);
356
-            $current_data_migration_script->schema_changes_before_migration();
357
-            $current_data_migration_script->schema_changes_after_migration();
358
-            if ($current_data_migration_script->get_errors()) {
359
-                foreach ($current_data_migration_script->get_errors() as $error) {
360
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
361
-                }
362
-            }
363
-        }
364
-        //if not DMS was found that should be ok. This addon just doesn't require any database changes
365
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
366
-            array(
367
-                'slug'    => $this->name(),
368
-                'version' => $this->version(),
369
-            )
370
-        );
371
-    }
372
-
373
-
374
-    /**
375
-     * If you want to setup default data for the addon, override this method, and call
376
-     * parent::initialize_default_data() from within it. This is normally called
377
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
378
-     * and should verify default data is present (but this is also called
379
-     * on reactivations and just after migrations, so please verify you actually want
380
-     * to ADD default data, because it may already be present).
381
-     * However, please call this parent (currently it just fires a hook which other
382
-     * addons may be depending on)
383
-     */
384
-    public function initialize_default_data()
385
-    {
386
-        /**
387
-         * Called when an addon is ensuring its default data is set (possibly called
388
-         * on a reactivation, so first check for the absence of other data before setting
389
-         * default data)
390
-         *
391
-         * @param EE_Addon $addon the addon that called this
392
-         */
393
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
394
-        //override to insert default data. It is safe to use the models here
395
-        //because the site should not be in maintenance mode
396
-    }
397
-
398
-
399
-    /**
400
-     * EE Core detected that this addon has been upgraded. We should check if there
401
-     * are any new migration scripts, and if so put the site into maintenance mode until
402
-     * they're ran
403
-     *
404
-     * @return void
405
-     */
406
-    public function upgrade()
407
-    {
408
-        $classname = get_class($this);
409
-        do_action("AHEE__{$classname}__upgrade");
410
-        do_action('AHEE__EE_Addon__upgrade', $this);
411
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
412
-        //also it's possible there is new default data that needs to be added
413
-        add_action(
414
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
415
-            array($this, 'initialize_db_if_no_migrations_required')
416
-        );
417
-    }
418
-
419
-
420
-    /**
421
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
422
-     */
423
-    public function downgrade()
424
-    {
425
-        $classname = get_class($this);
426
-        do_action("AHEE__{$classname}__downgrade");
427
-        do_action('AHEE__EE_Addon__downgrade', $this);
428
-        //it's possible there's old default data that needs to be double-checked
429
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
430
-            array($this, 'initialize_db_if_no_migrations_required'));
431
-    }
432
-
433
-
434
-    /**
435
-     * set_db_update_option_name
436
-     * Until we do something better, we'll just check for migration scripts upon
437
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
438
-     *
439
-     * @return bool
440
-     */
441
-    public function set_db_update_option_name()
442
-    {
443
-        EE_Error::doing_it_wrong(__FUNCTION__,
444
-            __('EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
445
-                'event_espresso'), '4.3.0.alpha.016');
446
-        //let's just handle this on the next request, ok? right now we're just not really ready
447
-        return $this->set_activation_indicator_option();
448
-    }
449
-
450
-
451
-    /**
452
-     * Returns the name of the activation indicator option
453
-     * (an option which is set temporarily to indicate that this addon was just activated)
454
-     *
455
-     * @deprecated since version 4.3.0.alpha.016
456
-     * @return string
457
-     */
458
-    public function get_db_update_option_name()
459
-    {
460
-        EE_Error::doing_it_wrong(__FUNCTION__,
461
-            __('EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
462
-                'event_espresso'), '4.3.0.alpha.016');
463
-        return $this->get_activation_indicator_option_name();
464
-    }
465
-
466
-
467
-    /**
468
-     * When the addon is activated, this should be called to set a wordpress option that
469
-     * indicates it was activated. This is especially useful for detecting reactivations.
470
-     *
471
-     * @return bool
472
-     */
473
-    public function set_activation_indicator_option()
474
-    {
475
-        // let's just handle this on the next request, ok? right now we're just not really ready
476
-        return update_option($this->get_activation_indicator_option_name(), true);
477
-    }
478
-
479
-
480
-    /**
481
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
482
-     *
483
-     * @return string
484
-     */
485
-    public function get_activation_indicator_option_name()
486
-    {
487
-        return 'ee_activation_' . $this->name();
488
-    }
489
-
490
-
491
-    /**
492
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
493
-     *
494
-     * @param int $req_type
495
-     */
496
-    public function set_req_type($req_type)
497
-    {
498
-        $this->_req_type = $req_type;
499
-    }
500
-
501
-
502
-    /**
503
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
504
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
505
-     * EE_System when it is checking for new install or upgrades of addons
506
-     */
507
-    public function detect_req_type()
508
-    {
509
-        if (! $this->_req_type) {
510
-            $this->detect_activation_or_upgrade();
511
-        }
512
-        return $this->_req_type;
513
-    }
514
-
515
-
516
-    /**
517
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
518
-     * Should only be called once per request
519
-     *
520
-     * @return void
521
-     */
522
-    public function detect_activation_or_upgrade()
523
-    {
524
-        $activation_history_for_addon = $this->get_activation_history();
329
+			EEH_Activation::initialize_db_content();
330
+			update_option('ee_flush_rewrite_rules', true);
331
+			//in case there are lots of addons being activated at once, let's force garbage collection
332
+			//to help avoid memory limit errors
333
+			//EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
334
+			gc_collect_cycles();
335
+		} else {
336
+			//ask the data migration manager to init this addon's data
337
+			//when migrations are finished because we can't do it now
338
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
339
+		}
340
+	}
341
+
342
+
343
+	/**
344
+	 * Used to setup this addon's database tables, but not necessarily any default
345
+	 * data in them. The default is to actually use the most up-to-date data migration script
346
+	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
347
+	 * methods to setup the db.
348
+	 */
349
+	public function initialize_db()
350
+	{
351
+		//find the migration script that sets the database to be compatible with the code
352
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
353
+		if ($current_dms_name) {
354
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
355
+			$current_data_migration_script->set_migrating(false);
356
+			$current_data_migration_script->schema_changes_before_migration();
357
+			$current_data_migration_script->schema_changes_after_migration();
358
+			if ($current_data_migration_script->get_errors()) {
359
+				foreach ($current_data_migration_script->get_errors() as $error) {
360
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
361
+				}
362
+			}
363
+		}
364
+		//if not DMS was found that should be ok. This addon just doesn't require any database changes
365
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
366
+			array(
367
+				'slug'    => $this->name(),
368
+				'version' => $this->version(),
369
+			)
370
+		);
371
+	}
372
+
373
+
374
+	/**
375
+	 * If you want to setup default data for the addon, override this method, and call
376
+	 * parent::initialize_default_data() from within it. This is normally called
377
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
378
+	 * and should verify default data is present (but this is also called
379
+	 * on reactivations and just after migrations, so please verify you actually want
380
+	 * to ADD default data, because it may already be present).
381
+	 * However, please call this parent (currently it just fires a hook which other
382
+	 * addons may be depending on)
383
+	 */
384
+	public function initialize_default_data()
385
+	{
386
+		/**
387
+		 * Called when an addon is ensuring its default data is set (possibly called
388
+		 * on a reactivation, so first check for the absence of other data before setting
389
+		 * default data)
390
+		 *
391
+		 * @param EE_Addon $addon the addon that called this
392
+		 */
393
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
394
+		//override to insert default data. It is safe to use the models here
395
+		//because the site should not be in maintenance mode
396
+	}
397
+
398
+
399
+	/**
400
+	 * EE Core detected that this addon has been upgraded. We should check if there
401
+	 * are any new migration scripts, and if so put the site into maintenance mode until
402
+	 * they're ran
403
+	 *
404
+	 * @return void
405
+	 */
406
+	public function upgrade()
407
+	{
408
+		$classname = get_class($this);
409
+		do_action("AHEE__{$classname}__upgrade");
410
+		do_action('AHEE__EE_Addon__upgrade', $this);
411
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
412
+		//also it's possible there is new default data that needs to be added
413
+		add_action(
414
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
415
+			array($this, 'initialize_db_if_no_migrations_required')
416
+		);
417
+	}
418
+
419
+
420
+	/**
421
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
422
+	 */
423
+	public function downgrade()
424
+	{
425
+		$classname = get_class($this);
426
+		do_action("AHEE__{$classname}__downgrade");
427
+		do_action('AHEE__EE_Addon__downgrade', $this);
428
+		//it's possible there's old default data that needs to be double-checked
429
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
430
+			array($this, 'initialize_db_if_no_migrations_required'));
431
+	}
432
+
433
+
434
+	/**
435
+	 * set_db_update_option_name
436
+	 * Until we do something better, we'll just check for migration scripts upon
437
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
438
+	 *
439
+	 * @return bool
440
+	 */
441
+	public function set_db_update_option_name()
442
+	{
443
+		EE_Error::doing_it_wrong(__FUNCTION__,
444
+			__('EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
445
+				'event_espresso'), '4.3.0.alpha.016');
446
+		//let's just handle this on the next request, ok? right now we're just not really ready
447
+		return $this->set_activation_indicator_option();
448
+	}
449
+
450
+
451
+	/**
452
+	 * Returns the name of the activation indicator option
453
+	 * (an option which is set temporarily to indicate that this addon was just activated)
454
+	 *
455
+	 * @deprecated since version 4.3.0.alpha.016
456
+	 * @return string
457
+	 */
458
+	public function get_db_update_option_name()
459
+	{
460
+		EE_Error::doing_it_wrong(__FUNCTION__,
461
+			__('EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
462
+				'event_espresso'), '4.3.0.alpha.016');
463
+		return $this->get_activation_indicator_option_name();
464
+	}
465
+
466
+
467
+	/**
468
+	 * When the addon is activated, this should be called to set a wordpress option that
469
+	 * indicates it was activated. This is especially useful for detecting reactivations.
470
+	 *
471
+	 * @return bool
472
+	 */
473
+	public function set_activation_indicator_option()
474
+	{
475
+		// let's just handle this on the next request, ok? right now we're just not really ready
476
+		return update_option($this->get_activation_indicator_option_name(), true);
477
+	}
478
+
479
+
480
+	/**
481
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
482
+	 *
483
+	 * @return string
484
+	 */
485
+	public function get_activation_indicator_option_name()
486
+	{
487
+		return 'ee_activation_' . $this->name();
488
+	}
489
+
490
+
491
+	/**
492
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
493
+	 *
494
+	 * @param int $req_type
495
+	 */
496
+	public function set_req_type($req_type)
497
+	{
498
+		$this->_req_type = $req_type;
499
+	}
500
+
501
+
502
+	/**
503
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
504
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
505
+	 * EE_System when it is checking for new install or upgrades of addons
506
+	 */
507
+	public function detect_req_type()
508
+	{
509
+		if (! $this->_req_type) {
510
+			$this->detect_activation_or_upgrade();
511
+		}
512
+		return $this->_req_type;
513
+	}
514
+
515
+
516
+	/**
517
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
518
+	 * Should only be called once per request
519
+	 *
520
+	 * @return void
521
+	 */
522
+	public function detect_activation_or_upgrade()
523
+	{
524
+		$activation_history_for_addon = $this->get_activation_history();
525 525
 //		d($activation_history_for_addon);
526
-        $request_type = EE_System::detect_req_type_given_activation_history($activation_history_for_addon,
527
-            $this->get_activation_indicator_option_name(), $this->version());
528
-        $this->set_req_type($request_type);
529
-        $classname = get_class($this);
530
-        switch ($request_type) {
531
-            case EE_System::req_type_new_activation:
532
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
533
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
534
-                $this->new_install();
535
-                $this->update_list_of_installed_versions($activation_history_for_addon);
536
-                break;
537
-            case EE_System::req_type_reactivation:
538
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
539
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
540
-                $this->reactivation();
541
-                $this->update_list_of_installed_versions($activation_history_for_addon);
542
-                break;
543
-            case EE_System::req_type_upgrade:
544
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
545
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
546
-                $this->upgrade();
547
-                $this->update_list_of_installed_versions($activation_history_for_addon);
548
-                break;
549
-            case EE_System::req_type_downgrade:
550
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
551
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
552
-                $this->downgrade();
553
-                $this->update_list_of_installed_versions($activation_history_for_addon);
554
-                break;
555
-            case EE_System::req_type_normal:
556
-            default:
526
+		$request_type = EE_System::detect_req_type_given_activation_history($activation_history_for_addon,
527
+			$this->get_activation_indicator_option_name(), $this->version());
528
+		$this->set_req_type($request_type);
529
+		$classname = get_class($this);
530
+		switch ($request_type) {
531
+			case EE_System::req_type_new_activation:
532
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
533
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
534
+				$this->new_install();
535
+				$this->update_list_of_installed_versions($activation_history_for_addon);
536
+				break;
537
+			case EE_System::req_type_reactivation:
538
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
539
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
540
+				$this->reactivation();
541
+				$this->update_list_of_installed_versions($activation_history_for_addon);
542
+				break;
543
+			case EE_System::req_type_upgrade:
544
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
545
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
546
+				$this->upgrade();
547
+				$this->update_list_of_installed_versions($activation_history_for_addon);
548
+				break;
549
+			case EE_System::req_type_downgrade:
550
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
551
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
552
+				$this->downgrade();
553
+				$this->update_list_of_installed_versions($activation_history_for_addon);
554
+				break;
555
+			case EE_System::req_type_normal:
556
+			default:
557 557
 //				$this->_maybe_redirect_to_ee_about();
558
-                break;
559
-        }
560
-
561
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
562
-    }
563
-
564
-    /**
565
-     * Updates the version history for this addon
566
-     *
567
-     * @param array  $version_history
568
-     * @param string $current_version_to_add
569
-     * @return boolean success
570
-     */
571
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
572
-    {
573
-        if (! $version_history) {
574
-            $version_history = $this->get_activation_history();
575
-        }
576
-        if ($current_version_to_add === null) {
577
-            $current_version_to_add = $this->version();
578
-        }
579
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
580
-        // resave
558
+				break;
559
+		}
560
+
561
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
562
+	}
563
+
564
+	/**
565
+	 * Updates the version history for this addon
566
+	 *
567
+	 * @param array  $version_history
568
+	 * @param string $current_version_to_add
569
+	 * @return boolean success
570
+	 */
571
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
572
+	{
573
+		if (! $version_history) {
574
+			$version_history = $this->get_activation_history();
575
+		}
576
+		if ($current_version_to_add === null) {
577
+			$current_version_to_add = $this->version();
578
+		}
579
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
580
+		// resave
581 581
 //		echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history);
582
-        return update_option($this->get_activation_history_option_name(), $version_history);
583
-    }
584
-
585
-    /**
586
-     * Gets the name of the wp option that stores the activation history
587
-     * of this addon
588
-     *
589
-     * @return string
590
-     */
591
-    public function get_activation_history_option_name()
592
-    {
593
-        return self::ee_addon_version_history_option_prefix . $this->name();
594
-    }
595
-
596
-
597
-    /**
598
-     * Gets the wp option which stores the activation history for this addon
599
-     *
600
-     * @return array
601
-     */
602
-    public function get_activation_history()
603
-    {
604
-        return get_option($this->get_activation_history_option_name(), null);
605
-    }
606
-
607
-
608
-    /**
609
-     * @param string $config_section
610
-     */
611
-    public function set_config_section($config_section = '')
612
-    {
613
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
614
-    }
615
-
616
-    /**
617
-     *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
618
-     *
619
-     * @type string
620
-     */
621
-    protected $_main_plugin_file;
622
-
623
-    /**
624
-     * Sets the filepath to the main plugin file
625
-     *
626
-     * @param string $filepath
627
-     */
628
-    public function set_main_plugin_file($filepath)
629
-    {
630
-        $this->_main_plugin_file = $filepath;
631
-    }
632
-
633
-    /**
634
-     * gets the filepath to teh main file
635
-     *
636
-     * @return string
637
-     */
638
-    public function get_main_plugin_file()
639
-    {
640
-        return $this->_main_plugin_file;
641
-    }
642
-
643
-    /**
644
-     * Gets the filename (no path) of the main file (the main file loaded
645
-     * by WP)
646
-     *
647
-     * @return string
648
-     */
649
-    public function get_main_plugin_file_basename()
650
-    {
651
-        return plugin_basename($this->get_main_plugin_file());
652
-    }
653
-
654
-    /**
655
-     * Gets the folder name which contains the main plugin file
656
-     *
657
-     * @return string
658
-     */
659
-    public function get_main_plugin_file_dirname()
660
-    {
661
-        return dirname($this->get_main_plugin_file());
662
-    }
663
-
664
-
665
-    /**
666
-     * sets hooks used in the admin
667
-     *
668
-     * @return void
669
-     */
670
-    public function admin_init()
671
-    {
672
-        // is admin and not in M-Mode ?
673
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
674
-            add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
675
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
676
-        }
677
-    }
678
-
679
-
680
-    /**
681
-     * plugin_actions
682
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
683
-     *
684
-     * @param $links
685
-     * @param $file
686
-     * @return array
687
-     */
688
-    public function plugin_action_links($links, $file)
689
-    {
690
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
691
-            // before other links
692
-            array_unshift($links,
693
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __('Settings') . '</a>');
694
-        }
695
-        return $links;
696
-    }
697
-
698
-
699
-    /**
700
-     * after_plugin_row
701
-     * Add additional content to the plugins page plugin row
702
-     * Inserts another row
703
-     *
704
-     * @param $plugin_file
705
-     * @param $plugin_data
706
-     * @param $status
707
-     * @return void
708
-     */
709
-    public function after_plugin_row($plugin_file, $plugin_data, $status)
710
-    {
711
-
712
-        $after_plugin_row = '';
713
-        if ($plugin_file === $this->plugin_basename() && $this->get_plugins_page_row() !== '') {
714
-            $class            = $status ? 'active' : 'inactive';
715
-            $plugins_page_row = $this->get_plugins_page_row();
716
-            $link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
717
-            $link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
718
-            $description      = isset($plugins_page_row['description']) ? $plugins_page_row['description'] : $plugins_page_row;
719
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
721
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
722
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
723
-                $after_plugin_row .= '<style>
582
+		return update_option($this->get_activation_history_option_name(), $version_history);
583
+	}
584
+
585
+	/**
586
+	 * Gets the name of the wp option that stores the activation history
587
+	 * of this addon
588
+	 *
589
+	 * @return string
590
+	 */
591
+	public function get_activation_history_option_name()
592
+	{
593
+		return self::ee_addon_version_history_option_prefix . $this->name();
594
+	}
595
+
596
+
597
+	/**
598
+	 * Gets the wp option which stores the activation history for this addon
599
+	 *
600
+	 * @return array
601
+	 */
602
+	public function get_activation_history()
603
+	{
604
+		return get_option($this->get_activation_history_option_name(), null);
605
+	}
606
+
607
+
608
+	/**
609
+	 * @param string $config_section
610
+	 */
611
+	public function set_config_section($config_section = '')
612
+	{
613
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
614
+	}
615
+
616
+	/**
617
+	 *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
618
+	 *
619
+	 * @type string
620
+	 */
621
+	protected $_main_plugin_file;
622
+
623
+	/**
624
+	 * Sets the filepath to the main plugin file
625
+	 *
626
+	 * @param string $filepath
627
+	 */
628
+	public function set_main_plugin_file($filepath)
629
+	{
630
+		$this->_main_plugin_file = $filepath;
631
+	}
632
+
633
+	/**
634
+	 * gets the filepath to teh main file
635
+	 *
636
+	 * @return string
637
+	 */
638
+	public function get_main_plugin_file()
639
+	{
640
+		return $this->_main_plugin_file;
641
+	}
642
+
643
+	/**
644
+	 * Gets the filename (no path) of the main file (the main file loaded
645
+	 * by WP)
646
+	 *
647
+	 * @return string
648
+	 */
649
+	public function get_main_plugin_file_basename()
650
+	{
651
+		return plugin_basename($this->get_main_plugin_file());
652
+	}
653
+
654
+	/**
655
+	 * Gets the folder name which contains the main plugin file
656
+	 *
657
+	 * @return string
658
+	 */
659
+	public function get_main_plugin_file_dirname()
660
+	{
661
+		return dirname($this->get_main_plugin_file());
662
+	}
663
+
664
+
665
+	/**
666
+	 * sets hooks used in the admin
667
+	 *
668
+	 * @return void
669
+	 */
670
+	public function admin_init()
671
+	{
672
+		// is admin and not in M-Mode ?
673
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
674
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
675
+			add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
676
+		}
677
+	}
678
+
679
+
680
+	/**
681
+	 * plugin_actions
682
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
683
+	 *
684
+	 * @param $links
685
+	 * @param $file
686
+	 * @return array
687
+	 */
688
+	public function plugin_action_links($links, $file)
689
+	{
690
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
691
+			// before other links
692
+			array_unshift($links,
693
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __('Settings') . '</a>');
694
+		}
695
+		return $links;
696
+	}
697
+
698
+
699
+	/**
700
+	 * after_plugin_row
701
+	 * Add additional content to the plugins page plugin row
702
+	 * Inserts another row
703
+	 *
704
+	 * @param $plugin_file
705
+	 * @param $plugin_data
706
+	 * @param $status
707
+	 * @return void
708
+	 */
709
+	public function after_plugin_row($plugin_file, $plugin_data, $status)
710
+	{
711
+
712
+		$after_plugin_row = '';
713
+		if ($plugin_file === $this->plugin_basename() && $this->get_plugins_page_row() !== '') {
714
+			$class            = $status ? 'active' : 'inactive';
715
+			$plugins_page_row = $this->get_plugins_page_row();
716
+			$link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
717
+			$link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
718
+			$description      = isset($plugins_page_row['description']) ? $plugins_page_row['description'] : $plugins_page_row;
719
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
721
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
722
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
723
+				$after_plugin_row .= '<style>
724 724
 .ee-button,
725 725
 .ee-button:active,
726 726
 .ee-button:visited {
@@ -757,35 +757,35 @@  discard block
 block discarded – undo
757 757
 }
758 758
 .ee-button:active { top:0; }
759 759
 </style>';
760
-                $after_plugin_row .= '
760
+				$after_plugin_row .= '
761 761
 <p class="ee-addon-upsell-info-dv">
762 762
 	<a class="ee-button" href="' . $link_url . '">' . $link_text . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
763 763
 </p>';
764
-                $after_plugin_row .= '</td>';
765
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
766
-                $after_plugin_row .= $description;
767
-                $after_plugin_row .= '</td>';
768
-                $after_plugin_row .= '</tr>';
769
-            } else {
770
-                $after_plugin_row .= $description;
771
-            }
772
-        }
773
-
774
-        echo $after_plugin_row;
775
-    }
776
-
777
-
778
-    /**
779
-     * a safe space for addons to add additional logic like setting hooks
780
-     * that will run immediately after addon registration
781
-     * making this a great place for code that needs to be "omnipresent"
782
-     *
783
-     * @since 4.9.26
784
-     */
785
-    public function after_registration()
786
-    {
787
-        // cricket chirp... cricket chirp...
788
-    }
764
+				$after_plugin_row .= '</td>';
765
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
766
+				$after_plugin_row .= $description;
767
+				$after_plugin_row .= '</td>';
768
+				$after_plugin_row .= '</tr>';
769
+			} else {
770
+				$after_plugin_row .= $description;
771
+			}
772
+		}
773
+
774
+		echo $after_plugin_row;
775
+	}
776
+
777
+
778
+	/**
779
+	 * a safe space for addons to add additional logic like setting hooks
780
+	 * that will run immediately after addon registration
781
+	 * making this a great place for code that needs to be "omnipresent"
782
+	 *
783
+	 * @since 4.9.26
784
+	 */
785
+	public function after_registration()
786
+	{
787
+		// cricket chirp... cricket chirp...
788
+	}
789 789
 
790 790
 
791 791
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
     public function set_plugins_page_row($plugins_page_row = array())
236 236
     {
237 237
         // sigh.... check for example content that I stupidly merged to master and remove it if found
238
-        if (! is_array($plugins_page_row) && strpos($plugins_page_row,
238
+        if ( ! is_array($plugins_page_row) && strpos($plugins_page_row,
239 239
                 '<h3>Promotions Addon Upsell Info</h3>') !== false) {
240 240
             $plugins_page_row = '';
241 241
         }
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      */
485 485
     public function get_activation_indicator_option_name()
486 486
     {
487
-        return 'ee_activation_' . $this->name();
487
+        return 'ee_activation_'.$this->name();
488 488
     }
489 489
 
490 490
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      */
507 507
     public function detect_req_type()
508 508
     {
509
-        if (! $this->_req_type) {
509
+        if ( ! $this->_req_type) {
510 510
             $this->detect_activation_or_upgrade();
511 511
         }
512 512
         return $this->_req_type;
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
      */
571 571
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
572 572
     {
573
-        if (! $version_history) {
573
+        if ( ! $version_history) {
574 574
             $version_history = $this->get_activation_history();
575 575
         }
576 576
         if ($current_version_to_add === null) {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
      */
591 591
     public function get_activation_history_option_name()
592 592
     {
593
-        return self::ee_addon_version_history_option_prefix . $this->name();
593
+        return self::ee_addon_version_history_option_prefix.$this->name();
594 594
     }
595 595
 
596 596
 
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
         // is admin and not in M-Mode ?
673 673
         if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
674 674
             add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
675
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
675
+            add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
676 676
         }
677 677
     }
678 678
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
         if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
691 691
             // before other links
692 692
             array_unshift($links,
693
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __('Settings') . '</a>');
693
+                '<a href="admin.php?page='.$this->plugin_action_slug().'">'.__('Settings').'</a>');
694 694
         }
695 695
         return $links;
696 696
     }
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
             $link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
717 717
             $link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
718 718
             $description      = isset($plugins_page_row['description']) ? $plugins_page_row['description'] : $plugins_page_row;
719
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
719
+            if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
+                $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">';
721 721
                 $after_plugin_row .= '<th class="check-column" scope="row"></th>';
722 722
                 $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
723 723
                 $after_plugin_row .= '<style>
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 </style>';
760 760
                 $after_plugin_row .= '
761 761
 <p class="ee-addon-upsell-info-dv">
762
-	<a class="ee-button" href="' . $link_url . '">' . $link_text . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
762
+	<a class="ee-button" href="' . $link_url.'">'.$link_text.' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
763 763
 </p>';
764 764
                 $after_plugin_row .= '</td>';
765 765
                 $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         // when adding a new registration...
74 74
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
75 75
             EE_System::do_not_cache();
76
-            if (! isset($this->_req_data['processing_registration'])
76
+            if ( ! isset($this->_req_data['processing_registration'])
77 77
                  || absint($this->_req_data['processing_registration']) !== 1
78 78
             ) {
79 79
                 // and it's NOT the attendee information reg step
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     public function _set_page_routes()
169 169
     {
170 170
         $this->_get_registration_status_array();
171
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
171
+        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
172 172
             ? $this->_req_data['_REG_ID'] : 0;
173 173
         $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
174 174
             ? $this->_req_data['reg_status_change_form']['REG_ID']
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
         //style
659 659
         wp_register_style(
660 660
             'espresso_reg',
661
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
661
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
662 662
             array('ee-admin-css'),
663 663
             EVENT_ESPRESSO_VERSION
664 664
         );
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
         //script
667 667
         wp_register_script(
668 668
             'espresso_reg',
669
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
669
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
670 670
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671 671
             EVENT_ESPRESSO_VERSION,
672 672
             true
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         wp_deregister_style('espresso_reg');
705 705
         wp_register_style(
706 706
             'espresso_att',
707
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
707
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
708 708
             array('ee-admin-css'),
709 709
             EVENT_ESPRESSO_VERSION
710 710
         );
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     {
717 717
         wp_register_script(
718 718
             'ee-spco-for-admin',
719
-            REG_ASSETS_URL . 'spco_for_admin.js',
719
+            REG_ASSETS_URL.'spco_for_admin.js',
720 720
             array('underscore', 'jquery'),
721 721
             EVENT_ESPRESSO_VERSION,
722 722
             true
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
850 850
                 ),
851 851
             );
852
-            $this->_views['trash']      = array(
852
+            $this->_views['trash'] = array(
853 853
                 'slug'        => 'trash',
854 854
                 'label'       => esc_html__('Trash', 'event_espresso'),
855 855
                 'count'       => 0,
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
         }
939 939
         $sc_items = array(
940 940
             'approved_status'   => array(
941
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
941
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
942 942
                 'desc'  => EEH_Template::pretty_status(
943 943
                     EEM_Registration::status_id_approved,
944 944
                     false,
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
                 ),
947 947
             ),
948 948
             'pending_status'    => array(
949
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
949
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
950 950
                 'desc'  => EEH_Template::pretty_status(
951 951
                     EEM_Registration::status_id_pending_payment,
952 952
                     false,
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
                 ),
955 955
             ),
956 956
             'wait_list'         => array(
957
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
957
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
958 958
                 'desc'  => EEH_Template::pretty_status(
959 959
                     EEM_Registration::status_id_wait_list,
960 960
                     false,
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
                 ),
963 963
             ),
964 964
             'incomplete_status' => array(
965
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
965
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
966 966
                 'desc'  => EEH_Template::pretty_status(
967 967
                     EEM_Registration::status_id_incomplete,
968 968
                     false,
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
                 ),
971 971
             ),
972 972
             'not_approved'      => array(
973
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
973
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
974 974
                 'desc'  => EEH_Template::pretty_status(
975 975
                     EEM_Registration::status_id_not_approved,
976 976
                     false,
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
                 ),
979 979
             ),
980 980
             'declined_status'   => array(
981
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
981
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
982 982
                 'desc'  => EEH_Template::pretty_status(
983 983
                     EEM_Registration::status_id_declined,
984 984
                     false,
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
                 ),
987 987
             ),
988 988
             'cancelled_status'  => array(
989
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
989
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
990 990
                 'desc'  => EEH_Template::pretty_status(
991 991
                     EEM_Registration::status_id_cancelled,
992 992
                     false,
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
                 'espresso_registrations_new_registration',
1016 1016
                 $EVT_ID
1017 1017
             )) {
1018
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1018
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1019 1019
                     'new_registration',
1020 1020
                     'add-registrant',
1021 1021
                     array('event_id' => $EVT_ID),
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1056 1056
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1057 1057
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1058
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1058
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1059 1059
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1060 1060
             }
1061 1061
         }
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
             'caps'                     => EEM_Registration::caps_read_admin,
1156 1156
             'default_where_conditions' => 'this_model_only',
1157 1157
         );
1158
-        if (! $count) {
1158
+        if ( ! $count) {
1159 1159
             $query_params = array_merge(
1160 1160
                 $query_params,
1161 1161
                 $this->_get_orderby_for_registrations_query(),
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
     protected function _add_event_id_to_where_conditions(array $request)
1177 1177
     {
1178 1178
         $where = array();
1179
-        if (! empty($request['event_id'])) {
1179
+        if ( ! empty($request['event_id'])) {
1180 1180
             $where['EVT_ID'] = absint($request['event_id']);
1181 1181
         }
1182 1182
         return $where;
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
     protected function _add_category_id_to_where_conditions(array $request)
1193 1193
     {
1194 1194
         $where = array();
1195
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1195
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1196 1196
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1197 1197
         }
1198 1198
         return $where;
@@ -1208,10 +1208,10 @@  discard block
 block discarded – undo
1208 1208
     protected function _add_datetime_id_to_where_conditions(array $request)
1209 1209
     {
1210 1210
         $where = array();
1211
-        if (! empty($request['datetime_id'])) {
1211
+        if ( ! empty($request['datetime_id'])) {
1212 1212
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1213 1213
         }
1214
-        if (! empty($request['DTT_ID'])) {
1214
+        if ( ! empty($request['DTT_ID'])) {
1215 1215
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1216 1216
         }
1217 1217
         return $where;
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1238 1238
          * UNLESS viewing trashed registrations.
1239 1239
          */
1240
-        if (! empty($registration_status)) {
1240
+        if ( ! empty($registration_status)) {
1241 1241
             $where['STS_ID'] = $registration_status;
1242 1242
         } else {
1243 1243
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1277,12 +1277,12 @@  discard block
 block discarded – undo
1277 1277
                 array(
1278 1278
                     EEM_Registration::instance()->convert_datetime_for_query(
1279 1279
                         'REG_date',
1280
-                        $now . ' 00:00:00',
1280
+                        $now.' 00:00:00',
1281 1281
                         'Y-m-d H:i:s'
1282 1282
                     ),
1283 1283
                     EEM_Registration::instance()->convert_datetime_for_query(
1284 1284
                         'REG_date',
1285
-                        $now . ' 23:59:59',
1285
+                        $now.' 23:59:59',
1286 1286
                         'Y-m-d H:i:s'
1287 1287
                     ),
1288 1288
                 ),
@@ -1295,12 +1295,12 @@  discard block
 block discarded – undo
1295 1295
                 array(
1296 1296
                     EEM_Registration::instance()->convert_datetime_for_query(
1297 1297
                         'REG_date',
1298
-                        $current_year_and_month . '-01 00:00:00',
1298
+                        $current_year_and_month.'-01 00:00:00',
1299 1299
                         'Y-m-d H:i:s'
1300 1300
                     ),
1301 1301
                     EEM_Registration::instance()->convert_datetime_for_query(
1302 1302
                         'REG_date',
1303
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1303
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1304 1304
                         'Y-m-d H:i:s'
1305 1305
                     ),
1306 1306
                 ),
@@ -1315,18 +1315,18 @@  discard block
 block discarded – undo
1315 1315
                 : '';
1316 1316
             //if there is not a month or year then we can't go further
1317 1317
             if ($month_requested && $year_requested) {
1318
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1318
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1319 1319
                 $where['REG_date'] = array(
1320 1320
                     'BETWEEN',
1321 1321
                     array(
1322 1322
                         EEM_Registration::instance()->convert_datetime_for_query(
1323 1323
                             'REG_date',
1324
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1324
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1325 1325
                             'Y-m-d H:i:s'
1326 1326
                         ),
1327 1327
                         EEM_Registration::instance()->convert_datetime_for_query(
1328 1328
                             'REG_date',
1329
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1329
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1330 1330
                             'Y-m-d H:i:s'
1331 1331
                         ),
1332 1332
                     ),
@@ -1346,8 +1346,8 @@  discard block
 block discarded – undo
1346 1346
     protected function _add_search_to_where_conditions(array $request)
1347 1347
     {
1348 1348
         $where = array();
1349
-        if (! empty($request['s'])) {
1350
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1349
+        if ( ! empty($request['s'])) {
1350
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1351 1351
             $where['OR*search_conditions'] = array(
1352 1352
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1353 1353
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
             : $per_page;
1461 1461
 
1462 1462
         //-1 means return all results so get out if that's set.
1463
-        if ((int)$per_page === -1) {
1463
+        if ((int) $per_page === -1) {
1464 1464
             return array();
1465 1465
         }
1466 1466
         $per_page = absint($per_page);
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
                 ),
1514 1514
                 REG_ADMIN_URL
1515 1515
             );
1516
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1516
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1517 1517
                 array(
1518 1518
                     'action' => 'default',
1519 1519
                     'EVT_ID' => $event_id,
@@ -1521,7 +1521,7 @@  discard block
 block discarded – undo
1521 1521
                 ),
1522 1522
                 admin_url('admin.php')
1523 1523
             );
1524
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1524
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1525 1525
                 array(
1526 1526
                     'page'   => 'espresso_events',
1527 1527
                     'action' => 'edit',
@@ -1530,12 +1530,12 @@  discard block
 block discarded – undo
1530 1530
                 admin_url('admin.php')
1531 1531
             );
1532 1532
             //next and previous links
1533
-            $next_reg                                      = $this->_registration->next(
1533
+            $next_reg = $this->_registration->next(
1534 1534
                 null,
1535 1535
                 array(),
1536 1536
                 'REG_ID'
1537 1537
             );
1538
-            $this->_template_args['next_registration']     = $next_reg
1538
+            $this->_template_args['next_registration'] = $next_reg
1539 1539
                 ? $this->_next_link(
1540 1540
                     EE_Admin_Page::add_query_args_and_nonce(
1541 1541
                         array(
@@ -1547,7 +1547,7 @@  discard block
 block discarded – undo
1547 1547
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1548 1548
                 )
1549 1549
                 : '';
1550
-            $previous_reg                                  = $this->_registration->previous(
1550
+            $previous_reg = $this->_registration->previous(
1551 1551
                 null,
1552 1552
                 array(),
1553 1553
                 'REG_ID'
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
                 )
1566 1566
                 : '';
1567 1567
             // grab header
1568
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1568
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1569 1569
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1570 1570
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1571 1571
                 $template_path,
@@ -1682,7 +1682,7 @@  discard block
 block discarded – undo
1682 1682
                             EEH_HTML::strong(
1683 1683
                                 $this->_registration->pretty_status(),
1684 1684
                                 '',
1685
-                                'status-' . $this->_registration->status_ID(),
1685
+                                'status-'.$this->_registration->status_ID(),
1686 1686
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1687 1687
                             )
1688 1688
                         )
@@ -1758,11 +1758,11 @@  discard block
 block discarded – undo
1758 1758
     {
1759 1759
         if (isset($this->_req_data['reg_status_change_form'])) {
1760 1760
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1761
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1761
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1762 1762
                 : array();
1763 1763
         } else {
1764 1764
             $REG_IDs = isset($this->_req_data['_REG_ID'])
1765
-                ? (array)$this->_req_data['_REG_ID']
1765
+                ? (array) $this->_req_data['_REG_ID']
1766 1766
                 : array();
1767 1767
         }
1768 1768
         // sanitize $REG_IDs
@@ -1807,7 +1807,7 @@  discard block
 block discarded – undo
1807 1807
     {
1808 1808
         $success = false;
1809 1809
         // typecast $REG_IDs
1810
-        $REG_IDs = (array)$REG_IDs;
1810
+        $REG_IDs = (array) $REG_IDs;
1811 1811
         if ( ! empty($REG_IDs)) {
1812 1812
             $success = true;
1813 1813
             // set default status if none is passed
@@ -1944,7 +1944,7 @@  discard block
 block discarded – undo
1944 1944
             $action,
1945 1945
             $notify
1946 1946
         );
1947
-        $method = $action . '_registration';
1947
+        $method = $action.'_registration';
1948 1948
         if (method_exists($this, $method)) {
1949 1949
             $this->$method($notify);
1950 1950
         }
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
             $filtered_line_item_tree,
2059 2059
             array('EE_Registration' => $this->_registration)
2060 2060
         );
2061
-        $attendee                                = $this->_registration->attendee();
2061
+        $attendee = $this->_registration->attendee();
2062 2062
         if (EE_Registry::instance()->CAP->current_user_can(
2063 2063
             'ee_read_transaction',
2064 2064
             'espresso_transactions_view_transaction'
@@ -2137,7 +2137,7 @@  discard block
 block discarded – undo
2137 2137
                 'Payment method response',
2138 2138
                 'event_espresso'
2139 2139
             );
2140
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2140
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2141 2141
         }
2142 2142
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2143 2143
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2165,7 +2165,7 @@  discard block
 block discarded – undo
2165 2165
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2166 2166
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2167 2167
         $template_path                                                        =
2168
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2168
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2169 2169
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2170 2170
     }
2171 2171
 
@@ -2194,7 +2194,7 @@  discard block
 block discarded – undo
2194 2194
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2195 2195
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2196 2196
             $template_path                                     =
2197
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2197
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2198 2198
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2199 2199
         }
2200 2200
     }
@@ -2211,7 +2211,7 @@  discard block
 block discarded – undo
2211 2211
     public function form_before_question_group($output)
2212 2212
     {
2213 2213
         EE_Error::doing_it_wrong(
2214
-            __CLASS__ . '::' . __FUNCTION__,
2214
+            __CLASS__.'::'.__FUNCTION__,
2215 2215
             esc_html__(
2216 2216
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2217 2217
                 'event_espresso'
@@ -2236,7 +2236,7 @@  discard block
 block discarded – undo
2236 2236
     public function form_after_question_group($output)
2237 2237
     {
2238 2238
         EE_Error::doing_it_wrong(
2239
-            __CLASS__ . '::' . __FUNCTION__,
2239
+            __CLASS__.'::'.__FUNCTION__,
2240 2240
             esc_html__(
2241 2241
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2242 2242
                 'event_espresso'
@@ -2274,7 +2274,7 @@  discard block
 block discarded – undo
2274 2274
     public function form_form_field_label_wrap($label)
2275 2275
     {
2276 2276
         EE_Error::doing_it_wrong(
2277
-            __CLASS__ . '::' . __FUNCTION__,
2277
+            __CLASS__.'::'.__FUNCTION__,
2278 2278
             esc_html__(
2279 2279
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2280 2280
                 'event_espresso'
@@ -2284,7 +2284,7 @@  discard block
 block discarded – undo
2284 2284
         return '
2285 2285
 			<tr>
2286 2286
 				<th>
2287
-					' . $label . '
2287
+					' . $label.'
2288 2288
 				</th>';
2289 2289
     }
2290 2290
 
@@ -2300,7 +2300,7 @@  discard block
 block discarded – undo
2300 2300
     public function form_form_field_input__wrap($input)
2301 2301
     {
2302 2302
         EE_Error::doing_it_wrong(
2303
-            __CLASS__ . '::' . __FUNCTION__,
2303
+            __CLASS__.'::'.__FUNCTION__,
2304 2304
             esc_html__(
2305 2305
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2306 2306
                 'event_espresso'
@@ -2309,7 +2309,7 @@  discard block
 block discarded – undo
2309 2309
         );
2310 2310
         return '
2311 2311
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2312
-					' . $input . '
2312
+					' . $input.'
2313 2313
 				</td>
2314 2314
 			</tr>';
2315 2315
     }
@@ -2351,7 +2351,7 @@  discard block
 block discarded – undo
2351 2351
     protected function _get_reg_custom_questions_form($REG_ID)
2352 2352
     {
2353 2353
         if ( ! $this->_reg_custom_questions_form) {
2354
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2354
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2355 2355
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2356 2356
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2357 2357
             );
@@ -2384,7 +2384,7 @@  discard block
 block discarded – undo
2384 2384
         if ($form->is_valid()) {
2385 2385
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2386 2386
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2387
-                    $where_conditions    = array(
2387
+                    $where_conditions = array(
2388 2388
                         'QST_ID' => $question_id,
2389 2389
                         'REG_ID' => $REG_ID,
2390 2390
                     );
@@ -2422,7 +2422,7 @@  discard block
 block discarded – undo
2422 2422
         $REG = EEM_Registration::instance();
2423 2423
         //get all other registrations on this transaction, and cache
2424 2424
         //the attendees for them so we don't have to run another query using force_join
2425
-        $registrations                           = $REG->get_all(array(
2425
+        $registrations = $REG->get_all(array(
2426 2426
             array(
2427 2427
                 'TXN_ID' => $this->_registration->transaction_ID(),
2428 2428
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2446,7 +2446,7 @@  discard block
 block discarded – undo
2446 2446
             $att_nmbr = 1;
2447 2447
             foreach ($registrations as $registration) {
2448 2448
                 /* @var $registration EE_Registration */
2449
-                $attendee                                                    = $registration->attendee()
2449
+                $attendee = $registration->attendee()
2450 2450
                     ? $registration->attendee()
2451 2451
                     : EEM_Attendee::instance()
2452 2452
                                   ->create_default_object();
@@ -2459,19 +2459,19 @@  discard block
 block discarded – undo
2459 2459
                     ', ',
2460 2460
                     $attendee->full_address_as_array()
2461 2461
                 );
2462
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2462
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2463 2463
                     array(
2464 2464
                         'action' => 'edit_attendee',
2465 2465
                         'post'   => $attendee->ID(),
2466 2466
                     ),
2467 2467
                     REG_ADMIN_URL
2468 2468
                 );
2469
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2469
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2470 2470
                 $att_nmbr++;
2471 2471
             }
2472 2472
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2473 2473
         }
2474
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2474
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2475 2475
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2476 2476
     }
2477 2477
 
@@ -2511,20 +2511,20 @@  discard block
 block discarded – undo
2511 2511
         $this->_template_args['phone']             = $attendee->phone();
2512 2512
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2513 2513
         //edit link
2514
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2514
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2515 2515
             'action' => 'edit_attendee',
2516 2516
             'post'   => $attendee->ID(),
2517 2517
         ), REG_ADMIN_URL);
2518 2518
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2519 2519
         //create link
2520
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2520
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2521 2521
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2522 2522
                 'action'  => 'duplicate_attendee',
2523 2523
                 '_REG_ID' => $this->_registration->ID(),
2524 2524
             ), REG_ADMIN_URL) : '';
2525 2525
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2526 2526
         $this->_template_args['att_check']    = $att_check;
2527
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2527
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2528 2528
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2529 2529
     }
2530 2530
 
@@ -2566,7 +2566,7 @@  discard block
 block discarded – undo
2566 2566
             /** @var EE_Registration $REG */
2567 2567
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2568 2568
             $payments = $REG->registration_payments();
2569
-            if (! empty($payments)) {
2569
+            if ( ! empty($payments)) {
2570 2570
                 $name = $REG->attendee() instanceof EE_Attendee
2571 2571
                     ? $REG->attendee()->full_name()
2572 2572
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2759,7 +2759,7 @@  discard block
 block discarded – undo
2759 2759
                 'action' => 'edit',
2760 2760
                 'post'   => $this->_reg_event->ID(),
2761 2761
             ), EVENTS_ADMIN_URL);
2762
-            $edit_event_lnk                     = '<a href="'
2762
+            $edit_event_lnk = '<a href="'
2763 2763
                                                   . $edit_event_url
2764 2764
                                                   . '" title="'
2765 2765
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2777,7 +2777,7 @@  discard block
 block discarded – undo
2777 2777
         }
2778 2778
         // grab header
2779 2779
         $template_path                              =
2780
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2780
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2781 2781
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2782 2782
             $this->_template_args, true);
2783 2783
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2812,7 +2812,7 @@  discard block
 block discarded – undo
2812 2812
                 '</b>'
2813 2813
             );
2814 2814
             return '
2815
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2815
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2816 2816
 	<script >
2817 2817
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2818 2818
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2880,7 +2880,7 @@  discard block
 block discarded – undo
2880 2880
         //we come back to the process_registration_step route.
2881 2881
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2882 2882
         return EEH_Template::display_template(
2883
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2883
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2884 2884
             $template_args,
2885 2885
             true
2886 2886
         );
@@ -2899,7 +2899,7 @@  discard block
 block discarded – undo
2899 2899
         if (is_object($this->_reg_event)) {
2900 2900
             return true;
2901 2901
         }
2902
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2902
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2903 2903
         if ( ! $EVT_ID) {
2904 2904
             return false;
2905 2905
         }
@@ -2965,7 +2965,7 @@  discard block
 block discarded – undo
2965 2965
                 }
2966 2966
                 break;
2967 2967
             case 'questions' :
2968
-                if (! isset(
2968
+                if ( ! isset(
2969 2969
                     $this->_req_data['txn_reg_status_change'],
2970 2970
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
2971 2971
                 ) {
@@ -3079,7 +3079,7 @@  discard block
 block discarded – undo
3079 3079
     public function get_attendees($per_page, $count = false, $trash = false)
3080 3080
     {
3081 3081
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3082
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3082
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3083 3083
         $ATT_MDL                    = EEM_Attendee::instance();
3084 3084
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3085 3085
         switch ($this->_req_data['orderby']) {
@@ -3116,7 +3116,7 @@  discard block
 block discarded – undo
3116 3116
             : $per_page;
3117 3117
         $_where       = array();
3118 3118
         if ( ! empty($this->_req_data['s'])) {
3119
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3119
+            $sstr         = '%'.$this->_req_data['s'].'%';
3120 3120
             $_where['OR'] = array(
3121 3121
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3122 3122
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3192,9 +3192,9 @@  discard block
 block discarded – undo
3192 3192
      *                                                     the query parameters from the request
3193 3193
      * @return void ends the request with a redirect or download
3194 3194
      */
3195
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3195
+    public function _registrations_report_base($method_name_for_getting_query_params)
3196 3196
     {
3197
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3197
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3198 3198
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3199 3199
                 array(
3200 3200
                     'page'        => 'espresso_batch',
@@ -3203,7 +3203,7 @@  discard block
 block discarded – undo
3203 3203
                     'filters'     => urlencode(
3204 3204
                         serialize(
3205 3205
                             call_user_func(
3206
-                                array( $this, $method_name_for_getting_query_params ),
3206
+                                array($this, $method_name_for_getting_query_params),
3207 3207
                                 EEH_Array::is_set(
3208 3208
                                     $this->_req_data,
3209 3209
                                     'filters',
@@ -3223,8 +3223,8 @@  discard block
 block discarded – undo
3223 3223
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3224 3224
             );
3225 3225
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3226
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3227
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3226
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3227
+                require_once(EE_CLASSES.'EE_Export.class.php');
3228 3228
                 $EE_Export = EE_Export::instance($this->_req_data);
3229 3229
                 $EE_Export->export();
3230 3230
             }
@@ -3245,8 +3245,8 @@  discard block
 block discarded – undo
3245 3245
 
3246 3246
     public function _contact_list_export()
3247 3247
     {
3248
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3249
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3248
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3249
+            require_once(EE_CLASSES.'EE_Export.class.php');
3250 3250
             $EE_Export = EE_Export::instance($this->_req_data);
3251 3251
             $EE_Export->export_attendees();
3252 3252
         }
@@ -3263,8 +3263,8 @@  discard block
 block discarded – undo
3263 3263
                 'return_url'  => urlencode($this->_req_data['return_url']),
3264 3264
             )));
3265 3265
         } else {
3266
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3267
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3266
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3267
+                require_once(EE_CLASSES.'EE_Export.class.php');
3268 3268
                 $EE_Export = EE_Export::instance($this->_req_data);
3269 3269
                 $EE_Export->report_attendees();
3270 3270
             }
@@ -3330,7 +3330,7 @@  discard block
 block discarded – undo
3330 3330
             $updated_fields = array(
3331 3331
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3332 3332
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3333
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3333
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3334 3334
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3335 3335
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3336 3336
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3463,7 +3463,7 @@  discard block
 block discarded – undo
3463 3463
     {
3464 3464
         //get attendee object ( should already have it )
3465 3465
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3466
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3466
+        $template                         = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php';
3467 3467
         EEH_Template::display_template($template, $this->_template_args);
3468 3468
     }
3469 3469
 
@@ -3525,8 +3525,8 @@  discard block
 block discarded – undo
3525 3525
                 )
3526 3526
             )
3527 3527
         );
3528
-        $template                             =
3529
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3528
+        $template =
3529
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3530 3530
         EEH_Template::display_template($template, $this->_template_args);
3531 3531
     }
3532 3532
 
@@ -3545,7 +3545,7 @@  discard block
 block discarded – undo
3545 3545
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3546 3546
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3547 3547
         $template                              =
3548
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3548
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3549 3549
         EEH_Template::display_template($template, $this->_template_args);
3550 3550
     }
3551 3551
 
@@ -3560,7 +3560,7 @@  discard block
 block discarded – undo
3560 3560
     public function after_title_form_fields($post)
3561 3561
     {
3562 3562
         if ($post->post_type == 'espresso_attendees') {
3563
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3563
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3564 3564
             $template_args['attendee'] = $this->_cpt_model_obj;
3565 3565
             EEH_Template::display_template($template, $template_args);
3566 3566
         }
Please login to merge, or discard this patch.
Indentation   +3584 added lines, -3584 removed lines patch added patch discarded remove patch
@@ -30,2271 +30,2271 @@  discard block
 block discarded – undo
30 30
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
31 31
 {
32 32
 
33
-    /**
34
-     * @var EE_Registration
35
-     */
36
-    private $_registration;
37
-
38
-    /**
39
-     * @var EE_Event
40
-     */
41
-    private $_reg_event;
42
-
43
-    /**
44
-     * @var EE_Session
45
-     */
46
-    private $_session;
47
-
48
-    private static $_reg_status;
49
-
50
-    /**
51
-     * Form for displaying the custom questions for this registration.
52
-     * This gets used a few times throughout the request so its best to cache it
53
-     *
54
-     * @var EE_Registration_Custom_Questions_Form
55
-     */
56
-    protected $_reg_custom_questions_form = null;
57
-
58
-
59
-    /**
60
-     *        constructor
61
-     *
62
-     * @Constructor
63
-     * @access public
64
-     * @param bool $routing
65
-     * @return Registrations_Admin_Page
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        parent::__construct($routing);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'));
71
-    }
72
-
73
-
74
-    public function wp_loaded()
75
-    {
76
-        // when adding a new registration...
77
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
-            EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
80
-                 || absint($this->_req_data['processing_registration']) !== 1
81
-            ) {
82
-                // and it's NOT the attendee information reg step
83
-                // force cookie expiration by setting time to last week
84
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
-                // and update the global
86
-                $_COOKIE['ee_registration_added'] = 0;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-    protected function _init_page_props()
93
-    {
94
-        $this->page_slug        = REG_PG_SLUG;
95
-        $this->_admin_base_url  = REG_ADMIN_URL;
96
-        $this->_admin_base_path = REG_ADMIN;
97
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
98
-        $this->_cpt_routes      = array(
99
-            'add_new_attendee' => 'espresso_attendees',
100
-            'edit_attendee'    => 'espresso_attendees',
101
-            'insert_attendee'  => 'espresso_attendees',
102
-            'update_attendee'  => 'espresso_attendees',
103
-        );
104
-        $this->_cpt_model_names = array(
105
-            'add_new_attendee' => 'EEM_Attendee',
106
-            'edit_attendee'    => 'EEM_Attendee',
107
-        );
108
-        $this->_cpt_edit_routes = array(
109
-            'espresso_attendees' => 'edit_attendee',
110
-        );
111
-        $this->_pagenow_map     = array(
112
-            'add_new_attendee' => 'post-new.php',
113
-            'edit_attendee'    => 'post.php',
114
-            'trash'            => 'post.php',
115
-        );
116
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
-        //add filters so that the comment urls don't take users to a confusing 404 page
118
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
-    }
120
-
121
-
122
-    public function clear_comment_link($link, $comment, $args)
123
-    {
124
-        //gotta make sure this only happens on this route
125
-        $post_type = get_post_type($comment->comment_post_ID);
126
-        if ($post_type === 'espresso_attendees') {
127
-            return '#commentsdiv';
128
-        }
129
-        return $link;
130
-    }
131
-
132
-
133
-    protected function _ajax_hooks()
134
-    {
135
-        //todo: all hooks for registrations ajax goes in here
136
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
-    }
138
-
139
-
140
-    protected function _define_page_props()
141
-    {
142
-        $this->_admin_page_title = $this->page_label;
143
-        $this->_labels           = array(
144
-            'buttons'                      => array(
145
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
-            ),
154
-            'publishbox'                   => array(
155
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
-            ),
158
-            'hide_add_button_on_cpt_route' => array(
159
-                'edit_attendee' => true,
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     *        grab url requests and route them
167
-     *
168
-     * @access private
169
-     * @return void
170
-     */
171
-    public function _set_page_routes()
172
-    {
173
-        $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
-            ? $this->_req_data['_REG_ID'] : 0;
176
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
178
-            : $reg_id;
179
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
-            ? $this->_req_data['ATT_ID'] : 0;
181
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
-            ? $this->_req_data['post']
183
-            : $att_id;
184
-        $this->_page_routes = array(
185
-            'default'                            => array(
186
-                'func'       => '_registrations_overview_list_table',
187
-                'capability' => 'ee_read_registrations',
188
-            ),
189
-            'view_registration'                  => array(
190
-                'func'       => '_registration_details',
191
-                'capability' => 'ee_read_registration',
192
-                'obj_id'     => $reg_id,
193
-            ),
194
-            'edit_registration'                  => array(
195
-                'func'               => '_update_attendee_registration_form',
196
-                'noheader'           => true,
197
-                'headers_sent_route' => 'view_registration',
198
-                'capability'         => 'ee_edit_registration',
199
-                'obj_id'             => $reg_id,
200
-                '_REG_ID'            => $reg_id,
201
-            ),
202
-            'trash_registrations'                => array(
203
-                'func'       => '_trash_or_restore_registrations',
204
-                'args'       => array('trash' => true),
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'restore_registrations'              => array(
209
-                'func'       => '_trash_or_restore_registrations',
210
-                'args'       => array('trash' => false),
211
-                'noheader'   => true,
212
-                'capability' => 'ee_delete_registrations',
213
-            ),
214
-            'delete_registrations'               => array(
215
-                'func'       => '_delete_registrations',
216
-                'noheader'   => true,
217
-                'capability' => 'ee_delete_registrations',
218
-            ),
219
-            'new_registration'                   => array(
220
-                'func'       => 'new_registration',
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'process_reg_step'                   => array(
224
-                'func'       => 'process_reg_step',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registrations',
227
-            ),
228
-            'redirect_to_txn'                    => array(
229
-                'func'       => 'redirect_to_txn',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registrations',
232
-            ),
233
-            'change_reg_status'                  => array(
234
-                'func'       => '_change_reg_status',
235
-                'noheader'   => true,
236
-                'capability' => 'ee_edit_registration',
237
-                'obj_id'     => $reg_id,
238
-            ),
239
-            'approve_registration'               => array(
240
-                'func'       => 'approve_registration',
241
-                'noheader'   => true,
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_and_notify_registration'    => array(
246
-                'func'       => 'approve_registration',
247
-                'noheader'   => true,
248
-                'args'       => array(true),
249
-                'capability' => 'ee_edit_registration',
250
-                'obj_id'     => $reg_id,
251
-            ),
252
-            'approve_registrations'               => array(
253
-                'func'       => 'bulk_action_on_registrations',
254
-                'noheader'   => true,
255
-                'capability' => 'ee_edit_registrations',
256
-                'args' => array('approve')
257
-            ),
258
-            'approve_and_notify_registrations'               => array(
259
-                'func'       => 'bulk_action_on_registrations',
260
-                'noheader'   => true,
261
-                'capability' => 'ee_edit_registrations',
262
-                'args' => array('approve', true)
263
-            ),
264
-            'decline_registration'               => array(
265
-                'func'       => 'decline_registration',
266
-                'noheader'   => true,
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_and_notify_registration'    => array(
271
-                'func'       => 'decline_registration',
272
-                'noheader'   => true,
273
-                'args'       => array(true),
274
-                'capability' => 'ee_edit_registration',
275
-                'obj_id'     => $reg_id,
276
-            ),
277
-            'decline_registrations'               => array(
278
-                'func'       => 'bulk_action_on_registrations',
279
-                'noheader'   => true,
280
-                'capability' => 'ee_edit_registrations',
281
-                'args' => array('decline')
282
-            ),
283
-            'decline_and_notify_registrations'    => array(
284
-                'func'       => 'bulk_action_on_registrations',
285
-                'noheader'   => true,
286
-                'capability' => 'ee_edit_registrations',
287
-                'args' => array('decline', true)
288
-            ),
289
-            'pending_registration'               => array(
290
-                'func'       => 'pending_registration',
291
-                'noheader'   => true,
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_and_notify_registration'    => array(
296
-                'func'       => 'pending_registration',
297
-                'noheader'   => true,
298
-                'args'       => array(true),
299
-                'capability' => 'ee_edit_registration',
300
-                'obj_id'     => $reg_id,
301
-            ),
302
-            'pending_registrations'               => array(
303
-                'func'       => 'bulk_action_on_registrations',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-                'args' => array('pending')
307
-            ),
308
-            'pending_and_notify_registrations'    => array(
309
-                'func'       => 'bulk_action_on_registrations',
310
-                'noheader'   => true,
311
-                'capability' => 'ee_edit_registrations',
312
-                'args' => array('pending', true)
313
-            ),
314
-            'no_approve_registration'            => array(
315
-                'func'       => 'not_approve_registration',
316
-                'noheader'   => true,
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_and_notify_registration' => array(
321
-                'func'       => 'not_approve_registration',
322
-                'noheader'   => true,
323
-                'args'       => array(true),
324
-                'capability' => 'ee_edit_registration',
325
-                'obj_id'     => $reg_id,
326
-            ),
327
-            'no_approve_registrations'            => array(
328
-                'func'       => 'bulk_action_on_registrations',
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_registrations',
331
-                'args' => array('not_approve')
332
-            ),
333
-            'no_approve_and_notify_registrations' => array(
334
-                'func'       => 'bulk_action_on_registrations',
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_registrations',
337
-                'args' => array('not_approve', true)
338
-            ),
339
-            'cancel_registration'                => array(
340
-                'func'       => 'cancel_registration',
341
-                'noheader'   => true,
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_and_notify_registration'     => array(
346
-                'func'       => 'cancel_registration',
347
-                'noheader'   => true,
348
-                'args'       => array(true),
349
-                'capability' => 'ee_edit_registration',
350
-                'obj_id'     => $reg_id,
351
-            ),
352
-            'cancel_registrations'                => array(
353
-                'func'       => 'bulk_action_on_registrations',
354
-                'noheader'   => true,
355
-                'capability' => 'ee_edit_registrations',
356
-                'args' => array('cancel')
357
-            ),
358
-            'cancel_and_notify_registrations'     => array(
359
-                'func'       => 'bulk_action_on_registrations',
360
-                'noheader'   => true,
361
-                'capability' => 'ee_edit_registrations',
362
-                'args' => array('cancel', true)
363
-            ),
364
-            'wait_list_registration' => array(
365
-                'func'       => 'wait_list_registration',
366
-                'noheader'   => true,
367
-                'capability' => 'ee_edit_registration',
368
-                'obj_id'     => $reg_id,
369
-            ),
370
-            'wait_list_and_notify_registration' => array(
371
-                'func'       => 'wait_list_registration',
372
-                'noheader'   => true,
373
-                'args'       => array(true),
374
-                'capability' => 'ee_edit_registration',
375
-                'obj_id'     => $reg_id,
376
-            ),
377
-            'contact_list'                       => array(
378
-                'func'       => '_attendee_contact_list_table',
379
-                'capability' => 'ee_read_contacts',
380
-            ),
381
-            'add_new_attendee'                   => array(
382
-                'func' => '_create_new_cpt_item',
383
-                'args' => array(
384
-                    'new_attendee' => true,
385
-                    'capability'   => 'ee_edit_contacts',
386
-                ),
387
-            ),
388
-            'edit_attendee'                      => array(
389
-                'func'       => '_edit_cpt_item',
390
-                'capability' => 'ee_edit_contacts',
391
-                'obj_id'     => $att_id,
392
-            ),
393
-            'duplicate_attendee'                 => array(
394
-                'func'       => '_duplicate_attendee',
395
-                'noheader'   => true,
396
-                'capability' => 'ee_edit_contacts',
397
-                'obj_id'     => $att_id,
398
-            ),
399
-            'insert_attendee'                    => array(
400
-                'func'       => '_insert_or_update_attendee',
401
-                'args'       => array(
402
-                    'new_attendee' => true,
403
-                ),
404
-                'noheader'   => true,
405
-                'capability' => 'ee_edit_contacts',
406
-            ),
407
-            'update_attendee'                    => array(
408
-                'func'       => '_insert_or_update_attendee',
409
-                'args'       => array(
410
-                    'new_attendee' => false,
411
-                ),
412
-                'noheader'   => true,
413
-                'capability' => 'ee_edit_contacts',
414
-                'obj_id'     => $att_id,
415
-            ),
416
-            'trash_attendees' => array(
417
-                'func' => '_trash_or_restore_attendees',
418
-                'args' => array(
419
-                    'trash' => 'true'
420
-                ),
421
-                'noheader' => true,
422
-                'capability' => 'ee_delete_contacts'
423
-            ),
424
-            'trash_attendee'                    => array(
425
-                'func'       => '_trash_or_restore_attendees',
426
-                'args'       => array(
427
-                    'trash' => true,
428
-                ),
429
-                'noheader'   => true,
430
-                'capability' => 'ee_delete_contacts',
431
-                'obj_id'     => $att_id,
432
-            ),
433
-            'restore_attendees'                  => array(
434
-                'func'       => '_trash_or_restore_attendees',
435
-                'args'       => array(
436
-                    'trash' => false,
437
-                ),
438
-                'noheader'   => true,
439
-                'capability' => 'ee_delete_contacts',
440
-                'obj_id'     => $att_id,
441
-            ),
442
-            'resend_registration'                => array(
443
-                'func'       => '_resend_registration',
444
-                'noheader'   => true,
445
-                'capability' => 'ee_send_message',
446
-            ),
447
-            'registrations_report'               => array(
448
-                'func'       => '_registrations_report',
449
-                'noheader'   => true,
450
-                'capability' => 'ee_read_registrations',
451
-            ),
452
-            'contact_list_export'                => array(
453
-                'func'       => '_contact_list_export',
454
-                'noheader'   => true,
455
-                'capability' => 'export',
456
-            ),
457
-            'contact_list_report'                => array(
458
-                'func'       => '_contact_list_report',
459
-                'noheader'   => true,
460
-                'capability' => 'ee_read_contacts',
461
-            ),
462
-        );
463
-    }
464
-
465
-
466
-    protected function _set_page_config()
467
-    {
468
-        $this->_page_config = array(
469
-            'default'           => array(
470
-                'nav'           => array(
471
-                    'label' => esc_html__('Overview', 'event_espresso'),
472
-                    'order' => 5,
473
-                ),
474
-                'help_tabs'     => array(
475
-                    'registrations_overview_help_tab'                       => array(
476
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
-                        'filename' => 'registrations_overview',
478
-                    ),
479
-                    'registrations_overview_table_column_headings_help_tab' => array(
480
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
-                        'filename' => 'registrations_overview_table_column_headings',
482
-                    ),
483
-                    'registrations_overview_filters_help_tab'               => array(
484
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
-                        'filename' => 'registrations_overview_filters',
486
-                    ),
487
-                    'registrations_overview_views_help_tab'                 => array(
488
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
489
-                        'filename' => 'registrations_overview_views',
490
-                    ),
491
-                    'registrations_regoverview_other_help_tab'              => array(
492
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
-                        'filename' => 'registrations_overview_other',
494
-                    ),
495
-                ),
496
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
497
-                'qtips'         => array('Registration_List_Table_Tips'),
498
-                'list_table'    => 'EE_Registrations_List_Table',
499
-                'require_nonce' => false,
500
-            ),
501
-            'view_registration' => array(
502
-                'nav'           => array(
503
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
504
-                    'order'      => 15,
505
-                    'url'        => isset($this->_req_data['_REG_ID'])
506
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
-                        : $this->_admin_base_url,
508
-                    'persistent' => false,
509
-                ),
510
-                'help_tabs'     => array(
511
-                    'registrations_details_help_tab'                    => array(
512
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
513
-                        'filename' => 'registrations_details',
514
-                    ),
515
-                    'registrations_details_table_help_tab'              => array(
516
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
-                        'filename' => 'registrations_details_table',
518
-                    ),
519
-                    'registrations_details_form_answers_help_tab'       => array(
520
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
-                        'filename' => 'registrations_details_form_answers',
522
-                    ),
523
-                    'registrations_details_registrant_details_help_tab' => array(
524
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
525
-                        'filename' => 'registrations_details_registrant_details',
526
-                    ),
527
-                ),
528
-                'help_tour'     => array('Registration_Details_Help_Tour'),
529
-                'metaboxes'     => array_merge(
530
-                    $this->_default_espresso_metaboxes,
531
-                    array('_registration_details_metaboxes')
532
-                ),
533
-                'require_nonce' => false,
534
-            ),
535
-            'new_registration'  => array(
536
-                'nav'           => array(
537
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
-                    'url'        => '#',
539
-                    'order'      => 15,
540
-                    'persistent' => false,
541
-                ),
542
-                'metaboxes'     => $this->_default_espresso_metaboxes,
543
-                'labels'        => array(
544
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
-                ),
546
-                'require_nonce' => false,
547
-            ),
548
-            'add_new_attendee'  => array(
549
-                'nav'           => array(
550
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
551
-                    'order'      => 15,
552
-                    'persistent' => false,
553
-                ),
554
-                'metaboxes'     => array_merge(
555
-                    $this->_default_espresso_metaboxes,
556
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
557
-                ),
558
-                'require_nonce' => false,
559
-            ),
560
-            'edit_attendee'     => array(
561
-                'nav'           => array(
562
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
-                    'order'      => 15,
564
-                    'persistent' => false,
565
-                    'url'        => isset($this->_req_data['ATT_ID'])
566
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
-                        : $this->_admin_base_url,
568
-                ),
569
-                'metaboxes'     => array('attendee_editor_metaboxes'),
570
-                'require_nonce' => false,
571
-            ),
572
-            'contact_list'      => array(
573
-                'nav'           => array(
574
-                    'label' => esc_html__('Contact List', 'event_espresso'),
575
-                    'order' => 20,
576
-                ),
577
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
578
-                'help_tabs'     => array(
579
-                    'registrations_contact_list_help_tab'                       => array(
580
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
-                        'filename' => 'registrations_contact_list',
582
-                    ),
583
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
584
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
-                        'filename' => 'registrations_contact_list_table_column_headings',
586
-                    ),
587
-                    'registrations_contact_list_views_help_tab'                 => array(
588
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
-                        'filename' => 'registrations_contact_list_views',
590
-                    ),
591
-                    'registrations_contact_list_other_help_tab'                 => array(
592
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
-                        'filename' => 'registrations_contact_list_other',
594
-                    ),
595
-                ),
596
-                'help_tour'     => array('Contact_List_Help_Tour'),
597
-                'metaboxes'     => array(),
598
-                'require_nonce' => false,
599
-            ),
600
-            //override default cpt routes
601
-            'create_new'        => '',
602
-            'edit'              => '',
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * The below methods aren't used by this class currently
609
-     */
610
-    protected function _add_screen_options()
611
-    {
612
-    }
613
-
614
-
615
-    protected function _add_feature_pointers()
616
-    {
617
-    }
618
-
619
-
620
-    public function admin_init()
621
-    {
622
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
-            'click "Update Registration Questions" to save your changes',
624
-            'event_espresso'
625
-        );
626
-    }
627
-
628
-
629
-    public function admin_notices()
630
-    {
631
-    }
632
-
633
-
634
-    public function admin_footer_scripts()
635
-    {
636
-    }
637
-
638
-
639
-    /**
640
-     *        get list of registration statuses
641
-     *
642
-     * @access private
643
-     * @return void
644
-     */
645
-    private function _get_registration_status_array()
646
-    {
647
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
648
-    }
649
-
650
-
651
-    protected function _add_screen_options_default()
652
-    {
653
-        $this->_per_page_screen_option();
654
-    }
655
-
656
-
657
-    protected function _add_screen_options_contact_list()
658
-    {
659
-        $page_title              = $this->_admin_page_title;
660
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
661
-        $this->_per_page_screen_option();
662
-        $this->_admin_page_title = $page_title;
663
-    }
664
-
665
-
666
-    public function load_scripts_styles()
667
-    {
668
-        //style
669
-        wp_register_style(
670
-            'espresso_reg',
671
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
672
-            array('ee-admin-css'),
673
-            EVENT_ESPRESSO_VERSION
674
-        );
675
-        wp_enqueue_style('espresso_reg');
676
-        //script
677
-        wp_register_script(
678
-            'espresso_reg',
679
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
680
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
681
-            EVENT_ESPRESSO_VERSION,
682
-            true
683
-        );
684
-        wp_enqueue_script('espresso_reg');
685
-    }
686
-
687
-
688
-    public function load_scripts_styles_edit_attendee()
689
-    {
690
-        //stuff to only show up on our attendee edit details page.
691
-        $attendee_details_translations = array(
692
-            'att_publish_text' => sprintf(
693
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
694
-                $this->_cpt_model_obj->get_datetime('ATT_created')
695
-            ),
696
-        );
697
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
698
-        wp_enqueue_script('jquery-validate');
699
-    }
700
-
701
-
702
-    public function load_scripts_styles_view_registration()
703
-    {
704
-        //styles
705
-        wp_enqueue_style('espresso-ui-theme');
706
-        //scripts
707
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
708
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
709
-    }
710
-
711
-
712
-    public function load_scripts_styles_contact_list()
713
-    {
714
-        wp_deregister_style('espresso_reg');
715
-        wp_register_style(
716
-            'espresso_att',
717
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
718
-            array('ee-admin-css'),
719
-            EVENT_ESPRESSO_VERSION
720
-        );
721
-        wp_enqueue_style('espresso_att');
722
-    }
723
-
724
-
725
-    public function load_scripts_styles_new_registration()
726
-    {
727
-        wp_register_script(
728
-            'ee-spco-for-admin',
729
-            REG_ASSETS_URL . 'spco_for_admin.js',
730
-            array('underscore', 'jquery'),
731
-            EVENT_ESPRESSO_VERSION,
732
-            true
733
-        );
734
-        wp_enqueue_script('ee-spco-for-admin');
735
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
736
-        EE_Form_Section_Proper::wp_enqueue_scripts();
737
-        EED_Ticket_Selector::load_tckt_slctr_assets();
738
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
739
-    }
740
-
741
-
742
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
743
-    {
744
-        add_filter('FHEE_load_EE_messages', '__return_true');
745
-    }
746
-
747
-
748
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
749
-    {
750
-        add_filter('FHEE_load_EE_messages', '__return_true');
751
-    }
752
-
753
-
754
-    protected function _set_list_table_views_default()
755
-    {
756
-        //for notification related bulk actions we need to make sure only active messengers have an option.
757
-        EED_Messages::set_autoloaders();
758
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
759
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
760
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
761
-        //key= bulk_action_slug, value= message type.
762
-        $match_array = array(
763
-            'approve_registrations'    => 'registration',
764
-            'decline_registrations'    => 'declined_registration',
765
-            'pending_registrations'    => 'pending_approval',
766
-            'no_approve_registrations' => 'not_approved_registration',
767
-            'cancel_registrations'     => 'cancelled_registration',
768
-        );
769
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
770
-            'ee_send_message',
771
-            'batch_send_messages'
772
-        );
773
-        /** setup reg status bulk actions **/
774
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
775
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
776
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
777
-                    'Approve and Notify Registrations',
778
-                    'event_espresso'
779
-                );
780
-        }
781
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
782
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
783
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
784
-                    'Decline and Notify Registrations',
785
-                    'event_espresso'
786
-                );
787
-        }
788
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
789
-            'Set Registrations to Pending Payment',
790
-            'event_espresso'
791
-        );
792
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
793
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
794
-                    'Set Registrations to Pending Payment and Notify',
795
-                    'event_espresso'
796
-                );
797
-        }
798
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
799
-            'Set Registrations to Not Approved',
800
-            'event_espresso'
801
-        );
802
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
803
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
804
-                    'Set Registrations to Not Approved and Notify',
805
-                    'event_espresso'
806
-                );
807
-        }
808
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
809
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
810
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
811
-                    'Cancel Registrations and Notify',
812
-                    'event_espresso'
813
-                );
814
-        }
815
-        $def_reg_status_actions = apply_filters(
816
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
817
-            $def_reg_status_actions,
818
-            $active_mts,
819
-            $can_send
820
-        );
821
-
822
-        $this->_views = array(
823
-            'all'   => array(
824
-                'slug'        => 'all',
825
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
826
-                'count'       => 0,
827
-                'bulk_action' => array_merge($def_reg_status_actions, array(
828
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
829
-                )),
830
-            ),
831
-            'month' => array(
832
-                'slug'        => 'month',
833
-                'label'       => esc_html__('This Month', 'event_espresso'),
834
-                'count'       => 0,
835
-                'bulk_action' => array_merge($def_reg_status_actions, array(
836
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
837
-                )),
838
-            ),
839
-            'today' => array(
840
-                'slug'        => 'today',
841
-                'label'       => sprintf(
842
-                    esc_html__('Today - %s', 'event_espresso'),
843
-                    date('M d, Y', current_time('timestamp'))
844
-                ),
845
-                'count'       => 0,
846
-                'bulk_action' => array_merge($def_reg_status_actions, array(
847
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
848
-                )),
849
-            ),
850
-        );
851
-        if (EE_Registry::instance()->CAP->current_user_can(
852
-            'ee_delete_registrations',
853
-            'espresso_registrations_delete_registration'
854
-        )) {
855
-            $this->_views['incomplete'] = array(
856
-                'slug'        => 'incomplete',
857
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
858
-                'count'       => 0,
859
-                'bulk_action' => array(
860
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
861
-                ),
862
-            );
863
-            $this->_views['trash']      = array(
864
-                'slug'        => 'trash',
865
-                'label'       => esc_html__('Trash', 'event_espresso'),
866
-                'count'       => 0,
867
-                'bulk_action' => array(
868
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
869
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
870
-                ),
871
-            );
872
-        }
873
-    }
874
-
875
-
876
-    protected function _set_list_table_views_contact_list()
877
-    {
878
-        $this->_views = array(
879
-            'in_use' => array(
880
-                'slug'        => 'in_use',
881
-                'label'       => esc_html__('In Use', 'event_espresso'),
882
-                'count'       => 0,
883
-                'bulk_action' => array(
884
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
885
-                ),
886
-            ),
887
-        );
888
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
889
-            'espresso_registrations_trash_attendees')
890
-        ) {
891
-            $this->_views['trash'] = array(
892
-                'slug'        => 'trash',
893
-                'label'       => esc_html__('Trash', 'event_espresso'),
894
-                'count'       => 0,
895
-                'bulk_action' => array(
896
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
897
-                ),
898
-            );
899
-        }
900
-    }
901
-
902
-
903
-    protected function _registration_legend_items()
904
-    {
905
-        $fc_items = array(
906
-            'star-icon'        => array(
907
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
908
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
909
-            ),
910
-            'view_details'     => array(
911
-                'class' => 'dashicons dashicons-clipboard',
912
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
913
-            ),
914
-            'edit_attendee'    => array(
915
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
916
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
917
-            ),
918
-            'view_transaction' => array(
919
-                'class' => 'dashicons dashicons-cart',
920
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
921
-            ),
922
-            'view_invoice'     => array(
923
-                'class' => 'dashicons dashicons-media-spreadsheet',
924
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
925
-            ),
926
-        );
927
-        if (EE_Registry::instance()->CAP->current_user_can(
928
-            'ee_send_message',
929
-            'espresso_registrations_resend_registration'
930
-        )) {
931
-            $fc_items['resend_registration'] = array(
932
-                'class' => 'dashicons dashicons-email-alt',
933
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
934
-            );
935
-        } else {
936
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
937
-        }
938
-        if (EE_Registry::instance()->CAP->current_user_can(
939
-            'ee_read_global_messages',
940
-            'view_filtered_messages'
941
-        )) {
942
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
943
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
944
-                $fc_items['view_related_messages'] = array(
945
-                    'class' => $related_for_icon['css_class'],
946
-                    'desc'  => $related_for_icon['label'],
947
-                );
948
-            }
949
-        }
950
-        $sc_items = array(
951
-            'approved_status'   => array(
952
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
-                'desc'  => EEH_Template::pretty_status(
954
-                    EEM_Registration::status_id_approved,
955
-                    false,
956
-                    'sentence'
957
-                ),
958
-            ),
959
-            'pending_status'    => array(
960
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
-                'desc'  => EEH_Template::pretty_status(
962
-                    EEM_Registration::status_id_pending_payment,
963
-                    false,
964
-                    'sentence'
965
-                ),
966
-            ),
967
-            'wait_list'         => array(
968
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
-                'desc'  => EEH_Template::pretty_status(
970
-                    EEM_Registration::status_id_wait_list,
971
-                    false,
972
-                    'sentence'
973
-                ),
974
-            ),
975
-            'incomplete_status' => array(
976
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
-                'desc'  => EEH_Template::pretty_status(
978
-                    EEM_Registration::status_id_incomplete,
979
-                    false,
980
-                    'sentence'
981
-                ),
982
-            ),
983
-            'not_approved'      => array(
984
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
-                'desc'  => EEH_Template::pretty_status(
986
-                    EEM_Registration::status_id_not_approved,
987
-                    false,
988
-                    'sentence'
989
-                ),
990
-            ),
991
-            'declined_status'   => array(
992
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
-                'desc'  => EEH_Template::pretty_status(
994
-                    EEM_Registration::status_id_declined,
995
-                    false,
996
-                    'sentence'
997
-                ),
998
-            ),
999
-            'cancelled_status'  => array(
1000
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
-                'desc'  => EEH_Template::pretty_status(
1002
-                    EEM_Registration::status_id_cancelled,
1003
-                    false,
1004
-                    'sentence'
1005
-                ),
1006
-            ),
1007
-        );
1008
-        return array_merge($fc_items, $sc_items);
1009
-    }
1010
-
1011
-
1012
-
1013
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1014
-    /**
1015
-     * @throws \EE_Error
1016
-     */
1017
-    protected function _registrations_overview_list_table()
1018
-    {
1019
-        $this->_template_args['admin_page_header'] = '';
1020
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1021
-            ? absint($this->_req_data['event_id'])
1022
-            : 0;
1023
-        if ($EVT_ID) {
1024
-            if (EE_Registry::instance()->CAP->current_user_can(
1025
-                'ee_edit_registrations',
1026
-                'espresso_registrations_new_registration',
1027
-                $EVT_ID
1028
-            )) {
1029
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1030
-                    'new_registration',
1031
-                    'add-registrant',
1032
-                    array('event_id' => $EVT_ID),
1033
-                    'add-new-h2'
1034
-                );
1035
-            }
1036
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1037
-            if ($event instanceof EE_Event) {
1038
-                $this->_template_args['admin_page_header'] = sprintf(
1039
-                    esc_html__(
1040
-                        '%s Viewing registrations for the event: %s%s',
1041
-                        'event_espresso'
1042
-                    ),
1043
-                    '<h3 style="line-height:1.5em;">',
1044
-                    '<br /><a href="'
1045
-                        . EE_Admin_Page::add_query_args_and_nonce(
1046
-                            array(
1047
-                                'action' => 'edit',
1048
-                                'post'   => $event->ID(),
1049
-                            ),
1050
-                            EVENTS_ADMIN_URL
1051
-                        )
1052
-                        . '">&nbsp;'
1053
-                        . $event->get('EVT_name')
1054
-                        . '&nbsp;</a>&nbsp;',
1055
-                    '</h3>'
1056
-                );
1057
-            }
1058
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1059
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1060
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1061
-                $this->_template_args['admin_page_header'] = substr(
1062
-                    $this->_template_args['admin_page_header'],
1063
-                    0,
1064
-                    -5
1065
-                );
1066
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1067
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1068
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1069
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1070
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1071
-            }
1072
-        }
1073
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1074
-        $this->display_admin_list_table_page_with_no_sidebar();
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     * This sets the _registration property for the registration details screen
1080
-     *
1081
-     * @access private
1082
-     * @return bool
1083
-     */
1084
-    private function _set_registration_object()
1085
-    {
1086
-        //get out if we've already set the object
1087
-        if ($this->_registration instanceof EE_Registration) {
1088
-            return true;
1089
-        }
1090
-        $REG    = EEM_Registration::instance();
1091
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1092
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1093
-            return true;
1094
-        } else {
1095
-            $error_msg = sprintf(
1096
-                esc_html__(
1097
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1098
-                    'event_espresso'
1099
-                ),
1100
-                $REG_ID
1101
-            );
1102
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1103
-            $this->_registration = null;
1104
-            return false;
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * Used to retrieve registrations for the list table.
1111
-     *
1112
-     * @param int  $per_page
1113
-     * @param bool $count
1114
-     * @param bool $this_month
1115
-     * @param bool $today
1116
-     * @return EE_Registration[]|int
1117
-     * @throws EE_Error
1118
-     */
1119
-    public function get_registrations(
1120
-        $per_page = 10,
1121
-        $count = false,
1122
-        $this_month = false,
1123
-        $today = false
1124
-    ) {
1125
-        if ($this_month) {
1126
-            $this->_req_data['status'] = 'month';
1127
-        }
1128
-        if ($today) {
1129
-            $this->_req_data['status'] = 'today';
1130
-        }
1131
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1132
-        /**
1133
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1134
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1135
-         * @see EEM_Base::get_all()
1136
-         */
1137
-        $query_params['group_by'] = '';
1138
-
1139
-        return $count
1140
-            ? EEM_Registration::instance()->count($query_params)
1141
-            /** @type EE_Registration[] */
1142
-            : EEM_Registration::instance()->get_all($query_params);
1143
-    }
1144
-
1145
-
1146
-
1147
-    /**
1148
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1149
-     * Note: this listens to values on the request for some of the query parameters.
1150
-     *
1151
-     * @param array $request
1152
-     * @param int    $per_page
1153
-     * @param bool   $count
1154
-     * @return array
1155
-     */
1156
-    protected function _get_registration_query_parameters(
1157
-        $request = array(),
1158
-        $per_page = 10,
1159
-        $count = false
1160
-    ) {
1161
-
1162
-        $query_params = array(
1163
-            0                          => $this->_get_where_conditions_for_registrations_query(
1164
-                $request
1165
-            ),
1166
-            'caps'                     => EEM_Registration::caps_read_admin,
1167
-            'default_where_conditions' => 'this_model_only',
1168
-        );
1169
-        if (! $count) {
1170
-            $query_params = array_merge(
1171
-                $query_params,
1172
-                $this->_get_orderby_for_registrations_query(),
1173
-                $this->_get_limit($per_page)
1174
-            );
1175
-        }
1176
-
1177
-        return $query_params;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1183
-     *
1184
-     * @param array $request usually the same as $this->_req_data but not necessarily
1185
-     * @return array
1186
-     */
1187
-    protected function _add_event_id_to_where_conditions(array $request)
1188
-    {
1189
-        $where = array();
1190
-        if (! empty($request['event_id'])) {
1191
-            $where['EVT_ID'] = absint($request['event_id']);
1192
-        }
1193
-        return $where;
1194
-    }
1195
-
1196
-
1197
-    /**
1198
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1199
-     *
1200
-     * @param array $request usually the same as $this->_req_data but not necessarily
1201
-     * @return array
1202
-     */
1203
-    protected function _add_category_id_to_where_conditions(array $request)
1204
-    {
1205
-        $where = array();
1206
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1207
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1208
-        }
1209
-        return $where;
1210
-    }
1211
-
1212
-
1213
-    /**
1214
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1215
-     *
1216
-     * @param array $request usually the same as $this->_req_data but not necessarily
1217
-     * @return array
1218
-     */
1219
-    protected function _add_datetime_id_to_where_conditions(array $request)
1220
-    {
1221
-        $where = array();
1222
-        if (! empty($request['datetime_id'])) {
1223
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1224
-        }
1225
-        if (! empty($request['DTT_ID'])) {
1226
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1227
-        }
1228
-        return $where;
1229
-    }
1230
-
1231
-
1232
-    /**
1233
-     * Adds the correct registration status to the where conditions for the registrations query.
1234
-     *
1235
-     * @param array $request usually the same as $this->_req_data but not necessarily
1236
-     * @return array
1237
-     */
1238
-    protected function _add_registration_status_to_where_conditions(array $request)
1239
-    {
1240
-        $where = array();
1241
-        $view = EEH_Array::is_set($request, 'status', '');
1242
-        $registration_status = ! empty($request['_reg_status'])
1243
-            ? sanitize_text_field($request['_reg_status'])
1244
-            : '';
1245
-
1246
-        /*
33
+	/**
34
+	 * @var EE_Registration
35
+	 */
36
+	private $_registration;
37
+
38
+	/**
39
+	 * @var EE_Event
40
+	 */
41
+	private $_reg_event;
42
+
43
+	/**
44
+	 * @var EE_Session
45
+	 */
46
+	private $_session;
47
+
48
+	private static $_reg_status;
49
+
50
+	/**
51
+	 * Form for displaying the custom questions for this registration.
52
+	 * This gets used a few times throughout the request so its best to cache it
53
+	 *
54
+	 * @var EE_Registration_Custom_Questions_Form
55
+	 */
56
+	protected $_reg_custom_questions_form = null;
57
+
58
+
59
+	/**
60
+	 *        constructor
61
+	 *
62
+	 * @Constructor
63
+	 * @access public
64
+	 * @param bool $routing
65
+	 * @return Registrations_Admin_Page
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		parent::__construct($routing);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'));
71
+	}
72
+
73
+
74
+	public function wp_loaded()
75
+	{
76
+		// when adding a new registration...
77
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
+			EE_System::do_not_cache();
79
+			if (! isset($this->_req_data['processing_registration'])
80
+				 || absint($this->_req_data['processing_registration']) !== 1
81
+			) {
82
+				// and it's NOT the attendee information reg step
83
+				// force cookie expiration by setting time to last week
84
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
+				// and update the global
86
+				$_COOKIE['ee_registration_added'] = 0;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+	protected function _init_page_props()
93
+	{
94
+		$this->page_slug        = REG_PG_SLUG;
95
+		$this->_admin_base_url  = REG_ADMIN_URL;
96
+		$this->_admin_base_path = REG_ADMIN;
97
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
98
+		$this->_cpt_routes      = array(
99
+			'add_new_attendee' => 'espresso_attendees',
100
+			'edit_attendee'    => 'espresso_attendees',
101
+			'insert_attendee'  => 'espresso_attendees',
102
+			'update_attendee'  => 'espresso_attendees',
103
+		);
104
+		$this->_cpt_model_names = array(
105
+			'add_new_attendee' => 'EEM_Attendee',
106
+			'edit_attendee'    => 'EEM_Attendee',
107
+		);
108
+		$this->_cpt_edit_routes = array(
109
+			'espresso_attendees' => 'edit_attendee',
110
+		);
111
+		$this->_pagenow_map     = array(
112
+			'add_new_attendee' => 'post-new.php',
113
+			'edit_attendee'    => 'post.php',
114
+			'trash'            => 'post.php',
115
+		);
116
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
+		//add filters so that the comment urls don't take users to a confusing 404 page
118
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
+	}
120
+
121
+
122
+	public function clear_comment_link($link, $comment, $args)
123
+	{
124
+		//gotta make sure this only happens on this route
125
+		$post_type = get_post_type($comment->comment_post_ID);
126
+		if ($post_type === 'espresso_attendees') {
127
+			return '#commentsdiv';
128
+		}
129
+		return $link;
130
+	}
131
+
132
+
133
+	protected function _ajax_hooks()
134
+	{
135
+		//todo: all hooks for registrations ajax goes in here
136
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
+	}
138
+
139
+
140
+	protected function _define_page_props()
141
+	{
142
+		$this->_admin_page_title = $this->page_label;
143
+		$this->_labels           = array(
144
+			'buttons'                      => array(
145
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
+			),
154
+			'publishbox'                   => array(
155
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
+			),
158
+			'hide_add_button_on_cpt_route' => array(
159
+				'edit_attendee' => true,
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 *        grab url requests and route them
167
+	 *
168
+	 * @access private
169
+	 * @return void
170
+	 */
171
+	public function _set_page_routes()
172
+	{
173
+		$this->_get_registration_status_array();
174
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
+			? $this->_req_data['_REG_ID'] : 0;
176
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
+			? $this->_req_data['reg_status_change_form']['REG_ID']
178
+			: $reg_id;
179
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
+			? $this->_req_data['ATT_ID'] : 0;
181
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
+			? $this->_req_data['post']
183
+			: $att_id;
184
+		$this->_page_routes = array(
185
+			'default'                            => array(
186
+				'func'       => '_registrations_overview_list_table',
187
+				'capability' => 'ee_read_registrations',
188
+			),
189
+			'view_registration'                  => array(
190
+				'func'       => '_registration_details',
191
+				'capability' => 'ee_read_registration',
192
+				'obj_id'     => $reg_id,
193
+			),
194
+			'edit_registration'                  => array(
195
+				'func'               => '_update_attendee_registration_form',
196
+				'noheader'           => true,
197
+				'headers_sent_route' => 'view_registration',
198
+				'capability'         => 'ee_edit_registration',
199
+				'obj_id'             => $reg_id,
200
+				'_REG_ID'            => $reg_id,
201
+			),
202
+			'trash_registrations'                => array(
203
+				'func'       => '_trash_or_restore_registrations',
204
+				'args'       => array('trash' => true),
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'restore_registrations'              => array(
209
+				'func'       => '_trash_or_restore_registrations',
210
+				'args'       => array('trash' => false),
211
+				'noheader'   => true,
212
+				'capability' => 'ee_delete_registrations',
213
+			),
214
+			'delete_registrations'               => array(
215
+				'func'       => '_delete_registrations',
216
+				'noheader'   => true,
217
+				'capability' => 'ee_delete_registrations',
218
+			),
219
+			'new_registration'                   => array(
220
+				'func'       => 'new_registration',
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'process_reg_step'                   => array(
224
+				'func'       => 'process_reg_step',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registrations',
227
+			),
228
+			'redirect_to_txn'                    => array(
229
+				'func'       => 'redirect_to_txn',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registrations',
232
+			),
233
+			'change_reg_status'                  => array(
234
+				'func'       => '_change_reg_status',
235
+				'noheader'   => true,
236
+				'capability' => 'ee_edit_registration',
237
+				'obj_id'     => $reg_id,
238
+			),
239
+			'approve_registration'               => array(
240
+				'func'       => 'approve_registration',
241
+				'noheader'   => true,
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_and_notify_registration'    => array(
246
+				'func'       => 'approve_registration',
247
+				'noheader'   => true,
248
+				'args'       => array(true),
249
+				'capability' => 'ee_edit_registration',
250
+				'obj_id'     => $reg_id,
251
+			),
252
+			'approve_registrations'               => array(
253
+				'func'       => 'bulk_action_on_registrations',
254
+				'noheader'   => true,
255
+				'capability' => 'ee_edit_registrations',
256
+				'args' => array('approve')
257
+			),
258
+			'approve_and_notify_registrations'               => array(
259
+				'func'       => 'bulk_action_on_registrations',
260
+				'noheader'   => true,
261
+				'capability' => 'ee_edit_registrations',
262
+				'args' => array('approve', true)
263
+			),
264
+			'decline_registration'               => array(
265
+				'func'       => 'decline_registration',
266
+				'noheader'   => true,
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_and_notify_registration'    => array(
271
+				'func'       => 'decline_registration',
272
+				'noheader'   => true,
273
+				'args'       => array(true),
274
+				'capability' => 'ee_edit_registration',
275
+				'obj_id'     => $reg_id,
276
+			),
277
+			'decline_registrations'               => array(
278
+				'func'       => 'bulk_action_on_registrations',
279
+				'noheader'   => true,
280
+				'capability' => 'ee_edit_registrations',
281
+				'args' => array('decline')
282
+			),
283
+			'decline_and_notify_registrations'    => array(
284
+				'func'       => 'bulk_action_on_registrations',
285
+				'noheader'   => true,
286
+				'capability' => 'ee_edit_registrations',
287
+				'args' => array('decline', true)
288
+			),
289
+			'pending_registration'               => array(
290
+				'func'       => 'pending_registration',
291
+				'noheader'   => true,
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_and_notify_registration'    => array(
296
+				'func'       => 'pending_registration',
297
+				'noheader'   => true,
298
+				'args'       => array(true),
299
+				'capability' => 'ee_edit_registration',
300
+				'obj_id'     => $reg_id,
301
+			),
302
+			'pending_registrations'               => array(
303
+				'func'       => 'bulk_action_on_registrations',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+				'args' => array('pending')
307
+			),
308
+			'pending_and_notify_registrations'    => array(
309
+				'func'       => 'bulk_action_on_registrations',
310
+				'noheader'   => true,
311
+				'capability' => 'ee_edit_registrations',
312
+				'args' => array('pending', true)
313
+			),
314
+			'no_approve_registration'            => array(
315
+				'func'       => 'not_approve_registration',
316
+				'noheader'   => true,
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_and_notify_registration' => array(
321
+				'func'       => 'not_approve_registration',
322
+				'noheader'   => true,
323
+				'args'       => array(true),
324
+				'capability' => 'ee_edit_registration',
325
+				'obj_id'     => $reg_id,
326
+			),
327
+			'no_approve_registrations'            => array(
328
+				'func'       => 'bulk_action_on_registrations',
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_registrations',
331
+				'args' => array('not_approve')
332
+			),
333
+			'no_approve_and_notify_registrations' => array(
334
+				'func'       => 'bulk_action_on_registrations',
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_registrations',
337
+				'args' => array('not_approve', true)
338
+			),
339
+			'cancel_registration'                => array(
340
+				'func'       => 'cancel_registration',
341
+				'noheader'   => true,
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_and_notify_registration'     => array(
346
+				'func'       => 'cancel_registration',
347
+				'noheader'   => true,
348
+				'args'       => array(true),
349
+				'capability' => 'ee_edit_registration',
350
+				'obj_id'     => $reg_id,
351
+			),
352
+			'cancel_registrations'                => array(
353
+				'func'       => 'bulk_action_on_registrations',
354
+				'noheader'   => true,
355
+				'capability' => 'ee_edit_registrations',
356
+				'args' => array('cancel')
357
+			),
358
+			'cancel_and_notify_registrations'     => array(
359
+				'func'       => 'bulk_action_on_registrations',
360
+				'noheader'   => true,
361
+				'capability' => 'ee_edit_registrations',
362
+				'args' => array('cancel', true)
363
+			),
364
+			'wait_list_registration' => array(
365
+				'func'       => 'wait_list_registration',
366
+				'noheader'   => true,
367
+				'capability' => 'ee_edit_registration',
368
+				'obj_id'     => $reg_id,
369
+			),
370
+			'wait_list_and_notify_registration' => array(
371
+				'func'       => 'wait_list_registration',
372
+				'noheader'   => true,
373
+				'args'       => array(true),
374
+				'capability' => 'ee_edit_registration',
375
+				'obj_id'     => $reg_id,
376
+			),
377
+			'contact_list'                       => array(
378
+				'func'       => '_attendee_contact_list_table',
379
+				'capability' => 'ee_read_contacts',
380
+			),
381
+			'add_new_attendee'                   => array(
382
+				'func' => '_create_new_cpt_item',
383
+				'args' => array(
384
+					'new_attendee' => true,
385
+					'capability'   => 'ee_edit_contacts',
386
+				),
387
+			),
388
+			'edit_attendee'                      => array(
389
+				'func'       => '_edit_cpt_item',
390
+				'capability' => 'ee_edit_contacts',
391
+				'obj_id'     => $att_id,
392
+			),
393
+			'duplicate_attendee'                 => array(
394
+				'func'       => '_duplicate_attendee',
395
+				'noheader'   => true,
396
+				'capability' => 'ee_edit_contacts',
397
+				'obj_id'     => $att_id,
398
+			),
399
+			'insert_attendee'                    => array(
400
+				'func'       => '_insert_or_update_attendee',
401
+				'args'       => array(
402
+					'new_attendee' => true,
403
+				),
404
+				'noheader'   => true,
405
+				'capability' => 'ee_edit_contacts',
406
+			),
407
+			'update_attendee'                    => array(
408
+				'func'       => '_insert_or_update_attendee',
409
+				'args'       => array(
410
+					'new_attendee' => false,
411
+				),
412
+				'noheader'   => true,
413
+				'capability' => 'ee_edit_contacts',
414
+				'obj_id'     => $att_id,
415
+			),
416
+			'trash_attendees' => array(
417
+				'func' => '_trash_or_restore_attendees',
418
+				'args' => array(
419
+					'trash' => 'true'
420
+				),
421
+				'noheader' => true,
422
+				'capability' => 'ee_delete_contacts'
423
+			),
424
+			'trash_attendee'                    => array(
425
+				'func'       => '_trash_or_restore_attendees',
426
+				'args'       => array(
427
+					'trash' => true,
428
+				),
429
+				'noheader'   => true,
430
+				'capability' => 'ee_delete_contacts',
431
+				'obj_id'     => $att_id,
432
+			),
433
+			'restore_attendees'                  => array(
434
+				'func'       => '_trash_or_restore_attendees',
435
+				'args'       => array(
436
+					'trash' => false,
437
+				),
438
+				'noheader'   => true,
439
+				'capability' => 'ee_delete_contacts',
440
+				'obj_id'     => $att_id,
441
+			),
442
+			'resend_registration'                => array(
443
+				'func'       => '_resend_registration',
444
+				'noheader'   => true,
445
+				'capability' => 'ee_send_message',
446
+			),
447
+			'registrations_report'               => array(
448
+				'func'       => '_registrations_report',
449
+				'noheader'   => true,
450
+				'capability' => 'ee_read_registrations',
451
+			),
452
+			'contact_list_export'                => array(
453
+				'func'       => '_contact_list_export',
454
+				'noheader'   => true,
455
+				'capability' => 'export',
456
+			),
457
+			'contact_list_report'                => array(
458
+				'func'       => '_contact_list_report',
459
+				'noheader'   => true,
460
+				'capability' => 'ee_read_contacts',
461
+			),
462
+		);
463
+	}
464
+
465
+
466
+	protected function _set_page_config()
467
+	{
468
+		$this->_page_config = array(
469
+			'default'           => array(
470
+				'nav'           => array(
471
+					'label' => esc_html__('Overview', 'event_espresso'),
472
+					'order' => 5,
473
+				),
474
+				'help_tabs'     => array(
475
+					'registrations_overview_help_tab'                       => array(
476
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
+						'filename' => 'registrations_overview',
478
+					),
479
+					'registrations_overview_table_column_headings_help_tab' => array(
480
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
+						'filename' => 'registrations_overview_table_column_headings',
482
+					),
483
+					'registrations_overview_filters_help_tab'               => array(
484
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
+						'filename' => 'registrations_overview_filters',
486
+					),
487
+					'registrations_overview_views_help_tab'                 => array(
488
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
489
+						'filename' => 'registrations_overview_views',
490
+					),
491
+					'registrations_regoverview_other_help_tab'              => array(
492
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
+						'filename' => 'registrations_overview_other',
494
+					),
495
+				),
496
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
497
+				'qtips'         => array('Registration_List_Table_Tips'),
498
+				'list_table'    => 'EE_Registrations_List_Table',
499
+				'require_nonce' => false,
500
+			),
501
+			'view_registration' => array(
502
+				'nav'           => array(
503
+					'label'      => esc_html__('REG Details', 'event_espresso'),
504
+					'order'      => 15,
505
+					'url'        => isset($this->_req_data['_REG_ID'])
506
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
+						: $this->_admin_base_url,
508
+					'persistent' => false,
509
+				),
510
+				'help_tabs'     => array(
511
+					'registrations_details_help_tab'                    => array(
512
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
513
+						'filename' => 'registrations_details',
514
+					),
515
+					'registrations_details_table_help_tab'              => array(
516
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
+						'filename' => 'registrations_details_table',
518
+					),
519
+					'registrations_details_form_answers_help_tab'       => array(
520
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
+						'filename' => 'registrations_details_form_answers',
522
+					),
523
+					'registrations_details_registrant_details_help_tab' => array(
524
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
525
+						'filename' => 'registrations_details_registrant_details',
526
+					),
527
+				),
528
+				'help_tour'     => array('Registration_Details_Help_Tour'),
529
+				'metaboxes'     => array_merge(
530
+					$this->_default_espresso_metaboxes,
531
+					array('_registration_details_metaboxes')
532
+				),
533
+				'require_nonce' => false,
534
+			),
535
+			'new_registration'  => array(
536
+				'nav'           => array(
537
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
+					'url'        => '#',
539
+					'order'      => 15,
540
+					'persistent' => false,
541
+				),
542
+				'metaboxes'     => $this->_default_espresso_metaboxes,
543
+				'labels'        => array(
544
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
+				),
546
+				'require_nonce' => false,
547
+			),
548
+			'add_new_attendee'  => array(
549
+				'nav'           => array(
550
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
551
+					'order'      => 15,
552
+					'persistent' => false,
553
+				),
554
+				'metaboxes'     => array_merge(
555
+					$this->_default_espresso_metaboxes,
556
+					array('_publish_post_box', 'attendee_editor_metaboxes')
557
+				),
558
+				'require_nonce' => false,
559
+			),
560
+			'edit_attendee'     => array(
561
+				'nav'           => array(
562
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
+					'order'      => 15,
564
+					'persistent' => false,
565
+					'url'        => isset($this->_req_data['ATT_ID'])
566
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
+						: $this->_admin_base_url,
568
+				),
569
+				'metaboxes'     => array('attendee_editor_metaboxes'),
570
+				'require_nonce' => false,
571
+			),
572
+			'contact_list'      => array(
573
+				'nav'           => array(
574
+					'label' => esc_html__('Contact List', 'event_espresso'),
575
+					'order' => 20,
576
+				),
577
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
578
+				'help_tabs'     => array(
579
+					'registrations_contact_list_help_tab'                       => array(
580
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
+						'filename' => 'registrations_contact_list',
582
+					),
583
+					'registrations_contact-list_table_column_headings_help_tab' => array(
584
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
+						'filename' => 'registrations_contact_list_table_column_headings',
586
+					),
587
+					'registrations_contact_list_views_help_tab'                 => array(
588
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
+						'filename' => 'registrations_contact_list_views',
590
+					),
591
+					'registrations_contact_list_other_help_tab'                 => array(
592
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
+						'filename' => 'registrations_contact_list_other',
594
+					),
595
+				),
596
+				'help_tour'     => array('Contact_List_Help_Tour'),
597
+				'metaboxes'     => array(),
598
+				'require_nonce' => false,
599
+			),
600
+			//override default cpt routes
601
+			'create_new'        => '',
602
+			'edit'              => '',
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * The below methods aren't used by this class currently
609
+	 */
610
+	protected function _add_screen_options()
611
+	{
612
+	}
613
+
614
+
615
+	protected function _add_feature_pointers()
616
+	{
617
+	}
618
+
619
+
620
+	public function admin_init()
621
+	{
622
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
+			'click "Update Registration Questions" to save your changes',
624
+			'event_espresso'
625
+		);
626
+	}
627
+
628
+
629
+	public function admin_notices()
630
+	{
631
+	}
632
+
633
+
634
+	public function admin_footer_scripts()
635
+	{
636
+	}
637
+
638
+
639
+	/**
640
+	 *        get list of registration statuses
641
+	 *
642
+	 * @access private
643
+	 * @return void
644
+	 */
645
+	private function _get_registration_status_array()
646
+	{
647
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
648
+	}
649
+
650
+
651
+	protected function _add_screen_options_default()
652
+	{
653
+		$this->_per_page_screen_option();
654
+	}
655
+
656
+
657
+	protected function _add_screen_options_contact_list()
658
+	{
659
+		$page_title              = $this->_admin_page_title;
660
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
661
+		$this->_per_page_screen_option();
662
+		$this->_admin_page_title = $page_title;
663
+	}
664
+
665
+
666
+	public function load_scripts_styles()
667
+	{
668
+		//style
669
+		wp_register_style(
670
+			'espresso_reg',
671
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
672
+			array('ee-admin-css'),
673
+			EVENT_ESPRESSO_VERSION
674
+		);
675
+		wp_enqueue_style('espresso_reg');
676
+		//script
677
+		wp_register_script(
678
+			'espresso_reg',
679
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
680
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
681
+			EVENT_ESPRESSO_VERSION,
682
+			true
683
+		);
684
+		wp_enqueue_script('espresso_reg');
685
+	}
686
+
687
+
688
+	public function load_scripts_styles_edit_attendee()
689
+	{
690
+		//stuff to only show up on our attendee edit details page.
691
+		$attendee_details_translations = array(
692
+			'att_publish_text' => sprintf(
693
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
694
+				$this->_cpt_model_obj->get_datetime('ATT_created')
695
+			),
696
+		);
697
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
698
+		wp_enqueue_script('jquery-validate');
699
+	}
700
+
701
+
702
+	public function load_scripts_styles_view_registration()
703
+	{
704
+		//styles
705
+		wp_enqueue_style('espresso-ui-theme');
706
+		//scripts
707
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
708
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
709
+	}
710
+
711
+
712
+	public function load_scripts_styles_contact_list()
713
+	{
714
+		wp_deregister_style('espresso_reg');
715
+		wp_register_style(
716
+			'espresso_att',
717
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
718
+			array('ee-admin-css'),
719
+			EVENT_ESPRESSO_VERSION
720
+		);
721
+		wp_enqueue_style('espresso_att');
722
+	}
723
+
724
+
725
+	public function load_scripts_styles_new_registration()
726
+	{
727
+		wp_register_script(
728
+			'ee-spco-for-admin',
729
+			REG_ASSETS_URL . 'spco_for_admin.js',
730
+			array('underscore', 'jquery'),
731
+			EVENT_ESPRESSO_VERSION,
732
+			true
733
+		);
734
+		wp_enqueue_script('ee-spco-for-admin');
735
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
736
+		EE_Form_Section_Proper::wp_enqueue_scripts();
737
+		EED_Ticket_Selector::load_tckt_slctr_assets();
738
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
739
+	}
740
+
741
+
742
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
743
+	{
744
+		add_filter('FHEE_load_EE_messages', '__return_true');
745
+	}
746
+
747
+
748
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
749
+	{
750
+		add_filter('FHEE_load_EE_messages', '__return_true');
751
+	}
752
+
753
+
754
+	protected function _set_list_table_views_default()
755
+	{
756
+		//for notification related bulk actions we need to make sure only active messengers have an option.
757
+		EED_Messages::set_autoloaders();
758
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
759
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
760
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
761
+		//key= bulk_action_slug, value= message type.
762
+		$match_array = array(
763
+			'approve_registrations'    => 'registration',
764
+			'decline_registrations'    => 'declined_registration',
765
+			'pending_registrations'    => 'pending_approval',
766
+			'no_approve_registrations' => 'not_approved_registration',
767
+			'cancel_registrations'     => 'cancelled_registration',
768
+		);
769
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
770
+			'ee_send_message',
771
+			'batch_send_messages'
772
+		);
773
+		/** setup reg status bulk actions **/
774
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
775
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
776
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
777
+					'Approve and Notify Registrations',
778
+					'event_espresso'
779
+				);
780
+		}
781
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
782
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
783
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
784
+					'Decline and Notify Registrations',
785
+					'event_espresso'
786
+				);
787
+		}
788
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
789
+			'Set Registrations to Pending Payment',
790
+			'event_espresso'
791
+		);
792
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
793
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
794
+					'Set Registrations to Pending Payment and Notify',
795
+					'event_espresso'
796
+				);
797
+		}
798
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
799
+			'Set Registrations to Not Approved',
800
+			'event_espresso'
801
+		);
802
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
803
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
804
+					'Set Registrations to Not Approved and Notify',
805
+					'event_espresso'
806
+				);
807
+		}
808
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
809
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
810
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
811
+					'Cancel Registrations and Notify',
812
+					'event_espresso'
813
+				);
814
+		}
815
+		$def_reg_status_actions = apply_filters(
816
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
817
+			$def_reg_status_actions,
818
+			$active_mts,
819
+			$can_send
820
+		);
821
+
822
+		$this->_views = array(
823
+			'all'   => array(
824
+				'slug'        => 'all',
825
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
826
+				'count'       => 0,
827
+				'bulk_action' => array_merge($def_reg_status_actions, array(
828
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
829
+				)),
830
+			),
831
+			'month' => array(
832
+				'slug'        => 'month',
833
+				'label'       => esc_html__('This Month', 'event_espresso'),
834
+				'count'       => 0,
835
+				'bulk_action' => array_merge($def_reg_status_actions, array(
836
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
837
+				)),
838
+			),
839
+			'today' => array(
840
+				'slug'        => 'today',
841
+				'label'       => sprintf(
842
+					esc_html__('Today - %s', 'event_espresso'),
843
+					date('M d, Y', current_time('timestamp'))
844
+				),
845
+				'count'       => 0,
846
+				'bulk_action' => array_merge($def_reg_status_actions, array(
847
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
848
+				)),
849
+			),
850
+		);
851
+		if (EE_Registry::instance()->CAP->current_user_can(
852
+			'ee_delete_registrations',
853
+			'espresso_registrations_delete_registration'
854
+		)) {
855
+			$this->_views['incomplete'] = array(
856
+				'slug'        => 'incomplete',
857
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
858
+				'count'       => 0,
859
+				'bulk_action' => array(
860
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
861
+				),
862
+			);
863
+			$this->_views['trash']      = array(
864
+				'slug'        => 'trash',
865
+				'label'       => esc_html__('Trash', 'event_espresso'),
866
+				'count'       => 0,
867
+				'bulk_action' => array(
868
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
869
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
870
+				),
871
+			);
872
+		}
873
+	}
874
+
875
+
876
+	protected function _set_list_table_views_contact_list()
877
+	{
878
+		$this->_views = array(
879
+			'in_use' => array(
880
+				'slug'        => 'in_use',
881
+				'label'       => esc_html__('In Use', 'event_espresso'),
882
+				'count'       => 0,
883
+				'bulk_action' => array(
884
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
885
+				),
886
+			),
887
+		);
888
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
889
+			'espresso_registrations_trash_attendees')
890
+		) {
891
+			$this->_views['trash'] = array(
892
+				'slug'        => 'trash',
893
+				'label'       => esc_html__('Trash', 'event_espresso'),
894
+				'count'       => 0,
895
+				'bulk_action' => array(
896
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
897
+				),
898
+			);
899
+		}
900
+	}
901
+
902
+
903
+	protected function _registration_legend_items()
904
+	{
905
+		$fc_items = array(
906
+			'star-icon'        => array(
907
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
908
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
909
+			),
910
+			'view_details'     => array(
911
+				'class' => 'dashicons dashicons-clipboard',
912
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
913
+			),
914
+			'edit_attendee'    => array(
915
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
916
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
917
+			),
918
+			'view_transaction' => array(
919
+				'class' => 'dashicons dashicons-cart',
920
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
921
+			),
922
+			'view_invoice'     => array(
923
+				'class' => 'dashicons dashicons-media-spreadsheet',
924
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
925
+			),
926
+		);
927
+		if (EE_Registry::instance()->CAP->current_user_can(
928
+			'ee_send_message',
929
+			'espresso_registrations_resend_registration'
930
+		)) {
931
+			$fc_items['resend_registration'] = array(
932
+				'class' => 'dashicons dashicons-email-alt',
933
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
934
+			);
935
+		} else {
936
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
937
+		}
938
+		if (EE_Registry::instance()->CAP->current_user_can(
939
+			'ee_read_global_messages',
940
+			'view_filtered_messages'
941
+		)) {
942
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
943
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
944
+				$fc_items['view_related_messages'] = array(
945
+					'class' => $related_for_icon['css_class'],
946
+					'desc'  => $related_for_icon['label'],
947
+				);
948
+			}
949
+		}
950
+		$sc_items = array(
951
+			'approved_status'   => array(
952
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
+				'desc'  => EEH_Template::pretty_status(
954
+					EEM_Registration::status_id_approved,
955
+					false,
956
+					'sentence'
957
+				),
958
+			),
959
+			'pending_status'    => array(
960
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
+				'desc'  => EEH_Template::pretty_status(
962
+					EEM_Registration::status_id_pending_payment,
963
+					false,
964
+					'sentence'
965
+				),
966
+			),
967
+			'wait_list'         => array(
968
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
+				'desc'  => EEH_Template::pretty_status(
970
+					EEM_Registration::status_id_wait_list,
971
+					false,
972
+					'sentence'
973
+				),
974
+			),
975
+			'incomplete_status' => array(
976
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
+				'desc'  => EEH_Template::pretty_status(
978
+					EEM_Registration::status_id_incomplete,
979
+					false,
980
+					'sentence'
981
+				),
982
+			),
983
+			'not_approved'      => array(
984
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
+				'desc'  => EEH_Template::pretty_status(
986
+					EEM_Registration::status_id_not_approved,
987
+					false,
988
+					'sentence'
989
+				),
990
+			),
991
+			'declined_status'   => array(
992
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
+				'desc'  => EEH_Template::pretty_status(
994
+					EEM_Registration::status_id_declined,
995
+					false,
996
+					'sentence'
997
+				),
998
+			),
999
+			'cancelled_status'  => array(
1000
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
+				'desc'  => EEH_Template::pretty_status(
1002
+					EEM_Registration::status_id_cancelled,
1003
+					false,
1004
+					'sentence'
1005
+				),
1006
+			),
1007
+		);
1008
+		return array_merge($fc_items, $sc_items);
1009
+	}
1010
+
1011
+
1012
+
1013
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1014
+	/**
1015
+	 * @throws \EE_Error
1016
+	 */
1017
+	protected function _registrations_overview_list_table()
1018
+	{
1019
+		$this->_template_args['admin_page_header'] = '';
1020
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1021
+			? absint($this->_req_data['event_id'])
1022
+			: 0;
1023
+		if ($EVT_ID) {
1024
+			if (EE_Registry::instance()->CAP->current_user_can(
1025
+				'ee_edit_registrations',
1026
+				'espresso_registrations_new_registration',
1027
+				$EVT_ID
1028
+			)) {
1029
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1030
+					'new_registration',
1031
+					'add-registrant',
1032
+					array('event_id' => $EVT_ID),
1033
+					'add-new-h2'
1034
+				);
1035
+			}
1036
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1037
+			if ($event instanceof EE_Event) {
1038
+				$this->_template_args['admin_page_header'] = sprintf(
1039
+					esc_html__(
1040
+						'%s Viewing registrations for the event: %s%s',
1041
+						'event_espresso'
1042
+					),
1043
+					'<h3 style="line-height:1.5em;">',
1044
+					'<br /><a href="'
1045
+						. EE_Admin_Page::add_query_args_and_nonce(
1046
+							array(
1047
+								'action' => 'edit',
1048
+								'post'   => $event->ID(),
1049
+							),
1050
+							EVENTS_ADMIN_URL
1051
+						)
1052
+						. '">&nbsp;'
1053
+						. $event->get('EVT_name')
1054
+						. '&nbsp;</a>&nbsp;',
1055
+					'</h3>'
1056
+				);
1057
+			}
1058
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1059
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1060
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1061
+				$this->_template_args['admin_page_header'] = substr(
1062
+					$this->_template_args['admin_page_header'],
1063
+					0,
1064
+					-5
1065
+				);
1066
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1067
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1068
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1069
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1070
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1071
+			}
1072
+		}
1073
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1074
+		$this->display_admin_list_table_page_with_no_sidebar();
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 * This sets the _registration property for the registration details screen
1080
+	 *
1081
+	 * @access private
1082
+	 * @return bool
1083
+	 */
1084
+	private function _set_registration_object()
1085
+	{
1086
+		//get out if we've already set the object
1087
+		if ($this->_registration instanceof EE_Registration) {
1088
+			return true;
1089
+		}
1090
+		$REG    = EEM_Registration::instance();
1091
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1092
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1093
+			return true;
1094
+		} else {
1095
+			$error_msg = sprintf(
1096
+				esc_html__(
1097
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1098
+					'event_espresso'
1099
+				),
1100
+				$REG_ID
1101
+			);
1102
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1103
+			$this->_registration = null;
1104
+			return false;
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * Used to retrieve registrations for the list table.
1111
+	 *
1112
+	 * @param int  $per_page
1113
+	 * @param bool $count
1114
+	 * @param bool $this_month
1115
+	 * @param bool $today
1116
+	 * @return EE_Registration[]|int
1117
+	 * @throws EE_Error
1118
+	 */
1119
+	public function get_registrations(
1120
+		$per_page = 10,
1121
+		$count = false,
1122
+		$this_month = false,
1123
+		$today = false
1124
+	) {
1125
+		if ($this_month) {
1126
+			$this->_req_data['status'] = 'month';
1127
+		}
1128
+		if ($today) {
1129
+			$this->_req_data['status'] = 'today';
1130
+		}
1131
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1132
+		/**
1133
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1134
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1135
+		 * @see EEM_Base::get_all()
1136
+		 */
1137
+		$query_params['group_by'] = '';
1138
+
1139
+		return $count
1140
+			? EEM_Registration::instance()->count($query_params)
1141
+			/** @type EE_Registration[] */
1142
+			: EEM_Registration::instance()->get_all($query_params);
1143
+	}
1144
+
1145
+
1146
+
1147
+	/**
1148
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1149
+	 * Note: this listens to values on the request for some of the query parameters.
1150
+	 *
1151
+	 * @param array $request
1152
+	 * @param int    $per_page
1153
+	 * @param bool   $count
1154
+	 * @return array
1155
+	 */
1156
+	protected function _get_registration_query_parameters(
1157
+		$request = array(),
1158
+		$per_page = 10,
1159
+		$count = false
1160
+	) {
1161
+
1162
+		$query_params = array(
1163
+			0                          => $this->_get_where_conditions_for_registrations_query(
1164
+				$request
1165
+			),
1166
+			'caps'                     => EEM_Registration::caps_read_admin,
1167
+			'default_where_conditions' => 'this_model_only',
1168
+		);
1169
+		if (! $count) {
1170
+			$query_params = array_merge(
1171
+				$query_params,
1172
+				$this->_get_orderby_for_registrations_query(),
1173
+				$this->_get_limit($per_page)
1174
+			);
1175
+		}
1176
+
1177
+		return $query_params;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1183
+	 *
1184
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1185
+	 * @return array
1186
+	 */
1187
+	protected function _add_event_id_to_where_conditions(array $request)
1188
+	{
1189
+		$where = array();
1190
+		if (! empty($request['event_id'])) {
1191
+			$where['EVT_ID'] = absint($request['event_id']);
1192
+		}
1193
+		return $where;
1194
+	}
1195
+
1196
+
1197
+	/**
1198
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1199
+	 *
1200
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1201
+	 * @return array
1202
+	 */
1203
+	protected function _add_category_id_to_where_conditions(array $request)
1204
+	{
1205
+		$where = array();
1206
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1207
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1208
+		}
1209
+		return $where;
1210
+	}
1211
+
1212
+
1213
+	/**
1214
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1215
+	 *
1216
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1217
+	 * @return array
1218
+	 */
1219
+	protected function _add_datetime_id_to_where_conditions(array $request)
1220
+	{
1221
+		$where = array();
1222
+		if (! empty($request['datetime_id'])) {
1223
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1224
+		}
1225
+		if (! empty($request['DTT_ID'])) {
1226
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1227
+		}
1228
+		return $where;
1229
+	}
1230
+
1231
+
1232
+	/**
1233
+	 * Adds the correct registration status to the where conditions for the registrations query.
1234
+	 *
1235
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1236
+	 * @return array
1237
+	 */
1238
+	protected function _add_registration_status_to_where_conditions(array $request)
1239
+	{
1240
+		$where = array();
1241
+		$view = EEH_Array::is_set($request, 'status', '');
1242
+		$registration_status = ! empty($request['_reg_status'])
1243
+			? sanitize_text_field($request['_reg_status'])
1244
+			: '';
1245
+
1246
+		/*
1247 1247
          * If filtering by registration status, then we show registrations matching that status.
1248 1248
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1249 1249
          * UNLESS viewing trashed registrations.
1250 1250
          */
1251
-        if (! empty($registration_status)) {
1252
-            $where['STS_ID'] = $registration_status;
1253
-        } else {
1254
-            //make sure we exclude incomplete registrations, but only if not trashed.
1255
-            if ($view === 'trash') {
1256
-                $where['REG_deleted'] = true;
1257
-            } elseif ($view === 'incomplete') {
1258
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1259
-            } else {
1260
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1261
-            }
1262
-        }
1263
-        return $where;
1264
-    }
1265
-
1266
-
1267
-    /**
1268
-     * Adds any provided date restraints to the where conditions for the registrations query.
1269
-     *
1270
-     * @param array $request usually the same as $this->_req_data but not necessarily
1271
-     * @return array
1272
-     * @throws EE_Error
1273
-     */
1274
-    protected function _add_date_to_where_conditions(array $request)
1275
-    {
1276
-        $where = array();
1277
-        $view = EEH_Array::is_set($request, 'status', '');
1278
-        $month_range             = ! empty($request['month_range'])
1279
-            ? sanitize_text_field($request['month_range'])
1280
-            : '';
1281
-        $retrieve_for_today      = $view === 'today';
1282
-        $retrieve_for_this_month = $view === 'month';
1283
-
1284
-        if ($retrieve_for_today) {
1285
-            $now               = date('Y-m-d', current_time('timestamp'));
1286
-            $where['REG_date'] = array(
1287
-                'BETWEEN',
1288
-                array(
1289
-                    EEM_Registration::instance()->convert_datetime_for_query(
1290
-                        'REG_date',
1291
-                        $now . ' 00:00:00',
1292
-                        'Y-m-d H:i:s'
1293
-                    ),
1294
-                    EEM_Registration::instance()->convert_datetime_for_query(
1295
-                        'REG_date',
1296
-                        $now . ' 23:59:59',
1297
-                        'Y-m-d H:i:s'
1298
-                    ),
1299
-                ),
1300
-            );
1301
-        } elseif ($retrieve_for_this_month) {
1302
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1303
-            $days_this_month        = date('t', current_time('timestamp'));
1304
-            $where['REG_date']      = array(
1305
-                'BETWEEN',
1306
-                array(
1307
-                    EEM_Registration::instance()->convert_datetime_for_query(
1308
-                        'REG_date',
1309
-                        $current_year_and_month . '-01 00:00:00',
1310
-                        'Y-m-d H:i:s'
1311
-                    ),
1312
-                    EEM_Registration::instance()->convert_datetime_for_query(
1313
-                        'REG_date',
1314
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1315
-                        'Y-m-d H:i:s'
1316
-                    ),
1317
-                ),
1318
-            );
1319
-        } elseif ($month_range) {
1320
-            $pieces          = explode(' ', $month_range, 3);
1321
-            $month_requested = ! empty($pieces[0])
1322
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1323
-                : '';
1324
-            $year_requested  = ! empty($pieces[1])
1325
-                ? $pieces[1]
1326
-                : '';
1327
-            //if there is not a month or year then we can't go further
1328
-            if ($month_requested && $year_requested) {
1329
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1330
-                $where['REG_date'] = array(
1331
-                    'BETWEEN',
1332
-                    array(
1333
-                        EEM_Registration::instance()->convert_datetime_for_query(
1334
-                            'REG_date',
1335
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1336
-                            'Y-m-d H:i:s'
1337
-                        ),
1338
-                        EEM_Registration::instance()->convert_datetime_for_query(
1339
-                            'REG_date',
1340
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1341
-                            'Y-m-d H:i:s'
1342
-                        ),
1343
-                    ),
1344
-                );
1345
-            }
1346
-        }
1347
-        return $where;
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * Adds any provided search restraints to the where conditions for the registrations query
1353
-     *
1354
-     * @param array $request usually the same as $this->_req_data but not necessarily
1355
-     * @return array
1356
-     */
1357
-    protected function _add_search_to_where_conditions(array $request)
1358
-    {
1359
-        $where = array();
1360
-        if (! empty($request['s'])) {
1361
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1362
-            $where['OR*search_conditions'] = array(
1363
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1364
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1365
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1366
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1367
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1368
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1369
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1370
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1371
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1372
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1373
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1374
-                'REG_final_price'                         => array('LIKE', $search_string),
1375
-                'REG_code'                                => array('LIKE', $search_string),
1376
-                'REG_count'                               => array('LIKE', $search_string),
1377
-                'REG_group_size'                          => array('LIKE', $search_string),
1378
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1379
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1380
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1381
-            );
1382
-        }
1383
-        return $where;
1384
-    }
1385
-
1386
-
1387
-    /**
1388
-     * Sets up the where conditions for the registrations query.
1389
-     *
1390
-     * @param array $request
1391
-     * @return array
1392
-     * @throws EE_Error
1393
-     */
1394
-    protected function _get_where_conditions_for_registrations_query($request)
1395
-    {
1396
-        return apply_filters(
1397
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1398
-            array_merge(
1399
-                $this->_add_event_id_to_where_conditions($request),
1400
-                $this->_add_category_id_to_where_conditions($request),
1401
-                $this->_add_datetime_id_to_where_conditions($request),
1402
-                $this->_add_registration_status_to_where_conditions($request),
1403
-                $this->_add_date_to_where_conditions($request),
1404
-                $this->_add_search_to_where_conditions($request)
1405
-            ),
1406
-            $request
1407
-        );
1408
-    }
1409
-
1410
-
1411
-    /**
1412
-     * Sets up the orderby for the registrations query.
1413
-     *
1414
-     * @return array
1415
-     */
1416
-    protected function _get_orderby_for_registrations_query()
1417
-    {
1418
-        $orderby_field = ! empty($this->_req_data['orderby'])
1419
-            ? sanitize_text_field($this->_req_data['orderby'])
1420
-            : '';
1421
-        switch ($orderby_field) {
1422
-            case '_REG_ID':
1423
-                $orderby_field = 'REG_ID';
1424
-                break;
1425
-            case '_Reg_status':
1426
-                $orderby_field = 'STS_ID';
1427
-                break;
1428
-            case 'ATT_fname':
1429
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1430
-                break;
1431
-            case 'ATT_lname':
1432
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1433
-                break;
1434
-            case 'event_name':
1435
-                $orderby_field = 'Event.EVT_name';
1436
-                break;
1437
-            case 'DTT_EVT_start':
1438
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1439
-                break;
1440
-            default: //'REG_date'
1441
-                $orderby_field = 'REG_date';
1442
-        }
1443
-
1444
-        //order
1445
-        $order = ! empty($this->_req_data['order'])
1446
-            ? sanitize_text_field($this->_req_data['order'])
1447
-            : 'DESC';
1448
-
1449
-        //mutate orderby_field
1450
-        $orderby_field = array_combine(
1451
-            (array) $orderby_field,
1452
-            array_fill(0, count($orderby_field), $order)
1453
-        );
1454
-        return array('order_by' => $orderby_field);
1455
-    }
1456
-
1457
-
1458
-    /**
1459
-     * Sets up the limit for the registrations query.
1460
-     *
1461
-     * @param $per_page
1462
-     * @return array
1463
-     */
1464
-    protected function _get_limit($per_page)
1465
-    {
1466
-        $current_page = ! empty($this->_req_data['paged'])
1467
-            ? absint($this->_req_data['paged'])
1468
-            : 1;
1469
-        $per_page     = ! empty($this->_req_data['perpage'])
1470
-            ? $this->_req_data['perpage']
1471
-            : $per_page;
1472
-
1473
-        //-1 means return all results so get out if that's set.
1474
-        if ((int)$per_page === -1) {
1475
-            return array();
1476
-        }
1477
-        $per_page = absint($per_page);
1478
-        $offset   = ($current_page - 1) * $per_page;
1479
-        return array('limit' => array($offset, $per_page));
1480
-    }
1481
-
1482
-
1483
-    public function get_registration_status_array()
1484
-    {
1485
-        return self::$_reg_status;
1486
-    }
1487
-
1488
-
1489
-
1490
-
1491
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1492
-    /**
1493
-     *        generates HTML for the View Registration Details Admin page
1494
-     *
1495
-     * @access protected
1496
-     * @return void
1497
-     * @throws DomainException
1498
-     * @throws EE_Error
1499
-     * @throws EntityNotFoundException
1500
-     */
1501
-    protected function _registration_details()
1502
-    {
1503
-        $this->_template_args = array();
1504
-        $this->_set_registration_object();
1505
-        if (is_object($this->_registration)) {
1506
-            $transaction                                   = $this->_registration->transaction()
1507
-                ? $this->_registration->transaction()
1508
-                : EE_Transaction::new_instance();
1509
-            $this->_session                                = $transaction->session_data();
1510
-            $event_id                                      = $this->_registration->event_ID();
1511
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1512
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1513
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1514
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1515
-            $this->_template_args['grand_total']           = $transaction->total();
1516
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1517
-            // link back to overview
1518
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1519
-            $this->_template_args['registration']                = $this->_registration;
1520
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1521
-                array(
1522
-                    'action'   => 'default',
1523
-                    'event_id' => $event_id,
1524
-                ),
1525
-                REG_ADMIN_URL
1526
-            );
1527
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1528
-                array(
1529
-                    'action' => 'default',
1530
-                    'EVT_ID' => $event_id,
1531
-                    'page'   => 'espresso_transactions',
1532
-                ),
1533
-                admin_url('admin.php')
1534
-            );
1535
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1536
-                array(
1537
-                    'page'   => 'espresso_events',
1538
-                    'action' => 'edit',
1539
-                    'post'   => $event_id,
1540
-                ),
1541
-                admin_url('admin.php')
1542
-            );
1543
-            //next and previous links
1544
-            $next_reg                                      = $this->_registration->next(
1545
-                null,
1546
-                array(),
1547
-                'REG_ID'
1548
-            );
1549
-            $this->_template_args['next_registration']     = $next_reg
1550
-                ? $this->_next_link(
1551
-                    EE_Admin_Page::add_query_args_and_nonce(
1552
-                        array(
1553
-                            'action'  => 'view_registration',
1554
-                            '_REG_ID' => $next_reg['REG_ID'],
1555
-                        ),
1556
-                        REG_ADMIN_URL
1557
-                    ),
1558
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1559
-                )
1560
-                : '';
1561
-            $previous_reg                                  = $this->_registration->previous(
1562
-                null,
1563
-                array(),
1564
-                'REG_ID'
1565
-            );
1566
-            $this->_template_args['previous_registration'] = $previous_reg
1567
-                ? $this->_previous_link(
1568
-                    EE_Admin_Page::add_query_args_and_nonce(
1569
-                        array(
1570
-                            'action'  => 'view_registration',
1571
-                            '_REG_ID' => $previous_reg['REG_ID'],
1572
-                        ),
1573
-                        REG_ADMIN_URL
1574
-                    ),
1575
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1576
-                )
1577
-                : '';
1578
-            // grab header
1579
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1580
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1581
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1582
-                $template_path,
1583
-                $this->_template_args,
1584
-                true
1585
-            );
1586
-        } else {
1587
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1588
-        }
1589
-        // the details template wrapper
1590
-        $this->display_admin_page_with_sidebar();
1591
-    }
1592
-
1593
-
1594
-    protected function _registration_details_metaboxes()
1595
-    {
1596
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1597
-        $this->_set_registration_object();
1598
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1599
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1600
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1601
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1602
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1603
-        if ($attendee instanceof EE_Attendee
1604
-            && EE_Registry::instance()->CAP->current_user_can(
1605
-                'ee_edit_registration',
1606
-                'edit-reg-questions-mbox',
1607
-                $this->_registration->ID()
1608
-            )
1609
-        ) {
1610
-            add_meta_box(
1611
-                'edit-reg-questions-mbox',
1612
-                esc_html__('Registration Form Answers', 'event_espresso'),
1613
-                array($this, '_reg_questions_meta_box'),
1614
-                $this->wp_page_slug,
1615
-                'normal',
1616
-                'high'
1617
-            );
1618
-        }
1619
-        add_meta_box(
1620
-            'edit-reg-registrant-mbox',
1621
-            esc_html__('Contact Details', 'event_espresso'),
1622
-            array($this, '_reg_registrant_side_meta_box'),
1623
-            $this->wp_page_slug,
1624
-            'side',
1625
-            'high'
1626
-        );
1627
-        if ($this->_registration->group_size() > 1) {
1628
-            add_meta_box(
1629
-                'edit-reg-attendees-mbox',
1630
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1631
-                array($this, '_reg_attendees_meta_box'),
1632
-                $this->wp_page_slug,
1633
-                'normal',
1634
-                'high'
1635
-            );
1636
-        }
1637
-    }
1638
-
1639
-
1640
-    /**
1641
-     * set_reg_status_buttons_metabox
1642
-     *
1643
-     * @access protected
1644
-     * @return string
1645
-     * @throws \EE_Error
1646
-     */
1647
-    public function set_reg_status_buttons_metabox()
1648
-    {
1649
-        $this->_set_registration_object();
1650
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1651
-        echo $change_reg_status_form->form_open(
1652
-            self::add_query_args_and_nonce(
1653
-                array(
1654
-                    'action' => 'change_reg_status',
1655
-                ),
1656
-                REG_ADMIN_URL
1657
-            )
1658
-        );
1659
-        echo $change_reg_status_form->get_html();
1660
-        echo $change_reg_status_form->form_close();
1661
-    }
1662
-
1663
-
1664
-
1665
-    /**
1666
-     * @return EE_Form_Section_Proper
1667
-     * @throws EE_Error
1668
-     */
1669
-    protected function _generate_reg_status_change_form()
1670
-    {
1671
-        return new EE_Form_Section_Proper(array(
1672
-            'name'            => 'reg_status_change_form',
1673
-            'html_id'         => 'reg-status-change-form',
1674
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1675
-            'subsections'     => array(
1676
-                'return'             => new EE_Hidden_Input(array(
1677
-                    'name'    => 'return',
1678
-                    'default' => 'view_registration',
1679
-                )),
1680
-                'REG_ID'             => new EE_Hidden_Input(array(
1681
-                    'name'    => 'REG_ID',
1682
-                    'default' => $this->_registration->ID(),
1683
-                )),
1684
-                'current_status'     => new EE_Form_Section_HTML(
1685
-                    EEH_HTML::tr(
1686
-                        EEH_HTML::th(
1687
-                            EEH_HTML::label(
1688
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1689
-                                )
1690
-                            )
1691
-                        )
1692
-                        . EEH_HTML::td(
1693
-                            EEH_HTML::strong(
1694
-                                $this->_registration->pretty_status(),
1695
-                                '',
1696
-                                'status-' . $this->_registration->status_ID(),
1697
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1698
-                            )
1699
-                        )
1700
-                    )
1701
-                ),
1702
-                'reg_status'         => new EE_Select_Input(
1703
-                    $this->_get_reg_statuses(),
1704
-                    array(
1705
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1706
-                        'default'         => $this->_registration->status_ID(),
1707
-                    )
1708
-                ),
1709
-                'send_notifications' => new EE_Yes_No_Input(
1710
-                    array(
1711
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1712
-                        'default'         => false,
1713
-                        'html_help_text'  => esc_html__(
1714
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1715
-                            'event_espresso'
1716
-                        ),
1717
-                    )
1718
-                ),
1719
-                'submit'             => new EE_Submit_Input(
1720
-                    array(
1721
-                        'html_class'      => 'button-primary',
1722
-                        'html_label_text' => '&nbsp;',
1723
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1724
-                    )
1725
-                ),
1726
-            ),
1727
-        ));
1728
-    }
1729
-
1730
-
1731
-    /**
1732
-     * Returns an array of all the buttons for the various statuses and switch status actions
1733
-     *
1734
-     * @return array
1735
-     * @throws EE_Error
1736
-     * @throws EntityNotFoundException
1737
-     */
1738
-    protected function _get_reg_statuses()
1739
-    {
1740
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1741
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1742
-        // get current reg status
1743
-        $current_status = $this->_registration->status_ID();
1744
-        // is registration for free event? This will determine whether to display the pending payment option
1745
-        if (
1746
-            $current_status !== EEM_Registration::status_id_pending_payment
1747
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1748
-        ) {
1749
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1750
-        }
1751
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1752
-    }
1753
-
1754
-
1755
-    /**
1756
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1757
-     *
1758
-     * @param bool $status REG status given for changing registrations to.
1759
-     * @param bool $notify Whether to send messages notifications or not.
1760
-     * @return array (array with reg_id(s) updated and whether update was successful.
1761
-     * @throws EE_Error
1762
-     * @throws InvalidArgumentException
1763
-     * @throws InvalidDataTypeException
1764
-     * @throws InvalidInterfaceException
1765
-     * @throws ReflectionException
1766
-     * @throws RuntimeException
1767
-     * @throws EntityNotFoundException
1768
-     */
1769
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1770
-    {
1771
-        if (isset($this->_req_data['reg_status_change_form'])) {
1772
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1773
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1774
-                : array();
1775
-        } else {
1776
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1777
-                ? (array)$this->_req_data['_REG_ID']
1778
-                : array();
1779
-        }
1780
-        // sanitize $REG_IDs
1781
-        $REG_IDs = array_map('absint', $REG_IDs);
1782
-        // and remove empty entries
1783
-        $REG_IDs = array_filter($REG_IDs);
1784
-
1785
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1786
-
1787
-        /**
1788
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1789
-         * Currently this value is used downstream by the _process_resend_registration method.
1790
-         *
1791
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1792
-         * @param bool                     $status           The status registrations were changed to.
1793
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1794
-         * @param Registrations_Admin_Page $admin_page_object
1795
-         */
1796
-        $this->_req_data['_REG_ID'] = apply_filters(
1797
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1798
-            $result['REG_ID'],
1799
-            $status,
1800
-            $result['success'],
1801
-            $this
1802
-        );
1803
-
1804
-        //notify?
1805
-        if ($notify
1806
-            && $result['success']
1807
-            && ! empty($this->_req_data['_REG_ID'])
1808
-            && EE_Registry::instance()->CAP->current_user_can(
1809
-                'ee_send_message',
1810
-                'espresso_registrations_resend_registration'
1811
-            )
1812
-        ) {
1813
-            $this->_process_resend_registration();
1814
-        }
1815
-        return $result;
1816
-    }
1817
-
1818
-
1819
-    /**
1820
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1821
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1822
-     *
1823
-     * @param array  $REG_IDs
1824
-     * @param string $status
1825
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1826
-     *                        slug sent with setting the registration status.
1827
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1828
-     * @throws EE_Error
1829
-     * @throws InvalidArgumentException
1830
-     * @throws InvalidDataTypeException
1831
-     * @throws InvalidInterfaceException
1832
-     * @throws ReflectionException
1833
-     * @throws RuntimeException
1834
-     * @throws EntityNotFoundException
1835
-     */
1836
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1837
-    {
1838
-        $success = false;
1839
-        // typecast $REG_IDs
1840
-        $REG_IDs = (array)$REG_IDs;
1841
-        if ( ! empty($REG_IDs)) {
1842
-            $success = true;
1843
-            // set default status if none is passed
1844
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1845
-            $status_context = $notify
1846
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1847
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1848
-            //loop through REG_ID's and change status
1849
-            foreach ($REG_IDs as $REG_ID) {
1850
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1851
-                if ($registration instanceof EE_Registration) {
1852
-                    $registration->set_status(
1853
-                        $status,
1854
-                        false,
1855
-                        new Context(
1856
-                            $status_context,
1857
-                            esc_html__(
1858
-                                'Manually triggered status change on a Registration Admin Page route.',
1859
-                                'event_espresso'
1860
-                            )
1861
-                        )
1862
-                    );
1863
-                    $result = $registration->save();
1864
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1865
-                    $success = $result !== false ? $success : false;
1866
-                }
1867
-            }
1868
-        }
1869
-
1870
-        //return $success and processed registrations
1871
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1872
-    }
1873
-
1874
-
1875
-    /**
1876
-     * Common logic for setting up success message and redirecting to appropriate route
1877
-     *
1878
-     * @param  string $STS_ID status id for the registration changed to
1879
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1880
-     * @return void
1881
-     */
1882
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1883
-    {
1884
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1885
-            : array('success' => false);
1886
-        $success = isset($result['success']) && $result['success'];
1887
-        //setup success message
1888
-        if ($success) {
1889
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1890
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1891
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1892
-            } else {
1893
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1894
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1895
-            }
1896
-            EE_Error::add_success($msg);
1897
-        } else {
1898
-            EE_Error::add_error(
1899
-                esc_html__(
1900
-                    'Something went wrong, and the status was not changed',
1901
-                    'event_espresso'
1902
-                ), __FILE__, __LINE__, __FUNCTION__
1903
-            );
1904
-        }
1905
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1906
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1907
-        } else {
1908
-            $route = array('action' => 'default');
1909
-        }
1910
-        //unset nonces
1911
-        foreach ($this->_req_data as $ref => $value) {
1912
-            if (strpos($ref, 'nonce') !== false) {
1913
-                unset($this->_req_data[$ref]);
1914
-                continue;
1915
-            }
1916
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1917
-            $this->_req_data[$ref] = $value;
1918
-        }
1919
-        //merge request vars so that the reloaded list table contains any existing filter query params
1920
-        $route = array_merge($this->_req_data, $route);
1921
-        $this->_redirect_after_action($success, '', '', $route, true);
1922
-    }
1923
-
1924
-
1925
-    /**
1926
-     * incoming reg status change from reg details page.
1927
-     *
1928
-     * @return void
1929
-     */
1930
-    protected function _change_reg_status()
1931
-    {
1932
-        $this->_req_data['return'] = 'view_registration';
1933
-        //set notify based on whether the send notifications toggle is set or not
1934
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1935
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1936
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1937
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1938
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1939
-            case EEM_Registration::status_id_approved :
1940
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1941
-                $this->approve_registration($notify);
1942
-                break;
1943
-            case EEM_Registration::status_id_pending_payment :
1944
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1945
-                $this->pending_registration($notify);
1946
-                break;
1947
-            case EEM_Registration::status_id_not_approved :
1948
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1949
-                $this->not_approve_registration($notify);
1950
-                break;
1951
-            case EEM_Registration::status_id_declined :
1952
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1953
-                $this->decline_registration($notify);
1954
-                break;
1955
-            case EEM_Registration::status_id_cancelled :
1956
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1957
-                $this->cancel_registration($notify);
1958
-                break;
1959
-            case EEM_Registration::status_id_wait_list :
1960
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1961
-                $this->wait_list_registration($notify);
1962
-                break;
1963
-            case EEM_Registration::status_id_incomplete :
1964
-            default :
1965
-                $result['success'] = false;
1966
-                unset($this->_req_data['return']);
1967
-                $this->_reg_status_change_return('', false);
1968
-                break;
1969
-        }
1970
-    }
1971
-
1972
-
1973
-    /**
1974
-     * Callback for bulk action routes.
1975
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1976
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1977
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1978
-     * when an action is happening on just a single registration).
1979
-     * @param      $action
1980
-     * @param bool $notify
1981
-     */
1982
-    protected function bulk_action_on_registrations($action, $notify = false) {
1983
-        do_action(
1984
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1985
-            $this,
1986
-            $action,
1987
-            $notify
1988
-        );
1989
-        $method = $action . '_registration';
1990
-        if (method_exists($this, $method)) {
1991
-            $this->$method($notify);
1992
-        }
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * approve_registration
1998
-     *
1999
-     * @access protected
2000
-     * @param bool $notify whether or not to notify the registrant about their approval.
2001
-     * @return void
2002
-     */
2003
-    protected function approve_registration($notify = false)
2004
-    {
2005
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2006
-    }
2007
-
2008
-
2009
-    /**
2010
-     *        decline_registration
2011
-     *
2012
-     * @access protected
2013
-     * @param bool $notify whether or not to notify the registrant about their status change.
2014
-     * @return void
2015
-     */
2016
-    protected function decline_registration($notify = false)
2017
-    {
2018
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2019
-    }
2020
-
2021
-
2022
-    /**
2023
-     *        cancel_registration
2024
-     *
2025
-     * @access protected
2026
-     * @param bool $notify whether or not to notify the registrant about their status change.
2027
-     * @return void
2028
-     */
2029
-    protected function cancel_registration($notify = false)
2030
-    {
2031
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2032
-    }
2033
-
2034
-
2035
-    /**
2036
-     *        not_approve_registration
2037
-     *
2038
-     * @access protected
2039
-     * @param bool $notify whether or not to notify the registrant about their status change.
2040
-     * @return void
2041
-     */
2042
-    protected function not_approve_registration($notify = false)
2043
-    {
2044
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2045
-    }
2046
-
2047
-
2048
-    /**
2049
-     *        decline_registration
2050
-     *
2051
-     * @access protected
2052
-     * @param bool $notify whether or not to notify the registrant about their status change.
2053
-     * @return void
2054
-     */
2055
-    protected function pending_registration($notify = false)
2056
-    {
2057
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2058
-    }
2059
-
2060
-
2061
-    /**
2062
-     * waitlist_registration
2063
-     *
2064
-     * @access protected
2065
-     * @param bool $notify whether or not to notify the registrant about their status change.
2066
-     * @return void
2067
-     */
2068
-    protected function wait_list_registration($notify = false)
2069
-    {
2070
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2071
-    }
2072
-
2073
-
2074
-    /**
2075
-     *        generates HTML for the Registration main meta box
2076
-     *
2077
-     * @access public
2078
-     * @return void
2079
-     * @throws DomainException
2080
-     * @throws EE_Error
2081
-     * @throws EntityNotFoundException
2082
-     */
2083
-    public function _reg_details_meta_box()
2084
-    {
2085
-        EEH_Autoloader::register_line_item_display_autoloaders();
2086
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2087
-        EE_Registry::instance()->load_helper('Line_Item');
2088
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2089
-            : EE_Transaction::new_instance();
2090
-        $this->_session = $transaction->session_data();
2091
-        $filters        = new EE_Line_Item_Filter_Collection();
2092
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2093
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2094
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2095
-            $transaction->total_line_item());
2096
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2097
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2098
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2099
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2100
-            $filtered_line_item_tree,
2101
-            array('EE_Registration' => $this->_registration)
2102
-        );
2103
-        $attendee                                = $this->_registration->attendee();
2104
-        if (EE_Registry::instance()->CAP->current_user_can(
2105
-            'ee_read_transaction',
2106
-            'espresso_transactions_view_transaction'
2107
-        )) {
2108
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2109
-                EE_Admin_Page::add_query_args_and_nonce(
2110
-                    array(
2111
-                        'action' => 'view_transaction',
2112
-                        'TXN_ID' => $transaction->ID(),
2113
-                    ),
2114
-                    TXN_ADMIN_URL
2115
-                ),
2116
-                esc_html__(' View Transaction', 'event_espresso'),
2117
-                'button secondary-button right',
2118
-                'dashicons dashicons-cart'
2119
-            );
2120
-        } else {
2121
-            $this->_template_args['view_transaction_button'] = '';
2122
-        }
2123
-        if ($attendee instanceof EE_Attendee
2124
-            && EE_Registry::instance()->CAP->current_user_can(
2125
-                'ee_send_message',
2126
-                'espresso_registrations_resend_registration'
2127
-            )
2128
-        ) {
2129
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2130
-                EE_Admin_Page::add_query_args_and_nonce(
2131
-                    array(
2132
-                        'action'      => 'resend_registration',
2133
-                        '_REG_ID'     => $this->_registration->ID(),
2134
-                        'redirect_to' => 'view_registration',
2135
-                    ),
2136
-                    REG_ADMIN_URL
2137
-                ),
2138
-                esc_html__(' Resend Registration', 'event_espresso'),
2139
-                'button secondary-button right',
2140
-                'dashicons dashicons-email-alt'
2141
-            );
2142
-        } else {
2143
-            $this->_template_args['resend_registration_button'] = '';
2144
-        }
2145
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2146
-        $payment                               = $transaction->get_first_related('Payment');
2147
-        $payment                               = ! $payment instanceof EE_Payment
2148
-            ? EE_Payment::new_instance()
2149
-            : $payment;
2150
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2151
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2152
-            ? EE_Payment_Method::new_instance()
2153
-            : $payment_method;
2154
-        $reg_details                           = array(
2155
-            'payment_method'       => $payment_method->name(),
2156
-            'response_msg'         => $payment->gateway_response(),
2157
-            'registration_id'      => $this->_registration->get('REG_code'),
2158
-            'registration_session' => $this->_registration->session_ID(),
2159
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2160
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2161
-        );
2162
-        if (isset($reg_details['registration_id'])) {
2163
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2164
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2165
-                'Registration ID',
2166
-                'event_espresso'
2167
-            );
2168
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2169
-        }
2170
-        if (isset($reg_details['payment_method'])) {
2171
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2172
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2173
-                'Most Recent Payment Method',
2174
-                'event_espresso'
2175
-            );
2176
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2177
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2178
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2179
-                'Payment method response',
2180
-                'event_espresso'
2181
-            );
2182
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2183
-        }
2184
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2185
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2186
-            'Registration Session',
2187
-            'event_espresso'
2188
-        );
2189
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2190
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2191
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2192
-            'Registration placed from IP',
2193
-            'event_espresso'
2194
-        );
2195
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2196
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2197
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2198
-            'event_espresso');
2199
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2200
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2201
-            array(
2202
-                'action'   => 'default',
2203
-                'event_id' => $this->_registration->event_ID(),
2204
-            ),
2205
-            REG_ADMIN_URL
2206
-        );
2207
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2208
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2209
-        $template_path                                                        =
2210
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2211
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2212
-    }
2213
-
2214
-
2215
-    /**
2216
-     * generates HTML for the Registration Questions meta box.
2217
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2218
-     * otherwise uses new forms system
2219
-     *
2220
-     * @access public
2221
-     * @return void
2222
-     * @throws DomainException
2223
-     * @throws EE_Error
2224
-     */
2225
-    public function _reg_questions_meta_box()
2226
-    {
2227
-        //allow someone to override this method entirely
2228
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2229
-            $this->_registration)) {
2230
-            $form                                              = $this->_get_reg_custom_questions_form(
2231
-                $this->_registration->ID()
2232
-            );
2233
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2234
-                ? $form->get_html_and_js()
2235
-                : '';
2236
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2237
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2238
-            $template_path                                     =
2239
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2240
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2241
-        }
2242
-    }
2243
-
2244
-
2245
-    /**
2246
-     * form_before_question_group
2247
-     *
2248
-     * @deprecated    as of 4.8.32.rc.000
2249
-     * @access        public
2250
-     * @param        string $output
2251
-     * @return        string
2252
-     */
2253
-    public function form_before_question_group($output)
2254
-    {
2255
-        EE_Error::doing_it_wrong(
2256
-            __CLASS__ . '::' . __FUNCTION__,
2257
-            esc_html__(
2258
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2259
-                'event_espresso'
2260
-            ),
2261
-            '4.8.32.rc.000'
2262
-        );
2263
-        return '
1251
+		if (! empty($registration_status)) {
1252
+			$where['STS_ID'] = $registration_status;
1253
+		} else {
1254
+			//make sure we exclude incomplete registrations, but only if not trashed.
1255
+			if ($view === 'trash') {
1256
+				$where['REG_deleted'] = true;
1257
+			} elseif ($view === 'incomplete') {
1258
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1259
+			} else {
1260
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1261
+			}
1262
+		}
1263
+		return $where;
1264
+	}
1265
+
1266
+
1267
+	/**
1268
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1269
+	 *
1270
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1271
+	 * @return array
1272
+	 * @throws EE_Error
1273
+	 */
1274
+	protected function _add_date_to_where_conditions(array $request)
1275
+	{
1276
+		$where = array();
1277
+		$view = EEH_Array::is_set($request, 'status', '');
1278
+		$month_range             = ! empty($request['month_range'])
1279
+			? sanitize_text_field($request['month_range'])
1280
+			: '';
1281
+		$retrieve_for_today      = $view === 'today';
1282
+		$retrieve_for_this_month = $view === 'month';
1283
+
1284
+		if ($retrieve_for_today) {
1285
+			$now               = date('Y-m-d', current_time('timestamp'));
1286
+			$where['REG_date'] = array(
1287
+				'BETWEEN',
1288
+				array(
1289
+					EEM_Registration::instance()->convert_datetime_for_query(
1290
+						'REG_date',
1291
+						$now . ' 00:00:00',
1292
+						'Y-m-d H:i:s'
1293
+					),
1294
+					EEM_Registration::instance()->convert_datetime_for_query(
1295
+						'REG_date',
1296
+						$now . ' 23:59:59',
1297
+						'Y-m-d H:i:s'
1298
+					),
1299
+				),
1300
+			);
1301
+		} elseif ($retrieve_for_this_month) {
1302
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1303
+			$days_this_month        = date('t', current_time('timestamp'));
1304
+			$where['REG_date']      = array(
1305
+				'BETWEEN',
1306
+				array(
1307
+					EEM_Registration::instance()->convert_datetime_for_query(
1308
+						'REG_date',
1309
+						$current_year_and_month . '-01 00:00:00',
1310
+						'Y-m-d H:i:s'
1311
+					),
1312
+					EEM_Registration::instance()->convert_datetime_for_query(
1313
+						'REG_date',
1314
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1315
+						'Y-m-d H:i:s'
1316
+					),
1317
+				),
1318
+			);
1319
+		} elseif ($month_range) {
1320
+			$pieces          = explode(' ', $month_range, 3);
1321
+			$month_requested = ! empty($pieces[0])
1322
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1323
+				: '';
1324
+			$year_requested  = ! empty($pieces[1])
1325
+				? $pieces[1]
1326
+				: '';
1327
+			//if there is not a month or year then we can't go further
1328
+			if ($month_requested && $year_requested) {
1329
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1330
+				$where['REG_date'] = array(
1331
+					'BETWEEN',
1332
+					array(
1333
+						EEM_Registration::instance()->convert_datetime_for_query(
1334
+							'REG_date',
1335
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1336
+							'Y-m-d H:i:s'
1337
+						),
1338
+						EEM_Registration::instance()->convert_datetime_for_query(
1339
+							'REG_date',
1340
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1341
+							'Y-m-d H:i:s'
1342
+						),
1343
+					),
1344
+				);
1345
+			}
1346
+		}
1347
+		return $where;
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * Adds any provided search restraints to the where conditions for the registrations query
1353
+	 *
1354
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1355
+	 * @return array
1356
+	 */
1357
+	protected function _add_search_to_where_conditions(array $request)
1358
+	{
1359
+		$where = array();
1360
+		if (! empty($request['s'])) {
1361
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1362
+			$where['OR*search_conditions'] = array(
1363
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1364
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1365
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1366
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1367
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1368
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1369
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1370
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1371
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1372
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1373
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1374
+				'REG_final_price'                         => array('LIKE', $search_string),
1375
+				'REG_code'                                => array('LIKE', $search_string),
1376
+				'REG_count'                               => array('LIKE', $search_string),
1377
+				'REG_group_size'                          => array('LIKE', $search_string),
1378
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1379
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1380
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1381
+			);
1382
+		}
1383
+		return $where;
1384
+	}
1385
+
1386
+
1387
+	/**
1388
+	 * Sets up the where conditions for the registrations query.
1389
+	 *
1390
+	 * @param array $request
1391
+	 * @return array
1392
+	 * @throws EE_Error
1393
+	 */
1394
+	protected function _get_where_conditions_for_registrations_query($request)
1395
+	{
1396
+		return apply_filters(
1397
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1398
+			array_merge(
1399
+				$this->_add_event_id_to_where_conditions($request),
1400
+				$this->_add_category_id_to_where_conditions($request),
1401
+				$this->_add_datetime_id_to_where_conditions($request),
1402
+				$this->_add_registration_status_to_where_conditions($request),
1403
+				$this->_add_date_to_where_conditions($request),
1404
+				$this->_add_search_to_where_conditions($request)
1405
+			),
1406
+			$request
1407
+		);
1408
+	}
1409
+
1410
+
1411
+	/**
1412
+	 * Sets up the orderby for the registrations query.
1413
+	 *
1414
+	 * @return array
1415
+	 */
1416
+	protected function _get_orderby_for_registrations_query()
1417
+	{
1418
+		$orderby_field = ! empty($this->_req_data['orderby'])
1419
+			? sanitize_text_field($this->_req_data['orderby'])
1420
+			: '';
1421
+		switch ($orderby_field) {
1422
+			case '_REG_ID':
1423
+				$orderby_field = 'REG_ID';
1424
+				break;
1425
+			case '_Reg_status':
1426
+				$orderby_field = 'STS_ID';
1427
+				break;
1428
+			case 'ATT_fname':
1429
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1430
+				break;
1431
+			case 'ATT_lname':
1432
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1433
+				break;
1434
+			case 'event_name':
1435
+				$orderby_field = 'Event.EVT_name';
1436
+				break;
1437
+			case 'DTT_EVT_start':
1438
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1439
+				break;
1440
+			default: //'REG_date'
1441
+				$orderby_field = 'REG_date';
1442
+		}
1443
+
1444
+		//order
1445
+		$order = ! empty($this->_req_data['order'])
1446
+			? sanitize_text_field($this->_req_data['order'])
1447
+			: 'DESC';
1448
+
1449
+		//mutate orderby_field
1450
+		$orderby_field = array_combine(
1451
+			(array) $orderby_field,
1452
+			array_fill(0, count($orderby_field), $order)
1453
+		);
1454
+		return array('order_by' => $orderby_field);
1455
+	}
1456
+
1457
+
1458
+	/**
1459
+	 * Sets up the limit for the registrations query.
1460
+	 *
1461
+	 * @param $per_page
1462
+	 * @return array
1463
+	 */
1464
+	protected function _get_limit($per_page)
1465
+	{
1466
+		$current_page = ! empty($this->_req_data['paged'])
1467
+			? absint($this->_req_data['paged'])
1468
+			: 1;
1469
+		$per_page     = ! empty($this->_req_data['perpage'])
1470
+			? $this->_req_data['perpage']
1471
+			: $per_page;
1472
+
1473
+		//-1 means return all results so get out if that's set.
1474
+		if ((int)$per_page === -1) {
1475
+			return array();
1476
+		}
1477
+		$per_page = absint($per_page);
1478
+		$offset   = ($current_page - 1) * $per_page;
1479
+		return array('limit' => array($offset, $per_page));
1480
+	}
1481
+
1482
+
1483
+	public function get_registration_status_array()
1484
+	{
1485
+		return self::$_reg_status;
1486
+	}
1487
+
1488
+
1489
+
1490
+
1491
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1492
+	/**
1493
+	 *        generates HTML for the View Registration Details Admin page
1494
+	 *
1495
+	 * @access protected
1496
+	 * @return void
1497
+	 * @throws DomainException
1498
+	 * @throws EE_Error
1499
+	 * @throws EntityNotFoundException
1500
+	 */
1501
+	protected function _registration_details()
1502
+	{
1503
+		$this->_template_args = array();
1504
+		$this->_set_registration_object();
1505
+		if (is_object($this->_registration)) {
1506
+			$transaction                                   = $this->_registration->transaction()
1507
+				? $this->_registration->transaction()
1508
+				: EE_Transaction::new_instance();
1509
+			$this->_session                                = $transaction->session_data();
1510
+			$event_id                                      = $this->_registration->event_ID();
1511
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1512
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1513
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1514
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1515
+			$this->_template_args['grand_total']           = $transaction->total();
1516
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1517
+			// link back to overview
1518
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1519
+			$this->_template_args['registration']                = $this->_registration;
1520
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1521
+				array(
1522
+					'action'   => 'default',
1523
+					'event_id' => $event_id,
1524
+				),
1525
+				REG_ADMIN_URL
1526
+			);
1527
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1528
+				array(
1529
+					'action' => 'default',
1530
+					'EVT_ID' => $event_id,
1531
+					'page'   => 'espresso_transactions',
1532
+				),
1533
+				admin_url('admin.php')
1534
+			);
1535
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1536
+				array(
1537
+					'page'   => 'espresso_events',
1538
+					'action' => 'edit',
1539
+					'post'   => $event_id,
1540
+				),
1541
+				admin_url('admin.php')
1542
+			);
1543
+			//next and previous links
1544
+			$next_reg                                      = $this->_registration->next(
1545
+				null,
1546
+				array(),
1547
+				'REG_ID'
1548
+			);
1549
+			$this->_template_args['next_registration']     = $next_reg
1550
+				? $this->_next_link(
1551
+					EE_Admin_Page::add_query_args_and_nonce(
1552
+						array(
1553
+							'action'  => 'view_registration',
1554
+							'_REG_ID' => $next_reg['REG_ID'],
1555
+						),
1556
+						REG_ADMIN_URL
1557
+					),
1558
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1559
+				)
1560
+				: '';
1561
+			$previous_reg                                  = $this->_registration->previous(
1562
+				null,
1563
+				array(),
1564
+				'REG_ID'
1565
+			);
1566
+			$this->_template_args['previous_registration'] = $previous_reg
1567
+				? $this->_previous_link(
1568
+					EE_Admin_Page::add_query_args_and_nonce(
1569
+						array(
1570
+							'action'  => 'view_registration',
1571
+							'_REG_ID' => $previous_reg['REG_ID'],
1572
+						),
1573
+						REG_ADMIN_URL
1574
+					),
1575
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1576
+				)
1577
+				: '';
1578
+			// grab header
1579
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1580
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1581
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1582
+				$template_path,
1583
+				$this->_template_args,
1584
+				true
1585
+			);
1586
+		} else {
1587
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1588
+		}
1589
+		// the details template wrapper
1590
+		$this->display_admin_page_with_sidebar();
1591
+	}
1592
+
1593
+
1594
+	protected function _registration_details_metaboxes()
1595
+	{
1596
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1597
+		$this->_set_registration_object();
1598
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1599
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1600
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1601
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1602
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1603
+		if ($attendee instanceof EE_Attendee
1604
+			&& EE_Registry::instance()->CAP->current_user_can(
1605
+				'ee_edit_registration',
1606
+				'edit-reg-questions-mbox',
1607
+				$this->_registration->ID()
1608
+			)
1609
+		) {
1610
+			add_meta_box(
1611
+				'edit-reg-questions-mbox',
1612
+				esc_html__('Registration Form Answers', 'event_espresso'),
1613
+				array($this, '_reg_questions_meta_box'),
1614
+				$this->wp_page_slug,
1615
+				'normal',
1616
+				'high'
1617
+			);
1618
+		}
1619
+		add_meta_box(
1620
+			'edit-reg-registrant-mbox',
1621
+			esc_html__('Contact Details', 'event_espresso'),
1622
+			array($this, '_reg_registrant_side_meta_box'),
1623
+			$this->wp_page_slug,
1624
+			'side',
1625
+			'high'
1626
+		);
1627
+		if ($this->_registration->group_size() > 1) {
1628
+			add_meta_box(
1629
+				'edit-reg-attendees-mbox',
1630
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1631
+				array($this, '_reg_attendees_meta_box'),
1632
+				$this->wp_page_slug,
1633
+				'normal',
1634
+				'high'
1635
+			);
1636
+		}
1637
+	}
1638
+
1639
+
1640
+	/**
1641
+	 * set_reg_status_buttons_metabox
1642
+	 *
1643
+	 * @access protected
1644
+	 * @return string
1645
+	 * @throws \EE_Error
1646
+	 */
1647
+	public function set_reg_status_buttons_metabox()
1648
+	{
1649
+		$this->_set_registration_object();
1650
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1651
+		echo $change_reg_status_form->form_open(
1652
+			self::add_query_args_and_nonce(
1653
+				array(
1654
+					'action' => 'change_reg_status',
1655
+				),
1656
+				REG_ADMIN_URL
1657
+			)
1658
+		);
1659
+		echo $change_reg_status_form->get_html();
1660
+		echo $change_reg_status_form->form_close();
1661
+	}
1662
+
1663
+
1664
+
1665
+	/**
1666
+	 * @return EE_Form_Section_Proper
1667
+	 * @throws EE_Error
1668
+	 */
1669
+	protected function _generate_reg_status_change_form()
1670
+	{
1671
+		return new EE_Form_Section_Proper(array(
1672
+			'name'            => 'reg_status_change_form',
1673
+			'html_id'         => 'reg-status-change-form',
1674
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1675
+			'subsections'     => array(
1676
+				'return'             => new EE_Hidden_Input(array(
1677
+					'name'    => 'return',
1678
+					'default' => 'view_registration',
1679
+				)),
1680
+				'REG_ID'             => new EE_Hidden_Input(array(
1681
+					'name'    => 'REG_ID',
1682
+					'default' => $this->_registration->ID(),
1683
+				)),
1684
+				'current_status'     => new EE_Form_Section_HTML(
1685
+					EEH_HTML::tr(
1686
+						EEH_HTML::th(
1687
+							EEH_HTML::label(
1688
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1689
+								)
1690
+							)
1691
+						)
1692
+						. EEH_HTML::td(
1693
+							EEH_HTML::strong(
1694
+								$this->_registration->pretty_status(),
1695
+								'',
1696
+								'status-' . $this->_registration->status_ID(),
1697
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1698
+							)
1699
+						)
1700
+					)
1701
+				),
1702
+				'reg_status'         => new EE_Select_Input(
1703
+					$this->_get_reg_statuses(),
1704
+					array(
1705
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1706
+						'default'         => $this->_registration->status_ID(),
1707
+					)
1708
+				),
1709
+				'send_notifications' => new EE_Yes_No_Input(
1710
+					array(
1711
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1712
+						'default'         => false,
1713
+						'html_help_text'  => esc_html__(
1714
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1715
+							'event_espresso'
1716
+						),
1717
+					)
1718
+				),
1719
+				'submit'             => new EE_Submit_Input(
1720
+					array(
1721
+						'html_class'      => 'button-primary',
1722
+						'html_label_text' => '&nbsp;',
1723
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1724
+					)
1725
+				),
1726
+			),
1727
+		));
1728
+	}
1729
+
1730
+
1731
+	/**
1732
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1733
+	 *
1734
+	 * @return array
1735
+	 * @throws EE_Error
1736
+	 * @throws EntityNotFoundException
1737
+	 */
1738
+	protected function _get_reg_statuses()
1739
+	{
1740
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1741
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1742
+		// get current reg status
1743
+		$current_status = $this->_registration->status_ID();
1744
+		// is registration for free event? This will determine whether to display the pending payment option
1745
+		if (
1746
+			$current_status !== EEM_Registration::status_id_pending_payment
1747
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1748
+		) {
1749
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1750
+		}
1751
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1752
+	}
1753
+
1754
+
1755
+	/**
1756
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1757
+	 *
1758
+	 * @param bool $status REG status given for changing registrations to.
1759
+	 * @param bool $notify Whether to send messages notifications or not.
1760
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1761
+	 * @throws EE_Error
1762
+	 * @throws InvalidArgumentException
1763
+	 * @throws InvalidDataTypeException
1764
+	 * @throws InvalidInterfaceException
1765
+	 * @throws ReflectionException
1766
+	 * @throws RuntimeException
1767
+	 * @throws EntityNotFoundException
1768
+	 */
1769
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1770
+	{
1771
+		if (isset($this->_req_data['reg_status_change_form'])) {
1772
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1773
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1774
+				: array();
1775
+		} else {
1776
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1777
+				? (array)$this->_req_data['_REG_ID']
1778
+				: array();
1779
+		}
1780
+		// sanitize $REG_IDs
1781
+		$REG_IDs = array_map('absint', $REG_IDs);
1782
+		// and remove empty entries
1783
+		$REG_IDs = array_filter($REG_IDs);
1784
+
1785
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1786
+
1787
+		/**
1788
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1789
+		 * Currently this value is used downstream by the _process_resend_registration method.
1790
+		 *
1791
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1792
+		 * @param bool                     $status           The status registrations were changed to.
1793
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1794
+		 * @param Registrations_Admin_Page $admin_page_object
1795
+		 */
1796
+		$this->_req_data['_REG_ID'] = apply_filters(
1797
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1798
+			$result['REG_ID'],
1799
+			$status,
1800
+			$result['success'],
1801
+			$this
1802
+		);
1803
+
1804
+		//notify?
1805
+		if ($notify
1806
+			&& $result['success']
1807
+			&& ! empty($this->_req_data['_REG_ID'])
1808
+			&& EE_Registry::instance()->CAP->current_user_can(
1809
+				'ee_send_message',
1810
+				'espresso_registrations_resend_registration'
1811
+			)
1812
+		) {
1813
+			$this->_process_resend_registration();
1814
+		}
1815
+		return $result;
1816
+	}
1817
+
1818
+
1819
+	/**
1820
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1821
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1822
+	 *
1823
+	 * @param array  $REG_IDs
1824
+	 * @param string $status
1825
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1826
+	 *                        slug sent with setting the registration status.
1827
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1828
+	 * @throws EE_Error
1829
+	 * @throws InvalidArgumentException
1830
+	 * @throws InvalidDataTypeException
1831
+	 * @throws InvalidInterfaceException
1832
+	 * @throws ReflectionException
1833
+	 * @throws RuntimeException
1834
+	 * @throws EntityNotFoundException
1835
+	 */
1836
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1837
+	{
1838
+		$success = false;
1839
+		// typecast $REG_IDs
1840
+		$REG_IDs = (array)$REG_IDs;
1841
+		if ( ! empty($REG_IDs)) {
1842
+			$success = true;
1843
+			// set default status if none is passed
1844
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1845
+			$status_context = $notify
1846
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1847
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1848
+			//loop through REG_ID's and change status
1849
+			foreach ($REG_IDs as $REG_ID) {
1850
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1851
+				if ($registration instanceof EE_Registration) {
1852
+					$registration->set_status(
1853
+						$status,
1854
+						false,
1855
+						new Context(
1856
+							$status_context,
1857
+							esc_html__(
1858
+								'Manually triggered status change on a Registration Admin Page route.',
1859
+								'event_espresso'
1860
+							)
1861
+						)
1862
+					);
1863
+					$result = $registration->save();
1864
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1865
+					$success = $result !== false ? $success : false;
1866
+				}
1867
+			}
1868
+		}
1869
+
1870
+		//return $success and processed registrations
1871
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1872
+	}
1873
+
1874
+
1875
+	/**
1876
+	 * Common logic for setting up success message and redirecting to appropriate route
1877
+	 *
1878
+	 * @param  string $STS_ID status id for the registration changed to
1879
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1880
+	 * @return void
1881
+	 */
1882
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1883
+	{
1884
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1885
+			: array('success' => false);
1886
+		$success = isset($result['success']) && $result['success'];
1887
+		//setup success message
1888
+		if ($success) {
1889
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1890
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1891
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1892
+			} else {
1893
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1894
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1895
+			}
1896
+			EE_Error::add_success($msg);
1897
+		} else {
1898
+			EE_Error::add_error(
1899
+				esc_html__(
1900
+					'Something went wrong, and the status was not changed',
1901
+					'event_espresso'
1902
+				), __FILE__, __LINE__, __FUNCTION__
1903
+			);
1904
+		}
1905
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1906
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1907
+		} else {
1908
+			$route = array('action' => 'default');
1909
+		}
1910
+		//unset nonces
1911
+		foreach ($this->_req_data as $ref => $value) {
1912
+			if (strpos($ref, 'nonce') !== false) {
1913
+				unset($this->_req_data[$ref]);
1914
+				continue;
1915
+			}
1916
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1917
+			$this->_req_data[$ref] = $value;
1918
+		}
1919
+		//merge request vars so that the reloaded list table contains any existing filter query params
1920
+		$route = array_merge($this->_req_data, $route);
1921
+		$this->_redirect_after_action($success, '', '', $route, true);
1922
+	}
1923
+
1924
+
1925
+	/**
1926
+	 * incoming reg status change from reg details page.
1927
+	 *
1928
+	 * @return void
1929
+	 */
1930
+	protected function _change_reg_status()
1931
+	{
1932
+		$this->_req_data['return'] = 'view_registration';
1933
+		//set notify based on whether the send notifications toggle is set or not
1934
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1935
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1936
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1937
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1938
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1939
+			case EEM_Registration::status_id_approved :
1940
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1941
+				$this->approve_registration($notify);
1942
+				break;
1943
+			case EEM_Registration::status_id_pending_payment :
1944
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1945
+				$this->pending_registration($notify);
1946
+				break;
1947
+			case EEM_Registration::status_id_not_approved :
1948
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1949
+				$this->not_approve_registration($notify);
1950
+				break;
1951
+			case EEM_Registration::status_id_declined :
1952
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1953
+				$this->decline_registration($notify);
1954
+				break;
1955
+			case EEM_Registration::status_id_cancelled :
1956
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1957
+				$this->cancel_registration($notify);
1958
+				break;
1959
+			case EEM_Registration::status_id_wait_list :
1960
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1961
+				$this->wait_list_registration($notify);
1962
+				break;
1963
+			case EEM_Registration::status_id_incomplete :
1964
+			default :
1965
+				$result['success'] = false;
1966
+				unset($this->_req_data['return']);
1967
+				$this->_reg_status_change_return('', false);
1968
+				break;
1969
+		}
1970
+	}
1971
+
1972
+
1973
+	/**
1974
+	 * Callback for bulk action routes.
1975
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1976
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1977
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1978
+	 * when an action is happening on just a single registration).
1979
+	 * @param      $action
1980
+	 * @param bool $notify
1981
+	 */
1982
+	protected function bulk_action_on_registrations($action, $notify = false) {
1983
+		do_action(
1984
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1985
+			$this,
1986
+			$action,
1987
+			$notify
1988
+		);
1989
+		$method = $action . '_registration';
1990
+		if (method_exists($this, $method)) {
1991
+			$this->$method($notify);
1992
+		}
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * approve_registration
1998
+	 *
1999
+	 * @access protected
2000
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2001
+	 * @return void
2002
+	 */
2003
+	protected function approve_registration($notify = false)
2004
+	{
2005
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2006
+	}
2007
+
2008
+
2009
+	/**
2010
+	 *        decline_registration
2011
+	 *
2012
+	 * @access protected
2013
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2014
+	 * @return void
2015
+	 */
2016
+	protected function decline_registration($notify = false)
2017
+	{
2018
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2019
+	}
2020
+
2021
+
2022
+	/**
2023
+	 *        cancel_registration
2024
+	 *
2025
+	 * @access protected
2026
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2027
+	 * @return void
2028
+	 */
2029
+	protected function cancel_registration($notify = false)
2030
+	{
2031
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2032
+	}
2033
+
2034
+
2035
+	/**
2036
+	 *        not_approve_registration
2037
+	 *
2038
+	 * @access protected
2039
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2040
+	 * @return void
2041
+	 */
2042
+	protected function not_approve_registration($notify = false)
2043
+	{
2044
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2045
+	}
2046
+
2047
+
2048
+	/**
2049
+	 *        decline_registration
2050
+	 *
2051
+	 * @access protected
2052
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2053
+	 * @return void
2054
+	 */
2055
+	protected function pending_registration($notify = false)
2056
+	{
2057
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2058
+	}
2059
+
2060
+
2061
+	/**
2062
+	 * waitlist_registration
2063
+	 *
2064
+	 * @access protected
2065
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2066
+	 * @return void
2067
+	 */
2068
+	protected function wait_list_registration($notify = false)
2069
+	{
2070
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2071
+	}
2072
+
2073
+
2074
+	/**
2075
+	 *        generates HTML for the Registration main meta box
2076
+	 *
2077
+	 * @access public
2078
+	 * @return void
2079
+	 * @throws DomainException
2080
+	 * @throws EE_Error
2081
+	 * @throws EntityNotFoundException
2082
+	 */
2083
+	public function _reg_details_meta_box()
2084
+	{
2085
+		EEH_Autoloader::register_line_item_display_autoloaders();
2086
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2087
+		EE_Registry::instance()->load_helper('Line_Item');
2088
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2089
+			: EE_Transaction::new_instance();
2090
+		$this->_session = $transaction->session_data();
2091
+		$filters        = new EE_Line_Item_Filter_Collection();
2092
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2093
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2094
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2095
+			$transaction->total_line_item());
2096
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2097
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2098
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2099
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2100
+			$filtered_line_item_tree,
2101
+			array('EE_Registration' => $this->_registration)
2102
+		);
2103
+		$attendee                                = $this->_registration->attendee();
2104
+		if (EE_Registry::instance()->CAP->current_user_can(
2105
+			'ee_read_transaction',
2106
+			'espresso_transactions_view_transaction'
2107
+		)) {
2108
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2109
+				EE_Admin_Page::add_query_args_and_nonce(
2110
+					array(
2111
+						'action' => 'view_transaction',
2112
+						'TXN_ID' => $transaction->ID(),
2113
+					),
2114
+					TXN_ADMIN_URL
2115
+				),
2116
+				esc_html__(' View Transaction', 'event_espresso'),
2117
+				'button secondary-button right',
2118
+				'dashicons dashicons-cart'
2119
+			);
2120
+		} else {
2121
+			$this->_template_args['view_transaction_button'] = '';
2122
+		}
2123
+		if ($attendee instanceof EE_Attendee
2124
+			&& EE_Registry::instance()->CAP->current_user_can(
2125
+				'ee_send_message',
2126
+				'espresso_registrations_resend_registration'
2127
+			)
2128
+		) {
2129
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2130
+				EE_Admin_Page::add_query_args_and_nonce(
2131
+					array(
2132
+						'action'      => 'resend_registration',
2133
+						'_REG_ID'     => $this->_registration->ID(),
2134
+						'redirect_to' => 'view_registration',
2135
+					),
2136
+					REG_ADMIN_URL
2137
+				),
2138
+				esc_html__(' Resend Registration', 'event_espresso'),
2139
+				'button secondary-button right',
2140
+				'dashicons dashicons-email-alt'
2141
+			);
2142
+		} else {
2143
+			$this->_template_args['resend_registration_button'] = '';
2144
+		}
2145
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2146
+		$payment                               = $transaction->get_first_related('Payment');
2147
+		$payment                               = ! $payment instanceof EE_Payment
2148
+			? EE_Payment::new_instance()
2149
+			: $payment;
2150
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2151
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2152
+			? EE_Payment_Method::new_instance()
2153
+			: $payment_method;
2154
+		$reg_details                           = array(
2155
+			'payment_method'       => $payment_method->name(),
2156
+			'response_msg'         => $payment->gateway_response(),
2157
+			'registration_id'      => $this->_registration->get('REG_code'),
2158
+			'registration_session' => $this->_registration->session_ID(),
2159
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2160
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2161
+		);
2162
+		if (isset($reg_details['registration_id'])) {
2163
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2164
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2165
+				'Registration ID',
2166
+				'event_espresso'
2167
+			);
2168
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2169
+		}
2170
+		if (isset($reg_details['payment_method'])) {
2171
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2172
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2173
+				'Most Recent Payment Method',
2174
+				'event_espresso'
2175
+			);
2176
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2177
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2178
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2179
+				'Payment method response',
2180
+				'event_espresso'
2181
+			);
2182
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2183
+		}
2184
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2185
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2186
+			'Registration Session',
2187
+			'event_espresso'
2188
+		);
2189
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2190
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2191
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2192
+			'Registration placed from IP',
2193
+			'event_espresso'
2194
+		);
2195
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2196
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2197
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2198
+			'event_espresso');
2199
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2200
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2201
+			array(
2202
+				'action'   => 'default',
2203
+				'event_id' => $this->_registration->event_ID(),
2204
+			),
2205
+			REG_ADMIN_URL
2206
+		);
2207
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2208
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2209
+		$template_path                                                        =
2210
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2211
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2212
+	}
2213
+
2214
+
2215
+	/**
2216
+	 * generates HTML for the Registration Questions meta box.
2217
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2218
+	 * otherwise uses new forms system
2219
+	 *
2220
+	 * @access public
2221
+	 * @return void
2222
+	 * @throws DomainException
2223
+	 * @throws EE_Error
2224
+	 */
2225
+	public function _reg_questions_meta_box()
2226
+	{
2227
+		//allow someone to override this method entirely
2228
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2229
+			$this->_registration)) {
2230
+			$form                                              = $this->_get_reg_custom_questions_form(
2231
+				$this->_registration->ID()
2232
+			);
2233
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2234
+				? $form->get_html_and_js()
2235
+				: '';
2236
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2237
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2238
+			$template_path                                     =
2239
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2240
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2241
+		}
2242
+	}
2243
+
2244
+
2245
+	/**
2246
+	 * form_before_question_group
2247
+	 *
2248
+	 * @deprecated    as of 4.8.32.rc.000
2249
+	 * @access        public
2250
+	 * @param        string $output
2251
+	 * @return        string
2252
+	 */
2253
+	public function form_before_question_group($output)
2254
+	{
2255
+		EE_Error::doing_it_wrong(
2256
+			__CLASS__ . '::' . __FUNCTION__,
2257
+			esc_html__(
2258
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2259
+				'event_espresso'
2260
+			),
2261
+			'4.8.32.rc.000'
2262
+		);
2263
+		return '
2264 2264
 	<table class="form-table ee-width-100">
2265 2265
 		<tbody>
2266 2266
 			';
2267
-    }
2268
-
2269
-
2270
-    /**
2271
-     * form_after_question_group
2272
-     *
2273
-     * @deprecated    as of 4.8.32.rc.000
2274
-     * @access        public
2275
-     * @param        string $output
2276
-     * @return        string
2277
-     */
2278
-    public function form_after_question_group($output)
2279
-    {
2280
-        EE_Error::doing_it_wrong(
2281
-            __CLASS__ . '::' . __FUNCTION__,
2282
-            esc_html__(
2283
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2284
-                'event_espresso'
2285
-            ),
2286
-            '4.8.32.rc.000'
2287
-        );
2288
-        return '
2267
+	}
2268
+
2269
+
2270
+	/**
2271
+	 * form_after_question_group
2272
+	 *
2273
+	 * @deprecated    as of 4.8.32.rc.000
2274
+	 * @access        public
2275
+	 * @param        string $output
2276
+	 * @return        string
2277
+	 */
2278
+	public function form_after_question_group($output)
2279
+	{
2280
+		EE_Error::doing_it_wrong(
2281
+			__CLASS__ . '::' . __FUNCTION__,
2282
+			esc_html__(
2283
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2284
+				'event_espresso'
2285
+			),
2286
+			'4.8.32.rc.000'
2287
+		);
2288
+		return '
2289 2289
 			<tr class="hide-if-no-js">
2290 2290
 				<th> </th>
2291 2291
 				<td class="reg-admin-edit-attendee-question-td">
2292 2292
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2293
-               . esc_attr__('click to edit question', 'event_espresso')
2294
-               . '">
2293
+			   . esc_attr__('click to edit question', 'event_espresso')
2294
+			   . '">
2295 2295
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2296
-               . esc_html__('edit the above question group', 'event_espresso')
2297
-               . '</span>
2296
+			   . esc_html__('edit the above question group', 'event_espresso')
2297
+			   . '</span>
2298 2298
 						<div class="dashicons dashicons-edit"></div>
2299 2299
 					</a>
2300 2300
 				</td>
@@ -2302,558 +2302,558 @@  discard block
 block discarded – undo
2302 2302
 		</tbody>
2303 2303
 	</table>
2304 2304
 ';
2305
-    }
2306
-
2307
-
2308
-    /**
2309
-     * form_form_field_label_wrap
2310
-     *
2311
-     * @deprecated    as of 4.8.32.rc.000
2312
-     * @access        public
2313
-     * @param        string $label
2314
-     * @return        string
2315
-     */
2316
-    public function form_form_field_label_wrap($label)
2317
-    {
2318
-        EE_Error::doing_it_wrong(
2319
-            __CLASS__ . '::' . __FUNCTION__,
2320
-            esc_html__(
2321
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2322
-                'event_espresso'
2323
-            ),
2324
-            '4.8.32.rc.000'
2325
-        );
2326
-        return '
2305
+	}
2306
+
2307
+
2308
+	/**
2309
+	 * form_form_field_label_wrap
2310
+	 *
2311
+	 * @deprecated    as of 4.8.32.rc.000
2312
+	 * @access        public
2313
+	 * @param        string $label
2314
+	 * @return        string
2315
+	 */
2316
+	public function form_form_field_label_wrap($label)
2317
+	{
2318
+		EE_Error::doing_it_wrong(
2319
+			__CLASS__ . '::' . __FUNCTION__,
2320
+			esc_html__(
2321
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2322
+				'event_espresso'
2323
+			),
2324
+			'4.8.32.rc.000'
2325
+		);
2326
+		return '
2327 2327
 			<tr>
2328 2328
 				<th>
2329 2329
 					' . $label . '
2330 2330
 				</th>';
2331
-    }
2332
-
2333
-
2334
-    /**
2335
-     * form_form_field_input__wrap
2336
-     *
2337
-     * @deprecated    as of 4.8.32.rc.000
2338
-     * @access        public
2339
-     * @param        string $input
2340
-     * @return        string
2341
-     */
2342
-    public function form_form_field_input__wrap($input)
2343
-    {
2344
-        EE_Error::doing_it_wrong(
2345
-            __CLASS__ . '::' . __FUNCTION__,
2346
-            esc_html__(
2347
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2348
-                'event_espresso'
2349
-            ),
2350
-            '4.8.32.rc.000'
2351
-        );
2352
-        return '
2331
+	}
2332
+
2333
+
2334
+	/**
2335
+	 * form_form_field_input__wrap
2336
+	 *
2337
+	 * @deprecated    as of 4.8.32.rc.000
2338
+	 * @access        public
2339
+	 * @param        string $input
2340
+	 * @return        string
2341
+	 */
2342
+	public function form_form_field_input__wrap($input)
2343
+	{
2344
+		EE_Error::doing_it_wrong(
2345
+			__CLASS__ . '::' . __FUNCTION__,
2346
+			esc_html__(
2347
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2348
+				'event_espresso'
2349
+			),
2350
+			'4.8.32.rc.000'
2351
+		);
2352
+		return '
2353 2353
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2354 2354
 					' . $input . '
2355 2355
 				</td>
2356 2356
 			</tr>';
2357
-    }
2358
-
2359
-
2360
-    /**
2361
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2362
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2363
-     * to display the page
2364
-     *
2365
-     * @access protected
2366
-     * @return void
2367
-     * @throws EE_Error
2368
-     */
2369
-    protected function _update_attendee_registration_form()
2370
-    {
2371
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2372
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2373
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2374
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2375
-            if ($success) {
2376
-                $what  = esc_html__('Registration Form', 'event_espresso');
2377
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2378
-                    : array('action' => 'default');
2379
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2380
-            }
2381
-        }
2382
-    }
2383
-
2384
-
2385
-    /**
2386
-     * Gets the form for saving registrations custom questions (if done
2387
-     * previously retrieves the cached form object, which may have validation errors in it)
2388
-     *
2389
-     * @param int $REG_ID
2390
-     * @return EE_Registration_Custom_Questions_Form
2391
-     * @throws EE_Error
2392
-     */
2393
-    protected function _get_reg_custom_questions_form($REG_ID)
2394
-    {
2395
-        if ( ! $this->_reg_custom_questions_form) {
2396
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2397
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2398
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2399
-            );
2400
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2401
-        }
2402
-        return $this->_reg_custom_questions_form;
2403
-    }
2404
-
2405
-
2406
-    /**
2407
-     * Saves
2408
-     *
2409
-     * @access private
2410
-     * @param bool $REG_ID
2411
-     * @return bool
2412
-     * @throws EE_Error
2413
-     */
2414
-    private function _save_reg_custom_questions_form($REG_ID = false)
2415
-    {
2416
-        if ( ! $REG_ID) {
2417
-            EE_Error::add_error(
2418
-                esc_html__(
2419
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2420
-                __FILE__, __FUNCTION__, __LINE__
2421
-            );
2422
-        }
2423
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2424
-        $form->receive_form_submission($this->_req_data);
2425
-        $success = false;
2426
-        if ($form->is_valid()) {
2427
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2428
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2429
-                    $where_conditions    = array(
2430
-                        'QST_ID' => $question_id,
2431
-                        'REG_ID' => $REG_ID,
2432
-                    );
2433
-                    $possibly_new_values = array(
2434
-                        'ANS_value' => $input->normalized_value(),
2435
-                    );
2436
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2437
-                    if ($answer instanceof EE_Answer) {
2438
-                        $success = $answer->save($possibly_new_values);
2439
-                    } else {
2440
-                        //insert it then
2441
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2442
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2443
-                        $success     = $answer->save();
2444
-                    }
2445
-                }
2446
-            }
2447
-        } else {
2448
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2449
-        }
2450
-        return $success;
2451
-    }
2452
-
2453
-
2454
-    /**
2455
-     *        generates HTML for the Registration main meta box
2456
-     *
2457
-     * @access public
2458
-     * @return void
2459
-     * @throws DomainException
2460
-     * @throws EE_Error
2461
-     */
2462
-    public function _reg_attendees_meta_box()
2463
-    {
2464
-        $REG = EEM_Registration::instance();
2465
-        //get all other registrations on this transaction, and cache
2466
-        //the attendees for them so we don't have to run another query using force_join
2467
-        $registrations                           = $REG->get_all(array(
2468
-            array(
2469
-                'TXN_ID' => $this->_registration->transaction_ID(),
2470
-                'REG_ID' => array('!=', $this->_registration->ID()),
2471
-            ),
2472
-            'force_join' => array('Attendee'),
2473
-        ));
2474
-        $this->_template_args['attendees']       = array();
2475
-        $this->_template_args['attendee_notice'] = '';
2476
-        if (empty($registrations)
2477
-            || (is_array($registrations)
2478
-                && ! EEH_Array::get_one_item_from_array($registrations))
2479
-        ) {
2480
-            EE_Error::add_error(
2481
-                esc_html__(
2482
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2483
-                    'event_espresso'
2484
-                ), __FILE__, __FUNCTION__, __LINE__
2485
-            );
2486
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2487
-        } else {
2488
-            $att_nmbr = 1;
2489
-            foreach ($registrations as $registration) {
2490
-                /* @var $registration EE_Registration */
2491
-                $attendee                                                    = $registration->attendee()
2492
-                    ? $registration->attendee()
2493
-                    : EEM_Attendee::instance()
2494
-                                  ->create_default_object();
2495
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2496
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2497
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2498
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2499
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2500
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2501
-                    ', ',
2502
-                    $attendee->full_address_as_array()
2503
-                );
2504
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2505
-                    array(
2506
-                        'action' => 'edit_attendee',
2507
-                        'post'   => $attendee->ID(),
2508
-                    ),
2509
-                    REG_ADMIN_URL
2510
-                );
2511
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2512
-                $att_nmbr++;
2513
-            }
2514
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2515
-        }
2516
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2517
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2518
-    }
2519
-
2520
-
2521
-    /**
2522
-     *        generates HTML for the Edit Registration side meta box
2523
-     *
2524
-     * @access public
2525
-     * @return void
2526
-     * @throws DomainException
2527
-     * @throws EE_Error
2528
-     */
2529
-    public function _reg_registrant_side_meta_box()
2530
-    {
2531
-        /*@var $attendee EE_Attendee */
2532
-        $att_check = $this->_registration->attendee();
2533
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2534
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2535
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2536
-        //primary registration object (that way we know if we need to show create button or not)
2537
-        if ( ! $this->_registration->is_primary_registrant()) {
2538
-            $primary_registration = $this->_registration->get_primary_registration();
2539
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2540
-                : null;
2541
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2542
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2543
-                //custom attendee object so let's not worry about the primary reg.
2544
-                $primary_registration = null;
2545
-            }
2546
-        } else {
2547
-            $primary_registration = null;
2548
-        }
2549
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2550
-        $this->_template_args['fname']             = $attendee->fname();
2551
-        $this->_template_args['lname']             = $attendee->lname();
2552
-        $this->_template_args['email']             = $attendee->email();
2553
-        $this->_template_args['phone']             = $attendee->phone();
2554
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2555
-        //edit link
2556
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2557
-            'action' => 'edit_attendee',
2558
-            'post'   => $attendee->ID(),
2559
-        ), REG_ADMIN_URL);
2560
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2561
-        //create link
2562
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2563
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2564
-                'action'  => 'duplicate_attendee',
2565
-                '_REG_ID' => $this->_registration->ID(),
2566
-            ), REG_ADMIN_URL) : '';
2567
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2568
-        $this->_template_args['att_check']    = $att_check;
2569
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2570
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2571
-    }
2572
-
2573
-
2574
-    /**
2575
-     * trash or restore registrations
2576
-     *
2577
-     * @param  boolean $trash whether to archive or restore
2578
-     * @return void
2579
-     * @throws EE_Error
2580
-     * @throws RuntimeException
2581
-     * @access protected
2582
-     */
2583
-    protected function _trash_or_restore_registrations($trash = true)
2584
-    {
2585
-        //if empty _REG_ID then get out because there's nothing to do
2586
-        if (empty($this->_req_data['_REG_ID'])) {
2587
-            EE_Error::add_error(
2588
-                sprintf(
2589
-                    esc_html__(
2590
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2591
-                        'event_espresso'
2592
-                    ),
2593
-                    $trash ? 'trash' : 'restore'
2594
-                ),
2595
-                __FILE__, __LINE__, __FUNCTION__
2596
-            );
2597
-            $this->_redirect_after_action(false, '', '', array(), true);
2598
-        }
2599
-        $success = 0;
2600
-        $overwrite_msgs = false;
2601
-        //Checkboxes
2602
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2603
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2604
-        }
2605
-        $reg_count = count($this->_req_data['_REG_ID']);
2606
-        // cycle thru checkboxes
2607
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2608
-            /** @var EE_Registration $REG */
2609
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2610
-            $payments = $REG->registration_payments();
2611
-            if (! empty($payments)) {
2612
-                $name = $REG->attendee() instanceof EE_Attendee
2613
-                    ? $REG->attendee()->full_name()
2614
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2615
-                $overwrite_msgs = true;
2616
-                EE_Error::add_error(
2617
-                    sprintf(
2618
-                        esc_html__(
2619
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2620
-                            'event_espresso'
2621
-                        ),
2622
-                        $name
2623
-                    ),
2624
-                    __FILE__, __FUNCTION__, __LINE__
2625
-                );
2626
-                //can't trash this registration because it has payments.
2627
-                continue;
2628
-            }
2629
-            $updated = $trash ? $REG->delete() : $REG->restore();
2630
-            if ($updated) {
2631
-                $success++;
2632
-            }
2633
-        }
2634
-        $this->_redirect_after_action(
2635
-            $success === $reg_count, // were ALL registrations affected?
2636
-            $success > 1
2637
-                ? esc_html__('Registrations', 'event_espresso')
2638
-                : esc_html__('Registration', 'event_espresso'),
2639
-            $trash
2640
-                ? esc_html__('moved to the trash', 'event_espresso')
2641
-                : esc_html__('restored', 'event_espresso'),
2642
-            array('action' => 'default'),
2643
-            $overwrite_msgs
2644
-        );
2645
-    }
2646
-
2647
-
2648
-    /**
2649
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2650
-     * registration but also.
2651
-     * 1. Removing relations to EE_Attendee
2652
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2653
-     * ALSO trashed.
2654
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2655
-     * 4. Removing relationships between all tickets and the related registrations
2656
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2657
-     * 6. Deleting permanently any related Checkins.
2658
-     *
2659
-     * @return void
2660
-     * @throws EE_Error
2661
-     */
2662
-    protected function _delete_registrations()
2663
-    {
2664
-        $REG_MDL = EEM_Registration::instance();
2665
-        $success = 1;
2666
-        //Checkboxes
2667
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2668
-            // if array has more than one element than success message should be plural
2669
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2670
-            // cycle thru checkboxes
2671
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2672
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2673
-                if ( ! $REG instanceof EE_Registration) {
2674
-                    continue;
2675
-                }
2676
-                $deleted = $this->_delete_registration($REG);
2677
-                if ( ! $deleted) {
2678
-                    $success = 0;
2679
-                }
2680
-            }
2681
-        } else {
2682
-            // grab single id and delete
2683
-            $REG_ID  = $this->_req_data['_REG_ID'];
2684
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2685
-            $deleted = $this->_delete_registration($REG);
2686
-            if ( ! $deleted) {
2687
-                $success = 0;
2688
-            }
2689
-        }
2690
-        $what        = $success > 1
2691
-            ? esc_html__('Registrations', 'event_espresso')
2692
-            : esc_html__('Registration', 'event_espresso');
2693
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2694
-        $this->_redirect_after_action(
2695
-            $success,
2696
-            $what,
2697
-            $action_desc,
2698
-            array('action' => 'default'),
2699
-            true
2700
-        );
2701
-    }
2702
-
2703
-
2704
-    /**
2705
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2706
-     * models get affected.
2707
-     *
2708
-     * @param  EE_Registration $REG registration to be deleted permenantly
2709
-     * @return bool true = successful deletion, false = fail.
2710
-     * @throws EE_Error
2711
-     */
2712
-    protected function _delete_registration(EE_Registration $REG)
2713
-    {
2714
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2715
-        //registrations on the transaction that are NOT trashed.
2716
-        $TXN         = $REG->get_first_related('Transaction');
2717
-        $REGS        = $TXN->get_many_related('Registration');
2718
-        $all_trashed = true;
2719
-        foreach ($REGS as $registration) {
2720
-            if ( ! $registration->get('REG_deleted')) {
2721
-                $all_trashed = false;
2722
-            }
2723
-        }
2724
-        if ( ! $all_trashed) {
2725
-            EE_Error::add_error(
2726
-                esc_html__(
2727
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2728
-                    'event_espresso'
2729
-                ),
2730
-                __FILE__, __FUNCTION__, __LINE__
2731
-            );
2732
-            return false;
2733
-        }
2734
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2735
-        //separately from THIS one).
2736
-        foreach ($REGS as $registration) {
2737
-            //delete related answers
2738
-            $registration->delete_related_permanently('Answer');
2739
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2740
-            $attendee = $registration->get_first_related('Attendee');
2741
-            if ($attendee instanceof EE_Attendee) {
2742
-                $registration->_remove_relation_to($attendee, 'Attendee');
2743
-            }
2744
-            //now remove relationships to tickets on this registration.
2745
-            $registration->_remove_relations('Ticket');
2746
-            //now delete permanently the checkins related to this registration.
2747
-            $registration->delete_related_permanently('Checkin');
2748
-            if ($registration->ID() === $REG->ID()) {
2749
-                continue;
2750
-            } //we don't want to delete permanently the existing registration just yet.
2751
-            //remove relation to transaction for these registrations if NOT the existing registrations
2752
-            $registration->_remove_relations('Transaction');
2753
-            //delete permanently any related messages.
2754
-            $registration->delete_related_permanently('Message');
2755
-            //now delete this registration permanently
2756
-            $registration->delete_permanently();
2757
-        }
2758
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2759
-        // (the transaction and line items should be all that's left).
2760
-        // delete the line items related to the transaction for this registration.
2761
-        $TXN->delete_related_permanently('Line_Item');
2762
-        //we need to remove all the relationships on the transaction
2763
-        $TXN->delete_related_permanently('Payment');
2764
-        $TXN->delete_related_permanently('Extra_Meta');
2765
-        $TXN->delete_related_permanently('Message');
2766
-        //now we can delete this REG permanently (and the transaction of course)
2767
-        $REG->delete_related_permanently('Transaction');
2768
-        return $REG->delete_permanently();
2769
-    }
2770
-
2771
-
2772
-    /**
2773
-     *    generates HTML for the Register New Attendee Admin page
2774
-     *
2775
-     * @access private
2776
-     * @throws DomainException
2777
-     * @throws EE_Error
2778
-     */
2779
-    public function new_registration()
2780
-    {
2781
-        if ( ! $this->_set_reg_event()) {
2782
-            throw new EE_Error(
2783
-                esc_html__(
2784
-                    'Unable to continue with registering because there is no Event ID in the request',
2785
-                    'event_espresso'
2786
-                )
2787
-            );
2788
-        }
2789
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2790
-        // gotta start with a clean slate if we're not coming here via ajax
2791
-        if ( ! defined('DOING_AJAX')
2792
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2793
-        ) {
2794
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2795
-        }
2796
-        $this->_template_args['event_name'] = '';
2797
-        // event name
2798
-        if ($this->_reg_event) {
2799
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2800
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2801
-                'action' => 'edit',
2802
-                'post'   => $this->_reg_event->ID(),
2803
-            ), EVENTS_ADMIN_URL);
2804
-            $edit_event_lnk                     = '<a href="'
2805
-                                                  . $edit_event_url
2806
-                                                  . '" title="'
2807
-                                                  . esc_attr__('Edit ', 'event_espresso')
2808
-                                                  . $this->_reg_event->name()
2809
-                                                  . '">'
2810
-                                                  . esc_html__('Edit Event', 'event_espresso')
2811
-                                                  . '</a>';
2812
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2813
-                                                   . $edit_event_lnk
2814
-                                                   . '</span>';
2815
-        }
2816
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2817
-        if (defined('DOING_AJAX')) {
2818
-            $this->_return_json();
2819
-        }
2820
-        // grab header
2821
-        $template_path                              =
2822
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2823
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2824
-            $this->_template_args, true);
2825
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2826
-        // the details template wrapper
2827
-        $this->display_admin_page_with_sidebar();
2828
-    }
2829
-
2830
-
2831
-    /**
2832
-     * This returns the content for a registration step
2833
-     *
2834
-     * @access protected
2835
-     * @return string html
2836
-     * @throws DomainException
2837
-     * @throws EE_Error
2838
-     */
2839
-    protected function _get_registration_step_content()
2840
-    {
2841
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2842
-            $warning_msg = sprintf(
2843
-                esc_html__(
2844
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2845
-                    'event_espresso'
2846
-                ),
2847
-                '<br />',
2848
-                '<h3 class="important-notice">',
2849
-                '</h3>',
2850
-                '<div class="float-right">',
2851
-                '<span id="redirect_timer" class="important-notice">30</span>',
2852
-                '</div>',
2853
-                '<b>',
2854
-                '</b>'
2855
-            );
2856
-            return '
2357
+	}
2358
+
2359
+
2360
+	/**
2361
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2362
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2363
+	 * to display the page
2364
+	 *
2365
+	 * @access protected
2366
+	 * @return void
2367
+	 * @throws EE_Error
2368
+	 */
2369
+	protected function _update_attendee_registration_form()
2370
+	{
2371
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2372
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2373
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2374
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2375
+			if ($success) {
2376
+				$what  = esc_html__('Registration Form', 'event_espresso');
2377
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2378
+					: array('action' => 'default');
2379
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2380
+			}
2381
+		}
2382
+	}
2383
+
2384
+
2385
+	/**
2386
+	 * Gets the form for saving registrations custom questions (if done
2387
+	 * previously retrieves the cached form object, which may have validation errors in it)
2388
+	 *
2389
+	 * @param int $REG_ID
2390
+	 * @return EE_Registration_Custom_Questions_Form
2391
+	 * @throws EE_Error
2392
+	 */
2393
+	protected function _get_reg_custom_questions_form($REG_ID)
2394
+	{
2395
+		if ( ! $this->_reg_custom_questions_form) {
2396
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2397
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2398
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2399
+			);
2400
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2401
+		}
2402
+		return $this->_reg_custom_questions_form;
2403
+	}
2404
+
2405
+
2406
+	/**
2407
+	 * Saves
2408
+	 *
2409
+	 * @access private
2410
+	 * @param bool $REG_ID
2411
+	 * @return bool
2412
+	 * @throws EE_Error
2413
+	 */
2414
+	private function _save_reg_custom_questions_form($REG_ID = false)
2415
+	{
2416
+		if ( ! $REG_ID) {
2417
+			EE_Error::add_error(
2418
+				esc_html__(
2419
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2420
+				__FILE__, __FUNCTION__, __LINE__
2421
+			);
2422
+		}
2423
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2424
+		$form->receive_form_submission($this->_req_data);
2425
+		$success = false;
2426
+		if ($form->is_valid()) {
2427
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2428
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2429
+					$where_conditions    = array(
2430
+						'QST_ID' => $question_id,
2431
+						'REG_ID' => $REG_ID,
2432
+					);
2433
+					$possibly_new_values = array(
2434
+						'ANS_value' => $input->normalized_value(),
2435
+					);
2436
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2437
+					if ($answer instanceof EE_Answer) {
2438
+						$success = $answer->save($possibly_new_values);
2439
+					} else {
2440
+						//insert it then
2441
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2442
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2443
+						$success     = $answer->save();
2444
+					}
2445
+				}
2446
+			}
2447
+		} else {
2448
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2449
+		}
2450
+		return $success;
2451
+	}
2452
+
2453
+
2454
+	/**
2455
+	 *        generates HTML for the Registration main meta box
2456
+	 *
2457
+	 * @access public
2458
+	 * @return void
2459
+	 * @throws DomainException
2460
+	 * @throws EE_Error
2461
+	 */
2462
+	public function _reg_attendees_meta_box()
2463
+	{
2464
+		$REG = EEM_Registration::instance();
2465
+		//get all other registrations on this transaction, and cache
2466
+		//the attendees for them so we don't have to run another query using force_join
2467
+		$registrations                           = $REG->get_all(array(
2468
+			array(
2469
+				'TXN_ID' => $this->_registration->transaction_ID(),
2470
+				'REG_ID' => array('!=', $this->_registration->ID()),
2471
+			),
2472
+			'force_join' => array('Attendee'),
2473
+		));
2474
+		$this->_template_args['attendees']       = array();
2475
+		$this->_template_args['attendee_notice'] = '';
2476
+		if (empty($registrations)
2477
+			|| (is_array($registrations)
2478
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2479
+		) {
2480
+			EE_Error::add_error(
2481
+				esc_html__(
2482
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2483
+					'event_espresso'
2484
+				), __FILE__, __FUNCTION__, __LINE__
2485
+			);
2486
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2487
+		} else {
2488
+			$att_nmbr = 1;
2489
+			foreach ($registrations as $registration) {
2490
+				/* @var $registration EE_Registration */
2491
+				$attendee                                                    = $registration->attendee()
2492
+					? $registration->attendee()
2493
+					: EEM_Attendee::instance()
2494
+								  ->create_default_object();
2495
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2496
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2497
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2498
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2499
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2500
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2501
+					', ',
2502
+					$attendee->full_address_as_array()
2503
+				);
2504
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2505
+					array(
2506
+						'action' => 'edit_attendee',
2507
+						'post'   => $attendee->ID(),
2508
+					),
2509
+					REG_ADMIN_URL
2510
+				);
2511
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2512
+				$att_nmbr++;
2513
+			}
2514
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2515
+		}
2516
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2517
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2518
+	}
2519
+
2520
+
2521
+	/**
2522
+	 *        generates HTML for the Edit Registration side meta box
2523
+	 *
2524
+	 * @access public
2525
+	 * @return void
2526
+	 * @throws DomainException
2527
+	 * @throws EE_Error
2528
+	 */
2529
+	public function _reg_registrant_side_meta_box()
2530
+	{
2531
+		/*@var $attendee EE_Attendee */
2532
+		$att_check = $this->_registration->attendee();
2533
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2534
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2535
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2536
+		//primary registration object (that way we know if we need to show create button or not)
2537
+		if ( ! $this->_registration->is_primary_registrant()) {
2538
+			$primary_registration = $this->_registration->get_primary_registration();
2539
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2540
+				: null;
2541
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2542
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2543
+				//custom attendee object so let's not worry about the primary reg.
2544
+				$primary_registration = null;
2545
+			}
2546
+		} else {
2547
+			$primary_registration = null;
2548
+		}
2549
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2550
+		$this->_template_args['fname']             = $attendee->fname();
2551
+		$this->_template_args['lname']             = $attendee->lname();
2552
+		$this->_template_args['email']             = $attendee->email();
2553
+		$this->_template_args['phone']             = $attendee->phone();
2554
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2555
+		//edit link
2556
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2557
+			'action' => 'edit_attendee',
2558
+			'post'   => $attendee->ID(),
2559
+		), REG_ADMIN_URL);
2560
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2561
+		//create link
2562
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2563
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2564
+				'action'  => 'duplicate_attendee',
2565
+				'_REG_ID' => $this->_registration->ID(),
2566
+			), REG_ADMIN_URL) : '';
2567
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2568
+		$this->_template_args['att_check']    = $att_check;
2569
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2570
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2571
+	}
2572
+
2573
+
2574
+	/**
2575
+	 * trash or restore registrations
2576
+	 *
2577
+	 * @param  boolean $trash whether to archive or restore
2578
+	 * @return void
2579
+	 * @throws EE_Error
2580
+	 * @throws RuntimeException
2581
+	 * @access protected
2582
+	 */
2583
+	protected function _trash_or_restore_registrations($trash = true)
2584
+	{
2585
+		//if empty _REG_ID then get out because there's nothing to do
2586
+		if (empty($this->_req_data['_REG_ID'])) {
2587
+			EE_Error::add_error(
2588
+				sprintf(
2589
+					esc_html__(
2590
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2591
+						'event_espresso'
2592
+					),
2593
+					$trash ? 'trash' : 'restore'
2594
+				),
2595
+				__FILE__, __LINE__, __FUNCTION__
2596
+			);
2597
+			$this->_redirect_after_action(false, '', '', array(), true);
2598
+		}
2599
+		$success = 0;
2600
+		$overwrite_msgs = false;
2601
+		//Checkboxes
2602
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2603
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2604
+		}
2605
+		$reg_count = count($this->_req_data['_REG_ID']);
2606
+		// cycle thru checkboxes
2607
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2608
+			/** @var EE_Registration $REG */
2609
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2610
+			$payments = $REG->registration_payments();
2611
+			if (! empty($payments)) {
2612
+				$name = $REG->attendee() instanceof EE_Attendee
2613
+					? $REG->attendee()->full_name()
2614
+					: esc_html__('Unknown Attendee', 'event_espresso');
2615
+				$overwrite_msgs = true;
2616
+				EE_Error::add_error(
2617
+					sprintf(
2618
+						esc_html__(
2619
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2620
+							'event_espresso'
2621
+						),
2622
+						$name
2623
+					),
2624
+					__FILE__, __FUNCTION__, __LINE__
2625
+				);
2626
+				//can't trash this registration because it has payments.
2627
+				continue;
2628
+			}
2629
+			$updated = $trash ? $REG->delete() : $REG->restore();
2630
+			if ($updated) {
2631
+				$success++;
2632
+			}
2633
+		}
2634
+		$this->_redirect_after_action(
2635
+			$success === $reg_count, // were ALL registrations affected?
2636
+			$success > 1
2637
+				? esc_html__('Registrations', 'event_espresso')
2638
+				: esc_html__('Registration', 'event_espresso'),
2639
+			$trash
2640
+				? esc_html__('moved to the trash', 'event_espresso')
2641
+				: esc_html__('restored', 'event_espresso'),
2642
+			array('action' => 'default'),
2643
+			$overwrite_msgs
2644
+		);
2645
+	}
2646
+
2647
+
2648
+	/**
2649
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2650
+	 * registration but also.
2651
+	 * 1. Removing relations to EE_Attendee
2652
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2653
+	 * ALSO trashed.
2654
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2655
+	 * 4. Removing relationships between all tickets and the related registrations
2656
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2657
+	 * 6. Deleting permanently any related Checkins.
2658
+	 *
2659
+	 * @return void
2660
+	 * @throws EE_Error
2661
+	 */
2662
+	protected function _delete_registrations()
2663
+	{
2664
+		$REG_MDL = EEM_Registration::instance();
2665
+		$success = 1;
2666
+		//Checkboxes
2667
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2668
+			// if array has more than one element than success message should be plural
2669
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2670
+			// cycle thru checkboxes
2671
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2672
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2673
+				if ( ! $REG instanceof EE_Registration) {
2674
+					continue;
2675
+				}
2676
+				$deleted = $this->_delete_registration($REG);
2677
+				if ( ! $deleted) {
2678
+					$success = 0;
2679
+				}
2680
+			}
2681
+		} else {
2682
+			// grab single id and delete
2683
+			$REG_ID  = $this->_req_data['_REG_ID'];
2684
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2685
+			$deleted = $this->_delete_registration($REG);
2686
+			if ( ! $deleted) {
2687
+				$success = 0;
2688
+			}
2689
+		}
2690
+		$what        = $success > 1
2691
+			? esc_html__('Registrations', 'event_espresso')
2692
+			: esc_html__('Registration', 'event_espresso');
2693
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2694
+		$this->_redirect_after_action(
2695
+			$success,
2696
+			$what,
2697
+			$action_desc,
2698
+			array('action' => 'default'),
2699
+			true
2700
+		);
2701
+	}
2702
+
2703
+
2704
+	/**
2705
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2706
+	 * models get affected.
2707
+	 *
2708
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2709
+	 * @return bool true = successful deletion, false = fail.
2710
+	 * @throws EE_Error
2711
+	 */
2712
+	protected function _delete_registration(EE_Registration $REG)
2713
+	{
2714
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2715
+		//registrations on the transaction that are NOT trashed.
2716
+		$TXN         = $REG->get_first_related('Transaction');
2717
+		$REGS        = $TXN->get_many_related('Registration');
2718
+		$all_trashed = true;
2719
+		foreach ($REGS as $registration) {
2720
+			if ( ! $registration->get('REG_deleted')) {
2721
+				$all_trashed = false;
2722
+			}
2723
+		}
2724
+		if ( ! $all_trashed) {
2725
+			EE_Error::add_error(
2726
+				esc_html__(
2727
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2728
+					'event_espresso'
2729
+				),
2730
+				__FILE__, __FUNCTION__, __LINE__
2731
+			);
2732
+			return false;
2733
+		}
2734
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2735
+		//separately from THIS one).
2736
+		foreach ($REGS as $registration) {
2737
+			//delete related answers
2738
+			$registration->delete_related_permanently('Answer');
2739
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2740
+			$attendee = $registration->get_first_related('Attendee');
2741
+			if ($attendee instanceof EE_Attendee) {
2742
+				$registration->_remove_relation_to($attendee, 'Attendee');
2743
+			}
2744
+			//now remove relationships to tickets on this registration.
2745
+			$registration->_remove_relations('Ticket');
2746
+			//now delete permanently the checkins related to this registration.
2747
+			$registration->delete_related_permanently('Checkin');
2748
+			if ($registration->ID() === $REG->ID()) {
2749
+				continue;
2750
+			} //we don't want to delete permanently the existing registration just yet.
2751
+			//remove relation to transaction for these registrations if NOT the existing registrations
2752
+			$registration->_remove_relations('Transaction');
2753
+			//delete permanently any related messages.
2754
+			$registration->delete_related_permanently('Message');
2755
+			//now delete this registration permanently
2756
+			$registration->delete_permanently();
2757
+		}
2758
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2759
+		// (the transaction and line items should be all that's left).
2760
+		// delete the line items related to the transaction for this registration.
2761
+		$TXN->delete_related_permanently('Line_Item');
2762
+		//we need to remove all the relationships on the transaction
2763
+		$TXN->delete_related_permanently('Payment');
2764
+		$TXN->delete_related_permanently('Extra_Meta');
2765
+		$TXN->delete_related_permanently('Message');
2766
+		//now we can delete this REG permanently (and the transaction of course)
2767
+		$REG->delete_related_permanently('Transaction');
2768
+		return $REG->delete_permanently();
2769
+	}
2770
+
2771
+
2772
+	/**
2773
+	 *    generates HTML for the Register New Attendee Admin page
2774
+	 *
2775
+	 * @access private
2776
+	 * @throws DomainException
2777
+	 * @throws EE_Error
2778
+	 */
2779
+	public function new_registration()
2780
+	{
2781
+		if ( ! $this->_set_reg_event()) {
2782
+			throw new EE_Error(
2783
+				esc_html__(
2784
+					'Unable to continue with registering because there is no Event ID in the request',
2785
+					'event_espresso'
2786
+				)
2787
+			);
2788
+		}
2789
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2790
+		// gotta start with a clean slate if we're not coming here via ajax
2791
+		if ( ! defined('DOING_AJAX')
2792
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2793
+		) {
2794
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2795
+		}
2796
+		$this->_template_args['event_name'] = '';
2797
+		// event name
2798
+		if ($this->_reg_event) {
2799
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2800
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2801
+				'action' => 'edit',
2802
+				'post'   => $this->_reg_event->ID(),
2803
+			), EVENTS_ADMIN_URL);
2804
+			$edit_event_lnk                     = '<a href="'
2805
+												  . $edit_event_url
2806
+												  . '" title="'
2807
+												  . esc_attr__('Edit ', 'event_espresso')
2808
+												  . $this->_reg_event->name()
2809
+												  . '">'
2810
+												  . esc_html__('Edit Event', 'event_espresso')
2811
+												  . '</a>';
2812
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2813
+												   . $edit_event_lnk
2814
+												   . '</span>';
2815
+		}
2816
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2817
+		if (defined('DOING_AJAX')) {
2818
+			$this->_return_json();
2819
+		}
2820
+		// grab header
2821
+		$template_path                              =
2822
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2823
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2824
+			$this->_template_args, true);
2825
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2826
+		// the details template wrapper
2827
+		$this->display_admin_page_with_sidebar();
2828
+	}
2829
+
2830
+
2831
+	/**
2832
+	 * This returns the content for a registration step
2833
+	 *
2834
+	 * @access protected
2835
+	 * @return string html
2836
+	 * @throws DomainException
2837
+	 * @throws EE_Error
2838
+	 */
2839
+	protected function _get_registration_step_content()
2840
+	{
2841
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2842
+			$warning_msg = sprintf(
2843
+				esc_html__(
2844
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2845
+					'event_espresso'
2846
+				),
2847
+				'<br />',
2848
+				'<h3 class="important-notice">',
2849
+				'</h3>',
2850
+				'<div class="float-right">',
2851
+				'<span id="redirect_timer" class="important-notice">30</span>',
2852
+				'</div>',
2853
+				'<b>',
2854
+				'</b>'
2855
+			);
2856
+			return '
2857 2857
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2858 2858
 	<script >
2859 2859
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2866,792 +2866,792 @@  discard block
 block discarded – undo
2866 2866
 	        }
2867 2867
 	    }, 800 );
2868 2868
 	</script >';
2869
-        }
2870
-        $template_args = array(
2871
-            'title'                    => '',
2872
-            'content'                  => '',
2873
-            'step_button_text'         => '',
2874
-            'show_notification_toggle' => false,
2875
-        );
2876
-        //to indicate we're processing a new registration
2877
-        $hidden_fields = array(
2878
-            'processing_registration' => array(
2879
-                'type'  => 'hidden',
2880
-                'value' => 0,
2881
-            ),
2882
-            'event_id'                => array(
2883
-                'type'  => 'hidden',
2884
-                'value' => $this->_reg_event->ID(),
2885
-            ),
2886
-        );
2887
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2888
-        $cart = EE_Registry::instance()->SSN->cart();
2889
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2890
-        switch ($step) {
2891
-            case 'ticket' :
2892
-                $hidden_fields['processing_registration']['value'] = 1;
2893
-                $template_args['title']                            = esc_html__(
2894
-                    'Step One: Select the Ticket for this registration',
2895
-                    'event_espresso'
2896
-                );
2897
-                $template_args['content']                          =
2898
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2899
-                $template_args['step_button_text']                 = esc_html__(
2900
-                    'Add Tickets and Continue to Registrant Details',
2901
-                    'event_espresso'
2902
-                );
2903
-                $template_args['show_notification_toggle']         = false;
2904
-                break;
2905
-            case 'questions' :
2906
-                $hidden_fields['processing_registration']['value'] = 2;
2907
-                $template_args['title']                            = esc_html__(
2908
-                    'Step Two: Add Registrant Details for this Registration',
2909
-                    'event_espresso'
2910
-                );
2911
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2912
-                // properly by the first process_reg_step run.
2913
-                $template_args['content']                  =
2914
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2915
-                $template_args['step_button_text']         = esc_html__(
2916
-                    'Save Registration and Continue to Details',
2917
-                    'event_espresso'
2918
-                );
2919
-                $template_args['show_notification_toggle'] = true;
2920
-                break;
2921
-        }
2922
-        //we come back to the process_registration_step route.
2923
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2924
-        return EEH_Template::display_template(
2925
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2926
-            $template_args,
2927
-            true
2928
-        );
2929
-    }
2930
-
2931
-
2932
-    /**
2933
-     *        set_reg_event
2934
-     *
2935
-     * @access private
2936
-     * @return bool
2937
-     * @throws EE_Error
2938
-     */
2939
-    private function _set_reg_event()
2940
-    {
2941
-        if (is_object($this->_reg_event)) {
2942
-            return true;
2943
-        }
2944
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2945
-        if ( ! $EVT_ID) {
2946
-            return false;
2947
-        }
2948
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2949
-        return true;
2950
-    }
2951
-
2952
-
2953
-    /**
2954
-     * process_reg_step
2955
-     *
2956
-     * @access        public
2957
-     * @return string
2958
-     * @throws DomainException
2959
-     * @throws EE_Error
2960
-     * @throws RuntimeException
2961
-     */
2962
-    public function process_reg_step()
2963
-    {
2964
-        EE_System::do_not_cache();
2965
-        $this->_set_reg_event();
2966
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2967
-        EE_Registry::instance()->REQ->set('uts', time());
2968
-        //what step are we on?
2969
-        $cart = EE_Registry::instance()->SSN->cart();
2970
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2971
-        //if doing ajax then we need to verify the nonce
2972
-        if (defined('DOING_AJAX')) {
2973
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2974
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2975
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2976
-        }
2977
-        switch ($step) {
2978
-            case 'ticket' :
2979
-                //process ticket selection
2980
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2981
-                if ($success) {
2982
-                    EE_Error::add_success(
2983
-                        esc_html__(
2984
-                            'Tickets Selected. Now complete the registration.',
2985
-                            'event_espresso'
2986
-                        )
2987
-                    );
2988
-                } else {
2989
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2990
-                }
2991
-                if (defined('DOING_AJAX')) {
2992
-                    $this->new_registration(); //display next step
2993
-                } else {
2994
-                    $query_args = array(
2995
-                        'action'                  => 'new_registration',
2996
-                        'processing_registration' => 1,
2997
-                        'event_id'                => $this->_reg_event->ID(),
2998
-                        'uts'                     => time(),
2999
-                    );
3000
-                    $this->_redirect_after_action(
3001
-                        false,
3002
-                        '',
3003
-                        '',
3004
-                        $query_args,
3005
-                        true
3006
-                    );
3007
-                }
3008
-                break;
3009
-            case 'questions' :
3010
-                if (! isset(
3011
-                    $this->_req_data['txn_reg_status_change'],
3012
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
3013
-                ) {
3014
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3015
-                }
3016
-                //process registration
3017
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3018
-                if ($cart instanceof EE_Cart) {
3019
-                    $grand_total = $cart->get_cart_grand_total();
3020
-                    if ($grand_total instanceof EE_Line_Item) {
3021
-                        $grand_total->save_this_and_descendants_to_txn();
3022
-                    }
3023
-                }
3024
-                if ( ! $transaction instanceof EE_Transaction) {
3025
-                    $query_args = array(
3026
-                        'action'                  => 'new_registration',
3027
-                        'processing_registration' => 2,
3028
-                        'event_id'                => $this->_reg_event->ID(),
3029
-                        'uts'                     => time(),
3030
-                    );
3031
-                    if (defined('DOING_AJAX')) {
3032
-                        //display registration form again because there are errors (maybe validation?)
3033
-                        $this->new_registration();
3034
-                        return;
3035
-                    } else {
3036
-                        $this->_redirect_after_action(
3037
-                            false,
3038
-                            '',
3039
-                            '',
3040
-                            $query_args,
3041
-                            true
3042
-                        );
3043
-                        return;
3044
-                    }
3045
-                }
3046
-                // maybe update status, and make sure to save transaction if not done already
3047
-                if ( ! $transaction->update_status_based_on_total_paid()) {
3048
-                    $transaction->save();
3049
-                }
3050
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3051
-                $this->_req_data = array();
3052
-                $query_args      = array(
3053
-                    'action'        => 'redirect_to_txn',
3054
-                    'TXN_ID'        => $transaction->ID(),
3055
-                    'EVT_ID'        => $this->_reg_event->ID(),
3056
-                    'event_name'    => urlencode($this->_reg_event->name()),
3057
-                    'redirect_from' => 'new_registration',
3058
-                );
3059
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3060
-                break;
3061
-        }
3062
-        //what are you looking here for?  Should be nothing to do at this point.
3063
-    }
3064
-
3065
-
3066
-    /**
3067
-     * redirect_to_txn
3068
-     *
3069
-     * @access public
3070
-     * @return void
3071
-     * @throws EE_Error
3072
-     */
3073
-    public function redirect_to_txn()
3074
-    {
3075
-        EE_System::do_not_cache();
3076
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3077
-        $query_args = array(
3078
-            'action' => 'view_transaction',
3079
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3080
-            'page'   => 'espresso_transactions',
3081
-        );
3082
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3083
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3084
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3085
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3086
-        }
3087
-        EE_Error::add_success(
3088
-            esc_html__(
3089
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3090
-                'event_espresso'
3091
-            )
3092
-        );
3093
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3094
-    }
3095
-
3096
-
3097
-    /**
3098
-     *        generates HTML for the Attendee Contact List
3099
-     *
3100
-     * @access protected
3101
-     * @return void
3102
-     */
3103
-    protected function _attendee_contact_list_table()
3104
-    {
3105
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3106
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3107
-        $this->display_admin_list_table_page_with_no_sidebar();
3108
-    }
3109
-
3110
-
3111
-    /**
3112
-     *        get_attendees
3113
-     *
3114
-     * @param      $per_page
3115
-     * @param bool $count whether to return count or data.
3116
-     * @param bool $trash
3117
-     * @return array
3118
-     * @throws EE_Error
3119
-     * @access public
3120
-     */
3121
-    public function get_attendees($per_page, $count = false, $trash = false)
3122
-    {
3123
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3124
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3125
-        $ATT_MDL                    = EEM_Attendee::instance();
3126
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3127
-        switch ($this->_req_data['orderby']) {
3128
-            case 'ATT_ID':
3129
-                $orderby = 'ATT_ID';
3130
-                break;
3131
-            case 'ATT_fname':
3132
-                $orderby = 'ATT_fname';
3133
-                break;
3134
-            case 'ATT_email':
3135
-                $orderby = 'ATT_email';
3136
-                break;
3137
-            case 'ATT_city':
3138
-                $orderby = 'ATT_city';
3139
-                break;
3140
-            case 'STA_ID':
3141
-                $orderby = 'STA_ID';
3142
-                break;
3143
-            case 'CNT_ID':
3144
-                $orderby = 'CNT_ID';
3145
-                break;
3146
-            default:
3147
-                $orderby = 'ATT_lname';
3148
-        }
3149
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3150
-            ? $this->_req_data['order']
3151
-            : 'ASC';
3152
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3153
-            ? $this->_req_data['paged']
3154
-            : 1;
3155
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3156
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3157
-            ? $this->_req_data['perpage']
3158
-            : $per_page;
3159
-        $_where       = array();
3160
-        if ( ! empty($this->_req_data['s'])) {
3161
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3162
-            $_where['OR'] = array(
3163
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3164
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3165
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3166
-                'ATT_fname'                         => array('LIKE', $sstr),
3167
-                'ATT_lname'                         => array('LIKE', $sstr),
3168
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3169
-                'ATT_email'                         => array('LIKE', $sstr),
3170
-                'ATT_address'                       => array('LIKE', $sstr),
3171
-                'ATT_address2'                      => array('LIKE', $sstr),
3172
-                'ATT_city'                          => array('LIKE', $sstr),
3173
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3174
-                'State.STA_name'                    => array('LIKE', $sstr),
3175
-                'ATT_phone'                         => array('LIKE', $sstr),
3176
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3177
-                'Registration.REG_code'             => array('LIKE', $sstr),
3178
-                'Registration.REG_count'            => array('LIKE', $sstr),
3179
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3180
-            );
3181
-        }
3182
-        $offset = ($current_page - 1) * $per_page;
3183
-        $limit  = $count ? null : array($offset, $per_page);
3184
-        if ($trash) {
3185
-            $_where['status'] = array('!=', 'publish');
3186
-            $all_attendees    = $count
3187
-                ? $ATT_MDL->count(array(
3188
-                    $_where,
3189
-                    'order_by' => array($orderby => $sort),
3190
-                    'limit'    => $limit,
3191
-                ), 'ATT_ID', true)
3192
-                : $ATT_MDL->get_all(array(
3193
-                    $_where,
3194
-                    'order_by' => array($orderby => $sort),
3195
-                    'limit'    => $limit,
3196
-                ));
3197
-        } else {
3198
-            $_where['status'] = array('IN', array('publish'));
3199
-            $all_attendees    = $count
3200
-                ? $ATT_MDL->count(array(
3201
-                    $_where,
3202
-                    'order_by' => array($orderby => $sort),
3203
-                    'limit'    => $limit,
3204
-                ), 'ATT_ID', true)
3205
-                : $ATT_MDL->get_all(array(
3206
-                    $_where,
3207
-                    'order_by' => array($orderby => $sort),
3208
-                    'limit'    => $limit,
3209
-                ));
3210
-        }
3211
-        return $all_attendees;
3212
-    }
3213
-
3214
-
3215
-    /**
3216
-     * This is just taking care of resending the registration confirmation
3217
-     *
3218
-     * @access protected
3219
-     * @return void
3220
-     */
3221
-    protected function _resend_registration()
3222
-    {
3223
-        $this->_process_resend_registration();
3224
-        $query_args = isset($this->_req_data['redirect_to'])
3225
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3226
-            : array('action' => 'default');
3227
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3228
-    }
3229
-
3230
-    /**
3231
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3232
-     * to use when selecting registrations
3233
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3234
-     *                                                     the query parameters from the request
3235
-     * @return void ends the request with a redirect or download
3236
-     */
3237
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3238
-    {
3239
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3240
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3241
-                array(
3242
-                    'page'        => 'espresso_batch',
3243
-                    'batch'       => 'file',
3244
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3245
-                    'filters'     => urlencode(
3246
-                        serialize(
3247
-                            call_user_func(
3248
-                                array( $this, $method_name_for_getting_query_params ),
3249
-                                EEH_Array::is_set(
3250
-                                    $this->_req_data,
3251
-                                    'filters',
3252
-                                    array()
3253
-                                )
3254
-                            )
3255
-                        )
3256
-                ),
3257
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3258
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3259
-                'return_url'  => urlencode($this->_req_data['return_url']),
3260
-            )));
3261
-        } else {
3262
-            $new_request_args = array(
3263
-                'export' => 'report',
3264
-                'action' => 'registrations_report_for_event',
3265
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3266
-            );
3267
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3268
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3269
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3270
-                $EE_Export = EE_Export::instance($this->_req_data);
3271
-                $EE_Export->export();
3272
-            }
3273
-        }
3274
-    }
3275
-
3276
-
3277
-
3278
-    /**
3279
-     * Creates a registration report using only query parameters in the request
3280
-     * @return void
3281
-     */
3282
-    public function _registrations_report()
3283
-    {
3284
-        $this->_registrations_report_base('_get_registration_query_parameters');
3285
-    }
3286
-
3287
-
3288
-    public function _contact_list_export()
3289
-    {
3290
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3291
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3292
-            $EE_Export = EE_Export::instance($this->_req_data);
3293
-            $EE_Export->export_attendees();
3294
-        }
3295
-    }
3296
-
3297
-
3298
-    public function _contact_list_report()
3299
-    {
3300
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3301
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3302
-                'page'        => 'espresso_batch',
3303
-                'batch'       => 'file',
3304
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3305
-                'return_url'  => urlencode($this->_req_data['return_url']),
3306
-            )));
3307
-        } else {
3308
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3309
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3310
-                $EE_Export = EE_Export::instance($this->_req_data);
3311
-                $EE_Export->report_attendees();
3312
-            }
3313
-        }
3314
-    }
3315
-
3316
-
3317
-
3318
-
3319
-
3320
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3321
-    /**
3322
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3323
-     *
3324
-     * @return void
3325
-     * @throws EE_Error
3326
-     */
3327
-    protected function _duplicate_attendee()
3328
-    {
3329
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3330
-        //verify we have necessary info
3331
-        if (empty($this->_req_data['_REG_ID'])) {
3332
-            EE_Error::add_error(
3333
-                esc_html__(
3334
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3335
-                    'event_espresso'
3336
-                ), __FILE__, __LINE__, __FUNCTION__
3337
-            );
3338
-            $query_args = array('action' => $action);
3339
-            $this->_redirect_after_action('', '', '', $query_args, true);
3340
-        }
3341
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3342
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3343
-        $attendee     = $registration->attendee();
3344
-        //remove relation of existing attendee on registration
3345
-        $registration->_remove_relation_to($attendee, 'Attendee');
3346
-        //new attendee
3347
-        $new_attendee = clone $attendee;
3348
-        $new_attendee->set('ATT_ID', 0);
3349
-        $new_attendee->save();
3350
-        //add new attendee to reg
3351
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3352
-        EE_Error::add_success(
3353
-            esc_html__(
3354
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3355
-                'event_espresso'
3356
-            )
3357
-        );
3358
-        //redirect to edit page for attendee
3359
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3360
-        $this->_redirect_after_action('', '', '', $query_args, true);
3361
-    }
3362
-
3363
-
3364
-    //related to cpt routes
3365
-    protected function _insert_update_cpt_item($post_id, $post)
3366
-    {
3367
-        $success  = true;
3368
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3369
-        //for attendee updates
3370
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3371
-            //note we should only be UPDATING attendees at this point.
3372
-            $updated_fields = array(
3373
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3374
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3375
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3376
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3377
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3378
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3379
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3380
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3381
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3382
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3383
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3384
-            );
3385
-            foreach ($updated_fields as $field => $value) {
3386
-                $attendee->set($field, $value);
3387
-            }
3388
-            $success                   = $attendee->save();
3389
-            $attendee_update_callbacks = apply_filters(
3390
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3391
-                array()
3392
-            );
3393
-            foreach ($attendee_update_callbacks as $a_callback) {
3394
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3395
-                    throw new EE_Error(
3396
-                        sprintf(
3397
-                            esc_html__(
3398
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3399
-                                'event_espresso'
3400
-                            ),
3401
-                            $a_callback
3402
-                        )
3403
-                    );
3404
-                }
3405
-            }
3406
-        }
3407
-        if ($success === false) {
3408
-            EE_Error::add_error(
3409
-                esc_html__(
3410
-                    'Something went wrong with updating the meta table data for the registration.',
3411
-                    'event_espresso'
3412
-                ),
3413
-                __FILE__, __FUNCTION__, __LINE__
3414
-            );
3415
-        }
3416
-    }
3417
-
3418
-
3419
-    public function trash_cpt_item($post_id)
3420
-    {
3421
-    }
3422
-
3423
-
3424
-    public function delete_cpt_item($post_id)
3425
-    {
3426
-    }
3427
-
3428
-
3429
-    public function restore_cpt_item($post_id)
3430
-    {
3431
-    }
3432
-
3433
-
3434
-    protected function _restore_cpt_item($post_id, $revision_id)
3435
-    {
3436
-    }
3437
-
3438
-
3439
-    public function attendee_editor_metaboxes()
3440
-    {
3441
-        $this->verify_cpt_object();
3442
-        remove_meta_box(
3443
-            'postexcerpt',
3444
-            esc_html__('Excerpt', 'event_espresso'),
3445
-            'post_excerpt_meta_box',
3446
-            $this->_cpt_routes[$this->_req_action],
3447
-            'normal',
3448
-            'core'
3449
-        );
3450
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3451
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3452
-            add_meta_box(
3453
-                'postexcerpt',
3454
-                esc_html__('Short Biography', 'event_espresso'),
3455
-                'post_excerpt_meta_box',
3456
-                $this->_cpt_routes[$this->_req_action],
3457
-                'normal'
3458
-            );
3459
-        }
3460
-        if (post_type_supports('espresso_attendees', 'comments')) {
3461
-            add_meta_box(
3462
-                'commentsdiv',
3463
-                esc_html__('Notes on the Contact', 'event_espresso'),
3464
-                'post_comment_meta_box',
3465
-                $this->_cpt_routes[$this->_req_action],
3466
-                'normal',
3467
-                'core'
3468
-            );
3469
-        }
3470
-        add_meta_box(
3471
-            'attendee_contact_info',
3472
-            esc_html__('Contact Info', 'event_espresso'),
3473
-            array($this, 'attendee_contact_info'),
3474
-            $this->_cpt_routes[$this->_req_action],
3475
-            'side',
3476
-            'core'
3477
-        );
3478
-        add_meta_box(
3479
-            'attendee_details_address',
3480
-            esc_html__('Address Details', 'event_espresso'),
3481
-            array($this, 'attendee_address_details'),
3482
-            $this->_cpt_routes[$this->_req_action],
3483
-            'normal',
3484
-            'core'
3485
-        );
3486
-        add_meta_box(
3487
-            'attendee_registrations',
3488
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3489
-            array($this, 'attendee_registrations_meta_box'),
3490
-            $this->_cpt_routes[$this->_req_action],
3491
-            'normal',
3492
-            'high'
3493
-        );
3494
-    }
3495
-
3496
-
3497
-    /**
3498
-     * Metabox for attendee contact info
3499
-     *
3500
-     * @param  WP_Post $post wp post object
3501
-     * @return string attendee contact info ( and form )
3502
-     * @throws DomainException
3503
-     */
3504
-    public function attendee_contact_info($post)
3505
-    {
3506
-        //get attendee object ( should already have it )
3507
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3508
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3509
-        EEH_Template::display_template($template, $this->_template_args);
3510
-    }
3511
-
3512
-
3513
-    /**
3514
-     * Metabox for attendee details
3515
-     *
3516
-     * @param  WP_Post $post wp post object
3517
-     * @return string attendee address details (and form)
3518
-     * @throws DomainException
3519
-     */
3520
-    public function attendee_address_details($post)
3521
-    {
3522
-        //get attendee object (should already have it)
3523
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3524
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3525
-            new EE_Question_Form_Input(
3526
-                EE_Question::new_instance(
3527
-                    array(
3528
-                        'QST_ID'           => 0,
3529
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3530
-                        'QST_system'       => 'admin-state',
3531
-                    )
3532
-                ),
3533
-                EE_Answer::new_instance(
3534
-                    array(
3535
-                        'ANS_ID'    => 0,
3536
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3537
-                    )
3538
-                ),
3539
-                array(
3540
-                    'input_id'       => 'STA_ID',
3541
-                    'input_name'     => 'STA_ID',
3542
-                    'input_prefix'   => '',
3543
-                    'append_qstn_id' => false,
3544
-                )
3545
-            )
3546
-        );
3547
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3548
-            new EE_Question_Form_Input(
3549
-                EE_Question::new_instance(
3550
-                    array(
3551
-                        'QST_ID'           => 0,
3552
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3553
-                        'QST_system'       => 'admin-country',
3554
-                    )
3555
-                ),
3556
-                EE_Answer::new_instance(
3557
-                    array(
3558
-                        'ANS_ID'    => 0,
3559
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3560
-                    )
3561
-                ),
3562
-                array(
3563
-                    'input_id'       => 'CNT_ISO',
3564
-                    'input_name'     => 'CNT_ISO',
3565
-                    'input_prefix'   => '',
3566
-                    'append_qstn_id' => false,
3567
-                )
3568
-            )
3569
-        );
3570
-        $template                             =
3571
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3572
-        EEH_Template::display_template($template, $this->_template_args);
3573
-    }
3574
-
3575
-
3576
-    /**
3577
-     *        _attendee_details
3578
-     *
3579
-     * @access protected
3580
-     * @param $post
3581
-     * @return void
3582
-     * @throws DomainException
3583
-     * @throws EE_Error
3584
-     */
3585
-    public function attendee_registrations_meta_box($post)
3586
-    {
3587
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3588
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3589
-        $template                              =
3590
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3591
-        EEH_Template::display_template($template, $this->_template_args);
3592
-    }
3593
-
3594
-
3595
-    /**
3596
-     * add in the form fields for the attendee edit
3597
-     *
3598
-     * @param  WP_Post $post wp post object
3599
-     * @return string html for new form.
3600
-     * @throws DomainException
3601
-     */
3602
-    public function after_title_form_fields($post)
3603
-    {
3604
-        if ($post->post_type == 'espresso_attendees') {
3605
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3606
-            $template_args['attendee'] = $this->_cpt_model_obj;
3607
-            EEH_Template::display_template($template, $template_args);
3608
-        }
3609
-    }
3610
-
3611
-
3612
-    /**
3613
-     *        _trash_or_restore_attendee
3614
-     *
3615
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3616
-     * @return void
3617
-     * @throws EE_Error
3618
-     * @access protected
3619
-     */
3620
-    protected function _trash_or_restore_attendees($trash = true)
3621
-    {
3622
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3623
-        $ATT_MDL = EEM_Attendee::instance();
3624
-        $success = 1;
3625
-        //Checkboxes
3626
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3627
-            // if array has more than one element than success message should be plural
3628
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3629
-            // cycle thru checkboxes
3630
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3631
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3632
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3633
-                if ( ! $updated) {
3634
-                    $success = 0;
3635
-                }
3636
-            }
3637
-        } else {
3638
-            // grab single id and delete
3639
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3640
-            //get attendee
3641
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3642
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3643
-            $updated = $att->save();
3644
-            if ( ! $updated) {
3645
-                $success = 0;
3646
-            }
3647
-        }
3648
-        $what        = $success > 1
3649
-            ? esc_html__('Contacts', 'event_espresso')
3650
-            : esc_html__('Contact', 'event_espresso');
3651
-        $action_desc = $trash
3652
-            ? esc_html__('moved to the trash', 'event_espresso')
3653
-            : esc_html__('restored', 'event_espresso');
3654
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3655
-    }
2869
+		}
2870
+		$template_args = array(
2871
+			'title'                    => '',
2872
+			'content'                  => '',
2873
+			'step_button_text'         => '',
2874
+			'show_notification_toggle' => false,
2875
+		);
2876
+		//to indicate we're processing a new registration
2877
+		$hidden_fields = array(
2878
+			'processing_registration' => array(
2879
+				'type'  => 'hidden',
2880
+				'value' => 0,
2881
+			),
2882
+			'event_id'                => array(
2883
+				'type'  => 'hidden',
2884
+				'value' => $this->_reg_event->ID(),
2885
+			),
2886
+		);
2887
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2888
+		$cart = EE_Registry::instance()->SSN->cart();
2889
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2890
+		switch ($step) {
2891
+			case 'ticket' :
2892
+				$hidden_fields['processing_registration']['value'] = 1;
2893
+				$template_args['title']                            = esc_html__(
2894
+					'Step One: Select the Ticket for this registration',
2895
+					'event_espresso'
2896
+				);
2897
+				$template_args['content']                          =
2898
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2899
+				$template_args['step_button_text']                 = esc_html__(
2900
+					'Add Tickets and Continue to Registrant Details',
2901
+					'event_espresso'
2902
+				);
2903
+				$template_args['show_notification_toggle']         = false;
2904
+				break;
2905
+			case 'questions' :
2906
+				$hidden_fields['processing_registration']['value'] = 2;
2907
+				$template_args['title']                            = esc_html__(
2908
+					'Step Two: Add Registrant Details for this Registration',
2909
+					'event_espresso'
2910
+				);
2911
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2912
+				// properly by the first process_reg_step run.
2913
+				$template_args['content']                  =
2914
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2915
+				$template_args['step_button_text']         = esc_html__(
2916
+					'Save Registration and Continue to Details',
2917
+					'event_espresso'
2918
+				);
2919
+				$template_args['show_notification_toggle'] = true;
2920
+				break;
2921
+		}
2922
+		//we come back to the process_registration_step route.
2923
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2924
+		return EEH_Template::display_template(
2925
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2926
+			$template_args,
2927
+			true
2928
+		);
2929
+	}
2930
+
2931
+
2932
+	/**
2933
+	 *        set_reg_event
2934
+	 *
2935
+	 * @access private
2936
+	 * @return bool
2937
+	 * @throws EE_Error
2938
+	 */
2939
+	private function _set_reg_event()
2940
+	{
2941
+		if (is_object($this->_reg_event)) {
2942
+			return true;
2943
+		}
2944
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2945
+		if ( ! $EVT_ID) {
2946
+			return false;
2947
+		}
2948
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2949
+		return true;
2950
+	}
2951
+
2952
+
2953
+	/**
2954
+	 * process_reg_step
2955
+	 *
2956
+	 * @access        public
2957
+	 * @return string
2958
+	 * @throws DomainException
2959
+	 * @throws EE_Error
2960
+	 * @throws RuntimeException
2961
+	 */
2962
+	public function process_reg_step()
2963
+	{
2964
+		EE_System::do_not_cache();
2965
+		$this->_set_reg_event();
2966
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2967
+		EE_Registry::instance()->REQ->set('uts', time());
2968
+		//what step are we on?
2969
+		$cart = EE_Registry::instance()->SSN->cart();
2970
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2971
+		//if doing ajax then we need to verify the nonce
2972
+		if (defined('DOING_AJAX')) {
2973
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2974
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2975
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2976
+		}
2977
+		switch ($step) {
2978
+			case 'ticket' :
2979
+				//process ticket selection
2980
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2981
+				if ($success) {
2982
+					EE_Error::add_success(
2983
+						esc_html__(
2984
+							'Tickets Selected. Now complete the registration.',
2985
+							'event_espresso'
2986
+						)
2987
+					);
2988
+				} else {
2989
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2990
+				}
2991
+				if (defined('DOING_AJAX')) {
2992
+					$this->new_registration(); //display next step
2993
+				} else {
2994
+					$query_args = array(
2995
+						'action'                  => 'new_registration',
2996
+						'processing_registration' => 1,
2997
+						'event_id'                => $this->_reg_event->ID(),
2998
+						'uts'                     => time(),
2999
+					);
3000
+					$this->_redirect_after_action(
3001
+						false,
3002
+						'',
3003
+						'',
3004
+						$query_args,
3005
+						true
3006
+					);
3007
+				}
3008
+				break;
3009
+			case 'questions' :
3010
+				if (! isset(
3011
+					$this->_req_data['txn_reg_status_change'],
3012
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
3013
+				) {
3014
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3015
+				}
3016
+				//process registration
3017
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3018
+				if ($cart instanceof EE_Cart) {
3019
+					$grand_total = $cart->get_cart_grand_total();
3020
+					if ($grand_total instanceof EE_Line_Item) {
3021
+						$grand_total->save_this_and_descendants_to_txn();
3022
+					}
3023
+				}
3024
+				if ( ! $transaction instanceof EE_Transaction) {
3025
+					$query_args = array(
3026
+						'action'                  => 'new_registration',
3027
+						'processing_registration' => 2,
3028
+						'event_id'                => $this->_reg_event->ID(),
3029
+						'uts'                     => time(),
3030
+					);
3031
+					if (defined('DOING_AJAX')) {
3032
+						//display registration form again because there are errors (maybe validation?)
3033
+						$this->new_registration();
3034
+						return;
3035
+					} else {
3036
+						$this->_redirect_after_action(
3037
+							false,
3038
+							'',
3039
+							'',
3040
+							$query_args,
3041
+							true
3042
+						);
3043
+						return;
3044
+					}
3045
+				}
3046
+				// maybe update status, and make sure to save transaction if not done already
3047
+				if ( ! $transaction->update_status_based_on_total_paid()) {
3048
+					$transaction->save();
3049
+				}
3050
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3051
+				$this->_req_data = array();
3052
+				$query_args      = array(
3053
+					'action'        => 'redirect_to_txn',
3054
+					'TXN_ID'        => $transaction->ID(),
3055
+					'EVT_ID'        => $this->_reg_event->ID(),
3056
+					'event_name'    => urlencode($this->_reg_event->name()),
3057
+					'redirect_from' => 'new_registration',
3058
+				);
3059
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3060
+				break;
3061
+		}
3062
+		//what are you looking here for?  Should be nothing to do at this point.
3063
+	}
3064
+
3065
+
3066
+	/**
3067
+	 * redirect_to_txn
3068
+	 *
3069
+	 * @access public
3070
+	 * @return void
3071
+	 * @throws EE_Error
3072
+	 */
3073
+	public function redirect_to_txn()
3074
+	{
3075
+		EE_System::do_not_cache();
3076
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3077
+		$query_args = array(
3078
+			'action' => 'view_transaction',
3079
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3080
+			'page'   => 'espresso_transactions',
3081
+		);
3082
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3083
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3084
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3085
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3086
+		}
3087
+		EE_Error::add_success(
3088
+			esc_html__(
3089
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3090
+				'event_espresso'
3091
+			)
3092
+		);
3093
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3094
+	}
3095
+
3096
+
3097
+	/**
3098
+	 *        generates HTML for the Attendee Contact List
3099
+	 *
3100
+	 * @access protected
3101
+	 * @return void
3102
+	 */
3103
+	protected function _attendee_contact_list_table()
3104
+	{
3105
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3106
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3107
+		$this->display_admin_list_table_page_with_no_sidebar();
3108
+	}
3109
+
3110
+
3111
+	/**
3112
+	 *        get_attendees
3113
+	 *
3114
+	 * @param      $per_page
3115
+	 * @param bool $count whether to return count or data.
3116
+	 * @param bool $trash
3117
+	 * @return array
3118
+	 * @throws EE_Error
3119
+	 * @access public
3120
+	 */
3121
+	public function get_attendees($per_page, $count = false, $trash = false)
3122
+	{
3123
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3124
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3125
+		$ATT_MDL                    = EEM_Attendee::instance();
3126
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3127
+		switch ($this->_req_data['orderby']) {
3128
+			case 'ATT_ID':
3129
+				$orderby = 'ATT_ID';
3130
+				break;
3131
+			case 'ATT_fname':
3132
+				$orderby = 'ATT_fname';
3133
+				break;
3134
+			case 'ATT_email':
3135
+				$orderby = 'ATT_email';
3136
+				break;
3137
+			case 'ATT_city':
3138
+				$orderby = 'ATT_city';
3139
+				break;
3140
+			case 'STA_ID':
3141
+				$orderby = 'STA_ID';
3142
+				break;
3143
+			case 'CNT_ID':
3144
+				$orderby = 'CNT_ID';
3145
+				break;
3146
+			default:
3147
+				$orderby = 'ATT_lname';
3148
+		}
3149
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3150
+			? $this->_req_data['order']
3151
+			: 'ASC';
3152
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3153
+			? $this->_req_data['paged']
3154
+			: 1;
3155
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3156
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3157
+			? $this->_req_data['perpage']
3158
+			: $per_page;
3159
+		$_where       = array();
3160
+		if ( ! empty($this->_req_data['s'])) {
3161
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3162
+			$_where['OR'] = array(
3163
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3164
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3165
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3166
+				'ATT_fname'                         => array('LIKE', $sstr),
3167
+				'ATT_lname'                         => array('LIKE', $sstr),
3168
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3169
+				'ATT_email'                         => array('LIKE', $sstr),
3170
+				'ATT_address'                       => array('LIKE', $sstr),
3171
+				'ATT_address2'                      => array('LIKE', $sstr),
3172
+				'ATT_city'                          => array('LIKE', $sstr),
3173
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3174
+				'State.STA_name'                    => array('LIKE', $sstr),
3175
+				'ATT_phone'                         => array('LIKE', $sstr),
3176
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3177
+				'Registration.REG_code'             => array('LIKE', $sstr),
3178
+				'Registration.REG_count'            => array('LIKE', $sstr),
3179
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3180
+			);
3181
+		}
3182
+		$offset = ($current_page - 1) * $per_page;
3183
+		$limit  = $count ? null : array($offset, $per_page);
3184
+		if ($trash) {
3185
+			$_where['status'] = array('!=', 'publish');
3186
+			$all_attendees    = $count
3187
+				? $ATT_MDL->count(array(
3188
+					$_where,
3189
+					'order_by' => array($orderby => $sort),
3190
+					'limit'    => $limit,
3191
+				), 'ATT_ID', true)
3192
+				: $ATT_MDL->get_all(array(
3193
+					$_where,
3194
+					'order_by' => array($orderby => $sort),
3195
+					'limit'    => $limit,
3196
+				));
3197
+		} else {
3198
+			$_where['status'] = array('IN', array('publish'));
3199
+			$all_attendees    = $count
3200
+				? $ATT_MDL->count(array(
3201
+					$_where,
3202
+					'order_by' => array($orderby => $sort),
3203
+					'limit'    => $limit,
3204
+				), 'ATT_ID', true)
3205
+				: $ATT_MDL->get_all(array(
3206
+					$_where,
3207
+					'order_by' => array($orderby => $sort),
3208
+					'limit'    => $limit,
3209
+				));
3210
+		}
3211
+		return $all_attendees;
3212
+	}
3213
+
3214
+
3215
+	/**
3216
+	 * This is just taking care of resending the registration confirmation
3217
+	 *
3218
+	 * @access protected
3219
+	 * @return void
3220
+	 */
3221
+	protected function _resend_registration()
3222
+	{
3223
+		$this->_process_resend_registration();
3224
+		$query_args = isset($this->_req_data['redirect_to'])
3225
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3226
+			: array('action' => 'default');
3227
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3228
+	}
3229
+
3230
+	/**
3231
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3232
+	 * to use when selecting registrations
3233
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3234
+	 *                                                     the query parameters from the request
3235
+	 * @return void ends the request with a redirect or download
3236
+	 */
3237
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3238
+	{
3239
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3240
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3241
+				array(
3242
+					'page'        => 'espresso_batch',
3243
+					'batch'       => 'file',
3244
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3245
+					'filters'     => urlencode(
3246
+						serialize(
3247
+							call_user_func(
3248
+								array( $this, $method_name_for_getting_query_params ),
3249
+								EEH_Array::is_set(
3250
+									$this->_req_data,
3251
+									'filters',
3252
+									array()
3253
+								)
3254
+							)
3255
+						)
3256
+				),
3257
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3258
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3259
+				'return_url'  => urlencode($this->_req_data['return_url']),
3260
+			)));
3261
+		} else {
3262
+			$new_request_args = array(
3263
+				'export' => 'report',
3264
+				'action' => 'registrations_report_for_event',
3265
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3266
+			);
3267
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3268
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3269
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3270
+				$EE_Export = EE_Export::instance($this->_req_data);
3271
+				$EE_Export->export();
3272
+			}
3273
+		}
3274
+	}
3275
+
3276
+
3277
+
3278
+	/**
3279
+	 * Creates a registration report using only query parameters in the request
3280
+	 * @return void
3281
+	 */
3282
+	public function _registrations_report()
3283
+	{
3284
+		$this->_registrations_report_base('_get_registration_query_parameters');
3285
+	}
3286
+
3287
+
3288
+	public function _contact_list_export()
3289
+	{
3290
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3291
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3292
+			$EE_Export = EE_Export::instance($this->_req_data);
3293
+			$EE_Export->export_attendees();
3294
+		}
3295
+	}
3296
+
3297
+
3298
+	public function _contact_list_report()
3299
+	{
3300
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3301
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3302
+				'page'        => 'espresso_batch',
3303
+				'batch'       => 'file',
3304
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3305
+				'return_url'  => urlencode($this->_req_data['return_url']),
3306
+			)));
3307
+		} else {
3308
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3309
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3310
+				$EE_Export = EE_Export::instance($this->_req_data);
3311
+				$EE_Export->report_attendees();
3312
+			}
3313
+		}
3314
+	}
3315
+
3316
+
3317
+
3318
+
3319
+
3320
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3321
+	/**
3322
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3323
+	 *
3324
+	 * @return void
3325
+	 * @throws EE_Error
3326
+	 */
3327
+	protected function _duplicate_attendee()
3328
+	{
3329
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3330
+		//verify we have necessary info
3331
+		if (empty($this->_req_data['_REG_ID'])) {
3332
+			EE_Error::add_error(
3333
+				esc_html__(
3334
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3335
+					'event_espresso'
3336
+				), __FILE__, __LINE__, __FUNCTION__
3337
+			);
3338
+			$query_args = array('action' => $action);
3339
+			$this->_redirect_after_action('', '', '', $query_args, true);
3340
+		}
3341
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3342
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3343
+		$attendee     = $registration->attendee();
3344
+		//remove relation of existing attendee on registration
3345
+		$registration->_remove_relation_to($attendee, 'Attendee');
3346
+		//new attendee
3347
+		$new_attendee = clone $attendee;
3348
+		$new_attendee->set('ATT_ID', 0);
3349
+		$new_attendee->save();
3350
+		//add new attendee to reg
3351
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3352
+		EE_Error::add_success(
3353
+			esc_html__(
3354
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3355
+				'event_espresso'
3356
+			)
3357
+		);
3358
+		//redirect to edit page for attendee
3359
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3360
+		$this->_redirect_after_action('', '', '', $query_args, true);
3361
+	}
3362
+
3363
+
3364
+	//related to cpt routes
3365
+	protected function _insert_update_cpt_item($post_id, $post)
3366
+	{
3367
+		$success  = true;
3368
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3369
+		//for attendee updates
3370
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3371
+			//note we should only be UPDATING attendees at this point.
3372
+			$updated_fields = array(
3373
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3374
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3375
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3376
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3377
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3378
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3379
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3380
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3381
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3382
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3383
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3384
+			);
3385
+			foreach ($updated_fields as $field => $value) {
3386
+				$attendee->set($field, $value);
3387
+			}
3388
+			$success                   = $attendee->save();
3389
+			$attendee_update_callbacks = apply_filters(
3390
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3391
+				array()
3392
+			);
3393
+			foreach ($attendee_update_callbacks as $a_callback) {
3394
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3395
+					throw new EE_Error(
3396
+						sprintf(
3397
+							esc_html__(
3398
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3399
+								'event_espresso'
3400
+							),
3401
+							$a_callback
3402
+						)
3403
+					);
3404
+				}
3405
+			}
3406
+		}
3407
+		if ($success === false) {
3408
+			EE_Error::add_error(
3409
+				esc_html__(
3410
+					'Something went wrong with updating the meta table data for the registration.',
3411
+					'event_espresso'
3412
+				),
3413
+				__FILE__, __FUNCTION__, __LINE__
3414
+			);
3415
+		}
3416
+	}
3417
+
3418
+
3419
+	public function trash_cpt_item($post_id)
3420
+	{
3421
+	}
3422
+
3423
+
3424
+	public function delete_cpt_item($post_id)
3425
+	{
3426
+	}
3427
+
3428
+
3429
+	public function restore_cpt_item($post_id)
3430
+	{
3431
+	}
3432
+
3433
+
3434
+	protected function _restore_cpt_item($post_id, $revision_id)
3435
+	{
3436
+	}
3437
+
3438
+
3439
+	public function attendee_editor_metaboxes()
3440
+	{
3441
+		$this->verify_cpt_object();
3442
+		remove_meta_box(
3443
+			'postexcerpt',
3444
+			esc_html__('Excerpt', 'event_espresso'),
3445
+			'post_excerpt_meta_box',
3446
+			$this->_cpt_routes[$this->_req_action],
3447
+			'normal',
3448
+			'core'
3449
+		);
3450
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3451
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3452
+			add_meta_box(
3453
+				'postexcerpt',
3454
+				esc_html__('Short Biography', 'event_espresso'),
3455
+				'post_excerpt_meta_box',
3456
+				$this->_cpt_routes[$this->_req_action],
3457
+				'normal'
3458
+			);
3459
+		}
3460
+		if (post_type_supports('espresso_attendees', 'comments')) {
3461
+			add_meta_box(
3462
+				'commentsdiv',
3463
+				esc_html__('Notes on the Contact', 'event_espresso'),
3464
+				'post_comment_meta_box',
3465
+				$this->_cpt_routes[$this->_req_action],
3466
+				'normal',
3467
+				'core'
3468
+			);
3469
+		}
3470
+		add_meta_box(
3471
+			'attendee_contact_info',
3472
+			esc_html__('Contact Info', 'event_espresso'),
3473
+			array($this, 'attendee_contact_info'),
3474
+			$this->_cpt_routes[$this->_req_action],
3475
+			'side',
3476
+			'core'
3477
+		);
3478
+		add_meta_box(
3479
+			'attendee_details_address',
3480
+			esc_html__('Address Details', 'event_espresso'),
3481
+			array($this, 'attendee_address_details'),
3482
+			$this->_cpt_routes[$this->_req_action],
3483
+			'normal',
3484
+			'core'
3485
+		);
3486
+		add_meta_box(
3487
+			'attendee_registrations',
3488
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3489
+			array($this, 'attendee_registrations_meta_box'),
3490
+			$this->_cpt_routes[$this->_req_action],
3491
+			'normal',
3492
+			'high'
3493
+		);
3494
+	}
3495
+
3496
+
3497
+	/**
3498
+	 * Metabox for attendee contact info
3499
+	 *
3500
+	 * @param  WP_Post $post wp post object
3501
+	 * @return string attendee contact info ( and form )
3502
+	 * @throws DomainException
3503
+	 */
3504
+	public function attendee_contact_info($post)
3505
+	{
3506
+		//get attendee object ( should already have it )
3507
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3508
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3509
+		EEH_Template::display_template($template, $this->_template_args);
3510
+	}
3511
+
3512
+
3513
+	/**
3514
+	 * Metabox for attendee details
3515
+	 *
3516
+	 * @param  WP_Post $post wp post object
3517
+	 * @return string attendee address details (and form)
3518
+	 * @throws DomainException
3519
+	 */
3520
+	public function attendee_address_details($post)
3521
+	{
3522
+		//get attendee object (should already have it)
3523
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3524
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3525
+			new EE_Question_Form_Input(
3526
+				EE_Question::new_instance(
3527
+					array(
3528
+						'QST_ID'           => 0,
3529
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3530
+						'QST_system'       => 'admin-state',
3531
+					)
3532
+				),
3533
+				EE_Answer::new_instance(
3534
+					array(
3535
+						'ANS_ID'    => 0,
3536
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3537
+					)
3538
+				),
3539
+				array(
3540
+					'input_id'       => 'STA_ID',
3541
+					'input_name'     => 'STA_ID',
3542
+					'input_prefix'   => '',
3543
+					'append_qstn_id' => false,
3544
+				)
3545
+			)
3546
+		);
3547
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3548
+			new EE_Question_Form_Input(
3549
+				EE_Question::new_instance(
3550
+					array(
3551
+						'QST_ID'           => 0,
3552
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3553
+						'QST_system'       => 'admin-country',
3554
+					)
3555
+				),
3556
+				EE_Answer::new_instance(
3557
+					array(
3558
+						'ANS_ID'    => 0,
3559
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3560
+					)
3561
+				),
3562
+				array(
3563
+					'input_id'       => 'CNT_ISO',
3564
+					'input_name'     => 'CNT_ISO',
3565
+					'input_prefix'   => '',
3566
+					'append_qstn_id' => false,
3567
+				)
3568
+			)
3569
+		);
3570
+		$template                             =
3571
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3572
+		EEH_Template::display_template($template, $this->_template_args);
3573
+	}
3574
+
3575
+
3576
+	/**
3577
+	 *        _attendee_details
3578
+	 *
3579
+	 * @access protected
3580
+	 * @param $post
3581
+	 * @return void
3582
+	 * @throws DomainException
3583
+	 * @throws EE_Error
3584
+	 */
3585
+	public function attendee_registrations_meta_box($post)
3586
+	{
3587
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3588
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3589
+		$template                              =
3590
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3591
+		EEH_Template::display_template($template, $this->_template_args);
3592
+	}
3593
+
3594
+
3595
+	/**
3596
+	 * add in the form fields for the attendee edit
3597
+	 *
3598
+	 * @param  WP_Post $post wp post object
3599
+	 * @return string html for new form.
3600
+	 * @throws DomainException
3601
+	 */
3602
+	public function after_title_form_fields($post)
3603
+	{
3604
+		if ($post->post_type == 'espresso_attendees') {
3605
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3606
+			$template_args['attendee'] = $this->_cpt_model_obj;
3607
+			EEH_Template::display_template($template, $template_args);
3608
+		}
3609
+	}
3610
+
3611
+
3612
+	/**
3613
+	 *        _trash_or_restore_attendee
3614
+	 *
3615
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3616
+	 * @return void
3617
+	 * @throws EE_Error
3618
+	 * @access protected
3619
+	 */
3620
+	protected function _trash_or_restore_attendees($trash = true)
3621
+	{
3622
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3623
+		$ATT_MDL = EEM_Attendee::instance();
3624
+		$success = 1;
3625
+		//Checkboxes
3626
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3627
+			// if array has more than one element than success message should be plural
3628
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3629
+			// cycle thru checkboxes
3630
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3631
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3632
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3633
+				if ( ! $updated) {
3634
+					$success = 0;
3635
+				}
3636
+			}
3637
+		} else {
3638
+			// grab single id and delete
3639
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3640
+			//get attendee
3641
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3642
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3643
+			$updated = $att->save();
3644
+			if ( ! $updated) {
3645
+				$success = 0;
3646
+			}
3647
+		}
3648
+		$what        = $success > 1
3649
+			? esc_html__('Contacts', 'event_espresso')
3650
+			: esc_html__('Contact', 'event_espresso');
3651
+		$action_desc = $trash
3652
+			? esc_html__('moved to the trash', 'event_espresso')
3653
+			: esc_html__('restored', 'event_espresso');
3654
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3655
+	}
3656 3656
 
3657 3657
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Factory.lib.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
 	 * @param \EE_Message_Resource_Manager $Message_Resource_Manager
54 54
 	 * @return \EE_Message_Factory instance
55 55
 	 */
56
-	public static function instance( EE_Message_Resource_Manager $Message_Resource_Manager ) {
56
+	public static function instance(EE_Message_Resource_Manager $Message_Resource_Manager) {
57 57
 		// check if class object is instantiated, and instantiated properly
58
-		if ( ! self::$_instance instanceof EE_Message_Factory ) {
59
-			self::$_instance = new EE_Message_Factory( $Message_Resource_Manager );
58
+		if ( ! self::$_instance instanceof EE_Message_Factory) {
59
+			self::$_instance = new EE_Message_Factory($Message_Resource_Manager);
60 60
 		}
61 61
 		return self::$_instance;
62 62
 	}
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	 * @param  array $props_n_values
69 69
 	 * @return EE_Message
70 70
 	 */
71
-	public static function create( $props_n_values = array() ) {
71
+	public static function create($props_n_values = array()) {
72 72
 		/** @type EE_Message_Factory $Message_Factory */
73
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
74
-		return $Message_Factory->_create( $props_n_values );
73
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
74
+		return $Message_Factory->_create($props_n_values);
75 75
 	}
76 76
 
77 77
 
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
 	 * @return \EE_Message
83 83
 	 * @throws \EE_Error
84 84
 	 */
85
-	public static function set_messenger_and_message_type( EE_Message $message ) {
85
+	public static function set_messenger_and_message_type(EE_Message $message) {
86 86
 		/** @type EE_Message_Factory $Message_Factory */
87
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
88
-		return $Message_Factory->_set_messenger_and_message_type( $message );
87
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
88
+		return $Message_Factory->_set_messenger_and_message_type($message);
89 89
 	}
90 90
 
91 91
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @return \EE_Message
97 97
 	 * @throws \EE_Error
98 98
 	 */
99
-	public static function set_messenger( EE_Message $message ) {
99
+	public static function set_messenger(EE_Message $message) {
100 100
 		/** @type EE_Message_Factory $Message_Factory */
101
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
102
-		return $Message_Factory->_set_messenger( $message );
101
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
102
+		return $Message_Factory->_set_messenger($message);
103 103
 	}
104 104
 
105 105
 
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 	 * @return \EE_Message
111 111
 	 * @throws \EE_Error
112 112
 	 */
113
-	public static function set_message_type( EE_Message $message ) {
113
+	public static function set_message_type(EE_Message $message) {
114 114
 		/** @type EE_Message_Factory $Message_Factory */
115
-		$Message_Factory = EE_Registry::instance()->load_lib( 'Message_Factory' );
116
-		return $Message_Factory->_set_message_type( $message );
115
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
116
+		return $Message_Factory->_set_message_type($message);
117 117
 	}
118 118
 
119 119
 
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
 	 * @return \EE_Message
125 125
 	 * @throws \EE_Error
126 126
 	 */
127
-	protected function _create( $props_n_values = array() ) {
127
+	protected function _create($props_n_values = array()) {
128 128
 		$new_instance = false;
129
-		if ( ! empty( $props_n_values['MSG_ID'] ) ) {
130
-			$message = EE_Message::new_instance_from_db( $props_n_values );
129
+		if ( ! empty($props_n_values['MSG_ID'])) {
130
+			$message = EE_Message::new_instance_from_db($props_n_values);
131 131
 		} else {
132
-			$message = EE_Message::new_instance( $props_n_values );
132
+			$message = EE_Message::new_instance($props_n_values);
133 133
 			$new_instance = true;
134 134
 		}
135
-		return $this->_set_messenger_and_message_type( $message, $new_instance );
135
+		return $this->_set_messenger_and_message_type($message, $new_instance);
136 136
 	}
137 137
 
138 138
 
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
 	 * @return \EE_Message
145 145
 	 * @throws \EE_Error
146 146
 	 */
147
-	protected function _set_messenger_and_message_type( EE_Message $message, $new_instance = false ) {
148
-		$message = $this->_set_messenger( $message );
149
-		$message = $this->_set_message_type( $message, $new_instance );
147
+	protected function _set_messenger_and_message_type(EE_Message $message, $new_instance = false) {
148
+		$message = $this->_set_messenger($message);
149
+		$message = $this->_set_message_type($message, $new_instance);
150 150
 		return $message;
151 151
 	}
152 152
 
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
 	 * @return \EE_Message
159 159
 	 * @throws \EE_Error
160 160
 	 */
161
-	protected function _set_messenger( EE_Message $message ) {
162
-		$messenger = $this->_message_resource_manager->get_messenger( $message->messenger() );
163
-		if ( $messenger instanceof EE_messenger ) {
164
-			$message->set_messenger_object( $messenger );
161
+	protected function _set_messenger(EE_Message $message) {
162
+		$messenger = $this->_message_resource_manager->get_messenger($message->messenger());
163
+		if ($messenger instanceof EE_messenger) {
164
+			$message->set_messenger_object($messenger);
165 165
 		}
166 166
 		return $message;
167 167
 	}
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
 	 * @return \EE_Message
176 176
 	 * @throws \EE_Error
177 177
 	 */
178
-	protected function _set_message_type( EE_Message $message, $new_instance = false ) {
179
-		$message_type = $this->_message_resource_manager->get_message_type( $message->message_type() );
180
-		if ( $message_type instanceof EE_message_type ) {
181
-			$message->set_message_type_object( $message_type, $new_instance );
178
+	protected function _set_message_type(EE_Message $message, $new_instance = false) {
179
+		$message_type = $this->_message_resource_manager->get_message_type($message->message_type());
180
+		if ($message_type instanceof EE_message_type) {
181
+			$message->set_message_type_object($message_type, $new_instance);
182 182
 		}
183 183
 		return $message;
184 184
 	}
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Queue.lib.php 1 patch
Indentation   +677 added lines, -677 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use \EventEspresso\core\exceptions\SendMessageException;
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
 /**
@@ -18,681 +18,681 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @type    string  reference for sending action
23
-     */
24
-    const action_sending = 'sending';
25
-
26
-    /**
27
-     * @type    string  reference for generation action
28
-     */
29
-    const action_generating = 'generation';
30
-
31
-
32
-    /**
33
-     * @type EE_Message_Repository $_message_repository
34
-     */
35
-    protected $_message_repository;
36
-
37
-    /**
38
-     * Sets the limit of how many messages are generated per process.
39
-     *
40
-     * @type int
41
-     */
42
-    protected $_batch_count;
43
-
44
-    /**
45
-     * Sets the limit of how many messages can be sent per hour.
46
-     *
47
-     * @type int
48
-     */
49
-    protected $_rate_limit;
50
-
51
-    /**
52
-     * This is an array of cached queue items being stored in this object.
53
-     * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
-     * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
-     *
56
-     * @type EE_Message[]
57
-     */
58
-    protected $_cached_queue_items;
59
-
60
-    /**
61
-     * Tracks the number of unsaved queue items.
62
-     *
63
-     * @type int
64
-     */
65
-    protected $_unsaved_count = 0;
66
-
67
-    /**
68
-     * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
-     * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
-     *
71
-     * @type array
72
-     */
73
-    protected $_did_hook = array();
74
-
75
-
76
-    /**
77
-     * Constructor.
78
-     * Setup all the initial properties and load a EE_Message_Repository.
79
-     *
80
-     * @param \EE_Message_Repository $message_repository
81
-     */
82
-    public function __construct(EE_Message_Repository $message_repository)
83
-    {
84
-        $this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
-        $this->_rate_limit         = $this->get_rate_limit();
86
-        $this->_message_repository = $message_repository;
87
-    }
88
-
89
-
90
-    /**
91
-     * Add a EE_Message object to the queue
92
-     *
93
-     * @param EE_Message $message
94
-     * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
-     *                                 object is persisted, this data will be saved on an extra_meta object related to
96
-     *                                 EE_Message.
97
-     * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
-     * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
-     *                                 use the messenger send method but typically is based on preview data.
100
-     * @return bool          Whether the message was successfully added to the repository or not.
101
-     */
102
-    public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
-    {
104
-        $data['preview']   = $preview;
105
-        $data['test_send'] = $test_send;
106
-        return $this->_message_repository->add($message, $data);
107
-    }
108
-
109
-
110
-    /**
111
-     * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
-     *
113
-     * @param EE_Message $message The message to detach from the queue
114
-     * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
-     * @return bool
116
-     */
117
-    public function remove(EE_Message $message, $persist = false)
118
-    {
119
-        if ($persist && $this->_message_repository->current() !== $message) {
120
-            //get pointer on right message
121
-            if ($this->_message_repository->has($message)) {
122
-                $this->_message_repository->rewind();
123
-                while ($this->_message_repository->valid()) {
124
-                    if ($this->_message_repository->current() === $message) {
125
-                        break;
126
-                    }
127
-                    $this->_message_repository->next();
128
-                }
129
-            } else {
130
-                return false;
131
-            }
132
-        }
133
-        return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
-    }
135
-
136
-
137
-    /**
138
-     * Persists all queued EE_Message objects to the db.
139
-     *
140
-     * @param bool $do_hooks_only       @see EE_Message_Repository::saveAll
141
-     * @return array @see EE_Messages_Repository::saveAll() for return values.
142
-     */
143
-    public function save($do_hooks_only = false)
144
-    {
145
-        return $this->_message_repository->saveAll($do_hooks_only);
146
-    }
147
-
148
-
149
-    /**
150
-     * @return EE_Message_Repository
151
-     */
152
-    public function get_message_repository()
153
-    {
154
-        return $this->_message_repository;
155
-    }
156
-
157
-
158
-    /**
159
-     * This does the following things:
160
-     * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
161
-     * false).
162
-     * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
163
-     * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
164
-     * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
165
-     * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
166
-     * removed.
167
-     *
168
-     * @return bool  true if successfully retrieved batch, false no batch ready.
169
-     */
170
-    public function get_batch_to_generate()
171
-    {
172
-        if ($this->is_locked(EE_Messages_Queue::action_generating)) {
173
-            return false;
174
-        }
175
-
176
-        //lock batch generation to prevent race conditions.
177
-        $this->lock_queue(EE_Messages_Queue::action_generating);
178
-
179
-        $query_args = array(
180
-            // key 0 = where conditions
181
-            0          => array('STS_ID' => EEM_Message::status_incomplete),
182
-            'order_by' => $this->_get_priority_orderby(),
183
-            'limit'    => $this->_batch_count,
184
-        );
185
-        $messages   = EEM_Message::instance()->get_all($query_args);
186
-
187
-        if ( ! $messages) {
188
-            return false; //nothing to generate
189
-        }
190
-
191
-        foreach ($messages as $message) {
192
-            if ($message instanceof EE_Message) {
193
-                $data = $message->all_extra_meta_array();
194
-                $this->add($message, $data);
195
-            }
196
-        }
197
-        return true;
198
-    }
199
-
200
-
201
-    /**
202
-     * This does the following things:
203
-     * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
204
-     * false).
205
-     * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
206
-     * return false.
207
-     * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
208
-     * 3. On success or unsuccessful send, sets status appropriately.
209
-     * 4. Saves messages via the queue
210
-     * 5. Releases lock.
211
-     *
212
-     * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
213
-     *               necessarily mean that all messages were successfully sent.  It just means that this method
214
-     *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
215
-     *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
216
-     *               will also have a saved error message on it to assist with notifying user.
217
-     */
218
-    public function get_to_send_batch_and_send()
219
-    {
220
-        if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
221
-            return false;
222
-        }
223
-
224
-        $this->lock_queue(EE_Messages_Queue::action_sending);
225
-
226
-        $batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
227
-
228
-        $query_args = array(
229
-            // key 0 = where conditions
230
-            0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
231
-            'order_by' => $this->_get_priority_orderby(),
232
-            'limit'    => $batch,
233
-        );
234
-
235
-        $messages_to_send = EEM_Message::instance()->get_all($query_args);
236
-
237
-
238
-        //any to send?
239
-        if ( ! $messages_to_send) {
240
-            $this->unlock_queue(EE_Messages_Queue::action_sending);
241
-            return false;
242
-        }
243
-
244
-        //add to queue.
245
-        foreach ($messages_to_send as $message) {
246
-            if ($message instanceof EE_Message) {
247
-                $this->add($message);
248
-            }
249
-        }
250
-
251
-        //send messages  (this also updates the rate limit)
252
-        $this->execute();
253
-
254
-        //release lock
255
-        $this->unlock_queue(EE_Messages_Queue::action_sending);
256
-        return true;
257
-    }
258
-
259
-
260
-    /**
261
-     * Locks the queue so that no other queues can call the "batch" methods.
262
-     *
263
-     * @param   string $type The type of queue being locked.
264
-     */
265
-    public function lock_queue($type = EE_Messages_Queue::action_generating)
266
-    {
267
-        set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
268
-    }
269
-
270
-
271
-    /**
272
-     * Unlocks the queue so that batch methods can be used.
273
-     *
274
-     * @param   string $type The type of queue being unlocked.
275
-     */
276
-    public function unlock_queue($type = EE_Messages_Queue::action_generating)
277
-    {
278
-        delete_transient($this->_get_lock_key($type));
279
-    }
280
-
281
-
282
-    /**
283
-     * Retrieve the key used for the lock transient.
284
-     *
285
-     * @param string $type The type of lock.
286
-     * @return string
287
-     */
288
-    protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
289
-    {
290
-        return '_ee_lock_' . $type;
291
-    }
292
-
293
-
294
-    /**
295
-     * Retrieve the expiry time for the lock transient.
296
-     *
297
-     * @param string $type The type of lock
298
-     * @return int   time to expiry in seconds.
299
-     */
300
-    protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
301
-    {
302
-        return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
303
-    }
304
-
305
-
306
-    /**
307
-     * Returns the key used for rate limit transient.
308
-     *
309
-     * @return string
310
-     */
311
-    protected function _get_rate_limit_key()
312
-    {
313
-        return '_ee_rate_limit';
314
-    }
315
-
316
-
317
-    /**
318
-     * Returns the rate limit expiry time.
319
-     *
320
-     * @return int
321
-     */
322
-    protected function _get_rate_limit_expiry()
323
-    {
324
-        return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
325
-    }
326
-
327
-
328
-    /**
329
-     * Returns the default rate limit for sending messages.
330
-     *
331
-     * @return int
332
-     */
333
-    protected function _default_rate_limit()
334
-    {
335
-        return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
336
-    }
337
-
338
-
339
-    /**
340
-     * Return the orderby array for priority.
341
-     *
342
-     * @return array
343
-     */
344
-    protected function _get_priority_orderby()
345
-    {
346
-        return array(
347
-            'MSG_priority' => 'ASC',
348
-            'MSG_modified' => 'DESC',
349
-        );
350
-    }
351
-
352
-
353
-    /**
354
-     * Returns whether batch methods are "locked" or not.
355
-     *
356
-     * @param  string $type The type of lock being checked for.
357
-     * @return bool
358
-     */
359
-    public function is_locked($type = EE_Messages_Queue::action_generating)
360
-    {
361
-        /**
362
-         * This filters the default is_locked behaviour.
363
-         */
364
-        $is_locked = filter_var(
365
-            apply_filters(
366
-                'FHEE__EE_Messages_Queue__is_locked',
367
-                get_transient($this->_get_lock_key($type)),
368
-                $this
369
-            ),
370
-            FILTER_VALIDATE_BOOLEAN
371
-        );
372
-
373
-        /**
374
-         * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
375
-         *            Also implemented here because messages processed on the same request should not have any locks applied.
376
-         */
377
-        if (
378
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
379
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
380
-        ) {
381
-            $is_locked = false;
382
-        }
383
-
384
-
385
-        return $is_locked;
386
-    }
387
-
388
-
389
-    /**
390
-     * Retrieves the rate limit that may be cached as a transient.
391
-     * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
392
-     *
393
-     * @return int
394
-     */
395
-    public function get_rate_limit()
396
-    {
397
-        if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
398
-            $rate_limit = $this->_default_rate_limit();
399
-            set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
400
-        }
401
-        return $rate_limit;
402
-    }
403
-
404
-
405
-    /**
406
-     * This updates existing rate limit with the new limit which is the old minus the batch.
407
-     *
408
-     * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
409
-     */
410
-    public function set_rate_limit($batch_completed)
411
-    {
412
-        //first get the most up to date rate limit (in case its expired and reset)
413
-        $rate_limit = $this->get_rate_limit();
414
-        $new_limit  = $rate_limit - $batch_completed;
415
-        //updating the transient option directly to avoid resetting the expiry.
416
-        update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
417
-    }
418
-
419
-
420
-    /**
421
-     * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
422
-     * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
423
-     * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
424
-     * request running on a queue for the given task.
425
-     *
426
-     * @param string $task     This indicates what type of request is going to be initiated.
427
-     * @param int    $priority This indicates the priority that triggers initiating the request.
428
-     */
429
-    public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
430
-    {
431
-        //determine what status is matched with the priority as part of the trigger conditions.
432
-        $status = $task == 'generate'
433
-            ? EEM_Message::status_incomplete
434
-            : EEM_Message::instance()->stati_indicating_to_send();
435
-        // always make sure we save because either this will get executed immediately on a separate request
436
-        // or remains in the queue for the regularly scheduled queue batch.
437
-        $this->save();
438
-        /**
439
-         * This filter/option allows users to override processing of messages on separate requests and instead have everything
440
-         * happen on the same request.  If this is utilized remember:
441
-         * - message priorities don't matter
442
-         * - existing unprocessed messages in the queue will not get processed unless manually triggered.
443
-         * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
444
-         *   processing happening on the same request.
445
-         * - any race condition protection (locks) are removed because they don't apply when things are processed on
446
-         *   the same request.
447
-         */
448
-        if (
449
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
450
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
451
-        ) {
452
-            $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
453
-            if ($messages_processor instanceof EE_Messages_Processor) {
454
-                return $messages_processor->process_immediately_from_queue($this);
455
-            }
456
-            //if we get here then that means the messages processor couldn't be loaded so messages will just remain
457
-            //queued for manual triggering by end user.
458
-        }
459
-
460
-        if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
461
-            EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
462
-        }
463
-    }
464
-
465
-
466
-    /**
467
-     *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
468
-     *
469
-     * @param   bool     $save                    Used to indicate whether to save the message queue after sending
470
-     *                                            (default will save).
471
-     * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
472
-     *                                            what is on the EE_Message object in the queue.
473
-     *                                            For instance, showing the browser view of an email message,
474
-     *                                            or giving a pdf generated view of an html document.
475
-     *                                            This should be an instance of EE_messenger but if you call this
476
-     *                                            method
477
-     *                                            intending it to be a sending messenger but a valid one could not be
478
-     *                                            retrieved then send in an instance of EE_Error that contains the
479
-     *                                            related error message.
480
-     * @param   bool|int $by_priority             When set, this indicates that only messages
481
-     *                                            matching the given priority should be executed.
482
-     * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
483
-     *                                            Also, if the messenger is an request type messenger (or a preview),
484
-     *                                            its entirely possible that the messenger will exit before
485
-     */
486
-    public function execute($save = true, $sending_messenger = null, $by_priority = false)
487
-    {
488
-        $messages_sent   = 0;
489
-        $this->_did_hook = array();
490
-        $this->_message_repository->rewind();
491
-
492
-        while ($this->_message_repository->valid()) {
493
-            $error_messages = array();
494
-            /** @type EE_Message $message */
495
-            $message = $this->_message_repository->current();
496
-            //only process things that are queued for sending
497
-            if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
498
-                $this->_message_repository->next();
499
-                continue;
500
-            }
501
-            //if $by_priority is set and does not match then continue;
502
-            if ($by_priority && $by_priority != $message->priority()) {
503
-                $this->_message_repository->next();
504
-                continue;
505
-            }
506
-            //error checking
507
-            if (! $message->valid_messenger()) {
508
-                $error_messages[] = sprintf(
509
-                    __('The %s messenger is not active at time of sending.', 'event_espresso'),
510
-                    $message->messenger()
511
-                );
512
-            }
513
-            if (! $message->valid_message_type()) {
514
-                $error_messages[] = sprintf(
515
-                    __('The %s message type is not active at the time of sending.', 'event_espresso'),
516
-                    $message->message_type()
517
-                );
518
-            }
519
-            // if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
520
-            // then it will instead be an EE_Error object, so let's check for that
521
-            if ($sending_messenger instanceof EE_Error) {
522
-                $error_messages[] = $sending_messenger->getMessage();
523
-            }
524
-            // if there are no errors, then let's process the message
525
-            if (empty($error_messages)) {
526
-                if ($save) {
527
-                    $message->set_messenger_is_executing();
528
-                }
529
-                if ($this->_process_message($message, $sending_messenger)) {
530
-                    $messages_sent++;
531
-                }
532
-            }
533
-            $this->_set_error_message($message, $error_messages);
534
-            //add modified time
535
-            $message->set_modified(time());
536
-            //we save each message after its processed to make sure its status persists in case PHP times-out or runs
537
-            //out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281
538
-            if ($save) {
539
-                $message->save();
540
-            }
541
-
542
-            $this->_message_repository->next();
543
-        }
544
-        if ($save) {
545
-            $this->save(true);
546
-        }
547
-        return $messages_sent;
548
-    }
549
-
550
-
551
-    /**
552
-     * _process_message
553
-     *
554
-     * @param EE_Message $message
555
-     * @param mixed      $sending_messenger (optional)
556
-     * @return bool
557
-     */
558
-    protected function _process_message(EE_Message $message, $sending_messenger = null)
559
-    {
560
-        // these *should* have been validated in the execute() method above
561
-        $messenger    = $message->messenger_object();
562
-        $message_type = $message->message_type_object();
563
-        //do actions for sending messenger if it differs from generating messenger and swap values.
564
-        if (
565
-            $sending_messenger instanceof EE_messenger
566
-            && $messenger instanceof EE_messenger
567
-            && $sending_messenger->name != $messenger->name
568
-        ) {
569
-            $messenger->do_secondary_messenger_hooks($sending_messenger->name);
570
-            $messenger = $sending_messenger;
571
-        }
572
-        // send using messenger, but double check objects
573
-        if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
574
-            //set hook for message type (but only if not using another messenger to send).
575
-            if ( ! isset($this->_did_hook[$message_type->name])) {
576
-                $message_type->do_messenger_hooks($messenger);
577
-                $this->_did_hook[$message_type->name] = 1;
578
-            }
579
-            //if preview then use preview method
580
-            return $this->_message_repository->is_preview()
581
-                ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
582
-                : $this->_do_send($message, $messenger, $message_type);
583
-        }
584
-        return false;
585
-    }
586
-
587
-
588
-    /**
589
-     * The intention of this method is to count how many EE_Message objects
590
-     * are in the queue with a given status.
591
-     * Example usage:
592
-     * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
593
-     * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
594
-     *
595
-     * @param array|string $status Stati to check for in queue
596
-     * @return int  Count of EE_Message's matching the given status.
597
-     */
598
-    public function count_STS_in_queue($status)
599
-    {
600
-        $count  = 0;
601
-        $status = is_array($status) ? $status : array($status);
602
-        $this->_message_repository->rewind();
603
-        foreach ($this->_message_repository as $message) {
604
-            if (in_array($message->STS_ID(), $status)) {
605
-                $count++;
606
-            }
607
-        }
608
-        return $count;
609
-    }
610
-
611
-
612
-    /**
613
-     * Executes the get_preview method on the provided messenger.
614
-     *
615
-     * @param EE_Message      $message
616
-     * @param EE_messenger    $messenger
617
-     * @param EE_message_type $message_type
618
-     * @param                 $test_send
619
-     * @return bool   true means all went well, false means, not so much.
620
-     */
621
-    protected function _do_preview(
622
-        EE_Message $message,
623
-        EE_messenger $messenger,
624
-        EE_message_type $message_type,
625
-        $test_send
626
-    ) {
627
-        if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
628
-            if ( ! $test_send) {
629
-                $message->set_content($preview);
630
-            }
631
-            $message->set_STS_ID(EEM_Message::status_sent);
632
-            return true;
633
-        } else {
634
-            $message->set_STS_ID(EEM_Message::status_failed);
635
-            return false;
636
-        }
637
-    }
638
-
639
-
640
-    /**
641
-     * Executes the send method on the provided messenger
642
-     * EE_Messengers are expected to:
643
-     * - return true if the send was successful.
644
-     * - return false if the send was unsuccessful but can be tried again.
645
-     * - throw an Exception if the send was unsuccessful and cannot be tried again.
646
-     *
647
-     * @param EE_Message      $message
648
-     * @param EE_messenger    $messenger
649
-     * @param EE_message_type $message_type
650
-     * @return bool true means all went well, false means, not so much.
651
-     */
652
-    protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
653
-    {
654
-        try {
655
-            if ($messenger->send_message($message, $message_type)) {
656
-                $message->set_STS_ID(EEM_Message::status_sent);
657
-                return true;
658
-            } else {
659
-                $message->set_STS_ID(EEM_Message::status_retry);
660
-                return false;
661
-            }
662
-        } catch (SendMessageException $e) {
663
-            $message->set_STS_ID(EEM_Message::status_failed);
664
-            $message->set_error_message($e->getMessage());
665
-            return false;
666
-        }
667
-    }
668
-
669
-
670
-    /**
671
-     * This sets any necessary error messages on the message object and its status to failed.
672
-     *
673
-     * @param EE_Message $message
674
-     * @param array      $error_messages the response from the messenger.
675
-     */
676
-    protected function _set_error_message(EE_Message $message, $error_messages)
677
-    {
678
-        $error_messages = (array)$error_messages;
679
-        if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
680
-            $notices          = EE_Error::has_notices();
681
-            $error_messages[] = __(
682
-                'Messenger and Message Type were valid and active, but the messenger send method failed.',
683
-                'event_espresso'
684
-            );
685
-            if ($notices === 1) {
686
-                $notices           = EE_Error::get_vanilla_notices();
687
-                $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
688
-                $error_messages[]  = implode("\n", $notices['errors']);
689
-            }
690
-        }
691
-        if (count($error_messages) > 0) {
692
-            $msg = __('Message was not executed successfully.', 'event_espresso');
693
-            $msg = $msg . "\n" . implode("\n", $error_messages);
694
-            $message->set_error_message($msg);
695
-        }
696
-    }
21
+	/**
22
+	 * @type    string  reference for sending action
23
+	 */
24
+	const action_sending = 'sending';
25
+
26
+	/**
27
+	 * @type    string  reference for generation action
28
+	 */
29
+	const action_generating = 'generation';
30
+
31
+
32
+	/**
33
+	 * @type EE_Message_Repository $_message_repository
34
+	 */
35
+	protected $_message_repository;
36
+
37
+	/**
38
+	 * Sets the limit of how many messages are generated per process.
39
+	 *
40
+	 * @type int
41
+	 */
42
+	protected $_batch_count;
43
+
44
+	/**
45
+	 * Sets the limit of how many messages can be sent per hour.
46
+	 *
47
+	 * @type int
48
+	 */
49
+	protected $_rate_limit;
50
+
51
+	/**
52
+	 * This is an array of cached queue items being stored in this object.
53
+	 * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
+	 * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
+	 *
56
+	 * @type EE_Message[]
57
+	 */
58
+	protected $_cached_queue_items;
59
+
60
+	/**
61
+	 * Tracks the number of unsaved queue items.
62
+	 *
63
+	 * @type int
64
+	 */
65
+	protected $_unsaved_count = 0;
66
+
67
+	/**
68
+	 * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
+	 * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
+	 *
71
+	 * @type array
72
+	 */
73
+	protected $_did_hook = array();
74
+
75
+
76
+	/**
77
+	 * Constructor.
78
+	 * Setup all the initial properties and load a EE_Message_Repository.
79
+	 *
80
+	 * @param \EE_Message_Repository $message_repository
81
+	 */
82
+	public function __construct(EE_Message_Repository $message_repository)
83
+	{
84
+		$this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
+		$this->_rate_limit         = $this->get_rate_limit();
86
+		$this->_message_repository = $message_repository;
87
+	}
88
+
89
+
90
+	/**
91
+	 * Add a EE_Message object to the queue
92
+	 *
93
+	 * @param EE_Message $message
94
+	 * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
+	 *                                 object is persisted, this data will be saved on an extra_meta object related to
96
+	 *                                 EE_Message.
97
+	 * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
+	 * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
+	 *                                 use the messenger send method but typically is based on preview data.
100
+	 * @return bool          Whether the message was successfully added to the repository or not.
101
+	 */
102
+	public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
+	{
104
+		$data['preview']   = $preview;
105
+		$data['test_send'] = $test_send;
106
+		return $this->_message_repository->add($message, $data);
107
+	}
108
+
109
+
110
+	/**
111
+	 * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
+	 *
113
+	 * @param EE_Message $message The message to detach from the queue
114
+	 * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
+	 * @return bool
116
+	 */
117
+	public function remove(EE_Message $message, $persist = false)
118
+	{
119
+		if ($persist && $this->_message_repository->current() !== $message) {
120
+			//get pointer on right message
121
+			if ($this->_message_repository->has($message)) {
122
+				$this->_message_repository->rewind();
123
+				while ($this->_message_repository->valid()) {
124
+					if ($this->_message_repository->current() === $message) {
125
+						break;
126
+					}
127
+					$this->_message_repository->next();
128
+				}
129
+			} else {
130
+				return false;
131
+			}
132
+		}
133
+		return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
+	}
135
+
136
+
137
+	/**
138
+	 * Persists all queued EE_Message objects to the db.
139
+	 *
140
+	 * @param bool $do_hooks_only       @see EE_Message_Repository::saveAll
141
+	 * @return array @see EE_Messages_Repository::saveAll() for return values.
142
+	 */
143
+	public function save($do_hooks_only = false)
144
+	{
145
+		return $this->_message_repository->saveAll($do_hooks_only);
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return EE_Message_Repository
151
+	 */
152
+	public function get_message_repository()
153
+	{
154
+		return $this->_message_repository;
155
+	}
156
+
157
+
158
+	/**
159
+	 * This does the following things:
160
+	 * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
161
+	 * false).
162
+	 * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
163
+	 * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
164
+	 * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
165
+	 * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
166
+	 * removed.
167
+	 *
168
+	 * @return bool  true if successfully retrieved batch, false no batch ready.
169
+	 */
170
+	public function get_batch_to_generate()
171
+	{
172
+		if ($this->is_locked(EE_Messages_Queue::action_generating)) {
173
+			return false;
174
+		}
175
+
176
+		//lock batch generation to prevent race conditions.
177
+		$this->lock_queue(EE_Messages_Queue::action_generating);
178
+
179
+		$query_args = array(
180
+			// key 0 = where conditions
181
+			0          => array('STS_ID' => EEM_Message::status_incomplete),
182
+			'order_by' => $this->_get_priority_orderby(),
183
+			'limit'    => $this->_batch_count,
184
+		);
185
+		$messages   = EEM_Message::instance()->get_all($query_args);
186
+
187
+		if ( ! $messages) {
188
+			return false; //nothing to generate
189
+		}
190
+
191
+		foreach ($messages as $message) {
192
+			if ($message instanceof EE_Message) {
193
+				$data = $message->all_extra_meta_array();
194
+				$this->add($message, $data);
195
+			}
196
+		}
197
+		return true;
198
+	}
199
+
200
+
201
+	/**
202
+	 * This does the following things:
203
+	 * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
204
+	 * false).
205
+	 * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
206
+	 * return false.
207
+	 * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
208
+	 * 3. On success or unsuccessful send, sets status appropriately.
209
+	 * 4. Saves messages via the queue
210
+	 * 5. Releases lock.
211
+	 *
212
+	 * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
213
+	 *               necessarily mean that all messages were successfully sent.  It just means that this method
214
+	 *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
215
+	 *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
216
+	 *               will also have a saved error message on it to assist with notifying user.
217
+	 */
218
+	public function get_to_send_batch_and_send()
219
+	{
220
+		if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
221
+			return false;
222
+		}
223
+
224
+		$this->lock_queue(EE_Messages_Queue::action_sending);
225
+
226
+		$batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
227
+
228
+		$query_args = array(
229
+			// key 0 = where conditions
230
+			0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
231
+			'order_by' => $this->_get_priority_orderby(),
232
+			'limit'    => $batch,
233
+		);
234
+
235
+		$messages_to_send = EEM_Message::instance()->get_all($query_args);
236
+
237
+
238
+		//any to send?
239
+		if ( ! $messages_to_send) {
240
+			$this->unlock_queue(EE_Messages_Queue::action_sending);
241
+			return false;
242
+		}
243
+
244
+		//add to queue.
245
+		foreach ($messages_to_send as $message) {
246
+			if ($message instanceof EE_Message) {
247
+				$this->add($message);
248
+			}
249
+		}
250
+
251
+		//send messages  (this also updates the rate limit)
252
+		$this->execute();
253
+
254
+		//release lock
255
+		$this->unlock_queue(EE_Messages_Queue::action_sending);
256
+		return true;
257
+	}
258
+
259
+
260
+	/**
261
+	 * Locks the queue so that no other queues can call the "batch" methods.
262
+	 *
263
+	 * @param   string $type The type of queue being locked.
264
+	 */
265
+	public function lock_queue($type = EE_Messages_Queue::action_generating)
266
+	{
267
+		set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
268
+	}
269
+
270
+
271
+	/**
272
+	 * Unlocks the queue so that batch methods can be used.
273
+	 *
274
+	 * @param   string $type The type of queue being unlocked.
275
+	 */
276
+	public function unlock_queue($type = EE_Messages_Queue::action_generating)
277
+	{
278
+		delete_transient($this->_get_lock_key($type));
279
+	}
280
+
281
+
282
+	/**
283
+	 * Retrieve the key used for the lock transient.
284
+	 *
285
+	 * @param string $type The type of lock.
286
+	 * @return string
287
+	 */
288
+	protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
289
+	{
290
+		return '_ee_lock_' . $type;
291
+	}
292
+
293
+
294
+	/**
295
+	 * Retrieve the expiry time for the lock transient.
296
+	 *
297
+	 * @param string $type The type of lock
298
+	 * @return int   time to expiry in seconds.
299
+	 */
300
+	protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
301
+	{
302
+		return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
303
+	}
304
+
305
+
306
+	/**
307
+	 * Returns the key used for rate limit transient.
308
+	 *
309
+	 * @return string
310
+	 */
311
+	protected function _get_rate_limit_key()
312
+	{
313
+		return '_ee_rate_limit';
314
+	}
315
+
316
+
317
+	/**
318
+	 * Returns the rate limit expiry time.
319
+	 *
320
+	 * @return int
321
+	 */
322
+	protected function _get_rate_limit_expiry()
323
+	{
324
+		return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
325
+	}
326
+
327
+
328
+	/**
329
+	 * Returns the default rate limit for sending messages.
330
+	 *
331
+	 * @return int
332
+	 */
333
+	protected function _default_rate_limit()
334
+	{
335
+		return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
336
+	}
337
+
338
+
339
+	/**
340
+	 * Return the orderby array for priority.
341
+	 *
342
+	 * @return array
343
+	 */
344
+	protected function _get_priority_orderby()
345
+	{
346
+		return array(
347
+			'MSG_priority' => 'ASC',
348
+			'MSG_modified' => 'DESC',
349
+		);
350
+	}
351
+
352
+
353
+	/**
354
+	 * Returns whether batch methods are "locked" or not.
355
+	 *
356
+	 * @param  string $type The type of lock being checked for.
357
+	 * @return bool
358
+	 */
359
+	public function is_locked($type = EE_Messages_Queue::action_generating)
360
+	{
361
+		/**
362
+		 * This filters the default is_locked behaviour.
363
+		 */
364
+		$is_locked = filter_var(
365
+			apply_filters(
366
+				'FHEE__EE_Messages_Queue__is_locked',
367
+				get_transient($this->_get_lock_key($type)),
368
+				$this
369
+			),
370
+			FILTER_VALIDATE_BOOLEAN
371
+		);
372
+
373
+		/**
374
+		 * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
375
+		 *            Also implemented here because messages processed on the same request should not have any locks applied.
376
+		 */
377
+		if (
378
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
379
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
380
+		) {
381
+			$is_locked = false;
382
+		}
383
+
384
+
385
+		return $is_locked;
386
+	}
387
+
388
+
389
+	/**
390
+	 * Retrieves the rate limit that may be cached as a transient.
391
+	 * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
392
+	 *
393
+	 * @return int
394
+	 */
395
+	public function get_rate_limit()
396
+	{
397
+		if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
398
+			$rate_limit = $this->_default_rate_limit();
399
+			set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
400
+		}
401
+		return $rate_limit;
402
+	}
403
+
404
+
405
+	/**
406
+	 * This updates existing rate limit with the new limit which is the old minus the batch.
407
+	 *
408
+	 * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
409
+	 */
410
+	public function set_rate_limit($batch_completed)
411
+	{
412
+		//first get the most up to date rate limit (in case its expired and reset)
413
+		$rate_limit = $this->get_rate_limit();
414
+		$new_limit  = $rate_limit - $batch_completed;
415
+		//updating the transient option directly to avoid resetting the expiry.
416
+		update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
417
+	}
418
+
419
+
420
+	/**
421
+	 * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
422
+	 * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
423
+	 * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
424
+	 * request running on a queue for the given task.
425
+	 *
426
+	 * @param string $task     This indicates what type of request is going to be initiated.
427
+	 * @param int    $priority This indicates the priority that triggers initiating the request.
428
+	 */
429
+	public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
430
+	{
431
+		//determine what status is matched with the priority as part of the trigger conditions.
432
+		$status = $task == 'generate'
433
+			? EEM_Message::status_incomplete
434
+			: EEM_Message::instance()->stati_indicating_to_send();
435
+		// always make sure we save because either this will get executed immediately on a separate request
436
+		// or remains in the queue for the regularly scheduled queue batch.
437
+		$this->save();
438
+		/**
439
+		 * This filter/option allows users to override processing of messages on separate requests and instead have everything
440
+		 * happen on the same request.  If this is utilized remember:
441
+		 * - message priorities don't matter
442
+		 * - existing unprocessed messages in the queue will not get processed unless manually triggered.
443
+		 * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
444
+		 *   processing happening on the same request.
445
+		 * - any race condition protection (locks) are removed because they don't apply when things are processed on
446
+		 *   the same request.
447
+		 */
448
+		if (
449
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
450
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
451
+		) {
452
+			$messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
453
+			if ($messages_processor instanceof EE_Messages_Processor) {
454
+				return $messages_processor->process_immediately_from_queue($this);
455
+			}
456
+			//if we get here then that means the messages processor couldn't be loaded so messages will just remain
457
+			//queued for manual triggering by end user.
458
+		}
459
+
460
+		if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
461
+			EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
462
+		}
463
+	}
464
+
465
+
466
+	/**
467
+	 *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
468
+	 *
469
+	 * @param   bool     $save                    Used to indicate whether to save the message queue after sending
470
+	 *                                            (default will save).
471
+	 * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
472
+	 *                                            what is on the EE_Message object in the queue.
473
+	 *                                            For instance, showing the browser view of an email message,
474
+	 *                                            or giving a pdf generated view of an html document.
475
+	 *                                            This should be an instance of EE_messenger but if you call this
476
+	 *                                            method
477
+	 *                                            intending it to be a sending messenger but a valid one could not be
478
+	 *                                            retrieved then send in an instance of EE_Error that contains the
479
+	 *                                            related error message.
480
+	 * @param   bool|int $by_priority             When set, this indicates that only messages
481
+	 *                                            matching the given priority should be executed.
482
+	 * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
483
+	 *                                            Also, if the messenger is an request type messenger (or a preview),
484
+	 *                                            its entirely possible that the messenger will exit before
485
+	 */
486
+	public function execute($save = true, $sending_messenger = null, $by_priority = false)
487
+	{
488
+		$messages_sent   = 0;
489
+		$this->_did_hook = array();
490
+		$this->_message_repository->rewind();
491
+
492
+		while ($this->_message_repository->valid()) {
493
+			$error_messages = array();
494
+			/** @type EE_Message $message */
495
+			$message = $this->_message_repository->current();
496
+			//only process things that are queued for sending
497
+			if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
498
+				$this->_message_repository->next();
499
+				continue;
500
+			}
501
+			//if $by_priority is set and does not match then continue;
502
+			if ($by_priority && $by_priority != $message->priority()) {
503
+				$this->_message_repository->next();
504
+				continue;
505
+			}
506
+			//error checking
507
+			if (! $message->valid_messenger()) {
508
+				$error_messages[] = sprintf(
509
+					__('The %s messenger is not active at time of sending.', 'event_espresso'),
510
+					$message->messenger()
511
+				);
512
+			}
513
+			if (! $message->valid_message_type()) {
514
+				$error_messages[] = sprintf(
515
+					__('The %s message type is not active at the time of sending.', 'event_espresso'),
516
+					$message->message_type()
517
+				);
518
+			}
519
+			// if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
520
+			// then it will instead be an EE_Error object, so let's check for that
521
+			if ($sending_messenger instanceof EE_Error) {
522
+				$error_messages[] = $sending_messenger->getMessage();
523
+			}
524
+			// if there are no errors, then let's process the message
525
+			if (empty($error_messages)) {
526
+				if ($save) {
527
+					$message->set_messenger_is_executing();
528
+				}
529
+				if ($this->_process_message($message, $sending_messenger)) {
530
+					$messages_sent++;
531
+				}
532
+			}
533
+			$this->_set_error_message($message, $error_messages);
534
+			//add modified time
535
+			$message->set_modified(time());
536
+			//we save each message after its processed to make sure its status persists in case PHP times-out or runs
537
+			//out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281
538
+			if ($save) {
539
+				$message->save();
540
+			}
541
+
542
+			$this->_message_repository->next();
543
+		}
544
+		if ($save) {
545
+			$this->save(true);
546
+		}
547
+		return $messages_sent;
548
+	}
549
+
550
+
551
+	/**
552
+	 * _process_message
553
+	 *
554
+	 * @param EE_Message $message
555
+	 * @param mixed      $sending_messenger (optional)
556
+	 * @return bool
557
+	 */
558
+	protected function _process_message(EE_Message $message, $sending_messenger = null)
559
+	{
560
+		// these *should* have been validated in the execute() method above
561
+		$messenger    = $message->messenger_object();
562
+		$message_type = $message->message_type_object();
563
+		//do actions for sending messenger if it differs from generating messenger and swap values.
564
+		if (
565
+			$sending_messenger instanceof EE_messenger
566
+			&& $messenger instanceof EE_messenger
567
+			&& $sending_messenger->name != $messenger->name
568
+		) {
569
+			$messenger->do_secondary_messenger_hooks($sending_messenger->name);
570
+			$messenger = $sending_messenger;
571
+		}
572
+		// send using messenger, but double check objects
573
+		if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
574
+			//set hook for message type (but only if not using another messenger to send).
575
+			if ( ! isset($this->_did_hook[$message_type->name])) {
576
+				$message_type->do_messenger_hooks($messenger);
577
+				$this->_did_hook[$message_type->name] = 1;
578
+			}
579
+			//if preview then use preview method
580
+			return $this->_message_repository->is_preview()
581
+				? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
582
+				: $this->_do_send($message, $messenger, $message_type);
583
+		}
584
+		return false;
585
+	}
586
+
587
+
588
+	/**
589
+	 * The intention of this method is to count how many EE_Message objects
590
+	 * are in the queue with a given status.
591
+	 * Example usage:
592
+	 * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
593
+	 * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
594
+	 *
595
+	 * @param array|string $status Stati to check for in queue
596
+	 * @return int  Count of EE_Message's matching the given status.
597
+	 */
598
+	public function count_STS_in_queue($status)
599
+	{
600
+		$count  = 0;
601
+		$status = is_array($status) ? $status : array($status);
602
+		$this->_message_repository->rewind();
603
+		foreach ($this->_message_repository as $message) {
604
+			if (in_array($message->STS_ID(), $status)) {
605
+				$count++;
606
+			}
607
+		}
608
+		return $count;
609
+	}
610
+
611
+
612
+	/**
613
+	 * Executes the get_preview method on the provided messenger.
614
+	 *
615
+	 * @param EE_Message      $message
616
+	 * @param EE_messenger    $messenger
617
+	 * @param EE_message_type $message_type
618
+	 * @param                 $test_send
619
+	 * @return bool   true means all went well, false means, not so much.
620
+	 */
621
+	protected function _do_preview(
622
+		EE_Message $message,
623
+		EE_messenger $messenger,
624
+		EE_message_type $message_type,
625
+		$test_send
626
+	) {
627
+		if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
628
+			if ( ! $test_send) {
629
+				$message->set_content($preview);
630
+			}
631
+			$message->set_STS_ID(EEM_Message::status_sent);
632
+			return true;
633
+		} else {
634
+			$message->set_STS_ID(EEM_Message::status_failed);
635
+			return false;
636
+		}
637
+	}
638
+
639
+
640
+	/**
641
+	 * Executes the send method on the provided messenger
642
+	 * EE_Messengers are expected to:
643
+	 * - return true if the send was successful.
644
+	 * - return false if the send was unsuccessful but can be tried again.
645
+	 * - throw an Exception if the send was unsuccessful and cannot be tried again.
646
+	 *
647
+	 * @param EE_Message      $message
648
+	 * @param EE_messenger    $messenger
649
+	 * @param EE_message_type $message_type
650
+	 * @return bool true means all went well, false means, not so much.
651
+	 */
652
+	protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
653
+	{
654
+		try {
655
+			if ($messenger->send_message($message, $message_type)) {
656
+				$message->set_STS_ID(EEM_Message::status_sent);
657
+				return true;
658
+			} else {
659
+				$message->set_STS_ID(EEM_Message::status_retry);
660
+				return false;
661
+			}
662
+		} catch (SendMessageException $e) {
663
+			$message->set_STS_ID(EEM_Message::status_failed);
664
+			$message->set_error_message($e->getMessage());
665
+			return false;
666
+		}
667
+	}
668
+
669
+
670
+	/**
671
+	 * This sets any necessary error messages on the message object and its status to failed.
672
+	 *
673
+	 * @param EE_Message $message
674
+	 * @param array      $error_messages the response from the messenger.
675
+	 */
676
+	protected function _set_error_message(EE_Message $message, $error_messages)
677
+	{
678
+		$error_messages = (array)$error_messages;
679
+		if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
680
+			$notices          = EE_Error::has_notices();
681
+			$error_messages[] = __(
682
+				'Messenger and Message Type were valid and active, but the messenger send method failed.',
683
+				'event_espresso'
684
+			);
685
+			if ($notices === 1) {
686
+				$notices           = EE_Error::get_vanilla_notices();
687
+				$notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
688
+				$error_messages[]  = implode("\n", $notices['errors']);
689
+			}
690
+		}
691
+		if (count($error_messages) > 0) {
692
+			$msg = __('Message was not executed successfully.', 'event_espresso');
693
+			$msg = $msg . "\n" . implode("\n", $error_messages);
694
+			$message->set_error_message($msg);
695
+		}
696
+	}
697 697
 
698 698
 } //end EE_Messages_Queue class
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Processor.lib.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -560,10 +560,10 @@
 block discarded – undo
560 560
 
561 561
 		foreach ( $regs_to_send as $status_group ) {
562 562
 			foreach ( $status_group as $status_id => $registrations ) {
563
-			    $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
564
-			    if (! $message_type) {
565
-			        continue;
566
-                }
563
+				$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
564
+				if (! $message_type) {
565
+					continue;
566
+				}
567 567
 				$messages_to_generate = array_merge(
568 568
 					$messages_to_generate,
569 569
 					$this->setup_mtgs_for_all_active_messengers(
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param EE_Message_Resource_Manager $message_resource_manager
37 37
 	 */
38
-	public function __construct( EE_Message_Resource_Manager $message_resource_manager ) {
38
+	public function __construct(EE_Message_Resource_Manager $message_resource_manager) {
39 39
 		$this->_message_resource_manager = $message_resource_manager;
40 40
 		$this->_init_queue_and_generator();
41 41
 	}
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * - $_generator = holds the messages generator
51 51
 	 */
52 52
 	protected function _init_queue_and_generator() {
53
-		$this->_generator = EE_Registry::factory( 'EE_Messages_Generator' );
53
+		$this->_generator = EE_Registry::factory('EE_Messages_Generator');
54 54
 		$this->_queue = $this->_generator->generation_queue();
55 55
 	}
56 56
 
@@ -75,31 +75,31 @@  discard block
 block discarded – undo
75 75
 	 * @param EE_Messages_Queue $queue_to_process
76 76
 	 * @return bool  true for success false for error.
77 77
 	 */
78
-	public function process_immediately_from_queue( EE_Messages_Queue $queue_to_process ) {
78
+	public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) {
79 79
 		$success = false;
80 80
 		$messages_to_send = array();
81 81
 		$messages_to_generate = array();
82 82
 		//loop through and setup the various messages from the queue so we know what is being processed
83 83
 		$queue_to_process->get_message_repository()->rewind();
84
-		foreach ( $queue_to_process->get_message_repository() as $message ) {
85
-			if ( $message->STS_ID() === EEM_Message::status_incomplete ) {
84
+		foreach ($queue_to_process->get_message_repository() as $message) {
85
+			if ($message->STS_ID() === EEM_Message::status_incomplete) {
86 86
 				$messages_to_generate[] = $message;
87 87
 				continue;
88 88
 			}
89 89
 
90
-			if ( in_array( $message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send() ) ) {
90
+			if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
91 91
 				$messages_to_send[] = $message;
92 92
 				continue;
93 93
 			}
94 94
 		}
95 95
 
96 96
 		//do generation/sends
97
-		if ( $messages_to_generate ) {
98
-			$success = $this->batch_generate_from_queue( $messages_to_generate, true );
97
+		if ($messages_to_generate) {
98
+			$success = $this->batch_generate_from_queue($messages_to_generate, true);
99 99
 		}
100 100
 
101
-		if ( $messages_to_send ) {
102
-			$sent = $this->batch_send_from_queue( $messages_to_send, true );
101
+		if ($messages_to_send) {
102
+			$sent = $this->batch_send_from_queue($messages_to_send, true);
103 103
 			//if there was messages to generate and it failed, then we override any success value for the sending process
104 104
 			//otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
105 105
 			//Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 	 * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
120 120
 	 *                                   generated messages.
121 121
 	 */
122
-	public function batch_generate_from_queue( $messages = array(), $clear_queue = false ) {
123
-		if ( $this->_build_queue_for_generation( $messages, $clear_queue ) ) {
122
+	public function batch_generate_from_queue($messages = array(), $clear_queue = false) {
123
+		if ($this->_build_queue_for_generation($messages, $clear_queue)) {
124 124
 			$new_queue = $this->_generator->generate();
125
-			if ( $new_queue instanceof EE_Messages_Queue ) {
125
+			if ($new_queue instanceof EE_Messages_Queue) {
126 126
 				//unlock queue
127 127
 				$this->_queue->unlock_queue();
128
-				$new_queue->initiate_request_by_priority( 'send' );
128
+				$new_queue->initiate_request_by_priority('send');
129 129
 				return $new_queue;
130 130
 			}
131 131
 		}
@@ -146,24 +146,24 @@  discard block
 block discarded – undo
146 146
 	 *
147 147
 	 * @return bool true means queue prepped, false means there was a lock so no generation please.
148 148
 	 */
149
-	protected function _build_queue_for_generation( $messages = array(), $clear_queue = false ) {
149
+	protected function _build_queue_for_generation($messages = array(), $clear_queue = false) {
150 150
 
151
-		if ( $clear_queue ) {
151
+		if ($clear_queue) {
152 152
 			$this->_init_queue_and_generator();
153 153
 		}
154 154
 
155
-		if ( $messages ) {
155
+		if ($messages) {
156 156
 			//if generation is locked then get out now because that means processing is already happening.
157
-			if ( $this->_queue->is_locked() ) {
157
+			if ($this->_queue->is_locked()) {
158 158
 				return false;
159 159
 			}
160 160
 
161 161
 			$this->_queue->lock_queue();
162
-			$messages = is_array( $messages ) ? $messages : array( $messages );
163
-			foreach ( $messages as $message ) {
164
-				if ( $message instanceof EE_Message ) {
162
+			$messages = is_array($messages) ? $messages : array($messages);
163
+			foreach ($messages as $message) {
164
+				if ($message instanceof EE_Message) {
165 165
 					$data = $message->all_extra_meta_array();
166
-					$this->_queue->add( $message, $data );
166
+					$this->_queue->add($message, $data);
167 167
 				}
168 168
 			}
169 169
 			return true;
@@ -181,22 +181,22 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return bool true means queue prepped, false means there was a lock so no queue prepped.
183 183
 	 */
184
-	protected function _build_queue_for_sending( $messages, $clear_queue = false ) {
184
+	protected function _build_queue_for_sending($messages, $clear_queue = false) {
185 185
 		//if sending is locked then get out now because that means processing is already happening.
186
-		if ( $this->_queue->is_locked( EE_Messages_Queue::action_sending ) ) {
186
+		if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
187 187
 			return false;
188 188
 		}
189 189
 
190
-		$this->_queue->lock_queue( EE_Messages_Queue::action_sending );
190
+		$this->_queue->lock_queue(EE_Messages_Queue::action_sending);
191 191
 
192
-		if ( $clear_queue ) {
192
+		if ($clear_queue) {
193 193
 			$this->_init_queue_and_generator();
194 194
 		}
195 195
 
196
-		$messages = is_array( $messages ) ? $messages : array( $messages );
196
+		$messages = is_array($messages) ? $messages : array($messages);
197 197
 
198
-		foreach ( $messages as $message ) {
199
-			$this->_queue->add( $message );
198
+		foreach ($messages as $message) {
199
+			$this->_queue->add($message);
200 200
 		}
201 201
 		return true;
202 202
 	}
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return EE_Messages_Queue
214 214
 	 */
215
-	public function batch_send_from_queue( $messages = array(), $clear_queue = false ) {
215
+	public function batch_send_from_queue($messages = array(), $clear_queue = false) {
216 216
 
217
-		if ( $messages && $this->_build_queue_for_sending( $messages, $clear_queue ) ) {
217
+		if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
218 218
 			$this->_queue->execute();
219
-			$this->_queue->unlock_queue( EE_Messages_Queue::action_sending );
219
+			$this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
220 220
 		} else {
221 221
 			//get messages to send and execute.
222 222
 			$this->_queue->get_to_send_batch_and_send();
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
 	 * @param EE_Message_To_Generate[] $messages_to_generate
240 240
 	 * @return EE_Messages_Queue
241 241
 	 */
242
-	public function generate_and_return(  $messages_to_generate ) {
242
+	public function generate_and_return($messages_to_generate) {
243 243
 		$this->_init_queue_and_generator();
244
-		$this->_queue_for_generation_loop( $messages_to_generate );
245
-		return $this->_generator->generate( false );
244
+		$this->_queue_for_generation_loop($messages_to_generate);
245
+		return $this->_generator->generate(false);
246 246
 	}
247 247
 
248 248
 
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 	 * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
254 254
 	 * @return EE_Messages_Queue
255 255
 	 */
256
-	public function generate_queue( $persist = true ) {
257
-		return $this->_generator->generate( $persist );
256
+	public function generate_queue($persist = true) {
257
+		return $this->_generator->generate($persist);
258 258
 	}
259 259
 
260 260
 
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 	 * @param bool                   $test_send             Whether this item is for a test send or not.
268 268
 	 * @return  EE_Messages_Queue
269 269
 	 */
270
-	public function queue_for_generation( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
271
-		if ( $message_to_generate->valid() ) {
272
-			$this->_generator->create_and_add_message_to_queue( $message_to_generate, $test_send );
270
+	public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) {
271
+		if ($message_to_generate->valid()) {
272
+			$this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
273 273
 		}
274 274
 	}
275 275
 
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 	 *
286 286
 	 * @param EE_Message_To_Generate[] $messages_to_generate
287 287
 	 */
288
-	public function batch_queue_for_generation_and_persist( $messages_to_generate ) {
288
+	public function batch_queue_for_generation_and_persist($messages_to_generate) {
289 289
 		$this->_init_queue_and_generator();
290
-		$this->_queue_for_generation_loop( $messages_to_generate );
290
+		$this->_queue_for_generation_loop($messages_to_generate);
291 291
 		$this->_queue->save();
292 292
 	}
293 293
 
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param EE_Message_To_Generate[]  $messages_to_generate
305 305
 	 */
306
-	public function batch_queue_for_generation_no_persist( $messages_to_generate ) {
306
+	public function batch_queue_for_generation_no_persist($messages_to_generate) {
307 307
 		$this->_init_queue_and_generator();
308
-		$this->_queue_for_generation_loop( $messages_to_generate );
308
+		$this->_queue_for_generation_loop($messages_to_generate);
309 309
 	}
310 310
 
311 311
 
@@ -317,15 +317,15 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @param EE_Message_To_Generate[] $messages_to_generate
319 319
 	 */
320
-	protected function _queue_for_generation_loop( $messages_to_generate ) {
320
+	protected function _queue_for_generation_loop($messages_to_generate) {
321 321
 		//make sure is in an array.
322
-		if ( ! is_array( $messages_to_generate ) ) {
323
-			$messages_to_generate = array( $messages_to_generate );
322
+		if ( ! is_array($messages_to_generate)) {
323
+			$messages_to_generate = array($messages_to_generate);
324 324
 		}
325 325
 
326
-		foreach ( $messages_to_generate as $message_to_generate ) {
327
-			if ( $message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid() ) {
328
-				$this->queue_for_generation( $message_to_generate );
326
+		foreach ($messages_to_generate as $message_to_generate) {
327
+			if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
328
+				$this->queue_for_generation($message_to_generate);
329 329
 			}
330 330
 		}
331 331
 	}
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 	 * @param  EE_Message_To_Generate[]
341 341
 	 * @return EE_Messages_Queue
342 342
 	 */
343
-	public function generate_and_queue_for_sending( $messages_to_generate ) {
343
+	public function generate_and_queue_for_sending($messages_to_generate) {
344 344
 		$this->_init_queue_and_generator();
345
-		$this->_queue_for_generation_loop( $messages_to_generate );
346
-		return $this->_generator->generate( true );
345
+		$this->_queue_for_generation_loop($messages_to_generate);
346
+		return $this->_generator->generate(true);
347 347
 	}
348 348
 
349 349
 
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	 * @param   bool                   $test_send                Whether this is a test send or not.
358 358
 	 * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
359 359
 	 */
360
-	public function generate_for_preview( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
361
-		if ( ! $message_to_generate->valid() ) {
360
+	public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) {
361
+		if ( ! $message_to_generate->valid()) {
362 362
 			EE_Error::add_error(
363
-				__( 'Unable to generate preview because of invalid data', 'event_espresso' ),
363
+				__('Unable to generate preview because of invalid data', 'event_espresso'),
364 364
 				__FILE__,
365 365
 				__FUNCTION__,
366 366
 				__LINE__
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 			return false;
369 369
 		}
370 370
 		//just make sure preview is set on the $message_to_generate (in case client forgot)
371
-		$message_to_generate->set_preview( true );
371
+		$message_to_generate->set_preview(true);
372 372
 		$this->_init_queue_and_generator();
373
-		$this->queue_for_generation( $message_to_generate, $test_send );
374
-		$generated_queue = $this->_generator->generate( false );
375
-		if ( $generated_queue->execute( false ) ) {
373
+		$this->queue_for_generation($message_to_generate, $test_send);
374
+		$generated_queue = $this->_generator->generate(false);
375
+		if ($generated_queue->execute(false)) {
376 376
 			//the first queue item should be the preview
377 377
 			$generated_queue->get_message_repository()->rewind();
378
-			if ( ! $generated_queue->get_message_repository()->valid() ) {
378
+			if ( ! $generated_queue->get_message_repository()->valid()) {
379 379
 				return $generated_queue;
380 380
 			}
381 381
 			return $generated_queue;
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
 	 * @param EE_Message_To_Generate $message_to_generate
393 393
 	 * @return bool true or false for success.
394 394
 	 */
395
-	public function queue_for_sending( EE_Message_To_Generate $message_to_generate ) {
396
-		if ( ! $message_to_generate->valid() ) {
395
+	public function queue_for_sending(EE_Message_To_Generate $message_to_generate) {
396
+		if ( ! $message_to_generate->valid()) {
397 397
 			return false;
398 398
 		}
399 399
 		$this->_init_queue_and_generator();
400 400
 		$message = $message_to_generate->get_EE_Message();
401
-		$this->_queue->add( $message );
402
-		if ( $message->send_now() ) {
403
-			$this->_queue->execute( false );
401
+		$this->_queue->add($message);
402
+		if ($message->send_now()) {
403
+			$this->_queue->execute(false);
404 404
 		} else {
405 405
 			$this->_queue->save();
406 406
 		}
@@ -413,12 +413,12 @@  discard block
 block discarded – undo
413 413
 	 * @param EE_Message_To_Generate $message_to_generate
414 414
 	 * @return EE_Messages_Queue | null
415 415
 	 */
416
-	public function generate_and_send_now( EE_Message_To_Generate $message_to_generate ) {
417
-		if ( ! $message_to_generate->valid() ) {
416
+	public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) {
417
+		if ( ! $message_to_generate->valid()) {
418 418
 			return null;
419 419
 		}
420 420
 		// is there supposed to be a sending messenger for this message?
421
-		if ( $message_to_generate instanceof EEI_Has_Sending_Messenger ) {
421
+		if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
422 422
 			// make sure it's valid, but if it's not,
423 423
 			// then set the value of $sending_messenger to an EE_Error object
424 424
 			// so that downstream code can easily see that things went wrong.
@@ -434,14 +434,14 @@  discard block
 block discarded – undo
434 434
 			$sending_messenger = null;
435 435
 		}
436 436
 
437
-		if ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle ) {
437
+		if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
438 438
 			$this->_init_queue_and_generator();
439
-			$this->_queue->add( $message_to_generate->get_EE_Message() );
440
-			$this->_queue->execute( false, $sending_messenger );
439
+			$this->_queue->add($message_to_generate->get_EE_Message());
440
+			$this->_queue->execute(false, $sending_messenger);
441 441
 			return $this->_queue;
442
-		} elseif ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete ) {
443
-			$generated_queue = $this->generate_and_return( array( $message_to_generate ) );
444
-			$generated_queue->execute( false, $sending_messenger );
442
+		} elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
443
+			$generated_queue = $this->generate_and_return(array($message_to_generate));
444
+			$generated_queue->execute(false, $sending_messenger);
445 445
 			return $generated_queue;
446 446
 		}
447 447
 		return null;
@@ -458,13 +458,13 @@  discard block
 block discarded – undo
458 458
 	 * @param mixed  $data   The data being used for generation.
459 459
 	 * @param bool   $persist   Whether to persist the queued messages to the db or not.
460 460
 	 */
461
-	public function generate_for_all_active_messengers( $message_type, $data, $persist = true ) {
462
-		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers( $message_type, $data );
463
-		if ( $persist ) {
464
-			$this->batch_queue_for_generation_and_persist( $messages_to_generate );
461
+	public function generate_for_all_active_messengers($message_type, $data, $persist = true) {
462
+		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
463
+		if ($persist) {
464
+			$this->batch_queue_for_generation_and_persist($messages_to_generate);
465 465
 			$this->_queue->initiate_request_by_priority();
466 466
 		} else {
467
-			$this->batch_queue_for_generation_no_persist( $messages_to_generate );
467
+			$this->batch_queue_for_generation_no_persist($messages_to_generate);
468 468
 		}
469 469
 	}
470 470
 
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
 	 *
480 480
 	 * @return EE_Message_To_Generate[]
481 481
 	 */
482
-	public function setup_mtgs_for_all_active_messengers( $message_type, $data ) {
482
+	public function setup_mtgs_for_all_active_messengers($message_type, $data) {
483 483
 		$messages_to_generate = array();
484
-		foreach ( $this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object  ) {
485
-			$message_to_generate = new EE_Message_To_Generate( $messenger_slug, $message_type, $data );
486
-			if ( $message_to_generate->valid() ) {
484
+		foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
485
+			$message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
486
+			if ($message_to_generate->valid()) {
487 487
 				$messages_to_generate[] = $message_to_generate;
488 488
 			}
489 489
 		}
@@ -498,29 +498,29 @@  discard block
 block discarded – undo
498 498
 	 * and send.
499 499
 	 * @param array $message_ids
500 500
 	 */
501
-	public function setup_messages_from_ids_and_send( $message_ids ) {
501
+	public function setup_messages_from_ids_and_send($message_ids) {
502 502
 		$this->_init_queue_and_generator();
503
-		$messages = EEM_Message::instance()->get_all( array(
503
+		$messages = EEM_Message::instance()->get_all(array(
504 504
 			array(
505
-				'MSG_ID' => array( 'IN', $message_ids ),
505
+				'MSG_ID' => array('IN', $message_ids),
506 506
 				'STS_ID' => array(
507 507
 					'IN',
508 508
 					array_merge(
509 509
 						EEM_Message::instance()->stati_indicating_sent(),
510
-						array( EEM_Message::status_retry )
510
+						array(EEM_Message::status_retry)
511 511
 					),
512 512
 				),
513 513
 			),
514 514
 		));
515 515
 		//set the Messages to resend.
516
-		foreach ( $messages as $message ) {
517
-			if ( $message instanceof EE_Message ) {
518
-				$message->set_STS_ID( EEM_Message::status_resend );
519
-				$this->_queue->add( $message );
516
+		foreach ($messages as $message) {
517
+			if ($message instanceof EE_Message) {
518
+				$message->set_STS_ID(EEM_Message::status_resend);
519
+				$this->_queue->add($message);
520 520
 			}
521 521
 		}
522 522
 
523
-		$this->_queue->initiate_request_by_priority( 'send' );
523
+		$this->_queue->initiate_request_by_priority('send');
524 524
 	}
525 525
 
526 526
 
@@ -534,23 +534,23 @@  discard block
 block discarded – undo
534 534
 	 *
535 535
 	 * @return EE_Message_To_Generate[]
536 536
 	 */
537
-	public function setup_messages_to_generate_from_registration_ids_in_request( $registration_ids_key = '_REG_ID' ) {
538
-		EE_Registry::instance()->load_core( 'Request_Handler' );
539
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
537
+	public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') {
538
+		EE_Registry::instance()->load_core('Request_Handler');
539
+		EE_Registry::instance()->load_helper('MSG_Template');
540 540
 		$regs_to_send = array();
541
-		$regIDs = EE_Registry::instance()->REQ->get( $registration_ids_key );
542
-		if ( empty( $regIDs ) ) {
543
-			EE_Error::add_error( __('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
541
+		$regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
542
+		if (empty($regIDs)) {
543
+			EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
544 544
 			return false;
545 545
 		}
546 546
 
547 547
 		//make sure is an array
548
-		$regIDs = is_array( $regIDs ) ? $regIDs : array( $regIDs );
548
+		$regIDs = is_array($regIDs) ? $regIDs : array($regIDs);
549 549
 
550
-		foreach( $regIDs as $regID ) {
551
-			$reg = EEM_Registration::instance()->get_one_by_ID( $regID );
552
-			if ( ! $reg instanceof EE_Registration ) {
553
-				EE_Error::add_error( sprintf( __('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID ) );
550
+		foreach ($regIDs as $regID) {
551
+			$reg = EEM_Registration::instance()->get_one_by_ID($regID);
552
+			if ( ! $reg instanceof EE_Registration) {
553
+				EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
554 554
 				return false;
555 555
 			}
556 556
 			$regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
@@ -558,17 +558,17 @@  discard block
 block discarded – undo
558 558
 
559 559
 		$messages_to_generate = array();
560 560
 
561
-		foreach ( $regs_to_send as $status_group ) {
562
-			foreach ( $status_group as $status_id => $registrations ) {
561
+		foreach ($regs_to_send as $status_group) {
562
+			foreach ($status_group as $status_id => $registrations) {
563 563
 			    $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
564
-			    if (! $message_type) {
564
+			    if ( ! $message_type) {
565 565
 			        continue;
566 566
                 }
567 567
 				$messages_to_generate = array_merge(
568 568
 					$messages_to_generate,
569 569
 					$this->setup_mtgs_for_all_active_messengers(
570 570
 						$message_type,
571
-						array( $registrations, $status_id )
571
+						array($registrations, $status_id)
572 572
 					)
573 573
 				);
574 574
 			}
Please login to merge, or discard this patch.
core/domain/entities/Context.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -18,64 +18,64 @@
 block discarded – undo
18 18
 class Context
19 19
 {
20 20
 
21
-    /**
22
-     * @var string $slug
23
-     */
24
-    private $slug;
25
-
26
-    /**
27
-     * @var string $description
28
-     */
29
-    private $description;
30
-
31
-
32
-    /**
33
-     * Context constructor.
34
-     *
35
-     * @param string $slug
36
-     * @param string $description
37
-     */
38
-    public function __construct($slug, $description)
39
-    {
40
-        $this->setSlug($slug);
41
-        $this->setDescription($description);
42
-    }
43
-
44
-
45
-    /**
46
-     * @return string
47
-     */
48
-    public function slug()
49
-    {
50
-        return $this->slug;
51
-    }
52
-
53
-
54
-    /**
55
-     * @param string $slug
56
-     */
57
-    private function setSlug($slug)
58
-    {
59
-        $this->slug = sanitize_key($slug);
60
-    }
61
-
62
-
63
-    /**
64
-     * @return string
65
-     */
66
-    public function description()
67
-    {
68
-        return $this->description;
69
-    }
70
-
71
-
72
-    /**
73
-     * @param string $description
74
-     */
75
-    private function setDescription($description)
76
-    {
77
-        $this->description = sanitize_text_field($description);
78
-    }
21
+	/**
22
+	 * @var string $slug
23
+	 */
24
+	private $slug;
25
+
26
+	/**
27
+	 * @var string $description
28
+	 */
29
+	private $description;
30
+
31
+
32
+	/**
33
+	 * Context constructor.
34
+	 *
35
+	 * @param string $slug
36
+	 * @param string $description
37
+	 */
38
+	public function __construct($slug, $description)
39
+	{
40
+		$this->setSlug($slug);
41
+		$this->setDescription($description);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @return string
47
+	 */
48
+	public function slug()
49
+	{
50
+		return $this->slug;
51
+	}
52
+
53
+
54
+	/**
55
+	 * @param string $slug
56
+	 */
57
+	private function setSlug($slug)
58
+	{
59
+		$this->slug = sanitize_key($slug);
60
+	}
61
+
62
+
63
+	/**
64
+	 * @return string
65
+	 */
66
+	public function description()
67
+	{
68
+		return $this->description;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param string $description
74
+	 */
75
+	private function setDescription($description)
76
+	{
77
+		$this->description = sanitize_text_field($description);
78
+	}
79 79
 
80 80
 }
81 81
 // Location: Context.php
Please login to merge, or discard this patch.