Completed
Branch decaf-fixes/replace-request-ha... (dd0ac0)
by
unknown
04:45 queued 03:02
created
core/EE_Maintenance_Mode.core.php 2 patches
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -16,335 +16,335 @@
 block discarded – undo
16 16
 class EE_Maintenance_Mode implements ResettableInterface
17 17
 {
18 18
 
19
-    /**
20
-     * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
21
-     * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
22
-     */
23
-    const level_0_not_in_maintenance = 0;
24
-
25
-    /**
26
-     * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
27
-     * but the admin backend should be running as normal. Maybe an admin can view the frontend though
28
-     */
29
-    const level_1_frontend_only_maintenance = 1;
30
-
31
-    /**
32
-     * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
33
-     * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
34
-     * migration scripts before taking the site out of maintenance mode
35
-     */
36
-    const level_2_complete_maintenance = 2;
37
-
38
-    /**
39
-     * the name of the option which stores the current level of maintenance mode
40
-     */
41
-    const option_name_maintenance_mode = 'ee_maintenance_mode';
42
-
43
-
44
-    /**
45
-     * @var EE_Maintenance_Mode $_instance
46
-     */
47
-    private static $_instance;
48
-
49
-    /**
50
-     * @var EE_Registry $EE
51
-     */
52
-    protected $EE;
53
-
54
-
55
-    /**
56
-     * @singleton method used to instantiate class object
57
-     * @return EE_Maintenance_Mode
58
-     */
59
-    public static function instance()
60
-    {
61
-        // check if class object is instantiated
62
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
63
-            self::$_instance = new self();
64
-        }
65
-        return self::$_instance;
66
-    }
67
-
68
-
69
-    /**
70
-     * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
71
-     *
72
-     * @return EE_Maintenance_Mode
73
-     */
74
-    public static function reset()
75
-    {
76
-        self::instance()->set_maintenance_mode_if_db_old();
77
-        return self::instance();
78
-    }
79
-
80
-
81
-    /**
82
-     *private constructor to prevent direct creation
83
-     */
84
-    private function __construct()
85
-    {
86
-        // if M-Mode level 2 is engaged, we still need basic assets loaded
87
-        add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
88
-        // shut 'er down down for maintenance ?
89
-        add_filter('the_content', array($this, 'the_content'), 2);
90
-        // add powered by EE msg
91
-        add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
92
-    }
93
-
94
-
95
-    /**
96
-     * retrieves the maintenance mode option value from the db
97
-     *
98
-     * @return int
99
-     */
100
-    public function real_level()
101
-    {
102
-        return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
103
-    }
104
-
105
-
106
-    /**
107
-     * Returns whether or not the models reportedly are able to run queries or not
108
-     * (ie, if the system thinks their tables are present and up-to-date).
109
-     *
110
-     * @return boolean
111
-     */
112
-    public function models_can_query()
113
-    {
114
-        return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
115
-    }
116
-
117
-
118
-    /**
119
-     * Determines whether or not we're in maintenance mode and what level. However, while the site
120
-     * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
121
-     * to them as if teh site isn't in maintenance mode.
122
-     * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
123
-     * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
124
-     * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
125
-     *
126
-     * @return int
127
-     */
128
-    public function level()
129
-    {
130
-        $maintenance_mode_level = $this->real_level();
131
-        // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
132
-        if ($maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
133
-            && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
134
-            && current_user_can('administrator') // when the user is an admin
135
-        ) {
136
-            $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
137
-        }
138
-        return $maintenance_mode_level;
139
-    }
140
-
141
-
142
-    /**
143
-     * Determines if we need to put EE in maintenance mode because the database needs updating
144
-     *
145
-     * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
146
-     */
147
-    public function set_maintenance_mode_if_db_old()
148
-    {
149
-        LoaderFactory::getLoader()->getShared('Data_Migration_Manager');
150
-        if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
151
-            update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
152
-            return true;
153
-        }
154
-        if ($this->level() === self::level_2_complete_maintenance) {
155
-            // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
156
-            // then we shouldn't be in mm2. (Maybe an addon got deactivated?)
157
-            update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
158
-            return false;
159
-        }
160
-        return false;
161
-    }
162
-
163
-
164
-    /**
165
-     * Updates the maintenance level on the site
166
-     *
167
-     * @param int $level
168
-     * @return void
169
-     */
170
-    public function set_maintenance_level($level)
171
-    {
172
-        do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
173
-        update_option(self::option_name_maintenance_mode, (int) $level);
174
-    }
175
-
176
-
177
-    /**
178
-     * returns TRUE if M-Mode is engaged and the current request is not for the admin
179
-     *
180
-     * @return bool
181
-     */
182
-    public static function disable_frontend_for_maintenance()
183
-    {
184
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
185
-    }
186
-
187
-
188
-    /**
189
-     * @return void
190
-     */
191
-    public function load_assets_required_for_m_mode()
192
-    {
193
-        if ($this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
194
-            && ! wp_script_is('espresso_core')
195
-        ) {
196
-            wp_register_style(
197
-                'espresso_default',
198
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
199
-                array('dashicons'),
200
-                EVENT_ESPRESSO_VERSION
201
-            );
202
-            wp_enqueue_style('espresso_default');
203
-            wp_register_script(
204
-                'espresso_core',
205
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
206
-                array('jquery'),
207
-                EVENT_ESPRESSO_VERSION,
208
-                true
209
-            );
210
-            wp_enqueue_script('espresso_core');
211
-        }
212
-    }
213
-
214
-
215
-    /**
216
-     * replacement EE CPT template that displays message notifying site visitors
217
-     * that EE has been temporarily placed into maintenance mode
218
-     * does NOT get called on non-EE-CPT requests
219
-     *
220
-     * @return    string
221
-     */
222
-    public static function template_include()
223
-    {
224
-        // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
225
-        return get_template_directory() . '/index.php';
226
-    }
227
-
228
-
229
-    /**
230
-     * displays message notifying site visitors that EE has been temporarily
231
-     * placed into maintenance mode when post_type != EE CPT
232
-     *
233
-     * @param string $the_content
234
-     * @return string
235
-     */
236
-    public function the_content($the_content)
237
-    {
238
-        // check if M-mode is engaged and for EE shortcode
239
-        if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
240
-            // this can eventually be moved to a template, or edited via admin. But for now...
241
-            $the_content = sprintf(
242
-                esc_html__(
243
-                    '%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',
244
-                    'event_espresso'
245
-                ),
246
-                '<h3>',
247
-                '</h3><p>',
248
-                '</p>'
249
-            );
250
-        }
251
-        return $the_content;
252
-    }
253
-
254
-
255
-    /**
256
-     * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
257
-     */
258
-    public function display_maintenance_mode_notice()
259
-    {
260
-        /** @var CurrentPage $current_page */
261
-        $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
262
-        // check if M-mode is engaged and for EE shortcode
263
-        if (! (defined('DOING_AJAX') && DOING_AJAX)
264
-            && $this->real_level()
265
-            && ! is_admin()
266
-            && current_user_can('administrator')
267
-            && $current_page->isEspressoPage()
268
-        ) {
269
-            printf(
270
-                esc_html__(
271
-                    '%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',
272
-                    'event_espresso'
273
-                ),
274
-                '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
275
-                '"><span class="dashicons dashicons-no"></span></a><p>',
276
-                ' &raquo; <a href="' . add_query_arg(
277
-                    array('page' => 'espresso_maintenance_settings'),
278
-                    admin_url('admin.php')
279
-                ) . '">',
280
-                '</a></p></div>'
281
-            );
282
-        }
283
-    }
284
-    // espresso-notices important-notice ee-attention
285
-
286
-
287
-    /**
288
-     * override magic methods
289
-     */
290
-    final public function __destruct()
291
-    {
292
-    }
293
-
294
-
295
-    final public function __call($a, $b)
296
-    {
297
-    }
298
-
299
-
300
-    final public function __get($a)
301
-    {
302
-    }
303
-
304
-
305
-    final public function __set($a, $b)
306
-    {
307
-    }
308
-
309
-
310
-    final public function __isset($a)
311
-    {
312
-    }
313
-
314
-
315
-    final public function __unset($a)
316
-    {
317
-    }
318
-
319
-
320
-    final public function __sleep()
321
-    {
322
-        return array();
323
-    }
324
-
325
-
326
-    final public function __wakeup()
327
-    {
328
-    }
329
-
330
-
331
-    final public function __invoke()
332
-    {
333
-    }
334
-
335
-
336
-    final public static function __set_state($a = null)
337
-    {
338
-        return EE_Maintenance_Mode::instance();
339
-    }
340
-
341
-
342
-    final public function __clone()
343
-    {
344
-    }
19
+	/**
20
+	 * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
21
+	 * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
22
+	 */
23
+	const level_0_not_in_maintenance = 0;
24
+
25
+	/**
26
+	 * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
27
+	 * but the admin backend should be running as normal. Maybe an admin can view the frontend though
28
+	 */
29
+	const level_1_frontend_only_maintenance = 1;
30
+
31
+	/**
32
+	 * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
33
+	 * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
34
+	 * migration scripts before taking the site out of maintenance mode
35
+	 */
36
+	const level_2_complete_maintenance = 2;
37
+
38
+	/**
39
+	 * the name of the option which stores the current level of maintenance mode
40
+	 */
41
+	const option_name_maintenance_mode = 'ee_maintenance_mode';
42
+
43
+
44
+	/**
45
+	 * @var EE_Maintenance_Mode $_instance
46
+	 */
47
+	private static $_instance;
48
+
49
+	/**
50
+	 * @var EE_Registry $EE
51
+	 */
52
+	protected $EE;
53
+
54
+
55
+	/**
56
+	 * @singleton method used to instantiate class object
57
+	 * @return EE_Maintenance_Mode
58
+	 */
59
+	public static function instance()
60
+	{
61
+		// check if class object is instantiated
62
+		if (! self::$_instance instanceof EE_Maintenance_Mode) {
63
+			self::$_instance = new self();
64
+		}
65
+		return self::$_instance;
66
+	}
67
+
68
+
69
+	/**
70
+	 * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
71
+	 *
72
+	 * @return EE_Maintenance_Mode
73
+	 */
74
+	public static function reset()
75
+	{
76
+		self::instance()->set_maintenance_mode_if_db_old();
77
+		return self::instance();
78
+	}
79
+
80
+
81
+	/**
82
+	 *private constructor to prevent direct creation
83
+	 */
84
+	private function __construct()
85
+	{
86
+		// if M-Mode level 2 is engaged, we still need basic assets loaded
87
+		add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
88
+		// shut 'er down down for maintenance ?
89
+		add_filter('the_content', array($this, 'the_content'), 2);
90
+		// add powered by EE msg
91
+		add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
92
+	}
93
+
94
+
95
+	/**
96
+	 * retrieves the maintenance mode option value from the db
97
+	 *
98
+	 * @return int
99
+	 */
100
+	public function real_level()
101
+	{
102
+		return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
103
+	}
104
+
105
+
106
+	/**
107
+	 * Returns whether or not the models reportedly are able to run queries or not
108
+	 * (ie, if the system thinks their tables are present and up-to-date).
109
+	 *
110
+	 * @return boolean
111
+	 */
112
+	public function models_can_query()
113
+	{
114
+		return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
115
+	}
116
+
117
+
118
+	/**
119
+	 * Determines whether or not we're in maintenance mode and what level. However, while the site
120
+	 * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
121
+	 * to them as if teh site isn't in maintenance mode.
122
+	 * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
123
+	 * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
124
+	 * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
125
+	 *
126
+	 * @return int
127
+	 */
128
+	public function level()
129
+	{
130
+		$maintenance_mode_level = $this->real_level();
131
+		// if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
132
+		if ($maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
133
+			&& ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
134
+			&& current_user_can('administrator') // when the user is an admin
135
+		) {
136
+			$maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
137
+		}
138
+		return $maintenance_mode_level;
139
+	}
140
+
141
+
142
+	/**
143
+	 * Determines if we need to put EE in maintenance mode because the database needs updating
144
+	 *
145
+	 * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
146
+	 */
147
+	public function set_maintenance_mode_if_db_old()
148
+	{
149
+		LoaderFactory::getLoader()->getShared('Data_Migration_Manager');
150
+		if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
151
+			update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
152
+			return true;
153
+		}
154
+		if ($this->level() === self::level_2_complete_maintenance) {
155
+			// we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
156
+			// then we shouldn't be in mm2. (Maybe an addon got deactivated?)
157
+			update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
158
+			return false;
159
+		}
160
+		return false;
161
+	}
162
+
163
+
164
+	/**
165
+	 * Updates the maintenance level on the site
166
+	 *
167
+	 * @param int $level
168
+	 * @return void
169
+	 */
170
+	public function set_maintenance_level($level)
171
+	{
172
+		do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
173
+		update_option(self::option_name_maintenance_mode, (int) $level);
174
+	}
175
+
176
+
177
+	/**
178
+	 * returns TRUE if M-Mode is engaged and the current request is not for the admin
179
+	 *
180
+	 * @return bool
181
+	 */
182
+	public static function disable_frontend_for_maintenance()
183
+	{
184
+		return (! is_admin() && EE_Maintenance_Mode::instance()->level());
185
+	}
186
+
187
+
188
+	/**
189
+	 * @return void
190
+	 */
191
+	public function load_assets_required_for_m_mode()
192
+	{
193
+		if ($this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
194
+			&& ! wp_script_is('espresso_core')
195
+		) {
196
+			wp_register_style(
197
+				'espresso_default',
198
+				EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
199
+				array('dashicons'),
200
+				EVENT_ESPRESSO_VERSION
201
+			);
202
+			wp_enqueue_style('espresso_default');
203
+			wp_register_script(
204
+				'espresso_core',
205
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
206
+				array('jquery'),
207
+				EVENT_ESPRESSO_VERSION,
208
+				true
209
+			);
210
+			wp_enqueue_script('espresso_core');
211
+		}
212
+	}
213
+
214
+
215
+	/**
216
+	 * replacement EE CPT template that displays message notifying site visitors
217
+	 * that EE has been temporarily placed into maintenance mode
218
+	 * does NOT get called on non-EE-CPT requests
219
+	 *
220
+	 * @return    string
221
+	 */
222
+	public static function template_include()
223
+	{
224
+		// shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
225
+		return get_template_directory() . '/index.php';
226
+	}
227
+
228
+
229
+	/**
230
+	 * displays message notifying site visitors that EE has been temporarily
231
+	 * placed into maintenance mode when post_type != EE CPT
232
+	 *
233
+	 * @param string $the_content
234
+	 * @return string
235
+	 */
236
+	public function the_content($the_content)
237
+	{
238
+		// check if M-mode is engaged and for EE shortcode
239
+		if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
240
+			// this can eventually be moved to a template, or edited via admin. But for now...
241
+			$the_content = sprintf(
242
+				esc_html__(
243
+					'%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',
244
+					'event_espresso'
245
+				),
246
+				'<h3>',
247
+				'</h3><p>',
248
+				'</p>'
249
+			);
250
+		}
251
+		return $the_content;
252
+	}
253
+
254
+
255
+	/**
256
+	 * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
257
+	 */
258
+	public function display_maintenance_mode_notice()
259
+	{
260
+		/** @var CurrentPage $current_page */
261
+		$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
262
+		// check if M-mode is engaged and for EE shortcode
263
+		if (! (defined('DOING_AJAX') && DOING_AJAX)
264
+			&& $this->real_level()
265
+			&& ! is_admin()
266
+			&& current_user_can('administrator')
267
+			&& $current_page->isEspressoPage()
268
+		) {
269
+			printf(
270
+				esc_html__(
271
+					'%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',
272
+					'event_espresso'
273
+				),
274
+				'<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
275
+				'"><span class="dashicons dashicons-no"></span></a><p>',
276
+				' &raquo; <a href="' . add_query_arg(
277
+					array('page' => 'espresso_maintenance_settings'),
278
+					admin_url('admin.php')
279
+				) . '">',
280
+				'</a></p></div>'
281
+			);
282
+		}
283
+	}
284
+	// espresso-notices important-notice ee-attention
285
+
286
+
287
+	/**
288
+	 * override magic methods
289
+	 */
290
+	final public function __destruct()
291
+	{
292
+	}
293
+
294
+
295
+	final public function __call($a, $b)
296
+	{
297
+	}
298
+
299
+
300
+	final public function __get($a)
301
+	{
302
+	}
303
+
304
+
305
+	final public function __set($a, $b)
306
+	{
307
+	}
308
+
309
+
310
+	final public function __isset($a)
311
+	{
312
+	}
313
+
314
+
315
+	final public function __unset($a)
316
+	{
317
+	}
318
+
319
+
320
+	final public function __sleep()
321
+	{
322
+		return array();
323
+	}
324
+
325
+
326
+	final public function __wakeup()
327
+	{
328
+	}
329
+
330
+
331
+	final public function __invoke()
332
+	{
333
+	}
334
+
335
+
336
+	final public static function __set_state($a = null)
337
+	{
338
+		return EE_Maintenance_Mode::instance();
339
+	}
340
+
341
+
342
+	final public function __clone()
343
+	{
344
+	}
345 345
 
346 346
 
347
-    final public static function __callStatic($a, $b)
348
-    {
349
-    }
347
+	final public static function __callStatic($a, $b)
348
+	{
349
+	}
350 350
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     public static function instance()
60 60
     {
61 61
         // check if class object is instantiated
62
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
62
+        if ( ! self::$_instance instanceof EE_Maintenance_Mode) {
63 63
             self::$_instance = new self();
64 64
         }
65 65
         return self::$_instance;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      */
182 182
     public static function disable_frontend_for_maintenance()
183 183
     {
184
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
184
+        return ( ! is_admin() && EE_Maintenance_Mode::instance()->level());
185 185
     }
186 186
 
187 187
 
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
         ) {
196 196
             wp_register_style(
197 197
                 'espresso_default',
198
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
198
+                EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
199 199
                 array('dashicons'),
200 200
                 EVENT_ESPRESSO_VERSION
201 201
             );
202 202
             wp_enqueue_style('espresso_default');
203 203
             wp_register_script(
204 204
                 'espresso_core',
205
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
205
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
206 206
                 array('jquery'),
207 207
                 EVENT_ESPRESSO_VERSION,
208 208
                 true
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
     public static function template_include()
223 223
     {
224 224
         // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
225
-        return get_template_directory() . '/index.php';
225
+        return get_template_directory().'/index.php';
226 226
     }
227 227
 
228 228
 
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
         /** @var CurrentPage $current_page */
261 261
         $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
262 262
         // check if M-mode is engaged and for EE shortcode
263
-        if (! (defined('DOING_AJAX') && DOING_AJAX)
263
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)
264 264
             && $this->real_level()
265 265
             && ! is_admin()
266 266
             && current_user_can('administrator')
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
                 ),
274 274
                 '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
275 275
                 '"><span class="dashicons dashicons-no"></span></a><p>',
276
-                ' &raquo; <a href="' . add_query_arg(
276
+                ' &raquo; <a href="'.add_query_arg(
277 277
                     array('page' => 'espresso_maintenance_settings'),
278 278
                     admin_url('admin.php')
279
-                ) . '">',
279
+                ).'">',
280 280
                 '</a></p></div>'
281 281
             );
282 282
         }
Please login to merge, or discard this patch.
core/EED_Module.module.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -15,140 +15,140 @@
 block discarded – undo
15 15
 abstract class EED_Module extends EE_Configurable implements ResettableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * rendered output to be returned to WP
20
-     *
21
-     * @var    string $output
22
-     */
23
-    protected $output = '';
24
-
25
-    /**
26
-     * the current active espresso template theme
27
-     *
28
-     * @var    string $theme
29
-     */
30
-    protected $theme = '';
31
-
32
-
33
-    /**
34
-     * @return void
35
-     */
36
-    public static function reset()
37
-    {
38
-        $module_name = get_called_class();
39
-        new $module_name();
40
-    }
41
-
42
-
43
-    /**
44
-     *    set_hooks - for hooking into EE Core, other modules, etc
45
-     *
46
-     * @access    public
47
-     * @return    void
48
-     */
49
-    public static function set_hooks()
50
-    {
51
-    }
52
-
53
-
54
-    /**
55
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
56
-     *
57
-     * @access    public
58
-     * @return    void
59
-     */
60
-    public static function set_hooks_admin()
61
-    {
62
-    }
63
-
64
-
65
-    /**
66
-     *    run - initial module setup
67
-     *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
68
-     *
69
-     * @access    public
70
-     * @var            WP $WP
71
-     * @return    void
72
-     */
73
-    abstract public function run($WP);
74
-
75
-
76
-    /**
77
-     * EED_Module constructor.
78
-     */
79
-    final public function __construct()
80
-    {
81
-        $this->theme = EE_Config::get_current_theme();
82
-        $module_name = $this->module_name();
83
-        EE_Registry::instance()->modules->{$module_name} = $this;
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $module_name
89
-     * @return EED_Module
90
-     * @throws EE_Error
91
-     * @throws ReflectionException
92
-     */
93
-    protected static function get_instance($module_name = '')
94
-    {
95
-        $module_name = ! empty($module_name)
96
-            ? $module_name
97
-            : get_called_class();
98
-        if (! isset(EE_Registry::instance()->modules->{$module_name})
99
-            || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
100
-        ) {
101
-            EE_Registry::instance()->add_module($module_name);
102
-        }
103
-        return EE_Registry::instance()->get_module($module_name);
104
-    }
105
-
106
-
107
-    /**
108
-     *    module_name
109
-     *
110
-     * @access    public
111
-     * @return    string
112
-     */
113
-    public function module_name()
114
-    {
115
-        return get_class($this);
116
-    }
117
-
118
-
119
-    /**
120
-     * @return string
121
-     */
122
-    public function theme()
123
-    {
124
-        return $this->theme;
125
-    }
126
-
127
-
128
-    /**
129
-     * @return RequestInterface
130
-     * @since   $VID:$
131
-     */
132
-    protected static function getRequest()
133
-    {
134
-        static $request;
135
-        if (! $request instanceof RequestInterface) {
136
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
137
-        }
138
-        return $request;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return ResponseInterface
144
-     * @since   $VID:$
145
-     */
146
-    protected static function getResponse()
147
-    {
148
-        static $response;
149
-        if (! $response instanceof RequestInterface) {
150
-            $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
151
-        }
152
-        return $response;
153
-    }
18
+	/**
19
+	 * rendered output to be returned to WP
20
+	 *
21
+	 * @var    string $output
22
+	 */
23
+	protected $output = '';
24
+
25
+	/**
26
+	 * the current active espresso template theme
27
+	 *
28
+	 * @var    string $theme
29
+	 */
30
+	protected $theme = '';
31
+
32
+
33
+	/**
34
+	 * @return void
35
+	 */
36
+	public static function reset()
37
+	{
38
+		$module_name = get_called_class();
39
+		new $module_name();
40
+	}
41
+
42
+
43
+	/**
44
+	 *    set_hooks - for hooking into EE Core, other modules, etc
45
+	 *
46
+	 * @access    public
47
+	 * @return    void
48
+	 */
49
+	public static function set_hooks()
50
+	{
51
+	}
52
+
53
+
54
+	/**
55
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
56
+	 *
57
+	 * @access    public
58
+	 * @return    void
59
+	 */
60
+	public static function set_hooks_admin()
61
+	{
62
+	}
63
+
64
+
65
+	/**
66
+	 *    run - initial module setup
67
+	 *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
68
+	 *
69
+	 * @access    public
70
+	 * @var            WP $WP
71
+	 * @return    void
72
+	 */
73
+	abstract public function run($WP);
74
+
75
+
76
+	/**
77
+	 * EED_Module constructor.
78
+	 */
79
+	final public function __construct()
80
+	{
81
+		$this->theme = EE_Config::get_current_theme();
82
+		$module_name = $this->module_name();
83
+		EE_Registry::instance()->modules->{$module_name} = $this;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $module_name
89
+	 * @return EED_Module
90
+	 * @throws EE_Error
91
+	 * @throws ReflectionException
92
+	 */
93
+	protected static function get_instance($module_name = '')
94
+	{
95
+		$module_name = ! empty($module_name)
96
+			? $module_name
97
+			: get_called_class();
98
+		if (! isset(EE_Registry::instance()->modules->{$module_name})
99
+			|| ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
100
+		) {
101
+			EE_Registry::instance()->add_module($module_name);
102
+		}
103
+		return EE_Registry::instance()->get_module($module_name);
104
+	}
105
+
106
+
107
+	/**
108
+	 *    module_name
109
+	 *
110
+	 * @access    public
111
+	 * @return    string
112
+	 */
113
+	public function module_name()
114
+	{
115
+		return get_class($this);
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function theme()
123
+	{
124
+		return $this->theme;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @return RequestInterface
130
+	 * @since   $VID:$
131
+	 */
132
+	protected static function getRequest()
133
+	{
134
+		static $request;
135
+		if (! $request instanceof RequestInterface) {
136
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
137
+		}
138
+		return $request;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return ResponseInterface
144
+	 * @since   $VID:$
145
+	 */
146
+	protected static function getResponse()
147
+	{
148
+		static $response;
149
+		if (! $response instanceof RequestInterface) {
150
+			$response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
151
+		}
152
+		return $response;
153
+	}
154 154
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         $module_name = ! empty($module_name)
96 96
             ? $module_name
97 97
             : get_called_class();
98
-        if (! isset(EE_Registry::instance()->modules->{$module_name})
98
+        if ( ! isset(EE_Registry::instance()->modules->{$module_name})
99 99
             || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
100 100
         ) {
101 101
             EE_Registry::instance()->add_module($module_name);
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     protected static function getRequest()
133 133
     {
134 134
         static $request;
135
-        if (! $request instanceof RequestInterface) {
135
+        if ( ! $request instanceof RequestInterface) {
136 136
             $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
137 137
         }
138 138
         return $request;
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     protected static function getResponse()
147 147
     {
148 148
         static $response;
149
-        if (! $response instanceof RequestInterface) {
149
+        if ( ! $response instanceof RequestInterface) {
150 150
             $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
151 151
         }
152 152
         return $response;
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 2 patches
Indentation   +1325 added lines, -1325 removed lines patch added patch discarded remove patch
@@ -16,1338 +16,1338 @@
 block discarded – undo
16 16
 class EED_Messages extends EED_Module
17 17
 {
18 18
 
19
-    /**
20
-     * This holds the EE_messages controller
21
-     *
22
-     * @deprecated 4.9.0
23
-     * @var EE_messages $_EEMSG
24
-     */
25
-    protected static $_EEMSG;
26
-
27
-    /**
28
-     * @type EE_Message_Resource_Manager $_message_resource_manager
29
-     */
30
-    protected static $_message_resource_manager;
31
-
32
-    /**
33
-     * This holds the EE_Messages_Processor business class.
34
-     *
35
-     * @type EE_Messages_Processor
36
-     */
37
-    protected static $_MSG_PROCESSOR;
38
-
39
-    /**
40
-     * holds all the paths for various messages components.
41
-     * Utilized by autoloader registry
42
-     *
43
-     * @var array
44
-     */
45
-    protected static $_MSG_PATHS;
46
-
47
-
48
-    /**
49
-     * This will hold an array of messages template packs that are registered in the messages system.
50
-     * Format is:
51
-     * array(
52
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
-     * )
54
-     *
55
-     * @var EE_Messages_Template_Pack[]
56
-     */
57
-    protected static $_TMP_PACKS = array();
58
-
59
-
60
-    /**
61
-     * @return EED_Messages|EED_Module
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public static function instance()
66
-    {
67
-        return parent::get_instance(__CLASS__);
68
-    }
69
-
70
-
71
-    /**
72
-     *  set_hooks - for hooking into EE Core, other modules, etc
73
-     *
74
-     * @since 4.5.0
75
-     * @return    void
76
-     */
77
-    public static function set_hooks()
78
-    {
79
-        // actions
80
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
-        add_action(
82
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
-            array('EED_Messages', 'maybe_registration'),
84
-            10,
85
-            2
86
-        );
87
-        // filters
88
-        add_filter(
89
-            'FHEE__EE_Registration__receipt_url__receipt_url',
90
-            array('EED_Messages', 'registration_message_trigger_url'),
91
-            10,
92
-            4
93
-        );
94
-        add_filter(
95
-            'FHEE__EE_Registration__invoice_url__invoice_url',
96
-            array('EED_Messages', 'registration_message_trigger_url'),
97
-            10,
98
-            4
99
-        );
100
-        // register routes
101
-        self::_register_routes();
102
-    }
103
-
104
-    /**
105
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
-     *
107
-     * @access    public
108
-     * @return    void
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        // actions
113
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
-        add_action(
115
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
-            array('EED_Messages', 'payment_reminder'),
117
-            10
118
-        );
119
-        add_action(
120
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
-            array('EED_Messages', 'maybe_registration'),
122
-            10,
123
-            3
124
-        );
125
-        add_action(
126
-            'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
-            array('EED_Messages', 'send_newsletter_message'),
128
-            10,
129
-            2
130
-        );
131
-        add_action(
132
-            'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
-            array('EED_Messages', 'cancelled_registration'),
134
-            10
135
-        );
136
-        add_action(
137
-            'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
-            array('EED_Messages', 'process_admin_payment'),
139
-            10,
140
-            1
141
-        );
142
-        // filters
143
-        add_filter(
144
-            'FHEE__EE_Admin_Page___process_resend_registration__success',
145
-            array('EED_Messages', 'process_resend'),
146
-            10,
147
-            2
148
-        );
149
-        add_filter(
150
-            'FHEE__EE_Registration__receipt_url__receipt_url',
151
-            array('EED_Messages', 'registration_message_trigger_url'),
152
-            10,
153
-            4
154
-        );
155
-        add_filter(
156
-            'FHEE__EE_Registration__invoice_url__invoice_url',
157
-            array('EED_Messages', 'registration_message_trigger_url'),
158
-            10,
159
-            4
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * All the message triggers done by route go in here.
166
-     *
167
-     * @since 4.5.0
168
-     * @return void
169
-     */
170
-    protected static function _register_routes()
171
-    {
172
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
-        do_action('AHEE__EED_Messages___register_routes');
177
-    }
178
-
179
-
180
-    /**
181
-     * This is called when a browser display trigger is executed.
182
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
183
-     * browser.
184
-     *
185
-     * @since 4.9.0
186
-     * @param WP $WP
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws ReflectionException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    public function browser_trigger($WP)
194
-    {
195
-        // ensure controller is loaded
196
-        self::_load_controller();
197
-        $token = self::getRequest()->getRequestParam('token');
198
-        try {
199
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
-        } catch (EE_Error $e) {
202
-            $error_msg = __(
203
-                'Please note that a system message failed to send due to a technical issue.',
204
-                'event_espresso'
205
-            );
206
-            // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
208
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * This is called when a browser error trigger is executed.
215
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
-     * message and display it.
217
-     *
218
-     * @since 4.9.0
219
-     * @param $WP
220
-     * @throws EE_Error
221
-     * @throws InvalidArgumentException
222
-     * @throws InvalidDataTypeException
223
-     * @throws InvalidInterfaceException
224
-     */
225
-    public function browser_error_trigger($WP)
226
-    {
227
-        $token = self::getRequest()->getRequestParam('token');
228
-        if ($token) {
229
-            $message = EEM_Message::instance()->get_one_by_token($token);
230
-            if ($message instanceof EE_Message) {
231
-                header('HTTP/1.1 200 OK');
232
-                $error_msg = nl2br($message->error_message());
233
-                ?>
19
+	/**
20
+	 * This holds the EE_messages controller
21
+	 *
22
+	 * @deprecated 4.9.0
23
+	 * @var EE_messages $_EEMSG
24
+	 */
25
+	protected static $_EEMSG;
26
+
27
+	/**
28
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
29
+	 */
30
+	protected static $_message_resource_manager;
31
+
32
+	/**
33
+	 * This holds the EE_Messages_Processor business class.
34
+	 *
35
+	 * @type EE_Messages_Processor
36
+	 */
37
+	protected static $_MSG_PROCESSOR;
38
+
39
+	/**
40
+	 * holds all the paths for various messages components.
41
+	 * Utilized by autoloader registry
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected static $_MSG_PATHS;
46
+
47
+
48
+	/**
49
+	 * This will hold an array of messages template packs that are registered in the messages system.
50
+	 * Format is:
51
+	 * array(
52
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
+	 * )
54
+	 *
55
+	 * @var EE_Messages_Template_Pack[]
56
+	 */
57
+	protected static $_TMP_PACKS = array();
58
+
59
+
60
+	/**
61
+	 * @return EED_Messages|EED_Module
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public static function instance()
66
+	{
67
+		return parent::get_instance(__CLASS__);
68
+	}
69
+
70
+
71
+	/**
72
+	 *  set_hooks - for hooking into EE Core, other modules, etc
73
+	 *
74
+	 * @since 4.5.0
75
+	 * @return    void
76
+	 */
77
+	public static function set_hooks()
78
+	{
79
+		// actions
80
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
+		add_action(
82
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
+			array('EED_Messages', 'maybe_registration'),
84
+			10,
85
+			2
86
+		);
87
+		// filters
88
+		add_filter(
89
+			'FHEE__EE_Registration__receipt_url__receipt_url',
90
+			array('EED_Messages', 'registration_message_trigger_url'),
91
+			10,
92
+			4
93
+		);
94
+		add_filter(
95
+			'FHEE__EE_Registration__invoice_url__invoice_url',
96
+			array('EED_Messages', 'registration_message_trigger_url'),
97
+			10,
98
+			4
99
+		);
100
+		// register routes
101
+		self::_register_routes();
102
+	}
103
+
104
+	/**
105
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
+	 *
107
+	 * @access    public
108
+	 * @return    void
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		// actions
113
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
+		add_action(
115
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
+			array('EED_Messages', 'payment_reminder'),
117
+			10
118
+		);
119
+		add_action(
120
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
+			array('EED_Messages', 'maybe_registration'),
122
+			10,
123
+			3
124
+		);
125
+		add_action(
126
+			'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
+			array('EED_Messages', 'send_newsletter_message'),
128
+			10,
129
+			2
130
+		);
131
+		add_action(
132
+			'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
+			array('EED_Messages', 'cancelled_registration'),
134
+			10
135
+		);
136
+		add_action(
137
+			'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
+			array('EED_Messages', 'process_admin_payment'),
139
+			10,
140
+			1
141
+		);
142
+		// filters
143
+		add_filter(
144
+			'FHEE__EE_Admin_Page___process_resend_registration__success',
145
+			array('EED_Messages', 'process_resend'),
146
+			10,
147
+			2
148
+		);
149
+		add_filter(
150
+			'FHEE__EE_Registration__receipt_url__receipt_url',
151
+			array('EED_Messages', 'registration_message_trigger_url'),
152
+			10,
153
+			4
154
+		);
155
+		add_filter(
156
+			'FHEE__EE_Registration__invoice_url__invoice_url',
157
+			array('EED_Messages', 'registration_message_trigger_url'),
158
+			10,
159
+			4
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * All the message triggers done by route go in here.
166
+	 *
167
+	 * @since 4.5.0
168
+	 * @return void
169
+	 */
170
+	protected static function _register_routes()
171
+	{
172
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
+		do_action('AHEE__EED_Messages___register_routes');
177
+	}
178
+
179
+
180
+	/**
181
+	 * This is called when a browser display trigger is executed.
182
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
183
+	 * browser.
184
+	 *
185
+	 * @since 4.9.0
186
+	 * @param WP $WP
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws ReflectionException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	public function browser_trigger($WP)
194
+	{
195
+		// ensure controller is loaded
196
+		self::_load_controller();
197
+		$token = self::getRequest()->getRequestParam('token');
198
+		try {
199
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
+		} catch (EE_Error $e) {
202
+			$error_msg = __(
203
+				'Please note that a system message failed to send due to a technical issue.',
204
+				'event_espresso'
205
+			);
206
+			// add specific message for developers if WP_DEBUG in on
207
+			$error_msg .= '||' . $e->getMessage();
208
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * This is called when a browser error trigger is executed.
215
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
+	 * message and display it.
217
+	 *
218
+	 * @since 4.9.0
219
+	 * @param $WP
220
+	 * @throws EE_Error
221
+	 * @throws InvalidArgumentException
222
+	 * @throws InvalidDataTypeException
223
+	 * @throws InvalidInterfaceException
224
+	 */
225
+	public function browser_error_trigger($WP)
226
+	{
227
+		$token = self::getRequest()->getRequestParam('token');
228
+		if ($token) {
229
+			$message = EEM_Message::instance()->get_one_by_token($token);
230
+			if ($message instanceof EE_Message) {
231
+				header('HTTP/1.1 200 OK');
232
+				$error_msg = nl2br($message->error_message());
233
+				?>
234 234
                 <!DOCTYPE html>
235 235
                 <html>
236 236
                 <head></head>
237 237
                 <body>
238 238
                 <?php echo empty($error_msg)
239
-                    ? esc_html__(
240
-                        'Unfortunately, we were unable to capture the error message for this message.',
241
-                        'event_espresso'
242
-                    )
243
-                    : wp_kses(
244
-                        $error_msg,
245
-                        array(
246
-                            'a'      => array(
247
-                                'href'  => array(),
248
-                                'title' => array(),
249
-                            ),
250
-                            'span'   => array(),
251
-                            'div'    => array(),
252
-                            'p'      => array(),
253
-                            'strong' => array(),
254
-                            'em'     => array(),
255
-                            'br'     => array(),
256
-                        )
257
-                    ); ?>
239
+					? esc_html__(
240
+						'Unfortunately, we were unable to capture the error message for this message.',
241
+						'event_espresso'
242
+					)
243
+					: wp_kses(
244
+						$error_msg,
245
+						array(
246
+							'a'      => array(
247
+								'href'  => array(),
248
+								'title' => array(),
249
+							),
250
+							'span'   => array(),
251
+							'div'    => array(),
252
+							'p'      => array(),
253
+							'strong' => array(),
254
+							'em'     => array(),
255
+							'br'     => array(),
256
+						)
257
+					); ?>
258 258
                 </body>
259 259
                 </html>
260 260
                 <?php
261
-                exit;
262
-            }
263
-        }
264
-        return;
265
-    }
266
-
267
-
268
-    /**
269
-     *  This runs when the msg_url_trigger route has initiated.
270
-     *
271
-     * @since 4.5.0
272
-     * @param WP $WP
273
-     * @throws EE_Error
274
-     * @throws InvalidArgumentException
275
-     * @throws ReflectionException
276
-     * @throws InvalidDataTypeException
277
-     * @throws InvalidInterfaceException
278
-     */
279
-    public function run($WP)
280
-    {
281
-        // ensure controller is loaded
282
-        self::_load_controller();
283
-        // attempt to process message
284
-        try {
285
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
286
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
287
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
288
-        } catch (EE_Error $e) {
289
-            $error_msg = __(
290
-                'Please note that a system message failed to send due to a technical issue.',
291
-                'event_espresso'
292
-            );
293
-            // add specific message for developers if WP_DEBUG in on
294
-            $error_msg .= '||' . $e->getMessage();
295
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
296
-        }
297
-    }
298
-
299
-
300
-    /**
301
-     * This is triggered by the 'msg_cron_trigger' route.
302
-     *
303
-     * @param WP $WP
304
-     */
305
-    public function execute_batch_request($WP)
306
-    {
307
-        $this->run_cron();
308
-        header('HTTP/1.1 200 OK');
309
-        exit();
310
-    }
311
-
312
-
313
-    /**
314
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
315
-     * request.
316
-     */
317
-    public function run_cron()
318
-    {
319
-        self::_load_controller();
320
-        $request = self::getRequest();
321
-        // get required vars
322
-        $cron_type = $request->getRequestParam('type');
323
-        $transient_key = $request->getRequestParam('key');
324
-
325
-        // now let's verify transient, if not valid exit immediately
326
-        if (! get_transient($transient_key)) {
327
-            /**
328
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user
329
-             * request.
330
-             */
331
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
332
-        }
333
-
334
-        // if made it here, lets' delete the transient to keep the db clean
335
-        delete_transient($transient_key);
336
-
337
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
338
-            $method = 'batch_' . $cron_type . '_from_queue';
339
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
340
-                self::$_MSG_PROCESSOR->$method();
341
-            } else {
342
-                // no matching task
343
-                /**
344
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user
345
-                 * request.
346
-                 */
347
-                trigger_error(
348
-                    esc_attr(
349
-                        sprintf(
350
-                            __('There is no task corresponding to this route %s', 'event_espresso'),
351
-                            $cron_type
352
-                        )
353
-                    )
354
-                );
355
-            }
356
-        }
357
-
358
-        do_action('FHEE__EED_Messages__run_cron__end');
359
-    }
360
-
361
-
362
-    /**
363
-     * This is used to retrieve the template pack for the given name.
364
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
365
-     * the default template pack is returned.
366
-     *
367
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
368
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
369
-     *                                   in generating the Pack class name).
370
-     * @return EE_Messages_Template_Pack
371
-     * @throws EE_Error
372
-     * @throws InvalidArgumentException
373
-     * @throws ReflectionException
374
-     * @throws InvalidDataTypeException
375
-     * @throws InvalidInterfaceException
376
-     */
377
-    public static function get_template_pack($template_pack_name)
378
-    {
379
-        EE_Registry::instance()->load_helper('MSG_Template');
380
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
381
-    }
382
-
383
-
384
-    /**
385
-     * Retrieves an array of all template packs.
386
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
387
-     *
388
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
389
-     * @return EE_Messages_Template_Pack[]
390
-     * @throws EE_Error
391
-     * @throws InvalidArgumentException
392
-     * @throws ReflectionException
393
-     * @throws InvalidDataTypeException
394
-     * @throws InvalidInterfaceException
395
-     */
396
-    public static function get_template_packs()
397
-    {
398
-        EE_Registry::instance()->load_helper('MSG_Template');
399
-
400
-        // for backward compat, let's make sure this returns in the same format as originally.
401
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
402
-        $template_pack_collection->rewind();
403
-        $template_packs = array();
404
-        while ($template_pack_collection->valid()) {
405
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
406
-            $template_pack_collection->next();
407
-        }
408
-        return $template_packs;
409
-    }
410
-
411
-
412
-    /**
413
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
414
-     *
415
-     * @since 4.5.0
416
-     * @return void
417
-     * @throws EE_Error
418
-     */
419
-    public static function set_autoloaders()
420
-    {
421
-        if (empty(self::$_MSG_PATHS)) {
422
-            self::_set_messages_paths();
423
-            foreach (self::$_MSG_PATHS as $path) {
424
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
425
-            }
426
-            // add aliases
427
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
428
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
429
-        }
430
-    }
431
-
432
-
433
-    /**
434
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
435
-     * for use by the Messages Autoloaders
436
-     *
437
-     * @since 4.5.0
438
-     * @return void.
439
-     */
440
-    protected static function _set_messages_paths()
441
-    {
442
-        $dir_ref = array(
443
-            'messages/message_type',
444
-            'messages/messenger',
445
-            'messages/defaults',
446
-            'messages/defaults/email',
447
-            'messages/data_class',
448
-            'messages/validators',
449
-            'messages/validators/email',
450
-            'messages/validators/html',
451
-            'shortcodes',
452
-        );
453
-        $paths = array();
454
-        foreach ($dir_ref as $index => $dir) {
455
-            $paths[ $index ] = EE_LIBRARIES . $dir;
456
-        }
457
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
458
-    }
459
-
460
-
461
-    /**
462
-     * Takes care of loading dependencies
463
-     *
464
-     * @since 4.5.0
465
-     * @return void
466
-     * @throws EE_Error
467
-     * @throws InvalidArgumentException
468
-     * @throws ReflectionException
469
-     * @throws InvalidDataTypeException
470
-     * @throws InvalidInterfaceException
471
-     */
472
-    protected static function _load_controller()
473
-    {
474
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
475
-            EE_Registry::instance()->load_core('Request_Handler');
476
-            self::set_autoloaders();
477
-            self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
478
-            self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
479
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
480
-        }
481
-    }
482
-
483
-
484
-    /**
485
-     * @param EE_Transaction $transaction
486
-     * @throws EE_Error
487
-     * @throws InvalidArgumentException
488
-     * @throws InvalidDataTypeException
489
-     * @throws InvalidInterfaceException
490
-     * @throws ReflectionException
491
-     */
492
-    public static function payment_reminder(EE_Transaction $transaction)
493
-    {
494
-        self::_load_controller();
495
-        $data = array($transaction, null);
496
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
497
-    }
498
-
499
-
500
-    /**
501
-     * Any messages triggers for after successful gateway payments should go in here.
502
-     *
503
-     * @param EE_Transaction  $transaction object
504
-     * @param EE_Payment|null $payment     object
505
-     * @return void
506
-     * @throws EE_Error
507
-     * @throws InvalidArgumentException
508
-     * @throws ReflectionException
509
-     * @throws InvalidDataTypeException
510
-     * @throws InvalidInterfaceException
511
-     */
512
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
513
-    {
514
-        // if there's no payment object, then we cannot do a payment type message!
515
-        if (! $payment instanceof EE_Payment) {
516
-            return;
517
-        }
518
-        self::_load_controller();
519
-        $data = array($transaction, $payment);
520
-        EE_Registry::instance()->load_helper('MSG_Template');
521
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
522
-        // if payment amount is less than 0 then switch to payment_refund message type.
523
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
524
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
525
-    }
526
-
527
-
528
-    /**
529
-     * @param EE_Transaction $transaction
530
-     * @throws EE_Error
531
-     * @throws InvalidArgumentException
532
-     * @throws InvalidDataTypeException
533
-     * @throws InvalidInterfaceException
534
-     * @throws ReflectionException
535
-     */
536
-    public static function cancelled_registration(EE_Transaction $transaction)
537
-    {
538
-        self::_load_controller();
539
-        $data = array($transaction, null);
540
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
541
-    }
542
-
543
-
544
-    /**
545
-     * Trigger for Registration messages
546
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
547
-     * incoming transaction.
548
-     *
549
-     * @param EE_Registration $registration
550
-     * @param array           $extra_details
551
-     * @return void
552
-     * @throws EE_Error
553
-     * @throws InvalidArgumentException
554
-     * @throws InvalidDataTypeException
555
-     * @throws InvalidInterfaceException
556
-     * @throws ReflectionException
557
-     * @throws EntityNotFoundException
558
-     */
559
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
560
-    {
561
-
562
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
563
-            // no messages please
564
-            return;
565
-        }
566
-
567
-        // get all non-trashed registrations so we make sure we send messages for the right status.
568
-        $all_registrations = $registration->transaction()->registrations(
569
-            array(
570
-                array('REG_deleted' => false),
571
-                'order_by' => array(
572
-                    'Event.EVT_name'     => 'ASC',
573
-                    'Attendee.ATT_lname' => 'ASC',
574
-                    'Attendee.ATT_fname' => 'ASC',
575
-                ),
576
-            )
577
-        );
578
-        // cached array of statuses so we only trigger messages once per status.
579
-        $statuses_sent = array();
580
-        self::_load_controller();
581
-        $mtgs = array();
582
-
583
-        // loop through registrations and trigger messages once per status.
584
-        foreach ($all_registrations as $reg) {
585
-            // already triggered?
586
-            if (in_array($reg->status_ID(), $statuses_sent)) {
587
-                continue;
588
-            }
589
-
590
-            $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
591
-            $mtgs = array_merge(
592
-                $mtgs,
593
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
594
-                    $message_type,
595
-                    array($registration->transaction(), null, $reg->status_ID())
596
-                )
597
-            );
598
-            $statuses_sent[] = $reg->status_ID();
599
-        }
600
-
601
-        if (count($statuses_sent) > 1) {
602
-            $mtgs = array_merge(
603
-                $mtgs,
604
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
605
-                    'registration_summary',
606
-                    array($registration->transaction(), null)
607
-                )
608
-            );
609
-        }
610
-
611
-        // batch queue and initiate request
612
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
613
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
614
-    }
615
-
616
-
617
-    /**
618
-     * This is a helper method used to very whether a registration notification should be sent or
619
-     * not.  Prevents duplicate notifications going out for registration context notifications.
620
-     *
621
-     * @param EE_Registration $registration  [description]
622
-     * @param array           $extra_details [description]
623
-     * @return bool          true = send away, false = nope halt the presses.
624
-     */
625
-    protected static function _verify_registration_notification_send(
626
-        EE_Registration $registration,
627
-        $extra_details = array()
628
-    ) {
629
-        if (! $registration->is_primary_registrant()) {
630
-            return false;
631
-        }
632
-        $request = self::getRequest();
633
-        // first we check if we're in admin and not doing front ajax
634
-        if ($request->isAdmin() && ! $request->isFrontAjax()) {
635
-            $status_change = $request->getRequestParam('txn_reg_status_change', [], 'arrayOf|int');
636
-            // make sure appropriate admin params are set for sending messages
637
-            if (! $status_change['send_notifications']) {
638
-                // no messages sent please.
639
-                return false;
640
-            }
641
-        } else {
642
-            // frontend request (either regular or via AJAX)
643
-            // TXN is NOT finalized ?
644
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
645
-                return false;
646
-            }
647
-            // return visit but nothing changed ???
648
-            if (isset($extra_details['revisit'], $extra_details['status_updates']) &&
649
-                $extra_details['revisit'] && ! $extra_details['status_updates']
650
-            ) {
651
-                return false;
652
-            }
653
-            // NOT sending messages && reg status is something other than "Not-Approved"
654
-            if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
655
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
656
-            ) {
657
-                return false;
658
-            }
659
-        }
660
-        // release the kraken
661
-        return true;
662
-    }
663
-
664
-
665
-    /**
666
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
667
-     * status id.
668
-     *
669
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
670
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
671
-     * @param string $reg_status
672
-     * @return array
673
-     * @throws EE_Error
674
-     * @throws InvalidArgumentException
675
-     * @throws ReflectionException
676
-     * @throws InvalidDataTypeException
677
-     * @throws InvalidInterfaceException
678
-     */
679
-    protected static function _get_reg_status_array($reg_status = '')
680
-    {
681
-        EE_Registry::instance()->load_helper('MSG_Template');
682
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
683
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
684
-            : EEH_MSG_Template::reg_status_to_message_type_array();
685
-    }
686
-
687
-
688
-    /**
689
-     * Simply returns the payment message type for the given payment status.
690
-     *
691
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
692
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
693
-     * @param string $payment_status The payment status being matched.
694
-     * @return bool|string The payment message type slug matching the status or false if no match.
695
-     * @throws EE_Error
696
-     * @throws InvalidArgumentException
697
-     * @throws ReflectionException
698
-     * @throws InvalidDataTypeException
699
-     * @throws InvalidInterfaceException
700
-     */
701
-    protected static function _get_payment_message_type($payment_status)
702
-    {
703
-        EE_Registry::instance()->load_helper('MSG_Template');
704
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
705
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
706
-            : false;
707
-    }
708
-
709
-
710
-    /**
711
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
712
-     *
713
-     * @access public
714
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
715
-     * @return bool success/fail
716
-     * @throws EE_Error
717
-     * @throws InvalidArgumentException
718
-     * @throws InvalidDataTypeException
719
-     * @throws InvalidInterfaceException
720
-     * @throws ReflectionException
721
-     */
722
-    public static function process_resend($req_data)
723
-    {
724
-        self::_load_controller();
725
-        $request = self::getRequest();
726
-        // if $msgID in this request then skip to the new resend_message
727
-        if ($request->getRequestParam('MSG_ID')) {
728
-            return self::resend_message();
729
-        }
730
-
731
-        // make sure any incoming request data is set on the request so that it gets picked up later.
732
-        $req_data = (array) $req_data;
733
-        foreach ($req_data as $request_key => $request_value) {
734
-            $request->setRequestParam($request_key, $request_value);
735
-        }
736
-
737
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request(
738
-        )) {
739
-            return false;
740
-        }
741
-
742
-        try {
743
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
744
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
745
-        } catch (EE_Error $e) {
746
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
747
-            return false;
748
-        }
749
-        EE_Error::add_success(
750
-            __('Messages have been successfully queued for generation and sending.', 'event_espresso')
751
-        );
752
-        return true; // everything got queued.
753
-    }
754
-
755
-
756
-    /**
757
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
758
-     *
759
-     * @return bool
760
-     * @throws EE_Error
761
-     * @throws InvalidArgumentException
762
-     * @throws InvalidDataTypeException
763
-     * @throws InvalidInterfaceException
764
-     * @throws ReflectionException
765
-     */
766
-    public static function resend_message()
767
-    {
768
-        self::_load_controller();
769
-
770
-        $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
771
-        if (! $msgID) {
772
-            EE_Error::add_error(
773
-                __(
774
-                    'Something went wrong because there is no "MSG_ID" value in the request',
775
-                    'event_espresso'
776
-                ),
777
-                __FILE__,
778
-                __FUNCTION__,
779
-                __LINE__
780
-            );
781
-            return false;
782
-        }
783
-
784
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
785
-
786
-        // setup success message.
787
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
788
-        EE_Error::add_success(
789
-            sprintf(
790
-                _n(
791
-                    'There was %d message queued for resending.',
792
-                    'There were %d messages queued for resending.',
793
-                    $count_ready_for_resend,
794
-                    'event_espresso'
795
-                ),
796
-                $count_ready_for_resend
797
-            )
798
-        );
799
-        return true;
800
-    }
801
-
802
-
803
-    /**
804
-     * Message triggers for manual payment applied by admin
805
-     *
806
-     * @param  EE_Payment $payment EE_payment object
807
-     * @return bool success/fail
808
-     * @throws EE_Error
809
-     * @throws InvalidArgumentException
810
-     * @throws ReflectionException
811
-     * @throws InvalidDataTypeException
812
-     * @throws InvalidInterfaceException
813
-     */
814
-    public static function process_admin_payment(EE_Payment $payment)
815
-    {
816
-        EE_Registry::instance()->load_helper('MSG_Template');
817
-        // we need to get the transaction object
818
-        $transaction = $payment->transaction();
819
-        if ($transaction instanceof EE_Transaction) {
820
-            $data = array($transaction, $payment);
821
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
822
-
823
-            // if payment amount is less than 0 then switch to payment_refund message type.
824
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
825
-
826
-            // if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
827
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
828
-                ? false : $message_type;
829
-
830
-            self::_load_controller();
831
-
832
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
833
-
834
-            // get count of queued for generation
835
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
836
-                array(
837
-                    EEM_Message::status_incomplete,
838
-                    EEM_Message::status_idle,
839
-                )
840
-            );
841
-
842
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
843
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
844
-                return true;
845
-            } else {
846
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
847
-                    EEM_Message::instance()->stati_indicating_failed_sending()
848
-                );
849
-                /**
850
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
851
-                 * IMMEDIATE generation.
852
-                 */
853
-                if ($count_failed > 0) {
854
-                    EE_Error::add_error(
855
-                        sprintf(
856
-                            _n(
857
-                                'The payment notification generation failed.',
858
-                                '%d payment notifications failed being sent.',
859
-                                $count_failed,
860
-                                'event_espresso'
861
-                            ),
862
-                            $count_failed
863
-                        ),
864
-                        __FILE__,
865
-                        __FUNCTION__,
866
-                        __LINE__
867
-                    );
868
-
869
-                    return false;
870
-                } else {
871
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
872
-                    return true;
873
-                }
874
-            }
875
-        } else {
876
-            EE_Error::add_error(
877
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
878
-                'event_espresso'
879
-            );
880
-            return false;
881
-        }
882
-    }
883
-
884
-
885
-    /**
886
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
887
-     *
888
-     * @since   4.3.0
889
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
890
-     * @param  int               $grp_id        a specific message template group id.
891
-     * @return void
892
-     * @throws EE_Error
893
-     * @throws InvalidArgumentException
894
-     * @throws InvalidDataTypeException
895
-     * @throws InvalidInterfaceException
896
-     * @throws ReflectionException
897
-     */
898
-    public static function send_newsletter_message($registrations, $grp_id)
899
-    {
900
-        // make sure mtp is id and set it in the request later messages setup.
901
-        self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
902
-        self::_load_controller();
903
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
904
-    }
905
-
906
-
907
-    /**
908
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
909
-     *
910
-     * @since   4.3.0
911
-     * @param    string          $registration_message_trigger_url
912
-     * @param    EE_Registration $registration
913
-     * @param string             $messenger
914
-     * @param string             $message_type
915
-     * @return string
916
-     * @throws EE_Error
917
-     * @throws InvalidArgumentException
918
-     * @throws InvalidDataTypeException
919
-     * @throws InvalidInterfaceException
920
-     */
921
-    public static function registration_message_trigger_url(
922
-        $registration_message_trigger_url,
923
-        EE_Registration $registration,
924
-        $messenger = 'html',
925
-        $message_type = 'invoice'
926
-    ) {
927
-        // whitelist $messenger
928
-        switch ($messenger) {
929
-            case 'pdf':
930
-                $sending_messenger = 'pdf';
931
-                $generating_messenger = 'html';
932
-                break;
933
-            case 'html':
934
-            default:
935
-                $sending_messenger = 'html';
936
-                $generating_messenger = 'html';
937
-                break;
938
-        }
939
-        // whitelist $message_type
940
-        switch ($message_type) {
941
-            case 'receipt':
942
-                $message_type = 'receipt';
943
-                break;
944
-            case 'invoice':
945
-            default:
946
-                $message_type = 'invoice';
947
-                break;
948
-        }
949
-        // verify that both the messenger AND the message type are active
950
-        if (EEH_MSG_Template::is_messenger_active($sending_messenger)
951
-            && EEH_MSG_Template::is_mt_active($message_type)
952
-        ) {
953
-            // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
954
-            $template_query_params = array(
955
-                'MTP_is_active'    => true,
956
-                'MTP_messenger'    => $generating_messenger,
957
-                'MTP_message_type' => $message_type,
958
-                'Event.EVT_ID'     => $registration->event_ID(),
959
-            );
960
-            // get the message template group.
961
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
962
-            // if we don't have an EE_Message_Template_Group then return
963
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
964
-                // remove EVT_ID from query params so that global templates get picked up
965
-                unset($template_query_params['Event.EVT_ID']);
966
-                // get global template as the fallback
967
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
968
-            }
969
-            // if we don't have an EE_Message_Template_Group then return
970
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
971
-                return '';
972
-            }
973
-            // generate the URL
974
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
975
-                $sending_messenger,
976
-                $generating_messenger,
977
-                'purchaser',
978
-                $message_type,
979
-                $registration,
980
-                $msg_template_group->ID(),
981
-                $registration->transaction_ID()
982
-            );
983
-        }
984
-        return $registration_message_trigger_url;
985
-    }
986
-
987
-
988
-    /**
989
-     * Use to generate and return a message preview!
990
-     *
991
-     * @param  string $type      This should correspond with a valid message type
992
-     * @param  string $context   This should correspond with a valid context for the message type
993
-     * @param  string $messenger This should correspond with a valid messenger.
994
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
995
-     *                           preview
996
-     * @return bool|string The body of the message or if send is requested, sends.
997
-     * @throws EE_Error
998
-     * @throws InvalidArgumentException
999
-     * @throws InvalidDataTypeException
1000
-     * @throws InvalidInterfaceException
1001
-     * @throws ReflectionException
1002
-     */
1003
-    public static function preview_message($type, $context, $messenger, $send = false)
1004
-    {
1005
-        self::_load_controller();
1006
-        $mtg = new EE_Message_To_Generate(
1007
-            $messenger,
1008
-            $type,
1009
-            array(),
1010
-            $context,
1011
-            true
1012
-        );
1013
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1014
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
1015
-            // loop through all content for the preview and remove any persisted records.
1016
-            $content = '';
1017
-            foreach ($generated_preview_queue->get_message_repository() as $message) {
1018
-                $content = $message->content();
1019
-                if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1020
-                    $message->delete();
1021
-                }
1022
-            }
1023
-            return $content;
1024
-        } else {
1025
-            return $generated_preview_queue;
1026
-        }
1027
-    }
1028
-
1029
-
1030
-    /**
1031
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
1032
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1033
-     * content found in the EE_Message objects in the queue.
1034
-     *
1035
-     * @since 4.9.0
1036
-     * @param string            $messenger            a string matching a valid active messenger in the system
1037
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
1038
-     *                                                type name is still required to send along the message type to the
1039
-     *                                                messenger because this is used for determining what specific
1040
-     *                                                variations might be loaded for the generated message.
1041
-     * @param EE_Messages_Queue $queue
1042
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1043
-     *                                                aggregate EE_Message object.
1044
-     * @return bool success or fail.
1045
-     * @throws EE_Error
1046
-     * @throws InvalidArgumentException
1047
-     * @throws ReflectionException
1048
-     * @throws InvalidDataTypeException
1049
-     * @throws InvalidInterfaceException
1050
-     */
1051
-    public static function send_message_with_messenger_only(
1052
-        $messenger,
1053
-        $message_type,
1054
-        EE_Messages_Queue $queue,
1055
-        $custom_subject = ''
1056
-    ) {
1057
-        self::_load_controller();
1058
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1059
-        $message_to_generate = EE_Registry::instance()->load_lib(
1060
-            'Message_To_Generate_From_Queue',
1061
-            array(
1062
-                $messenger,
1063
-                $message_type,
1064
-                $queue,
1065
-                $custom_subject,
1066
-            )
1067
-        );
1068
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1074
-     *
1075
-     * @since 4.9.0
1076
-     * @param array $message_ids An array of message ids
1077
-     * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1078
-     *                           messages.
1079
-     * @throws EE_Error
1080
-     * @throws InvalidArgumentException
1081
-     * @throws InvalidDataTypeException
1082
-     * @throws InvalidInterfaceException
1083
-     * @throws ReflectionException
1084
-     */
1085
-    public static function generate_now($message_ids)
1086
-    {
1087
-        self::_load_controller();
1088
-        $messages = EEM_Message::instance()->get_all(
1089
-            array(
1090
-                0 => array(
1091
-                    'MSG_ID' => array('IN', $message_ids),
1092
-                    'STS_ID' => EEM_Message::status_incomplete,
1093
-                ),
1094
-            )
1095
-        );
1096
-        $generated_queue = false;
1097
-        if ($messages) {
1098
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1099
-        }
1100
-
1101
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1102
-            EE_Error::add_error(
1103
-                __(
1104
-                    'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1105
-                    'event_espresso'
1106
-                ),
1107
-                __FILE__,
1108
-                __FUNCTION__,
1109
-                __LINE__
1110
-            );
1111
-        }
1112
-        return $generated_queue;
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1118
-     * EEM_Message::status_idle
1119
-     *
1120
-     * @since 4.9.0
1121
-     * @param $message_ids
1122
-     * @return bool|EE_Messages_Queue false if no messages sent.
1123
-     * @throws EE_Error
1124
-     * @throws InvalidArgumentException
1125
-     * @throws InvalidDataTypeException
1126
-     * @throws InvalidInterfaceException
1127
-     * @throws ReflectionException
1128
-     */
1129
-    public static function send_now($message_ids)
1130
-    {
1131
-        self::_load_controller();
1132
-        $messages = EEM_Message::instance()->get_all(
1133
-            array(
1134
-                0 => array(
1135
-                    'MSG_ID' => array('IN', $message_ids),
1136
-                    'STS_ID' => array(
1137
-                        'IN',
1138
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1139
-                    ),
1140
-                ),
1141
-            )
1142
-        );
1143
-        $sent_queue = false;
1144
-        if ($messages) {
1145
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1146
-        }
1147
-
1148
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1149
-            EE_Error::add_error(
1150
-                __(
1151
-                    'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1152
-                    'event_espresso'
1153
-                ),
1154
-                __FILE__,
1155
-                __FUNCTION__,
1156
-                __LINE__
1157
-            );
1158
-        } else {
1159
-            // can count how many sent by using the messages in the queue
1160
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1161
-            if ($sent_count > 0) {
1162
-                EE_Error::add_success(
1163
-                    sprintf(
1164
-                        _n(
1165
-                            'There was %d message successfully sent.',
1166
-                            'There were %d messages successfully sent.',
1167
-                            $sent_count,
1168
-                            'event_espresso'
1169
-                        ),
1170
-                        $sent_count
1171
-                    )
1172
-                );
1173
-            } else {
1174
-                EE_Error::overwrite_errors();
1175
-                EE_Error::add_error(
1176
-                    __(
1177
-                        'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
261
+				exit;
262
+			}
263
+		}
264
+		return;
265
+	}
266
+
267
+
268
+	/**
269
+	 *  This runs when the msg_url_trigger route has initiated.
270
+	 *
271
+	 * @since 4.5.0
272
+	 * @param WP $WP
273
+	 * @throws EE_Error
274
+	 * @throws InvalidArgumentException
275
+	 * @throws ReflectionException
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws InvalidInterfaceException
278
+	 */
279
+	public function run($WP)
280
+	{
281
+		// ensure controller is loaded
282
+		self::_load_controller();
283
+		// attempt to process message
284
+		try {
285
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
286
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
287
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
288
+		} catch (EE_Error $e) {
289
+			$error_msg = __(
290
+				'Please note that a system message failed to send due to a technical issue.',
291
+				'event_espresso'
292
+			);
293
+			// add specific message for developers if WP_DEBUG in on
294
+			$error_msg .= '||' . $e->getMessage();
295
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
296
+		}
297
+	}
298
+
299
+
300
+	/**
301
+	 * This is triggered by the 'msg_cron_trigger' route.
302
+	 *
303
+	 * @param WP $WP
304
+	 */
305
+	public function execute_batch_request($WP)
306
+	{
307
+		$this->run_cron();
308
+		header('HTTP/1.1 200 OK');
309
+		exit();
310
+	}
311
+
312
+
313
+	/**
314
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
315
+	 * request.
316
+	 */
317
+	public function run_cron()
318
+	{
319
+		self::_load_controller();
320
+		$request = self::getRequest();
321
+		// get required vars
322
+		$cron_type = $request->getRequestParam('type');
323
+		$transient_key = $request->getRequestParam('key');
324
+
325
+		// now let's verify transient, if not valid exit immediately
326
+		if (! get_transient($transient_key)) {
327
+			/**
328
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user
329
+			 * request.
330
+			 */
331
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
332
+		}
333
+
334
+		// if made it here, lets' delete the transient to keep the db clean
335
+		delete_transient($transient_key);
336
+
337
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
338
+			$method = 'batch_' . $cron_type . '_from_queue';
339
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
340
+				self::$_MSG_PROCESSOR->$method();
341
+			} else {
342
+				// no matching task
343
+				/**
344
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user
345
+				 * request.
346
+				 */
347
+				trigger_error(
348
+					esc_attr(
349
+						sprintf(
350
+							__('There is no task corresponding to this route %s', 'event_espresso'),
351
+							$cron_type
352
+						)
353
+					)
354
+				);
355
+			}
356
+		}
357
+
358
+		do_action('FHEE__EED_Messages__run_cron__end');
359
+	}
360
+
361
+
362
+	/**
363
+	 * This is used to retrieve the template pack for the given name.
364
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
365
+	 * the default template pack is returned.
366
+	 *
367
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
368
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
369
+	 *                                   in generating the Pack class name).
370
+	 * @return EE_Messages_Template_Pack
371
+	 * @throws EE_Error
372
+	 * @throws InvalidArgumentException
373
+	 * @throws ReflectionException
374
+	 * @throws InvalidDataTypeException
375
+	 * @throws InvalidInterfaceException
376
+	 */
377
+	public static function get_template_pack($template_pack_name)
378
+	{
379
+		EE_Registry::instance()->load_helper('MSG_Template');
380
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
381
+	}
382
+
383
+
384
+	/**
385
+	 * Retrieves an array of all template packs.
386
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
387
+	 *
388
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
389
+	 * @return EE_Messages_Template_Pack[]
390
+	 * @throws EE_Error
391
+	 * @throws InvalidArgumentException
392
+	 * @throws ReflectionException
393
+	 * @throws InvalidDataTypeException
394
+	 * @throws InvalidInterfaceException
395
+	 */
396
+	public static function get_template_packs()
397
+	{
398
+		EE_Registry::instance()->load_helper('MSG_Template');
399
+
400
+		// for backward compat, let's make sure this returns in the same format as originally.
401
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
402
+		$template_pack_collection->rewind();
403
+		$template_packs = array();
404
+		while ($template_pack_collection->valid()) {
405
+			$template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
406
+			$template_pack_collection->next();
407
+		}
408
+		return $template_packs;
409
+	}
410
+
411
+
412
+	/**
413
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
414
+	 *
415
+	 * @since 4.5.0
416
+	 * @return void
417
+	 * @throws EE_Error
418
+	 */
419
+	public static function set_autoloaders()
420
+	{
421
+		if (empty(self::$_MSG_PATHS)) {
422
+			self::_set_messages_paths();
423
+			foreach (self::$_MSG_PATHS as $path) {
424
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
425
+			}
426
+			// add aliases
427
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
428
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
429
+		}
430
+	}
431
+
432
+
433
+	/**
434
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
435
+	 * for use by the Messages Autoloaders
436
+	 *
437
+	 * @since 4.5.0
438
+	 * @return void.
439
+	 */
440
+	protected static function _set_messages_paths()
441
+	{
442
+		$dir_ref = array(
443
+			'messages/message_type',
444
+			'messages/messenger',
445
+			'messages/defaults',
446
+			'messages/defaults/email',
447
+			'messages/data_class',
448
+			'messages/validators',
449
+			'messages/validators/email',
450
+			'messages/validators/html',
451
+			'shortcodes',
452
+		);
453
+		$paths = array();
454
+		foreach ($dir_ref as $index => $dir) {
455
+			$paths[ $index ] = EE_LIBRARIES . $dir;
456
+		}
457
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
458
+	}
459
+
460
+
461
+	/**
462
+	 * Takes care of loading dependencies
463
+	 *
464
+	 * @since 4.5.0
465
+	 * @return void
466
+	 * @throws EE_Error
467
+	 * @throws InvalidArgumentException
468
+	 * @throws ReflectionException
469
+	 * @throws InvalidDataTypeException
470
+	 * @throws InvalidInterfaceException
471
+	 */
472
+	protected static function _load_controller()
473
+	{
474
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
475
+			EE_Registry::instance()->load_core('Request_Handler');
476
+			self::set_autoloaders();
477
+			self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
478
+			self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
479
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
480
+		}
481
+	}
482
+
483
+
484
+	/**
485
+	 * @param EE_Transaction $transaction
486
+	 * @throws EE_Error
487
+	 * @throws InvalidArgumentException
488
+	 * @throws InvalidDataTypeException
489
+	 * @throws InvalidInterfaceException
490
+	 * @throws ReflectionException
491
+	 */
492
+	public static function payment_reminder(EE_Transaction $transaction)
493
+	{
494
+		self::_load_controller();
495
+		$data = array($transaction, null);
496
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
497
+	}
498
+
499
+
500
+	/**
501
+	 * Any messages triggers for after successful gateway payments should go in here.
502
+	 *
503
+	 * @param EE_Transaction  $transaction object
504
+	 * @param EE_Payment|null $payment     object
505
+	 * @return void
506
+	 * @throws EE_Error
507
+	 * @throws InvalidArgumentException
508
+	 * @throws ReflectionException
509
+	 * @throws InvalidDataTypeException
510
+	 * @throws InvalidInterfaceException
511
+	 */
512
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
513
+	{
514
+		// if there's no payment object, then we cannot do a payment type message!
515
+		if (! $payment instanceof EE_Payment) {
516
+			return;
517
+		}
518
+		self::_load_controller();
519
+		$data = array($transaction, $payment);
520
+		EE_Registry::instance()->load_helper('MSG_Template');
521
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
522
+		// if payment amount is less than 0 then switch to payment_refund message type.
523
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
524
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @param EE_Transaction $transaction
530
+	 * @throws EE_Error
531
+	 * @throws InvalidArgumentException
532
+	 * @throws InvalidDataTypeException
533
+	 * @throws InvalidInterfaceException
534
+	 * @throws ReflectionException
535
+	 */
536
+	public static function cancelled_registration(EE_Transaction $transaction)
537
+	{
538
+		self::_load_controller();
539
+		$data = array($transaction, null);
540
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
541
+	}
542
+
543
+
544
+	/**
545
+	 * Trigger for Registration messages
546
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
547
+	 * incoming transaction.
548
+	 *
549
+	 * @param EE_Registration $registration
550
+	 * @param array           $extra_details
551
+	 * @return void
552
+	 * @throws EE_Error
553
+	 * @throws InvalidArgumentException
554
+	 * @throws InvalidDataTypeException
555
+	 * @throws InvalidInterfaceException
556
+	 * @throws ReflectionException
557
+	 * @throws EntityNotFoundException
558
+	 */
559
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
560
+	{
561
+
562
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
563
+			// no messages please
564
+			return;
565
+		}
566
+
567
+		// get all non-trashed registrations so we make sure we send messages for the right status.
568
+		$all_registrations = $registration->transaction()->registrations(
569
+			array(
570
+				array('REG_deleted' => false),
571
+				'order_by' => array(
572
+					'Event.EVT_name'     => 'ASC',
573
+					'Attendee.ATT_lname' => 'ASC',
574
+					'Attendee.ATT_fname' => 'ASC',
575
+				),
576
+			)
577
+		);
578
+		// cached array of statuses so we only trigger messages once per status.
579
+		$statuses_sent = array();
580
+		self::_load_controller();
581
+		$mtgs = array();
582
+
583
+		// loop through registrations and trigger messages once per status.
584
+		foreach ($all_registrations as $reg) {
585
+			// already triggered?
586
+			if (in_array($reg->status_ID(), $statuses_sent)) {
587
+				continue;
588
+			}
589
+
590
+			$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
591
+			$mtgs = array_merge(
592
+				$mtgs,
593
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
594
+					$message_type,
595
+					array($registration->transaction(), null, $reg->status_ID())
596
+				)
597
+			);
598
+			$statuses_sent[] = $reg->status_ID();
599
+		}
600
+
601
+		if (count($statuses_sent) > 1) {
602
+			$mtgs = array_merge(
603
+				$mtgs,
604
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
605
+					'registration_summary',
606
+					array($registration->transaction(), null)
607
+				)
608
+			);
609
+		}
610
+
611
+		// batch queue and initiate request
612
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
613
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
614
+	}
615
+
616
+
617
+	/**
618
+	 * This is a helper method used to very whether a registration notification should be sent or
619
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
620
+	 *
621
+	 * @param EE_Registration $registration  [description]
622
+	 * @param array           $extra_details [description]
623
+	 * @return bool          true = send away, false = nope halt the presses.
624
+	 */
625
+	protected static function _verify_registration_notification_send(
626
+		EE_Registration $registration,
627
+		$extra_details = array()
628
+	) {
629
+		if (! $registration->is_primary_registrant()) {
630
+			return false;
631
+		}
632
+		$request = self::getRequest();
633
+		// first we check if we're in admin and not doing front ajax
634
+		if ($request->isAdmin() && ! $request->isFrontAjax()) {
635
+			$status_change = $request->getRequestParam('txn_reg_status_change', [], 'arrayOf|int');
636
+			// make sure appropriate admin params are set for sending messages
637
+			if (! $status_change['send_notifications']) {
638
+				// no messages sent please.
639
+				return false;
640
+			}
641
+		} else {
642
+			// frontend request (either regular or via AJAX)
643
+			// TXN is NOT finalized ?
644
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
645
+				return false;
646
+			}
647
+			// return visit but nothing changed ???
648
+			if (isset($extra_details['revisit'], $extra_details['status_updates']) &&
649
+				$extra_details['revisit'] && ! $extra_details['status_updates']
650
+			) {
651
+				return false;
652
+			}
653
+			// NOT sending messages && reg status is something other than "Not-Approved"
654
+			if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
655
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
656
+			) {
657
+				return false;
658
+			}
659
+		}
660
+		// release the kraken
661
+		return true;
662
+	}
663
+
664
+
665
+	/**
666
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
667
+	 * status id.
668
+	 *
669
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
670
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
671
+	 * @param string $reg_status
672
+	 * @return array
673
+	 * @throws EE_Error
674
+	 * @throws InvalidArgumentException
675
+	 * @throws ReflectionException
676
+	 * @throws InvalidDataTypeException
677
+	 * @throws InvalidInterfaceException
678
+	 */
679
+	protected static function _get_reg_status_array($reg_status = '')
680
+	{
681
+		EE_Registry::instance()->load_helper('MSG_Template');
682
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
683
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
684
+			: EEH_MSG_Template::reg_status_to_message_type_array();
685
+	}
686
+
687
+
688
+	/**
689
+	 * Simply returns the payment message type for the given payment status.
690
+	 *
691
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
692
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
693
+	 * @param string $payment_status The payment status being matched.
694
+	 * @return bool|string The payment message type slug matching the status or false if no match.
695
+	 * @throws EE_Error
696
+	 * @throws InvalidArgumentException
697
+	 * @throws ReflectionException
698
+	 * @throws InvalidDataTypeException
699
+	 * @throws InvalidInterfaceException
700
+	 */
701
+	protected static function _get_payment_message_type($payment_status)
702
+	{
703
+		EE_Registry::instance()->load_helper('MSG_Template');
704
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
705
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
706
+			: false;
707
+	}
708
+
709
+
710
+	/**
711
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
712
+	 *
713
+	 * @access public
714
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
715
+	 * @return bool success/fail
716
+	 * @throws EE_Error
717
+	 * @throws InvalidArgumentException
718
+	 * @throws InvalidDataTypeException
719
+	 * @throws InvalidInterfaceException
720
+	 * @throws ReflectionException
721
+	 */
722
+	public static function process_resend($req_data)
723
+	{
724
+		self::_load_controller();
725
+		$request = self::getRequest();
726
+		// if $msgID in this request then skip to the new resend_message
727
+		if ($request->getRequestParam('MSG_ID')) {
728
+			return self::resend_message();
729
+		}
730
+
731
+		// make sure any incoming request data is set on the request so that it gets picked up later.
732
+		$req_data = (array) $req_data;
733
+		foreach ($req_data as $request_key => $request_value) {
734
+			$request->setRequestParam($request_key, $request_value);
735
+		}
736
+
737
+		if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request(
738
+		)) {
739
+			return false;
740
+		}
741
+
742
+		try {
743
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
744
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
745
+		} catch (EE_Error $e) {
746
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
747
+			return false;
748
+		}
749
+		EE_Error::add_success(
750
+			__('Messages have been successfully queued for generation and sending.', 'event_espresso')
751
+		);
752
+		return true; // everything got queued.
753
+	}
754
+
755
+
756
+	/**
757
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
758
+	 *
759
+	 * @return bool
760
+	 * @throws EE_Error
761
+	 * @throws InvalidArgumentException
762
+	 * @throws InvalidDataTypeException
763
+	 * @throws InvalidInterfaceException
764
+	 * @throws ReflectionException
765
+	 */
766
+	public static function resend_message()
767
+	{
768
+		self::_load_controller();
769
+
770
+		$msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
771
+		if (! $msgID) {
772
+			EE_Error::add_error(
773
+				__(
774
+					'Something went wrong because there is no "MSG_ID" value in the request',
775
+					'event_espresso'
776
+				),
777
+				__FILE__,
778
+				__FUNCTION__,
779
+				__LINE__
780
+			);
781
+			return false;
782
+		}
783
+
784
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
785
+
786
+		// setup success message.
787
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
788
+		EE_Error::add_success(
789
+			sprintf(
790
+				_n(
791
+					'There was %d message queued for resending.',
792
+					'There were %d messages queued for resending.',
793
+					$count_ready_for_resend,
794
+					'event_espresso'
795
+				),
796
+				$count_ready_for_resend
797
+			)
798
+		);
799
+		return true;
800
+	}
801
+
802
+
803
+	/**
804
+	 * Message triggers for manual payment applied by admin
805
+	 *
806
+	 * @param  EE_Payment $payment EE_payment object
807
+	 * @return bool success/fail
808
+	 * @throws EE_Error
809
+	 * @throws InvalidArgumentException
810
+	 * @throws ReflectionException
811
+	 * @throws InvalidDataTypeException
812
+	 * @throws InvalidInterfaceException
813
+	 */
814
+	public static function process_admin_payment(EE_Payment $payment)
815
+	{
816
+		EE_Registry::instance()->load_helper('MSG_Template');
817
+		// we need to get the transaction object
818
+		$transaction = $payment->transaction();
819
+		if ($transaction instanceof EE_Transaction) {
820
+			$data = array($transaction, $payment);
821
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
822
+
823
+			// if payment amount is less than 0 then switch to payment_refund message type.
824
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
825
+
826
+			// if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
827
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
828
+				? false : $message_type;
829
+
830
+			self::_load_controller();
831
+
832
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
833
+
834
+			// get count of queued for generation
835
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
836
+				array(
837
+					EEM_Message::status_incomplete,
838
+					EEM_Message::status_idle,
839
+				)
840
+			);
841
+
842
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
843
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
844
+				return true;
845
+			} else {
846
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
847
+					EEM_Message::instance()->stati_indicating_failed_sending()
848
+				);
849
+				/**
850
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
851
+				 * IMMEDIATE generation.
852
+				 */
853
+				if ($count_failed > 0) {
854
+					EE_Error::add_error(
855
+						sprintf(
856
+							_n(
857
+								'The payment notification generation failed.',
858
+								'%d payment notifications failed being sent.',
859
+								$count_failed,
860
+								'event_espresso'
861
+							),
862
+							$count_failed
863
+						),
864
+						__FILE__,
865
+						__FUNCTION__,
866
+						__LINE__
867
+					);
868
+
869
+					return false;
870
+				} else {
871
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
872
+					return true;
873
+				}
874
+			}
875
+		} else {
876
+			EE_Error::add_error(
877
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
878
+				'event_espresso'
879
+			);
880
+			return false;
881
+		}
882
+	}
883
+
884
+
885
+	/**
886
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
887
+	 *
888
+	 * @since   4.3.0
889
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
890
+	 * @param  int               $grp_id        a specific message template group id.
891
+	 * @return void
892
+	 * @throws EE_Error
893
+	 * @throws InvalidArgumentException
894
+	 * @throws InvalidDataTypeException
895
+	 * @throws InvalidInterfaceException
896
+	 * @throws ReflectionException
897
+	 */
898
+	public static function send_newsletter_message($registrations, $grp_id)
899
+	{
900
+		// make sure mtp is id and set it in the request later messages setup.
901
+		self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
902
+		self::_load_controller();
903
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
904
+	}
905
+
906
+
907
+	/**
908
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
909
+	 *
910
+	 * @since   4.3.0
911
+	 * @param    string          $registration_message_trigger_url
912
+	 * @param    EE_Registration $registration
913
+	 * @param string             $messenger
914
+	 * @param string             $message_type
915
+	 * @return string
916
+	 * @throws EE_Error
917
+	 * @throws InvalidArgumentException
918
+	 * @throws InvalidDataTypeException
919
+	 * @throws InvalidInterfaceException
920
+	 */
921
+	public static function registration_message_trigger_url(
922
+		$registration_message_trigger_url,
923
+		EE_Registration $registration,
924
+		$messenger = 'html',
925
+		$message_type = 'invoice'
926
+	) {
927
+		// whitelist $messenger
928
+		switch ($messenger) {
929
+			case 'pdf':
930
+				$sending_messenger = 'pdf';
931
+				$generating_messenger = 'html';
932
+				break;
933
+			case 'html':
934
+			default:
935
+				$sending_messenger = 'html';
936
+				$generating_messenger = 'html';
937
+				break;
938
+		}
939
+		// whitelist $message_type
940
+		switch ($message_type) {
941
+			case 'receipt':
942
+				$message_type = 'receipt';
943
+				break;
944
+			case 'invoice':
945
+			default:
946
+				$message_type = 'invoice';
947
+				break;
948
+		}
949
+		// verify that both the messenger AND the message type are active
950
+		if (EEH_MSG_Template::is_messenger_active($sending_messenger)
951
+			&& EEH_MSG_Template::is_mt_active($message_type)
952
+		) {
953
+			// need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
954
+			$template_query_params = array(
955
+				'MTP_is_active'    => true,
956
+				'MTP_messenger'    => $generating_messenger,
957
+				'MTP_message_type' => $message_type,
958
+				'Event.EVT_ID'     => $registration->event_ID(),
959
+			);
960
+			// get the message template group.
961
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
962
+			// if we don't have an EE_Message_Template_Group then return
963
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
964
+				// remove EVT_ID from query params so that global templates get picked up
965
+				unset($template_query_params['Event.EVT_ID']);
966
+				// get global template as the fallback
967
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
968
+			}
969
+			// if we don't have an EE_Message_Template_Group then return
970
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
971
+				return '';
972
+			}
973
+			// generate the URL
974
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
975
+				$sending_messenger,
976
+				$generating_messenger,
977
+				'purchaser',
978
+				$message_type,
979
+				$registration,
980
+				$msg_template_group->ID(),
981
+				$registration->transaction_ID()
982
+			);
983
+		}
984
+		return $registration_message_trigger_url;
985
+	}
986
+
987
+
988
+	/**
989
+	 * Use to generate and return a message preview!
990
+	 *
991
+	 * @param  string $type      This should correspond with a valid message type
992
+	 * @param  string $context   This should correspond with a valid context for the message type
993
+	 * @param  string $messenger This should correspond with a valid messenger.
994
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
995
+	 *                           preview
996
+	 * @return bool|string The body of the message or if send is requested, sends.
997
+	 * @throws EE_Error
998
+	 * @throws InvalidArgumentException
999
+	 * @throws InvalidDataTypeException
1000
+	 * @throws InvalidInterfaceException
1001
+	 * @throws ReflectionException
1002
+	 */
1003
+	public static function preview_message($type, $context, $messenger, $send = false)
1004
+	{
1005
+		self::_load_controller();
1006
+		$mtg = new EE_Message_To_Generate(
1007
+			$messenger,
1008
+			$type,
1009
+			array(),
1010
+			$context,
1011
+			true
1012
+		);
1013
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1014
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
1015
+			// loop through all content for the preview and remove any persisted records.
1016
+			$content = '';
1017
+			foreach ($generated_preview_queue->get_message_repository() as $message) {
1018
+				$content = $message->content();
1019
+				if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1020
+					$message->delete();
1021
+				}
1022
+			}
1023
+			return $content;
1024
+		} else {
1025
+			return $generated_preview_queue;
1026
+		}
1027
+	}
1028
+
1029
+
1030
+	/**
1031
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
1032
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1033
+	 * content found in the EE_Message objects in the queue.
1034
+	 *
1035
+	 * @since 4.9.0
1036
+	 * @param string            $messenger            a string matching a valid active messenger in the system
1037
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
1038
+	 *                                                type name is still required to send along the message type to the
1039
+	 *                                                messenger because this is used for determining what specific
1040
+	 *                                                variations might be loaded for the generated message.
1041
+	 * @param EE_Messages_Queue $queue
1042
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1043
+	 *                                                aggregate EE_Message object.
1044
+	 * @return bool success or fail.
1045
+	 * @throws EE_Error
1046
+	 * @throws InvalidArgumentException
1047
+	 * @throws ReflectionException
1048
+	 * @throws InvalidDataTypeException
1049
+	 * @throws InvalidInterfaceException
1050
+	 */
1051
+	public static function send_message_with_messenger_only(
1052
+		$messenger,
1053
+		$message_type,
1054
+		EE_Messages_Queue $queue,
1055
+		$custom_subject = ''
1056
+	) {
1057
+		self::_load_controller();
1058
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1059
+		$message_to_generate = EE_Registry::instance()->load_lib(
1060
+			'Message_To_Generate_From_Queue',
1061
+			array(
1062
+				$messenger,
1063
+				$message_type,
1064
+				$queue,
1065
+				$custom_subject,
1066
+			)
1067
+		);
1068
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1074
+	 *
1075
+	 * @since 4.9.0
1076
+	 * @param array $message_ids An array of message ids
1077
+	 * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1078
+	 *                           messages.
1079
+	 * @throws EE_Error
1080
+	 * @throws InvalidArgumentException
1081
+	 * @throws InvalidDataTypeException
1082
+	 * @throws InvalidInterfaceException
1083
+	 * @throws ReflectionException
1084
+	 */
1085
+	public static function generate_now($message_ids)
1086
+	{
1087
+		self::_load_controller();
1088
+		$messages = EEM_Message::instance()->get_all(
1089
+			array(
1090
+				0 => array(
1091
+					'MSG_ID' => array('IN', $message_ids),
1092
+					'STS_ID' => EEM_Message::status_incomplete,
1093
+				),
1094
+			)
1095
+		);
1096
+		$generated_queue = false;
1097
+		if ($messages) {
1098
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1099
+		}
1100
+
1101
+		if (! $generated_queue instanceof EE_Messages_Queue) {
1102
+			EE_Error::add_error(
1103
+				__(
1104
+					'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1105
+					'event_espresso'
1106
+				),
1107
+				__FILE__,
1108
+				__FUNCTION__,
1109
+				__LINE__
1110
+			);
1111
+		}
1112
+		return $generated_queue;
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1118
+	 * EEM_Message::status_idle
1119
+	 *
1120
+	 * @since 4.9.0
1121
+	 * @param $message_ids
1122
+	 * @return bool|EE_Messages_Queue false if no messages sent.
1123
+	 * @throws EE_Error
1124
+	 * @throws InvalidArgumentException
1125
+	 * @throws InvalidDataTypeException
1126
+	 * @throws InvalidInterfaceException
1127
+	 * @throws ReflectionException
1128
+	 */
1129
+	public static function send_now($message_ids)
1130
+	{
1131
+		self::_load_controller();
1132
+		$messages = EEM_Message::instance()->get_all(
1133
+			array(
1134
+				0 => array(
1135
+					'MSG_ID' => array('IN', $message_ids),
1136
+					'STS_ID' => array(
1137
+						'IN',
1138
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1139
+					),
1140
+				),
1141
+			)
1142
+		);
1143
+		$sent_queue = false;
1144
+		if ($messages) {
1145
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1146
+		}
1147
+
1148
+		if (! $sent_queue instanceof EE_Messages_Queue) {
1149
+			EE_Error::add_error(
1150
+				__(
1151
+					'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1152
+					'event_espresso'
1153
+				),
1154
+				__FILE__,
1155
+				__FUNCTION__,
1156
+				__LINE__
1157
+			);
1158
+		} else {
1159
+			// can count how many sent by using the messages in the queue
1160
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1161
+			if ($sent_count > 0) {
1162
+				EE_Error::add_success(
1163
+					sprintf(
1164
+						_n(
1165
+							'There was %d message successfully sent.',
1166
+							'There were %d messages successfully sent.',
1167
+							$sent_count,
1168
+							'event_espresso'
1169
+						),
1170
+						$sent_count
1171
+					)
1172
+				);
1173
+			} else {
1174
+				EE_Error::overwrite_errors();
1175
+				EE_Error::add_error(
1176
+					__(
1177
+						'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
1178 1178
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
1179
-                        'event_espresso'
1180
-                    ),
1181
-                    __FILE__,
1182
-                    __FUNCTION__,
1183
-                    __LINE__
1184
-                );
1185
-            }
1186
-        }
1187
-        return $sent_queue;
1188
-    }
1189
-
1190
-
1191
-    /**
1192
-     * Generate and send immediately from the given $message_ids
1193
-     *
1194
-     * @param array $message_ids EE_Message entity ids.
1195
-     * @throws EE_Error
1196
-     * @throws InvalidArgumentException
1197
-     * @throws InvalidDataTypeException
1198
-     * @throws InvalidInterfaceException
1199
-     * @throws ReflectionException
1200
-     */
1201
-    public static function generate_and_send_now(array $message_ids)
1202
-    {
1203
-        $generated_queue = self::generate_now($message_ids);
1204
-        // now let's just trigger sending immediately from this queue.
1205
-        $messages_sent = $generated_queue instanceof EE_Messages_Queue
1206
-            ? $generated_queue->execute()
1207
-            : 0;
1208
-        if ($messages_sent) {
1209
-            EE_Error::add_success(
1210
-                esc_html(
1211
-                    sprintf(
1212
-                        _n(
1213
-                            'There was %d message successfully generated and sent.',
1214
-                            'There were %d messages successfully generated and sent.',
1215
-                            $messages_sent,
1216
-                            'event_espresso'
1217
-                        ),
1218
-                        $messages_sent
1219
-                    )
1220
-                )
1221
-            );
1222
-            // errors would be added via the generate_now method.
1223
-        }
1224
-    }
1225
-
1226
-
1227
-    /**
1228
-     * This will queue the incoming message ids for resending.
1229
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1230
-     *
1231
-     * @since 4.9.0
1232
-     * @param array $message_ids An array of EE_Message IDs
1233
-     * @return bool true means messages were successfully queued for resending, false means none were queued for
1234
-     *                           resending.
1235
-     * @throws EE_Error
1236
-     * @throws InvalidArgumentException
1237
-     * @throws InvalidDataTypeException
1238
-     * @throws InvalidInterfaceException
1239
-     * @throws ReflectionException
1240
-     */
1241
-    public static function queue_for_resending($message_ids)
1242
-    {
1243
-        self::_load_controller();
1244
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1245
-
1246
-        // get queue and count
1247
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1248
-
1249
-        if ($queue_count > 0
1250
-        ) {
1251
-            EE_Error::add_success(
1252
-                sprintf(
1253
-                    _n(
1254
-                        '%d message successfully queued for resending.',
1255
-                        '%d messages successfully queued for resending.',
1256
-                        $queue_count,
1257
-                        'event_espresso'
1258
-                    ),
1259
-                    $queue_count
1260
-                )
1261
-            );
1262
-            /**
1263
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1264
-             */
1265
-        } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1266
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1267
-        ) {
1268
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1269
-            if ($queue_count > 0) {
1270
-                EE_Error::add_success(
1271
-                    sprintf(
1272
-                        _n(
1273
-                            '%d message successfully sent.',
1274
-                            '%d messages successfully sent.',
1275
-                            $queue_count,
1276
-                            'event_espresso'
1277
-                        ),
1278
-                        $queue_count
1279
-                    )
1280
-                );
1281
-            } else {
1282
-                EE_Error::add_error(
1283
-                    __(
1284
-                        'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1285
-                        'event_espresso'
1286
-                    ),
1287
-                    __FILE__,
1288
-                    __FUNCTION__,
1289
-                    __LINE__
1290
-                );
1291
-            }
1292
-        } else {
1293
-            EE_Error::add_error(
1294
-                __(
1295
-                    'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1296
-                    'event_espresso'
1297
-                ),
1298
-                __FILE__,
1299
-                __FUNCTION__,
1300
-                __LINE__
1301
-            );
1302
-        }
1303
-        return (bool) $queue_count;
1304
-    }
1305
-
1306
-
1307
-    /**
1308
-     * debug
1309
-     *
1310
-     * @param string          $class
1311
-     * @param string          $func
1312
-     * @param string          $line
1313
-     * @param \EE_Transaction $transaction
1314
-     * @param array           $info
1315
-     * @param bool            $display_request
1316
-     * @throws EE_Error
1317
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1318
-     */
1319
-    protected static function log(
1320
-        $class = '',
1321
-        $func = '',
1322
-        $line = '',
1323
-        EE_Transaction $transaction,
1324
-        $info = array(),
1325
-        $display_request = false
1326
-    ) {
1327
-        if (defined('EE_DEBUG') && EE_DEBUG) {
1328
-            if ($transaction instanceof EE_Transaction) {
1329
-                // don't serialize objects
1330
-                $info = EEH_Debug_Tools::strip_objects($info);
1331
-                $info['TXN_status'] = $transaction->status_ID();
1332
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1333
-                if ($transaction->ID()) {
1334
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1335
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1336
-                }
1337
-            }
1338
-        }
1339
-    }
1340
-
1341
-
1342
-    /**
1343
-     *  Resets all the static properties in this class when called.
1344
-     */
1345
-    public static function reset()
1346
-    {
1347
-        self::$_EEMSG = null;
1348
-        self::$_message_resource_manager = null;
1349
-        self::$_MSG_PROCESSOR = null;
1350
-        self::$_MSG_PATHS = null;
1351
-        self::$_TMP_PACKS = array();
1352
-    }
1179
+						'event_espresso'
1180
+					),
1181
+					__FILE__,
1182
+					__FUNCTION__,
1183
+					__LINE__
1184
+				);
1185
+			}
1186
+		}
1187
+		return $sent_queue;
1188
+	}
1189
+
1190
+
1191
+	/**
1192
+	 * Generate and send immediately from the given $message_ids
1193
+	 *
1194
+	 * @param array $message_ids EE_Message entity ids.
1195
+	 * @throws EE_Error
1196
+	 * @throws InvalidArgumentException
1197
+	 * @throws InvalidDataTypeException
1198
+	 * @throws InvalidInterfaceException
1199
+	 * @throws ReflectionException
1200
+	 */
1201
+	public static function generate_and_send_now(array $message_ids)
1202
+	{
1203
+		$generated_queue = self::generate_now($message_ids);
1204
+		// now let's just trigger sending immediately from this queue.
1205
+		$messages_sent = $generated_queue instanceof EE_Messages_Queue
1206
+			? $generated_queue->execute()
1207
+			: 0;
1208
+		if ($messages_sent) {
1209
+			EE_Error::add_success(
1210
+				esc_html(
1211
+					sprintf(
1212
+						_n(
1213
+							'There was %d message successfully generated and sent.',
1214
+							'There were %d messages successfully generated and sent.',
1215
+							$messages_sent,
1216
+							'event_espresso'
1217
+						),
1218
+						$messages_sent
1219
+					)
1220
+				)
1221
+			);
1222
+			// errors would be added via the generate_now method.
1223
+		}
1224
+	}
1225
+
1226
+
1227
+	/**
1228
+	 * This will queue the incoming message ids for resending.
1229
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1230
+	 *
1231
+	 * @since 4.9.0
1232
+	 * @param array $message_ids An array of EE_Message IDs
1233
+	 * @return bool true means messages were successfully queued for resending, false means none were queued for
1234
+	 *                           resending.
1235
+	 * @throws EE_Error
1236
+	 * @throws InvalidArgumentException
1237
+	 * @throws InvalidDataTypeException
1238
+	 * @throws InvalidInterfaceException
1239
+	 * @throws ReflectionException
1240
+	 */
1241
+	public static function queue_for_resending($message_ids)
1242
+	{
1243
+		self::_load_controller();
1244
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1245
+
1246
+		// get queue and count
1247
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1248
+
1249
+		if ($queue_count > 0
1250
+		) {
1251
+			EE_Error::add_success(
1252
+				sprintf(
1253
+					_n(
1254
+						'%d message successfully queued for resending.',
1255
+						'%d messages successfully queued for resending.',
1256
+						$queue_count,
1257
+						'event_espresso'
1258
+					),
1259
+					$queue_count
1260
+				)
1261
+			);
1262
+			/**
1263
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1264
+			 */
1265
+		} elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1266
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1267
+		) {
1268
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1269
+			if ($queue_count > 0) {
1270
+				EE_Error::add_success(
1271
+					sprintf(
1272
+						_n(
1273
+							'%d message successfully sent.',
1274
+							'%d messages successfully sent.',
1275
+							$queue_count,
1276
+							'event_espresso'
1277
+						),
1278
+						$queue_count
1279
+					)
1280
+				);
1281
+			} else {
1282
+				EE_Error::add_error(
1283
+					__(
1284
+						'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1285
+						'event_espresso'
1286
+					),
1287
+					__FILE__,
1288
+					__FUNCTION__,
1289
+					__LINE__
1290
+				);
1291
+			}
1292
+		} else {
1293
+			EE_Error::add_error(
1294
+				__(
1295
+					'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1296
+					'event_espresso'
1297
+				),
1298
+				__FILE__,
1299
+				__FUNCTION__,
1300
+				__LINE__
1301
+			);
1302
+		}
1303
+		return (bool) $queue_count;
1304
+	}
1305
+
1306
+
1307
+	/**
1308
+	 * debug
1309
+	 *
1310
+	 * @param string          $class
1311
+	 * @param string          $func
1312
+	 * @param string          $line
1313
+	 * @param \EE_Transaction $transaction
1314
+	 * @param array           $info
1315
+	 * @param bool            $display_request
1316
+	 * @throws EE_Error
1317
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1318
+	 */
1319
+	protected static function log(
1320
+		$class = '',
1321
+		$func = '',
1322
+		$line = '',
1323
+		EE_Transaction $transaction,
1324
+		$info = array(),
1325
+		$display_request = false
1326
+	) {
1327
+		if (defined('EE_DEBUG') && EE_DEBUG) {
1328
+			if ($transaction instanceof EE_Transaction) {
1329
+				// don't serialize objects
1330
+				$info = EEH_Debug_Tools::strip_objects($info);
1331
+				$info['TXN_status'] = $transaction->status_ID();
1332
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1333
+				if ($transaction->ID()) {
1334
+					$index = 'EE_Transaction: ' . $transaction->ID();
1335
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1336
+				}
1337
+			}
1338
+		}
1339
+	}
1340
+
1341
+
1342
+	/**
1343
+	 *  Resets all the static properties in this class when called.
1344
+	 */
1345
+	public static function reset()
1346
+	{
1347
+		self::$_EEMSG = null;
1348
+		self::$_message_resource_manager = null;
1349
+		self::$_MSG_PROCESSOR = null;
1350
+		self::$_MSG_PATHS = null;
1351
+		self::$_TMP_PACKS = array();
1352
+	}
1353 1353
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                 'event_espresso'
205 205
             );
206 206
             // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
207
+            $error_msg .= '||'.$e->getMessage();
208 208
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209 209
         }
210 210
     }
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
                 'event_espresso'
292 292
             );
293 293
             // add specific message for developers if WP_DEBUG in on
294
-            $error_msg .= '||' . $e->getMessage();
294
+            $error_msg .= '||'.$e->getMessage();
295 295
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
296 296
         }
297 297
     }
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
         $transient_key = $request->getRequestParam('key');
324 324
 
325 325
         // now let's verify transient, if not valid exit immediately
326
-        if (! get_transient($transient_key)) {
326
+        if ( ! get_transient($transient_key)) {
327 327
             /**
328 328
              * trigger error so this gets in the error logs.  This is important because it happens on a non-user
329 329
              * request.
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         delete_transient($transient_key);
336 336
 
337 337
         if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
338
-            $method = 'batch_' . $cron_type . '_from_queue';
338
+            $method = 'batch_'.$cron_type.'_from_queue';
339 339
             if (method_exists(self::$_MSG_PROCESSOR, $method)) {
340 340
                 self::$_MSG_PROCESSOR->$method();
341 341
             } else {
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
         $template_pack_collection->rewind();
403 403
         $template_packs = array();
404 404
         while ($template_pack_collection->valid()) {
405
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
+            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
406 406
             $template_pack_collection->next();
407 407
         }
408 408
         return $template_packs;
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         );
453 453
         $paths = array();
454 454
         foreach ($dir_ref as $index => $dir) {
455
-            $paths[ $index ] = EE_LIBRARIES . $dir;
455
+            $paths[$index] = EE_LIBRARIES.$dir;
456 456
         }
457 457
         self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
458 458
     }
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
      */
472 472
     protected static function _load_controller()
473 473
     {
474
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474
+        if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
475 475
             EE_Registry::instance()->load_core('Request_Handler');
476 476
             self::set_autoloaders();
477 477
             self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
     public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
513 513
     {
514 514
         // if there's no payment object, then we cannot do a payment type message!
515
-        if (! $payment instanceof EE_Payment) {
515
+        if ( ! $payment instanceof EE_Payment) {
516 516
             return;
517 517
         }
518 518
         self::_load_controller();
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
     public static function maybe_registration(EE_Registration $registration, $extra_details = array())
560 560
     {
561 561
 
562
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
562
+        if ( ! self::_verify_registration_notification_send($registration, $extra_details)) {
563 563
             // no messages please
564 564
             return;
565 565
         }
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
         EE_Registration $registration,
627 627
         $extra_details = array()
628 628
     ) {
629
-        if (! $registration->is_primary_registrant()) {
629
+        if ( ! $registration->is_primary_registrant()) {
630 630
             return false;
631 631
         }
632 632
         $request = self::getRequest();
@@ -634,14 +634,14 @@  discard block
 block discarded – undo
634 634
         if ($request->isAdmin() && ! $request->isFrontAjax()) {
635 635
             $status_change = $request->getRequestParam('txn_reg_status_change', [], 'arrayOf|int');
636 636
             // make sure appropriate admin params are set for sending messages
637
-            if (! $status_change['send_notifications']) {
637
+            if ( ! $status_change['send_notifications']) {
638 638
                 // no messages sent please.
639 639
                 return false;
640 640
             }
641 641
         } else {
642 642
             // frontend request (either regular or via AJAX)
643 643
             // TXN is NOT finalized ?
644
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
644
+            if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
645 645
                 return false;
646 646
             }
647 647
             // return visit but nothing changed ???
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
                 return false;
652 652
             }
653 653
             // NOT sending messages && reg status is something other than "Not-Approved"
654
-            if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
654
+            if ( ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
655 655
                 $registration->status_ID() !== EEM_Registration::status_id_not_approved
656 656
             ) {
657 657
                 return false;
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             $request->setRequestParam($request_key, $request_value);
735 735
         }
736 736
 
737
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request(
737
+        if ( ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request(
738 738
         )) {
739 739
             return false;
740 740
         }
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
         self::_load_controller();
769 769
 
770 770
         $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
771
-        if (! $msgID) {
771
+        if ( ! $msgID) {
772 772
             EE_Error::add_error(
773 773
                 __(
774 774
                     'Something went wrong because there is no "MSG_ID" value in the request',
@@ -960,14 +960,14 @@  discard block
 block discarded – undo
960 960
             // get the message template group.
961 961
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
962 962
             // if we don't have an EE_Message_Template_Group then return
963
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
963
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
964 964
                 // remove EVT_ID from query params so that global templates get picked up
965 965
                 unset($template_query_params['Event.EVT_ID']);
966 966
                 // get global template as the fallback
967 967
                 $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
968 968
             }
969 969
             // if we don't have an EE_Message_Template_Group then return
970
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
970
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
971 971
                 return '';
972 972
             }
973 973
             // generate the URL
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
             $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1099 1099
         }
1100 1100
 
1101
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1101
+        if ( ! $generated_queue instanceof EE_Messages_Queue) {
1102 1102
             EE_Error::add_error(
1103 1103
                 __(
1104 1104
                     'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
             $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1146 1146
         }
1147 1147
 
1148
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1148
+        if ( ! $sent_queue instanceof EE_Messages_Queue) {
1149 1149
             EE_Error::add_error(
1150 1150
                 __(
1151 1151
                     'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
                 $info['TXN_status'] = $transaction->status_ID();
1332 1332
                 $info['TXN_reg_steps'] = $transaction->reg_steps();
1333 1333
                 if ($transaction->ID()) {
1334
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1334
+                    $index = 'EE_Transaction: '.$transaction->ID();
1335 1335
                     EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1336 1336
                 }
1337 1337
             }
Please login to merge, or discard this patch.
modules/bot_trap/EED_Bot_Trap.module.php 1 patch
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -17,306 +17,306 @@
 block discarded – undo
17 17
 class EED_Bot_Trap extends EED_Module
18 18
 {
19 19
 
20
-    /**
21
-     * @return EED_Module|EED_Bot_Trap
22
-     * @throws EE_Error
23
-     * @throws ReflectionException
24
-     */
25
-    public static function instance()
26
-    {
27
-        return parent::get_instance(__CLASS__);
28
-    }
20
+	/**
21
+	 * @return EED_Module|EED_Bot_Trap
22
+	 * @throws EE_Error
23
+	 * @throws ReflectionException
24
+	 */
25
+	public static function instance()
26
+	{
27
+		return parent::get_instance(__CLASS__);
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * set_hooks - for hooking into EE Core, other modules, etc
33
-     *
34
-     * @return void
35
-     */
36
-    public static function set_hooks()
37
-    {
38
-        if (apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) &&
39
-            EE_Registry::instance()->CFG->registration->use_bot_trap
40
-        ) {
41
-            EED_Bot_Trap::set_trap();
42
-            // redirect bots to bogus success page
43
-            EE_Config::register_route(
44
-                'ticket_selection_received',
45
-                'EED_Bot_Trap',
46
-                'display_bot_trap_success'
47
-            );
48
-        }
49
-    }
31
+	/**
32
+	 * set_hooks - for hooking into EE Core, other modules, etc
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public static function set_hooks()
37
+	{
38
+		if (apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) &&
39
+			EE_Registry::instance()->CFG->registration->use_bot_trap
40
+		) {
41
+			EED_Bot_Trap::set_trap();
42
+			// redirect bots to bogus success page
43
+			EE_Config::register_route(
44
+				'ticket_selection_received',
45
+				'EED_Bot_Trap',
46
+				'display_bot_trap_success'
47
+			);
48
+		}
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
54
-     *
55
-     * @return void
56
-     */
57
-    public static function set_trap()
58
-    {
59
-        define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/');
60
-        add_action(
61
-            'AHEE__ticket_selector_chart__template__after_ticket_selector',
62
-            array('EED_Bot_Trap', 'generate_bot_trap'),
63
-            10,
64
-            2
65
-        );
66
-        add_action(
67
-            'EED_Ticket_Selector__process_ticket_selections__before',
68
-            array('EED_Bot_Trap', 'process_bot_trap'),
69
-            1,
70
-            2
71
-        );
72
-    }
52
+	/**
53
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
54
+	 *
55
+	 * @return void
56
+	 */
57
+	public static function set_trap()
58
+	{
59
+		define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . '/');
60
+		add_action(
61
+			'AHEE__ticket_selector_chart__template__after_ticket_selector',
62
+			array('EED_Bot_Trap', 'generate_bot_trap'),
63
+			10,
64
+			2
65
+		);
66
+		add_action(
67
+			'EED_Ticket_Selector__process_ticket_selections__before',
68
+			array('EED_Bot_Trap', 'process_bot_trap'),
69
+			1,
70
+			2
71
+		);
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
77
-     *
78
-     * @return void
79
-     */
80
-    public static function set_hooks_admin()
81
-    {
82
-        if (defined('DOING_AJAX')
83
-            && DOING_AJAX
84
-            && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true)
85
-            && EE_Registry::instance()->CFG->registration->use_bot_trap
86
-        ) {
87
-            EED_Bot_Trap::set_trap();
88
-        }
89
-        add_action(
90
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
91
-            array('EED_Bot_Trap', 'bot_trap_settings_form'),
92
-            5
93
-        );
94
-        add_filter(
95
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
96
-            array('EED_Bot_Trap', 'update_bot_trap_settings_form'),
97
-            10,
98
-            1
99
-        );
100
-    }
75
+	/**
76
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
77
+	 *
78
+	 * @return void
79
+	 */
80
+	public static function set_hooks_admin()
81
+	{
82
+		if (defined('DOING_AJAX')
83
+			&& DOING_AJAX
84
+			&& apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true)
85
+			&& EE_Registry::instance()->CFG->registration->use_bot_trap
86
+		) {
87
+			EED_Bot_Trap::set_trap();
88
+		}
89
+		add_action(
90
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
91
+			array('EED_Bot_Trap', 'bot_trap_settings_form'),
92
+			5
93
+		);
94
+		add_filter(
95
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
96
+			array('EED_Bot_Trap', 'update_bot_trap_settings_form'),
97
+			10,
98
+			1
99
+		);
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * run - initial module setup
105
-     *
106
-     * @param WP $WP
107
-     * @return void
108
-     */
109
-    public function run($WP)
110
-    {
111
-    }
103
+	/**
104
+	 * run - initial module setup
105
+	 *
106
+	 * @param WP $WP
107
+	 * @return void
108
+	 */
109
+	public function run($WP)
110
+	{
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * generate_bot_trap
116
-     *
117
-     * @return void
118
-     * @throws RuntimeException
119
-     */
120
-    public static function generate_bot_trap()
121
-    {
122
-        $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso');
123
-        $time = microtime(true);
124
-        $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">';
125
-        $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>';
126
-        $html .= '<input type="email" id="tkt-slctr-request-processor-email-';
127
-        $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>';
128
-        $html .= '</div><!-- .tkt-slctr-request-processor-dv -->';
129
-        echo $html;
130
-    }
114
+	/**
115
+	 * generate_bot_trap
116
+	 *
117
+	 * @return void
118
+	 * @throws RuntimeException
119
+	 */
120
+	public static function generate_bot_trap()
121
+	{
122
+		$do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso');
123
+		$time = microtime(true);
124
+		$html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">';
125
+		$html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>';
126
+		$html .= '<input type="email" id="tkt-slctr-request-processor-email-';
127
+		$html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>';
128
+		$html .= '</div><!-- .tkt-slctr-request-processor-dv -->';
129
+		echo $html;
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * process_bot_trap
135
-     *
136
-     * @param array|string $triggered_trap_callback Callback that will be executed for handling the
137
-     *                                              response if the bot trap is triggered.
138
-     *                                              It should receive one argument: a boolean indicating
139
-     *                                              whether the trap was triggered by suspicious timing or not.
140
-     * @throws RuntimeException
141
-     */
142
-    public static function process_bot_trap($triggered_trap_callback = array())
143
-    {
144
-        // what's your email address Mr. Bot ?
145
-        $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email'])
146
-                      && $_REQUEST['tkt-slctr-request-processor-email'] === '';
147
-        // are we human ?
148
-        if ($empty_trap) {
149
-            do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered');
150
-            return;
151
-        }
152
-        // check the given callback is valid first before executing
153
-        if (! is_callable($triggered_trap_callback)) {
154
-            // invalid callback so lets just sub in our default.
155
-            $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response');
156
-        }
157
-        call_user_func($triggered_trap_callback);
158
-    }
133
+	/**
134
+	 * process_bot_trap
135
+	 *
136
+	 * @param array|string $triggered_trap_callback Callback that will be executed for handling the
137
+	 *                                              response if the bot trap is triggered.
138
+	 *                                              It should receive one argument: a boolean indicating
139
+	 *                                              whether the trap was triggered by suspicious timing or not.
140
+	 * @throws RuntimeException
141
+	 */
142
+	public static function process_bot_trap($triggered_trap_callback = array())
143
+	{
144
+		// what's your email address Mr. Bot ?
145
+		$empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email'])
146
+					  && $_REQUEST['tkt-slctr-request-processor-email'] === '';
147
+		// are we human ?
148
+		if ($empty_trap) {
149
+			do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered');
150
+			return;
151
+		}
152
+		// check the given callback is valid first before executing
153
+		if (! is_callable($triggered_trap_callback)) {
154
+			// invalid callback so lets just sub in our default.
155
+			$triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response');
156
+		}
157
+		call_user_func($triggered_trap_callback);
158
+	}
159 159
 
160 160
 
161
-    /**
162
-     * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response.
163
-     *
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     */
168
-    public static function triggered_trap_response()
169
-    {
170
-        // UH OH...
171
-        $redirect_url = apply_filters(
172
-            'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url',
173
-            add_query_arg(
174
-                array('ee' => 'ticket_selection_received'),
175
-                EE_Registry::instance()->CFG->core->reg_page_url()
176
-            )
177
-        );
178
-        // if AJAX, return the redirect URL
179
-        if (defined('DOING_AJAX') && DOING_AJAX) {
180
-            echo wp_json_encode(
181
-                array_merge(
182
-                    EE_Error::get_notices(false),
183
-                    array(
184
-                        'redirect_url' => $redirect_url,
185
-                    )
186
-                )
187
-            );
188
-            exit();
189
-        }
190
-        wp_safe_redirect($redirect_url);
191
-        exit();
192
-    }
161
+	/**
162
+	 * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response.
163
+	 *
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 */
168
+	public static function triggered_trap_response()
169
+	{
170
+		// UH OH...
171
+		$redirect_url = apply_filters(
172
+			'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url',
173
+			add_query_arg(
174
+				array('ee' => 'ticket_selection_received'),
175
+				EE_Registry::instance()->CFG->core->reg_page_url()
176
+			)
177
+		);
178
+		// if AJAX, return the redirect URL
179
+		if (defined('DOING_AJAX') && DOING_AJAX) {
180
+			echo wp_json_encode(
181
+				array_merge(
182
+					EE_Error::get_notices(false),
183
+					array(
184
+						'redirect_url' => $redirect_url,
185
+					)
186
+				)
187
+			);
188
+			exit();
189
+		}
190
+		wp_safe_redirect($redirect_url);
191
+		exit();
192
+	}
193 193
 
194 194
 
195
-    /**
196
-     * display_bot_trap_success
197
-     * shows a "success" screen to bots so that they (ie: the ppl managing them)
198
-     * think the form was submitted successfully
199
-     *
200
-     * @return void
201
-     */
202
-    public static function display_bot_trap_success()
203
-    {
204
-        add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false');
205
-        $bot_notice = esc_html__(
206
-            'Thank you so much. Your ticket selections have been received for consideration.',
207
-            'event_espresso'
208
-        );
209
-        $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== ''
210
-            ? sanitize_text_field(stripslashes($_REQUEST['ee-notice']))
211
-            : $bot_notice;
212
-        EED_Bot_Trap::getResponse()->addOutput(EEH_HTML::div($bot_notice, '', 'ee-attention'));
213
-    }
195
+	/**
196
+	 * display_bot_trap_success
197
+	 * shows a "success" screen to bots so that they (ie: the ppl managing them)
198
+	 * think the form was submitted successfully
199
+	 *
200
+	 * @return void
201
+	 */
202
+	public static function display_bot_trap_success()
203
+	{
204
+		add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false');
205
+		$bot_notice = esc_html__(
206
+			'Thank you so much. Your ticket selections have been received for consideration.',
207
+			'event_espresso'
208
+		);
209
+		$bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== ''
210
+			? sanitize_text_field(stripslashes($_REQUEST['ee-notice']))
211
+			: $bot_notice;
212
+		EED_Bot_Trap::getResponse()->addOutput(EEH_HTML::div($bot_notice, '', 'ee-attention'));
213
+	}
214 214
 
215 215
 
216 216
 
217
-    /***********************************    ADMIN    **********************************/
217
+	/***********************************    ADMIN    **********************************/
218 218
 
219 219
 
220
-    /**
221
-     * bot_trap_settings_form
222
-     *
223
-     * @return void
224
-     * @throws EE_Error
225
-     * @throws InvalidArgumentException
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidInterfaceException
228
-     */
229
-    public static function bot_trap_settings_form()
230
-    {
231
-        EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js();
232
-        echo EED_Bot_Trap::_bot_trap_settings_form()->get_html();
233
-    }
220
+	/**
221
+	 * bot_trap_settings_form
222
+	 *
223
+	 * @return void
224
+	 * @throws EE_Error
225
+	 * @throws InvalidArgumentException
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidInterfaceException
228
+	 */
229
+	public static function bot_trap_settings_form()
230
+	{
231
+		EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js();
232
+		echo EED_Bot_Trap::_bot_trap_settings_form()->get_html();
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * _bot_trap_settings_form
238
-     *
239
-     * @return EE_Form_Section_Proper
240
-     * @throws EE_Error
241
-     */
242
-    protected static function _bot_trap_settings_form()
243
-    {
244
-        return new EE_Form_Section_Proper(
245
-            array(
246
-                'name'            => 'bot_trap_settings',
247
-                'html_id'         => 'bot_trap_settings',
248
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
249
-                'subsections'     => array(
250
-                    'bot_trap_hdr' => new EE_Form_Section_HTML(
251
-                        EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))
252
-                    ),
253
-                    'use_bot_trap' => new EE_Yes_No_Input(
254
-                        array(
255
-                            'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'),
256
-                            'html_help_text'  => esc_html__(
257
-                                'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.',
258
-                                'event_espresso'
259
-                            ),
260
-                            'default'         => EE_Registry::instance()->CFG->registration->use_bot_trap !== null
261
-                                ? EE_Registry::instance()->CFG->registration->use_bot_trap
262
-                                : true,
263
-                            'required'        => false,
264
-                        )
265
-                    ),
266
-                ),
267
-            )
268
-        );
269
-    }
236
+	/**
237
+	 * _bot_trap_settings_form
238
+	 *
239
+	 * @return EE_Form_Section_Proper
240
+	 * @throws EE_Error
241
+	 */
242
+	protected static function _bot_trap_settings_form()
243
+	{
244
+		return new EE_Form_Section_Proper(
245
+			array(
246
+				'name'            => 'bot_trap_settings',
247
+				'html_id'         => 'bot_trap_settings',
248
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
249
+				'subsections'     => array(
250
+					'bot_trap_hdr' => new EE_Form_Section_HTML(
251
+						EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))
252
+					),
253
+					'use_bot_trap' => new EE_Yes_No_Input(
254
+						array(
255
+							'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'),
256
+							'html_help_text'  => esc_html__(
257
+								'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.',
258
+								'event_espresso'
259
+							),
260
+							'default'         => EE_Registry::instance()->CFG->registration->use_bot_trap !== null
261
+								? EE_Registry::instance()->CFG->registration->use_bot_trap
262
+								: true,
263
+							'required'        => false,
264
+						)
265
+					),
266
+				),
267
+			)
268
+		);
269
+	}
270 270
 
271 271
 
272
-    /**
273
-     * update_bot_trap_settings_form
274
-     *
275
-     * @param EE_Registration_Config $EE_Registration_Config
276
-     * @return EE_Registration_Config
277
-     * @throws EE_Error
278
-     * @throws InvalidArgumentException
279
-     * @throws ReflectionException
280
-     * @throws InvalidDataTypeException
281
-     * @throws InvalidInterfaceException
282
-     */
283
-    public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config)
284
-    {
285
-        try {
286
-            $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form();
287
-            // if not displaying a form, then check for form submission
288
-            if ($bot_trap_settings_form->was_submitted()) {
289
-                // capture form data
290
-                $bot_trap_settings_form->receive_form_submission();
291
-                // validate form data
292
-                if ($bot_trap_settings_form->is_valid()) {
293
-                    // grab validated data from form
294
-                    $valid_data = $bot_trap_settings_form->valid_data();
295
-                    if (isset($valid_data['use_bot_trap'])) {
296
-                        $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap'];
297
-                    } else {
298
-                        EE_Error::add_error(
299
-                            esc_html__(
300
-                                'Invalid or missing Bot Trap settings. Please refresh the form and try again.',
301
-                                'event_espresso'
302
-                            ),
303
-                            __FILE__,
304
-                            __FUNCTION__,
305
-                            __LINE__
306
-                        );
307
-                    }
308
-                } elseif ($bot_trap_settings_form->submission_error_message() !== '') {
309
-                    EE_Error::add_error(
310
-                        $bot_trap_settings_form->submission_error_message(),
311
-                        __FILE__,
312
-                        __FUNCTION__,
313
-                        __LINE__
314
-                    );
315
-                }
316
-            }
317
-        } catch (EE_Error $e) {
318
-            $e->get_error();
319
-        }
320
-        return $EE_Registration_Config;
321
-    }
272
+	/**
273
+	 * update_bot_trap_settings_form
274
+	 *
275
+	 * @param EE_Registration_Config $EE_Registration_Config
276
+	 * @return EE_Registration_Config
277
+	 * @throws EE_Error
278
+	 * @throws InvalidArgumentException
279
+	 * @throws ReflectionException
280
+	 * @throws InvalidDataTypeException
281
+	 * @throws InvalidInterfaceException
282
+	 */
283
+	public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config)
284
+	{
285
+		try {
286
+			$bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form();
287
+			// if not displaying a form, then check for form submission
288
+			if ($bot_trap_settings_form->was_submitted()) {
289
+				// capture form data
290
+				$bot_trap_settings_form->receive_form_submission();
291
+				// validate form data
292
+				if ($bot_trap_settings_form->is_valid()) {
293
+					// grab validated data from form
294
+					$valid_data = $bot_trap_settings_form->valid_data();
295
+					if (isset($valid_data['use_bot_trap'])) {
296
+						$EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap'];
297
+					} else {
298
+						EE_Error::add_error(
299
+							esc_html__(
300
+								'Invalid or missing Bot Trap settings. Please refresh the form and try again.',
301
+								'event_espresso'
302
+							),
303
+							__FILE__,
304
+							__FUNCTION__,
305
+							__LINE__
306
+						);
307
+					}
308
+				} elseif ($bot_trap_settings_form->submission_error_message() !== '') {
309
+					EE_Error::add_error(
310
+						$bot_trap_settings_form->submission_error_message(),
311
+						__FILE__,
312
+						__FUNCTION__,
313
+						__LINE__
314
+					);
315
+				}
316
+			}
317
+		} catch (EE_Error $e) {
318
+			$e->get_error();
319
+		}
320
+		return $EE_Registration_Config;
321
+	}
322 322
 }
Please login to merge, or discard this patch.
modules/ical/EED_Ical.module.php 2 patches
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -13,232 +13,232 @@
 block discarded – undo
13 13
 class EED_Ical extends EED_Module
14 14
 {
15 15
 
16
-    const iCal_datetime_format = 'Ymd\THis\Z';
17
-
18
-
19
-    /**
20
-     * @return EED_Ical|EED_Module
21
-     * @throws EE_Error
22
-     * @throws ReflectionException
23
-     */
24
-    public static function instance()
25
-    {
26
-        return parent::get_instance(__CLASS__);
27
-    }
28
-
29
-
30
-    /**
31
-     *    set_hooks - for hooking into EE Core, other modules, etc
32
-     *
33
-     * @return    void
34
-     */
35
-    public static function set_hooks()
36
-    {
37
-        // create download buttons
38
-        add_filter(
39
-            'FHEE__espresso_list_of_event_dates__datetime_html',
40
-            ['EED_Ical', 'generate_add_to_iCal_button'],
41
-            10,
42
-            2
43
-        );
44
-        // process ics download request
45
-        EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
46
-    }
47
-
48
-
49
-    /**
50
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
51
-     *
52
-     * @return    void
53
-     */
54
-    public static function set_hooks_admin()
55
-    {
56
-    }
57
-
58
-
59
-    /**
60
-     *    run - initial module setup
61
-     *
62
-     * @param WP $WP
63
-     * @return    void
64
-     */
65
-    public function run($WP)
66
-    {
67
-    }
68
-
69
-
70
-    /**
71
-     * @param $html
72
-     * @param $datetime
73
-     * @return string
74
-     * @throws EE_Error
75
-     * @throws ReflectionException
76
-     */
77
-    public static function generate_add_to_iCal_button($html, $datetime)
78
-    {
79
-        // first verify a proper datetime object has been received
80
-        if ($datetime instanceof EE_Datetime) {
81
-            // set whether a link or submit button is shown
82
-            $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
83
-            // generate a link to the route we registered in set_hooks()
84
-            $URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url());
85
-            // what type ?
86
-            switch ($iCal_type) {
87
-                // submit buttons appear as buttons and are very compatible with a theme's style
88
-                case 'submit':
89
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
90
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
91
-                    $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
92
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
93
-                    $html .= '</form>';
94
-                    break;
95
-                // buttons are just links that have been styled to appear as buttons,
96
-                // but may not be blend with a theme as well as submit buttons
97
-                case 'button':
98
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
99
-                    $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
100
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
101
-                    $html .= '</a>';
102
-                    break;
103
-                // links are just links that use the calendar dashicon
104
-                case 'icon':
105
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
106
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
107
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
108
-                    $html .= '</a>';
109
-                    break;
110
-            }
111
-        }
112
-        return $html;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return void
118
-     * @throws EE_Error
119
-     * @throws ReflectionException
120
-     */
121
-    public static function download_ics_file()
122
-    {
123
-        $request = self::getRequest();
124
-        if ($request->requestParamIsSet('ics_id')) {
125
-            $DTT_ID   = $request->getRequestParam('ics_id', 0, 'int');
126
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
127
-            if ($datetime instanceof EE_Datetime) {
128
-                // get related event, venues, and event categories
129
-                $event = $datetime->event();
130
-                if ($event instanceof EE_Event) {
131
-                    // get related category Term object and it's name
132
-                    $category = $event->first_event_category();
133
-                    if ($category instanceof EE_Term) {
134
-                        $category = $category->name();
135
-                    }
136
-                    $location = '';
137
-                    // get first related venue and convert to CSV string
138
-                    $venue = $event->venues(['limit' => 1]);
139
-                    if (is_array($venue) && ! empty($venue)) {
140
-                        $venue = array_shift($venue);
141
-                        if ($venue instanceof EE_Venue) {
142
-                            $location = espresso_venue_raw_address('inline', $venue->ID(), false);
143
-                        }
144
-                    }
145
-
146
-                    // Generate filename
147
-                    $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
148
-
149
-                    // Check the datetime status has not been cancelled and set the ics value accordingly
150
-                    $status = $datetime->get_active_status();
151
-                    $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
152
-
153
-                    // Create array of ics details, escape strings, convert timestamps to ics format, etc
154
-                    $ics_data = [
155
-                        'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
156
-                        'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
157
-                        'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
158
-                        'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
159
-                        'LOCATION'       => $location,
160
-                        'SUMMARY'        => $event->name(),
161
-                        'DESCRIPTION'    => wp_strip_all_tags($event->description()),
162
-                        'STATUS'         => $status,
163
-                        'CATEGORIES'     => $category,
164
-                        'URL;VALUE=URI'  => get_permalink($event->ID()),
165
-                        'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
166
-                        'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
167
-                    ];
168
-
169
-                    // Filter the values used within the ics output.
170
-                    // NOTE - all values within ics_data will be escaped automatically.
171
-                    $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
172
-
173
-                    // Escape all ics data
174
-                    foreach ($ics_data as $key => $value) {
175
-                        // Description is escaped differently from all all values
176
-                        if ($key === 'DESCRIPTION') {
177
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
178
-                        } else {
179
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
180
-                        }
181
-                    }
182
-
183
-                    // Pull the organizer name from ics_data and remove it from the array.
184
-                    $organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
185
-                    unset($ics_data['ORGANIZER_NAME']);
186
-
187
-                    // set headers
188
-                    header('Content-type: text/calendar; charset=utf-8');
189
-                    header('Content-Disposition: attachment; filename="' . $filename . '"');
190
-                    header('Cache-Control: private, max-age=0, must-revalidate');
191
-                    header('Pragma: public');
192
-                    header('Content-Type: application/octet-stream');
193
-                    header('Content-Type: application/force-download');
194
-                    header('Cache-Control: no-cache, must-revalidate');
195
-                    header('Content-Transfer-Encoding: binary');
196
-                    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
197
-                    ini_set('zlib.output_compression', '0');
198
-                    // echo the output
199
-                    echo "BEGIN:VCALENDAR\r\n";
200
-                    echo "VERSION:2.0\r\n";
201
-                    echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
202
-                    echo "CALSCALE:GREGORIAN\r\n";
203
-                    echo "BEGIN:VEVENT\r\n";
204
-
205
-                    // Output all remaining values from ics_data.
206
-                    foreach ($ics_data as $key => $value) {
207
-                        echo $key . ':' . $value . "\r\n";
208
-                    }
209
-
210
-                    echo "END:VEVENT\r\n";
211
-                    echo "END:VCALENDAR\r\n";
212
-                }
213
-            }
214
-        }
215
-        die();
216
-    }
217
-
218
-
219
-    /**
220
-     *    _escape_ICal_data
221
-     *
222
-     * @param string $string
223
-     * @return    string
224
-     */
225
-    private static function _escape_ICal_data($string = '')
226
-    {
227
-        return preg_replace('/([\,;])/', '\\\$1', $string);
228
-    }
229
-
230
-
231
-    /**
232
-     *    _escape_ICal_description
233
-     *
234
-     * @param string $description
235
-     * @return    string
236
-     */
237
-    private static function _escape_ICal_description($description = '')
238
-    {
239
-        // Escape special chars within the description
240
-        $description = EED_Ical::_escape_ICal_data($description);
241
-        // Remove line breaks and output in iCal format
242
-        return str_replace(["\r\n", "\n"], '\n', $description);
243
-    }
16
+	const iCal_datetime_format = 'Ymd\THis\Z';
17
+
18
+
19
+	/**
20
+	 * @return EED_Ical|EED_Module
21
+	 * @throws EE_Error
22
+	 * @throws ReflectionException
23
+	 */
24
+	public static function instance()
25
+	{
26
+		return parent::get_instance(__CLASS__);
27
+	}
28
+
29
+
30
+	/**
31
+	 *    set_hooks - for hooking into EE Core, other modules, etc
32
+	 *
33
+	 * @return    void
34
+	 */
35
+	public static function set_hooks()
36
+	{
37
+		// create download buttons
38
+		add_filter(
39
+			'FHEE__espresso_list_of_event_dates__datetime_html',
40
+			['EED_Ical', 'generate_add_to_iCal_button'],
41
+			10,
42
+			2
43
+		);
44
+		// process ics download request
45
+		EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
46
+	}
47
+
48
+
49
+	/**
50
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
51
+	 *
52
+	 * @return    void
53
+	 */
54
+	public static function set_hooks_admin()
55
+	{
56
+	}
57
+
58
+
59
+	/**
60
+	 *    run - initial module setup
61
+	 *
62
+	 * @param WP $WP
63
+	 * @return    void
64
+	 */
65
+	public function run($WP)
66
+	{
67
+	}
68
+
69
+
70
+	/**
71
+	 * @param $html
72
+	 * @param $datetime
73
+	 * @return string
74
+	 * @throws EE_Error
75
+	 * @throws ReflectionException
76
+	 */
77
+	public static function generate_add_to_iCal_button($html, $datetime)
78
+	{
79
+		// first verify a proper datetime object has been received
80
+		if ($datetime instanceof EE_Datetime) {
81
+			// set whether a link or submit button is shown
82
+			$iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
83
+			// generate a link to the route we registered in set_hooks()
84
+			$URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url());
85
+			// what type ?
86
+			switch ($iCal_type) {
87
+				// submit buttons appear as buttons and are very compatible with a theme's style
88
+				case 'submit':
89
+					$html .= '<form id="download-iCal-frm-' . $datetime->ID();
90
+					$html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
91
+					$html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
92
+					$html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
93
+					$html .= '</form>';
94
+					break;
95
+				// buttons are just links that have been styled to appear as buttons,
96
+				// but may not be blend with a theme as well as submit buttons
97
+				case 'button':
98
+					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
99
+					$html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
100
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
101
+					$html .= '</a>';
102
+					break;
103
+				// links are just links that use the calendar dashicon
104
+				case 'icon':
105
+					$html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
106
+					$html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
107
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
108
+					$html .= '</a>';
109
+					break;
110
+			}
111
+		}
112
+		return $html;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return void
118
+	 * @throws EE_Error
119
+	 * @throws ReflectionException
120
+	 */
121
+	public static function download_ics_file()
122
+	{
123
+		$request = self::getRequest();
124
+		if ($request->requestParamIsSet('ics_id')) {
125
+			$DTT_ID   = $request->getRequestParam('ics_id', 0, 'int');
126
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
127
+			if ($datetime instanceof EE_Datetime) {
128
+				// get related event, venues, and event categories
129
+				$event = $datetime->event();
130
+				if ($event instanceof EE_Event) {
131
+					// get related category Term object and it's name
132
+					$category = $event->first_event_category();
133
+					if ($category instanceof EE_Term) {
134
+						$category = $category->name();
135
+					}
136
+					$location = '';
137
+					// get first related venue and convert to CSV string
138
+					$venue = $event->venues(['limit' => 1]);
139
+					if (is_array($venue) && ! empty($venue)) {
140
+						$venue = array_shift($venue);
141
+						if ($venue instanceof EE_Venue) {
142
+							$location = espresso_venue_raw_address('inline', $venue->ID(), false);
143
+						}
144
+					}
145
+
146
+					// Generate filename
147
+					$filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
148
+
149
+					// Check the datetime status has not been cancelled and set the ics value accordingly
150
+					$status = $datetime->get_active_status();
151
+					$status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
152
+
153
+					// Create array of ics details, escape strings, convert timestamps to ics format, etc
154
+					$ics_data = [
155
+						'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
156
+						'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
157
+						'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
158
+						'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
159
+						'LOCATION'       => $location,
160
+						'SUMMARY'        => $event->name(),
161
+						'DESCRIPTION'    => wp_strip_all_tags($event->description()),
162
+						'STATUS'         => $status,
163
+						'CATEGORIES'     => $category,
164
+						'URL;VALUE=URI'  => get_permalink($event->ID()),
165
+						'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
166
+						'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
167
+					];
168
+
169
+					// Filter the values used within the ics output.
170
+					// NOTE - all values within ics_data will be escaped automatically.
171
+					$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
172
+
173
+					// Escape all ics data
174
+					foreach ($ics_data as $key => $value) {
175
+						// Description is escaped differently from all all values
176
+						if ($key === 'DESCRIPTION') {
177
+							$ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
178
+						} else {
179
+							$ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
180
+						}
181
+					}
182
+
183
+					// Pull the organizer name from ics_data and remove it from the array.
184
+					$organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
185
+					unset($ics_data['ORGANIZER_NAME']);
186
+
187
+					// set headers
188
+					header('Content-type: text/calendar; charset=utf-8');
189
+					header('Content-Disposition: attachment; filename="' . $filename . '"');
190
+					header('Cache-Control: private, max-age=0, must-revalidate');
191
+					header('Pragma: public');
192
+					header('Content-Type: application/octet-stream');
193
+					header('Content-Type: application/force-download');
194
+					header('Cache-Control: no-cache, must-revalidate');
195
+					header('Content-Transfer-Encoding: binary');
196
+					header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
197
+					ini_set('zlib.output_compression', '0');
198
+					// echo the output
199
+					echo "BEGIN:VCALENDAR\r\n";
200
+					echo "VERSION:2.0\r\n";
201
+					echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
202
+					echo "CALSCALE:GREGORIAN\r\n";
203
+					echo "BEGIN:VEVENT\r\n";
204
+
205
+					// Output all remaining values from ics_data.
206
+					foreach ($ics_data as $key => $value) {
207
+						echo $key . ':' . $value . "\r\n";
208
+					}
209
+
210
+					echo "END:VEVENT\r\n";
211
+					echo "END:VCALENDAR\r\n";
212
+				}
213
+			}
214
+		}
215
+		die();
216
+	}
217
+
218
+
219
+	/**
220
+	 *    _escape_ICal_data
221
+	 *
222
+	 * @param string $string
223
+	 * @return    string
224
+	 */
225
+	private static function _escape_ICal_data($string = '')
226
+	{
227
+		return preg_replace('/([\,;])/', '\\\$1', $string);
228
+	}
229
+
230
+
231
+	/**
232
+	 *    _escape_ICal_description
233
+	 *
234
+	 * @param string $description
235
+	 * @return    string
236
+	 */
237
+	private static function _escape_ICal_description($description = '')
238
+	{
239
+		// Escape special chars within the description
240
+		$description = EED_Ical::_escape_ICal_data($description);
241
+		// Remove line breaks and output in iCal format
242
+		return str_replace(["\r\n", "\n"], '\n', $description);
243
+	}
244 244
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -86,24 +86,24 @@  discard block
 block discarded – undo
86 86
             switch ($iCal_type) {
87 87
                 // submit buttons appear as buttons and are very compatible with a theme's style
88 88
                 case 'submit':
89
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
90
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
89
+                    $html .= '<form id="download-iCal-frm-'.$datetime->ID();
90
+                    $html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >';
91 91
                     $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
92
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
92
+                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'"/>';
93 93
                     $html .= '</form>';
94 94
                     break;
95 95
                 // buttons are just links that have been styled to appear as buttons,
96 96
                 // but may not be blend with a theme as well as submit buttons
97 97
                 case 'button':
98
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
99
-                    $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
98
+                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL;
99
+                    $html .= '" title="'.esc_html__('Add to iCal Calendar', 'event_espresso').'">';
100 100
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
101 101
                     $html .= '</a>';
102 102
                     break;
103 103
                 // links are just links that use the calendar dashicon
104 104
                 case 'icon':
105
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
106
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
105
+                    $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="';
106
+                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'">';
107 107
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
108 108
                     $html .= '</a>';
109 109
                     break;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                     }
145 145
 
146 146
                     // Generate filename
147
-                    $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
147
+                    $filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics';
148 148
 
149 149
                     // Check the datetime status has not been cancelled and set the ics value accordingly
150 150
                     $status = $datetime->get_active_status();
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                     // Create array of ics details, escape strings, convert timestamps to ics format, etc
154 154
                     $ics_data = [
155 155
                         'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
156
-                        'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
156
+                        'UID'            => md5($event->name().$event->ID().$datetime->ID()),
157 157
                         'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
158 158
                         'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
159 159
                         'LOCATION'       => $location,
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
                     foreach ($ics_data as $key => $value) {
175 175
                         // Description is escaped differently from all all values
176 176
                         if ($key === 'DESCRIPTION') {
177
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
177
+                            $ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
178 178
                         } else {
179
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
179
+                            $ics_data[$key] = EED_Ical::_escape_ICal_data($value);
180 180
                         }
181 181
                     }
182 182
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
                     // set headers
188 188
                     header('Content-type: text/calendar; charset=utf-8');
189
-                    header('Content-Disposition: attachment; filename="' . $filename . '"');
189
+                    header('Content-Disposition: attachment; filename="'.$filename.'"');
190 190
                     header('Cache-Control: private, max-age=0, must-revalidate');
191 191
                     header('Pragma: public');
192 192
                     header('Content-Type: application/octet-stream');
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 
205 205
                     // Output all remaining values from ics_data.
206 206
                     foreach ($ics_data as $key => $value) {
207
-                        echo $key . ':' . $value . "\r\n";
207
+                        echo $key.':'.$value."\r\n";
208 208
                     }
209 209
 
210 210
                     echo "END:VEVENT\r\n";
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 2 patches
Indentation   +805 added lines, -805 removed lines patch added patch discarded remove patch
@@ -17,809 +17,809 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @return EED_Add_New_State|EED_Module
22
-     * @throws EE_Error
23
-     * @throws ReflectionException
24
-     */
25
-    public static function instance()
26
-    {
27
-        return parent::get_instance(__CLASS__);
28
-    }
29
-
30
-
31
-    /**
32
-     * set_hooks - for hooking into EE Core, other modules, etc
33
-     *
34
-     * @return void
35
-     */
36
-    public static function set_hooks()
37
-    {
38
-        add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
39
-        add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'translate_js_strings'], 0);
40
-        add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'wp_enqueue_scripts'], 10);
41
-        add_filter(
42
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
44
-            1,
45
-            1
46
-        );
47
-        add_filter(
48
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
49
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
50
-            1,
51
-            1
52
-        );
53
-        add_filter(
54
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
55
-            ['EED_Add_New_State', 'unset_new_state_request_params'],
56
-            10,
57
-            1
58
-        );
59
-        add_filter(
60
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
61
-            ['EED_Add_New_State', 'inject_new_reg_state_into_options'],
62
-            10,
63
-            5
64
-        );
65
-        add_filter(
66
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
67
-            ['EED_Add_New_State', 'inject_new_reg_country_into_options'],
68
-            10,
69
-            5
70
-        );
71
-        add_filter(
72
-            'FHEE__EE_State_Select_Input____construct__state_options',
73
-            ['EED_Add_New_State', 'state_options'],
74
-            10,
75
-            1
76
-        );
77
-        add_filter(
78
-            'FHEE__EE_Country_Select_Input____construct__country_options',
79
-            ['EED_Add_New_State', 'country_options'],
80
-            10,
81
-            1
82
-        );
83
-    }
84
-
85
-
86
-    /**
87
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
88
-     *
89
-     * @return void
90
-     */
91
-    public static function set_hooks_admin()
92
-    {
93
-        add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
94
-        add_filter(
95
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
96
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
97
-            1,
98
-            1
99
-        );
100
-        add_filter(
101
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
102
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
103
-            1,
104
-            1
105
-        );
106
-        add_action('wp_ajax_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
107
-        add_action('wp_ajax_nopriv_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
108
-        add_filter(
109
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
110
-            ['EED_Add_New_State', 'unset_new_state_request_params'],
111
-            10,
112
-            1
113
-        );
114
-        add_action(
115
-            'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
116
-            ['EED_Add_New_State', 'update_country_settings'],
117
-            10,
118
-            3
119
-        );
120
-        add_action(
121
-            'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
122
-            ['EED_Add_New_State', 'update_country_settings'],
123
-            10,
124
-            3
125
-        );
126
-        add_filter(
127
-            'FHEE__EE_State_Select_Input____construct__state_options',
128
-            ['EED_Add_New_State', 'state_options'],
129
-            10,
130
-            1
131
-        );
132
-        add_filter(
133
-            'FHEE__EE_Country_Select_Input____construct__country_options',
134
-            ['EED_Add_New_State', 'country_options'],
135
-            10,
136
-            1
137
-        );
138
-        add_filter(
139
-            'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
140
-            ['EED_Add_New_State', 'filter_checkout_request_params'],
141
-            10,
142
-            1
143
-        );
144
-        add_filter(
145
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
146
-            ['EED_Add_New_State', 'inject_new_reg_state_into_options'],
147
-            10,
148
-            5
149
-        );
150
-        add_filter(
151
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
152
-            ['EED_Add_New_State', 'inject_new_reg_country_into_options'],
153
-            10,
154
-            5
155
-        );
156
-    }
157
-
158
-
159
-    /**
160
-     * @return void
161
-     */
162
-    public static function set_definitions()
163
-    {
164
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
165
-        define(
166
-            'ANS_TEMPLATES_PATH',
167
-            str_replace(
168
-                '\\',
169
-                '/',
170
-                plugin_dir_path(__FILE__)
171
-            ) . 'templates/'
172
-        );
173
-    }
174
-
175
-
176
-    /**
177
-     * @param WP $WP
178
-     * @return void
179
-     */
180
-    public function run($WP)
181
-    {
182
-    }
183
-
184
-
185
-    /**
186
-     * @return void
187
-     */
188
-    public static function translate_js_strings()
189
-    {
190
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
191
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
192
-            'event_espresso'
193
-        );
194
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
195
-            'In order to proceed, you need to enter the name of your State/Province.',
196
-            'event_espresso'
197
-        );
198
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
199
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
200
-            'event_espresso'
201
-        );
202
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
203
-            'The new state was successfully saved to the database.',
204
-            'event_espresso'
205
-        );
206
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
207
-            'An unknown error has occurred on the server while saving the new state to the database.',
208
-            'event_espresso'
209
-        );
210
-    }
211
-
212
-
213
-    /**
214
-     * @return void
215
-     */
216
-    public static function wp_enqueue_scripts()
217
-    {
218
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
219
-            wp_register_script(
220
-                'add_new_state',
221
-                ANS_ASSETS_URL . 'add_new_state.js',
222
-                ['espresso_core', 'single_page_checkout'],
223
-                EVENT_ESPRESSO_VERSION,
224
-                true
225
-            );
226
-            wp_enqueue_script('add_new_state');
227
-        }
228
-    }
229
-
230
-
231
-    /**
232
-     * display_add_new_state_micro_form
233
-     *
234
-     * @param EE_Form_Section_Proper $question_group_reg_form
235
-     * @return EE_Form_Section_Proper
236
-     * @throws EE_Error
237
-     * @throws ReflectionException
238
-     */
239
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
240
-    {
241
-        $request = self::getRequest();
242
-        // only add the 'new_state_micro_form' when displaying reg forms,
243
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
-        $action = $request->getRequestParam('action');
245
-        // is the "state" question in this form section?
246
-        $input = $question_group_reg_form->get_subsection('state');
247
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
-            // ok then all we need to do is make sure the input's HTML name is consistent
249
-            // by forcing it to set it now, like it did while getting the form for display
250
-            if ($input instanceof EE_State_Select_Input) {
251
-                $input->html_name();
252
-            }
253
-            return $question_group_reg_form;
254
-        }
255
-        // we're only doing this for state select inputs
256
-        if ($input instanceof EE_State_Select_Input
257
-            && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
258
-        ) {
259
-            // grab any set values from the request
260
-            $country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
261
-            $state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
262
-            $abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
263
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264
-            $country_options     = [];
265
-            $countries           = EEM_Country::instance()->get_all_countries();
266
-            if (! empty($countries)) {
267
-                foreach ($countries as $country) {
268
-                    if ($country instanceof EE_Country) {
269
-                        $country_options[ $country->ID() ] = $country->name();
270
-                    }
271
-                }
272
-            }
273
-            $new_state_micro_form = new EE_Form_Section_Proper(
274
-                [
275
-                    'name'            => 'new_state_micro_form',
276
-                    'html_id'         => 'new_state_micro_form',
277
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
278
-                    'subsections'     => [
279
-                        // add hidden input to indicate that a new state is being added
280
-                        'add_new_state'               => new EE_Hidden_Input(
281
-                            [
282
-                                'html_name' => str_replace(
283
-                                    'state',
284
-                                    'nsmf_add_new_state',
285
-                                    $input->html_name()
286
-                                ),
287
-                                'html_id'   => str_replace(
288
-                                    'state',
289
-                                    'nsmf_add_new_state',
290
-                                    $input->html_id()
291
-                                ),
292
-                                'default'   => 0,
293
-                            ]
294
-                        ),
295
-                        // add link for displaying hidden container
296
-                        'click_here_link'             => new EE_Form_Section_HTML(
297
-                            apply_filters(
298
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
299
-                                EEH_HTML::link(
300
-                                    '',
301
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
302
-                                    '',
303
-                                    'display-' . $input->html_id(),
304
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305
-                                    '',
306
-                                    'data-target="' . $input->html_id() . '"'
307
-                                )
308
-                            )
309
-                        ),
310
-                        // add initial html for hidden container
311
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
312
-                            apply_filters(
313
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314
-                                EEH_HTML::div(
315
-                                    '',
316
-                                    $input->html_id() . '-dv',
317
-                                    'ee-form-add-new-state-dv',
318
-                                    'display: none;'
319
-                                ) .
320
-                                EEH_HTML::h6(
321
-                                    esc_html__(
322
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323
-                                        'event_espresso'
324
-                                    )
325
-                                ) .
326
-                                EEH_HTML::ul() .
327
-                                EEH_HTML::li(
328
-                                    esc_html__(
329
-                                        'first select the Country that your State/Province belongs to',
330
-                                        'event_espresso'
331
-                                    )
332
-                                ) .
333
-                                EEH_HTML::li(
334
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
335
-                                ) .
336
-                                EEH_HTML::li(
337
-                                    esc_html__(
338
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
339
-                                        'event_espresso'
340
-                                    )
341
-                                ) .
342
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
343
-                                EEH_HTML::ulx()
344
-                            )
345
-                        ),
346
-                        // NEW STATE COUNTRY
347
-                        'new_state_country'           => new EE_Country_Select_Input(
348
-                            $country_options,
349
-                            [
350
-                                'html_name'       => $country_name,
351
-                                'html_id'         => str_replace(
352
-                                    'state',
353
-                                    'nsmf_new_state_country',
354
-                                    $input->html_id()
355
-                                ),
356
-                                'html_class'      => $input->html_class() . ' new-state-country',
357
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358
-                                'default'         => $request->getRequestParam($country_name),
359
-                                'required'        => false,
360
-                            ]
361
-                        ),
362
-                        // NEW STATE NAME
363
-                        'new_state_name'              => new EE_Text_Input(
364
-                            [
365
-                                'html_name'       => $state_name,
366
-                                'html_id'         => str_replace(
367
-                                    'state',
368
-                                    'nsmf_new_state_name',
369
-                                    $input->html_id()
370
-                                ),
371
-                                'html_class'      => $input->html_class() . ' new-state-state',
372
-                                'html_label_text' => esc_html__(
373
-                                    'New State/Province Name',
374
-                                    'event_espresso'
375
-                                ),
376
-                                'default'         => $request->getRequestParam($state_name),
377
-                                'required'        => false,
378
-                            ]
379
-                        ),
380
-                        'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
381
-                        // NEW STATE NAME
382
-                        'new_state_abbrv'             => new EE_Text_Input(
383
-                            [
384
-                                'html_name'             => $abbrv_name,
385
-                                'html_id'               => str_replace(
386
-                                    'state',
387
-                                    'nsmf_new_state_abbrv',
388
-                                    $input->html_id()
389
-                                ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
391
-                                'html_label_text'       => esc_html__(
392
-                                                               'New State/Province Abbreviation',
393
-                                                               'event_espresso'
394
-                                                           ) . ' *',
395
-                                'other_html_attributes' => 'size="24"',
396
-                                'default'               => $request->getRequestParam($abbrv_name),
397
-                                'required'              => false,
398
-                            ]
399
-                        ),
400
-                        // "submit" button
401
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
-                            apply_filters(
403
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
-                                EEH_HTML::nbsp(3) .
405
-                                EEH_HTML::link(
406
-                                    '',
407
-                                    esc_html__('ADD', 'event_espresso'),
408
-                                    '',
409
-                                    'submit-' . $new_state_submit_id,
410
-                                    'ee-form-add-new-state-submit button button-secondary',
411
-                                    '',
412
-                                    'data-target="'
413
-                                    . $new_state_submit_id
414
-                                    . '" data-value-field-name="'
415
-                                    . $input->valueFieldName()
416
-                                    . '"'
417
-                                )
418
-                            )
419
-                        ),
420
-                        // extra info
421
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
422
-                            apply_filters(
423
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
424
-                                EEH_HTML::br(2)
425
-                                .
426
-                                EEH_HTML::div('', '', 'small-text')
427
-                                .
428
-                                EEH_HTML::strong(
429
-                                    '* ' .
430
-                                    esc_html__(
431
-                                        'Don\'t know your State/Province Abbreviation?',
432
-                                        'event_espresso'
433
-                                    )
434
-                                )
435
-                                .
436
-                                EEH_HTML::br()
437
-                                .
438
-                                sprintf(
439
-                                    esc_html__(
440
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
441
-                                        'event_espresso'
442
-                                    ),
443
-                                    EEH_HTML::link(
444
-                                        'https://en.wikipedia.org/wiki/ISO_3166-2',
445
-                                        'https://en.wikipedia.org/wiki/ISO_3166-2',
446
-                                        '',
447
-                                        '',
448
-                                        'ee-form-add-new-state-wiki-lnk',
449
-                                        '',
450
-                                        'target="_blank"'
451
-                                    )
452
-                                )
453
-                                .
454
-                                EEH_HTML::divx()
455
-                                .
456
-                                EEH_HTML::br()
457
-                                .
458
-                                EEH_HTML::link(
459
-                                    '',
460
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
461
-                                    '',
462
-                                    'hide-' . $input->html_id(),
463
-                                    'ee-form-cancel-new-state-lnk smaller-text',
464
-                                    '',
465
-                                    'data-target="' . $input->html_id() . '"'
466
-                                )
467
-                                .
468
-                                EEH_HTML::divx()
469
-                                .
470
-                                EEH_HTML::br()
471
-                            )
472
-                        ),
473
-                    ],
474
-                ]
475
-            );
476
-            $question_group_reg_form->add_subsections(
477
-                ['new_state_micro_form' => $new_state_micro_form],
478
-                'state',
479
-                false
480
-            );
481
-        }
482
-        return $question_group_reg_form;
483
-    }
484
-
485
-
486
-    /**
487
-     * set_new_state_input_width
488
-     *
489
-     * @return int|string
490
-     * @throws EE_Error
491
-     * @throws InvalidArgumentException
492
-     * @throws InvalidDataTypeException
493
-     * @throws InvalidInterfaceException
494
-     * @throws ReflectionException
495
-     */
496
-    public static function add_new_state()
497
-    {
498
-        $request = self::getRequest();
499
-        if ($request->getRequestParam('nsmf_add_new_state', 0, 'int') === 1) {
500
-            EE_Registry::instance()->load_model('State');
501
-            // grab country ISO code, new state name, and new state abbreviation
502
-            $state_country = $request->getRequestParam('nsmf_new_state_country');
503
-            $state_name    = $request->getRequestParam('nsmf_new_state_name');
504
-            $state_abbr    = $request->getRequestParam('nsmf_new_state_abbrv');
505
-            if ($state_country && $state_name && $state_abbr) {
506
-                $new_state = EED_Add_New_State::save_new_state_to_db(
507
-                    [
508
-                        'CNT_ISO'    => strtoupper($state_country),
509
-                        'STA_abbrev' => strtoupper($state_abbr),
510
-                        'STA_name'   => ucwords($state_name),
511
-                        'STA_active' => false,
512
-                    ]
513
-                );
514
-                if ($new_state instanceof EE_State) {
515
-                    // clean house
516
-                    $request->unSetRequestParams(
517
-                        [
518
-                            'nsmf_add_new_state',
519
-                            'nsmf_new_state_country',
520
-                            'nsmf_new_state_name',
521
-                            'nsmf_new_state_abbrv',
522
-                        ]
523
-                    );
524
-                    // get any existing new states
525
-                    $new_states                     = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states');
526
-                    $new_states[ $new_state->ID() ] = $new_state;
527
-                    EE_Registry::instance()->SSN->set_session_data(
528
-                        ['nsmf_new_states' => $new_states]
529
-                    );
530
-                    if ($request->isAjax()) {
531
-                        echo wp_json_encode(
532
-                            [
533
-                                'success'      => true,
534
-                                'id'           => $new_state->ID(),
535
-                                'name'         => $new_state->name(),
536
-                                'abbrev'       => $new_state->abbrev(),
537
-                                'country_iso'  => $new_state->country_iso(),
538
-                                'country_name' => $new_state->country()->name(),
539
-                            ]
540
-                        );
541
-                        exit();
542
-                    }
543
-                    return $new_state->ID();
544
-                }
545
-            } else {
546
-                $error = esc_html__(
547
-                    'A new State/Province could not be added because invalid or missing data was received.',
548
-                    'event_espresso'
549
-                );
550
-                if ($request->isAjax()) {
551
-                    echo wp_json_encode(['error' => $error]);
552
-                    exit();
553
-                }
554
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
555
-            }
556
-        }
557
-        return false;
558
-    }
559
-
560
-
561
-    /**
562
-     * recursively drills down through request params to remove any that were added by this module
563
-     *
564
-     * @param array $request_params
565
-     * @return array
566
-     */
567
-    public static function filter_checkout_request_params($request_params)
568
-    {
569
-        foreach ($request_params as $form_section) {
570
-            if (is_array($form_section)) {
571
-                EED_Add_New_State::unset_new_state_request_params($form_section);
572
-                EED_Add_New_State::filter_checkout_request_params($form_section);
573
-            }
574
-        }
575
-        return $request_params;
576
-    }
577
-
578
-
579
-    /**
580
-     * @param array $request_params
581
-     * @return array
582
-     */
583
-    public static function unset_new_state_request_params($request_params)
584
-    {
585
-        unset(
586
-            $request_params['new_state_micro_form'],
587
-            $request_params['new_state_micro_add_new_state'],
588
-            $request_params['new_state_micro_new_state_country'],
589
-            $request_params['new_state_micro_new_state_name'],
590
-            $request_params['new_state_micro_new_state_abbrv']
591
-        );
592
-        return $request_params;
593
-    }
594
-
595
-
596
-    /**
597
-     * @param array $props_n_values
598
-     * @return EE_State|null
599
-     * @throws EE_Error
600
-     * @throws ReflectionException
601
-     */
602
-    public static function save_new_state_to_db($props_n_values = [])
603
-    {
604
-        /** @var EE_State[] $existing_state */
605
-        $existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]);
606
-        if (! empty($existing_state)) {
607
-            return array_pop($existing_state);
608
-        }
609
-        $new_state = EE_State::new_instance($props_n_values);
610
-        if ($new_state instanceof EE_State) {
611
-            $country_settings_url = add_query_arg(
612
-                [
613
-                    'page'    => 'espresso_general_settings',
614
-                    'action'  => 'country_settings',
615
-                    'country' => $new_state->country_iso(),
616
-                ],
617
-                admin_url('admin.php')
618
-            );
619
-            // if not non-ajax admin
620
-            new PersistentAdminNotice(
621
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
622
-                sprintf(
623
-                    esc_html__(
624
-                        '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.',
625
-                        'event_espresso'
626
-                    ),
627
-                    '<b>' . $new_state->name() . '</b>',
628
-                    '<b>' . $new_state->abbrev() . '</b>',
629
-                    '<b>' . $new_state->country()->name() . '</b>',
630
-                    '<a href="'
631
-                    . $country_settings_url
632
-                    . '">'
633
-                    . esc_html__(
634
-                        'Event Espresso - General Settings > Countries Tab',
635
-                        'event_espresso'
636
-                    )
637
-                    . '</a>',
638
-                    '<br />'
639
-                )
640
-            );
641
-            $new_state->save();
642
-            EEM_State::instance()->reset_cached_states();
643
-            return $new_state;
644
-        }
645
-        return null;
646
-    }
647
-
648
-
649
-    /**
650
-     * @param string $CNT_ISO
651
-     * @param string $STA_ID
652
-     * @param array  $cols_n_values
653
-     * @return void
654
-     * @throws DomainException
655
-     * @throws EE_Error
656
-     * @throws InvalidArgumentException
657
-     * @throws InvalidDataTypeException
658
-     * @throws InvalidInterfaceException
659
-     */
660
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = [])
661
-    {
662
-        if (! $CNT_ISO) {
663
-            EE_Error::add_error(
664
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
665
-                __FILE__,
666
-                __FUNCTION__,
667
-                __LINE__
668
-            );
669
-        }
670
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
671
-            : false;
672
-        if (! $STA_abbrev && ! empty($STA_ID)) {
673
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
674
-            if ($state instanceof EE_State) {
675
-                $STA_abbrev = $state->abbrev();
676
-            }
677
-        }
678
-        if (! $STA_abbrev) {
679
-            EE_Error::add_error(
680
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
681
-                __FILE__,
682
-                __FUNCTION__,
683
-                __LINE__
684
-            );
685
-        }
686
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
687
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
688
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
689
-        );
690
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
691
-    }
692
-
693
-
694
-    /**
695
-     * @param EE_State[]                            $state_options
696
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
697
-     * @param EE_Registration                       $registration
698
-     * @param EE_Question                           $question
699
-     * @param                                       $answer
700
-     * @return array
701
-     * @throws EE_Error
702
-     * @throws ReflectionException
703
-     */
704
-    public static function inject_new_reg_state_into_options(
705
-        array $state_options,
706
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
707
-        EE_Registration $registration,
708
-        EE_Question $question,
709
-        $answer
710
-    ) {
711
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
712
-            && $question->type() === EEM_Question::QST_type_state
713
-        ) {
714
-            $STA_ID = $answer->value();
715
-            if (! empty($STA_ID)) {
716
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
717
-                if ($state instanceof EE_State) {
718
-                    $country = $state->country();
719
-                    if ($country instanceof EE_Country) {
720
-                        if (! isset($state_options[ $country->name() ])) {
721
-                            $state_options[ $country->name() ] = [];
722
-                        }
723
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
724
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
725
-                        }
726
-                    }
727
-                }
728
-            }
729
-        }
730
-        return $state_options;
731
-    }
732
-
733
-
734
-    /**
735
-     * @param EE_Country[]                          $country_options
736
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
737
-     * @param EE_Registration                       $registration
738
-     * @param EE_Question                           $question
739
-     * @param                                       $answer
740
-     * @return array
741
-     * @throws EE_Error
742
-     * @throws ReflectionException
743
-     */
744
-    public static function inject_new_reg_country_into_options(
745
-        array $country_options,
746
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
747
-        EE_Registration $registration,
748
-        EE_Question $question,
749
-        $answer
750
-    ) {
751
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
752
-            && $question->type()
753
-               === EEM_Question::QST_type_country
754
-        ) {
755
-            $CNT_ISO = $answer->value();
756
-            if (! empty($CNT_ISO)) {
757
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
758
-                if ($country instanceof EE_Country) {
759
-                    if (! isset($country_options[ $CNT_ISO ])) {
760
-                        $country_options[ $CNT_ISO ] = $country->name();
761
-                    }
762
-                }
763
-            }
764
-        }
765
-        return $country_options;
766
-    }
767
-
768
-
769
-    /**
770
-     * @param EE_State[] $state_options
771
-     * @return array
772
-     * @throws EE_Error
773
-     * @throws ReflectionException
774
-     */
775
-    public static function state_options($state_options = [])
776
-    {
777
-        $new_states = EED_Add_New_State::_get_new_states();
778
-        foreach ($new_states as $new_state) {
779
-            if ($new_state instanceof EE_State
780
-                && $new_state->country() instanceof EE_Country
781
-            ) {
782
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
783
-            }
784
-        }
785
-        return $state_options;
786
-    }
787
-
788
-
789
-    /**
790
-     * @return array
791
-     * @throws InvalidArgumentException
792
-     * @throws InvalidDataTypeException
793
-     * @throws InvalidInterfaceException
794
-     */
795
-    protected static function _get_new_states()
796
-    {
797
-        $new_states = [];
798
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
799
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
800
-                'nsmf_new_states'
801
-            );
802
-        }
803
-        return is_array($new_states) ? $new_states : [];
804
-    }
805
-
806
-
807
-    /**
808
-     * @param EE_Country[] $country_options
809
-     * @return array
810
-     * @throws EE_Error
811
-     * @throws ReflectionException
812
-     */
813
-    public static function country_options($country_options = [])
814
-    {
815
-        $new_states = EED_Add_New_State::_get_new_states();
816
-        foreach ($new_states as $new_state) {
817
-            if ($new_state instanceof EE_State
818
-                && $new_state->country() instanceof EE_Country
819
-            ) {
820
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
821
-            }
822
-        }
823
-        return $country_options;
824
-    }
20
+	/**
21
+	 * @return EED_Add_New_State|EED_Module
22
+	 * @throws EE_Error
23
+	 * @throws ReflectionException
24
+	 */
25
+	public static function instance()
26
+	{
27
+		return parent::get_instance(__CLASS__);
28
+	}
29
+
30
+
31
+	/**
32
+	 * set_hooks - for hooking into EE Core, other modules, etc
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public static function set_hooks()
37
+	{
38
+		add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
39
+		add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'translate_js_strings'], 0);
40
+		add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'wp_enqueue_scripts'], 10);
41
+		add_filter(
42
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
44
+			1,
45
+			1
46
+		);
47
+		add_filter(
48
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
49
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
50
+			1,
51
+			1
52
+		);
53
+		add_filter(
54
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
55
+			['EED_Add_New_State', 'unset_new_state_request_params'],
56
+			10,
57
+			1
58
+		);
59
+		add_filter(
60
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
61
+			['EED_Add_New_State', 'inject_new_reg_state_into_options'],
62
+			10,
63
+			5
64
+		);
65
+		add_filter(
66
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
67
+			['EED_Add_New_State', 'inject_new_reg_country_into_options'],
68
+			10,
69
+			5
70
+		);
71
+		add_filter(
72
+			'FHEE__EE_State_Select_Input____construct__state_options',
73
+			['EED_Add_New_State', 'state_options'],
74
+			10,
75
+			1
76
+		);
77
+		add_filter(
78
+			'FHEE__EE_Country_Select_Input____construct__country_options',
79
+			['EED_Add_New_State', 'country_options'],
80
+			10,
81
+			1
82
+		);
83
+	}
84
+
85
+
86
+	/**
87
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
88
+	 *
89
+	 * @return void
90
+	 */
91
+	public static function set_hooks_admin()
92
+	{
93
+		add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
94
+		add_filter(
95
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
96
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
97
+			1,
98
+			1
99
+		);
100
+		add_filter(
101
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
102
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
103
+			1,
104
+			1
105
+		);
106
+		add_action('wp_ajax_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
107
+		add_action('wp_ajax_nopriv_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
108
+		add_filter(
109
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
110
+			['EED_Add_New_State', 'unset_new_state_request_params'],
111
+			10,
112
+			1
113
+		);
114
+		add_action(
115
+			'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
116
+			['EED_Add_New_State', 'update_country_settings'],
117
+			10,
118
+			3
119
+		);
120
+		add_action(
121
+			'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
122
+			['EED_Add_New_State', 'update_country_settings'],
123
+			10,
124
+			3
125
+		);
126
+		add_filter(
127
+			'FHEE__EE_State_Select_Input____construct__state_options',
128
+			['EED_Add_New_State', 'state_options'],
129
+			10,
130
+			1
131
+		);
132
+		add_filter(
133
+			'FHEE__EE_Country_Select_Input____construct__country_options',
134
+			['EED_Add_New_State', 'country_options'],
135
+			10,
136
+			1
137
+		);
138
+		add_filter(
139
+			'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
140
+			['EED_Add_New_State', 'filter_checkout_request_params'],
141
+			10,
142
+			1
143
+		);
144
+		add_filter(
145
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
146
+			['EED_Add_New_State', 'inject_new_reg_state_into_options'],
147
+			10,
148
+			5
149
+		);
150
+		add_filter(
151
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
152
+			['EED_Add_New_State', 'inject_new_reg_country_into_options'],
153
+			10,
154
+			5
155
+		);
156
+	}
157
+
158
+
159
+	/**
160
+	 * @return void
161
+	 */
162
+	public static function set_definitions()
163
+	{
164
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
165
+		define(
166
+			'ANS_TEMPLATES_PATH',
167
+			str_replace(
168
+				'\\',
169
+				'/',
170
+				plugin_dir_path(__FILE__)
171
+			) . 'templates/'
172
+		);
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param WP $WP
178
+	 * @return void
179
+	 */
180
+	public function run($WP)
181
+	{
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return void
187
+	 */
188
+	public static function translate_js_strings()
189
+	{
190
+		EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
191
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
192
+			'event_espresso'
193
+		);
194
+		EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
195
+			'In order to proceed, you need to enter the name of your State/Province.',
196
+			'event_espresso'
197
+		);
198
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
199
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
200
+			'event_espresso'
201
+		);
202
+		EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
203
+			'The new state was successfully saved to the database.',
204
+			'event_espresso'
205
+		);
206
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
207
+			'An unknown error has occurred on the server while saving the new state to the database.',
208
+			'event_espresso'
209
+		);
210
+	}
211
+
212
+
213
+	/**
214
+	 * @return void
215
+	 */
216
+	public static function wp_enqueue_scripts()
217
+	{
218
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
219
+			wp_register_script(
220
+				'add_new_state',
221
+				ANS_ASSETS_URL . 'add_new_state.js',
222
+				['espresso_core', 'single_page_checkout'],
223
+				EVENT_ESPRESSO_VERSION,
224
+				true
225
+			);
226
+			wp_enqueue_script('add_new_state');
227
+		}
228
+	}
229
+
230
+
231
+	/**
232
+	 * display_add_new_state_micro_form
233
+	 *
234
+	 * @param EE_Form_Section_Proper $question_group_reg_form
235
+	 * @return EE_Form_Section_Proper
236
+	 * @throws EE_Error
237
+	 * @throws ReflectionException
238
+	 */
239
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
240
+	{
241
+		$request = self::getRequest();
242
+		// only add the 'new_state_micro_form' when displaying reg forms,
243
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
+		$action = $request->getRequestParam('action');
245
+		// is the "state" question in this form section?
246
+		$input = $question_group_reg_form->get_subsection('state');
247
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
+			// ok then all we need to do is make sure the input's HTML name is consistent
249
+			// by forcing it to set it now, like it did while getting the form for display
250
+			if ($input instanceof EE_State_Select_Input) {
251
+				$input->html_name();
252
+			}
253
+			return $question_group_reg_form;
254
+		}
255
+		// we're only doing this for state select inputs
256
+		if ($input instanceof EE_State_Select_Input
257
+			&& ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
258
+		) {
259
+			// grab any set values from the request
260
+			$country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
261
+			$state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
262
+			$abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
263
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264
+			$country_options     = [];
265
+			$countries           = EEM_Country::instance()->get_all_countries();
266
+			if (! empty($countries)) {
267
+				foreach ($countries as $country) {
268
+					if ($country instanceof EE_Country) {
269
+						$country_options[ $country->ID() ] = $country->name();
270
+					}
271
+				}
272
+			}
273
+			$new_state_micro_form = new EE_Form_Section_Proper(
274
+				[
275
+					'name'            => 'new_state_micro_form',
276
+					'html_id'         => 'new_state_micro_form',
277
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
278
+					'subsections'     => [
279
+						// add hidden input to indicate that a new state is being added
280
+						'add_new_state'               => new EE_Hidden_Input(
281
+							[
282
+								'html_name' => str_replace(
283
+									'state',
284
+									'nsmf_add_new_state',
285
+									$input->html_name()
286
+								),
287
+								'html_id'   => str_replace(
288
+									'state',
289
+									'nsmf_add_new_state',
290
+									$input->html_id()
291
+								),
292
+								'default'   => 0,
293
+							]
294
+						),
295
+						// add link for displaying hidden container
296
+						'click_here_link'             => new EE_Form_Section_HTML(
297
+							apply_filters(
298
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
299
+								EEH_HTML::link(
300
+									'',
301
+									esc_html__('click here to add a new state/province', 'event_espresso'),
302
+									'',
303
+									'display-' . $input->html_id(),
304
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305
+									'',
306
+									'data-target="' . $input->html_id() . '"'
307
+								)
308
+							)
309
+						),
310
+						// add initial html for hidden container
311
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
312
+							apply_filters(
313
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314
+								EEH_HTML::div(
315
+									'',
316
+									$input->html_id() . '-dv',
317
+									'ee-form-add-new-state-dv',
318
+									'display: none;'
319
+								) .
320
+								EEH_HTML::h6(
321
+									esc_html__(
322
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323
+										'event_espresso'
324
+									)
325
+								) .
326
+								EEH_HTML::ul() .
327
+								EEH_HTML::li(
328
+									esc_html__(
329
+										'first select the Country that your State/Province belongs to',
330
+										'event_espresso'
331
+									)
332
+								) .
333
+								EEH_HTML::li(
334
+									esc_html__('enter the name of your State/Province', 'event_espresso')
335
+								) .
336
+								EEH_HTML::li(
337
+									esc_html__(
338
+										'enter a two to six letter abbreviation for the name of your State/Province',
339
+										'event_espresso'
340
+									)
341
+								) .
342
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
343
+								EEH_HTML::ulx()
344
+							)
345
+						),
346
+						// NEW STATE COUNTRY
347
+						'new_state_country'           => new EE_Country_Select_Input(
348
+							$country_options,
349
+							[
350
+								'html_name'       => $country_name,
351
+								'html_id'         => str_replace(
352
+									'state',
353
+									'nsmf_new_state_country',
354
+									$input->html_id()
355
+								),
356
+								'html_class'      => $input->html_class() . ' new-state-country',
357
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358
+								'default'         => $request->getRequestParam($country_name),
359
+								'required'        => false,
360
+							]
361
+						),
362
+						// NEW STATE NAME
363
+						'new_state_name'              => new EE_Text_Input(
364
+							[
365
+								'html_name'       => $state_name,
366
+								'html_id'         => str_replace(
367
+									'state',
368
+									'nsmf_new_state_name',
369
+									$input->html_id()
370
+								),
371
+								'html_class'      => $input->html_class() . ' new-state-state',
372
+								'html_label_text' => esc_html__(
373
+									'New State/Province Name',
374
+									'event_espresso'
375
+								),
376
+								'default'         => $request->getRequestParam($state_name),
377
+								'required'        => false,
378
+							]
379
+						),
380
+						'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
381
+						// NEW STATE NAME
382
+						'new_state_abbrv'             => new EE_Text_Input(
383
+							[
384
+								'html_name'             => $abbrv_name,
385
+								'html_id'               => str_replace(
386
+									'state',
387
+									'nsmf_new_state_abbrv',
388
+									$input->html_id()
389
+								),
390
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
391
+								'html_label_text'       => esc_html__(
392
+															   'New State/Province Abbreviation',
393
+															   'event_espresso'
394
+														   ) . ' *',
395
+								'other_html_attributes' => 'size="24"',
396
+								'default'               => $request->getRequestParam($abbrv_name),
397
+								'required'              => false,
398
+							]
399
+						),
400
+						// "submit" button
401
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
+							apply_filters(
403
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
+								EEH_HTML::nbsp(3) .
405
+								EEH_HTML::link(
406
+									'',
407
+									esc_html__('ADD', 'event_espresso'),
408
+									'',
409
+									'submit-' . $new_state_submit_id,
410
+									'ee-form-add-new-state-submit button button-secondary',
411
+									'',
412
+									'data-target="'
413
+									. $new_state_submit_id
414
+									. '" data-value-field-name="'
415
+									. $input->valueFieldName()
416
+									. '"'
417
+								)
418
+							)
419
+						),
420
+						// extra info
421
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
422
+							apply_filters(
423
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
424
+								EEH_HTML::br(2)
425
+								.
426
+								EEH_HTML::div('', '', 'small-text')
427
+								.
428
+								EEH_HTML::strong(
429
+									'* ' .
430
+									esc_html__(
431
+										'Don\'t know your State/Province Abbreviation?',
432
+										'event_espresso'
433
+									)
434
+								)
435
+								.
436
+								EEH_HTML::br()
437
+								.
438
+								sprintf(
439
+									esc_html__(
440
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
441
+										'event_espresso'
442
+									),
443
+									EEH_HTML::link(
444
+										'https://en.wikipedia.org/wiki/ISO_3166-2',
445
+										'https://en.wikipedia.org/wiki/ISO_3166-2',
446
+										'',
447
+										'',
448
+										'ee-form-add-new-state-wiki-lnk',
449
+										'',
450
+										'target="_blank"'
451
+									)
452
+								)
453
+								.
454
+								EEH_HTML::divx()
455
+								.
456
+								EEH_HTML::br()
457
+								.
458
+								EEH_HTML::link(
459
+									'',
460
+									esc_html__('cancel new State/Province', 'event_espresso'),
461
+									'',
462
+									'hide-' . $input->html_id(),
463
+									'ee-form-cancel-new-state-lnk smaller-text',
464
+									'',
465
+									'data-target="' . $input->html_id() . '"'
466
+								)
467
+								.
468
+								EEH_HTML::divx()
469
+								.
470
+								EEH_HTML::br()
471
+							)
472
+						),
473
+					],
474
+				]
475
+			);
476
+			$question_group_reg_form->add_subsections(
477
+				['new_state_micro_form' => $new_state_micro_form],
478
+				'state',
479
+				false
480
+			);
481
+		}
482
+		return $question_group_reg_form;
483
+	}
484
+
485
+
486
+	/**
487
+	 * set_new_state_input_width
488
+	 *
489
+	 * @return int|string
490
+	 * @throws EE_Error
491
+	 * @throws InvalidArgumentException
492
+	 * @throws InvalidDataTypeException
493
+	 * @throws InvalidInterfaceException
494
+	 * @throws ReflectionException
495
+	 */
496
+	public static function add_new_state()
497
+	{
498
+		$request = self::getRequest();
499
+		if ($request->getRequestParam('nsmf_add_new_state', 0, 'int') === 1) {
500
+			EE_Registry::instance()->load_model('State');
501
+			// grab country ISO code, new state name, and new state abbreviation
502
+			$state_country = $request->getRequestParam('nsmf_new_state_country');
503
+			$state_name    = $request->getRequestParam('nsmf_new_state_name');
504
+			$state_abbr    = $request->getRequestParam('nsmf_new_state_abbrv');
505
+			if ($state_country && $state_name && $state_abbr) {
506
+				$new_state = EED_Add_New_State::save_new_state_to_db(
507
+					[
508
+						'CNT_ISO'    => strtoupper($state_country),
509
+						'STA_abbrev' => strtoupper($state_abbr),
510
+						'STA_name'   => ucwords($state_name),
511
+						'STA_active' => false,
512
+					]
513
+				);
514
+				if ($new_state instanceof EE_State) {
515
+					// clean house
516
+					$request->unSetRequestParams(
517
+						[
518
+							'nsmf_add_new_state',
519
+							'nsmf_new_state_country',
520
+							'nsmf_new_state_name',
521
+							'nsmf_new_state_abbrv',
522
+						]
523
+					);
524
+					// get any existing new states
525
+					$new_states                     = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states');
526
+					$new_states[ $new_state->ID() ] = $new_state;
527
+					EE_Registry::instance()->SSN->set_session_data(
528
+						['nsmf_new_states' => $new_states]
529
+					);
530
+					if ($request->isAjax()) {
531
+						echo wp_json_encode(
532
+							[
533
+								'success'      => true,
534
+								'id'           => $new_state->ID(),
535
+								'name'         => $new_state->name(),
536
+								'abbrev'       => $new_state->abbrev(),
537
+								'country_iso'  => $new_state->country_iso(),
538
+								'country_name' => $new_state->country()->name(),
539
+							]
540
+						);
541
+						exit();
542
+					}
543
+					return $new_state->ID();
544
+				}
545
+			} else {
546
+				$error = esc_html__(
547
+					'A new State/Province could not be added because invalid or missing data was received.',
548
+					'event_espresso'
549
+				);
550
+				if ($request->isAjax()) {
551
+					echo wp_json_encode(['error' => $error]);
552
+					exit();
553
+				}
554
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
555
+			}
556
+		}
557
+		return false;
558
+	}
559
+
560
+
561
+	/**
562
+	 * recursively drills down through request params to remove any that were added by this module
563
+	 *
564
+	 * @param array $request_params
565
+	 * @return array
566
+	 */
567
+	public static function filter_checkout_request_params($request_params)
568
+	{
569
+		foreach ($request_params as $form_section) {
570
+			if (is_array($form_section)) {
571
+				EED_Add_New_State::unset_new_state_request_params($form_section);
572
+				EED_Add_New_State::filter_checkout_request_params($form_section);
573
+			}
574
+		}
575
+		return $request_params;
576
+	}
577
+
578
+
579
+	/**
580
+	 * @param array $request_params
581
+	 * @return array
582
+	 */
583
+	public static function unset_new_state_request_params($request_params)
584
+	{
585
+		unset(
586
+			$request_params['new_state_micro_form'],
587
+			$request_params['new_state_micro_add_new_state'],
588
+			$request_params['new_state_micro_new_state_country'],
589
+			$request_params['new_state_micro_new_state_name'],
590
+			$request_params['new_state_micro_new_state_abbrv']
591
+		);
592
+		return $request_params;
593
+	}
594
+
595
+
596
+	/**
597
+	 * @param array $props_n_values
598
+	 * @return EE_State|null
599
+	 * @throws EE_Error
600
+	 * @throws ReflectionException
601
+	 */
602
+	public static function save_new_state_to_db($props_n_values = [])
603
+	{
604
+		/** @var EE_State[] $existing_state */
605
+		$existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]);
606
+		if (! empty($existing_state)) {
607
+			return array_pop($existing_state);
608
+		}
609
+		$new_state = EE_State::new_instance($props_n_values);
610
+		if ($new_state instanceof EE_State) {
611
+			$country_settings_url = add_query_arg(
612
+				[
613
+					'page'    => 'espresso_general_settings',
614
+					'action'  => 'country_settings',
615
+					'country' => $new_state->country_iso(),
616
+				],
617
+				admin_url('admin.php')
618
+			);
619
+			// if not non-ajax admin
620
+			new PersistentAdminNotice(
621
+				'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
622
+				sprintf(
623
+					esc_html__(
624
+						'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.',
625
+						'event_espresso'
626
+					),
627
+					'<b>' . $new_state->name() . '</b>',
628
+					'<b>' . $new_state->abbrev() . '</b>',
629
+					'<b>' . $new_state->country()->name() . '</b>',
630
+					'<a href="'
631
+					. $country_settings_url
632
+					. '">'
633
+					. esc_html__(
634
+						'Event Espresso - General Settings > Countries Tab',
635
+						'event_espresso'
636
+					)
637
+					. '</a>',
638
+					'<br />'
639
+				)
640
+			);
641
+			$new_state->save();
642
+			EEM_State::instance()->reset_cached_states();
643
+			return $new_state;
644
+		}
645
+		return null;
646
+	}
647
+
648
+
649
+	/**
650
+	 * @param string $CNT_ISO
651
+	 * @param string $STA_ID
652
+	 * @param array  $cols_n_values
653
+	 * @return void
654
+	 * @throws DomainException
655
+	 * @throws EE_Error
656
+	 * @throws InvalidArgumentException
657
+	 * @throws InvalidDataTypeException
658
+	 * @throws InvalidInterfaceException
659
+	 */
660
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = [])
661
+	{
662
+		if (! $CNT_ISO) {
663
+			EE_Error::add_error(
664
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
665
+				__FILE__,
666
+				__FUNCTION__,
667
+				__LINE__
668
+			);
669
+		}
670
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
671
+			: false;
672
+		if (! $STA_abbrev && ! empty($STA_ID)) {
673
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
674
+			if ($state instanceof EE_State) {
675
+				$STA_abbrev = $state->abbrev();
676
+			}
677
+		}
678
+		if (! $STA_abbrev) {
679
+			EE_Error::add_error(
680
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
681
+				__FILE__,
682
+				__FUNCTION__,
683
+				__LINE__
684
+			);
685
+		}
686
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
687
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
688
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
689
+		);
690
+		$persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
691
+	}
692
+
693
+
694
+	/**
695
+	 * @param EE_State[]                            $state_options
696
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
697
+	 * @param EE_Registration                       $registration
698
+	 * @param EE_Question                           $question
699
+	 * @param                                       $answer
700
+	 * @return array
701
+	 * @throws EE_Error
702
+	 * @throws ReflectionException
703
+	 */
704
+	public static function inject_new_reg_state_into_options(
705
+		array $state_options,
706
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
707
+		EE_Registration $registration,
708
+		EE_Question $question,
709
+		$answer
710
+	) {
711
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
712
+			&& $question->type() === EEM_Question::QST_type_state
713
+		) {
714
+			$STA_ID = $answer->value();
715
+			if (! empty($STA_ID)) {
716
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
717
+				if ($state instanceof EE_State) {
718
+					$country = $state->country();
719
+					if ($country instanceof EE_Country) {
720
+						if (! isset($state_options[ $country->name() ])) {
721
+							$state_options[ $country->name() ] = [];
722
+						}
723
+						if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
724
+							$state_options[ $country->name() ][ $STA_ID ] = $state->name();
725
+						}
726
+					}
727
+				}
728
+			}
729
+		}
730
+		return $state_options;
731
+	}
732
+
733
+
734
+	/**
735
+	 * @param EE_Country[]                          $country_options
736
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
737
+	 * @param EE_Registration                       $registration
738
+	 * @param EE_Question                           $question
739
+	 * @param                                       $answer
740
+	 * @return array
741
+	 * @throws EE_Error
742
+	 * @throws ReflectionException
743
+	 */
744
+	public static function inject_new_reg_country_into_options(
745
+		array $country_options,
746
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
747
+		EE_Registration $registration,
748
+		EE_Question $question,
749
+		$answer
750
+	) {
751
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
752
+			&& $question->type()
753
+			   === EEM_Question::QST_type_country
754
+		) {
755
+			$CNT_ISO = $answer->value();
756
+			if (! empty($CNT_ISO)) {
757
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
758
+				if ($country instanceof EE_Country) {
759
+					if (! isset($country_options[ $CNT_ISO ])) {
760
+						$country_options[ $CNT_ISO ] = $country->name();
761
+					}
762
+				}
763
+			}
764
+		}
765
+		return $country_options;
766
+	}
767
+
768
+
769
+	/**
770
+	 * @param EE_State[] $state_options
771
+	 * @return array
772
+	 * @throws EE_Error
773
+	 * @throws ReflectionException
774
+	 */
775
+	public static function state_options($state_options = [])
776
+	{
777
+		$new_states = EED_Add_New_State::_get_new_states();
778
+		foreach ($new_states as $new_state) {
779
+			if ($new_state instanceof EE_State
780
+				&& $new_state->country() instanceof EE_Country
781
+			) {
782
+				$state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
783
+			}
784
+		}
785
+		return $state_options;
786
+	}
787
+
788
+
789
+	/**
790
+	 * @return array
791
+	 * @throws InvalidArgumentException
792
+	 * @throws InvalidDataTypeException
793
+	 * @throws InvalidInterfaceException
794
+	 */
795
+	protected static function _get_new_states()
796
+	{
797
+		$new_states = [];
798
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
799
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
800
+				'nsmf_new_states'
801
+			);
802
+		}
803
+		return is_array($new_states) ? $new_states : [];
804
+	}
805
+
806
+
807
+	/**
808
+	 * @param EE_Country[] $country_options
809
+	 * @return array
810
+	 * @throws EE_Error
811
+	 * @throws ReflectionException
812
+	 */
813
+	public static function country_options($country_options = [])
814
+	{
815
+		$new_states = EED_Add_New_State::_get_new_states();
816
+		foreach ($new_states as $new_state) {
817
+			if ($new_state instanceof EE_State
818
+				&& $new_state->country() instanceof EE_Country
819
+			) {
820
+				$country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
821
+			}
822
+		}
823
+		return $country_options;
824
+	}
825 825
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
      */
162 162
     public static function set_definitions()
163 163
     {
164
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
164
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
165 165
         define(
166 166
             'ANS_TEMPLATES_PATH',
167 167
             str_replace(
168 168
                 '\\',
169 169
                 '/',
170 170
                 plugin_dir_path(__FILE__)
171
-            ) . 'templates/'
171
+            ).'templates/'
172 172
         );
173 173
     }
174 174
 
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public static function translate_js_strings()
189 189
     {
190
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
190
+        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
191 191
             'In order to proceed, you need to select the Country that your State/Province belongs to.',
192 192
             'event_espresso'
193 193
         );
194
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
194
+        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
195 195
             'In order to proceed, you need to enter the name of your State/Province.',
196 196
             'event_espresso'
197 197
         );
198
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
198
+        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
199 199
             'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
200 200
             'event_espresso'
201 201
         );
202
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
202
+        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
203 203
             'The new state was successfully saved to the database.',
204 204
             'event_espresso'
205 205
         );
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
219 219
             wp_register_script(
220 220
                 'add_new_state',
221
-                ANS_ASSETS_URL . 'add_new_state.js',
221
+                ANS_ASSETS_URL.'add_new_state.js',
222 222
                 ['espresso_core', 'single_page_checkout'],
223 223
                 EVENT_ESPRESSO_VERSION,
224 224
                 true
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264 264
             $country_options     = [];
265 265
             $countries           = EEM_Country::instance()->get_all_countries();
266
-            if (! empty($countries)) {
266
+            if ( ! empty($countries)) {
267 267
                 foreach ($countries as $country) {
268 268
                     if ($country instanceof EE_Country) {
269
-                        $country_options[ $country->ID() ] = $country->name();
269
+                        $country_options[$country->ID()] = $country->name();
270 270
                     }
271 271
                 }
272 272
             }
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
                                     '',
301 301
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
302 302
                                     '',
303
-                                    'display-' . $input->html_id(),
303
+                                    'display-'.$input->html_id(),
304 304
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305 305
                                     '',
306
-                                    'data-target="' . $input->html_id() . '"'
306
+                                    'data-target="'.$input->html_id().'"'
307 307
                                 )
308 308
                             )
309 309
                         ),
@@ -313,33 +313,33 @@  discard block
 block discarded – undo
313 313
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314 314
                                 EEH_HTML::div(
315 315
                                     '',
316
-                                    $input->html_id() . '-dv',
316
+                                    $input->html_id().'-dv',
317 317
                                     'ee-form-add-new-state-dv',
318 318
                                     'display: none;'
319
-                                ) .
319
+                                ).
320 320
                                 EEH_HTML::h6(
321 321
                                     esc_html__(
322 322
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323 323
                                         'event_espresso'
324 324
                                     )
325
-                                ) .
326
-                                EEH_HTML::ul() .
325
+                                ).
326
+                                EEH_HTML::ul().
327 327
                                 EEH_HTML::li(
328 328
                                     esc_html__(
329 329
                                         'first select the Country that your State/Province belongs to',
330 330
                                         'event_espresso'
331 331
                                     )
332
-                                ) .
332
+                                ).
333 333
                                 EEH_HTML::li(
334 334
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
335
-                                ) .
335
+                                ).
336 336
                                 EEH_HTML::li(
337 337
                                     esc_html__(
338 338
                                         'enter a two to six letter abbreviation for the name of your State/Province',
339 339
                                         'event_espresso'
340 340
                                     )
341
-                                ) .
342
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
341
+                                ).
342
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
343 343
                                 EEH_HTML::ulx()
344 344
                             )
345 345
                         ),
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
                                     'nsmf_new_state_country',
354 354
                                     $input->html_id()
355 355
                                 ),
356
-                                'html_class'      => $input->html_class() . ' new-state-country',
356
+                                'html_class'      => $input->html_class().' new-state-country',
357 357
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358 358
                                 'default'         => $request->getRequestParam($country_name),
359 359
                                 'required'        => false,
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                                     'nsmf_new_state_name',
369 369
                                     $input->html_id()
370 370
                                 ),
371
-                                'html_class'      => $input->html_class() . ' new-state-state',
371
+                                'html_class'      => $input->html_class().' new-state-state',
372 372
                                 'html_label_text' => esc_html__(
373 373
                                     'New State/Province Name',
374 374
                                     'event_espresso'
@@ -387,11 +387,11 @@  discard block
 block discarded – undo
387 387
                                     'nsmf_new_state_abbrv',
388 388
                                     $input->html_id()
389 389
                                 ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
390
+                                'html_class'            => $input->html_class().' new-state-abbrv',
391 391
                                 'html_label_text'       => esc_html__(
392 392
                                                                'New State/Province Abbreviation',
393 393
                                                                'event_espresso'
394
-                                                           ) . ' *',
394
+                                                           ).' *',
395 395
                                 'other_html_attributes' => 'size="24"',
396 396
                                 'default'               => $request->getRequestParam($abbrv_name),
397 397
                                 'required'              => false,
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
                         'add_new_state_submit_button' => new EE_Form_Section_HTML(
402 402
                             apply_filters(
403 403
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
-                                EEH_HTML::nbsp(3) .
404
+                                EEH_HTML::nbsp(3).
405 405
                                 EEH_HTML::link(
406 406
                                     '',
407 407
                                     esc_html__('ADD', 'event_espresso'),
408 408
                                     '',
409
-                                    'submit-' . $new_state_submit_id,
409
+                                    'submit-'.$new_state_submit_id,
410 410
                                     'ee-form-add-new-state-submit button button-secondary',
411 411
                                     '',
412 412
                                     'data-target="'
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
                                 EEH_HTML::div('', '', 'small-text')
427 427
                                 .
428 428
                                 EEH_HTML::strong(
429
-                                    '* ' .
429
+                                    '* '.
430 430
                                     esc_html__(
431 431
                                         'Don\'t know your State/Province Abbreviation?',
432 432
                                         'event_espresso'
@@ -459,10 +459,10 @@  discard block
 block discarded – undo
459 459
                                     '',
460 460
                                     esc_html__('cancel new State/Province', 'event_espresso'),
461 461
                                     '',
462
-                                    'hide-' . $input->html_id(),
462
+                                    'hide-'.$input->html_id(),
463 463
                                     'ee-form-cancel-new-state-lnk smaller-text',
464 464
                                     '',
465
-                                    'data-target="' . $input->html_id() . '"'
465
+                                    'data-target="'.$input->html_id().'"'
466 466
                                 )
467 467
                                 .
468 468
                                 EEH_HTML::divx()
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
                     );
524 524
                     // get any existing new states
525 525
                     $new_states                     = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states');
526
-                    $new_states[ $new_state->ID() ] = $new_state;
526
+                    $new_states[$new_state->ID()] = $new_state;
527 527
                     EE_Registry::instance()->SSN->set_session_data(
528 528
                         ['nsmf_new_states' => $new_states]
529 529
                     );
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
     {
604 604
         /** @var EE_State[] $existing_state */
605 605
         $existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]);
606
-        if (! empty($existing_state)) {
606
+        if ( ! empty($existing_state)) {
607 607
             return array_pop($existing_state);
608 608
         }
609 609
         $new_state = EE_State::new_instance($props_n_values);
@@ -618,15 +618,15 @@  discard block
 block discarded – undo
618 618
             );
619 619
             // if not non-ajax admin
620 620
             new PersistentAdminNotice(
621
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
621
+                'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(),
622 622
                 sprintf(
623 623
                     esc_html__(
624 624
                         '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.',
625 625
                         'event_espresso'
626 626
                     ),
627
-                    '<b>' . $new_state->name() . '</b>',
628
-                    '<b>' . $new_state->abbrev() . '</b>',
629
-                    '<b>' . $new_state->country()->name() . '</b>',
627
+                    '<b>'.$new_state->name().'</b>',
628
+                    '<b>'.$new_state->abbrev().'</b>',
629
+                    '<b>'.$new_state->country()->name().'</b>',
630 630
                     '<a href="'
631 631
                     . $country_settings_url
632 632
                     . '">'
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
      */
660 660
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = [])
661 661
     {
662
-        if (! $CNT_ISO) {
662
+        if ( ! $CNT_ISO) {
663 663
             EE_Error::add_error(
664 664
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
665 665
                 __FILE__,
@@ -669,13 +669,13 @@  discard block
 block discarded – undo
669 669
         }
670 670
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
671 671
             : false;
672
-        if (! $STA_abbrev && ! empty($STA_ID)) {
672
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
673 673
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
674 674
             if ($state instanceof EE_State) {
675 675
                 $STA_abbrev = $state->abbrev();
676 676
             }
677 677
         }
678
-        if (! $STA_abbrev) {
678
+        if ( ! $STA_abbrev) {
679 679
             EE_Error::add_error(
680 680
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
681 681
                 __FILE__,
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
         $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
688 688
             'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
689 689
         );
690
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
690
+        $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true);
691 691
     }
692 692
 
693 693
 
@@ -712,16 +712,16 @@  discard block
 block discarded – undo
712 712
             && $question->type() === EEM_Question::QST_type_state
713 713
         ) {
714 714
             $STA_ID = $answer->value();
715
-            if (! empty($STA_ID)) {
715
+            if ( ! empty($STA_ID)) {
716 716
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
717 717
                 if ($state instanceof EE_State) {
718 718
                     $country = $state->country();
719 719
                     if ($country instanceof EE_Country) {
720
-                        if (! isset($state_options[ $country->name() ])) {
721
-                            $state_options[ $country->name() ] = [];
720
+                        if ( ! isset($state_options[$country->name()])) {
721
+                            $state_options[$country->name()] = [];
722 722
                         }
723
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
724
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
723
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
724
+                            $state_options[$country->name()][$STA_ID] = $state->name();
725 725
                         }
726 726
                     }
727 727
                 }
@@ -753,11 +753,11 @@  discard block
 block discarded – undo
753 753
                === EEM_Question::QST_type_country
754 754
         ) {
755 755
             $CNT_ISO = $answer->value();
756
-            if (! empty($CNT_ISO)) {
756
+            if ( ! empty($CNT_ISO)) {
757 757
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
758 758
                 if ($country instanceof EE_Country) {
759
-                    if (! isset($country_options[ $CNT_ISO ])) {
760
-                        $country_options[ $CNT_ISO ] = $country->name();
759
+                    if ( ! isset($country_options[$CNT_ISO])) {
760
+                        $country_options[$CNT_ISO] = $country->name();
761 761
                     }
762 762
                 }
763 763
             }
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
             if ($new_state instanceof EE_State
780 780
                 && $new_state->country() instanceof EE_Country
781 781
             ) {
782
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
782
+                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
783 783
             }
784 784
         }
785 785
         return $state_options;
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
             if ($new_state instanceof EE_State
818 818
                 && $new_state->country() instanceof EE_Country
819 819
             ) {
820
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
820
+                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
821 821
             }
822 822
         }
823 823
         return $country_options;
Please login to merge, or discard this patch.
modules/events_archive/EventsArchiveIframe.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -23,58 +23,58 @@
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     * EventsArchiveIframe constructor.
28
-     *
29
-     * @param EED_Events_Archive $EED_Events_Archive
30
-     * @throws EE_Error
31
-     * @throws ReflectionException
32
-     */
33
-    public function __construct($EED_Events_Archive)
34
-    {
35
-        /** @var CurrentPage $current_page */
36
-        $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
37
-        $current_page->setEspressoPage(true);
38
-        add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true');
39
-        $EED_Events_Archive->event_list();
40
-        /** @var EspressoEvents $event_list */
41
-        $event_list = EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents');
42
-        parent::__construct(
43
-            esc_html__('Event List', 'event_espresso'),
44
-            $event_list->processShortcode()
45
-        );
46
-        $this->addStylesheets(
47
-            apply_filters(
48
-                'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
49
-                [
50
-                    'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
51
-                        ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
52
-                        : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
53
-                ],
54
-                $this
55
-            )
56
-        );
57
-        $this->addScripts(
58
-            apply_filters(
59
-                'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
60
-                [
61
-                    'gmap_api' => sprintf(
62
-                        'https://maps.googleapis.com/maps/api/js?key=%s',
63
-                        apply_filters(
64
-                            'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
65
-                            EE_Registry::instance()->CFG->map_settings->google_map_api_key
66
-                        )
67
-                    ),
68
-                    'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
69
-                ],
70
-                $this
71
-            )
72
-        );
73
-        $this->addLocalizedVars(
74
-            [
75
-                'ee_gmap' => EEH_Maps::$gmap_vars,
76
-            ],
77
-            'ee_gmap_vars'
78
-        );
79
-    }
26
+	/**
27
+	 * EventsArchiveIframe constructor.
28
+	 *
29
+	 * @param EED_Events_Archive $EED_Events_Archive
30
+	 * @throws EE_Error
31
+	 * @throws ReflectionException
32
+	 */
33
+	public function __construct($EED_Events_Archive)
34
+	{
35
+		/** @var CurrentPage $current_page */
36
+		$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
37
+		$current_page->setEspressoPage(true);
38
+		add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true');
39
+		$EED_Events_Archive->event_list();
40
+		/** @var EspressoEvents $event_list */
41
+		$event_list = EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents');
42
+		parent::__construct(
43
+			esc_html__('Event List', 'event_espresso'),
44
+			$event_list->processShortcode()
45
+		);
46
+		$this->addStylesheets(
47
+			apply_filters(
48
+				'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
49
+				[
50
+					'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
51
+						? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
52
+						: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
53
+				],
54
+				$this
55
+			)
56
+		);
57
+		$this->addScripts(
58
+			apply_filters(
59
+				'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
60
+				[
61
+					'gmap_api' => sprintf(
62
+						'https://maps.googleapis.com/maps/api/js?key=%s',
63
+						apply_filters(
64
+							'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
65
+							EE_Registry::instance()->CFG->map_settings->google_map_api_key
66
+						)
67
+					),
68
+					'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
69
+				],
70
+				$this
71
+			)
72
+		);
73
+		$this->addLocalizedVars(
74
+			[
75
+				'ee_gmap' => EEH_Maps::$gmap_vars,
76
+			],
77
+			'ee_gmap_vars'
78
+		);
79
+	}
80 80
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
             apply_filters(
48 48
                 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
49 49
                 [
50
-                    'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
51
-                        ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
52
-                        : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
50
+                    'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
51
+                        ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION
52
+                        : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION,
53 53
                 ],
54 54
                 $this
55 55
             )
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
                             EE_Registry::instance()->CFG->map_settings->google_map_api_key
66 66
                         )
67 67
                     ),
68
-                    'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
68
+                    'ee_gmap'  => EE_HELPERS_ASSETS.'ee_gmap.js?ver=1.0',
69 69
                 ],
70 70
                 $this
71 71
             )
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorIframe.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -19,75 +19,75 @@
 block discarded – undo
19 19
  */
20 20
 class TicketSelectorIframe extends Iframe
21 21
 {
22
-    /**
23
-     * TicketSelectorIframe constructor.
24
-     *
25
-     * @param EEM_Event        $event_model
26
-     * @param CurrentPage      $current_page
27
-     * @param RequestInterface $request
28
-     * @throws EE_Error
29
-     */
30
-    public function __construct(EEM_Event $event_model, CurrentPage $current_page, RequestInterface $request)
31
-    {
32
-        $current_page->setEspressoPage(true);
33
-        $ticket_selector = LoaderFactory::getLoader()->getNew(DisplayTicketSelector::class);
34
-        $ticket_selector->setIframe();
35
-        $event = $event_model->get_one_by_ID($request->getRequestParam('event', 0, 'int'));
36
-        parent::__construct(
37
-            esc_html__('Ticket Selector', 'event_espresso'),
38
-            $ticket_selector->display($event)
39
-        );
40
-        $this->addStylesheets(
41
-            apply_filters(
42
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
43
-                array(
44
-                    'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
45
-                                               . 'ticket_selector_embed.css?ver='
46
-                                               . EVENT_ESPRESSO_VERSION,
47
-                    'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
48
-                                               . 'ticket_selector.css?ver='
49
-                                               . EVENT_ESPRESSO_VERSION,
50
-                ),
51
-                $this
52
-            )
53
-        );
54
-        if (! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
55
-            $this->addStylesheets(array('site_theme' => ''));
56
-        }
57
-        $this->addScripts(
58
-            apply_filters(
59
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
60
-                array(
61
-                    'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
62
-                                                      . 'ticket_selector_iframe_embed.js?ver='
63
-                                                      . EVENT_ESPRESSO_VERSION,
64
-                ),
65
-                $this
66
-            )
67
-        );
68
-        $js_attributes = apply_filters(
69
-            'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
70
-            array(),
71
-            $this
72
-        );
73
-        if (! empty($js_attributes)) {
74
-            $this->addScriptAttributes($js_attributes);
75
-        }
76
-        $this->addLocalizedVars(
77
-            apply_filters(
78
-                'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars',
79
-                array(
80
-                    'ticket_selector_iframe' => true,
81
-                    'EEDTicketSelectorMsg'   => __(
82
-                        'Please choose at least one ticket before continuing.',
83
-                        'event_espresso'
84
-                    ),
85
-                )
86
-            )
87
-        );
88
-        do_action(
89
-            'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
90
-            $this
91
-        );
92
-    }
22
+	/**
23
+	 * TicketSelectorIframe constructor.
24
+	 *
25
+	 * @param EEM_Event        $event_model
26
+	 * @param CurrentPage      $current_page
27
+	 * @param RequestInterface $request
28
+	 * @throws EE_Error
29
+	 */
30
+	public function __construct(EEM_Event $event_model, CurrentPage $current_page, RequestInterface $request)
31
+	{
32
+		$current_page->setEspressoPage(true);
33
+		$ticket_selector = LoaderFactory::getLoader()->getNew(DisplayTicketSelector::class);
34
+		$ticket_selector->setIframe();
35
+		$event = $event_model->get_one_by_ID($request->getRequestParam('event', 0, 'int'));
36
+		parent::__construct(
37
+			esc_html__('Ticket Selector', 'event_espresso'),
38
+			$ticket_selector->display($event)
39
+		);
40
+		$this->addStylesheets(
41
+			apply_filters(
42
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
43
+				array(
44
+					'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
45
+											   . 'ticket_selector_embed.css?ver='
46
+											   . EVENT_ESPRESSO_VERSION,
47
+					'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
48
+											   . 'ticket_selector.css?ver='
49
+											   . EVENT_ESPRESSO_VERSION,
50
+				),
51
+				$this
52
+			)
53
+		);
54
+		if (! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
55
+			$this->addStylesheets(array('site_theme' => ''));
56
+		}
57
+		$this->addScripts(
58
+			apply_filters(
59
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
60
+				array(
61
+					'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
62
+													  . 'ticket_selector_iframe_embed.js?ver='
63
+													  . EVENT_ESPRESSO_VERSION,
64
+				),
65
+				$this
66
+			)
67
+		);
68
+		$js_attributes = apply_filters(
69
+			'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
70
+			array(),
71
+			$this
72
+		);
73
+		if (! empty($js_attributes)) {
74
+			$this->addScriptAttributes($js_attributes);
75
+		}
76
+		$this->addLocalizedVars(
77
+			apply_filters(
78
+				'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars',
79
+				array(
80
+					'ticket_selector_iframe' => true,
81
+					'EEDTicketSelectorMsg'   => __(
82
+						'Please choose at least one ticket before continuing.',
83
+						'event_espresso'
84
+					),
85
+				)
86
+			)
87
+		);
88
+		do_action(
89
+			'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
90
+			$this
91
+		);
92
+	}
93 93
 }
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorSimple.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -20,58 +20,58 @@
 block discarded – undo
20 20
 class TicketSelectorSimple extends TicketSelector
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Ticket $ticket
25
-     */
26
-    protected $ticket;
23
+	/**
24
+	 * @var EE_Ticket $ticket
25
+	 */
26
+	protected $ticket;
27 27
 
28 28
 
29
-    /**
30
-     * TicketSelectorSimple constructor.
31
-     *
32
-     * @param EE_Event  $event
33
-     * @param EE_Ticket $ticket
34
-     * @param int       $max_attendees
35
-     * @param array     $template_args
36
-     * @throws EE_Error
37
-     */
38
-    public function __construct(EE_Event $event, EE_Ticket $ticket, $max_attendees, array $template_args)
39
-    {
40
-        $this->ticket = $ticket;
41
-        parent::__construct(
42
-            $event,
43
-            [$this->ticket],
44
-            $max_attendees,
45
-            $template_args
46
-        );
47
-    }
29
+	/**
30
+	 * TicketSelectorSimple constructor.
31
+	 *
32
+	 * @param EE_Event  $event
33
+	 * @param EE_Ticket $ticket
34
+	 * @param int       $max_attendees
35
+	 * @param array     $template_args
36
+	 * @throws EE_Error
37
+	 */
38
+	public function __construct(EE_Event $event, EE_Ticket $ticket, $max_attendees, array $template_args)
39
+	{
40
+		$this->ticket = $ticket;
41
+		parent::__construct(
42
+			$event,
43
+			[$this->ticket],
44
+			$max_attendees,
45
+			$template_args
46
+		);
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * sets any and all template args that are required for this Ticket Selector
52
-     *
53
-     * @return void
54
-     * @throws UnexpectedEntityException
55
-     * @throws EE_Error
56
-     */
57
-    protected function addTemplateArgs()
58
-    {
59
-        unset($this->template_args['tickets']);
60
-        $this->template_args['ticket'] = $this->ticket;
61
-        $ticket_selector_row           = new TicketSelectorRowSimple(
62
-            $this->ticket,
63
-            $this->max_attendees,
64
-            $this->template_args['date_format'],
65
-            $this->template_args['event_status']
66
-        );
67
-        $this->template_args['TKT_ID'] = $this->ticket->ID();
68
-        $ticket_selector_row->setupTicketStatusDisplay();
69
-        $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay();
70
-        if (empty($this->template_args['ticket_status_display'])) {
71
-            add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
72
-        }
73
-        $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription();
74
-        $this->template_args['template_path']      =
75
-            TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
76
-    }
50
+	/**
51
+	 * sets any and all template args that are required for this Ticket Selector
52
+	 *
53
+	 * @return void
54
+	 * @throws UnexpectedEntityException
55
+	 * @throws EE_Error
56
+	 */
57
+	protected function addTemplateArgs()
58
+	{
59
+		unset($this->template_args['tickets']);
60
+		$this->template_args['ticket'] = $this->ticket;
61
+		$ticket_selector_row           = new TicketSelectorRowSimple(
62
+			$this->ticket,
63
+			$this->max_attendees,
64
+			$this->template_args['date_format'],
65
+			$this->template_args['event_status']
66
+		);
67
+		$this->template_args['TKT_ID'] = $this->ticket->ID();
68
+		$ticket_selector_row->setupTicketStatusDisplay();
69
+		$this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay();
70
+		if (empty($this->template_args['ticket_status_display'])) {
71
+			add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
72
+		}
73
+		$this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription();
74
+		$this->template_args['template_path']      =
75
+			TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
76
+	}
77 77
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,6 +72,6 @@
 block discarded – undo
72 72
         }
73 73
         $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription();
74 74
         $this->template_args['template_path']      =
75
-            TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
75
+            TICKET_SELECTOR_TEMPLATES_PATH.'simple_ticket_selector.template.php';
76 76
     }
77 77
 }
Please login to merge, or discard this patch.