Completed
Branch BUG-10725-paypal-express-dupli... (e50e53)
by
unknown
31:07 queued 17:12
created
modules/messages/EED_Messages.module.php 1 patch
Indentation   +1069 added lines, -1069 removed lines patch added patch discarded remove patch
@@ -13,1084 +13,1084 @@
 block discarded – undo
13 13
 class EED_Messages extends EED_Module
14 14
 {
15 15
 
16
-    /**
17
-     * This holds the EE_messages controller
18
-     *
19
-     * @deprecated 4.9.0
20
-     * @var EE_messages $_EEMSG
21
-     */
22
-    protected static $_EEMSG;
23
-
24
-    /**
25
-     * @type EE_Message_Resource_Manager $_message_resource_manager
26
-     */
27
-    protected static $_message_resource_manager;
28
-
29
-    /**
30
-     * This holds the EE_Messages_Processor business class.
31
-     *
32
-     * @type EE_Messages_Processor
33
-     */
34
-    protected static $_MSG_PROCESSOR;
35
-
36
-    /**
37
-     * holds all the paths for various messages components.
38
-     * Utilized by autoloader registry
39
-     *
40
-     * @var array
41
-     */
42
-    protected static $_MSG_PATHS;
43
-
44
-
45
-    /**
46
-     * This will hold an array of messages template packs that are registered in the messages system.
47
-     * Format is:
48
-     * array(
49
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
50
-     * )
51
-     *
52
-     * @var EE_Messages_Template_Pack[]
53
-     */
54
-    protected static $_TMP_PACKS = array();
55
-
56
-
57
-    /**
58
-     * @return EED_Messages
59
-     */
60
-    public static function instance()
61
-    {
62
-        return parent::get_instance(__CLASS__);
63
-    }
64
-
65
-
66
-    /**
67
-     *  set_hooks - for hooking into EE Core, other modules, etc
68
-     *
69
-     * @since 4.5.0
70
-     * @return    void
71
-     */
72
-    public static function set_hooks()
73
-    {
74
-        //actions
75
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
76
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
77
-            array('EED_Messages', 'maybe_registration'), 10, 2);
78
-        //filters
79
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
80
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
81
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
82
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
83
-        //register routes
84
-        self::_register_routes();
85
-    }
86
-
87
-    /**
88
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
89
-     *
90
-     * @access    public
91
-     * @return    void
92
-     */
93
-    public static function set_hooks_admin()
94
-    {
95
-        //actions
96
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
97
-        add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
98
-            array('EED_Messages', 'payment_reminder'), 10);
99
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
100
-            array('EED_Messages', 'maybe_registration'), 10, 3);
101
-        add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
102
-            array('EED_Messages', 'send_newsletter_message'), 10, 2);
103
-        add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
104
-            array('EED_Messages', 'cancelled_registration'), 10);
105
-        add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
106
-            array('EED_Messages', 'process_admin_payment'), 10, 1);
107
-        //filters
108
-        add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
109
-            array('EED_Messages', 'process_resend'), 10, 2);
110
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
111
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
112
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
113
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
114
-    }
115
-
116
-
117
-    /**
118
-     * All the message triggers done by route go in here.
119
-     *
120
-     * @since 4.5.0
121
-     * @return void
122
-     */
123
-    protected static function _register_routes()
124
-    {
125
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
126
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
127
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
128
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
129
-        do_action('AHEE__EED_Messages___register_routes');
130
-    }
131
-
132
-
133
-    /**
134
-     * This is called when a browser display trigger is executed.
135
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
136
-     * browser.
137
-     *
138
-     * @since 4.9.0
139
-     * @param WP $WP
140
-     */
141
-    public function browser_trigger($WP)
142
-    {
143
-        //ensure controller is loaded
144
-        self::_load_controller();
145
-        $token = EE_Registry::instance()->REQ->get('token');
146
-        try {
147
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
148
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
149
-        } catch (EE_Error $e) {
150
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
151
-                'event_espresso');
152
-            // add specific message for developers if WP_DEBUG in on
153
-            $error_msg .= '||' . $e->getMessage();
154
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * This is called when a browser error trigger is executed.
161
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
162
-     * message and display it.
163
-     *
164
-     * @since 4.9.0
165
-     * @param $WP
166
-     */
167
-    public function browser_error_trigger($WP)
168
-    {
169
-        $token = EE_Registry::instance()->REQ->get('token');
170
-        if ($token) {
171
-            $message = EEM_Message::instance()->get_one_by_token($token);
172
-            if ($message instanceof EE_Message) {
173
-                header('HTTP/1.1 200 OK');
174
-                $error_msg = nl2br($message->error_message());
175
-                ?>
16
+	/**
17
+	 * This holds the EE_messages controller
18
+	 *
19
+	 * @deprecated 4.9.0
20
+	 * @var EE_messages $_EEMSG
21
+	 */
22
+	protected static $_EEMSG;
23
+
24
+	/**
25
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
26
+	 */
27
+	protected static $_message_resource_manager;
28
+
29
+	/**
30
+	 * This holds the EE_Messages_Processor business class.
31
+	 *
32
+	 * @type EE_Messages_Processor
33
+	 */
34
+	protected static $_MSG_PROCESSOR;
35
+
36
+	/**
37
+	 * holds all the paths for various messages components.
38
+	 * Utilized by autoloader registry
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected static $_MSG_PATHS;
43
+
44
+
45
+	/**
46
+	 * This will hold an array of messages template packs that are registered in the messages system.
47
+	 * Format is:
48
+	 * array(
49
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
50
+	 * )
51
+	 *
52
+	 * @var EE_Messages_Template_Pack[]
53
+	 */
54
+	protected static $_TMP_PACKS = array();
55
+
56
+
57
+	/**
58
+	 * @return EED_Messages
59
+	 */
60
+	public static function instance()
61
+	{
62
+		return parent::get_instance(__CLASS__);
63
+	}
64
+
65
+
66
+	/**
67
+	 *  set_hooks - for hooking into EE Core, other modules, etc
68
+	 *
69
+	 * @since 4.5.0
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks()
73
+	{
74
+		//actions
75
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
76
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
77
+			array('EED_Messages', 'maybe_registration'), 10, 2);
78
+		//filters
79
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
80
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
81
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
82
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
83
+		//register routes
84
+		self::_register_routes();
85
+	}
86
+
87
+	/**
88
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
89
+	 *
90
+	 * @access    public
91
+	 * @return    void
92
+	 */
93
+	public static function set_hooks_admin()
94
+	{
95
+		//actions
96
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
97
+		add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
98
+			array('EED_Messages', 'payment_reminder'), 10);
99
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
100
+			array('EED_Messages', 'maybe_registration'), 10, 3);
101
+		add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
102
+			array('EED_Messages', 'send_newsletter_message'), 10, 2);
103
+		add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
104
+			array('EED_Messages', 'cancelled_registration'), 10);
105
+		add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
106
+			array('EED_Messages', 'process_admin_payment'), 10, 1);
107
+		//filters
108
+		add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
109
+			array('EED_Messages', 'process_resend'), 10, 2);
110
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
111
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
112
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
113
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
114
+	}
115
+
116
+
117
+	/**
118
+	 * All the message triggers done by route go in here.
119
+	 *
120
+	 * @since 4.5.0
121
+	 * @return void
122
+	 */
123
+	protected static function _register_routes()
124
+	{
125
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
126
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
127
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
128
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
129
+		do_action('AHEE__EED_Messages___register_routes');
130
+	}
131
+
132
+
133
+	/**
134
+	 * This is called when a browser display trigger is executed.
135
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
136
+	 * browser.
137
+	 *
138
+	 * @since 4.9.0
139
+	 * @param WP $WP
140
+	 */
141
+	public function browser_trigger($WP)
142
+	{
143
+		//ensure controller is loaded
144
+		self::_load_controller();
145
+		$token = EE_Registry::instance()->REQ->get('token');
146
+		try {
147
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
148
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
149
+		} catch (EE_Error $e) {
150
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
151
+				'event_espresso');
152
+			// add specific message for developers if WP_DEBUG in on
153
+			$error_msg .= '||' . $e->getMessage();
154
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * This is called when a browser error trigger is executed.
161
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
162
+	 * message and display it.
163
+	 *
164
+	 * @since 4.9.0
165
+	 * @param $WP
166
+	 */
167
+	public function browser_error_trigger($WP)
168
+	{
169
+		$token = EE_Registry::instance()->REQ->get('token');
170
+		if ($token) {
171
+			$message = EEM_Message::instance()->get_one_by_token($token);
172
+			if ($message instanceof EE_Message) {
173
+				header('HTTP/1.1 200 OK');
174
+				$error_msg = nl2br($message->error_message());
175
+				?>
176 176
                 <!DOCTYPE html>
177 177
                 <html>
178 178
                 <head></head>
179 179
                 <body>
180 180
                 <?php echo empty($error_msg)
181
-                    ? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
182
-                        'event_espresso')
183
-                    : wp_kses(
184
-                        $error_msg,
185
-                        array(
186
-                            'a'      => array(
187
-                                'href'  => array(),
188
-                                'title' => array(),
189
-                            ),
190
-                            'span'   => array(),
191
-                            'div'    => array(),
192
-                            'p'      => array(),
193
-                            'strong' => array(),
194
-                            'em'     => array(),
195
-                            'br'     => array(),
196
-                        )
197
-                    ); ?>
181
+					? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
182
+						'event_espresso')
183
+					: wp_kses(
184
+						$error_msg,
185
+						array(
186
+							'a'      => array(
187
+								'href'  => array(),
188
+								'title' => array(),
189
+							),
190
+							'span'   => array(),
191
+							'div'    => array(),
192
+							'p'      => array(),
193
+							'strong' => array(),
194
+							'em'     => array(),
195
+							'br'     => array(),
196
+						)
197
+					); ?>
198 198
                 </body>
199 199
                 </html>
200 200
                 <?php
201
-                exit;
202
-            }
203
-        }
204
-        return;
205
-    }
206
-
207
-
208
-    /**
209
-     *  This runs when the msg_url_trigger route has initiated.
210
-     *
211
-     * @since 4.5.0
212
-     * @param WP $WP
213
-     * @throws EE_Error
214
-     * @return    void
215
-     */
216
-    public function run($WP)
217
-    {
218
-        //ensure controller is loaded
219
-        self::_load_controller();
220
-        // attempt to process message
221
-        try {
222
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
223
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
224
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
225
-        } catch (EE_Error $e) {
226
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
227
-                'event_espresso');
228
-            // add specific message for developers if WP_DEBUG in on
229
-            $error_msg .= '||' . $e->getMessage();
230
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
231
-        }
232
-    }
233
-
234
-
235
-    /**
236
-     * This is triggered by the 'msg_cron_trigger' route.
237
-     *
238
-     * @param WP $WP
239
-     */
240
-    public function execute_batch_request($WP)
241
-    {
242
-        $this->run_cron();
243
-        header('HTTP/1.1 200 OK');
244
-        exit();
245
-    }
246
-
247
-
248
-    /**
249
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
250
-     * request.
251
-     */
252
-    public function run_cron()
253
-    {
254
-        self::_load_controller();
255
-        //get required vars
256
-        $cron_type     = EE_Registry::instance()->REQ->get('type');
257
-        $transient_key = EE_Registry::instance()->REQ->get('key');
258
-
259
-        //now let's verify transient, if not valid exit immediately
260
-        if (! get_transient($transient_key)) {
261
-            /**
262
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user request.
263
-             */
264
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
265
-        }
266
-
267
-        //if made it here, lets' delete the transient to keep the db clean
268
-        delete_transient($transient_key);
269
-
270
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
271
-
272
-            $method = 'batch_' . $cron_type . '_from_queue';
273
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
274
-                self::$_MSG_PROCESSOR->$method();
275
-            } else {
276
-                //no matching task
277
-                /**
278
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user request.
279
-                 */
280
-                trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
281
-                    $cron_type)));
282
-            }
283
-        }
284
-
285
-        do_action('FHEE__EED_Messages__run_cron__end');
286
-    }
287
-
288
-
289
-    /**
290
-     * This is used to retrieve the template pack for the given name.
291
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
292
-     * the default template pack is returned.
293
-     *
294
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
295
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
296
-     *                                   in generating the Pack class name).
297
-     * @return EE_Messages_Template_Pack
298
-     */
299
-    public static function get_template_pack($template_pack_name)
300
-    {
301
-        EE_Registry::instance()->load_helper('MSG_Template');
302
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
303
-    }
304
-
305
-
306
-    /**
307
-     * Retrieves an array of all template packs.
308
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
309
-     *
310
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
311
-     * @return EE_Messages_Template_Pack[]
312
-     */
313
-    public static function get_template_packs()
314
-    {
315
-        EE_Registry::instance()->load_helper('MSG_Template');
316
-
317
-        //for backward compat, let's make sure this returns in the same format as originally.
318
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
319
-        $template_pack_collection->rewind();
320
-        $template_packs = array();
321
-        while ($template_pack_collection->valid()) {
322
-            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
323
-            $template_pack_collection->next();
324
-        }
325
-        return $template_packs;
326
-    }
327
-
328
-
329
-    /**
330
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
331
-     *
332
-     * @since 4.5.0
333
-     * @return void
334
-     */
335
-    public static function set_autoloaders()
336
-    {
337
-        if (empty(self::$_MSG_PATHS)) {
338
-            self::_set_messages_paths();
339
-            foreach (self::$_MSG_PATHS as $path) {
340
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
341
-            }
342
-            // add aliases
343
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
344
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
345
-        }
346
-    }
347
-
348
-
349
-    /**
350
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
351
-     * for use by the Messages Autoloaders
352
-     *
353
-     * @since 4.5.0
354
-     * @return void.
355
-     */
356
-    protected static function _set_messages_paths()
357
-    {
358
-        $dir_ref = array(
359
-            'messages/message_type',
360
-            'messages/messenger',
361
-            'messages/defaults',
362
-            'messages/defaults/email',
363
-            'messages/data_class',
364
-            'messages/validators',
365
-            'messages/validators/email',
366
-            'messages/validators/html',
367
-            'shortcodes',
368
-        );
369
-        $paths   = array();
370
-        foreach ($dir_ref as $index => $dir) {
371
-            $paths[$index] = EE_LIBRARIES . $dir;
372
-        }
373
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
374
-    }
375
-
376
-
377
-    /**
378
-     * Takes care of loading dependencies
379
-     *
380
-     * @since 4.5.0
381
-     * @return void
382
-     */
383
-    protected static function _load_controller()
384
-    {
385
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
386
-            EE_Registry::instance()->load_core('Request_Handler');
387
-            self::set_autoloaders();
388
-            self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
389
-            self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
390
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
-        }
392
-    }
393
-
394
-
395
-    /**
396
-     * @param EE_Transaction $transaction
397
-     */
398
-    public static function payment_reminder(EE_Transaction $transaction)
399
-    {
400
-        self::_load_controller();
401
-        $data = array($transaction, null);
402
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
403
-    }
404
-
405
-
406
-    /**
407
-     * Any messages triggers for after successful gateway payments should go in here.
408
-     *
409
-     * @param  EE_Transaction object
410
-     * @param  EE_Payment     object
411
-     * @return void
412
-     */
413
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment)
414
-    {
415
-        self::_load_controller();
416
-        $data = array($transaction, $payment);
417
-        EE_Registry::instance()->load_helper('MSG_Template');
418
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
419
-        //if payment amount is less than 0 then switch to payment_refund message type.
420
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
421
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
422
-    }
423
-
424
-
425
-    /**
426
-     * @param EE_Transaction $transaction
427
-     */
428
-    public static function cancelled_registration(EE_Transaction $transaction)
429
-    {
430
-        self::_load_controller();
431
-        $data = array($transaction, null);
432
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
433
-    }
434
-
435
-
436
-    /**
437
-     * Trigger for Registration messages
438
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
439
-     * incoming transaction.
440
-     *
441
-     * @param EE_Registration $registration
442
-     * @param array           $extra_details
443
-     * @return void
444
-     */
445
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
446
-    {
447
-
448
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
449
-            //no messages please
450
-            return;
451
-        }
452
-
453
-
454
-        //get all registrations so we make sure we send messages for the right status.
455
-        $all_registrations = $registration->transaction()->registrations();
456
-
457
-        //cached array of statuses so we only trigger messages once per status.
458
-        $statuses_sent = array();
459
-        self::_load_controller();
460
-        $mtgs = array();
461
-
462
-        //loop through registrations and trigger messages once per status.
463
-        foreach ($all_registrations as $reg) {
464
-
465
-            //already triggered?
466
-            if (in_array($reg->status_ID(), $statuses_sent)) {
467
-                continue;
468
-            }
469
-
470
-            $message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
471
-            $mtgs            = array_merge(
472
-                    $mtgs,
473
-                    self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
474
-                            $message_type,
475
-                            array($registration->transaction(), null, $reg->status_ID())
476
-                    )
477
-            );
478
-            $statuses_sent[] = $reg->status_ID();
479
-        }
480
-
481
-        $mtgs = array_merge(
482
-                $mtgs,
483
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
484
-                        'registration_summary',
485
-                        array($registration->transaction(), null)
486
-                )
487
-        );
488
-
489
-        //batch queue and initiate request
490
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
491
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
492
-    }
493
-
494
-
495
-    /**
496
-     * This is a helper method used to very whether a registration notification should be sent or
497
-     * not.  Prevents duplicate notifications going out for registration context notifications.
498
-     *
499
-     * @param EE_Registration $registration  [description]
500
-     * @param array           $extra_details [description]
501
-     * @return bool          true = send away, false = nope halt the presses.
502
-     */
503
-    protected static function _verify_registration_notification_send(
504
-        EE_Registration $registration,
505
-        $extra_details = array()
506
-    ) {
507
-        //self::log(
508
-        //	__CLASS__, __FUNCTION__, __LINE__,
509
-        //	$registration->transaction(),
510
-        //	array( '$extra_details' => $extra_details )
511
-        //);
512
-        // currently only using this to send messages for the primary registrant
513
-        if (! $registration->is_primary_registrant()) {
514
-            return false;
515
-        }
516
-        // first we check if we're in admin and not doing front ajax
517
-        if (is_admin() && ! EE_FRONT_AJAX) {
518
-            //make sure appropriate admin params are set for sending messages
519
-            if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
520
-                //no messages sent please.
521
-                return false;
522
-            }
523
-        } else {
524
-            // frontend request (either regular or via AJAX)
525
-            // TXN is NOT finalized ?
526
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
527
-                return false;
528
-            }
529
-            // return visit but nothing changed ???
530
-            if (
531
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
532
-                $extra_details['revisit'] && ! $extra_details['status_updates']
533
-            ) {
534
-                return false;
535
-            }
536
-            // NOT sending messages && reg status is something other than "Not-Approved"
537
-            if (
538
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
539
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
540
-            ) {
541
-                return false;
542
-            }
543
-        }
544
-        // release the kraken
545
-        return true;
546
-    }
547
-
548
-
549
-    /**
550
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
551
-     * status id.
552
-     *
553
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
554
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
555
-     * @param string $reg_status
556
-     * @return array
557
-     */
558
-    protected static function _get_reg_status_array($reg_status = '')
559
-    {
560
-        EE_Registry::instance()->load_helper('MSG_Template');
561
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
562
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
563
-            : EEH_MSG_Template::reg_status_to_message_type_array();
564
-    }
565
-
566
-
567
-    /**
568
-     * Simply returns the payment message type for the given payment status.
569
-     *
570
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
571
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
572
-     * @param string $payment_status The payment status being matched.
573
-     * @return string|bool The payment message type slug matching the status or false if no match.
574
-     */
575
-    protected static function _get_payment_message_type($payment_status)
576
-    {
577
-        EE_Registry::instance()->load_helper('MSG_Template');
578
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
579
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
580
-            : false;
581
-    }
582
-
583
-
584
-    /**
585
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
586
-     *
587
-     * @access public
588
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
589
-     * @return bool          success/fail
590
-     */
591
-    public static function process_resend($req_data)
592
-    {
593
-        self::_load_controller();
594
-
595
-        //if $msgID in this request then skip to the new resend_message
596
-        if (EE_Registry::instance()->REQ->get('MSG_ID')) {
597
-            return self::resend_message();
598
-        }
599
-
600
-        //make sure any incoming request data is set on the REQ so that it gets picked up later.
601
-        $req_data = (array)$req_data;
602
-        foreach ($req_data as $request_key => $request_value) {
603
-            EE_Registry::instance()->REQ->set($request_key, $request_value);
604
-        }
605
-
606
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
607
-            return false;
608
-        }
609
-
610
-        try {
611
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
612
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
-        } catch (EE_Error $e) {
614
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
615
-            return false;
616
-        }
617
-        EE_Error::add_success(
618
-            __('Messages have been successfully queued for generation and sending.', 'event_espresso')
619
-        );
620
-        return true; //everything got queued.
621
-    }
622
-
623
-
624
-    /**
625
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
626
-     *
627
-     * @return bool
628
-     */
629
-    public static function resend_message()
630
-    {
631
-        self::_load_controller();
632
-
633
-        $msgID = EE_Registry::instance()->REQ->get('MSG_ID');
634
-        if (! $msgID) {
635
-            EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
636
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
637
-            return false;
638
-        }
639
-
640
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
641
-
642
-        //setup success message.
643
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
644
-        EE_Error::add_success(sprintf(
645
-            _n(
646
-                'There was %d message queued for resending.',
647
-                'There were %d messages queued for resending.',
648
-                $count_ready_for_resend,
649
-                'event_espresso'
650
-            ),
651
-            $count_ready_for_resend
652
-        ));
653
-        return true;
654
-    }
655
-
656
-
657
-    /**
658
-     * Message triggers for manual payment applied by admin
659
-     *
660
-     * @param  EE_Payment $payment EE_payment object
661
-     * @return bool              success/fail
662
-     */
663
-    public static function process_admin_payment(EE_Payment $payment)
664
-    {
665
-        EE_Registry::instance()->load_helper('MSG_Template');
666
-        //we need to get the transaction object
667
-        $transaction = $payment->transaction();
668
-        if ($transaction instanceof EE_Transaction) {
669
-            $data         = array($transaction, $payment);
670
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
671
-
672
-            //if payment amount is less than 0 then switch to payment_refund message type.
673
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
674
-
675
-            //if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
676
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
677
-
678
-            self::_load_controller();
679
-
680
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
681
-
682
-            //get count of queued for generation
683
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
684
-                EEM_Message::status_incomplete,
685
-                EEM_Message::status_idle,
686
-            ));
687
-
688
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
689
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
690
-                return true;
691
-            } else {
692
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
693
-                /**
694
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
695
-                 * IMMEDIATE generation.
696
-                 */
697
-                if ($count_failed > 0) {
698
-                    EE_Error::add_error(sprintf(
699
-                        _n(
700
-                            'The payment notification generation failed.',
701
-                            '%d payment notifications failed being sent.',
702
-                            $count_failed,
703
-                            'event_espresso'
704
-                        ),
705
-                        $count_failed
706
-                    ), __FILE__, __FUNCTION__, __LINE__);
707
-
708
-                    return false;
709
-                } else {
710
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
711
-                    return true;
712
-                }
713
-            }
714
-        } else {
715
-            EE_Error::add_error(
716
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
717
-                'event_espresso'
718
-            );
719
-            return false;
720
-        }
721
-    }
722
-
723
-
724
-    /**
725
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
726
-     *
727
-     * @since   4.3.0
728
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
729
-     * @param  int               $grp_id        a specific message template group id.
730
-     * @return void
731
-     */
732
-    public static function send_newsletter_message($registrations, $grp_id)
733
-    {
734
-        //make sure mtp is id and set it in the EE_Request Handler later messages setup.
735
-        EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
736
-        self::_load_controller();
737
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
738
-    }
739
-
740
-
741
-    /**
742
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
743
-     *
744
-     * @since   4.3.0
745
-     * @param    string          $registration_message_trigger_url
746
-     * @param    EE_Registration $registration
747
-     * @param string             $messenger
748
-     * @param string             $message_type
749
-     * @return    string
750
-     */
751
-    public static function registration_message_trigger_url(
752
-        $registration_message_trigger_url,
753
-        EE_Registration $registration,
754
-        $messenger = 'html',
755
-        $message_type = 'invoice'
756
-    ) {
757
-        // whitelist $messenger
758
-        switch ($messenger) {
759
-            case 'pdf' :
760
-                $sending_messenger    = 'pdf';
761
-                $generating_messenger = 'html';
762
-                break;
763
-            case 'html' :
764
-            default :
765
-                $sending_messenger    = 'html';
766
-                $generating_messenger = 'html';
767
-                break;
768
-        }
769
-        // whitelist $message_type
770
-        switch ($message_type) {
771
-            case 'receipt' :
772
-                $message_type = 'receipt';
773
-                break;
774
-            case 'invoice' :
775
-            default :
776
-                $message_type = 'invoice';
777
-                break;
778
-        }
779
-        // verify that both the messenger AND the message type are active
780
-        if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
781
-            //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?)
782
-            $template_query_params = array(
783
-                'MTP_is_active'    => true,
784
-                'MTP_messenger'    => $generating_messenger,
785
-                'MTP_message_type' => $message_type,
786
-                'Event.EVT_ID'     => $registration->event_ID(),
787
-            );
788
-            //get the message template group.
789
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
790
-            //if we don't have an EE_Message_Template_Group then return
791
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
792
-                // remove EVT_ID from query params so that global templates get picked up
793
-                unset($template_query_params['Event.EVT_ID']);
794
-                //get global template as the fallback
795
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
796
-            }
797
-            //if we don't have an EE_Message_Template_Group then return
798
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
799
-                return '';
800
-            }
801
-            // generate the URL
802
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
803
-                $sending_messenger,
804
-                $generating_messenger,
805
-                'purchaser',
806
-                $message_type,
807
-                $registration,
808
-                $msg_template_group->ID(),
809
-                $registration->transaction_ID()
810
-            );
811
-
812
-        }
813
-        return $registration_message_trigger_url;
814
-    }
815
-
816
-
817
-    /**
818
-     * Use to generate and return a message preview!
819
-     *
820
-     * @param  string $type      This should correspond with a valid message type
821
-     * @param  string $context   This should correspond with a valid context for the message type
822
-     * @param  string $messenger This should correspond with a valid messenger.
823
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
824
-     *                           preview
825
-     * @return string|bool          The body of the message or if send is requested, sends.
826
-     */
827
-    public static function preview_message($type, $context, $messenger, $send = false)
828
-    {
829
-        self::_load_controller();
830
-        $mtg                     = new EE_Message_To_Generate(
831
-            $messenger,
832
-            $type,
833
-            array(),
834
-            $context,
835
-            true
836
-        );
837
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
838
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
839
-            return $generated_preview_queue->get_message_repository()->current()->content();
840
-        } else {
841
-            return $generated_preview_queue;
842
-        }
843
-    }
844
-
845
-
846
-    /**
847
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
848
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
849
-     * content found in the EE_Message objects in the queue.
850
-     *
851
-     * @since 4.9.0
852
-     * @param string            $messenger            a string matching a valid active messenger in the system
853
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
854
-     *                                                type name is still required to send along the message type to the
855
-     *                                                messenger because this is used for determining what specific
856
-     *                                                variations might be loaded for the generated message.
857
-     * @param EE_Messages_Queue $queue
858
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
859
-     *                                                aggregate EE_Message object.
860
-     * @return bool          success or fail.
861
-     */
862
-    public static function send_message_with_messenger_only(
863
-        $messenger,
864
-        $message_type,
865
-        EE_Messages_Queue $queue,
866
-        $custom_subject = ''
867
-    ) {
868
-        self::_load_controller();
869
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
870
-        $message_to_generate = EE_Registry::instance()->load_lib(
871
-            'Message_To_Generate_From_Queue',
872
-            array(
873
-                $messenger,
874
-                $message_type,
875
-                $queue,
876
-                $custom_subject,
877
-            )
878
-        );
879
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
880
-    }
881
-
882
-
883
-    /**
884
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
885
-     *
886
-     * @since 4.9.0
887
-     * @param array $message_ids An array of message ids
888
-     * @return bool | EE_Messages_Queue     false if nothing was generated, EE_Messages_Queue containing generated
889
-     *              messages.
890
-     */
891
-    public static function generate_now($message_ids)
892
-    {
893
-        self::_load_controller();
894
-        $messages        = EEM_Message::instance()->get_all(
895
-            array(
896
-                0 => array(
897
-                    'MSG_ID' => array('IN', $message_ids),
898
-                    'STS_ID' => EEM_Message::status_incomplete,
899
-                ),
900
-            )
901
-        );
902
-        $generated_queue = false;
903
-        if ($messages) {
904
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
905
-        }
906
-
907
-        if (! $generated_queue instanceof EE_Messages_Queue) {
908
-            EE_Error::add_error(
909
-                __('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.',
910
-                    'event_espresso'),
911
-                __FILE__, __FUNCTION__, __LINE__
912
-            );
913
-        }
914
-        return $generated_queue;
915
-    }
916
-
917
-
918
-    /**
919
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
920
-     * EEM_Message::status_idle
921
-     *
922
-     * @since 4.9.0
923
-     * @param $message_ids
924
-     * @return bool | EE_Messages_Queue  false if no messages sent.
925
-     */
926
-    public static function send_now($message_ids)
927
-    {
928
-        self::_load_controller();
929
-        $messages   = EEM_Message::instance()->get_all(
930
-            array(
931
-                0 => array(
932
-                    'MSG_ID' => array('IN', $message_ids),
933
-                    'STS_ID' => array(
934
-                        'IN',
935
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
936
-                    ),
937
-                ),
938
-            )
939
-        );
940
-        $sent_queue = false;
941
-        if ($messages) {
942
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
943
-        }
944
-
945
-        if (! $sent_queue instanceof EE_Messages_Queue) {
946
-            EE_Error::add_error(
947
-                __('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.',
948
-                    'event_espresso'),
949
-                __FILE__, __FUNCTION__, __LINE__
950
-            );
951
-        } else {
952
-            //can count how many sent by using the messages in the queue
953
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
954
-            if ($sent_count > 0) {
955
-                EE_Error::add_success(
956
-                    sprintf(
957
-                        _n(
958
-                            'There was %d message successfully sent.',
959
-                            'There were %d messages successfully sent.',
960
-                            $sent_count,
961
-                            'event_espresso'
962
-                        ),
963
-                        $sent_count
964
-                    )
965
-                );
966
-            } else {
967
-                EE_Error::overwrite_errors();
968
-                EE_Error::add_error(
969
-                    __('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.
201
+				exit;
202
+			}
203
+		}
204
+		return;
205
+	}
206
+
207
+
208
+	/**
209
+	 *  This runs when the msg_url_trigger route has initiated.
210
+	 *
211
+	 * @since 4.5.0
212
+	 * @param WP $WP
213
+	 * @throws EE_Error
214
+	 * @return    void
215
+	 */
216
+	public function run($WP)
217
+	{
218
+		//ensure controller is loaded
219
+		self::_load_controller();
220
+		// attempt to process message
221
+		try {
222
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
223
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
224
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
225
+		} catch (EE_Error $e) {
226
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
227
+				'event_espresso');
228
+			// add specific message for developers if WP_DEBUG in on
229
+			$error_msg .= '||' . $e->getMessage();
230
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
231
+		}
232
+	}
233
+
234
+
235
+	/**
236
+	 * This is triggered by the 'msg_cron_trigger' route.
237
+	 *
238
+	 * @param WP $WP
239
+	 */
240
+	public function execute_batch_request($WP)
241
+	{
242
+		$this->run_cron();
243
+		header('HTTP/1.1 200 OK');
244
+		exit();
245
+	}
246
+
247
+
248
+	/**
249
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
250
+	 * request.
251
+	 */
252
+	public function run_cron()
253
+	{
254
+		self::_load_controller();
255
+		//get required vars
256
+		$cron_type     = EE_Registry::instance()->REQ->get('type');
257
+		$transient_key = EE_Registry::instance()->REQ->get('key');
258
+
259
+		//now let's verify transient, if not valid exit immediately
260
+		if (! get_transient($transient_key)) {
261
+			/**
262
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user request.
263
+			 */
264
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
265
+		}
266
+
267
+		//if made it here, lets' delete the transient to keep the db clean
268
+		delete_transient($transient_key);
269
+
270
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
271
+
272
+			$method = 'batch_' . $cron_type . '_from_queue';
273
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
274
+				self::$_MSG_PROCESSOR->$method();
275
+			} else {
276
+				//no matching task
277
+				/**
278
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user request.
279
+				 */
280
+				trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
281
+					$cron_type)));
282
+			}
283
+		}
284
+
285
+		do_action('FHEE__EED_Messages__run_cron__end');
286
+	}
287
+
288
+
289
+	/**
290
+	 * This is used to retrieve the template pack for the given name.
291
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
292
+	 * the default template pack is returned.
293
+	 *
294
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
295
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
296
+	 *                                   in generating the Pack class name).
297
+	 * @return EE_Messages_Template_Pack
298
+	 */
299
+	public static function get_template_pack($template_pack_name)
300
+	{
301
+		EE_Registry::instance()->load_helper('MSG_Template');
302
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
303
+	}
304
+
305
+
306
+	/**
307
+	 * Retrieves an array of all template packs.
308
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
309
+	 *
310
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
311
+	 * @return EE_Messages_Template_Pack[]
312
+	 */
313
+	public static function get_template_packs()
314
+	{
315
+		EE_Registry::instance()->load_helper('MSG_Template');
316
+
317
+		//for backward compat, let's make sure this returns in the same format as originally.
318
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
319
+		$template_pack_collection->rewind();
320
+		$template_packs = array();
321
+		while ($template_pack_collection->valid()) {
322
+			$template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
323
+			$template_pack_collection->next();
324
+		}
325
+		return $template_packs;
326
+	}
327
+
328
+
329
+	/**
330
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
331
+	 *
332
+	 * @since 4.5.0
333
+	 * @return void
334
+	 */
335
+	public static function set_autoloaders()
336
+	{
337
+		if (empty(self::$_MSG_PATHS)) {
338
+			self::_set_messages_paths();
339
+			foreach (self::$_MSG_PATHS as $path) {
340
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
341
+			}
342
+			// add aliases
343
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
344
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
345
+		}
346
+	}
347
+
348
+
349
+	/**
350
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
351
+	 * for use by the Messages Autoloaders
352
+	 *
353
+	 * @since 4.5.0
354
+	 * @return void.
355
+	 */
356
+	protected static function _set_messages_paths()
357
+	{
358
+		$dir_ref = array(
359
+			'messages/message_type',
360
+			'messages/messenger',
361
+			'messages/defaults',
362
+			'messages/defaults/email',
363
+			'messages/data_class',
364
+			'messages/validators',
365
+			'messages/validators/email',
366
+			'messages/validators/html',
367
+			'shortcodes',
368
+		);
369
+		$paths   = array();
370
+		foreach ($dir_ref as $index => $dir) {
371
+			$paths[$index] = EE_LIBRARIES . $dir;
372
+		}
373
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Takes care of loading dependencies
379
+	 *
380
+	 * @since 4.5.0
381
+	 * @return void
382
+	 */
383
+	protected static function _load_controller()
384
+	{
385
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
386
+			EE_Registry::instance()->load_core('Request_Handler');
387
+			self::set_autoloaders();
388
+			self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
389
+			self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
390
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
+		}
392
+	}
393
+
394
+
395
+	/**
396
+	 * @param EE_Transaction $transaction
397
+	 */
398
+	public static function payment_reminder(EE_Transaction $transaction)
399
+	{
400
+		self::_load_controller();
401
+		$data = array($transaction, null);
402
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
403
+	}
404
+
405
+
406
+	/**
407
+	 * Any messages triggers for after successful gateway payments should go in here.
408
+	 *
409
+	 * @param  EE_Transaction object
410
+	 * @param  EE_Payment     object
411
+	 * @return void
412
+	 */
413
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment)
414
+	{
415
+		self::_load_controller();
416
+		$data = array($transaction, $payment);
417
+		EE_Registry::instance()->load_helper('MSG_Template');
418
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
419
+		//if payment amount is less than 0 then switch to payment_refund message type.
420
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
421
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
422
+	}
423
+
424
+
425
+	/**
426
+	 * @param EE_Transaction $transaction
427
+	 */
428
+	public static function cancelled_registration(EE_Transaction $transaction)
429
+	{
430
+		self::_load_controller();
431
+		$data = array($transaction, null);
432
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Trigger for Registration messages
438
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
439
+	 * incoming transaction.
440
+	 *
441
+	 * @param EE_Registration $registration
442
+	 * @param array           $extra_details
443
+	 * @return void
444
+	 */
445
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
446
+	{
447
+
448
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
449
+			//no messages please
450
+			return;
451
+		}
452
+
453
+
454
+		//get all registrations so we make sure we send messages for the right status.
455
+		$all_registrations = $registration->transaction()->registrations();
456
+
457
+		//cached array of statuses so we only trigger messages once per status.
458
+		$statuses_sent = array();
459
+		self::_load_controller();
460
+		$mtgs = array();
461
+
462
+		//loop through registrations and trigger messages once per status.
463
+		foreach ($all_registrations as $reg) {
464
+
465
+			//already triggered?
466
+			if (in_array($reg->status_ID(), $statuses_sent)) {
467
+				continue;
468
+			}
469
+
470
+			$message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
471
+			$mtgs            = array_merge(
472
+					$mtgs,
473
+					self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
474
+							$message_type,
475
+							array($registration->transaction(), null, $reg->status_ID())
476
+					)
477
+			);
478
+			$statuses_sent[] = $reg->status_ID();
479
+		}
480
+
481
+		$mtgs = array_merge(
482
+				$mtgs,
483
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
484
+						'registration_summary',
485
+						array($registration->transaction(), null)
486
+				)
487
+		);
488
+
489
+		//batch queue and initiate request
490
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
491
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
492
+	}
493
+
494
+
495
+	/**
496
+	 * This is a helper method used to very whether a registration notification should be sent or
497
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
498
+	 *
499
+	 * @param EE_Registration $registration  [description]
500
+	 * @param array           $extra_details [description]
501
+	 * @return bool          true = send away, false = nope halt the presses.
502
+	 */
503
+	protected static function _verify_registration_notification_send(
504
+		EE_Registration $registration,
505
+		$extra_details = array()
506
+	) {
507
+		//self::log(
508
+		//	__CLASS__, __FUNCTION__, __LINE__,
509
+		//	$registration->transaction(),
510
+		//	array( '$extra_details' => $extra_details )
511
+		//);
512
+		// currently only using this to send messages for the primary registrant
513
+		if (! $registration->is_primary_registrant()) {
514
+			return false;
515
+		}
516
+		// first we check if we're in admin and not doing front ajax
517
+		if (is_admin() && ! EE_FRONT_AJAX) {
518
+			//make sure appropriate admin params are set for sending messages
519
+			if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
520
+				//no messages sent please.
521
+				return false;
522
+			}
523
+		} else {
524
+			// frontend request (either regular or via AJAX)
525
+			// TXN is NOT finalized ?
526
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
527
+				return false;
528
+			}
529
+			// return visit but nothing changed ???
530
+			if (
531
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
532
+				$extra_details['revisit'] && ! $extra_details['status_updates']
533
+			) {
534
+				return false;
535
+			}
536
+			// NOT sending messages && reg status is something other than "Not-Approved"
537
+			if (
538
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
539
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
540
+			) {
541
+				return false;
542
+			}
543
+		}
544
+		// release the kraken
545
+		return true;
546
+	}
547
+
548
+
549
+	/**
550
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
551
+	 * status id.
552
+	 *
553
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
554
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
555
+	 * @param string $reg_status
556
+	 * @return array
557
+	 */
558
+	protected static function _get_reg_status_array($reg_status = '')
559
+	{
560
+		EE_Registry::instance()->load_helper('MSG_Template');
561
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
562
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
563
+			: EEH_MSG_Template::reg_status_to_message_type_array();
564
+	}
565
+
566
+
567
+	/**
568
+	 * Simply returns the payment message type for the given payment status.
569
+	 *
570
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
571
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
572
+	 * @param string $payment_status The payment status being matched.
573
+	 * @return string|bool The payment message type slug matching the status or false if no match.
574
+	 */
575
+	protected static function _get_payment_message_type($payment_status)
576
+	{
577
+		EE_Registry::instance()->load_helper('MSG_Template');
578
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
579
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
580
+			: false;
581
+	}
582
+
583
+
584
+	/**
585
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
586
+	 *
587
+	 * @access public
588
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
589
+	 * @return bool          success/fail
590
+	 */
591
+	public static function process_resend($req_data)
592
+	{
593
+		self::_load_controller();
594
+
595
+		//if $msgID in this request then skip to the new resend_message
596
+		if (EE_Registry::instance()->REQ->get('MSG_ID')) {
597
+			return self::resend_message();
598
+		}
599
+
600
+		//make sure any incoming request data is set on the REQ so that it gets picked up later.
601
+		$req_data = (array)$req_data;
602
+		foreach ($req_data as $request_key => $request_value) {
603
+			EE_Registry::instance()->REQ->set($request_key, $request_value);
604
+		}
605
+
606
+		if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
607
+			return false;
608
+		}
609
+
610
+		try {
611
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
612
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
+		} catch (EE_Error $e) {
614
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
615
+			return false;
616
+		}
617
+		EE_Error::add_success(
618
+			__('Messages have been successfully queued for generation and sending.', 'event_espresso')
619
+		);
620
+		return true; //everything got queued.
621
+	}
622
+
623
+
624
+	/**
625
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
626
+	 *
627
+	 * @return bool
628
+	 */
629
+	public static function resend_message()
630
+	{
631
+		self::_load_controller();
632
+
633
+		$msgID = EE_Registry::instance()->REQ->get('MSG_ID');
634
+		if (! $msgID) {
635
+			EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
636
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
637
+			return false;
638
+		}
639
+
640
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
641
+
642
+		//setup success message.
643
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
644
+		EE_Error::add_success(sprintf(
645
+			_n(
646
+				'There was %d message queued for resending.',
647
+				'There were %d messages queued for resending.',
648
+				$count_ready_for_resend,
649
+				'event_espresso'
650
+			),
651
+			$count_ready_for_resend
652
+		));
653
+		return true;
654
+	}
655
+
656
+
657
+	/**
658
+	 * Message triggers for manual payment applied by admin
659
+	 *
660
+	 * @param  EE_Payment $payment EE_payment object
661
+	 * @return bool              success/fail
662
+	 */
663
+	public static function process_admin_payment(EE_Payment $payment)
664
+	{
665
+		EE_Registry::instance()->load_helper('MSG_Template');
666
+		//we need to get the transaction object
667
+		$transaction = $payment->transaction();
668
+		if ($transaction instanceof EE_Transaction) {
669
+			$data         = array($transaction, $payment);
670
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
671
+
672
+			//if payment amount is less than 0 then switch to payment_refund message type.
673
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
674
+
675
+			//if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
676
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
677
+
678
+			self::_load_controller();
679
+
680
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
681
+
682
+			//get count of queued for generation
683
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
684
+				EEM_Message::status_incomplete,
685
+				EEM_Message::status_idle,
686
+			));
687
+
688
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
689
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
690
+				return true;
691
+			} else {
692
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
693
+				/**
694
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
695
+				 * IMMEDIATE generation.
696
+				 */
697
+				if ($count_failed > 0) {
698
+					EE_Error::add_error(sprintf(
699
+						_n(
700
+							'The payment notification generation failed.',
701
+							'%d payment notifications failed being sent.',
702
+							$count_failed,
703
+							'event_espresso'
704
+						),
705
+						$count_failed
706
+					), __FILE__, __FUNCTION__, __LINE__);
707
+
708
+					return false;
709
+				} else {
710
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
711
+					return true;
712
+				}
713
+			}
714
+		} else {
715
+			EE_Error::add_error(
716
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
717
+				'event_espresso'
718
+			);
719
+			return false;
720
+		}
721
+	}
722
+
723
+
724
+	/**
725
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
726
+	 *
727
+	 * @since   4.3.0
728
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
729
+	 * @param  int               $grp_id        a specific message template group id.
730
+	 * @return void
731
+	 */
732
+	public static function send_newsletter_message($registrations, $grp_id)
733
+	{
734
+		//make sure mtp is id and set it in the EE_Request Handler later messages setup.
735
+		EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
736
+		self::_load_controller();
737
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
738
+	}
739
+
740
+
741
+	/**
742
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
743
+	 *
744
+	 * @since   4.3.0
745
+	 * @param    string          $registration_message_trigger_url
746
+	 * @param    EE_Registration $registration
747
+	 * @param string             $messenger
748
+	 * @param string             $message_type
749
+	 * @return    string
750
+	 */
751
+	public static function registration_message_trigger_url(
752
+		$registration_message_trigger_url,
753
+		EE_Registration $registration,
754
+		$messenger = 'html',
755
+		$message_type = 'invoice'
756
+	) {
757
+		// whitelist $messenger
758
+		switch ($messenger) {
759
+			case 'pdf' :
760
+				$sending_messenger    = 'pdf';
761
+				$generating_messenger = 'html';
762
+				break;
763
+			case 'html' :
764
+			default :
765
+				$sending_messenger    = 'html';
766
+				$generating_messenger = 'html';
767
+				break;
768
+		}
769
+		// whitelist $message_type
770
+		switch ($message_type) {
771
+			case 'receipt' :
772
+				$message_type = 'receipt';
773
+				break;
774
+			case 'invoice' :
775
+			default :
776
+				$message_type = 'invoice';
777
+				break;
778
+		}
779
+		// verify that both the messenger AND the message type are active
780
+		if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
781
+			//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?)
782
+			$template_query_params = array(
783
+				'MTP_is_active'    => true,
784
+				'MTP_messenger'    => $generating_messenger,
785
+				'MTP_message_type' => $message_type,
786
+				'Event.EVT_ID'     => $registration->event_ID(),
787
+			);
788
+			//get the message template group.
789
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
790
+			//if we don't have an EE_Message_Template_Group then return
791
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
792
+				// remove EVT_ID from query params so that global templates get picked up
793
+				unset($template_query_params['Event.EVT_ID']);
794
+				//get global template as the fallback
795
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
796
+			}
797
+			//if we don't have an EE_Message_Template_Group then return
798
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
799
+				return '';
800
+			}
801
+			// generate the URL
802
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
803
+				$sending_messenger,
804
+				$generating_messenger,
805
+				'purchaser',
806
+				$message_type,
807
+				$registration,
808
+				$msg_template_group->ID(),
809
+				$registration->transaction_ID()
810
+			);
811
+
812
+		}
813
+		return $registration_message_trigger_url;
814
+	}
815
+
816
+
817
+	/**
818
+	 * Use to generate and return a message preview!
819
+	 *
820
+	 * @param  string $type      This should correspond with a valid message type
821
+	 * @param  string $context   This should correspond with a valid context for the message type
822
+	 * @param  string $messenger This should correspond with a valid messenger.
823
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
824
+	 *                           preview
825
+	 * @return string|bool          The body of the message or if send is requested, sends.
826
+	 */
827
+	public static function preview_message($type, $context, $messenger, $send = false)
828
+	{
829
+		self::_load_controller();
830
+		$mtg                     = new EE_Message_To_Generate(
831
+			$messenger,
832
+			$type,
833
+			array(),
834
+			$context,
835
+			true
836
+		);
837
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
838
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
839
+			return $generated_preview_queue->get_message_repository()->current()->content();
840
+		} else {
841
+			return $generated_preview_queue;
842
+		}
843
+	}
844
+
845
+
846
+	/**
847
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
848
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
849
+	 * content found in the EE_Message objects in the queue.
850
+	 *
851
+	 * @since 4.9.0
852
+	 * @param string            $messenger            a string matching a valid active messenger in the system
853
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
854
+	 *                                                type name is still required to send along the message type to the
855
+	 *                                                messenger because this is used for determining what specific
856
+	 *                                                variations might be loaded for the generated message.
857
+	 * @param EE_Messages_Queue $queue
858
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
859
+	 *                                                aggregate EE_Message object.
860
+	 * @return bool          success or fail.
861
+	 */
862
+	public static function send_message_with_messenger_only(
863
+		$messenger,
864
+		$message_type,
865
+		EE_Messages_Queue $queue,
866
+		$custom_subject = ''
867
+	) {
868
+		self::_load_controller();
869
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
870
+		$message_to_generate = EE_Registry::instance()->load_lib(
871
+			'Message_To_Generate_From_Queue',
872
+			array(
873
+				$messenger,
874
+				$message_type,
875
+				$queue,
876
+				$custom_subject,
877
+			)
878
+		);
879
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
880
+	}
881
+
882
+
883
+	/**
884
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
885
+	 *
886
+	 * @since 4.9.0
887
+	 * @param array $message_ids An array of message ids
888
+	 * @return bool | EE_Messages_Queue     false if nothing was generated, EE_Messages_Queue containing generated
889
+	 *              messages.
890
+	 */
891
+	public static function generate_now($message_ids)
892
+	{
893
+		self::_load_controller();
894
+		$messages        = EEM_Message::instance()->get_all(
895
+			array(
896
+				0 => array(
897
+					'MSG_ID' => array('IN', $message_ids),
898
+					'STS_ID' => EEM_Message::status_incomplete,
899
+				),
900
+			)
901
+		);
902
+		$generated_queue = false;
903
+		if ($messages) {
904
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
905
+		}
906
+
907
+		if (! $generated_queue instanceof EE_Messages_Queue) {
908
+			EE_Error::add_error(
909
+				__('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.',
910
+					'event_espresso'),
911
+				__FILE__, __FUNCTION__, __LINE__
912
+			);
913
+		}
914
+		return $generated_queue;
915
+	}
916
+
917
+
918
+	/**
919
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
920
+	 * EEM_Message::status_idle
921
+	 *
922
+	 * @since 4.9.0
923
+	 * @param $message_ids
924
+	 * @return bool | EE_Messages_Queue  false if no messages sent.
925
+	 */
926
+	public static function send_now($message_ids)
927
+	{
928
+		self::_load_controller();
929
+		$messages   = EEM_Message::instance()->get_all(
930
+			array(
931
+				0 => array(
932
+					'MSG_ID' => array('IN', $message_ids),
933
+					'STS_ID' => array(
934
+						'IN',
935
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
936
+					),
937
+				),
938
+			)
939
+		);
940
+		$sent_queue = false;
941
+		if ($messages) {
942
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
943
+		}
944
+
945
+		if (! $sent_queue instanceof EE_Messages_Queue) {
946
+			EE_Error::add_error(
947
+				__('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.',
948
+					'event_espresso'),
949
+				__FILE__, __FUNCTION__, __LINE__
950
+			);
951
+		} else {
952
+			//can count how many sent by using the messages in the queue
953
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
954
+			if ($sent_count > 0) {
955
+				EE_Error::add_success(
956
+					sprintf(
957
+						_n(
958
+							'There was %d message successfully sent.',
959
+							'There were %d messages successfully sent.',
960
+							$sent_count,
961
+							'event_espresso'
962
+						),
963
+						$sent_count
964
+					)
965
+				);
966
+			} else {
967
+				EE_Error::overwrite_errors();
968
+				EE_Error::add_error(
969
+					__('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.
970 970
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
971
-                        'event_espresso'),
972
-                    __FILE__, __FUNCTION__, __LINE__
973
-                );
974
-            }
975
-        }
976
-        return $sent_queue;
977
-    }
978
-
979
-
980
-    /**
981
-     * This will queue the incoming message ids for resending.
982
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
983
-     *
984
-     * @since 4.9.0
985
-     * @param array $message_ids An array of EE_Message IDs
986
-     * @return bool  true means messages were successfully queued for resending, false means none were queued for
987
-     *               resending.
988
-     */
989
-    public static function queue_for_resending($message_ids)
990
-    {
991
-        self::_load_controller();
992
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
993
-
994
-        //get queue and count
995
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
996
-
997
-        if (
998
-            $queue_count > 0
999
-        ) {
1000
-            EE_Error::add_success(
1001
-                sprintf(
1002
-                    _n(
1003
-                        '%d message successfully queued for resending.',
1004
-                        '%d messages successfully queued for resending.',
1005
-                        $queue_count,
1006
-                        'event_espresso'
1007
-                    ),
1008
-                    $queue_count
1009
-                )
1010
-            );
1011
-            /**
1012
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1013
-             */
1014
-        } elseif (
1015
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1016
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1017
-        ) {
1018
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1019
-            if ($queue_count > 0) {
1020
-                EE_Error::add_success(
1021
-                    sprintf(
1022
-                        _n(
1023
-                            '%d message successfully sent.',
1024
-                            '%d messages successfully sent.',
1025
-                            $queue_count,
1026
-                            'event_espresso'
1027
-                        ),
1028
-                        $queue_count
1029
-                    )
1030
-                );
1031
-            } else {
1032
-                EE_Error::add_error(
1033
-                    __('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.',
1034
-                        'event_espresso'),
1035
-                    __FILE__, __FUNCTION__, __LINE__
1036
-                );
1037
-            }
1038
-        } else {
1039
-            EE_Error::add_error(
1040
-                __('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.',
1041
-                    'event_espresso'),
1042
-                __FILE__, __FUNCTION__, __LINE__
1043
-            );
1044
-        }
1045
-        return (bool)$queue_count;
1046
-    }
1047
-
1048
-
1049
-    /**
1050
-     * debug
1051
-     *
1052
-     * @param string          $class
1053
-     * @param string          $func
1054
-     * @param string          $line
1055
-     * @param \EE_Transaction $transaction
1056
-     * @param array           $info
1057
-     * @param bool            $display_request
1058
-     */
1059
-    protected static function log(
1060
-        $class = '',
1061
-        $func = '',
1062
-        $line = '',
1063
-        EE_Transaction $transaction,
1064
-        $info = array(),
1065
-        $display_request = false
1066
-    ) {
1067
-        if (WP_DEBUG && false) {
1068
-            if ($transaction instanceof EE_Transaction) {
1069
-                // don't serialize objects
1070
-                $info                  = EEH_Debug_Tools::strip_objects($info);
1071
-                $info['TXN_status']    = $transaction->status_ID();
1072
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1073
-                if ($transaction->ID()) {
1074
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1075
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1076
-                }
1077
-            }
1078
-        }
1079
-
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     *  Resets all the static properties in this class when called.
1085
-     */
1086
-    public static function reset()
1087
-    {
1088
-        self::$_EEMSG                    = null;
1089
-        self::$_message_resource_manager = null;
1090
-        self::$_MSG_PROCESSOR            = null;
1091
-        self::$_MSG_PATHS                = null;
1092
-        self::$_TMP_PACKS                = array();
1093
-    }
971
+						'event_espresso'),
972
+					__FILE__, __FUNCTION__, __LINE__
973
+				);
974
+			}
975
+		}
976
+		return $sent_queue;
977
+	}
978
+
979
+
980
+	/**
981
+	 * This will queue the incoming message ids for resending.
982
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
983
+	 *
984
+	 * @since 4.9.0
985
+	 * @param array $message_ids An array of EE_Message IDs
986
+	 * @return bool  true means messages were successfully queued for resending, false means none were queued for
987
+	 *               resending.
988
+	 */
989
+	public static function queue_for_resending($message_ids)
990
+	{
991
+		self::_load_controller();
992
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
993
+
994
+		//get queue and count
995
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
996
+
997
+		if (
998
+			$queue_count > 0
999
+		) {
1000
+			EE_Error::add_success(
1001
+				sprintf(
1002
+					_n(
1003
+						'%d message successfully queued for resending.',
1004
+						'%d messages successfully queued for resending.',
1005
+						$queue_count,
1006
+						'event_espresso'
1007
+					),
1008
+					$queue_count
1009
+				)
1010
+			);
1011
+			/**
1012
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1013
+			 */
1014
+		} elseif (
1015
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1016
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1017
+		) {
1018
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1019
+			if ($queue_count > 0) {
1020
+				EE_Error::add_success(
1021
+					sprintf(
1022
+						_n(
1023
+							'%d message successfully sent.',
1024
+							'%d messages successfully sent.',
1025
+							$queue_count,
1026
+							'event_espresso'
1027
+						),
1028
+						$queue_count
1029
+					)
1030
+				);
1031
+			} else {
1032
+				EE_Error::add_error(
1033
+					__('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.',
1034
+						'event_espresso'),
1035
+					__FILE__, __FUNCTION__, __LINE__
1036
+				);
1037
+			}
1038
+		} else {
1039
+			EE_Error::add_error(
1040
+				__('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.',
1041
+					'event_espresso'),
1042
+				__FILE__, __FUNCTION__, __LINE__
1043
+			);
1044
+		}
1045
+		return (bool)$queue_count;
1046
+	}
1047
+
1048
+
1049
+	/**
1050
+	 * debug
1051
+	 *
1052
+	 * @param string          $class
1053
+	 * @param string          $func
1054
+	 * @param string          $line
1055
+	 * @param \EE_Transaction $transaction
1056
+	 * @param array           $info
1057
+	 * @param bool            $display_request
1058
+	 */
1059
+	protected static function log(
1060
+		$class = '',
1061
+		$func = '',
1062
+		$line = '',
1063
+		EE_Transaction $transaction,
1064
+		$info = array(),
1065
+		$display_request = false
1066
+	) {
1067
+		if (WP_DEBUG && false) {
1068
+			if ($transaction instanceof EE_Transaction) {
1069
+				// don't serialize objects
1070
+				$info                  = EEH_Debug_Tools::strip_objects($info);
1071
+				$info['TXN_status']    = $transaction->status_ID();
1072
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1073
+				if ($transaction->ID()) {
1074
+					$index = 'EE_Transaction: ' . $transaction->ID();
1075
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1076
+				}
1077
+			}
1078
+		}
1079
+
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 *  Resets all the static properties in this class when called.
1085
+	 */
1086
+	public static function reset()
1087
+	{
1088
+		self::$_EEMSG                    = null;
1089
+		self::$_message_resource_manager = null;
1090
+		self::$_MSG_PROCESSOR            = null;
1091
+		self::$_MSG_PATHS                = null;
1092
+		self::$_TMP_PACKS                = array();
1093
+	}
1094 1094
 
1095 1095
 }
1096 1096
 // End of file EED_Messages.module.php
Please login to merge, or discard this patch.
acceptance_tests/tests/b-TestRegistrationSummaryCept.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
 
15 15
 //need the MER plugin active for this test (we'll deactivate it after).
16 16
 $I->ensurePluginActive(
17
-    'event-espresso-mer-multi-event-registration',
18
-    'activated'
17
+	'event-espresso-mer-multi-event-registration',
18
+	'activated'
19 19
 );
20 20
 
21 21
 //k now we need to make sure the registration multi-status message type is active because it isn't by default
@@ -68,42 +68,42 @@  discard block
 block discarded – undo
68 68
 $I->loginAsAdmin();
69 69
 $I->amOnMessagesActivityListTablePage();
70 70
 $I->see(
71
-    '[email protected]',
72
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
73
-        'to',
74
-        'Registration Multi-status Summary',
75
-        MessagesAdmin::MESSAGE_STATUS_SENT,
76
-        '',
77
-        'Primary Registrant'
78
-    )
71
+	'[email protected]',
72
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
73
+		'to',
74
+		'Registration Multi-status Summary',
75
+		MessagesAdmin::MESSAGE_STATUS_SENT,
76
+		'',
77
+		'Primary Registrant'
78
+	)
79 79
 );
80 80
 $I->see(
81
-    '[email protected]',
82
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
83
-        'to',
84
-        'Registration Multi-status Summary',
85
-        MessagesAdmin::MESSAGE_STATUS_SENT
86
-    )
81
+	'[email protected]',
82
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
83
+		'to',
84
+		'Registration Multi-status Summary',
85
+		MessagesAdmin::MESSAGE_STATUS_SENT
86
+	)
87 87
 );
88 88
 //verify count
89 89
 $I->verifyMatchingCountofTextInMessageActivityListTableFor(
90
-    1,
91
-    '[email protected]',
92
-    'to',
93
-    'Registration Multi-status Summary',
94
-    MessagesAdmin::MESSAGE_STATUS_SENT,
95
-    'Email',
96
-    'Primary Registrant'
90
+	1,
91
+	'[email protected]',
92
+	'to',
93
+	'Registration Multi-status Summary',
94
+	MessagesAdmin::MESSAGE_STATUS_SENT,
95
+	'Email',
96
+	'Primary Registrant'
97 97
 );
98 98
 $I->verifyMatchingCountofTextInMessageActivityListTableFor(
99
-    1,
100
-    '[email protected]',
101
-    'to',
102
-    'Registration Multi-status Summary'
99
+	1,
100
+	'[email protected]',
101
+	'to',
102
+	'Registration Multi-status Summary'
103 103
 );
104 104
 
105 105
 //deactivate MER plugin so its not active for future tests
106 106
 $I->ensurePluginDeactivated(
107
-    'event-espresso-mer-multi-event-registration',
108
-    'Plugin deactivated'
107
+	'event-espresso-mer-multi-event-registration',
108
+	'Plugin deactivated'
109 109
 );
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Page/MessagesAdmin.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -12,146 +12,146 @@
 block discarded – undo
12 12
 class MessagesAdmin extends CoreAdmin
13 13
 {
14 14
 
15
-    /**
16
-     * Context slug for the admin messages context.
17
-     * @var string
18
-     */
19
-    const ADMIN_CONTEXT_SLUG = 'admin';
20
-
21
-    /**
22
-     * Context slug for the primary attendee messages context
23
-     * @var string
24
-     */
25
-    const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
26
-
27
-
28
-    /**
29
-     * Status reference for the EEM_Message::status_sent status.
30
-     * @var string
31
-     */
32
-    const MESSAGE_STATUS_SENT = 'MSN';
33
-
34
-
35
-    /**
36
-     * Message type slug for the Payment Failed message type
37
-     */
38
-    const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
39
-
40
-
41
-    /**
42
-     * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
43
-     * @var string
44
-     */
45
-    const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request';
46
-
47
-
48
-    /**
49
-     * Selector for the Global Messages Settings submit button in the Messages Settings tab.
50
-     * @var string
51
-     */
52
-    const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
53
-
54
-
55
-    /**
56
-     * This is the container where active message types for a messenger are found/dragged to.
57
-     * @var string
58
-     */
59
-    const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
60
-
61
-
62
-
63
-    /**
64
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
65
-     *                                  a string.
66
-     * @return string
67
-     */
68
-    public static function messageActivityListTableUrl($additional_params = '')
69
-    {
70
-        return self::adminUrl('espresso_messages', 'default', $additional_params);
71
-    }
72
-
73
-
74
-    /**
75
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
76
-     *                                  a string.
77
-     * @return string
78
-     */
79
-    public static function defaultMessageTemplateListTableUrl($additional_params = '')
80
-    {
81
-        return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
82
-    }
83
-
84
-
85
-    /**
86
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
87
-     *                                  a string.
88
-     * @return string
89
-     */
90
-    public static function customMessageTemplateListTableUrl($additional_params = '')
91
-    {
92
-        return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
93
-    }
94
-
95
-
96
-    /**
97
-     * @return string
98
-     */
99
-    public static function messageSettingsUrl()
100
-    {
101
-        return self::adminUrl('espresso_messages', 'settings');
102
-    }
103
-
104
-
105
-
106
-    public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
107
-        $message_type_slug,
108
-        $messenger_slug = 'email'
109
-    ) {
110
-        return "#$message_type_slug-messagetype-$messenger_slug";
111
-    }
112
-
113
-
114
-    /**
115
-     * @param string $message_type_slug
116
-     * @param string $context
117
-     * @return string
118
-     */
119
-    public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
120
-    {
121
-        return $context
122
-            ? '.' . $message_type_slug . '-' . $context . '-edit-link'
123
-            : '.' . $message_type_slug . '-edit-link';
124
-    }
125
-
126
-
127
-    /**
128
-     * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
129
-     * @param        $field
130
-     * @param        $message_type_label
131
-     * @param string $message_status
132
-     * @param string $messenger
133
-     * @param string $context
134
-     * @param string $table_cell_content_for_field
135
-     * @return string
136
-     */
137
-    public static function messagesActivityListTableCellSelectorFor(
138
-        $field,
139
-        $message_type_label,
140
-        $message_status = self::MESSAGE_STATUS_SENT,
141
-        $messenger = 'Email',
142
-        $context = 'Event Admin',
143
-        $table_cell_content_for_field = ''
144
-    ) {
145
-        $selector = "//tr[contains(@class, 'msg-status-$message_status')]"
146
-                . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
147
-        if ($messenger) {
148
-            $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
149
-        }
150
-        $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
151
-        $selector .= $table_cell_content_for_field
152
-            ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
153
-            : "/ancestor::tr/td[contains(@class, 'column-$field')]";
154
-        return $selector;
155
-    }
15
+	/**
16
+	 * Context slug for the admin messages context.
17
+	 * @var string
18
+	 */
19
+	const ADMIN_CONTEXT_SLUG = 'admin';
20
+
21
+	/**
22
+	 * Context slug for the primary attendee messages context
23
+	 * @var string
24
+	 */
25
+	const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
26
+
27
+
28
+	/**
29
+	 * Status reference for the EEM_Message::status_sent status.
30
+	 * @var string
31
+	 */
32
+	const MESSAGE_STATUS_SENT = 'MSN';
33
+
34
+
35
+	/**
36
+	 * Message type slug for the Payment Failed message type
37
+	 */
38
+	const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
39
+
40
+
41
+	/**
42
+	 * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
43
+	 * @var string
44
+	 */
45
+	const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request';
46
+
47
+
48
+	/**
49
+	 * Selector for the Global Messages Settings submit button in the Messages Settings tab.
50
+	 * @var string
51
+	 */
52
+	const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
53
+
54
+
55
+	/**
56
+	 * This is the container where active message types for a messenger are found/dragged to.
57
+	 * @var string
58
+	 */
59
+	const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
60
+
61
+
62
+
63
+	/**
64
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
65
+	 *                                  a string.
66
+	 * @return string
67
+	 */
68
+	public static function messageActivityListTableUrl($additional_params = '')
69
+	{
70
+		return self::adminUrl('espresso_messages', 'default', $additional_params);
71
+	}
72
+
73
+
74
+	/**
75
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
76
+	 *                                  a string.
77
+	 * @return string
78
+	 */
79
+	public static function defaultMessageTemplateListTableUrl($additional_params = '')
80
+	{
81
+		return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
82
+	}
83
+
84
+
85
+	/**
86
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
87
+	 *                                  a string.
88
+	 * @return string
89
+	 */
90
+	public static function customMessageTemplateListTableUrl($additional_params = '')
91
+	{
92
+		return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return string
98
+	 */
99
+	public static function messageSettingsUrl()
100
+	{
101
+		return self::adminUrl('espresso_messages', 'settings');
102
+	}
103
+
104
+
105
+
106
+	public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
107
+		$message_type_slug,
108
+		$messenger_slug = 'email'
109
+	) {
110
+		return "#$message_type_slug-messagetype-$messenger_slug";
111
+	}
112
+
113
+
114
+	/**
115
+	 * @param string $message_type_slug
116
+	 * @param string $context
117
+	 * @return string
118
+	 */
119
+	public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
120
+	{
121
+		return $context
122
+			? '.' . $message_type_slug . '-' . $context . '-edit-link'
123
+			: '.' . $message_type_slug . '-edit-link';
124
+	}
125
+
126
+
127
+	/**
128
+	 * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
129
+	 * @param        $field
130
+	 * @param        $message_type_label
131
+	 * @param string $message_status
132
+	 * @param string $messenger
133
+	 * @param string $context
134
+	 * @param string $table_cell_content_for_field
135
+	 * @return string
136
+	 */
137
+	public static function messagesActivityListTableCellSelectorFor(
138
+		$field,
139
+		$message_type_label,
140
+		$message_status = self::MESSAGE_STATUS_SENT,
141
+		$messenger = 'Email',
142
+		$context = 'Event Admin',
143
+		$table_cell_content_for_field = ''
144
+	) {
145
+		$selector = "//tr[contains(@class, 'msg-status-$message_status')]"
146
+				. "//td[contains(@class, 'message_type') and text()='$message_type_label']";
147
+		if ($messenger) {
148
+			$selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
149
+		}
150
+		$selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
151
+		$selector .= $table_cell_content_for_field
152
+			? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
153
+			: "/ancestor::tr/td[contains(@class, 'column-$field')]";
154
+		return $selector;
155
+	}
156 156
 
157 157
 }
158 158
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/MessagesAdmin.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -10,105 +10,105 @@
 block discarded – undo
10 10
  */
11 11
 trait MessagesAdmin
12 12
 {
13
-    /**
14
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
15
-     *                                  a string.
16
-     */
17
-    public function amOnMessagesActivityListTablePage($additional_params = '')
18
-    {
19
-        $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
-    }
13
+	/**
14
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
15
+	 *                                  a string.
16
+	 */
17
+	public function amOnMessagesActivityListTablePage($additional_params = '')
18
+	{
19
+		$this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
+	}
21 21
 
22
-    /**
23
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
24
-     *                                  a string.
25
-     */
26
-    public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
-    {
28
-        $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
-    }
22
+	/**
23
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
24
+	 *                                  a string.
25
+	 */
26
+	public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
+	{
28
+		$this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
34
-     *                                  a string.
35
-     */
36
-    public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
-    {
38
-        $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
-    }
32
+	/**
33
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
34
+	 *                                  a string.
35
+	 */
36
+	public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
+	{
38
+		$this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * Directs to message settings page
44
-     */
45
-    public function amOnMessageSettingsPage()
46
-    {
47
-        $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
-    }
42
+	/**
43
+	 * Directs to message settings page
44
+	 */
45
+	public function amOnMessageSettingsPage()
46
+	{
47
+		$this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
+	}
49 49
 
50 50
 
51
-    public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
-    {
53
-        $this->actor()->dragAndDrop(
54
-            MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
-            MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
-        );
57
-    }
51
+	public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
+	{
53
+		$this->actor()->dragAndDrop(
54
+			MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
+			MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
+		);
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * Assumes you are already on the list table page that has the ui for editing the template.
62
-     * @param string $message_type_slug
63
-     * @param string $context [optional] if you want to click directly to the given context in the editor
64
-     */
65
-    public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
-    {
67
-        $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
-    }
60
+	/**
61
+	 * Assumes you are already on the list table page that has the ui for editing the template.
62
+	 * @param string $message_type_slug
63
+	 * @param string $context [optional] if you want to click directly to the given context in the editor
64
+	 */
65
+	public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
+	{
67
+		$this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
-     * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
-     *
75
-     * @param int    $expected_occurence_count
76
-     * @param string $text_to_check_for
77
-     * @param string $field
78
-     * @param string $message_type_label
79
-     * @param string $message_status
80
-     * @param string $messenger
81
-     * @param string $context
82
-     */
83
-    public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
-        $expected_occurence_count,
85
-        $text_to_check_for,
86
-        $field,
87
-        $message_type_label,
88
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
-        $messenger = 'Email',
90
-        $context = 'Event Admin'
91
-    ) {
92
-        $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
-            $field,
94
-            $message_type_label,
95
-            $message_status,
96
-            $messenger,
97
-            $context,
98
-            $text_to_check_for
99
-        ));
100
-        $actual_count = count($elements);
101
-        $this->actor()->assertEquals(
102
-            $expected_occurence_count,
103
-            $actual_count,
104
-            sprintf(
105
-                'Expected %s of the %s text for the %s field but there were actually %s counted.',
106
-                $expected_occurence_count,
107
-                $text_to_check_for,
108
-                $field,
109
-                $actual_count
110
-            )
111
-        );
112
-    }
71
+	/**
72
+	 * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
+	 * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
+	 *
75
+	 * @param int    $expected_occurence_count
76
+	 * @param string $text_to_check_for
77
+	 * @param string $field
78
+	 * @param string $message_type_label
79
+	 * @param string $message_status
80
+	 * @param string $messenger
81
+	 * @param string $context
82
+	 */
83
+	public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
+		$expected_occurence_count,
85
+		$text_to_check_for,
86
+		$field,
87
+		$message_type_label,
88
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
+		$messenger = 'Email',
90
+		$context = 'Event Admin'
91
+	) {
92
+		$elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
+			$field,
94
+			$message_type_label,
95
+			$message_status,
96
+			$messenger,
97
+			$context,
98
+			$text_to_check_for
99
+		));
100
+		$actual_count = count($elements);
101
+		$this->actor()->assertEquals(
102
+			$expected_occurence_count,
103
+			$actual_count,
104
+			sprintf(
105
+				'Expected %s of the %s text for the %s field but there were actually %s counted.',
106
+				$expected_occurence_count,
107
+				$text_to_check_for,
108
+				$field,
109
+				$actual_count
110
+			)
111
+		);
112
+	}
113 113
 
114 114
 }
115 115
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Error.core.php 1 patch
Indentation   +1085 added lines, -1085 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
 // if you're a dev and want to receive all errors via email
6 6
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
7 7
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
8
-    set_error_handler(array('EE_Error', 'error_handler'));
9
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
8
+	set_error_handler(array('EE_Error', 'error_handler'));
9
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
10 10
 }
11 11
 
12 12
 
@@ -23,259 +23,259 @@  discard block
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     *    name of the file to log exceptions to
28
-     *
29
-     * @var string
30
-     */
31
-    private static $_exception_log_file = 'espresso_error_log.txt';
32
-
33
-    /**
34
-     *    stores details for all exception
35
-     *
36
-     * @var array
37
-     */
38
-    private static $_all_exceptions = array();
39
-
40
-    /**
41
-     *    tracks number of errors
42
-     *
43
-     * @var int
44
-     */
45
-    private static $_error_count = 0;
46
-
47
-    /**
48
-     *    has shutdown action been added ?
49
-     *
50
-     * @var array $_espresso_notices
51
-     */
52
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
-
54
-
55
-
56
-    /**
57
-     * @override default exception handling
58
-     * @param string         $message
59
-     * @param int            $code
60
-     * @param Exception|null $previous
61
-     */
62
-    public function __construct($message, $code = 0, Exception $previous = null)
63
-    {
64
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
-            parent::__construct($message, $code);
66
-        } else {
67
-            parent::__construct($message, $code, $previous);
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    error_handler
75
-     *
76
-     * @param $code
77
-     * @param $message
78
-     * @param $file
79
-     * @param $line
80
-     * @return void
81
-     */
82
-    public static function error_handler($code, $message, $file, $line)
83
-    {
84
-        $type = EE_Error::error_type($code);
85
-        $site = site_url();
86
-        switch ($site) {
87
-            case 'http://ee4.eventespresso.com/' :
88
-            case 'http://ee4decaf.eventespresso.com/' :
89
-            case 'http://ee4hf.eventespresso.com/' :
90
-            case 'http://ee4a.eventespresso.com/' :
91
-            case 'http://ee4ad.eventespresso.com/' :
92
-            case 'http://ee4b.eventespresso.com/' :
93
-            case 'http://ee4bd.eventespresso.com/' :
94
-            case 'http://ee4d.eventespresso.com/' :
95
-            case 'http://ee4dd.eventespresso.com/' :
96
-                $to = '[email protected]';
97
-                break;
98
-            default :
99
-                $to = get_option('admin_email');
100
-        }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
103
-        if (function_exists('wp_mail')) {
104
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
-            wp_mail($to, $subject, $msg);
106
-        }
107
-        echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
-        echo '<br /></p></div>';
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * error_type
116
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
-     *
118
-     * @param $code
119
-     * @return string
120
-     */
121
-    public static function error_type($code)
122
-    {
123
-        switch ($code) {
124
-            case E_ERROR: // 1 //
125
-                return 'E_ERROR';
126
-            case E_WARNING: // 2 //
127
-                return 'E_WARNING';
128
-            case E_PARSE: // 4 //
129
-                return 'E_PARSE';
130
-            case E_NOTICE: // 8 //
131
-                return 'E_NOTICE';
132
-            case E_CORE_ERROR: // 16 //
133
-                return 'E_CORE_ERROR';
134
-            case E_CORE_WARNING: // 32 //
135
-                return 'E_CORE_WARNING';
136
-            case E_COMPILE_ERROR: // 64 //
137
-                return 'E_COMPILE_ERROR';
138
-            case E_COMPILE_WARNING: // 128 //
139
-                return 'E_COMPILE_WARNING';
140
-            case E_USER_ERROR: // 256 //
141
-                return 'E_USER_ERROR';
142
-            case E_USER_WARNING: // 512 //
143
-                return 'E_USER_WARNING';
144
-            case E_USER_NOTICE: // 1024 //
145
-                return 'E_USER_NOTICE';
146
-            case E_STRICT: // 2048 //
147
-                return 'E_STRICT';
148
-            case E_RECOVERABLE_ERROR: // 4096 //
149
-                return 'E_RECOVERABLE_ERROR';
150
-            case E_DEPRECATED: // 8192 //
151
-                return 'E_DEPRECATED';
152
-            case E_USER_DEPRECATED: // 16384 //
153
-                return 'E_USER_DEPRECATED';
154
-            case E_ALL: // 16384 //
155
-                return 'E_ALL';
156
-        }
157
-        return '';
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     *    fatal_error_handler
164
-     *
165
-     * @return void
166
-     */
167
-    public static function fatal_error_handler()
168
-    {
169
-        $last_error = error_get_last();
170
-        if ($last_error['type'] === E_ERROR) {
171
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
-        }
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * _format_error
179
-     *
180
-     * @param $code
181
-     * @param $message
182
-     * @param $file
183
-     * @param $line
184
-     * @return string
185
-     */
186
-    private static function _format_error($code, $message, $file, $line)
187
-    {
188
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
-        $html .= '</tbody></table>';
194
-        return $html;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * set_content_type
201
-     *
202
-     * @param $content_type
203
-     * @return string
204
-     */
205
-    public static function set_content_type($content_type)
206
-    {
207
-        return 'text/html';
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * @return void
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function get_error()
218
-    {
219
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
-            throw $this;
221
-        }
222
-        // get separate user and developer messages if they exist
223
-        $msg = explode('||', $this->getMessage());
224
-        $user_msg = $msg[0];
225
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
227
-        // add details to _all_exceptions array
228
-        $x_time = time();
229
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
233
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
-        self::$_error_count++;
237
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
238
-        $this->display_errors();
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     *    has_error
245
-     *
246
-     * @param bool   $check_stored
247
-     * @param string $type_to_check
248
-     * @return bool
249
-     */
250
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
251
-    {
252
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
253
-                     && ! empty(self::$_espresso_notices[$type_to_check])
254
-            ? true
255
-            : false;
256
-        if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
258
-            foreach ($notices as $type => $notice) {
259
-                if ($type === $type_to_check && $notice) {
260
-                    return true;
261
-                }
262
-            }
263
-        }
264
-        return $has_error;
265
-    }
266
-
267
-
268
-
269
-    /**
270
-     *    display_errors
271
-     *
272
-     * @echo   string
273
-     * @throws \ReflectionException
274
-     */
275
-    public function display_errors()
276
-    {
277
-        $trace_details = '';
278
-        $output = '
26
+	/**
27
+	 *    name of the file to log exceptions to
28
+	 *
29
+	 * @var string
30
+	 */
31
+	private static $_exception_log_file = 'espresso_error_log.txt';
32
+
33
+	/**
34
+	 *    stores details for all exception
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private static $_all_exceptions = array();
39
+
40
+	/**
41
+	 *    tracks number of errors
42
+	 *
43
+	 * @var int
44
+	 */
45
+	private static $_error_count = 0;
46
+
47
+	/**
48
+	 *    has shutdown action been added ?
49
+	 *
50
+	 * @var array $_espresso_notices
51
+	 */
52
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
+
54
+
55
+
56
+	/**
57
+	 * @override default exception handling
58
+	 * @param string         $message
59
+	 * @param int            $code
60
+	 * @param Exception|null $previous
61
+	 */
62
+	public function __construct($message, $code = 0, Exception $previous = null)
63
+	{
64
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
+			parent::__construct($message, $code);
66
+		} else {
67
+			parent::__construct($message, $code, $previous);
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    error_handler
75
+	 *
76
+	 * @param $code
77
+	 * @param $message
78
+	 * @param $file
79
+	 * @param $line
80
+	 * @return void
81
+	 */
82
+	public static function error_handler($code, $message, $file, $line)
83
+	{
84
+		$type = EE_Error::error_type($code);
85
+		$site = site_url();
86
+		switch ($site) {
87
+			case 'http://ee4.eventespresso.com/' :
88
+			case 'http://ee4decaf.eventespresso.com/' :
89
+			case 'http://ee4hf.eventespresso.com/' :
90
+			case 'http://ee4a.eventespresso.com/' :
91
+			case 'http://ee4ad.eventespresso.com/' :
92
+			case 'http://ee4b.eventespresso.com/' :
93
+			case 'http://ee4bd.eventespresso.com/' :
94
+			case 'http://ee4d.eventespresso.com/' :
95
+			case 'http://ee4dd.eventespresso.com/' :
96
+				$to = '[email protected]';
97
+				break;
98
+			default :
99
+				$to = get_option('admin_email');
100
+		}
101
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
103
+		if (function_exists('wp_mail')) {
104
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
+			wp_mail($to, $subject, $msg);
106
+		}
107
+		echo '<div id="message" class="espresso-notices error"><p>';
108
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
+		echo '<br /></p></div>';
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * error_type
116
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
+	 *
118
+	 * @param $code
119
+	 * @return string
120
+	 */
121
+	public static function error_type($code)
122
+	{
123
+		switch ($code) {
124
+			case E_ERROR: // 1 //
125
+				return 'E_ERROR';
126
+			case E_WARNING: // 2 //
127
+				return 'E_WARNING';
128
+			case E_PARSE: // 4 //
129
+				return 'E_PARSE';
130
+			case E_NOTICE: // 8 //
131
+				return 'E_NOTICE';
132
+			case E_CORE_ERROR: // 16 //
133
+				return 'E_CORE_ERROR';
134
+			case E_CORE_WARNING: // 32 //
135
+				return 'E_CORE_WARNING';
136
+			case E_COMPILE_ERROR: // 64 //
137
+				return 'E_COMPILE_ERROR';
138
+			case E_COMPILE_WARNING: // 128 //
139
+				return 'E_COMPILE_WARNING';
140
+			case E_USER_ERROR: // 256 //
141
+				return 'E_USER_ERROR';
142
+			case E_USER_WARNING: // 512 //
143
+				return 'E_USER_WARNING';
144
+			case E_USER_NOTICE: // 1024 //
145
+				return 'E_USER_NOTICE';
146
+			case E_STRICT: // 2048 //
147
+				return 'E_STRICT';
148
+			case E_RECOVERABLE_ERROR: // 4096 //
149
+				return 'E_RECOVERABLE_ERROR';
150
+			case E_DEPRECATED: // 8192 //
151
+				return 'E_DEPRECATED';
152
+			case E_USER_DEPRECATED: // 16384 //
153
+				return 'E_USER_DEPRECATED';
154
+			case E_ALL: // 16384 //
155
+				return 'E_ALL';
156
+		}
157
+		return '';
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 *    fatal_error_handler
164
+	 *
165
+	 * @return void
166
+	 */
167
+	public static function fatal_error_handler()
168
+	{
169
+		$last_error = error_get_last();
170
+		if ($last_error['type'] === E_ERROR) {
171
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
+		}
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * _format_error
179
+	 *
180
+	 * @param $code
181
+	 * @param $message
182
+	 * @param $file
183
+	 * @param $line
184
+	 * @return string
185
+	 */
186
+	private static function _format_error($code, $message, $file, $line)
187
+	{
188
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
+		$html .= '</tbody></table>';
194
+		return $html;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * set_content_type
201
+	 *
202
+	 * @param $content_type
203
+	 * @return string
204
+	 */
205
+	public static function set_content_type($content_type)
206
+	{
207
+		return 'text/html';
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * @return void
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function get_error()
218
+	{
219
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
+			throw $this;
221
+		}
222
+		// get separate user and developer messages if they exist
223
+		$msg = explode('||', $this->getMessage());
224
+		$user_msg = $msg[0];
225
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
227
+		// add details to _all_exceptions array
228
+		$x_time = time();
229
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
233
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
+		self::$_error_count++;
237
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
238
+		$this->display_errors();
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 *    has_error
245
+	 *
246
+	 * @param bool   $check_stored
247
+	 * @param string $type_to_check
248
+	 * @return bool
249
+	 */
250
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
251
+	{
252
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
253
+					 && ! empty(self::$_espresso_notices[$type_to_check])
254
+			? true
255
+			: false;
256
+		if ($check_stored && ! $has_error) {
257
+			$notices = (array)get_option('ee_notices', array());
258
+			foreach ($notices as $type => $notice) {
259
+				if ($type === $type_to_check && $notice) {
260
+					return true;
261
+				}
262
+			}
263
+		}
264
+		return $has_error;
265
+	}
266
+
267
+
268
+
269
+	/**
270
+	 *    display_errors
271
+	 *
272
+	 * @echo   string
273
+	 * @throws \ReflectionException
274
+	 */
275
+	public function display_errors()
276
+	{
277
+		$trace_details = '';
278
+		$output = '
279 279
 <style type="text/css">
280 280
 	#ee-error-message {
281 281
 		max-width:90% !important;
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
335
-            $output .= '
334
+		if (! WP_DEBUG) {
335
+			$output .= '
336 336
 	<p>';
337
-        }
338
-        // cycle thru errors
339
-        foreach (self::$_all_exceptions as $time => $ex) {
340
-            $error_code = '';
341
-            // process trace info
342
-            if (empty($ex['trace'])) {
343
-                $trace_details .= __('Sorry, but no trace information was available for this exception.',
344
-                    'event_espresso');
345
-            } else {
346
-                $trace_details .= '
337
+		}
338
+		// cycle thru errors
339
+		foreach (self::$_all_exceptions as $time => $ex) {
340
+			$error_code = '';
341
+			// process trace info
342
+			if (empty($ex['trace'])) {
343
+				$trace_details .= __('Sorry, but no trace information was available for this exception.',
344
+					'event_espresso');
345
+			} else {
346
+				$trace_details .= '
347 347
 			<div id="ee-trace-details">
348 348
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
349 349
 				<tr>
@@ -353,38 +353,38 @@  discard block
 block discarded – undo
353 353
 					<th scope="col" align="left">Class</th>
354 354
 					<th scope="col" align="left">Method( arguments )</th>
355 355
 				</tr>';
356
-                $last_on_stack = count($ex['trace']) - 1;
357
-                // reverse array so that stack is in proper chronological order
358
-                $sorted_trace = array_reverse($ex['trace']);
359
-                foreach ($sorted_trace as $nmbr => $trace) {
360
-                    $file = isset($trace['file']) ? $trace['file'] : '';
361
-                    $class = isset($trace['class']) ? $trace['class'] : '';
362
-                    $type = isset($trace['type']) ? $trace['type'] : '';
363
-                    $function = isset($trace['function']) ? $trace['function'] : '';
364
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
-                    $line = isset($trace['line']) ? $trace['line'] : '';
366
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
367
-                    if (empty($file) && ! empty($class)) {
368
-                        $a = new ReflectionClass($class);
369
-                        $file = $a->getFileName();
370
-                        if (empty($line) && ! empty($function)) {
371
-                            $b = new ReflectionMethod($class, $function);
372
-                            $line = $b->getStartLine();
373
-                        }
374
-                    }
375
-                    if ($nmbr === $last_on_stack) {
376
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
377
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
378
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
379
-                    }
380
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
382
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
383
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
384
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
385
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
-                    $trace_details .= '
356
+				$last_on_stack = count($ex['trace']) - 1;
357
+				// reverse array so that stack is in proper chronological order
358
+				$sorted_trace = array_reverse($ex['trace']);
359
+				foreach ($sorted_trace as $nmbr => $trace) {
360
+					$file = isset($trace['file']) ? $trace['file'] : '';
361
+					$class = isset($trace['class']) ? $trace['class'] : '';
362
+					$type = isset($trace['type']) ? $trace['type'] : '';
363
+					$function = isset($trace['function']) ? $trace['function'] : '';
364
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
+					$line = isset($trace['line']) ? $trace['line'] : '';
366
+					$zebra = ($nmbr % 2) ? ' odd' : '';
367
+					if (empty($file) && ! empty($class)) {
368
+						$a = new ReflectionClass($class);
369
+						$file = $a->getFileName();
370
+						if (empty($line) && ! empty($function)) {
371
+							$b = new ReflectionMethod($class, $function);
372
+							$line = $b->getStartLine();
373
+						}
374
+					}
375
+					if ($nmbr === $last_on_stack) {
376
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
377
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
378
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
379
+					}
380
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
382
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
383
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
384
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
385
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
386
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
+					$trace_details .= '
388 388
 					<tr>
389 389
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390 390
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -392,669 +392,669 @@  discard block
 block discarded – undo
392 392
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393 393
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
394 394
 					</tr>';
395
-                }
396
-                $trace_details .= '
395
+				}
396
+				$trace_details .= '
397 397
 			 </table>
398 398
 			</div>';
399
-            }
400
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
-            // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
403
-                $output .= '<span class="ee-error-user-msg-spn">'
404
-                           . trim($ex['msg'])
405
-                           . '</span> &nbsp; <sup>'
406
-                           . $ex['code']
407
-                           . '</sup><br />';
408
-            } else {
409
-                // or helpful developer messages if debugging is on
410
-                $output .= '
399
+			}
400
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
+			// add generic non-identifying messages for non-privileged users
402
+			if (! WP_DEBUG) {
403
+				$output .= '<span class="ee-error-user-msg-spn">'
404
+						   . trim($ex['msg'])
405
+						   . '</span> &nbsp; <sup>'
406
+						   . $ex['code']
407
+						   . '</sup><br />';
408
+			} else {
409
+				// or helpful developer messages if debugging is on
410
+				$output .= '
411 411
 		<div class="ee-error-dev-msg-dv">
412 412
 			<p class="ee-error-dev-msg-pg">
413 413
 				<strong class="ee-error-dev-msg-str">An '
414
-                           . $ex['name']
415
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
-                           . $ex['code']
417
-                           . '</span><br />
414
+						   . $ex['name']
415
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
+						   . $ex['code']
417
+						   . '</span><br />
418 418
 				<span class="big-text">"'
419
-                           . trim($ex['msg'])
420
-                           . '"</span><br/>
419
+						   . trim($ex['msg'])
420
+						   . '"</span><br/>
421 421
 				<a id="display-ee-error-trace-'
422
-                           . self::$_error_count
423
-                           . $time
424
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
-                           . self::$_error_count
426
-                           . $time
427
-                           . '">
422
+						   . self::$_error_count
423
+						   . $time
424
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
+						   . self::$_error_count
426
+						   . $time
427
+						   . '">
428 428
 					'
429
-                           . __('click to view backtrace and class/method details', 'event_espresso')
430
-                           . '
429
+						   . __('click to view backtrace and class/method details', 'event_espresso')
430
+						   . '
431 431
 				</a><br />
432 432
 				<span class="small-text lt-grey-text">'
433
-                           . $ex['file']
434
-                           . ' &nbsp; ( line no: '
435
-                           . $ex['line']
436
-                           . ' )</span>
433
+						   . $ex['file']
434
+						   . ' &nbsp; ( line no: '
435
+						   . $ex['line']
436
+						   . ' )</span>
437 437
 			</p>
438 438
 			<div id="ee-error-trace-'
439
-                           . self::$_error_count
440
-                           . $time
441
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
439
+						   . self::$_error_count
440
+						   . $time
441
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443
-                           . $trace_details;
444
-                if (! empty($class)) {
445
-                    $output .= '
443
+						   . $trace_details;
444
+				if (! empty($class)) {
445
+					$output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449
-                    $a = new ReflectionClass($class);
450
-                    $output .= '
449
+					$a = new ReflectionClass($class);
450
+					$output .= '
451 451
 						<pre>' . $a . '</pre>
452 452
 					</div>
453 453
 				</div>';
454
-                }
455
-                $output .= '
454
+				}
455
+				$output .= '
456 456
 			</div>
457 457
 		</div>
458 458
 		<br />';
459
-            }
460
-            $this->write_to_error_log($time, $ex);
461
-        }
462
-        // remove last linebreak
463
-        $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
465
-            $output .= '
459
+			}
460
+			$this->write_to_error_log($time, $ex);
461
+		}
462
+		// remove last linebreak
463
+		$output = substr($output, 0, -6);
464
+		if (! WP_DEBUG) {
465
+			$output .= '
466 466
 	</p>';
467
-        }
468
-        $output .= '
467
+		}
468
+		$output .= '
469 469
 </div>';
470
-        $output .= self::_print_scripts(true);
471
-        if (defined('DOING_AJAX')) {
472
-            echo wp_json_encode(array('error' => $output));
473
-            exit();
474
-        }
475
-        echo $output;
476
-        die();
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     *    generate string from exception trace args
483
-     *
484
-     * @param array $arguments
485
-     * @param bool  $array
486
-     * @return string
487
-     */
488
-    private function _convert_args_to_string($arguments = array(), $array = false)
489
-    {
490
-        $arg_string = '';
491
-        if (! empty($arguments)) {
492
-            $args = array();
493
-            foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
495
-                    if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
497
-                    } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
-                    } elseif ($arg === null) {
500
-                        $args[] = ' NULL';
501
-                    } elseif (is_bool($arg)) {
502
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
503
-                    } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
505
-                    } elseif (is_resource($arg)) {
506
-                        $args[] = get_resource_type($arg);
507
-                    } else {
508
-                        $args[] = $arg;
509
-                    }
510
-                }
511
-            }
512
-            $arg_string = implode(', ', $args);
513
-        }
514
-        if ($array) {
515
-            $arg_string .= ' )';
516
-        }
517
-        return $arg_string;
518
-    }
519
-
520
-
521
-
522
-    /**
523
-     *    add error message
524
-     *
525
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
-     *                            separate messages for user || dev
527
-     * @param        string $file the file that the error occurred in - just use __FILE__
528
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
-     * @param        string $line the line number where the error occurred - just use __LINE__
530
-     * @return        void
531
-     */
532
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
-    {
534
-        self::_add_notice('errors', $msg, $file, $func, $line);
535
-        self::$_error_count++;
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
-     * adds an error
543
-     *
544
-     * @param string $msg
545
-     * @param string $file
546
-     * @param string $func
547
-     * @param string $line
548
-     * @throws EE_Error
549
-     */
550
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
-    {
552
-        if (WP_DEBUG) {
553
-            throw new EE_Error($msg);
554
-        }
555
-        EE_Error::add_error($msg, $file, $func, $line);
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     *    add success message
562
-     *
563
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
-     *                            separate messages for user || dev
565
-     * @param        string $file the file that the error occurred in - just use __FILE__
566
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
-     * @param        string $line the line number where the error occurred - just use __LINE__
568
-     * @return        void
569
-     */
570
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
-    {
572
-        self::_add_notice('success', $msg, $file, $func, $line);
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     *    add attention message
579
-     *
580
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
-     *                            separate messages for user || dev
582
-     * @param        string $file the file that the error occurred in - just use __FILE__
583
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
-     * @param        string $line the line number where the error occurred - just use __LINE__
585
-     * @return        void
586
-     */
587
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
-    {
589
-        self::_add_notice('attention', $msg, $file, $func, $line);
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     *    add success message
596
-     *
597
-     * @param        string $type whether the message is for a success or error notification
598
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
-     *                            separate messages for user || dev
600
-     * @param        string $file the file that the error occurred in - just use __FILE__
601
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
-     * @param        string $line the line number where the error occurred - just use __LINE__
603
-     * @return        void
604
-     */
605
-    private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
-    {
607
-        if (empty($msg)) {
608
-            EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
610
-                sprintf(
611
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612
-                        'event_espresso'),
613
-                    $type,
614
-                    $file,
615
-                    $line
616
-                ),
617
-                EVENT_ESPRESSO_VERSION
618
-            );
619
-        }
620
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
-            EE_Error::doing_it_wrong(
622
-                'EE_Error::add_error()',
623
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
-                    'event_espresso'),
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-        }
628
-        // get separate user and developer messages if they exist
629
-        $msg = explode('||', $msg);
630
-        $user_msg = $msg[0];
631
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
-        /**
633
-         * Do an action so other code can be triggered when a notice is created
634
-         *
635
-         * @param string $type     can be 'errors', 'attention', or 'success'
636
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
637
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
638
-         * @param string $file     file where error was generated
639
-         * @param string $func     function where error was generated
640
-         * @param string $line     line where error was generated
641
-         */
642
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
644
-        // add notice if message exists
645
-        if (! empty($msg)) {
646
-            // get error code
647
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
648
-            if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
-            }
651
-            // add notice. Index by code if it's not blank
652
-            if ($notice_code) {
653
-                self::$_espresso_notices[$type][$notice_code] = $msg;
654
-            } else {
655
-                self::$_espresso_notices[$type][] = $msg;
656
-            }
657
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
-        }
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     *    in some case it may be necessary to overwrite the existing success messages
665
-     *
666
-     * @return        void
667
-     */
668
-    public static function overwrite_success()
669
-    {
670
-        self::$_espresso_notices['success'] = false;
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     *    in some case it may be necessary to overwrite the existing attention messages
677
-     *
678
-     * @return        void
679
-     */
680
-    public static function overwrite_attention()
681
-    {
682
-        self::$_espresso_notices['attention'] = false;
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     *    in some case it may be necessary to overwrite the existing error messages
689
-     *
690
-     * @return        void
691
-     */
692
-    public static function overwrite_errors()
693
-    {
694
-        self::$_espresso_notices['errors'] = false;
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     *    reset_notices
701
-     *
702
-     * @return void
703
-     */
704
-    public static function reset_notices()
705
-    {
706
-        self::$_espresso_notices['success'] = false;
707
-        self::$_espresso_notices['attention'] = false;
708
-        self::$_espresso_notices['errors'] = false;
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     *    has_errors
715
-     *
716
-     * @return int
717
-     */
718
-    public static function has_notices()
719
-    {
720
-        $has_notices = 0;
721
-        // check for success messages
722
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
-            : $has_notices;
724
-        // check for attention messages
725
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
-            : $has_notices;
727
-        // check for error messages
728
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
-            : $has_notices;
730
-        return $has_notices;
731
-    }
732
-
733
-
734
-
735
-    /**
736
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
-     *
738
-     * @since 4.9.0
739
-     * @return array
740
-     */
741
-    public static function get_vanilla_notices()
742
-    {
743
-        return array(
744
-            'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
-            'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
-                : array(),
747
-            'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
-        );
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     *    compile all error or success messages into one string
755
-     *
756
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
-     * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
-     * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
-     *                                          - ONLY do this just before redirecting
760
-     * @param        boolean $remove_empty      whether or not to unset empty messages
761
-     * @return        array
762
-     */
763
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
-    {
765
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
-        $success_messages = '';
767
-        $attention_messages = '';
768
-        $error_messages = '';
769
-        $print_scripts = false;
770
-        // either save notices to the db
771
-        if ($save_to_transient) {
772
-            update_option('ee_notices', self::$_espresso_notices);
773
-            return array();
774
-        }
775
-        // grab any notices that have been previously saved
776
-        if ($notices = get_option('ee_notices', false)) {
777
-            foreach ($notices as $type => $notice) {
778
-                if (is_array($notice) && ! empty($notice)) {
779
-                    // make sure that existing notice type is an array
780
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
-                                                      && ! empty(self::$_espresso_notices[$type])
782
-                        ? self::$_espresso_notices[$type] : array();
783
-                    // merge stored notices with any newly created ones
784
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
-                    $print_scripts = true;
786
-                }
787
-            }
788
-            // now clear any stored notices
789
-            update_option('ee_notices', false);
790
-        }
791
-        // check for success messages
792
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
-            // combine messages
794
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
-            $print_scripts = true;
796
-        }
797
-        // check for attention messages
798
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
-            // combine messages
800
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
-            $print_scripts = true;
802
-        }
803
-        // check for error messages
804
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
806
-                ? __('The following errors have occurred:<br />', 'event_espresso')
807
-                : __('An error has occurred:<br />', 'event_espresso');
808
-            // combine messages
809
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
-            $print_scripts = true;
811
-        }
812
-        if ($format_output) {
813
-            $notices = '<div id="espresso-notices">';
814
-            $close = is_admin() ? ''
815
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
816
-            if ($success_messages !== '') {
817
-                $css_id = is_admin() ? 'message' : 'espresso-notices-success';
818
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
819
-                //showMessage( $success_messages );
820
-                $notices .= '<div id="'
821
-                            . $css_id
822
-                            . '" class="espresso-notices '
823
-                            . $css_class
824
-                            . '" style="display:none;"><p>'
825
-                            . $success_messages
826
-                            . '</p>'
827
-                            . $close
828
-                            . '</div>';
829
-            }
830
-            if ($attention_messages !== '') {
831
-                $css_id = is_admin() ? 'message' : 'espresso-notices-attention';
832
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
833
-                //showMessage( $error_messages, TRUE );
834
-                $notices .= '<div id="'
835
-                            . $css_id
836
-                            . '" class="espresso-notices '
837
-                            . $css_class
838
-                            . '" style="display:none;"><p>'
839
-                            . $attention_messages
840
-                            . '</p>'
841
-                            . $close
842
-                            . '</div>';
843
-            }
844
-            if ($error_messages !== '') {
845
-                $css_id = is_admin() ? 'message' : 'espresso-notices-error';
846
-                $css_class = is_admin() ? 'error' : 'error fade-away';
847
-                //showMessage( $error_messages, TRUE );
848
-                $notices .= '<div id="'
849
-                            . $css_id
850
-                            . '" class="espresso-notices '
851
-                            . $css_class
852
-                            . '" style="display:none;"><p>'
853
-                            . $error_messages
854
-                            . '</p>'
855
-                            . $close
856
-                            . '</div>';
857
-            }
858
-            $notices .= '</div>';
859
-        } else {
860
-            $notices = array(
861
-                'success'   => $success_messages,
862
-                'attention' => $attention_messages,
863
-                'errors'    => $error_messages,
864
-            );
865
-            if ($remove_empty) {
866
-                // remove empty notices
867
-                foreach ($notices as $type => $notice) {
868
-                    if (empty($notice)) {
869
-                        unset($notices[$type]);
870
-                    }
871
-                }
872
-            }
873
-        }
874
-        if ($print_scripts) {
875
-            self::_print_scripts();
876
-        }
877
-        return $notices;
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     *    add_persistent_admin_notice
884
-     *
885
-     * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
886
-     * @param        string $pan_message  the message to be stored persistently until dismissed
887
-     * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
888
-     * @return        void
889
-     */
890
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
891
-    {
892
-        if (! empty($pan_name) && ! empty($pan_message)) {
893
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
894
-            //maybe initialize persistent_admin_notices
895
-            if (empty($persistent_admin_notices)) {
896
-                add_option('ee_pers_admin_notices', array(), '', 'no');
897
-            }
898
-            $pan_name = sanitize_key($pan_name);
899
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
900
-                $persistent_admin_notices[$pan_name] = $pan_message;
901
-                update_option('ee_pers_admin_notices', $persistent_admin_notices);
902
-            }
903
-        }
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     *    dismiss_persistent_admin_notice
910
-     *
911
-     * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
912
-     * @param bool          $purge
913
-     * @param bool          $return_immediately
914
-     * @return        void
915
-     */
916
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
917
-    {
918
-        $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
919
-            ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
920
-        if (! empty($pan_name)) {
921
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
922
-            // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
923
-            if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
924
-                // completely delete nag notice, or just NULL message so that it can NOT be added again ?
925
-                if ($purge) {
926
-                    unset($persistent_admin_notices[$pan_name]);
927
-                } else {
928
-                    $persistent_admin_notices[$pan_name] = null;
929
-                }
930
-                if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
931
-                    EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
932
-                        'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
933
-                }
934
-            }
935
-        }
936
-        if ($return_immediately) {
937
-            return;
938
-        }
939
-        if (EE_Registry::instance()->REQ->ajax) {
940
-            // grab any notices and concatenate into string
941
-            echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
942
-            exit();
943
-        }
944
-        // save errors to a transient to be displayed on next request (after redirect)
945
-        EE_Error::get_notices(false, true);
946
-        $return_url = EE_Registry::instance()->REQ->is_set('return_url')
947
-            ? EE_Registry::instance()->REQ->get('return_url') : '';
948
-        wp_safe_redirect(urldecode($return_url));
949
-    }
950
-
951
-
952
-
953
-    /**
954
-     * display_persistent_admin_notices
955
-     *
956
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
957
-     * @param  string $pan_message the message to be stored persistently until dismissed
958
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
959
-     * @return string
960
-     */
961
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
962
-    {
963
-        if (! empty($pan_name) && ! empty($pan_message)) {
964
-            $args = array(
965
-                'nag_notice'    => $pan_name,
966
-                'return_url'    => urlencode($return_url),
967
-                'ajax_url'      => WP_AJAX_URL,
968
-                'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
969
-                    'event_espresso'),
970
-            );
971
-            wp_localize_script('espresso_core', 'ee_dismiss', $args);
972
-            return '
470
+		$output .= self::_print_scripts(true);
471
+		if (defined('DOING_AJAX')) {
472
+			echo wp_json_encode(array('error' => $output));
473
+			exit();
474
+		}
475
+		echo $output;
476
+		die();
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 *    generate string from exception trace args
483
+	 *
484
+	 * @param array $arguments
485
+	 * @param bool  $array
486
+	 * @return string
487
+	 */
488
+	private function _convert_args_to_string($arguments = array(), $array = false)
489
+	{
490
+		$arg_string = '';
491
+		if (! empty($arguments)) {
492
+			$args = array();
493
+			foreach ($arguments as $arg) {
494
+				if (! empty($arg)) {
495
+					if (is_string($arg)) {
496
+						$args[] = " '" . $arg . "'";
497
+					} elseif (is_array($arg)) {
498
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
+					} elseif ($arg === null) {
500
+						$args[] = ' NULL';
501
+					} elseif (is_bool($arg)) {
502
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
503
+					} elseif (is_object($arg)) {
504
+						$args[] = ' OBJECT ' . get_class($arg);
505
+					} elseif (is_resource($arg)) {
506
+						$args[] = get_resource_type($arg);
507
+					} else {
508
+						$args[] = $arg;
509
+					}
510
+				}
511
+			}
512
+			$arg_string = implode(', ', $args);
513
+		}
514
+		if ($array) {
515
+			$arg_string .= ' )';
516
+		}
517
+		return $arg_string;
518
+	}
519
+
520
+
521
+
522
+	/**
523
+	 *    add error message
524
+	 *
525
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
+	 *                            separate messages for user || dev
527
+	 * @param        string $file the file that the error occurred in - just use __FILE__
528
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
+	 * @param        string $line the line number where the error occurred - just use __LINE__
530
+	 * @return        void
531
+	 */
532
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
+	{
534
+		self::_add_notice('errors', $msg, $file, $func, $line);
535
+		self::$_error_count++;
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
+	 * adds an error
543
+	 *
544
+	 * @param string $msg
545
+	 * @param string $file
546
+	 * @param string $func
547
+	 * @param string $line
548
+	 * @throws EE_Error
549
+	 */
550
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
+	{
552
+		if (WP_DEBUG) {
553
+			throw new EE_Error($msg);
554
+		}
555
+		EE_Error::add_error($msg, $file, $func, $line);
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 *    add success message
562
+	 *
563
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
+	 *                            separate messages for user || dev
565
+	 * @param        string $file the file that the error occurred in - just use __FILE__
566
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
+	 * @param        string $line the line number where the error occurred - just use __LINE__
568
+	 * @return        void
569
+	 */
570
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
+	{
572
+		self::_add_notice('success', $msg, $file, $func, $line);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 *    add attention message
579
+	 *
580
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
+	 *                            separate messages for user || dev
582
+	 * @param        string $file the file that the error occurred in - just use __FILE__
583
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
+	 * @param        string $line the line number where the error occurred - just use __LINE__
585
+	 * @return        void
586
+	 */
587
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
+	{
589
+		self::_add_notice('attention', $msg, $file, $func, $line);
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 *    add success message
596
+	 *
597
+	 * @param        string $type whether the message is for a success or error notification
598
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
+	 *                            separate messages for user || dev
600
+	 * @param        string $file the file that the error occurred in - just use __FILE__
601
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
+	 * @param        string $line the line number where the error occurred - just use __LINE__
603
+	 * @return        void
604
+	 */
605
+	private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
+	{
607
+		if (empty($msg)) {
608
+			EE_Error::doing_it_wrong(
609
+				'EE_Error::add_' . $type . '()',
610
+				sprintf(
611
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612
+						'event_espresso'),
613
+					$type,
614
+					$file,
615
+					$line
616
+				),
617
+				EVENT_ESPRESSO_VERSION
618
+			);
619
+		}
620
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
+			EE_Error::doing_it_wrong(
622
+				'EE_Error::add_error()',
623
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
+					'event_espresso'),
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+		}
628
+		// get separate user and developer messages if they exist
629
+		$msg = explode('||', $msg);
630
+		$user_msg = $msg[0];
631
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
+		/**
633
+		 * Do an action so other code can be triggered when a notice is created
634
+		 *
635
+		 * @param string $type     can be 'errors', 'attention', or 'success'
636
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
637
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
638
+		 * @param string $file     file where error was generated
639
+		 * @param string $func     function where error was generated
640
+		 * @param string $line     line where error was generated
641
+		 */
642
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
644
+		// add notice if message exists
645
+		if (! empty($msg)) {
646
+			// get error code
647
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
648
+			if (WP_DEBUG && $type === 'errors') {
649
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
+			}
651
+			// add notice. Index by code if it's not blank
652
+			if ($notice_code) {
653
+				self::$_espresso_notices[$type][$notice_code] = $msg;
654
+			} else {
655
+				self::$_espresso_notices[$type][] = $msg;
656
+			}
657
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
+		}
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 *    in some case it may be necessary to overwrite the existing success messages
665
+	 *
666
+	 * @return        void
667
+	 */
668
+	public static function overwrite_success()
669
+	{
670
+		self::$_espresso_notices['success'] = false;
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 *    in some case it may be necessary to overwrite the existing attention messages
677
+	 *
678
+	 * @return        void
679
+	 */
680
+	public static function overwrite_attention()
681
+	{
682
+		self::$_espresso_notices['attention'] = false;
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 *    in some case it may be necessary to overwrite the existing error messages
689
+	 *
690
+	 * @return        void
691
+	 */
692
+	public static function overwrite_errors()
693
+	{
694
+		self::$_espresso_notices['errors'] = false;
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 *    reset_notices
701
+	 *
702
+	 * @return void
703
+	 */
704
+	public static function reset_notices()
705
+	{
706
+		self::$_espresso_notices['success'] = false;
707
+		self::$_espresso_notices['attention'] = false;
708
+		self::$_espresso_notices['errors'] = false;
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 *    has_errors
715
+	 *
716
+	 * @return int
717
+	 */
718
+	public static function has_notices()
719
+	{
720
+		$has_notices = 0;
721
+		// check for success messages
722
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
+			: $has_notices;
724
+		// check for attention messages
725
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
+			: $has_notices;
727
+		// check for error messages
728
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
+			: $has_notices;
730
+		return $has_notices;
731
+	}
732
+
733
+
734
+
735
+	/**
736
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
+	 *
738
+	 * @since 4.9.0
739
+	 * @return array
740
+	 */
741
+	public static function get_vanilla_notices()
742
+	{
743
+		return array(
744
+			'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
+				: array(),
747
+			'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
+		);
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 *    compile all error or success messages into one string
755
+	 *
756
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
+	 * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
+	 * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
+	 *                                          - ONLY do this just before redirecting
760
+	 * @param        boolean $remove_empty      whether or not to unset empty messages
761
+	 * @return        array
762
+	 */
763
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
+	{
765
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
+		$success_messages = '';
767
+		$attention_messages = '';
768
+		$error_messages = '';
769
+		$print_scripts = false;
770
+		// either save notices to the db
771
+		if ($save_to_transient) {
772
+			update_option('ee_notices', self::$_espresso_notices);
773
+			return array();
774
+		}
775
+		// grab any notices that have been previously saved
776
+		if ($notices = get_option('ee_notices', false)) {
777
+			foreach ($notices as $type => $notice) {
778
+				if (is_array($notice) && ! empty($notice)) {
779
+					// make sure that existing notice type is an array
780
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
+													  && ! empty(self::$_espresso_notices[$type])
782
+						? self::$_espresso_notices[$type] : array();
783
+					// merge stored notices with any newly created ones
784
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
+					$print_scripts = true;
786
+				}
787
+			}
788
+			// now clear any stored notices
789
+			update_option('ee_notices', false);
790
+		}
791
+		// check for success messages
792
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
+			// combine messages
794
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
+			$print_scripts = true;
796
+		}
797
+		// check for attention messages
798
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
+			// combine messages
800
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
+			$print_scripts = true;
802
+		}
803
+		// check for error messages
804
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
806
+				? __('The following errors have occurred:<br />', 'event_espresso')
807
+				: __('An error has occurred:<br />', 'event_espresso');
808
+			// combine messages
809
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
+			$print_scripts = true;
811
+		}
812
+		if ($format_output) {
813
+			$notices = '<div id="espresso-notices">';
814
+			$close = is_admin() ? ''
815
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
816
+			if ($success_messages !== '') {
817
+				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
818
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
819
+				//showMessage( $success_messages );
820
+				$notices .= '<div id="'
821
+							. $css_id
822
+							. '" class="espresso-notices '
823
+							. $css_class
824
+							. '" style="display:none;"><p>'
825
+							. $success_messages
826
+							. '</p>'
827
+							. $close
828
+							. '</div>';
829
+			}
830
+			if ($attention_messages !== '') {
831
+				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
832
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
833
+				//showMessage( $error_messages, TRUE );
834
+				$notices .= '<div id="'
835
+							. $css_id
836
+							. '" class="espresso-notices '
837
+							. $css_class
838
+							. '" style="display:none;"><p>'
839
+							. $attention_messages
840
+							. '</p>'
841
+							. $close
842
+							. '</div>';
843
+			}
844
+			if ($error_messages !== '') {
845
+				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
846
+				$css_class = is_admin() ? 'error' : 'error fade-away';
847
+				//showMessage( $error_messages, TRUE );
848
+				$notices .= '<div id="'
849
+							. $css_id
850
+							. '" class="espresso-notices '
851
+							. $css_class
852
+							. '" style="display:none;"><p>'
853
+							. $error_messages
854
+							. '</p>'
855
+							. $close
856
+							. '</div>';
857
+			}
858
+			$notices .= '</div>';
859
+		} else {
860
+			$notices = array(
861
+				'success'   => $success_messages,
862
+				'attention' => $attention_messages,
863
+				'errors'    => $error_messages,
864
+			);
865
+			if ($remove_empty) {
866
+				// remove empty notices
867
+				foreach ($notices as $type => $notice) {
868
+					if (empty($notice)) {
869
+						unset($notices[$type]);
870
+					}
871
+				}
872
+			}
873
+		}
874
+		if ($print_scripts) {
875
+			self::_print_scripts();
876
+		}
877
+		return $notices;
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 *    add_persistent_admin_notice
884
+	 *
885
+	 * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
886
+	 * @param        string $pan_message  the message to be stored persistently until dismissed
887
+	 * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
888
+	 * @return        void
889
+	 */
890
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
891
+	{
892
+		if (! empty($pan_name) && ! empty($pan_message)) {
893
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
894
+			//maybe initialize persistent_admin_notices
895
+			if (empty($persistent_admin_notices)) {
896
+				add_option('ee_pers_admin_notices', array(), '', 'no');
897
+			}
898
+			$pan_name = sanitize_key($pan_name);
899
+			if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
900
+				$persistent_admin_notices[$pan_name] = $pan_message;
901
+				update_option('ee_pers_admin_notices', $persistent_admin_notices);
902
+			}
903
+		}
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 *    dismiss_persistent_admin_notice
910
+	 *
911
+	 * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
912
+	 * @param bool          $purge
913
+	 * @param bool          $return_immediately
914
+	 * @return        void
915
+	 */
916
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
917
+	{
918
+		$pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
919
+			? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
920
+		if (! empty($pan_name)) {
921
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
922
+			// check if notice we wish to dismiss is actually in the $persistent_admin_notices array
923
+			if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
924
+				// completely delete nag notice, or just NULL message so that it can NOT be added again ?
925
+				if ($purge) {
926
+					unset($persistent_admin_notices[$pan_name]);
927
+				} else {
928
+					$persistent_admin_notices[$pan_name] = null;
929
+				}
930
+				if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
931
+					EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
932
+						'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
933
+				}
934
+			}
935
+		}
936
+		if ($return_immediately) {
937
+			return;
938
+		}
939
+		if (EE_Registry::instance()->REQ->ajax) {
940
+			// grab any notices and concatenate into string
941
+			echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
942
+			exit();
943
+		}
944
+		// save errors to a transient to be displayed on next request (after redirect)
945
+		EE_Error::get_notices(false, true);
946
+		$return_url = EE_Registry::instance()->REQ->is_set('return_url')
947
+			? EE_Registry::instance()->REQ->get('return_url') : '';
948
+		wp_safe_redirect(urldecode($return_url));
949
+	}
950
+
951
+
952
+
953
+	/**
954
+	 * display_persistent_admin_notices
955
+	 *
956
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
957
+	 * @param  string $pan_message the message to be stored persistently until dismissed
958
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
959
+	 * @return string
960
+	 */
961
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
962
+	{
963
+		if (! empty($pan_name) && ! empty($pan_message)) {
964
+			$args = array(
965
+				'nag_notice'    => $pan_name,
966
+				'return_url'    => urlencode($return_url),
967
+				'ajax_url'      => WP_AJAX_URL,
968
+				'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
969
+					'event_espresso'),
970
+			);
971
+			wp_localize_script('espresso_core', 'ee_dismiss', $args);
972
+			return '
973 973
 			<div id="'
974
-                   . $pan_name
975
-                   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
974
+				   . $pan_name
975
+				   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
976 976
 				<p>'
977
-                   . $pan_message
978
-                   . '</p>
977
+				   . $pan_message
978
+				   . '</p>
979 979
 				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="'
980
-                   . $pan_name
981
-                   . '">
980
+				   . $pan_name
981
+				   . '">
982 982
 					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'
983
-                   . __('Dismiss', 'event_espresso')
984
-                   . '
983
+				   . __('Dismiss', 'event_espresso')
984
+				   . '
985 985
 				</a>
986 986
 				<div style="clear:both;"></div>
987 987
 			</div>';
988
-        }
989
-        return '';
990
-    }
991
-
992
-
993
-
994
-    /**
995
-     *    get_persistent_admin_notices
996
-     *
997
-     * @param string $return_url
998
-     * @return string
999
-     */
1000
-    public static function get_persistent_admin_notices($return_url = '')
1001
-    {
1002
-        $notices = '';
1003
-        // check for persistent admin notices
1004
-        //filter the list though so plugins can notify the admin in a different way if they want
1005
-        $persistent_admin_notices = apply_filters(
1006
-            'FHEE__EE_Error__get_persistent_admin_notices',
1007
-            get_option('ee_pers_admin_notices', false),
1008
-            'ee_pers_admin_notices',
1009
-            $return_url
1010
-        );
1011
-        if ($persistent_admin_notices) {
1012
-            // load scripts
1013
-            wp_register_script(
1014
-                'espresso_core',
1015
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1016
-                array('jquery'),
1017
-                EVENT_ESPRESSO_VERSION,
1018
-                true
1019
-            );
1020
-            wp_register_script(
1021
-                'ee_error_js',
1022
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1023
-                array('espresso_core'),
1024
-                EVENT_ESPRESSO_VERSION,
1025
-                true
1026
-            );
1027
-            wp_enqueue_script('ee_error_js');
1028
-            // and display notices
1029
-            foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1030
-                $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1031
-            }
1032
-        }
1033
-        return $notices;
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     * _print_scripts
1040
-     *
1041
-     * @param    bool $force_print
1042
-     * @return    string
1043
-     */
1044
-    private static function _print_scripts($force_print = false)
1045
-    {
1046
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1047
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1048
-                return '';
1049
-            }
1050
-            if (wp_script_is('ee_error_js', 'registered')) {
1051
-                add_filter('FHEE_load_css', '__return_true');
1052
-                add_filter('FHEE_load_js', '__return_true');
1053
-                wp_enqueue_script('ee_error_js');
1054
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1055
-            }
1056
-        } else {
1057
-            return '
988
+		}
989
+		return '';
990
+	}
991
+
992
+
993
+
994
+	/**
995
+	 *    get_persistent_admin_notices
996
+	 *
997
+	 * @param string $return_url
998
+	 * @return string
999
+	 */
1000
+	public static function get_persistent_admin_notices($return_url = '')
1001
+	{
1002
+		$notices = '';
1003
+		// check for persistent admin notices
1004
+		//filter the list though so plugins can notify the admin in a different way if they want
1005
+		$persistent_admin_notices = apply_filters(
1006
+			'FHEE__EE_Error__get_persistent_admin_notices',
1007
+			get_option('ee_pers_admin_notices', false),
1008
+			'ee_pers_admin_notices',
1009
+			$return_url
1010
+		);
1011
+		if ($persistent_admin_notices) {
1012
+			// load scripts
1013
+			wp_register_script(
1014
+				'espresso_core',
1015
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1016
+				array('jquery'),
1017
+				EVENT_ESPRESSO_VERSION,
1018
+				true
1019
+			);
1020
+			wp_register_script(
1021
+				'ee_error_js',
1022
+				EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1023
+				array('espresso_core'),
1024
+				EVENT_ESPRESSO_VERSION,
1025
+				true
1026
+			);
1027
+			wp_enqueue_script('ee_error_js');
1028
+			// and display notices
1029
+			foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1030
+				$notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1031
+			}
1032
+		}
1033
+		return $notices;
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 * _print_scripts
1040
+	 *
1041
+	 * @param    bool $force_print
1042
+	 * @return    string
1043
+	 */
1044
+	private static function _print_scripts($force_print = false)
1045
+	{
1046
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1047
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1048
+				return '';
1049
+			}
1050
+			if (wp_script_is('ee_error_js', 'registered')) {
1051
+				add_filter('FHEE_load_css', '__return_true');
1052
+				add_filter('FHEE_load_js', '__return_true');
1053
+				wp_enqueue_script('ee_error_js');
1054
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1055
+			}
1056
+		} else {
1057
+			return '
1058 1058
 <script>
1059 1059
 /* <![CDATA[ */
1060 1060
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1064,143 +1064,143 @@  discard block
 block discarded – undo
1064 1064
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1065 1065
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066 1066
 ';
1067
-        }
1068
-        return '';
1069
-    }
1070
-
1071
-
1072
-
1073
-    /**
1074
-     *    enqueue_error_scripts
1075
-     *
1076
-     * @return        void
1077
-     */
1078
-    public static function enqueue_error_scripts()
1079
-    {
1080
-        self::_print_scripts();
1081
-    }
1082
-
1083
-
1084
-
1085
-    /**
1086
-     *    create error code from filepath, function name,
1087
-     *    and line number where exception or error was thrown
1088
-     *
1089
-     * @param string $file
1090
-     * @param string $func
1091
-     * @param string $line
1092
-     * @return string
1093
-     */
1094
-    public static function generate_error_code($file = '', $func = '', $line = '')
1095
-    {
1096
-        $file = explode('.', basename($file));
1097
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1098
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1099
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1100
-        return $error_code;
1101
-    }
1102
-
1103
-
1104
-
1105
-    /**
1106
-     *    write exception details to log file
1107
-     *
1108
-     * @param int   $time
1109
-     * @param array $ex
1110
-     * @param bool  $clear
1111
-     * @return void
1112
-     */
1113
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1114
-    {
1115
-        if (empty($ex)) {
1116
-            return;
1117
-        }
1118
-        if (! $time) {
1119
-            $time = time();
1120
-        }
1121
-        $exception_log = '----------------------------------------------------------------------------------------'
1122
-                         . PHP_EOL;
1123
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1124
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1125
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1126
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1127
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1128
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1129
-        $exception_log .= $ex['string'] . PHP_EOL;
1130
-        $exception_log .= '----------------------------------------------------------------------------------------'
1131
-                          . PHP_EOL;
1132
-        try {
1133
-            EEH_File::ensure_file_exists_and_is_writable(
1134
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1135
-            );
1136
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1137
-            if (! $clear) {
1138
-                //get existing log file and append new log info
1139
-                $exception_log = EEH_File::get_file_contents(
1140
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1141
-                ) . $exception_log;
1142
-            }
1143
-            EEH_File::write_to_file(
1144
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1145
-                $exception_log
1146
-            );
1147
-        } catch (EE_Error $e) {
1148
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1149
-                'event_espresso'), $e->getMessage()));
1150
-            return;
1151
-        }
1152
-    }
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1158
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1159
-     * but the code execution is done in a manner that could lead to unexpected results
1160
-     * (i.e. running to early, or too late in WP or EE loading process).
1161
-     * A good test for knowing whether to use this method is:
1162
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1163
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1164
-     * 2. If this is loaded before something else, it won't break anything,
1165
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1166
-     *
1167
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1168
-     * @param string $function      The function that was called
1169
-     * @param string $message       A message explaining what has been done incorrectly
1170
-     * @param string $version       The version of Event Espresso where the error was added
1171
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1172
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1173
-     *                              but not have any notices appear until a later version. This allows developers
1174
-     *                              extra time to update their code before notices appear.
1175
-     * @param int    $error_type
1176
-     */
1177
-    public static function doing_it_wrong(
1178
-        $function,
1179
-        $message,
1180
-        $version,
1181
-        $applies_when = '',
1182
-        $error_type = null
1183
-    ) {
1184
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1185
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1186
-        }
1187
-    }
1188
-
1189
-
1190
-
1191
-    /**
1192
-     * Like get_notices, but returns an array of all the notices of the given type.
1193
-     *
1194
-     * @return array {
1195
-     * @type array $success   all the success messages
1196
-     * @type array $errors    all the error messages
1197
-     * @type array $attention all the attention messages
1198
-     * }
1199
-     */
1200
-    public static function get_raw_notices()
1201
-    {
1202
-        return self::$_espresso_notices;
1203
-    }
1067
+		}
1068
+		return '';
1069
+	}
1070
+
1071
+
1072
+
1073
+	/**
1074
+	 *    enqueue_error_scripts
1075
+	 *
1076
+	 * @return        void
1077
+	 */
1078
+	public static function enqueue_error_scripts()
1079
+	{
1080
+		self::_print_scripts();
1081
+	}
1082
+
1083
+
1084
+
1085
+	/**
1086
+	 *    create error code from filepath, function name,
1087
+	 *    and line number where exception or error was thrown
1088
+	 *
1089
+	 * @param string $file
1090
+	 * @param string $func
1091
+	 * @param string $line
1092
+	 * @return string
1093
+	 */
1094
+	public static function generate_error_code($file = '', $func = '', $line = '')
1095
+	{
1096
+		$file = explode('.', basename($file));
1097
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1098
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1099
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1100
+		return $error_code;
1101
+	}
1102
+
1103
+
1104
+
1105
+	/**
1106
+	 *    write exception details to log file
1107
+	 *
1108
+	 * @param int   $time
1109
+	 * @param array $ex
1110
+	 * @param bool  $clear
1111
+	 * @return void
1112
+	 */
1113
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1114
+	{
1115
+		if (empty($ex)) {
1116
+			return;
1117
+		}
1118
+		if (! $time) {
1119
+			$time = time();
1120
+		}
1121
+		$exception_log = '----------------------------------------------------------------------------------------'
1122
+						 . PHP_EOL;
1123
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1124
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1125
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1126
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1127
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1128
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1129
+		$exception_log .= $ex['string'] . PHP_EOL;
1130
+		$exception_log .= '----------------------------------------------------------------------------------------'
1131
+						  . PHP_EOL;
1132
+		try {
1133
+			EEH_File::ensure_file_exists_and_is_writable(
1134
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1135
+			);
1136
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1137
+			if (! $clear) {
1138
+				//get existing log file and append new log info
1139
+				$exception_log = EEH_File::get_file_contents(
1140
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1141
+				) . $exception_log;
1142
+			}
1143
+			EEH_File::write_to_file(
1144
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1145
+				$exception_log
1146
+			);
1147
+		} catch (EE_Error $e) {
1148
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1149
+				'event_espresso'), $e->getMessage()));
1150
+			return;
1151
+		}
1152
+	}
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1158
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1159
+	 * but the code execution is done in a manner that could lead to unexpected results
1160
+	 * (i.e. running to early, or too late in WP or EE loading process).
1161
+	 * A good test for knowing whether to use this method is:
1162
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1163
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1164
+	 * 2. If this is loaded before something else, it won't break anything,
1165
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1166
+	 *
1167
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1168
+	 * @param string $function      The function that was called
1169
+	 * @param string $message       A message explaining what has been done incorrectly
1170
+	 * @param string $version       The version of Event Espresso where the error was added
1171
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1172
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1173
+	 *                              but not have any notices appear until a later version. This allows developers
1174
+	 *                              extra time to update their code before notices appear.
1175
+	 * @param int    $error_type
1176
+	 */
1177
+	public static function doing_it_wrong(
1178
+		$function,
1179
+		$message,
1180
+		$version,
1181
+		$applies_when = '',
1182
+		$error_type = null
1183
+	) {
1184
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1185
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1186
+		}
1187
+	}
1188
+
1189
+
1190
+
1191
+	/**
1192
+	 * Like get_notices, but returns an array of all the notices of the given type.
1193
+	 *
1194
+	 * @return array {
1195
+	 * @type array $success   all the success messages
1196
+	 * @type array $errors    all the error messages
1197
+	 * @type array $attention all the attention messages
1198
+	 * }
1199
+	 */
1200
+	public static function get_raw_notices()
1201
+	{
1202
+		return self::$_espresso_notices;
1203
+	}
1204 1204
 
1205 1205
 
1206 1206
 
@@ -1216,27 +1216,27 @@  discard block
 block discarded – undo
1216 1216
  */
1217 1217
 function espresso_error_enqueue_scripts()
1218 1218
 {
1219
-    // js for error handling
1220
-    wp_register_script(
1221
-        'espresso_core',
1222
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1223
-        array('jquery'),
1224
-        EVENT_ESPRESSO_VERSION,
1225
-        false
1226
-    );
1227
-    wp_register_script(
1228
-        'ee_error_js',
1229
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1230
-        array('espresso_core'),
1231
-        EVENT_ESPRESSO_VERSION,
1232
-        false
1233
-    );
1219
+	// js for error handling
1220
+	wp_register_script(
1221
+		'espresso_core',
1222
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1223
+		array('jquery'),
1224
+		EVENT_ESPRESSO_VERSION,
1225
+		false
1226
+	);
1227
+	wp_register_script(
1228
+		'ee_error_js',
1229
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1230
+		array('espresso_core'),
1231
+		EVENT_ESPRESSO_VERSION,
1232
+		false
1233
+	);
1234 1234
 }
1235 1235
 
1236 1236
 if (is_admin()) {
1237
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1237
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1238 1238
 } else {
1239
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1239
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1240 1240
 }
1241 1241
 
1242 1242
 
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Venue_Shortcodes.lib.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 
165 165
 
166 166
         //If there is no event objecdt by now then get out.
167
-        if (! $this->_event instanceof EE_Event) {
167
+        if ( ! $this->_event instanceof EE_Event) {
168 168
             return '';
169 169
         }
170 170
 
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
                 break;
191 191
 
192 192
             case 'image':
193
-                return '<img src="' . $venue->feature_image_url(array(200, 200,))
194
-                       . '" alt="' . sprintf(
193
+                return '<img src="'.$venue->feature_image_url(array(200, 200,))
194
+                       . '" alt="'.sprintf(
195 195
                            esc_attr__('%s Feature Image', 'event_espresso'),
196 196
                            $venue->get('VNU_name')
197
-                       ) . '" />';
197
+                       ).'" />';
198 198
                 break;
199 199
 
200 200
             case 'phone':
Please login to merge, or discard this patch.
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -16,257 +16,257 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Will hold the EE_Event if available
21
-     *
22
-     * @var EE_Event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * Initialize properties
29
-     */
30
-    protected function _init_props()
31
-    {
32
-        $this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
33
-        $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
34
-        $this->_shortcodes = array(
35
-            '[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
36
-            '[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
37
-            '[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
38
-            '[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
39
-            '[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
40
-            '[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
41
-            '[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
42
-            '[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
43
-            '[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
44
-            '[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
45
-            '[VENUE_FORMATTED_ADDRESS]' => esc_html__(
46
-                'This just outputs the venue address in a semantic address format.',
47
-                'event_espresso'
48
-            ),
49
-            '[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
50
-            '[GOOGLE_MAP_URL]'          => esc_html__(
51
-                'URL for the google map associated with the venue.',
52
-                'event_espresso'
53
-            ),
54
-            '[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
55
-            '[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
56
-        );
57
-    }
58
-
59
-
60
-    /**
61
-     * Parse incoming shortcode
62
-     * @param string $shortcode
63
-     * @return string
64
-     */
65
-    protected function _parser($shortcode)
66
-    {
67
-
68
-        switch ($shortcode) {
69
-            case '[VENUE_TITLE]':
70
-                return $this->_venue('title');
71
-                break;
72
-
73
-            case '[VENUE_DESCRIPTION]':
74
-                return $this->_venue('description');
75
-                break;
76
-
77
-            case '[VENUE_URL]':
78
-                return $this->_venue('url');
79
-                break;
80
-
81
-            case '[VENUE_IMAGE]':
82
-                return $this->_venue('image');
83
-                break;
84
-
85
-            case '[VENUE_PHONE]':
86
-                return $this->_venue('phone');
87
-                break;
88
-
89
-            case '[VENUE_ADDRESS]':
90
-                return $this->_venue('address');
91
-                break;
92
-
93
-            case '[VENUE_ADDRESS2]':
94
-                return $this->_venue('address2');
95
-                break;
96
-
97
-            case '[VENUE_CITY]':
98
-                return $this->_venue('city');
99
-                break;
100
-
101
-            case '[VENUE_COUNTRY]':
102
-                return $this->_venue('country');
103
-                break;
104
-
105
-            case '[VENUE_STATE]':
106
-                return $this->_venue('state');
107
-                break;
108
-
109
-            case '[VENUE_ZIP]':
110
-                return $this->_venue('zip');
111
-                break;
112
-
113
-            case '[VENUE_FORMATTED_ADDRESS]':
114
-                return $this->_venue('formatted_address');
115
-                break;
116
-
117
-            case '[GOOGLE_MAP_URL]':
118
-                return $this->_venue('gmap_url');
119
-                break;
120
-
121
-            case '[GOOGLE_MAP_LINK]':
122
-                return $this->_venue('gmap_link');
123
-                break;
124
-
125
-            case '[GOOGLE_MAP_IMAGE]':
126
-                return $this->_venue('gmap_link_img');
127
-                break;
128
-
129
-        }
130
-    }
131
-
132
-
133
-    /**
134
-     * This retrieves the specified venue information
135
-     *
136
-     * @param string $field  What Venue field to retrieve
137
-     * @return string What was retrieved!
138
-     * @throws EE_Error
139
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
140
-     */
141
-    private function _venue($field)
142
-    {
143
-        //we need the EE_Event object to get the venue.
144
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
145
-
146
-        //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
147
-        if (empty($this->_event)) {
148
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
149
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
150
-
151
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null;
152
-
153
-            //if still empty do we have a ticket data item?
154
-            $this->_event = empty($this->_event)
155
-                            && $this->_data instanceof EE_Ticket
156
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
157
-                ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
158
-                : $this->_event;
159
-
160
-            //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that.
161
-            $event        = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array();
162
-            $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event;
163
-        }
164
-
165
-
166
-        //If there is no event objecdt by now then get out.
167
-        if (! $this->_event instanceof EE_Event) {
168
-            return '';
169
-        }
170
-
171
-        /** @var EE_Venue $venue */
172
-        $venue = $this->_event->get_first_related('Venue');
173
-
174
-        if (empty($venue)) {
175
-            return '';
176
-        } //no venue so get out.
177
-
178
-        switch ($field) {
179
-            case 'title':
180
-                return $venue->get('VNU_name');
181
-                break;
182
-
183
-            case 'description':
184
-                return $venue->get('VNU_desc');
185
-                break;
186
-
187
-            case 'url':
188
-                $url = $venue->get('VNU_url');
189
-                return empty($url) ? $venue->get_permalink() : $url;
190
-                break;
191
-
192
-            case 'image':
193
-                return '<img src="' . $venue->feature_image_url(array(200, 200,))
194
-                       . '" alt="' . sprintf(
195
-                           esc_attr__('%s Feature Image', 'event_espresso'),
196
-                           $venue->get('VNU_name')
197
-                       ) . '" />';
198
-                break;
199
-
200
-            case 'phone':
201
-                return $venue->get('VNU_phone');
202
-                break;
203
-
204
-            case 'address':
205
-                return $venue->get('VNU_address');
206
-                break;
207
-
208
-            case 'address2':
209
-                return $venue->get('VNU_address2');
210
-                break;
211
-
212
-            case 'city':
213
-                return $venue->get('VNU_city');
214
-                break;
215
-
216
-            case 'state':
217
-                $state = $venue->state_obj();
218
-                return is_object($state) ? $state->get('STA_name') : '';
219
-                break;
220
-
221
-            case 'country':
222
-                $country = $venue->country_obj();
223
-                return is_object($country) ? $country->get('CNT_name') : '';
224
-                break;
225
-
226
-            case 'zip':
227
-                return $venue->get('VNU_zip');
228
-                break;
229
-
230
-            case 'formatted_address':
231
-                return EEH_Address::format($venue);
232
-                break;
233
-
234
-            case 'gmap_link':
235
-            case 'gmap_url':
236
-            case 'gmap_link_img':
237
-                $atts = $this->get_map_attributes($venue, $field);
238
-                return EEH_Maps::google_map_link($atts);
239
-                break;
240
-        }
241
-        return '';
242
-    }
243
-
244
-
245
-    /**
246
-     * Generates the attributes for retrieving a google_map artifact.
247
-     * @param EE_Venue $venue
248
-     * @param string   $field
249
-     * @return array
250
-     * @throws EE_Error
251
-     */
252
-    protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
253
-    {
254
-        $state   = $venue->state_obj();
255
-        $country = $venue->country_obj();
256
-        $atts    = array(
257
-            'id'      => $venue->ID(),
258
-            'address' => $venue->get('VNU_address'),
259
-            'city'    => $venue->get('VNU_city'),
260
-            'state'   => is_object($state) ? $state->get('STA_name') : '',
261
-            'zip'     => $venue->get('VNU_zip'),
262
-            'country' => is_object($country) ? $country->get('CNT_name') : '',
263
-            'type'    => $field === 'gmap_link' ? 'url' : 'map',
264
-            'map_w'   => 200,
265
-            'map_h'   => 200,
266
-        );
267
-        if ($field === 'gmap_url') {
268
-            $atts['type'] = 'url_only';
269
-        }
270
-        return $atts;
271
-    }
19
+	/**
20
+	 * Will hold the EE_Event if available
21
+	 *
22
+	 * @var EE_Event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * Initialize properties
29
+	 */
30
+	protected function _init_props()
31
+	{
32
+		$this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
33
+		$this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
34
+		$this->_shortcodes = array(
35
+			'[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
36
+			'[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
37
+			'[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
38
+			'[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
39
+			'[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
40
+			'[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
41
+			'[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
42
+			'[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
43
+			'[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
44
+			'[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
45
+			'[VENUE_FORMATTED_ADDRESS]' => esc_html__(
46
+				'This just outputs the venue address in a semantic address format.',
47
+				'event_espresso'
48
+			),
49
+			'[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
50
+			'[GOOGLE_MAP_URL]'          => esc_html__(
51
+				'URL for the google map associated with the venue.',
52
+				'event_espresso'
53
+			),
54
+			'[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
55
+			'[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
56
+		);
57
+	}
58
+
59
+
60
+	/**
61
+	 * Parse incoming shortcode
62
+	 * @param string $shortcode
63
+	 * @return string
64
+	 */
65
+	protected function _parser($shortcode)
66
+	{
67
+
68
+		switch ($shortcode) {
69
+			case '[VENUE_TITLE]':
70
+				return $this->_venue('title');
71
+				break;
72
+
73
+			case '[VENUE_DESCRIPTION]':
74
+				return $this->_venue('description');
75
+				break;
76
+
77
+			case '[VENUE_URL]':
78
+				return $this->_venue('url');
79
+				break;
80
+
81
+			case '[VENUE_IMAGE]':
82
+				return $this->_venue('image');
83
+				break;
84
+
85
+			case '[VENUE_PHONE]':
86
+				return $this->_venue('phone');
87
+				break;
88
+
89
+			case '[VENUE_ADDRESS]':
90
+				return $this->_venue('address');
91
+				break;
92
+
93
+			case '[VENUE_ADDRESS2]':
94
+				return $this->_venue('address2');
95
+				break;
96
+
97
+			case '[VENUE_CITY]':
98
+				return $this->_venue('city');
99
+				break;
100
+
101
+			case '[VENUE_COUNTRY]':
102
+				return $this->_venue('country');
103
+				break;
104
+
105
+			case '[VENUE_STATE]':
106
+				return $this->_venue('state');
107
+				break;
108
+
109
+			case '[VENUE_ZIP]':
110
+				return $this->_venue('zip');
111
+				break;
112
+
113
+			case '[VENUE_FORMATTED_ADDRESS]':
114
+				return $this->_venue('formatted_address');
115
+				break;
116
+
117
+			case '[GOOGLE_MAP_URL]':
118
+				return $this->_venue('gmap_url');
119
+				break;
120
+
121
+			case '[GOOGLE_MAP_LINK]':
122
+				return $this->_venue('gmap_link');
123
+				break;
124
+
125
+			case '[GOOGLE_MAP_IMAGE]':
126
+				return $this->_venue('gmap_link_img');
127
+				break;
128
+
129
+		}
130
+	}
131
+
132
+
133
+	/**
134
+	 * This retrieves the specified venue information
135
+	 *
136
+	 * @param string $field  What Venue field to retrieve
137
+	 * @return string What was retrieved!
138
+	 * @throws EE_Error
139
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
140
+	 */
141
+	private function _venue($field)
142
+	{
143
+		//we need the EE_Event object to get the venue.
144
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
145
+
146
+		//if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
147
+		if (empty($this->_event)) {
148
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
149
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
150
+
151
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null;
152
+
153
+			//if still empty do we have a ticket data item?
154
+			$this->_event = empty($this->_event)
155
+							&& $this->_data instanceof EE_Ticket
156
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
157
+				? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
158
+				: $this->_event;
159
+
160
+			//if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that.
161
+			$event        = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array();
162
+			$this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event;
163
+		}
164
+
165
+
166
+		//If there is no event objecdt by now then get out.
167
+		if (! $this->_event instanceof EE_Event) {
168
+			return '';
169
+		}
170
+
171
+		/** @var EE_Venue $venue */
172
+		$venue = $this->_event->get_first_related('Venue');
173
+
174
+		if (empty($venue)) {
175
+			return '';
176
+		} //no venue so get out.
177
+
178
+		switch ($field) {
179
+			case 'title':
180
+				return $venue->get('VNU_name');
181
+				break;
182
+
183
+			case 'description':
184
+				return $venue->get('VNU_desc');
185
+				break;
186
+
187
+			case 'url':
188
+				$url = $venue->get('VNU_url');
189
+				return empty($url) ? $venue->get_permalink() : $url;
190
+				break;
191
+
192
+			case 'image':
193
+				return '<img src="' . $venue->feature_image_url(array(200, 200,))
194
+					   . '" alt="' . sprintf(
195
+						   esc_attr__('%s Feature Image', 'event_espresso'),
196
+						   $venue->get('VNU_name')
197
+					   ) . '" />';
198
+				break;
199
+
200
+			case 'phone':
201
+				return $venue->get('VNU_phone');
202
+				break;
203
+
204
+			case 'address':
205
+				return $venue->get('VNU_address');
206
+				break;
207
+
208
+			case 'address2':
209
+				return $venue->get('VNU_address2');
210
+				break;
211
+
212
+			case 'city':
213
+				return $venue->get('VNU_city');
214
+				break;
215
+
216
+			case 'state':
217
+				$state = $venue->state_obj();
218
+				return is_object($state) ? $state->get('STA_name') : '';
219
+				break;
220
+
221
+			case 'country':
222
+				$country = $venue->country_obj();
223
+				return is_object($country) ? $country->get('CNT_name') : '';
224
+				break;
225
+
226
+			case 'zip':
227
+				return $venue->get('VNU_zip');
228
+				break;
229
+
230
+			case 'formatted_address':
231
+				return EEH_Address::format($venue);
232
+				break;
233
+
234
+			case 'gmap_link':
235
+			case 'gmap_url':
236
+			case 'gmap_link_img':
237
+				$atts = $this->get_map_attributes($venue, $field);
238
+				return EEH_Maps::google_map_link($atts);
239
+				break;
240
+		}
241
+		return '';
242
+	}
243
+
244
+
245
+	/**
246
+	 * Generates the attributes for retrieving a google_map artifact.
247
+	 * @param EE_Venue $venue
248
+	 * @param string   $field
249
+	 * @return array
250
+	 * @throws EE_Error
251
+	 */
252
+	protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
253
+	{
254
+		$state   = $venue->state_obj();
255
+		$country = $venue->country_obj();
256
+		$atts    = array(
257
+			'id'      => $venue->ID(),
258
+			'address' => $venue->get('VNU_address'),
259
+			'city'    => $venue->get('VNU_city'),
260
+			'state'   => is_object($state) ? $state->get('STA_name') : '',
261
+			'zip'     => $venue->get('VNU_zip'),
262
+			'country' => is_object($country) ? $country->get('CNT_name') : '',
263
+			'type'    => $field === 'gmap_link' ? 'url' : 'map',
264
+			'map_w'   => 200,
265
+			'map_h'   => 200,
266
+		);
267
+		if ($field === 'gmap_url') {
268
+			$atts['type'] = 'url_only';
269
+		}
270
+		return $atts;
271
+	}
272 272
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Maps.helper.php 2 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -14,176 +14,176 @@
 block discarded – undo
14 14
 class EEH_Maps
15 15
 {
16 16
 
17
-    // array of map settings
18
-    public static $gmap_vars = array();
19
-
20
-
21
-    /**
22
-     * google_map - creates a Google Map Link
23
-     *
24
-     * @param  array $ee_gmaps_opts array of attributes required for the map link generation
25
-     * @return string (link to map!)
26
-     */
27
-    public static function google_map($ee_gmaps_opts)
28
-    {
29
-
30
-        $ee_map_width        = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300';
31
-        $ee_map_height       = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185';
32
-        $ee_map_zoom         = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12';
33
-        $ee_map_nav_display  = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
34
-        $ee_map_nav_size     = ! empty($ee_gmaps_opts['ee_map_nav_size'])
35
-            ? $ee_gmaps_opts['ee_map_nav_size']
36
-            : 'default';
37
-        $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
38
-            ? $ee_gmaps_opts['ee_map_type_control']
39
-            : 'default';
40
-        $static_url          = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false;
41
-
42
-        if (! empty($ee_gmaps_opts['ee_map_align'])) {
43
-            switch ($ee_gmaps_opts['ee_map_align']) {
44
-                case "left":
45
-                    $map_align = 'ee-gmap-align-left left';
46
-                    break;
47
-                case "right":
48
-                    $map_align = 'ee-gmap-align-right right';
49
-                    break;
50
-                case "center":
51
-                    $map_align = 'ee-gmap-align-center center';
52
-                    break;
53
-                case "none":
54
-                default:
55
-                    $map_align = 'ee-gmap-align-none';
56
-            }
57
-        } else {
58
-            $map_align = 'ee-gmap-align-none';
59
-        }
60
-
61
-
62
-        // Determine whether user has set a hardoded url to use and
63
-        // if so display a Google static iframe map else run V3 api
64
-        if ($static_url) {
65
-            $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">';
66
-            $html .= '<iframe src="' . $static_url . '&output=embed"'
67
-                . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"'
68
-                . ' frameborder="0" scrolling="no">';
69
-            $html .= '</iframe>';
70
-            $html .= '<a href="' . $static_url . '">View Large map</a>';
71
-            $html .= '</div>';
72
-            return $html;
73
-
74
-        } else {
75
-            EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array(
76
-                'map_ID'              => $ee_gmaps_opts['map_ID'],
77
-                'ee_map_zoom'         => $ee_map_zoom,
78
-                'ee_map_nav_display'  => $ee_map_nav_display,
79
-                'ee_map_nav_size'     => $ee_map_nav_size,
80
-                'ee_map_type_control' => $ee_map_type_control,
81
-                'location'            => $ee_gmaps_opts['location'],
82
-            );
83
-
84
-            $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
85
-            $html = '<div class="ee-gmap-wrapper ' . $map_align . '">'
86
-                    . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"'
87
-                    . ' style="' . $style . '"></div>'
88
-                    . '</div>';
89
-
90
-            wp_enqueue_script('gmap_api');
91
-            wp_enqueue_script('ee_gmap');
92
-            add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script'));
93
-
94
-            return $html;
95
-        } // end auto map or static url map check
96
-    }
97
-
98
-
99
-    /**
100
-     * enqueue_script
101
-     *
102
-     * @return void
103
-     */
104
-    public static function footer_enqueue_script()
105
-    {
106
-        wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
107
-    }
108
-
109
-
110
-    /**
111
-     * registers scripts for maps
112
-     */
113
-    public static function espresso_google_map_js()
114
-    {
115
-        $api_url = sprintf(
116
-            "https://maps.googleapis.com/maps/api/js?key=%s",
117
-            apply_filters(
118
-                'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
119
-                EE_Registry::instance()->CFG->map_settings->google_map_api_key
120
-            )
121
-        );
122
-        wp_register_script('gmap_api', $api_url, array('jquery'), null, true);
123
-        wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
124
-    }
125
-
126
-    /**
127
-     * creates a Google Map Link
128
-     *
129
-     * @param  array $atts array of attributes required for the map link generation
130
-     * @return string (link to map!)
131
-     */
132
-    public static function google_map_link($atts)
133
-    {
134
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
135
-        extract($atts);
136
-        /** @var string $address */
137
-        /** @var string $city */
138
-        /** @var string $state */
139
-        /** @var string $zip */
140
-        /** @var string $country */
141
-        $address         = "{$address}";
142
-        $city            = "{$city}";
143
-        $state           = "{$state}";
144
-        $zip             = "{$zip}";
145
-        $country         = "{$country}";
146
-        $text            = isset($text) ? "{$text}" : "";
147
-        $type            = isset($type) ? "{$type}" : "";
148
-        $map_w           = isset($map_w) ? "{$map_w}" : 400;
149
-        $map_h           = isset($map_h) ? "{$map_h}" : 400;
150
-        $id              = isset($id) ? $id : 'not_set';
151
-        $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
152
-
153
-        $address_string = ($address != '' ? $address : '')
154
-                          . ($city != '' ? ',' . $city : '')
155
-                          . ($state != '' ? ',' . $state : '')
156
-                          . ($zip != '' ? ',' . $zip : '')
157
-                          . ($country != '' ? ',' . $country : '');
158
-
159
-        $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string));
160
-
161
-        switch ($type) {
162
-            case 'text':
163
-            default:
164
-                $text = $text == '' ? __('Map and Directions', 'event_espresso') : $text;
165
-                break;
166
-
167
-            case 'url_only':
168
-            case 'url':
169
-                $text = $google_map;
170
-                break;
171
-
172
-            case 'map':
173
-                $scheme = is_ssl() ? 'https://' : 'http://';
174
-
175
-                $api_key = apply_filters(
176
-                    'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
177
-                    EE_Registry::instance()->CFG->map_settings->google_map_api_key
178
-                );
179
-
180
-                return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&amp;zoom=14&amp;size=' . $map_w . 'x' . $map_h . '&amp;markers=color:green|label:|' . urlencode($address_string) . '&amp;sensor=false&amp;key=' . $api_key) . '" /></a>';
181
-        }
182
-
183
-        return $type === 'url_only'
184
-            ? $text
185
-            : '<a href="' . $google_map . '" target="_blank">' . $text . '</a>';
186
-    }
17
+	// array of map settings
18
+	public static $gmap_vars = array();
19
+
20
+
21
+	/**
22
+	 * google_map - creates a Google Map Link
23
+	 *
24
+	 * @param  array $ee_gmaps_opts array of attributes required for the map link generation
25
+	 * @return string (link to map!)
26
+	 */
27
+	public static function google_map($ee_gmaps_opts)
28
+	{
29
+
30
+		$ee_map_width        = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300';
31
+		$ee_map_height       = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185';
32
+		$ee_map_zoom         = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12';
33
+		$ee_map_nav_display  = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false';
34
+		$ee_map_nav_size     = ! empty($ee_gmaps_opts['ee_map_nav_size'])
35
+			? $ee_gmaps_opts['ee_map_nav_size']
36
+			: 'default';
37
+		$ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control'])
38
+			? $ee_gmaps_opts['ee_map_type_control']
39
+			: 'default';
40
+		$static_url          = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false;
41
+
42
+		if (! empty($ee_gmaps_opts['ee_map_align'])) {
43
+			switch ($ee_gmaps_opts['ee_map_align']) {
44
+				case "left":
45
+					$map_align = 'ee-gmap-align-left left';
46
+					break;
47
+				case "right":
48
+					$map_align = 'ee-gmap-align-right right';
49
+					break;
50
+				case "center":
51
+					$map_align = 'ee-gmap-align-center center';
52
+					break;
53
+				case "none":
54
+				default:
55
+					$map_align = 'ee-gmap-align-none';
56
+			}
57
+		} else {
58
+			$map_align = 'ee-gmap-align-none';
59
+		}
60
+
61
+
62
+		// Determine whether user has set a hardoded url to use and
63
+		// if so display a Google static iframe map else run V3 api
64
+		if ($static_url) {
65
+			$html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">';
66
+			$html .= '<iframe src="' . $static_url . '&output=embed"'
67
+				. ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"'
68
+				. ' frameborder="0" scrolling="no">';
69
+			$html .= '</iframe>';
70
+			$html .= '<a href="' . $static_url . '">View Large map</a>';
71
+			$html .= '</div>';
72
+			return $html;
73
+
74
+		} else {
75
+			EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array(
76
+				'map_ID'              => $ee_gmaps_opts['map_ID'],
77
+				'ee_map_zoom'         => $ee_map_zoom,
78
+				'ee_map_nav_display'  => $ee_map_nav_display,
79
+				'ee_map_nav_size'     => $ee_map_nav_size,
80
+				'ee_map_type_control' => $ee_map_type_control,
81
+				'location'            => $ee_gmaps_opts['location'],
82
+			);
83
+
84
+			$style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
85
+			$html = '<div class="ee-gmap-wrapper ' . $map_align . '">'
86
+					. '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"'
87
+					. ' style="' . $style . '"></div>'
88
+					. '</div>';
89
+
90
+			wp_enqueue_script('gmap_api');
91
+			wp_enqueue_script('ee_gmap');
92
+			add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script'));
93
+
94
+			return $html;
95
+		} // end auto map or static url map check
96
+	}
97
+
98
+
99
+	/**
100
+	 * enqueue_script
101
+	 *
102
+	 * @return void
103
+	 */
104
+	public static function footer_enqueue_script()
105
+	{
106
+		wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars);
107
+	}
108
+
109
+
110
+	/**
111
+	 * registers scripts for maps
112
+	 */
113
+	public static function espresso_google_map_js()
114
+	{
115
+		$api_url = sprintf(
116
+			"https://maps.googleapis.com/maps/api/js?key=%s",
117
+			apply_filters(
118
+				'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
119
+				EE_Registry::instance()->CFG->map_settings->google_map_api_key
120
+			)
121
+		);
122
+		wp_register_script('gmap_api', $api_url, array('jquery'), null, true);
123
+		wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
124
+	}
125
+
126
+	/**
127
+	 * creates a Google Map Link
128
+	 *
129
+	 * @param  array $atts array of attributes required for the map link generation
130
+	 * @return string (link to map!)
131
+	 */
132
+	public static function google_map_link($atts)
133
+	{
134
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
135
+		extract($atts);
136
+		/** @var string $address */
137
+		/** @var string $city */
138
+		/** @var string $state */
139
+		/** @var string $zip */
140
+		/** @var string $country */
141
+		$address         = "{$address}";
142
+		$city            = "{$city}";
143
+		$state           = "{$state}";
144
+		$zip             = "{$zip}";
145
+		$country         = "{$country}";
146
+		$text            = isset($text) ? "{$text}" : "";
147
+		$type            = isset($type) ? "{$type}" : "";
148
+		$map_w           = isset($map_w) ? "{$map_w}" : 400;
149
+		$map_h           = isset($map_h) ? "{$map_h}" : 400;
150
+		$id              = isset($id) ? $id : 'not_set';
151
+		$map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
152
+
153
+		$address_string = ($address != '' ? $address : '')
154
+						  . ($city != '' ? ',' . $city : '')
155
+						  . ($state != '' ? ',' . $state : '')
156
+						  . ($zip != '' ? ',' . $zip : '')
157
+						  . ($country != '' ? ',' . $country : '');
158
+
159
+		$google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string));
160
+
161
+		switch ($type) {
162
+			case 'text':
163
+			default:
164
+				$text = $text == '' ? __('Map and Directions', 'event_espresso') : $text;
165
+				break;
166
+
167
+			case 'url_only':
168
+			case 'url':
169
+				$text = $google_map;
170
+				break;
171
+
172
+			case 'map':
173
+				$scheme = is_ssl() ? 'https://' : 'http://';
174
+
175
+				$api_key = apply_filters(
176
+					'FHEE__EEH_Maps__espresso_google_maps_link__api_key',
177
+					EE_Registry::instance()->CFG->map_settings->google_map_api_key
178
+				);
179
+
180
+				return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&amp;zoom=14&amp;size=' . $map_w . 'x' . $map_h . '&amp;markers=color:green|label:|' . urlencode($address_string) . '&amp;sensor=false&amp;key=' . $api_key) . '" /></a>';
181
+		}
182
+
183
+		return $type === 'url_only'
184
+			? $text
185
+			: '<a href="' . $google_map . '" target="_blank">' . $text . '</a>';
186
+	}
187 187
 }
188 188
 // End of file EEH_Maps.helper.php
189 189
 // Location: /helpers/EEH_Maps.helper.php
190 190
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             : 'default';
40 40
         $static_url          = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false;
41 41
 
42
-        if (! empty($ee_gmaps_opts['ee_map_align'])) {
42
+        if ( ! empty($ee_gmaps_opts['ee_map_align'])) {
43 43
             switch ($ee_gmaps_opts['ee_map_align']) {
44 44
                 case "left":
45 45
                     $map_align = 'ee-gmap-align-left left';
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
         // Determine whether user has set a hardoded url to use and
63 63
         // if so display a Google static iframe map else run V3 api
64 64
         if ($static_url) {
65
-            $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">';
66
-            $html .= '<iframe src="' . $static_url . '&output=embed"'
67
-                . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"'
65
+            $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper '.$map_align.'">';
66
+            $html .= '<iframe src="'.$static_url.'&output=embed"'
67
+                . ' style="width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;"'
68 68
                 . ' frameborder="0" scrolling="no">';
69 69
             $html .= '</iframe>';
70
-            $html .= '<a href="' . $static_url . '">View Large map</a>';
70
+            $html .= '<a href="'.$static_url.'">View Large map</a>';
71 71
             $html .= '</div>';
72 72
             return $html;
73 73
 
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
                 'location'            => $ee_gmaps_opts['location'],
82 82
             );
83 83
 
84
-            $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;';
85
-            $html = '<div class="ee-gmap-wrapper ' . $map_align . '">'
86
-                    . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"'
87
-                    . ' style="' . $style . '"></div>'
84
+            $style = 'width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;';
85
+            $html = '<div class="ee-gmap-wrapper '.$map_align.'">'
86
+                    . '<div class="ee-gmap" id="map_canvas_'.$ee_gmaps_opts['map_ID'].'"'
87
+                    . ' style="'.$style.'"></div>'
88 88
                     . '</div>';
89 89
 
90 90
             wp_enqueue_script('gmap_api');
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             )
121 121
         );
122 122
         wp_register_script('gmap_api', $api_url, array('jquery'), null, true);
123
-        wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
123
+        wp_register_script('ee_gmap', plugin_dir_url(__FILE__).'assets/ee_gmap.js', array('gmap_api'), '1.0', true);
124 124
     }
125 125
 
126 126
     /**
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
         $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view';
152 152
 
153 153
         $address_string = ($address != '' ? $address : '')
154
-                          . ($city != '' ? ',' . $city : '')
155
-                          . ($state != '' ? ',' . $state : '')
156
-                          . ($zip != '' ? ',' . $zip : '')
157
-                          . ($country != '' ? ',' . $country : '');
154
+                          . ($city != '' ? ','.$city : '')
155
+                          . ($state != '' ? ','.$state : '')
156
+                          . ($zip != '' ? ','.$zip : '')
157
+                          . ($country != '' ? ','.$country : '');
158 158
 
159
-        $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string));
159
+        $google_map = htmlentities2('http://maps.google.com/maps?q='.urlencode($address_string));
160 160
 
161 161
         switch ($type) {
162 162
             case 'text':
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
                     EE_Registry::instance()->CFG->map_settings->google_map_api_key
178 178
                 );
179 179
 
180
-                return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&amp;zoom=14&amp;size=' . $map_w . 'x' . $map_h . '&amp;markers=color:green|label:|' . urlencode($address_string) . '&amp;sensor=false&amp;key=' . $api_key) . '" /></a>';
180
+                return '<a class="a_map_image_link" href="'.$google_map.'" target="_blank">'.'<img class="map_image_link" id="venue_map_'.$id.'" '.$map_image_class.' src="'.htmlentities2($scheme.'maps.googleapis.com/maps/api/staticmap?center='.urlencode($address_string).'&amp;zoom=14&amp;size='.$map_w.'x'.$map_h.'&amp;markers=color:green|label:|'.urlencode($address_string).'&amp;sensor=false&amp;key='.$api_key).'" /></a>';
181 181
         }
182 182
 
183 183
         return $type === 'url_only'
184 184
             ? $text
185
-            : '<a href="' . $google_map . '" target="_blank">' . $text . '</a>';
185
+            : '<a href="'.$google_map.'" target="_blank">'.$text.'</a>';
186 186
     }
187 187
 }
188 188
 // End of file EEH_Maps.helper.php
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 2 patches
Indentation   +97 added lines, -99 removed lines patch added patch discarded remove patch
@@ -44,77 +44,76 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	protected $_image_url;
46 46
 
47
-    /**
48
-     * gateway URL variable
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_base_gateway_url = '';
53
-
54
-
55
-
56
-    /**
57
-     * EEG_Paypal_Express constructor.
58
-     */
59
-    public function __construct()
60
-    {
61
-        $this->_currencies_supported = array(
62
-            'USD',
63
-            'AUD',
64
-            'BRL',
65
-            'CAD',
66
-            'CZK',
67
-            'DKK',
68
-            'EUR',
69
-            'HKD',
70
-            'HUF',
71
-            'ILS',
72
-            'JPY',
73
-            'MYR',
74
-            'MXN',
75
-            'NOK',
76
-            'NZD',
77
-            'PHP',
78
-            'PLN',
79
-            'GBP',
80
-            'RUB',
81
-            'SGD',
82
-            'SEK',
83
-            'CHF',
84
-            'TWD',
85
-            'THB',
86
-            'TRY'
87
-        );
88
-        parent::__construct();
89
-    }
90
-
91
-
92
-
93
-    /**
94
-	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
47
+	/**
48
+	 * gateway URL variable
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_base_gateway_url = '';
53
+
54
+
55
+
56
+	/**
57
+	 * EEG_Paypal_Express constructor.
58
+	 */
59
+	public function __construct()
60
+	{
61
+		$this->_currencies_supported = array(
62
+			'USD',
63
+			'AUD',
64
+			'BRL',
65
+			'CAD',
66
+			'CZK',
67
+			'DKK',
68
+			'EUR',
69
+			'HKD',
70
+			'HUF',
71
+			'ILS',
72
+			'JPY',
73
+			'MYR',
74
+			'MXN',
75
+			'NOK',
76
+			'NZD',
77
+			'PHP',
78
+			'PLN',
79
+			'GBP',
80
+			'RUB',
81
+			'SGD',
82
+			'SEK',
83
+			'CHF',
84
+			'TWD',
85
+			'THB',
86
+			'TRY'
87
+		);
88
+		parent::__construct();
89
+	}
90
+
95 91
 
92
+
93
+	/**
94
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
96 95
 	 *
97 96
 *@param array $settings_array
98 97
 	 */
99 98
 	public function set_settings( $settings_array ) {
100 99
 		parent::set_settings($settings_array);
101 100
 		// Redirect URL.
102
-        $this->_base_gateway_url = $this->_debug_mode
103
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
104
-            : 'https://api-3t.paypal.com/nvp';
101
+		$this->_base_gateway_url = $this->_debug_mode
102
+			? 'https://api-3t.sandbox.paypal.com/nvp'
103
+			: 'https://api-3t.paypal.com/nvp';
105 104
 	}
106 105
 
107 106
 
108 107
 
109
-    /**
110
-     * @param EEI_Payment $payment
111
-     * @param array       $billing_info
112
-     * @param string      $return_url
113
-     * @param string      $notify_url
114
-     * @param string      $cancel_url
115
-     * @return \EE_Payment|\EEI_Payment
116
-     * @throws \EE_Error
117
-     */
108
+	/**
109
+	 * @param EEI_Payment $payment
110
+	 * @param array       $billing_info
111
+	 * @param string      $return_url
112
+	 * @param string      $notify_url
113
+	 * @param string      $cancel_url
114
+	 * @return \EE_Payment|\EEI_Payment
115
+	 * @throws \EE_Error
116
+	 */
118 117
 	public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) {
119 118
 		if ( ! $payment instanceof EEI_Payment ) {
120 119
 			$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) );
@@ -202,9 +201,9 @@  discard block
 block discarded – undo
202 201
 				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
203 202
 				// Item quantity.
204 203
 				$token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
205
-                // Digital item is sold.
206
-                $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
207
-                $item_num++;
204
+				// Digital item is sold.
205
+				$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
206
+				$item_num++;
208 207
 			}
209 208
 		} else {
210 209
 			// Just one Item.
@@ -277,7 +276,6 @@  discard block
 block discarded – undo
277 276
 
278 277
 
279 278
 	/**
280
-
281 279
 	 *  @param array $update_info {
282 280
 	 *	  @type string $gateway_txn_id
283 281
 	 *	  @type string status an EEMI_Payment status
@@ -297,8 +295,8 @@  discard block
 block discarded – undo
297 295
 				return $payment;
298 296
 			}
299 297
 			$primary_registrant = $transaction->primary_registration();
300
-            $payment_details = $payment->details();
301
-            // Check if we still have the token.
298
+			$payment_details = $payment->details();
299
+			// Check if we still have the token.
302 300
 			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) {
303 301
 				$payment->set_status( $this->_pay_model->failed_status() );
304 302
 				return $payment;
@@ -407,35 +405,35 @@  discard block
 block discarded – undo
407 405
 	 */
408 406
 	public function _ppExpress_check_response( $request_response ) {
409 407
 		if ( is_wp_error( $request_response ) || empty($request_response['body']) ) {
410
-            // If we got here then there was an error in this request.
411
-            return array('status' => false, 'args' => $request_response);
412
-        }
413
-        $response_args = array();
414
-        parse_str( urldecode($request_response['body']), $response_args );
415
-        if ( ! isset($response_args['ACK'])) {
416
-            return array('status' => false, 'args' => $request_response);
417
-        }
418
-        if (
419
-            (
420
-                isset($response_args['PAYERID'])
421
-                || isset($response_args['TOKEN'])
422
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
423
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
424
-            )
425
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
426
-        ) {
427
-            // Response status OK, return response parameters for further processing.
428
-            return array('status' => true, 'args' => $response_args);
429
-        }
430
-        $errors = $this->_get_errors($response_args);
431
-        return array('status' => false, 'args' => $errors);
408
+			// If we got here then there was an error in this request.
409
+			return array('status' => false, 'args' => $request_response);
410
+		}
411
+		$response_args = array();
412
+		parse_str( urldecode($request_response['body']), $response_args );
413
+		if ( ! isset($response_args['ACK'])) {
414
+			return array('status' => false, 'args' => $request_response);
415
+		}
416
+		if (
417
+			(
418
+				isset($response_args['PAYERID'])
419
+				|| isset($response_args['TOKEN'])
420
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
421
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
422
+			)
423
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
424
+		) {
425
+			// Response status OK, return response parameters for further processing.
426
+			return array('status' => true, 'args' => $response_args);
427
+		}
428
+		$errors = $this->_get_errors($response_args);
429
+		return array('status' => false, 'args' => $errors);
432 430
 	}
433 431
 
434 432
 
435 433
 	/**
436
-     *  Log a "Cleared" request.
437
-     *
438
-     * @param array $request
434
+	 *  Log a "Cleared" request.
435
+	 *
436
+	 * @param array $request
439 437
 	 * @param EEI_Payment  $payment
440 438
 	 * @param string  		$info
441 439
 	 * @return void
@@ -458,17 +456,17 @@  discard block
 block discarded – undo
458 456
 		$n = 0;
459 457
 		while ( isset($data_array["L_ERRORCODE{$n}"]) ) {
460 458
 			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
461
-                ? $data_array["L_ERRORCODE{$n}"]
462
-                : '';
459
+				? $data_array["L_ERRORCODE{$n}"]
460
+				: '';
463 461
 			$l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
464
-                ? $data_array["L_SEVERITYCODE{$n}"]
465
-                : '';
462
+				? $data_array["L_SEVERITYCODE{$n}"]
463
+				: '';
466 464
 			$l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
467
-                ? $data_array["L_SHORTMESSAGE{$n}"]
468
-                : '';
465
+				? $data_array["L_SHORTMESSAGE{$n}"]
466
+				: '';
469 467
 			$l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
470
-                ? $data_array["L_LONGMESSAGE{$n}"]
471
-                : '';
468
+				? $data_array["L_LONGMESSAGE{$n}"]
469
+				: '';
472 470
 
473 471
 			if ( $n === 0 ) {
474 472
 				$errors = array(
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); }
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); }
2 2
 
3 3
 /**
4 4
  * ----------------------------------------------
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 *@param array $settings_array
98 98
 	 */
99
-	public function set_settings( $settings_array ) {
99
+	public function set_settings($settings_array) {
100 100
 		parent::set_settings($settings_array);
101 101
 		// Redirect URL.
102 102
         $this->_base_gateway_url = $this->_debug_mode
@@ -115,19 +115,19 @@  discard block
 block discarded – undo
115 115
      * @return \EE_Payment|\EEI_Payment
116 116
      * @throws \EE_Error
117 117
      */
118
-	public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) {
119
-		if ( ! $payment instanceof EEI_Payment ) {
120
-			$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) );
121
-			$payment->set_status( $this->_pay_model->failed_status() );
118
+	public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) {
119
+		if ( ! $payment instanceof EEI_Payment) {
120
+			$payment->set_gateway_response(__('Error. No associated payment was found.', 'event_espresso'));
121
+			$payment->set_status($this->_pay_model->failed_status());
122 122
 			return $payment;
123 123
 		}
124 124
 		$transaction = $payment->transaction();
125
-		if ( ! $transaction instanceof EEI_Transaction ) {
126
-			$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
127
-			$payment->set_status( $this->_pay_model->failed_status() );
125
+		if ( ! $transaction instanceof EEI_Transaction) {
126
+			$payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso'));
127
+			$payment->set_status($this->_pay_model->failed_status());
128 128
 			return $payment;
129 129
 		}
130
-		$order_description = substr( $this->_format_order_description($payment), 0, 127 );
130
+		$order_description = substr($this->_format_order_description($payment), 0, 127);
131 131
 		$primary_registration = $transaction->primary_registration();
132 132
 		$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false;
133 133
 		$locale = explode('-', get_bloginfo('language'));
@@ -141,37 +141,37 @@  discard block
 block discarded – undo
141 141
 			'RETURNURL' => $return_url,
142 142
 			'CANCELURL' => $cancel_url,
143 143
 			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
144
-			'SOLUTIONTYPE' => 'Sole',	// Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional.
145
-			'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this
144
+			'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional.
145
+			'BUTTONSOURCE' => 'EventEspresso_SP', //EE will blow up if you change this
146 146
 			'LOCALECODE' => $locale[1]	// Locale of the pages displayed by PayPal during Express Checkout.
147 147
 		);
148 148
 
149 149
 		// Show itemized list.
150
-		if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) {
150
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
151 151
 			$item_num = 0;
152 152
 			$itemized_sum = 0;
153 153
 			$total_line_items = $transaction->total_line_item();
154 154
 			// Go through each item in the list.
155
-			foreach ( $total_line_items->get_items() as $line_item ) {
156
-				if ( $line_item instanceof EE_Line_Item ) {
155
+			foreach ($total_line_items->get_items() as $line_item) {
156
+				if ($line_item instanceof EE_Line_Item) {
157 157
 					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
158
-					if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) {
158
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
159 159
 						continue;
160 160
 					}
161 161
 
162 162
 					$unit_price = $line_item->unit_price();
163 163
 					$line_item_quantity = $line_item->quantity();
164 164
 					// This is a discount.
165
-					if ( $line_item->is_percent() ) {
165
+					if ($line_item->is_percent()) {
166 166
 						$unit_price = $line_item->total();
167 167
 						$line_item_quantity = 1;
168 168
 					}
169 169
 					// Item Name.
170
-					$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127);
170
+					$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name($line_item, $payment), 0, 127);
171 171
 					// Item description.
172
-					$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127);
172
+					$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc($line_item, $payment), 0, 127);
173 173
 					// Cost of individual item.
174
-					$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price );
174
+					$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price);
175 175
 					// Item Number.
176 176
 					$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
177 177
 					// Item quantity.
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
189 189
 			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
190 190
 
191
-			$itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 );
191
+			$itemized_sum_diff_from_txn_total = round($transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2);
192 192
 			// If we were not able to recognize some item like promotion, surcharge or cancellation,
193 193
 			// add the difference as an extra line item.
194
-			if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) {
194
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
195 195
 				// Item Name.
196
-				$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 );
196
+				$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr(__('Other (promotion/surcharge/cancellation)', 'event_espresso'), 0, 127);
197 197
 				// Item description.
198 198
 				$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = '';
199 199
 				// Cost of individual item.
200
-				$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total );
200
+				$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total);
201 201
 				// Item Number.
202 202
 				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
203 203
 				// Item quantity.
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 		} else {
210 210
 			// Just one Item.
211 211
 			// Item Name.
212
-			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 );
212
+			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr($this->_format_partial_payment_line_item_name($payment), 0, 127);
213 213
 			// Item description.
214
-			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 );
214
+			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr($this->_format_partial_payment_line_item_desc($payment), 0, 127);
215 215
 			// Cost of individual item.
216
-			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() );
216
+			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount());
217 217
 			// Item Number.
218 218
 			$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
219 219
 			// Item quantity.
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 			// Digital item is sold.
222 222
 			$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
223 223
 			// Item's sales S/H and tax amount.
224
-			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() );
224
+			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount());
225 225
 			$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0';
226 226
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
227 227
 			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
228 228
 		}
229 229
 		// Automatically filling out shipping and contact information.
230
-		if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) {
231
-			$token_request_dtls['NOSHIPPING'] = '2';	//  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
230
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
231
+			$token_request_dtls['NOSHIPPING'] = '2'; //  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
232 232
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
233 233
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
234 234
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
238 238
 			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
239 239
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
240
-		} elseif ( ! $this->_request_shipping_addr ) {
240
+		} elseif ( ! $this->_request_shipping_addr) {
241 241
 			// Do not request shipping details on the PP Checkout page.
242 242
 			$token_request_dtls['NOSHIPPING'] = '1';
243 243
 			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
244 244
 
245 245
 		}
246 246
 		// Used a business/personal logo on the PayPal page.
247
-		if ( ! empty($this->_image_url) ) {
247
+		if ( ! empty($this->_image_url)) {
248 248
 			$token_request_dtls['LOGOIMG'] = $this->_image_url;
249 249
 		}
250 250
 		$token_request_dtls = apply_filters(
@@ -253,23 +253,23 @@  discard block
 block discarded – undo
253 253
 			$this
254 254
 		);
255 255
 		// Request PayPal token.
256
-		$token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment );
257
-		$token_rstatus = $this->_ppExpress_check_response( $token_request_response );
258
-		$response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array();
259
-		if ( $token_rstatus['status'] ) {
256
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
257
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
258
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) ? $token_rstatus['args'] : array();
259
+		if ($token_rstatus['status']) {
260 260
 			// We got the Token so we may continue with the payment and redirect the client.
261
-			$payment->set_details( $response_args );
261
+			$payment->set_details($response_args);
262 262
 
263 263
 			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
264
-			$payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] );
264
+			$payment->set_redirect_url($gateway_url.'/checkoutnow?useraction=commit&cmd=_express-checkout&token='.$response_args['TOKEN']);
265 265
 		} else {
266
-			if ( isset($response_args['L_ERRORCODE']) ) {
267
-				$payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] );
266
+			if (isset($response_args['L_ERRORCODE'])) {
267
+				$payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']);
268 268
 			} else {
269
-				$payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) );
269
+				$payment->set_gateway_response(__('Error occurred while trying to setup the Express Checkout.', 'event_espresso'));
270 270
 			}
271
-			$payment->set_details( $response_args );
272
-			$payment->set_status( $this->_pay_model->failed_status() );
271
+			$payment->set_details($response_args);
272
+			$payment->set_status($this->_pay_model->failed_status());
273 273
 		}
274 274
 
275 275
 		return $payment;
@@ -285,22 +285,22 @@  discard block
 block discarded – undo
285 285
 	 *  @param EEI_Transaction $transaction
286 286
 	 *  @return EEI_Payment
287 287
 	 */
288
-	public function handle_payment_update( $update_info, $transaction ) {
288
+	public function handle_payment_update($update_info, $transaction) {
289 289
 		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
290 290
 
291
-		if ( $payment instanceof EEI_Payment ) {
292
-			$this->log( array( 'Return from Authorization' => $update_info ), $payment );
291
+		if ($payment instanceof EEI_Payment) {
292
+			$this->log(array('Return from Authorization' => $update_info), $payment);
293 293
 			$transaction = $payment->transaction();
294
-			if ( ! $transaction instanceof EEI_Transaction ) {
295
-				$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
296
-				$payment->set_status( $this->_pay_model->failed_status() );
294
+			if ( ! $transaction instanceof EEI_Transaction) {
295
+				$payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso'));
296
+				$payment->set_status($this->_pay_model->failed_status());
297 297
 				return $payment;
298 298
 			}
299 299
 			$primary_registrant = $transaction->primary_registration();
300 300
             $payment_details = $payment->details();
301 301
             // Check if we still have the token.
302
-			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) {
303
-				$payment->set_status( $this->_pay_model->failed_status() );
302
+			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
303
+				$payment->set_status($this->_pay_model->failed_status());
304 304
 				return $payment;
305 305
 			}
306 306
 
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
 				'TOKEN' => $payment_details['TOKEN']
310 310
 			);
311 311
 			// Request Customer Details.
312
-			$cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment );
313
-			$cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response );
314
-			$cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array();
315
-			if ( $cdetails_rstatus['status'] ) {
312
+			$cdetails_request_response = $this->_ppExpress_request($cdetails_request_dtls, 'Customer Details', $payment);
313
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
314
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) ? $cdetails_rstatus['args'] : array();
315
+			if ($cdetails_rstatus['status']) {
316 316
 				// We got the PayerID so now we can Complete the transaction.
317 317
 				$docheckout_request_dtls = array(
318 318
 					'METHOD' => 'DoExpressCheckoutPayment',
@@ -323,39 +323,39 @@  discard block
 block discarded – undo
323 323
 					'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code()
324 324
 				);
325 325
 				// Payment Checkout/Capture.
326
-				$docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment );
327
-				$docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response );
328
-				$docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array();
329
-				if ( $docheckout_rstatus['status'] ) {
326
+				$docheckout_request_response = $this->_ppExpress_request($docheckout_request_dtls, 'Do Payment', $payment);
327
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
328
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) ? $docheckout_rstatus['args'] : array();
329
+				if ($docheckout_rstatus['status']) {
330 330
 					// All is well, payment approved.
331 331
 					$primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : '';
332
-					$payment->set_extra_accntng( $primary_registration_code );
333
-					$payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 );
334
-					$payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null );
335
-					$payment->set_details( $cdata_response_args );
336
-					$payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' );
337
-					$payment->set_status( $this->_pay_model->approved_status() );
332
+					$payment->set_extra_accntng($primary_registration_code);
333
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0);
334
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null);
335
+					$payment->set_details($cdata_response_args);
336
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '');
337
+					$payment->set_status($this->_pay_model->approved_status());
338 338
 				} else {
339
-					if ( isset($docheckout_response_args['L_ERRORCODE']) ) {
340
-						$payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] );
339
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
340
+						$payment->set_gateway_response($docheckout_response_args['L_ERRORCODE'].'; '.$docheckout_response_args['L_SHORTMESSAGE']);
341 341
 					} else {
342
-						$payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) );
342
+						$payment->set_gateway_response(__('Error occurred while trying to Capture the funds.', 'event_espresso'));
343 343
 					}
344
-					$payment->set_details( $docheckout_response_args );
345
-					$payment->set_status( $this->_pay_model->declined_status() );
344
+					$payment->set_details($docheckout_response_args);
345
+					$payment->set_status($this->_pay_model->declined_status());
346 346
 				}
347 347
 			} else {
348
-				if ( isset($cdata_response_args['L_ERRORCODE']) ) {
349
-					$payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] );
348
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
349
+					$payment->set_gateway_response($cdata_response_args['L_ERRORCODE'].'; '.$cdata_response_args['L_SHORTMESSAGE']);
350 350
 				} else {
351
-					$payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) );
351
+					$payment->set_gateway_response(__('Error occurred while trying to get payment Details from PayPal.', 'event_espresso'));
352 352
 				}
353
-				$payment->set_details( $cdata_response_args );
354
-				$payment->set_status( $this->_pay_model->failed_status() );
353
+				$payment->set_details($cdata_response_args);
354
+				$payment->set_status($this->_pay_model->failed_status());
355 355
 			}
356 356
 		} else {
357
-			$payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) );
358
-			$payment->set_status( $this->_pay_model->failed_status() );
357
+			$payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso'));
358
+			$payment->set_status($this->_pay_model->failed_status());
359 359
 		}
360 360
 
361 361
 		return $payment;
@@ -370,16 +370,16 @@  discard block
 block discarded – undo
370 370
 	 *  @param EEI_Payment  $payment
371 371
 	 *	@return mixed
372 372
 	 */
373
-	public function _ppExpress_request( $request_params, $request_text, $payment ) {
373
+	public function _ppExpress_request($request_params, $request_text, $payment) {
374 374
 		$request_dtls = array(
375 375
 			'VERSION' => '204.0',
376
-			'USER' => urlencode( $this->_api_username ),
377
-			'PWD' => urlencode( $this->_api_password ),
378
-			'SIGNATURE' => urlencode( $this->_api_signature )
376
+			'USER' => urlencode($this->_api_username),
377
+			'PWD' => urlencode($this->_api_password),
378
+			'SIGNATURE' => urlencode($this->_api_signature)
379 379
 		);
380
-		$dtls = array_merge( $request_dtls, $request_params );
380
+		$dtls = array_merge($request_dtls, $request_params);
381 381
 
382
-		$this->_log_clean_request( $dtls, $payment, $request_text . ' Request' );
382
+		$this->_log_clean_request($dtls, $payment, $request_text.' Request');
383 383
 		// Request Customer Details.
384 384
 		$request_response = wp_remote_post(
385 385
 			$this->_base_gateway_url,
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 				'httpversion' => '1.1',
390 390
 				'cookies' => array(),
391 391
 				'headers' => array(),
392
-				'body' => http_build_query( $dtls )
392
+				'body' => http_build_query($dtls)
393 393
 			)
394 394
 		);
395 395
 		// Log the response.
396
-		$this->log( array( $request_text . ' Response' => $request_response), $payment );
396
+		$this->log(array($request_text.' Response' => $request_response), $payment);
397 397
 
398 398
 		return $request_response;
399 399
 	}
@@ -405,13 +405,13 @@  discard block
 block discarded – undo
405 405
 	 *	@param mixed        $request_response
406 406
 	 *	@return array
407 407
 	 */
408
-	public function _ppExpress_check_response( $request_response ) {
409
-		if ( is_wp_error( $request_response ) || empty($request_response['body']) ) {
408
+	public function _ppExpress_check_response($request_response) {
409
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
410 410
             // If we got here then there was an error in this request.
411 411
             return array('status' => false, 'args' => $request_response);
412 412
         }
413 413
         $response_args = array();
414
-        parse_str( urldecode($request_response['body']), $response_args );
414
+        parse_str(urldecode($request_response['body']), $response_args);
415 415
         if ( ! isset($response_args['ACK'])) {
416 416
             return array('status' => false, 'args' => $request_response);
417 417
         }
@@ -440,10 +440,10 @@  discard block
 block discarded – undo
440 440
 	 * @param string  		$info
441 441
 	 * @return void
442 442
 	 */
443
-	private function _log_clean_request($request, $payment, $info ) {
443
+	private function _log_clean_request($request, $payment, $info) {
444 444
 		$cleaned_request_data = $request;
445 445
 		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
446
-		$this->log( array($info => $cleaned_request_data), $payment );
446
+		$this->log(array($info => $cleaned_request_data), $payment);
447 447
 	}
448 448
 
449 449
 
@@ -453,10 +453,10 @@  discard block
 block discarded – undo
453 453
 	 *  @param array	$data_array
454 454
 	 *  @return array
455 455
 	 */
456
-	private function _get_errors( $data_array ) {
456
+	private function _get_errors($data_array) {
457 457
 		$errors = array();
458 458
 		$n = 0;
459
-		while ( isset($data_array["L_ERRORCODE{$n}"]) ) {
459
+		while (isset($data_array["L_ERRORCODE{$n}"])) {
460 460
 			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
461 461
                 ? $data_array["L_ERRORCODE{$n}"]
462 462
                 : '';
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
                 ? $data_array["L_LONGMESSAGE{$n}"]
471 471
                 : '';
472 472
 
473
-			if ( $n === 0 ) {
473
+			if ($n === 0) {
474 474
 				$errors = array(
475 475
 					'L_ERRORCODE' => $l_error_code,
476 476
 					'L_SHORTMESSAGE' => $l_short_message,
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
 					'L_SEVERITYCODE' => $l_severity_code
479 479
 				);
480 480
 			} else {
481
-				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
482
-				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
483
-				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
484
-				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
481
+				$errors['L_ERRORCODE'] .= ', '.$l_error_code;
482
+				$errors['L_SHORTMESSAGE'] .= ', '.$l_short_message;
483
+				$errors['L_LONGMESSAGE'] .= ', '.$l_long_message;
484
+				$errors['L_SEVERITYCODE'] .= ', '.$l_severity_code;
485 485
 			}
486 486
 
487 487
 			$n++;
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 2 patches
Indentation   +693 added lines, -693 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,698 +16,698 @@  discard block
 block discarded – undo
16 16
 
17 17
 
18 18
 
19
-    /**
20
-     * @return EED_Module|EED_Add_New_State
21
-     */
22
-    public static function instance()
23
-    {
24
-        return parent::get_instance(__CLASS__);
25
-    }
26
-
27
-
28
-
29
-    /**
30
-     * set_hooks - for hooking into EE Core, other modules, etc
31
-     *
32
-     * @return void
33
-     */
34
-    public static function set_hooks()
35
-    {
36
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
40
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
41
-        add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
42
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
43
-        add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
44
-            array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
45
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
46
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
47
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
48
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
49
-        add_filter('FHEE__EE_State_Select_Input____construct__state_options',
50
-            array('EED_Add_New_State', 'state_options'), 10, 1);
51
-        add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
52
-            array('EED_Add_New_State', 'country_options'), 10, 1);
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
59
-     *
60
-     * @return void
61
-     */
62
-    public static function set_hooks_admin()
63
-    {
64
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
65
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
66
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
67
-        add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
68
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
69
-        add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
70
-        add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
71
-        add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
72
-            array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
73
-        add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
74
-            array('EED_Add_New_State', 'update_country_settings'), 10, 3);
75
-        add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
76
-            array('EED_Add_New_State', 'update_country_settings'), 10, 3);
77
-        add_filter('FHEE__EE_State_Select_Input____construct__state_options',
78
-            array('EED_Add_New_State', 'state_options'), 10, 1);
79
-        add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
80
-            array('EED_Add_New_State', 'country_options'), 10, 1);
81
-        add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
82
-            array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1);
83
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
84
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
85
-        add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
86
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     * @return void
93
-     */
94
-    public static function set_definitions()
95
-    {
96
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
97
-        define('ANS_TEMPLATES_PATH', str_replace(
98
-            '\\',
99
-            DS, plugin_dir_path(__FILE__)) . 'templates' . DS
100
-        );
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @param WP $WP
107
-     * @return void
108
-     */
109
-    public function run($WP)
110
-    {
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @return void
117
-     */
118
-    public static function translate_js_strings()
119
-    {
120
-        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
121
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
122
-            'event_espresso'
123
-        );
124
-        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
125
-            'In order to proceed, you need to enter the name of your State/Province.',
126
-            'event_espresso'
127
-        );
128
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
129
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
130
-            'event_espresso'
131
-        );
132
-        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
133
-            'The new state was successfully saved to the database.',
134
-            'event_espresso'
135
-        );
136
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
137
-            'An unknown error has occurred on the server while saving the new state to the database.',
138
-            'event_espresso'
139
-        );
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * @return void
146
-     */
147
-    public static function wp_enqueue_scripts()
148
-    {
149
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
150
-            wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
151
-                array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
152
-            wp_enqueue_script('add_new_state');
153
-        }
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * display_add_new_state_micro_form
160
-     *
161
-     * @param EE_Form_Section_Proper $question_group_reg_form
162
-     * @return string
163
-     * @throws EE_Error
164
-     */
165
-    //	public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){
166
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
167
-    {
168
-        // only add the 'new_state_micro_form' when displaying reg forms,
169
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
170
-        $action = EE_Registry::instance()->REQ->get('action', '');
171
-        // is the "state" question in this form section?
172
-        $input = $question_group_reg_form->get_subsection('state');
173
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
174
-            //ok then all we need to do is make sure the input's HTML name is consistent
175
-            //by forcing it to set it now, like it did while getting the form for display
176
-            if ($input instanceof EE_State_Select_Input) {
177
-                $input->html_name();
178
-            }
179
-            return $question_group_reg_form;
180
-        }
181
-        // we're only doing this for state select inputs
182
-        if ($input instanceof EE_State_Select_Input) {
183
-            // grab any set values from the request
184
-            $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
185
-            $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
186
-            $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
187
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
188
-            $country_options = array();
189
-            $countries = EEM_Country::instance()->get_all_countries();
190
-            if (! empty($countries)) {
191
-                foreach ($countries as $country) {
192
-                    if ($country instanceof EE_Country) {
193
-                        $country_options[$country->ID()] = $country->name();
194
-                    }
195
-                }
196
-            }
197
-            $new_state_micro_form = new EE_Form_Section_Proper(
198
-                array(
199
-                    'name'            => 'new_state_micro_form',
200
-                    'html_id'         => 'new_state_micro_form',
201
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
202
-                    'subsections'     => array(
203
-                        // add hidden input to indicate that a new state is being added
204
-                        'add_new_state'               => new EE_Hidden_Input(
205
-                            array(
206
-                                'html_name' => str_replace(
207
-                                    'state',
208
-                                    'nsmf_add_new_state', $input->html_name()
209
-                                ),
210
-                                'html_id'   => str_replace(
211
-                                    'state',
212
-                                    'nsmf_add_new_state', $input->html_id()
213
-                                ),
214
-                                'default'   => 0,
215
-                            )
216
-                        ),
217
-                        // add link for displaying hidden container
218
-                        'click_here_link'             => new EE_Form_Section_HTML(
219
-                            apply_filters(
220
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
221
-                                EEH_HTML::link(
222
-                                    '',
223
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
224
-                                    '',
225
-                                    'display-' . $input->html_id(),
226
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
227
-                                    '',
228
-                                    'data-target="' . $input->html_id() . '"'
229
-                                )
230
-                            )
231
-                        ),
232
-                        // add initial html for hidden container
233
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
234
-                            apply_filters(
235
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
236
-                                EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
237
-                                    'display: none;') .
238
-                                EEH_HTML::h6(
239
-                                    esc_html__(
240
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
241
-                                        'event_espresso'
242
-                                    )
243
-                                ) .
244
-                                EEH_HTML::ul() .
245
-                                EEH_HTML::li(
246
-                                    esc_html__(
247
-                                        'first select the Country that your State/Province belongs to',
248
-                                        'event_espresso'
249
-                                    )
250
-                                ) .
251
-                                EEH_HTML::li(
252
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
253
-                                ) .
254
-                                EEH_HTML::li(
255
-                                    esc_html__(
256
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
257
-                                        'event_espresso'
258
-                                    )
259
-                                ) .
260
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
261
-                                EEH_HTML::ulx()
262
-                            )
263
-                        ),
264
-                        // NEW STATE COUNTRY
265
-                        'new_state_country'           => new EE_Country_Select_Input(
266
-                            $country_options,
267
-                            array(
268
-                                'html_name'       => $country_name,
269
-                                'html_id'         => str_replace(
270
-                                    'state',
271
-                                    'nsmf_new_state_country', $input->html_id()
272
-                                ),
273
-                                'html_class'      => $input->html_class() . ' new-state-country',
274
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
275
-                                'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
276
-                                'required'        => false,
277
-                            )
278
-                        ),
279
-                        // NEW STATE NAME
280
-                        'new_state_name'              => new EE_Text_Input(
281
-                            array(
282
-                                'html_name'       => $state_name,
283
-                                'html_id'         => str_replace(
284
-                                    'state',
285
-                                    'nsmf_new_state_name', $input->html_id()
286
-                                ),
287
-                                'html_class'      => $input->html_class() . ' new-state-state',
288
-                                'html_label_text' => esc_html__('New State/Province Name',
289
-                                    'event_espresso'),
290
-                                'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
291
-                                'required'        => false,
292
-                            )
293
-                        ),
294
-                        'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
295
-                        // NEW STATE NAME
296
-                        'new_state_abbrv'             => new EE_Text_Input(
297
-                            array(
298
-                                'html_name'             => $abbrv_name,
299
-                                'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
300
-                                    $input->html_id()),
301
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
302
-                                'html_label_text'       => esc_html__(
303
-                                    'New State/Province Abbreviation',
304
-                                    'event_espresso'
305
-                                ) . ' *',
306
-                                'html_other_attributes' => 'size="24"',
307
-                                'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
308
-                                'required'              => false,
309
-                            )
310
-                        ),
311
-                        // "submit" button
312
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
313
-                            apply_filters(
314
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
315
-                                EEH_HTML::nbsp(3) .
316
-                                EEH_HTML::link(
317
-                                    '',
318
-                                    esc_html__('ADD', 'event_espresso'),
319
-                                    '',
320
-                                    'submit-' . $new_state_submit_id,
321
-                                    'ee-form-add-new-state-submit button button-secondary',
322
-                                    '',
323
-                                    'data-target="' . $new_state_submit_id . '"'
324
-                                )
325
-                            )
326
-                        ),
327
-                        // extra info
328
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
329
-                            apply_filters(
330
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
331
-                                EEH_HTML::br(2)
332
-                                .
333
-                                EEH_HTML::div('', '', 'small-text')
334
-                                .
335
-                                EEH_HTML::strong(
336
-                                    '* ' .
337
-                                    esc_html__(
338
-                                        'Don\'t know your State/Province Abbreviation?',
339
-                                        'event_espresso'
340
-                                    )
341
-                                )
342
-                                .
343
-                                EEH_HTML::br()
344
-                                .
345
-                                sprintf(
346
-                                    esc_html__(
347
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
348
-                                        'event_espresso'
349
-                                    ),
350
-                                    EEH_HTML::link(
351
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
352
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
353
-                                        '',
354
-                                        '',
355
-                                        'ee-form-add-new-state-wiki-lnk',
356
-                                        '',
357
-                                        'target="_blank"'
358
-                                    )
359
-                                )
360
-                                .
361
-                                EEH_HTML::divx()
362
-                                .
363
-                                EEH_HTML::br()
364
-                                .
365
-                                EEH_HTML::link(
366
-                                    '',
367
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
368
-                                    '',
369
-                                    'hide-' . $input->html_id(),
370
-                                    'ee-form-cancel-new-state-lnk smaller-text',
371
-                                    '',
372
-                                    'data-target="' . $input->html_id() . '"'
373
-                                )
374
-                                .
375
-                                EEH_HTML::divx()
376
-                                .
377
-                                EEH_HTML::br()
378
-                            )
379
-                        ),
380
-                    ),
381
-                )
382
-            );
383
-            $question_group_reg_form->add_subsections(
384
-                array('new_state_micro_form' => $new_state_micro_form),
385
-                'state',
386
-                false
387
-            );
388
-        }
389
-        return $question_group_reg_form;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * set_new_state_input_width
396
-     *
397
-     * @return int|string
398
-     * @throws EE_Error
399
-     */
400
-    public static function add_new_state()
401
-    {
402
-        $REQ = EE_Registry::instance()->load_core('Request_Handler');
403
-        if (absint($REQ->get('nsmf_add_new_state')) === 1) {
404
-            EE_Registry::instance()->load_model('State');
405
-            // grab country ISO code, new state name, and new state abbreviation
406
-            $state_country = $REQ->is_set('nsmf_new_state_country')
407
-                ? sanitize_text_field($REQ->get('nsmf_new_state_country'))
408
-                : false;
409
-            $state_name = $REQ->is_set('nsmf_new_state_name')
410
-                ? sanitize_text_field($REQ->get('nsmf_new_state_name'))
411
-                : false;
412
-            $state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
413
-                ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
414
-                : false;
415
-            if ($state_country && $state_name && $state_abbr) {
416
-                $new_state = EED_Add_New_State::save_new_state_to_db(array(
417
-                    'CNT_ISO'    => strtoupper($state_country),
418
-                    'STA_abbrev' => strtoupper($state_abbr),
419
-                    'STA_name'   => ucwords($state_name),
420
-                    'STA_active' => false,
421
-                ));
422
-                if ($new_state instanceof EE_State) {
423
-                    // clean house
424
-                    EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
425
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
426
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
427
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
428
-                    // get any existing new states
429
-                    $new_states = EE_Registry::instance()->SSN->get_session_data(
430
-                        'nsmf_new_states'
431
-                    );
432
-                    $new_states[$new_state->ID()] = $new_state;
433
-                    EE_Registry::instance()->SSN->set_session_data(
434
-                        array('nsmf_new_states' => $new_states)
435
-                    );
436
-                    if (EE_Registry::instance()->REQ->ajax) {
437
-                        echo wp_json_encode(array(
438
-                            'success'      => true,
439
-                            'id'           => $new_state->ID(),
440
-                            'name'         => $new_state->name(),
441
-                            'abbrev'       => $new_state->abbrev(),
442
-                            'country_iso'  => $new_state->country_iso(),
443
-                            'country_name' => $new_state->country()->name(),
444
-                        ));
445
-                        exit();
446
-                    }
447
-                    return $new_state->ID();
448
-                }
449
-            } else {
450
-                $error = esc_html__(
451
-                    'A new State/Province could not be added because invalid or missing data was received.',
452
-                    'event_espresso'
453
-                );
454
-                if (EE_Registry::instance()->REQ->ajax) {
455
-                    echo wp_json_encode(array('error' => $error));
456
-                    exit();
457
-                }
458
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
459
-            }
460
-        }
461
-        return false;
462
-    }
463
-
464
-
465
-
466
-    /**
467
-     * recursively drills down through request params to remove any that were added by this module
468
-     *
469
-     * @param array $request_params
470
-     * @return array
471
-     */
472
-    public static function filter_checkout_request_params($request_params)
473
-    {
474
-        foreach ($request_params as $form_section) {
475
-            if (is_array($form_section)) {
476
-                EED_Add_New_State::unset_new_state_request_params($form_section);
477
-                EED_Add_New_State::filter_checkout_request_params($form_section);
478
-            }
479
-        }
480
-        return $request_params;
481
-    }
482
-
483
-
484
-
485
-    /**
486
-     * @param array $request_params
487
-     * @return array
488
-     */
489
-    public static function unset_new_state_request_params($request_params)
490
-    {
491
-        unset(
492
-            $request_params['new_state_micro_form'],
493
-            $request_params['new_state_micro_add_new_state'],
494
-            $request_params['new_state_micro_new_state_country'],
495
-            $request_params['new_state_micro_new_state_name'],
496
-            $request_params['new_state_micro_new_state_abbrv']
497
-        );
498
-        return $request_params;
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * @param array $props_n_values
505
-     * @return bool
506
-     * @throws EE_Error
507
-     */
508
-    public static function save_new_state_to_db($props_n_values = array())
509
-    {
510
-        $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
511
-        if (! empty($existing_state)) {
512
-            return array_pop($existing_state);
513
-        }
514
-        $new_state = EE_State::new_instance($props_n_values);
515
-        if ($new_state instanceof EE_State) {
516
-            // if not non-ajax admin
517
-            $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
518
-            $new_state_notice = sprintf(
519
-                esc_html__(
520
-                    '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.',
521
-                    'event_espresso'
522
-                ),
523
-                '<b>' . $new_state->name() . '</b>',
524
-                '<b>' . $new_state->abbrev() . '</b>',
525
-                '<b>' . $new_state->country()->name() . '</b>',
526
-                '<a href="' . add_query_arg(array(
527
-                    'page'    => 'espresso_general_settings',
528
-                    'action'  => 'country_settings',
529
-                    'country' => $new_state->country_iso(),
530
-                ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
531
-                    'event_espresso') . '</a>',
532
-                '<br />'
533
-            );
534
-            EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
535
-            $new_state->save();
536
-            EEM_State::instance()->reset_cached_states();
537
-            return $new_state;
538
-        }
539
-        return false;
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * @param string $CNT_ISO
546
-     * @param string $STA_ID
547
-     * @param array  $cols_n_values
548
-     * @return void
549
-     */
550
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
551
-    {
552
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false;
553
-        if (! $CNT_ISO) {
554
-            EE_Error::add_error(
555
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
556
-                __FILE__,
557
-                __FUNCTION__,
558
-                __LINE__
559
-            );
560
-        }
561
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
562
-            : false;
563
-        if (! $STA_abbrev && ! empty($STA_ID)) {
564
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
565
-            if ($state instanceof EE_State) {
566
-                $STA_abbrev = $state->abbrev();
567
-            }
568
-        }
569
-        if (! $STA_abbrev) {
570
-            EE_Error::add_error(
571
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
572
-                __FILE__,
573
-                __FUNCTION__,
574
-                __LINE__
575
-            );
576
-        }
577
-        EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * @param EE_State[]                             $state_options
584
-     * @param EE_SPCO_Reg_Step_Attendee_Information  $reg_step
585
-     * @param EE_Registration                        $registration
586
-     * @param EE_Question                            $question
587
-     * @param                                        $answer
588
-     * @return array
589
-     */
590
-    public static function inject_new_reg_state_into_options(
591
-        $state_options = array(),
592
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
593
-        EE_Registration $registration,
594
-        EE_Question $question,
595
-        $answer
596
-    ) {
597
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
598
-            && $question->type()
599
-               === EEM_Question::QST_type_state
600
-        ) {
601
-            $STA_ID = $answer->value();
602
-            if (! empty($STA_ID)) {
603
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
604
-                if ($state instanceof EE_State) {
605
-                    $country = $state->country();
606
-                    if ($country instanceof EE_Country) {
607
-                        if (! isset($state_options[$country->name()])) {
608
-                            $state_options[$country->name()] = array();
609
-                        }
610
-                        if (! isset($state_options[$country->name()][$STA_ID])) {
611
-                            $state_options[$country->name()][$STA_ID] = $state->name();
612
-                        }
613
-                    }
614
-                }
615
-            }
616
-        }
617
-        return $state_options;
618
-    }
619
-
620
-
621
-
622
-    /**
623
-     * @param EE_Country[]                           $country_options
624
-     * @param EE_SPCO_Reg_Step_Attendee_Information  $reg_step
625
-     * @param EE_Registration                        $registration
626
-     * @param EE_Question                            $question
627
-     * @param                                        $answer
628
-     * @return array
629
-     */
630
-    public static function inject_new_reg_country_into_options(
631
-        $country_options = array(),
632
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
633
-        EE_Registration $registration,
634
-        EE_Question $question,
635
-        $answer
636
-    ) {
637
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
638
-            && $question->type()
639
-               === EEM_Question::QST_type_country
640
-        ) {
641
-            $CNT_ISO = $answer->value();
642
-            if (! empty($CNT_ISO)) {
643
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
644
-                if ($country instanceof EE_Country) {
645
-                    if (! isset($country_options[$CNT_ISO])) {
646
-                        $country_options[$CNT_ISO] = $country->name();
647
-                    }
648
-                }
649
-            }
650
-        }
651
-        return $country_options;
652
-    }
653
-
654
-
655
-
656
-    /**
657
-     * @param EE_State[] $state_options
658
-     * @return array
659
-     * @throws EE_Error
660
-     */
661
-    public static function state_options($state_options = array())
662
-    {
663
-        $new_states = EED_Add_New_State::_get_new_states();
664
-        foreach ($new_states as $new_state) {
665
-            if (
666
-                $new_state instanceof EE_State
667
-                && $new_state->country() instanceof EE_Country
668
-            ) {
669
-                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
670
-            }
671
-        }
672
-        return $state_options;
673
-    }
674
-
675
-
676
-
677
-    /**
678
-     * @return array
679
-     */
680
-    protected static function _get_new_states()
681
-    {
682
-        $new_states = array();
683
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
684
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
685
-                'nsmf_new_states'
686
-            );
687
-        }
688
-        return is_array($new_states) ? $new_states : array();
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     * @param EE_Country[] $country_options
695
-     * @return array
696
-     * @throws EE_Error
697
-     */
698
-    public static function country_options($country_options = array())
699
-    {
700
-        $new_states = EED_Add_New_State::_get_new_states();
701
-        foreach ($new_states as $new_state) {
702
-            if (
703
-                $new_state instanceof EE_State
704
-                && $new_state->country() instanceof EE_Country
705
-            ) {
706
-                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
707
-            }
708
-        }
709
-        return $country_options;
710
-    }
19
+	/**
20
+	 * @return EED_Module|EED_Add_New_State
21
+	 */
22
+	public static function instance()
23
+	{
24
+		return parent::get_instance(__CLASS__);
25
+	}
26
+
27
+
28
+
29
+	/**
30
+	 * set_hooks - for hooking into EE Core, other modules, etc
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public static function set_hooks()
35
+	{
36
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
40
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
41
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
42
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
43
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
44
+			array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
45
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
46
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
47
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
48
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
49
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options',
50
+			array('EED_Add_New_State', 'state_options'), 10, 1);
51
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
52
+			array('EED_Add_New_State', 'country_options'), 10, 1);
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
59
+	 *
60
+	 * @return void
61
+	 */
62
+	public static function set_hooks_admin()
63
+	{
64
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
65
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
66
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
67
+		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
68
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1);
69
+		add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
70
+		add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
71
+		add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
72
+			array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1);
73
+		add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
74
+			array('EED_Add_New_State', 'update_country_settings'), 10, 3);
75
+		add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
76
+			array('EED_Add_New_State', 'update_country_settings'), 10, 3);
77
+		add_filter('FHEE__EE_State_Select_Input____construct__state_options',
78
+			array('EED_Add_New_State', 'state_options'), 10, 1);
79
+		add_filter('FHEE__EE_Country_Select_Input____construct__country_options',
80
+			array('EED_Add_New_State', 'country_options'), 10, 1);
81
+		add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
82
+			array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1);
83
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
84
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5);
85
+		add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
86
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5);
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 * @return void
93
+	 */
94
+	public static function set_definitions()
95
+	{
96
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
97
+		define('ANS_TEMPLATES_PATH', str_replace(
98
+			'\\',
99
+			DS, plugin_dir_path(__FILE__)) . 'templates' . DS
100
+		);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @param WP $WP
107
+	 * @return void
108
+	 */
109
+	public function run($WP)
110
+	{
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @return void
117
+	 */
118
+	public static function translate_js_strings()
119
+	{
120
+		EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
121
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
122
+			'event_espresso'
123
+		);
124
+		EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
125
+			'In order to proceed, you need to enter the name of your State/Province.',
126
+			'event_espresso'
127
+		);
128
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
129
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
130
+			'event_espresso'
131
+		);
132
+		EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
133
+			'The new state was successfully saved to the database.',
134
+			'event_espresso'
135
+		);
136
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
137
+			'An unknown error has occurred on the server while saving the new state to the database.',
138
+			'event_espresso'
139
+		);
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * @return void
146
+	 */
147
+	public static function wp_enqueue_scripts()
148
+	{
149
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
150
+			wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
151
+				array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
152
+			wp_enqueue_script('add_new_state');
153
+		}
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * display_add_new_state_micro_form
160
+	 *
161
+	 * @param EE_Form_Section_Proper $question_group_reg_form
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 */
165
+	//	public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){
166
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
167
+	{
168
+		// only add the 'new_state_micro_form' when displaying reg forms,
169
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
170
+		$action = EE_Registry::instance()->REQ->get('action', '');
171
+		// is the "state" question in this form section?
172
+		$input = $question_group_reg_form->get_subsection('state');
173
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
174
+			//ok then all we need to do is make sure the input's HTML name is consistent
175
+			//by forcing it to set it now, like it did while getting the form for display
176
+			if ($input instanceof EE_State_Select_Input) {
177
+				$input->html_name();
178
+			}
179
+			return $question_group_reg_form;
180
+		}
181
+		// we're only doing this for state select inputs
182
+		if ($input instanceof EE_State_Select_Input) {
183
+			// grab any set values from the request
184
+			$country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
185
+			$state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
186
+			$abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
187
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
188
+			$country_options = array();
189
+			$countries = EEM_Country::instance()->get_all_countries();
190
+			if (! empty($countries)) {
191
+				foreach ($countries as $country) {
192
+					if ($country instanceof EE_Country) {
193
+						$country_options[$country->ID()] = $country->name();
194
+					}
195
+				}
196
+			}
197
+			$new_state_micro_form = new EE_Form_Section_Proper(
198
+				array(
199
+					'name'            => 'new_state_micro_form',
200
+					'html_id'         => 'new_state_micro_form',
201
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
202
+					'subsections'     => array(
203
+						// add hidden input to indicate that a new state is being added
204
+						'add_new_state'               => new EE_Hidden_Input(
205
+							array(
206
+								'html_name' => str_replace(
207
+									'state',
208
+									'nsmf_add_new_state', $input->html_name()
209
+								),
210
+								'html_id'   => str_replace(
211
+									'state',
212
+									'nsmf_add_new_state', $input->html_id()
213
+								),
214
+								'default'   => 0,
215
+							)
216
+						),
217
+						// add link for displaying hidden container
218
+						'click_here_link'             => new EE_Form_Section_HTML(
219
+							apply_filters(
220
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
221
+								EEH_HTML::link(
222
+									'',
223
+									esc_html__('click here to add a new state/province', 'event_espresso'),
224
+									'',
225
+									'display-' . $input->html_id(),
226
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
227
+									'',
228
+									'data-target="' . $input->html_id() . '"'
229
+								)
230
+							)
231
+						),
232
+						// add initial html for hidden container
233
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
234
+							apply_filters(
235
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
236
+								EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
237
+									'display: none;') .
238
+								EEH_HTML::h6(
239
+									esc_html__(
240
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
241
+										'event_espresso'
242
+									)
243
+								) .
244
+								EEH_HTML::ul() .
245
+								EEH_HTML::li(
246
+									esc_html__(
247
+										'first select the Country that your State/Province belongs to',
248
+										'event_espresso'
249
+									)
250
+								) .
251
+								EEH_HTML::li(
252
+									esc_html__('enter the name of your State/Province', 'event_espresso')
253
+								) .
254
+								EEH_HTML::li(
255
+									esc_html__(
256
+										'enter a two to six letter abbreviation for the name of your State/Province',
257
+										'event_espresso'
258
+									)
259
+								) .
260
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
261
+								EEH_HTML::ulx()
262
+							)
263
+						),
264
+						// NEW STATE COUNTRY
265
+						'new_state_country'           => new EE_Country_Select_Input(
266
+							$country_options,
267
+							array(
268
+								'html_name'       => $country_name,
269
+								'html_id'         => str_replace(
270
+									'state',
271
+									'nsmf_new_state_country', $input->html_id()
272
+								),
273
+								'html_class'      => $input->html_class() . ' new-state-country',
274
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
275
+								'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
276
+								'required'        => false,
277
+							)
278
+						),
279
+						// NEW STATE NAME
280
+						'new_state_name'              => new EE_Text_Input(
281
+							array(
282
+								'html_name'       => $state_name,
283
+								'html_id'         => str_replace(
284
+									'state',
285
+									'nsmf_new_state_name', $input->html_id()
286
+								),
287
+								'html_class'      => $input->html_class() . ' new-state-state',
288
+								'html_label_text' => esc_html__('New State/Province Name',
289
+									'event_espresso'),
290
+								'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
291
+								'required'        => false,
292
+							)
293
+						),
294
+						'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
295
+						// NEW STATE NAME
296
+						'new_state_abbrv'             => new EE_Text_Input(
297
+							array(
298
+								'html_name'             => $abbrv_name,
299
+								'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
300
+									$input->html_id()),
301
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
302
+								'html_label_text'       => esc_html__(
303
+									'New State/Province Abbreviation',
304
+									'event_espresso'
305
+								) . ' *',
306
+								'html_other_attributes' => 'size="24"',
307
+								'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
308
+								'required'              => false,
309
+							)
310
+						),
311
+						// "submit" button
312
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
313
+							apply_filters(
314
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
315
+								EEH_HTML::nbsp(3) .
316
+								EEH_HTML::link(
317
+									'',
318
+									esc_html__('ADD', 'event_espresso'),
319
+									'',
320
+									'submit-' . $new_state_submit_id,
321
+									'ee-form-add-new-state-submit button button-secondary',
322
+									'',
323
+									'data-target="' . $new_state_submit_id . '"'
324
+								)
325
+							)
326
+						),
327
+						// extra info
328
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
329
+							apply_filters(
330
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
331
+								EEH_HTML::br(2)
332
+								.
333
+								EEH_HTML::div('', '', 'small-text')
334
+								.
335
+								EEH_HTML::strong(
336
+									'* ' .
337
+									esc_html__(
338
+										'Don\'t know your State/Province Abbreviation?',
339
+										'event_espresso'
340
+									)
341
+								)
342
+								.
343
+								EEH_HTML::br()
344
+								.
345
+								sprintf(
346
+									esc_html__(
347
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
348
+										'event_espresso'
349
+									),
350
+									EEH_HTML::link(
351
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
352
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
353
+										'',
354
+										'',
355
+										'ee-form-add-new-state-wiki-lnk',
356
+										'',
357
+										'target="_blank"'
358
+									)
359
+								)
360
+								.
361
+								EEH_HTML::divx()
362
+								.
363
+								EEH_HTML::br()
364
+								.
365
+								EEH_HTML::link(
366
+									'',
367
+									esc_html__('cancel new State/Province', 'event_espresso'),
368
+									'',
369
+									'hide-' . $input->html_id(),
370
+									'ee-form-cancel-new-state-lnk smaller-text',
371
+									'',
372
+									'data-target="' . $input->html_id() . '"'
373
+								)
374
+								.
375
+								EEH_HTML::divx()
376
+								.
377
+								EEH_HTML::br()
378
+							)
379
+						),
380
+					),
381
+				)
382
+			);
383
+			$question_group_reg_form->add_subsections(
384
+				array('new_state_micro_form' => $new_state_micro_form),
385
+				'state',
386
+				false
387
+			);
388
+		}
389
+		return $question_group_reg_form;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * set_new_state_input_width
396
+	 *
397
+	 * @return int|string
398
+	 * @throws EE_Error
399
+	 */
400
+	public static function add_new_state()
401
+	{
402
+		$REQ = EE_Registry::instance()->load_core('Request_Handler');
403
+		if (absint($REQ->get('nsmf_add_new_state')) === 1) {
404
+			EE_Registry::instance()->load_model('State');
405
+			// grab country ISO code, new state name, and new state abbreviation
406
+			$state_country = $REQ->is_set('nsmf_new_state_country')
407
+				? sanitize_text_field($REQ->get('nsmf_new_state_country'))
408
+				: false;
409
+			$state_name = $REQ->is_set('nsmf_new_state_name')
410
+				? sanitize_text_field($REQ->get('nsmf_new_state_name'))
411
+				: false;
412
+			$state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
413
+				? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
414
+				: false;
415
+			if ($state_country && $state_name && $state_abbr) {
416
+				$new_state = EED_Add_New_State::save_new_state_to_db(array(
417
+					'CNT_ISO'    => strtoupper($state_country),
418
+					'STA_abbrev' => strtoupper($state_abbr),
419
+					'STA_name'   => ucwords($state_name),
420
+					'STA_active' => false,
421
+				));
422
+				if ($new_state instanceof EE_State) {
423
+					// clean house
424
+					EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
425
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
426
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
427
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
428
+					// get any existing new states
429
+					$new_states = EE_Registry::instance()->SSN->get_session_data(
430
+						'nsmf_new_states'
431
+					);
432
+					$new_states[$new_state->ID()] = $new_state;
433
+					EE_Registry::instance()->SSN->set_session_data(
434
+						array('nsmf_new_states' => $new_states)
435
+					);
436
+					if (EE_Registry::instance()->REQ->ajax) {
437
+						echo wp_json_encode(array(
438
+							'success'      => true,
439
+							'id'           => $new_state->ID(),
440
+							'name'         => $new_state->name(),
441
+							'abbrev'       => $new_state->abbrev(),
442
+							'country_iso'  => $new_state->country_iso(),
443
+							'country_name' => $new_state->country()->name(),
444
+						));
445
+						exit();
446
+					}
447
+					return $new_state->ID();
448
+				}
449
+			} else {
450
+				$error = esc_html__(
451
+					'A new State/Province could not be added because invalid or missing data was received.',
452
+					'event_espresso'
453
+				);
454
+				if (EE_Registry::instance()->REQ->ajax) {
455
+					echo wp_json_encode(array('error' => $error));
456
+					exit();
457
+				}
458
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
459
+			}
460
+		}
461
+		return false;
462
+	}
463
+
464
+
465
+
466
+	/**
467
+	 * recursively drills down through request params to remove any that were added by this module
468
+	 *
469
+	 * @param array $request_params
470
+	 * @return array
471
+	 */
472
+	public static function filter_checkout_request_params($request_params)
473
+	{
474
+		foreach ($request_params as $form_section) {
475
+			if (is_array($form_section)) {
476
+				EED_Add_New_State::unset_new_state_request_params($form_section);
477
+				EED_Add_New_State::filter_checkout_request_params($form_section);
478
+			}
479
+		}
480
+		return $request_params;
481
+	}
482
+
483
+
484
+
485
+	/**
486
+	 * @param array $request_params
487
+	 * @return array
488
+	 */
489
+	public static function unset_new_state_request_params($request_params)
490
+	{
491
+		unset(
492
+			$request_params['new_state_micro_form'],
493
+			$request_params['new_state_micro_add_new_state'],
494
+			$request_params['new_state_micro_new_state_country'],
495
+			$request_params['new_state_micro_new_state_name'],
496
+			$request_params['new_state_micro_new_state_abbrv']
497
+		);
498
+		return $request_params;
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * @param array $props_n_values
505
+	 * @return bool
506
+	 * @throws EE_Error
507
+	 */
508
+	public static function save_new_state_to_db($props_n_values = array())
509
+	{
510
+		$existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
511
+		if (! empty($existing_state)) {
512
+			return array_pop($existing_state);
513
+		}
514
+		$new_state = EE_State::new_instance($props_n_values);
515
+		if ($new_state instanceof EE_State) {
516
+			// if not non-ajax admin
517
+			$new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
518
+			$new_state_notice = sprintf(
519
+				esc_html__(
520
+					'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.',
521
+					'event_espresso'
522
+				),
523
+				'<b>' . $new_state->name() . '</b>',
524
+				'<b>' . $new_state->abbrev() . '</b>',
525
+				'<b>' . $new_state->country()->name() . '</b>',
526
+				'<a href="' . add_query_arg(array(
527
+					'page'    => 'espresso_general_settings',
528
+					'action'  => 'country_settings',
529
+					'country' => $new_state->country_iso(),
530
+				), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
531
+					'event_espresso') . '</a>',
532
+				'<br />'
533
+			);
534
+			EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
535
+			$new_state->save();
536
+			EEM_State::instance()->reset_cached_states();
537
+			return $new_state;
538
+		}
539
+		return false;
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * @param string $CNT_ISO
546
+	 * @param string $STA_ID
547
+	 * @param array  $cols_n_values
548
+	 * @return void
549
+	 */
550
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
551
+	{
552
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false;
553
+		if (! $CNT_ISO) {
554
+			EE_Error::add_error(
555
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
556
+				__FILE__,
557
+				__FUNCTION__,
558
+				__LINE__
559
+			);
560
+		}
561
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
562
+			: false;
563
+		if (! $STA_abbrev && ! empty($STA_ID)) {
564
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
565
+			if ($state instanceof EE_State) {
566
+				$STA_abbrev = $state->abbrev();
567
+			}
568
+		}
569
+		if (! $STA_abbrev) {
570
+			EE_Error::add_error(
571
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
572
+				__FILE__,
573
+				__FUNCTION__,
574
+				__LINE__
575
+			);
576
+		}
577
+		EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * @param EE_State[]                             $state_options
584
+	 * @param EE_SPCO_Reg_Step_Attendee_Information  $reg_step
585
+	 * @param EE_Registration                        $registration
586
+	 * @param EE_Question                            $question
587
+	 * @param                                        $answer
588
+	 * @return array
589
+	 */
590
+	public static function inject_new_reg_state_into_options(
591
+		$state_options = array(),
592
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
593
+		EE_Registration $registration,
594
+		EE_Question $question,
595
+		$answer
596
+	) {
597
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
598
+			&& $question->type()
599
+			   === EEM_Question::QST_type_state
600
+		) {
601
+			$STA_ID = $answer->value();
602
+			if (! empty($STA_ID)) {
603
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
604
+				if ($state instanceof EE_State) {
605
+					$country = $state->country();
606
+					if ($country instanceof EE_Country) {
607
+						if (! isset($state_options[$country->name()])) {
608
+							$state_options[$country->name()] = array();
609
+						}
610
+						if (! isset($state_options[$country->name()][$STA_ID])) {
611
+							$state_options[$country->name()][$STA_ID] = $state->name();
612
+						}
613
+					}
614
+				}
615
+			}
616
+		}
617
+		return $state_options;
618
+	}
619
+
620
+
621
+
622
+	/**
623
+	 * @param EE_Country[]                           $country_options
624
+	 * @param EE_SPCO_Reg_Step_Attendee_Information  $reg_step
625
+	 * @param EE_Registration                        $registration
626
+	 * @param EE_Question                            $question
627
+	 * @param                                        $answer
628
+	 * @return array
629
+	 */
630
+	public static function inject_new_reg_country_into_options(
631
+		$country_options = array(),
632
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
633
+		EE_Registration $registration,
634
+		EE_Question $question,
635
+		$answer
636
+	) {
637
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
638
+			&& $question->type()
639
+			   === EEM_Question::QST_type_country
640
+		) {
641
+			$CNT_ISO = $answer->value();
642
+			if (! empty($CNT_ISO)) {
643
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
644
+				if ($country instanceof EE_Country) {
645
+					if (! isset($country_options[$CNT_ISO])) {
646
+						$country_options[$CNT_ISO] = $country->name();
647
+					}
648
+				}
649
+			}
650
+		}
651
+		return $country_options;
652
+	}
653
+
654
+
655
+
656
+	/**
657
+	 * @param EE_State[] $state_options
658
+	 * @return array
659
+	 * @throws EE_Error
660
+	 */
661
+	public static function state_options($state_options = array())
662
+	{
663
+		$new_states = EED_Add_New_State::_get_new_states();
664
+		foreach ($new_states as $new_state) {
665
+			if (
666
+				$new_state instanceof EE_State
667
+				&& $new_state->country() instanceof EE_Country
668
+			) {
669
+				$state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
670
+			}
671
+		}
672
+		return $state_options;
673
+	}
674
+
675
+
676
+
677
+	/**
678
+	 * @return array
679
+	 */
680
+	protected static function _get_new_states()
681
+	{
682
+		$new_states = array();
683
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
684
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
685
+				'nsmf_new_states'
686
+			);
687
+		}
688
+		return is_array($new_states) ? $new_states : array();
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 * @param EE_Country[] $country_options
695
+	 * @return array
696
+	 * @throws EE_Error
697
+	 */
698
+	public static function country_options($country_options = array())
699
+	{
700
+		$new_states = EED_Add_New_State::_get_new_states();
701
+		foreach ($new_states as $new_state) {
702
+			if (
703
+				$new_state instanceof EE_State
704
+				&& $new_state->country() instanceof EE_Country
705
+			) {
706
+				$country_options[$new_state->country()->ID()] = $new_state->country()->name();
707
+			}
708
+		}
709
+		return $country_options;
710
+	}
711 711
 
712 712
 
713 713
 
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public static function set_definitions()
95 95
     {
96
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
96
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
97 97
         define('ANS_TEMPLATES_PATH', str_replace(
98 98
             '\\',
99
-            DS, plugin_dir_path(__FILE__)) . 'templates' . DS
99
+            DS, plugin_dir_path(__FILE__)).'templates'.DS
100 100
         );
101 101
     }
102 102
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     public static function wp_enqueue_scripts()
148 148
     {
149 149
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
150
-            wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js',
150
+            wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js',
151 151
                 array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true);
152 152
             wp_enqueue_script('add_new_state');
153 153
         }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
188 188
             $country_options = array();
189 189
             $countries = EEM_Country::instance()->get_all_countries();
190
-            if (! empty($countries)) {
190
+            if ( ! empty($countries)) {
191 191
                 foreach ($countries as $country) {
192 192
                     if ($country instanceof EE_Country) {
193 193
                         $country_options[$country->ID()] = $country->name();
@@ -222,10 +222,10 @@  discard block
 block discarded – undo
222 222
                                     '',
223 223
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
224 224
                                     '',
225
-                                    'display-' . $input->html_id(),
225
+                                    'display-'.$input->html_id(),
226 226
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
227 227
                                     '',
228
-                                    'data-target="' . $input->html_id() . '"'
228
+                                    'data-target="'.$input->html_id().'"'
229 229
                                 )
230 230
                             )
231 231
                         ),
@@ -233,31 +233,31 @@  discard block
 block discarded – undo
233 233
                         'add_new_state_micro_form'    => new EE_Form_Section_HTML(
234 234
                             apply_filters(
235 235
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
236
-                                EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv',
237
-                                    'display: none;') .
236
+                                EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv',
237
+                                    'display: none;').
238 238
                                 EEH_HTML::h6(
239 239
                                     esc_html__(
240 240
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
241 241
                                         'event_espresso'
242 242
                                     )
243
-                                ) .
244
-                                EEH_HTML::ul() .
243
+                                ).
244
+                                EEH_HTML::ul().
245 245
                                 EEH_HTML::li(
246 246
                                     esc_html__(
247 247
                                         'first select the Country that your State/Province belongs to',
248 248
                                         'event_espresso'
249 249
                                     )
250
-                                ) .
250
+                                ).
251 251
                                 EEH_HTML::li(
252 252
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
253
-                                ) .
253
+                                ).
254 254
                                 EEH_HTML::li(
255 255
                                     esc_html__(
256 256
                                         'enter a two to six letter abbreviation for the name of your State/Province',
257 257
                                         'event_espresso'
258 258
                                     )
259
-                                ) .
260
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
259
+                                ).
260
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
261 261
                                 EEH_HTML::ulx()
262 262
                             )
263 263
                         ),
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
                                     'state',
271 271
                                     'nsmf_new_state_country', $input->html_id()
272 272
                                 ),
273
-                                'html_class'      => $input->html_class() . ' new-state-country',
273
+                                'html_class'      => $input->html_class().' new-state-country',
274 274
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
275 275
                                 'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
276 276
                                 'required'        => false,
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
                                     'state',
285 285
                                     'nsmf_new_state_name', $input->html_id()
286 286
                                 ),
287
-                                'html_class'      => $input->html_class() . ' new-state-state',
287
+                                'html_class'      => $input->html_class().' new-state-state',
288 288
                                 'html_label_text' => esc_html__('New State/Province Name',
289 289
                                     'event_espresso'),
290 290
                                 'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
@@ -298,11 +298,11 @@  discard block
 block discarded – undo
298 298
                                 'html_name'             => $abbrv_name,
299 299
                                 'html_id'               => str_replace('state', 'nsmf_new_state_abbrv',
300 300
                                     $input->html_id()),
301
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
301
+                                'html_class'            => $input->html_class().' new-state-abbrv',
302 302
                                 'html_label_text'       => esc_html__(
303 303
                                     'New State/Province Abbreviation',
304 304
                                     'event_espresso'
305
-                                ) . ' *',
305
+                                ).' *',
306 306
                                 'html_other_attributes' => 'size="24"',
307 307
                                 'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
308 308
                                 'required'              => false,
@@ -312,15 +312,15 @@  discard block
 block discarded – undo
312 312
                         'add_new_state_submit_button' => new EE_Form_Section_HTML(
313 313
                             apply_filters(
314 314
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
315
-                                EEH_HTML::nbsp(3) .
315
+                                EEH_HTML::nbsp(3).
316 316
                                 EEH_HTML::link(
317 317
                                     '',
318 318
                                     esc_html__('ADD', 'event_espresso'),
319 319
                                     '',
320
-                                    'submit-' . $new_state_submit_id,
320
+                                    'submit-'.$new_state_submit_id,
321 321
                                     'ee-form-add-new-state-submit button button-secondary',
322 322
                                     '',
323
-                                    'data-target="' . $new_state_submit_id . '"'
323
+                                    'data-target="'.$new_state_submit_id.'"'
324 324
                                 )
325 325
                             )
326 326
                         ),
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                                 EEH_HTML::div('', '', 'small-text')
334 334
                                 .
335 335
                                 EEH_HTML::strong(
336
-                                    '* ' .
336
+                                    '* '.
337 337
                                     esc_html__(
338 338
                                         'Don\'t know your State/Province Abbreviation?',
339 339
                                         'event_espresso'
@@ -366,10 +366,10 @@  discard block
 block discarded – undo
366 366
                                     '',
367 367
                                     esc_html__('cancel new State/Province', 'event_espresso'),
368 368
                                     '',
369
-                                    'hide-' . $input->html_id(),
369
+                                    'hide-'.$input->html_id(),
370 370
                                     'ee-form-cancel-new-state-lnk smaller-text',
371 371
                                     '',
372
-                                    'data-target="' . $input->html_id() . '"'
372
+                                    'data-target="'.$input->html_id().'"'
373 373
                                 )
374 374
                                 .
375 375
                                 EEH_HTML::divx()
@@ -508,27 +508,27 @@  discard block
 block discarded – undo
508 508
     public static function save_new_state_to_db($props_n_values = array())
509 509
     {
510 510
         $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
511
-        if (! empty($existing_state)) {
511
+        if ( ! empty($existing_state)) {
512 512
             return array_pop($existing_state);
513 513
         }
514 514
         $new_state = EE_State::new_instance($props_n_values);
515 515
         if ($new_state instanceof EE_State) {
516 516
             // if not non-ajax admin
517
-            $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev();
517
+            $new_state_key = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev();
518 518
             $new_state_notice = sprintf(
519 519
                 esc_html__(
520 520
                     '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.',
521 521
                     'event_espresso'
522 522
                 ),
523
-                '<b>' . $new_state->name() . '</b>',
524
-                '<b>' . $new_state->abbrev() . '</b>',
525
-                '<b>' . $new_state->country()->name() . '</b>',
526
-                '<a href="' . add_query_arg(array(
523
+                '<b>'.$new_state->name().'</b>',
524
+                '<b>'.$new_state->abbrev().'</b>',
525
+                '<b>'.$new_state->country()->name().'</b>',
526
+                '<a href="'.add_query_arg(array(
527 527
                     'page'    => 'espresso_general_settings',
528 528
                     'action'  => 'country_settings',
529 529
                     'country' => $new_state->country_iso(),
530
-                ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab',
531
-                    'event_espresso') . '</a>',
530
+                ), admin_url('admin.php')).'">'.esc_html__('Event Espresso - General Settings > Countries Tab',
531
+                    'event_espresso').'</a>',
532 532
                 '<br />'
533 533
             );
534 534
             EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice);
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
551 551
     {
552 552
         $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false;
553
-        if (! $CNT_ISO) {
553
+        if ( ! $CNT_ISO) {
554 554
             EE_Error::add_error(
555 555
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
556 556
                 __FILE__,
@@ -560,13 +560,13 @@  discard block
 block discarded – undo
560 560
         }
561 561
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
562 562
             : false;
563
-        if (! $STA_abbrev && ! empty($STA_ID)) {
563
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
564 564
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
565 565
             if ($state instanceof EE_State) {
566 566
                 $STA_abbrev = $state->abbrev();
567 567
             }
568 568
         }
569
-        if (! $STA_abbrev) {
569
+        if ( ! $STA_abbrev) {
570 570
             EE_Error::add_error(
571 571
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
572 572
                 __FILE__,
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
                 __LINE__
575 575
             );
576 576
         }
577
-        EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true);
577
+        EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true);
578 578
     }
579 579
 
580 580
 
@@ -599,15 +599,15 @@  discard block
 block discarded – undo
599 599
                === EEM_Question::QST_type_state
600 600
         ) {
601 601
             $STA_ID = $answer->value();
602
-            if (! empty($STA_ID)) {
602
+            if ( ! empty($STA_ID)) {
603 603
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
604 604
                 if ($state instanceof EE_State) {
605 605
                     $country = $state->country();
606 606
                     if ($country instanceof EE_Country) {
607
-                        if (! isset($state_options[$country->name()])) {
607
+                        if ( ! isset($state_options[$country->name()])) {
608 608
                             $state_options[$country->name()] = array();
609 609
                         }
610
-                        if (! isset($state_options[$country->name()][$STA_ID])) {
610
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
611 611
                             $state_options[$country->name()][$STA_ID] = $state->name();
612 612
                         }
613 613
                     }
@@ -639,10 +639,10 @@  discard block
 block discarded – undo
639 639
                === EEM_Question::QST_type_country
640 640
         ) {
641 641
             $CNT_ISO = $answer->value();
642
-            if (! empty($CNT_ISO)) {
642
+            if ( ! empty($CNT_ISO)) {
643 643
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
644 644
                 if ($country instanceof EE_Country) {
645
-                    if (! isset($country_options[$CNT_ISO])) {
645
+                    if ( ! isset($country_options[$CNT_ISO])) {
646 646
                         $country_options[$CNT_ISO] = $country->name();
647 647
                     }
648 648
                 }
Please login to merge, or discard this patch.