Completed
Branch FET-10440-update-uxip-link (9b329d)
by
unknown
68:03 queued 57:45
created
modules/messages/EED_Messages.module.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -632,7 +632,7 @@
 block discarded – undo
632 632
      * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
633 633
      *                   or EEH_MSG_Template::convert_payment_status_to_message_type
634 634
      * @param string $payment_status The payment status being matched.
635
-     * @return bool|string The payment message type slug matching the status or false if no match.
635
+     * @return string|false The payment message type slug matching the status or false if no match.
636 636
      * @throws EE_Error
637 637
      * @throws InvalidArgumentException
638 638
      * @throws ReflectionException
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
             $error_msg = __('Please note that a system message failed to send due to a technical issue.',
160 160
                 'event_espresso');
161 161
             // add specific message for developers if WP_DEBUG in on
162
-            $error_msg .= '||' . $e->getMessage();
162
+            $error_msg .= '||'.$e->getMessage();
163 163
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
164 164
         }
165 165
     }
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             $error_msg = __('Please note that a system message failed to send due to a technical issue.',
243 243
                 'event_espresso');
244 244
             // add specific message for developers if WP_DEBUG in on
245
-            $error_msg .= '||' . $e->getMessage();
245
+            $error_msg .= '||'.$e->getMessage();
246 246
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
247 247
         }
248 248
     }
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         $transient_key = EE_Registry::instance()->REQ->get('key');
274 274
 
275 275
         //now let's verify transient, if not valid exit immediately
276
-        if (! get_transient($transient_key)) {
276
+        if ( ! get_transient($transient_key)) {
277 277
             /**
278 278
              * trigger error so this gets in the error logs.  This is important because it happens on a non-user
279 279
              * request.
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 
287 287
         if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
288 288
 
289
-            $method = 'batch_' . $cron_type . '_from_queue';
289
+            $method = 'batch_'.$cron_type.'_from_queue';
290 290
             if (method_exists(self::$_MSG_PROCESSOR, $method)) {
291 291
                 self::$_MSG_PROCESSOR->$method();
292 292
             } else {
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
             'messages/validators/html',
396 396
             'shortcodes',
397 397
         );
398
-        $paths   = array();
398
+        $paths = array();
399 399
         foreach ($dir_ref as $index => $dir) {
400
-            $paths[$index] = EE_LIBRARIES . $dir;
400
+            $paths[$index] = EE_LIBRARIES.$dir;
401 401
         }
402 402
         self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
403 403
     }
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      */
417 417
     protected static function _load_controller()
418 418
     {
419
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
419
+        if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
420 420
             EE_Registry::instance()->load_core('Request_Handler');
421 421
             self::set_autoloaders();
422 422
             self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
     public static function maybe_registration(EE_Registration $registration, $extra_details = array())
501 501
     {
502 502
 
503
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
503
+        if ( ! self::_verify_registration_notification_send($registration, $extra_details)) {
504 504
             //no messages please
505 505
             return;
506 506
         }
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
         //	array( '$extra_details' => $extra_details )
568 568
         //);
569 569
         // currently only using this to send messages for the primary registrant
570
-        if (! $registration->is_primary_registrant()) {
570
+        if ( ! $registration->is_primary_registrant()) {
571 571
             return false;
572 572
         }
573 573
         // first we check if we're in admin and not doing front ajax
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
         } else {
581 581
             // frontend request (either regular or via AJAX)
582 582
             // TXN is NOT finalized ?
583
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
583
+            if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
584 584
                 return false;
585 585
             }
586 586
             // return visit but nothing changed ???
@@ -670,12 +670,12 @@  discard block
 block discarded – undo
670 670
         }
671 671
 
672 672
         //make sure any incoming request data is set on the REQ so that it gets picked up later.
673
-        $req_data = (array)$req_data;
673
+        $req_data = (array) $req_data;
674 674
         foreach ($req_data as $request_key => $request_value) {
675 675
             EE_Registry::instance()->REQ->set($request_key, $request_value);
676 676
         }
677 677
 
678
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
678
+        if ( ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
679 679
             return false;
680 680
         }
681 681
 
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
         self::_load_controller();
709 709
 
710 710
         $msgID = EE_Registry::instance()->REQ->get('MSG_ID');
711
-        if (! $msgID) {
711
+        if ( ! $msgID) {
712 712
             EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
713 713
                 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
714 714
             return false;
715 715
         }
716 716
 
717
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
717
+        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
718 718
 
719 719
         //setup success message.
720 720
         $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
     public static function send_newsletter_message($registrations, $grp_id)
820 820
     {
821 821
         //make sure mtp is id and set it in the EE_Request Handler later messages setup.
822
-        EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
822
+        EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id);
823 823
         self::_load_controller();
824 824
         self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
825 825
     }
@@ -879,14 +879,14 @@  discard block
 block discarded – undo
879 879
             //get the message template group.
880 880
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
881 881
             //if we don't have an EE_Message_Template_Group then return
882
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
882
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
883 883
                 // remove EVT_ID from query params so that global templates get picked up
884 884
                 unset($template_query_params['Event.EVT_ID']);
885 885
                 //get global template as the fallback
886 886
                 $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
887 887
             }
888 888
             //if we don't have an EE_Message_Template_Group then return
889
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
889
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
890 890
                 return '';
891 891
             }
892 892
             // generate the URL
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
     public static function preview_message($type, $context, $messenger, $send = false)
924 924
     {
925 925
         self::_load_controller();
926
-        $mtg                     = new EE_Message_To_Generate(
926
+        $mtg = new EE_Message_To_Generate(
927 927
             $messenger,
928 928
             $type,
929 929
             array(),
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
     public static function generate_now($message_ids)
1006 1006
     {
1007 1007
         self::_load_controller();
1008
-        $messages        = EEM_Message::instance()->get_all(
1008
+        $messages = EEM_Message::instance()->get_all(
1009 1009
             array(
1010 1010
                 0 => array(
1011 1011
                     'MSG_ID' => array('IN', $message_ids),
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
             $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1019 1019
         }
1020 1020
 
1021
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1021
+        if ( ! $generated_queue instanceof EE_Messages_Queue) {
1022 1022
             EE_Error::add_error(
1023 1023
                 __('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.',
1024 1024
                     'event_espresso'),
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
     public static function send_now($message_ids)
1046 1046
     {
1047 1047
         self::_load_controller();
1048
-        $messages   = EEM_Message::instance()->get_all(
1048
+        $messages = EEM_Message::instance()->get_all(
1049 1049
             array(
1050 1050
                 0 => array(
1051 1051
                     'MSG_ID' => array('IN', $message_ids),
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
             $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1062 1062
         }
1063 1063
 
1064
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1064
+        if ( ! $sent_queue instanceof EE_Messages_Queue) {
1065 1065
             EE_Error::add_error(
1066 1066
                 __('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.',
1067 1067
                     'event_espresso'),
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
                 __FILE__, __FUNCTION__, __LINE__
1201 1201
             );
1202 1202
         }
1203
-        return (bool)$queue_count;
1203
+        return (bool) $queue_count;
1204 1204
     }
1205 1205
 
1206 1206
 
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
                 $info['TXN_status']    = $transaction->status_ID();
1232 1232
                 $info['TXN_reg_steps'] = $transaction->reg_steps();
1233 1233
                 if ($transaction->ID()) {
1234
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1234
+                    $index = 'EE_Transaction: '.$transaction->ID();
1235 1235
                     EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1236 1236
                 }
1237 1237
             }
Please login to merge, or discard this patch.
Indentation   +1233 added lines, -1233 removed lines patch added patch discarded remove patch
@@ -18,1248 +18,1248 @@
 block discarded – undo
18 18
 class EED_Messages extends EED_Module
19 19
 {
20 20
 
21
-    /**
22
-     * This holds the EE_messages controller
23
-     *
24
-     * @deprecated 4.9.0
25
-     * @var EE_messages $_EEMSG
26
-     */
27
-    protected static $_EEMSG;
28
-
29
-    /**
30
-     * @type EE_Message_Resource_Manager $_message_resource_manager
31
-     */
32
-    protected static $_message_resource_manager;
33
-
34
-    /**
35
-     * This holds the EE_Messages_Processor business class.
36
-     *
37
-     * @type EE_Messages_Processor
38
-     */
39
-    protected static $_MSG_PROCESSOR;
40
-
41
-    /**
42
-     * holds all the paths for various messages components.
43
-     * Utilized by autoloader registry
44
-     *
45
-     * @var array
46
-     */
47
-    protected static $_MSG_PATHS;
48
-
49
-
50
-    /**
51
-     * This will hold an array of messages template packs that are registered in the messages system.
52
-     * Format is:
53
-     * array(
54
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
55
-     * )
56
-     *
57
-     * @var EE_Messages_Template_Pack[]
58
-     */
59
-    protected static $_TMP_PACKS = array();
60
-
61
-
62
-    /**
63
-     * @return EED_Messages
64
-     */
65
-    public static function instance()
66
-    {
67
-        return parent::get_instance(__CLASS__);
68
-    }
69
-
70
-
71
-    /**
72
-     *  set_hooks - for hooking into EE Core, other modules, etc
73
-     *
74
-     * @since 4.5.0
75
-     * @return    void
76
-     */
77
-    public static function set_hooks()
78
-    {
79
-        //actions
80
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
82
-            array('EED_Messages', 'maybe_registration'), 10, 2);
83
-        //filters
84
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
85
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
86
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
87
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
88
-        //register routes
89
-        self::_register_routes();
90
-    }
91
-
92
-    /**
93
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
94
-     *
95
-     * @access    public
96
-     * @return    void
97
-     */
98
-    public static function set_hooks_admin()
99
-    {
100
-        //actions
101
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
102
-        add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
103
-            array('EED_Messages', 'payment_reminder'), 10);
104
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
105
-            array('EED_Messages', 'maybe_registration'), 10, 3);
106
-        add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
107
-            array('EED_Messages', 'send_newsletter_message'), 10, 2);
108
-        add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
109
-            array('EED_Messages', 'cancelled_registration'), 10);
110
-        add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
111
-            array('EED_Messages', 'process_admin_payment'), 10, 1);
112
-        //filters
113
-        add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
114
-            array('EED_Messages', 'process_resend'), 10, 2);
115
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
116
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
117
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
118
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
119
-    }
120
-
121
-
122
-    /**
123
-     * All the message triggers done by route go in here.
124
-     *
125
-     * @since 4.5.0
126
-     * @return void
127
-     */
128
-    protected static function _register_routes()
129
-    {
130
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
131
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
132
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
133
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
134
-        do_action('AHEE__EED_Messages___register_routes');
135
-    }
136
-
137
-
138
-    /**
139
-     * This is called when a browser display trigger is executed.
140
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
141
-     * browser.
142
-     *
143
-     * @since 4.9.0
144
-     * @param WP $WP
145
-     * @throws EE_Error
146
-     * @throws InvalidArgumentException
147
-     * @throws ReflectionException
148
-     * @throws InvalidDataTypeException
149
-     * @throws InvalidInterfaceException
150
-     */
151
-    public function browser_trigger($WP)
152
-    {
153
-        //ensure controller is loaded
154
-        self::_load_controller();
155
-        $token = EE_Registry::instance()->REQ->get('token');
156
-        try {
157
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
158
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
159
-        } catch (EE_Error $e) {
160
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
161
-                'event_espresso');
162
-            // add specific message for developers if WP_DEBUG in on
163
-            $error_msg .= '||' . $e->getMessage();
164
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
165
-        }
166
-    }
167
-
168
-
169
-    /**
170
-     * This is called when a browser error trigger is executed.
171
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
172
-     * message and display it.
173
-     *
174
-     * @since 4.9.0
175
-     * @param $WP
176
-     * @throws EE_Error
177
-     * @throws InvalidArgumentException
178
-     * @throws InvalidDataTypeException
179
-     * @throws InvalidInterfaceException
180
-     */
181
-    public function browser_error_trigger($WP)
182
-    {
183
-        $token = EE_Registry::instance()->REQ->get('token');
184
-        if ($token) {
185
-            $message = EEM_Message::instance()->get_one_by_token($token);
186
-            if ($message instanceof EE_Message) {
187
-                header('HTTP/1.1 200 OK');
188
-                $error_msg = nl2br($message->error_message());
189
-                ?>
21
+	/**
22
+	 * This holds the EE_messages controller
23
+	 *
24
+	 * @deprecated 4.9.0
25
+	 * @var EE_messages $_EEMSG
26
+	 */
27
+	protected static $_EEMSG;
28
+
29
+	/**
30
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
31
+	 */
32
+	protected static $_message_resource_manager;
33
+
34
+	/**
35
+	 * This holds the EE_Messages_Processor business class.
36
+	 *
37
+	 * @type EE_Messages_Processor
38
+	 */
39
+	protected static $_MSG_PROCESSOR;
40
+
41
+	/**
42
+	 * holds all the paths for various messages components.
43
+	 * Utilized by autoloader registry
44
+	 *
45
+	 * @var array
46
+	 */
47
+	protected static $_MSG_PATHS;
48
+
49
+
50
+	/**
51
+	 * This will hold an array of messages template packs that are registered in the messages system.
52
+	 * Format is:
53
+	 * array(
54
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
55
+	 * )
56
+	 *
57
+	 * @var EE_Messages_Template_Pack[]
58
+	 */
59
+	protected static $_TMP_PACKS = array();
60
+
61
+
62
+	/**
63
+	 * @return EED_Messages
64
+	 */
65
+	public static function instance()
66
+	{
67
+		return parent::get_instance(__CLASS__);
68
+	}
69
+
70
+
71
+	/**
72
+	 *  set_hooks - for hooking into EE Core, other modules, etc
73
+	 *
74
+	 * @since 4.5.0
75
+	 * @return    void
76
+	 */
77
+	public static function set_hooks()
78
+	{
79
+		//actions
80
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
82
+			array('EED_Messages', 'maybe_registration'), 10, 2);
83
+		//filters
84
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
85
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
86
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
87
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
88
+		//register routes
89
+		self::_register_routes();
90
+	}
91
+
92
+	/**
93
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
94
+	 *
95
+	 * @access    public
96
+	 * @return    void
97
+	 */
98
+	public static function set_hooks_admin()
99
+	{
100
+		//actions
101
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
102
+		add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
103
+			array('EED_Messages', 'payment_reminder'), 10);
104
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
105
+			array('EED_Messages', 'maybe_registration'), 10, 3);
106
+		add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
107
+			array('EED_Messages', 'send_newsletter_message'), 10, 2);
108
+		add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
109
+			array('EED_Messages', 'cancelled_registration'), 10);
110
+		add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
111
+			array('EED_Messages', 'process_admin_payment'), 10, 1);
112
+		//filters
113
+		add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
114
+			array('EED_Messages', 'process_resend'), 10, 2);
115
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
116
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
117
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
118
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
119
+	}
120
+
121
+
122
+	/**
123
+	 * All the message triggers done by route go in here.
124
+	 *
125
+	 * @since 4.5.0
126
+	 * @return void
127
+	 */
128
+	protected static function _register_routes()
129
+	{
130
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
131
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
132
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
133
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
134
+		do_action('AHEE__EED_Messages___register_routes');
135
+	}
136
+
137
+
138
+	/**
139
+	 * This is called when a browser display trigger is executed.
140
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
141
+	 * browser.
142
+	 *
143
+	 * @since 4.9.0
144
+	 * @param WP $WP
145
+	 * @throws EE_Error
146
+	 * @throws InvalidArgumentException
147
+	 * @throws ReflectionException
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws InvalidInterfaceException
150
+	 */
151
+	public function browser_trigger($WP)
152
+	{
153
+		//ensure controller is loaded
154
+		self::_load_controller();
155
+		$token = EE_Registry::instance()->REQ->get('token');
156
+		try {
157
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
158
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
159
+		} catch (EE_Error $e) {
160
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
161
+				'event_espresso');
162
+			// add specific message for developers if WP_DEBUG in on
163
+			$error_msg .= '||' . $e->getMessage();
164
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
165
+		}
166
+	}
167
+
168
+
169
+	/**
170
+	 * This is called when a browser error trigger is executed.
171
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
172
+	 * message and display it.
173
+	 *
174
+	 * @since 4.9.0
175
+	 * @param $WP
176
+	 * @throws EE_Error
177
+	 * @throws InvalidArgumentException
178
+	 * @throws InvalidDataTypeException
179
+	 * @throws InvalidInterfaceException
180
+	 */
181
+	public function browser_error_trigger($WP)
182
+	{
183
+		$token = EE_Registry::instance()->REQ->get('token');
184
+		if ($token) {
185
+			$message = EEM_Message::instance()->get_one_by_token($token);
186
+			if ($message instanceof EE_Message) {
187
+				header('HTTP/1.1 200 OK');
188
+				$error_msg = nl2br($message->error_message());
189
+				?>
190 190
                 <!DOCTYPE html>
191 191
                 <html>
192 192
                 <head></head>
193 193
                 <body>
194 194
                 <?php echo empty($error_msg)
195
-                    ? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
196
-                        'event_espresso')
197
-                    : wp_kses(
198
-                        $error_msg,
199
-                        array(
200
-                            'a'      => array(
201
-                                'href'  => array(),
202
-                                'title' => array(),
203
-                            ),
204
-                            'span'   => array(),
205
-                            'div'    => array(),
206
-                            'p'      => array(),
207
-                            'strong' => array(),
208
-                            'em'     => array(),
209
-                            'br'     => array(),
210
-                        )
211
-                    ); ?>
195
+					? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
196
+						'event_espresso')
197
+					: wp_kses(
198
+						$error_msg,
199
+						array(
200
+							'a'      => array(
201
+								'href'  => array(),
202
+								'title' => array(),
203
+							),
204
+							'span'   => array(),
205
+							'div'    => array(),
206
+							'p'      => array(),
207
+							'strong' => array(),
208
+							'em'     => array(),
209
+							'br'     => array(),
210
+						)
211
+					); ?>
212 212
                 </body>
213 213
                 </html>
214 214
                 <?php
215
-                exit;
216
-            }
217
-        }
218
-        return;
219
-    }
220
-
221
-
222
-    /**
223
-     *  This runs when the msg_url_trigger route has initiated.
224
-     *
225
-     * @since 4.5.0
226
-     * @param WP $WP
227
-     * @throws EE_Error
228
-     * @throws InvalidArgumentException
229
-     * @throws ReflectionException
230
-     * @throws InvalidDataTypeException
231
-     * @throws InvalidInterfaceException
232
-     */
233
-    public function run($WP)
234
-    {
235
-        //ensure controller is loaded
236
-        self::_load_controller();
237
-        // attempt to process message
238
-        try {
239
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
240
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
241
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
242
-        } catch (EE_Error $e) {
243
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
244
-                'event_espresso');
245
-            // add specific message for developers if WP_DEBUG in on
246
-            $error_msg .= '||' . $e->getMessage();
247
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
248
-        }
249
-    }
250
-
251
-
252
-    /**
253
-     * This is triggered by the 'msg_cron_trigger' route.
254
-     *
255
-     * @param WP $WP
256
-     */
257
-    public function execute_batch_request($WP)
258
-    {
259
-        $this->run_cron();
260
-        header('HTTP/1.1 200 OK');
261
-        exit();
262
-    }
263
-
264
-
265
-    /**
266
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
267
-     * request.
268
-     */
269
-    public function run_cron()
270
-    {
271
-        self::_load_controller();
272
-        //get required vars
273
-        $cron_type     = EE_Registry::instance()->REQ->get('type');
274
-        $transient_key = EE_Registry::instance()->REQ->get('key');
275
-
276
-        //now let's verify transient, if not valid exit immediately
277
-        if (! get_transient($transient_key)) {
278
-            /**
279
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user
280
-             * request.
281
-             */
282
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
283
-        }
284
-
285
-        //if made it here, lets' delete the transient to keep the db clean
286
-        delete_transient($transient_key);
287
-
288
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
289
-
290
-            $method = 'batch_' . $cron_type . '_from_queue';
291
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
292
-                self::$_MSG_PROCESSOR->$method();
293
-            } else {
294
-                //no matching task
295
-                /**
296
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user
297
-                 * request.
298
-                 */
299
-                trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
300
-                    $cron_type)));
301
-            }
302
-        }
303
-
304
-        do_action('FHEE__EED_Messages__run_cron__end');
305
-    }
306
-
307
-
308
-    /**
309
-     * This is used to retrieve the template pack for the given name.
310
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
311
-     * the default template pack is returned.
312
-     *
313
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
314
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
315
-     *                                   in generating the Pack class name).
316
-     * @return EE_Messages_Template_Pack
317
-     * @throws EE_Error
318
-     * @throws InvalidArgumentException
319
-     * @throws ReflectionException
320
-     * @throws InvalidDataTypeException
321
-     * @throws InvalidInterfaceException
322
-     */
323
-    public static function get_template_pack($template_pack_name)
324
-    {
325
-        EE_Registry::instance()->load_helper('MSG_Template');
326
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
327
-    }
328
-
329
-
330
-    /**
331
-     * Retrieves an array of all template packs.
332
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
333
-     *
334
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
335
-     * @return EE_Messages_Template_Pack[]
336
-     * @throws EE_Error
337
-     * @throws InvalidArgumentException
338
-     * @throws ReflectionException
339
-     * @throws InvalidDataTypeException
340
-     * @throws InvalidInterfaceException
341
-     */
342
-    public static function get_template_packs()
343
-    {
344
-        EE_Registry::instance()->load_helper('MSG_Template');
345
-
346
-        //for backward compat, let's make sure this returns in the same format as originally.
347
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
348
-        $template_pack_collection->rewind();
349
-        $template_packs = array();
350
-        while ($template_pack_collection->valid()) {
351
-            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
352
-            $template_pack_collection->next();
353
-        }
354
-        return $template_packs;
355
-    }
356
-
357
-
358
-    /**
359
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
360
-     *
361
-     * @since 4.5.0
362
-     * @return void
363
-     * @throws EE_Error
364
-     */
365
-    public static function set_autoloaders()
366
-    {
367
-        if (empty(self::$_MSG_PATHS)) {
368
-            self::_set_messages_paths();
369
-            foreach (self::$_MSG_PATHS as $path) {
370
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
371
-            }
372
-            // add aliases
373
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
374
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
375
-        }
376
-    }
377
-
378
-
379
-    /**
380
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
381
-     * for use by the Messages Autoloaders
382
-     *
383
-     * @since 4.5.0
384
-     * @return void.
385
-     */
386
-    protected static function _set_messages_paths()
387
-    {
388
-        $dir_ref = array(
389
-            'messages/message_type',
390
-            'messages/messenger',
391
-            'messages/defaults',
392
-            'messages/defaults/email',
393
-            'messages/data_class',
394
-            'messages/validators',
395
-            'messages/validators/email',
396
-            'messages/validators/html',
397
-            'shortcodes',
398
-        );
399
-        $paths   = array();
400
-        foreach ($dir_ref as $index => $dir) {
401
-            $paths[$index] = EE_LIBRARIES . $dir;
402
-        }
403
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
404
-    }
405
-
406
-
407
-    /**
408
-     * Takes care of loading dependencies
409
-     *
410
-     * @since 4.5.0
411
-     * @return void
412
-     * @throws EE_Error
413
-     * @throws InvalidArgumentException
414
-     * @throws ReflectionException
415
-     * @throws InvalidDataTypeException
416
-     * @throws InvalidInterfaceException
417
-     */
418
-    protected static function _load_controller()
419
-    {
420
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
421
-            EE_Registry::instance()->load_core('Request_Handler');
422
-            self::set_autoloaders();
423
-            self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
424
-            self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
425
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
426
-        }
427
-    }
428
-
429
-
430
-    /**
431
-     * @param EE_Transaction $transaction
432
-     * @throws EE_Error
433
-     * @throws InvalidArgumentException
434
-     * @throws InvalidDataTypeException
435
-     * @throws InvalidInterfaceException
436
-     * @throws ReflectionException
437
-     */
438
-    public static function payment_reminder(EE_Transaction $transaction)
439
-    {
440
-        self::_load_controller();
441
-        $data = array($transaction, null);
442
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
443
-    }
444
-
445
-
446
-    /**
447
-     * Any messages triggers for after successful gateway payments should go in here.
448
-     *
449
-     * @param EE_Transaction $transaction object
450
-     * @param EE_Payment     $payment     object
451
-     * @return void
452
-     * @throws EE_Error
453
-     * @throws InvalidArgumentException
454
-     * @throws ReflectionException
455
-     * @throws InvalidDataTypeException
456
-     * @throws InvalidInterfaceException
457
-     */
458
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment)
459
-    {
460
-        self::_load_controller();
461
-        $data = array($transaction, $payment);
462
-        EE_Registry::instance()->load_helper('MSG_Template');
463
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
464
-        //if payment amount is less than 0 then switch to payment_refund message type.
465
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
466
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
467
-    }
468
-
469
-
470
-    /**
471
-     * @param EE_Transaction $transaction
472
-     * @throws EE_Error
473
-     * @throws InvalidArgumentException
474
-     * @throws InvalidDataTypeException
475
-     * @throws InvalidInterfaceException
476
-     * @throws ReflectionException
477
-     */
478
-    public static function cancelled_registration(EE_Transaction $transaction)
479
-    {
480
-        self::_load_controller();
481
-        $data = array($transaction, null);
482
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
483
-    }
484
-
485
-
486
-
487
-    /**
488
-     * Trigger for Registration messages
489
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
490
-     * incoming transaction.
491
-     *
492
-     * @param EE_Registration $registration
493
-     * @param array           $extra_details
494
-     * @return void
495
-     * @throws EE_Error
496
-     * @throws InvalidArgumentException
497
-     * @throws InvalidDataTypeException
498
-     * @throws InvalidInterfaceException
499
-     * @throws ReflectionException
500
-     * @throws EntityNotFoundException
501
-     */
502
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
503
-    {
504
-
505
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
506
-            //no messages please
507
-            return;
508
-        }
509
-
510
-        // get all non-trashed registrations so we make sure we send messages for the right status.
511
-        $all_registrations = $registration->transaction()->registrations(
512
-            array(
513
-                array('REG_deleted' => false),
514
-                'order_by' => array(
515
-                    'Event.EVT_name'     => 'ASC',
516
-                    'Attendee.ATT_lname' => 'ASC',
517
-                    'Attendee.ATT_fname' => 'ASC'
518
-                )
519
-            )
520
-        );
521
-        //cached array of statuses so we only trigger messages once per status.
522
-        $statuses_sent = array();
523
-        self::_load_controller();
524
-        $mtgs = array();
525
-
526
-        //loop through registrations and trigger messages once per status.
527
-        foreach ($all_registrations as $reg) {
528
-
529
-            //already triggered?
530
-            if (in_array($reg->status_ID(), $statuses_sent)) {
531
-                continue;
532
-            }
533
-
534
-            $message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
535
-            $mtgs            = array_merge(
536
-                    $mtgs,
537
-                    self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
538
-                            $message_type,
539
-                            array($registration->transaction(), null, $reg->status_ID())
540
-                    )
541
-            );
542
-            $statuses_sent[] = $reg->status_ID();
543
-        }
544
-
545
-        if (count($statuses_sent) > 1) {
546
-            $mtgs = array_merge(
547
-                $mtgs,
548
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
549
-                    'registration_summary',
550
-                    array($registration->transaction(), null)
551
-                )
552
-            );
553
-        }
554
-
555
-        //batch queue and initiate request
556
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
557
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
558
-    }
559
-
560
-
561
-    /**
562
-     * This is a helper method used to very whether a registration notification should be sent or
563
-     * not.  Prevents duplicate notifications going out for registration context notifications.
564
-     *
565
-     * @param EE_Registration $registration  [description]
566
-     * @param array           $extra_details [description]
567
-     * @return bool          true = send away, false = nope halt the presses.
568
-     */
569
-    protected static function _verify_registration_notification_send(
570
-        EE_Registration $registration,
571
-        $extra_details = array()
572
-    ) {
573
-        //self::log(
574
-        //	__CLASS__, __FUNCTION__, __LINE__,
575
-        //	$registration->transaction(),
576
-        //	array( '$extra_details' => $extra_details )
577
-        //);
578
-        // currently only using this to send messages for the primary registrant
579
-        if (! $registration->is_primary_registrant()) {
580
-            return false;
581
-        }
582
-        // first we check if we're in admin and not doing front ajax
583
-        if (is_admin() && ! EE_FRONT_AJAX) {
584
-            //make sure appropriate admin params are set for sending messages
585
-            if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
586
-                //no messages sent please.
587
-                return false;
588
-            }
589
-        } else {
590
-            // frontend request (either regular or via AJAX)
591
-            // TXN is NOT finalized ?
592
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
593
-                return false;
594
-            }
595
-            // return visit but nothing changed ???
596
-            if (
597
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
598
-                $extra_details['revisit'] && ! $extra_details['status_updates']
599
-            ) {
600
-                return false;
601
-            }
602
-            // NOT sending messages && reg status is something other than "Not-Approved"
603
-            if (
604
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
605
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
606
-            ) {
607
-                return false;
608
-            }
609
-        }
610
-        // release the kraken
611
-        return true;
612
-    }
613
-
614
-
615
-    /**
616
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
617
-     * status id.
618
-     *
619
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
620
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
621
-     * @param string $reg_status
622
-     * @return array
623
-     * @throws EE_Error
624
-     * @throws InvalidArgumentException
625
-     * @throws ReflectionException
626
-     * @throws InvalidDataTypeException
627
-     * @throws InvalidInterfaceException
628
-     */
629
-    protected static function _get_reg_status_array($reg_status = '')
630
-    {
631
-        EE_Registry::instance()->load_helper('MSG_Template');
632
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
633
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
634
-            : EEH_MSG_Template::reg_status_to_message_type_array();
635
-    }
636
-
637
-
638
-    /**
639
-     * Simply returns the payment message type for the given payment status.
640
-     *
641
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
642
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
643
-     * @param string $payment_status The payment status being matched.
644
-     * @return bool|string The payment message type slug matching the status or false if no match.
645
-     * @throws EE_Error
646
-     * @throws InvalidArgumentException
647
-     * @throws ReflectionException
648
-     * @throws InvalidDataTypeException
649
-     * @throws InvalidInterfaceException
650
-     */
651
-    protected static function _get_payment_message_type($payment_status)
652
-    {
653
-        EE_Registry::instance()->load_helper('MSG_Template');
654
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
655
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
656
-            : false;
657
-    }
658
-
659
-
660
-    /**
661
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
662
-     *
663
-     * @access public
664
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
665
-     * @return bool success/fail
666
-     * @throws EE_Error
667
-     * @throws InvalidArgumentException
668
-     * @throws InvalidDataTypeException
669
-     * @throws InvalidInterfaceException
670
-     * @throws ReflectionException
671
-     */
672
-    public static function process_resend($req_data)
673
-    {
674
-        self::_load_controller();
675
-
676
-        //if $msgID in this request then skip to the new resend_message
677
-        if (EE_Registry::instance()->REQ->get('MSG_ID')) {
678
-            return self::resend_message();
679
-        }
680
-
681
-        //make sure any incoming request data is set on the REQ so that it gets picked up later.
682
-        $req_data = (array)$req_data;
683
-        foreach ($req_data as $request_key => $request_value) {
684
-            EE_Registry::instance()->REQ->set($request_key, $request_value);
685
-        }
686
-
687
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
688
-            return false;
689
-        }
690
-
691
-        try {
692
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
693
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
694
-        } catch (EE_Error $e) {
695
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
696
-            return false;
697
-        }
698
-        EE_Error::add_success(
699
-            __('Messages have been successfully queued for generation and sending.', 'event_espresso')
700
-        );
701
-        return true; //everything got queued.
702
-    }
703
-
704
-
705
-    /**
706
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
707
-     *
708
-     * @return bool
709
-     * @throws EE_Error
710
-     * @throws InvalidArgumentException
711
-     * @throws InvalidDataTypeException
712
-     * @throws InvalidInterfaceException
713
-     * @throws ReflectionException
714
-     */
715
-    public static function resend_message()
716
-    {
717
-        self::_load_controller();
718
-
719
-        $msgID = EE_Registry::instance()->REQ->get('MSG_ID');
720
-        if (! $msgID) {
721
-            EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
722
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
723
-            return false;
724
-        }
725
-
726
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
727
-
728
-        //setup success message.
729
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
730
-        EE_Error::add_success(sprintf(
731
-            _n(
732
-                'There was %d message queued for resending.',
733
-                'There were %d messages queued for resending.',
734
-                $count_ready_for_resend,
735
-                'event_espresso'
736
-            ),
737
-            $count_ready_for_resend
738
-        ));
739
-        return true;
740
-    }
741
-
742
-
743
-    /**
744
-     * Message triggers for manual payment applied by admin
745
-     *
746
-     * @param  EE_Payment $payment EE_payment object
747
-     * @return bool success/fail
748
-     * @throws EE_Error
749
-     * @throws InvalidArgumentException
750
-     * @throws ReflectionException
751
-     * @throws InvalidDataTypeException
752
-     * @throws InvalidInterfaceException
753
-     */
754
-    public static function process_admin_payment(EE_Payment $payment)
755
-    {
756
-        EE_Registry::instance()->load_helper('MSG_Template');
757
-        //we need to get the transaction object
758
-        $transaction = $payment->transaction();
759
-        if ($transaction instanceof EE_Transaction) {
760
-            $data         = array($transaction, $payment);
761
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
762
-
763
-            //if payment amount is less than 0 then switch to payment_refund message type.
764
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
765
-
766
-            //if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
767
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
768
-
769
-            self::_load_controller();
770
-
771
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
772
-
773
-            //get count of queued for generation
774
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
775
-                EEM_Message::status_incomplete,
776
-                EEM_Message::status_idle,
777
-            ));
778
-
779
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
780
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
781
-                return true;
782
-            } else {
783
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
784
-                /**
785
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
786
-                 * IMMEDIATE generation.
787
-                 */
788
-                if ($count_failed > 0) {
789
-                    EE_Error::add_error(sprintf(
790
-                        _n(
791
-                            'The payment notification generation failed.',
792
-                            '%d payment notifications failed being sent.',
793
-                            $count_failed,
794
-                            'event_espresso'
795
-                        ),
796
-                        $count_failed
797
-                    ), __FILE__, __FUNCTION__, __LINE__);
798
-
799
-                    return false;
800
-                } else {
801
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
802
-                    return true;
803
-                }
804
-            }
805
-        } else {
806
-            EE_Error::add_error(
807
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
808
-                'event_espresso'
809
-            );
810
-            return false;
811
-        }
812
-    }
813
-
814
-
815
-    /**
816
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
817
-     *
818
-     * @since   4.3.0
819
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
820
-     * @param  int               $grp_id        a specific message template group id.
821
-     * @return void
822
-     * @throws EE_Error
823
-     * @throws InvalidArgumentException
824
-     * @throws InvalidDataTypeException
825
-     * @throws InvalidInterfaceException
826
-     * @throws ReflectionException
827
-     */
828
-    public static function send_newsletter_message($registrations, $grp_id)
829
-    {
830
-        //make sure mtp is id and set it in the EE_Request Handler later messages setup.
831
-        EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
832
-        self::_load_controller();
833
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
834
-    }
835
-
836
-
837
-    /**
838
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
839
-     *
840
-     * @since   4.3.0
841
-     * @param    string          $registration_message_trigger_url
842
-     * @param    EE_Registration $registration
843
-     * @param string             $messenger
844
-     * @param string             $message_type
845
-     * @return string
846
-     * @throws EE_Error
847
-     * @throws InvalidArgumentException
848
-     * @throws InvalidDataTypeException
849
-     * @throws InvalidInterfaceException
850
-     */
851
-    public static function registration_message_trigger_url(
852
-        $registration_message_trigger_url,
853
-        EE_Registration $registration,
854
-        $messenger = 'html',
855
-        $message_type = 'invoice'
856
-    ) {
857
-        // whitelist $messenger
858
-        switch ($messenger) {
859
-            case 'pdf' :
860
-                $sending_messenger    = 'pdf';
861
-                $generating_messenger = 'html';
862
-                break;
863
-            case 'html' :
864
-            default :
865
-                $sending_messenger    = 'html';
866
-                $generating_messenger = 'html';
867
-                break;
868
-        }
869
-        // whitelist $message_type
870
-        switch ($message_type) {
871
-            case 'receipt' :
872
-                $message_type = 'receipt';
873
-                break;
874
-            case 'invoice' :
875
-            default :
876
-                $message_type = 'invoice';
877
-                break;
878
-        }
879
-        // verify that both the messenger AND the message type are active
880
-        if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
881
-            //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?)
882
-            $template_query_params = array(
883
-                'MTP_is_active'    => true,
884
-                'MTP_messenger'    => $generating_messenger,
885
-                'MTP_message_type' => $message_type,
886
-                'Event.EVT_ID'     => $registration->event_ID(),
887
-            );
888
-            //get the message template group.
889
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
890
-            //if we don't have an EE_Message_Template_Group then return
891
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
892
-                // remove EVT_ID from query params so that global templates get picked up
893
-                unset($template_query_params['Event.EVT_ID']);
894
-                //get global template as the fallback
895
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
896
-            }
897
-            //if we don't have an EE_Message_Template_Group then return
898
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
899
-                return '';
900
-            }
901
-            // generate the URL
902
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
903
-                $sending_messenger,
904
-                $generating_messenger,
905
-                'purchaser',
906
-                $message_type,
907
-                $registration,
908
-                $msg_template_group->ID(),
909
-                $registration->transaction_ID()
910
-            );
911
-
912
-        }
913
-        return $registration_message_trigger_url;
914
-    }
915
-
916
-
917
-    /**
918
-     * Use to generate and return a message preview!
919
-     *
920
-     * @param  string $type      This should correspond with a valid message type
921
-     * @param  string $context   This should correspond with a valid context for the message type
922
-     * @param  string $messenger This should correspond with a valid messenger.
923
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
924
-     *                           preview
925
-     * @return bool|string The body of the message or if send is requested, sends.
926
-     * @throws EE_Error
927
-     * @throws InvalidArgumentException
928
-     * @throws InvalidDataTypeException
929
-     * @throws InvalidInterfaceException
930
-     * @throws ReflectionException
931
-     */
932
-    public static function preview_message($type, $context, $messenger, $send = false)
933
-    {
934
-        self::_load_controller();
935
-        $mtg                     = new EE_Message_To_Generate(
936
-            $messenger,
937
-            $type,
938
-            array(),
939
-            $context,
940
-            true
941
-        );
942
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
943
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
944
-            //loop through all content for the preview and remove any persisted records.
945
-            $content = '';
946
-            foreach ($generated_preview_queue->get_message_repository() as $message) {
947
-                $content = $message->content();
948
-                if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
949
-                    $message->delete();
950
-                }
951
-            }
952
-            return $content;
953
-        } else {
954
-            return $generated_preview_queue;
955
-        }
956
-    }
957
-
958
-
959
-    /**
960
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
961
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
962
-     * content found in the EE_Message objects in the queue.
963
-     *
964
-     * @since 4.9.0
965
-     * @param string            $messenger            a string matching a valid active messenger in the system
966
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
967
-     *                                                type name is still required to send along the message type to the
968
-     *                                                messenger because this is used for determining what specific
969
-     *                                                variations might be loaded for the generated message.
970
-     * @param EE_Messages_Queue $queue
971
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
972
-     *                                                aggregate EE_Message object.
973
-     * @return bool success or fail.
974
-     * @throws EE_Error
975
-     * @throws InvalidArgumentException
976
-     * @throws ReflectionException
977
-     * @throws InvalidDataTypeException
978
-     * @throws InvalidInterfaceException
979
-     */
980
-    public static function send_message_with_messenger_only(
981
-        $messenger,
982
-        $message_type,
983
-        EE_Messages_Queue $queue,
984
-        $custom_subject = ''
985
-    ) {
986
-        self::_load_controller();
987
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
988
-        $message_to_generate = EE_Registry::instance()->load_lib(
989
-            'Message_To_Generate_From_Queue',
990
-            array(
991
-                $messenger,
992
-                $message_type,
993
-                $queue,
994
-                $custom_subject,
995
-            )
996
-        );
997
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1003
-     *
1004
-     * @since 4.9.0
1005
-     * @param array $message_ids An array of message ids
1006
-     * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1007
-     *                           messages.
1008
-     * @throws EE_Error
1009
-     * @throws InvalidArgumentException
1010
-     * @throws InvalidDataTypeException
1011
-     * @throws InvalidInterfaceException
1012
-     * @throws ReflectionException
1013
-     */
1014
-    public static function generate_now($message_ids)
1015
-    {
1016
-        self::_load_controller();
1017
-        $messages        = EEM_Message::instance()->get_all(
1018
-            array(
1019
-                0 => array(
1020
-                    'MSG_ID' => array('IN', $message_ids),
1021
-                    'STS_ID' => EEM_Message::status_incomplete,
1022
-                ),
1023
-            )
1024
-        );
1025
-        $generated_queue = false;
1026
-        if ($messages) {
1027
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1028
-        }
1029
-
1030
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1031
-            EE_Error::add_error(
1032
-                __('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.',
1033
-                    'event_espresso'),
1034
-                __FILE__, __FUNCTION__, __LINE__
1035
-            );
1036
-        }
1037
-        return $generated_queue;
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1043
-     * EEM_Message::status_idle
1044
-     *
1045
-     * @since 4.9.0
1046
-     * @param $message_ids
1047
-     * @return bool|EE_Messages_Queue false if no messages sent.
1048
-     * @throws EE_Error
1049
-     * @throws InvalidArgumentException
1050
-     * @throws InvalidDataTypeException
1051
-     * @throws InvalidInterfaceException
1052
-     * @throws ReflectionException
1053
-     */
1054
-    public static function send_now($message_ids)
1055
-    {
1056
-        self::_load_controller();
1057
-        $messages   = EEM_Message::instance()->get_all(
1058
-            array(
1059
-                0 => array(
1060
-                    'MSG_ID' => array('IN', $message_ids),
1061
-                    'STS_ID' => array(
1062
-                        'IN',
1063
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1064
-                    ),
1065
-                ),
1066
-            )
1067
-        );
1068
-        $sent_queue = false;
1069
-        if ($messages) {
1070
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1071
-        }
1072
-
1073
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1074
-            EE_Error::add_error(
1075
-                __('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.',
1076
-                    'event_espresso'),
1077
-                __FILE__, __FUNCTION__, __LINE__
1078
-            );
1079
-        } else {
1080
-            //can count how many sent by using the messages in the queue
1081
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1082
-            if ($sent_count > 0) {
1083
-                EE_Error::add_success(
1084
-                    sprintf(
1085
-                        _n(
1086
-                            'There was %d message successfully sent.',
1087
-                            'There were %d messages successfully sent.',
1088
-                            $sent_count,
1089
-                            'event_espresso'
1090
-                        ),
1091
-                        $sent_count
1092
-                    )
1093
-                );
1094
-            } else {
1095
-                EE_Error::overwrite_errors();
1096
-                EE_Error::add_error(
1097
-                    __('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.
215
+				exit;
216
+			}
217
+		}
218
+		return;
219
+	}
220
+
221
+
222
+	/**
223
+	 *  This runs when the msg_url_trigger route has initiated.
224
+	 *
225
+	 * @since 4.5.0
226
+	 * @param WP $WP
227
+	 * @throws EE_Error
228
+	 * @throws InvalidArgumentException
229
+	 * @throws ReflectionException
230
+	 * @throws InvalidDataTypeException
231
+	 * @throws InvalidInterfaceException
232
+	 */
233
+	public function run($WP)
234
+	{
235
+		//ensure controller is loaded
236
+		self::_load_controller();
237
+		// attempt to process message
238
+		try {
239
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
240
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
241
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
242
+		} catch (EE_Error $e) {
243
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
244
+				'event_espresso');
245
+			// add specific message for developers if WP_DEBUG in on
246
+			$error_msg .= '||' . $e->getMessage();
247
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
248
+		}
249
+	}
250
+
251
+
252
+	/**
253
+	 * This is triggered by the 'msg_cron_trigger' route.
254
+	 *
255
+	 * @param WP $WP
256
+	 */
257
+	public function execute_batch_request($WP)
258
+	{
259
+		$this->run_cron();
260
+		header('HTTP/1.1 200 OK');
261
+		exit();
262
+	}
263
+
264
+
265
+	/**
266
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
267
+	 * request.
268
+	 */
269
+	public function run_cron()
270
+	{
271
+		self::_load_controller();
272
+		//get required vars
273
+		$cron_type     = EE_Registry::instance()->REQ->get('type');
274
+		$transient_key = EE_Registry::instance()->REQ->get('key');
275
+
276
+		//now let's verify transient, if not valid exit immediately
277
+		if (! get_transient($transient_key)) {
278
+			/**
279
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user
280
+			 * request.
281
+			 */
282
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
283
+		}
284
+
285
+		//if made it here, lets' delete the transient to keep the db clean
286
+		delete_transient($transient_key);
287
+
288
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
289
+
290
+			$method = 'batch_' . $cron_type . '_from_queue';
291
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
292
+				self::$_MSG_PROCESSOR->$method();
293
+			} else {
294
+				//no matching task
295
+				/**
296
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user
297
+				 * request.
298
+				 */
299
+				trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
300
+					$cron_type)));
301
+			}
302
+		}
303
+
304
+		do_action('FHEE__EED_Messages__run_cron__end');
305
+	}
306
+
307
+
308
+	/**
309
+	 * This is used to retrieve the template pack for the given name.
310
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
311
+	 * the default template pack is returned.
312
+	 *
313
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
314
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
315
+	 *                                   in generating the Pack class name).
316
+	 * @return EE_Messages_Template_Pack
317
+	 * @throws EE_Error
318
+	 * @throws InvalidArgumentException
319
+	 * @throws ReflectionException
320
+	 * @throws InvalidDataTypeException
321
+	 * @throws InvalidInterfaceException
322
+	 */
323
+	public static function get_template_pack($template_pack_name)
324
+	{
325
+		EE_Registry::instance()->load_helper('MSG_Template');
326
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
327
+	}
328
+
329
+
330
+	/**
331
+	 * Retrieves an array of all template packs.
332
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
333
+	 *
334
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
335
+	 * @return EE_Messages_Template_Pack[]
336
+	 * @throws EE_Error
337
+	 * @throws InvalidArgumentException
338
+	 * @throws ReflectionException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws InvalidInterfaceException
341
+	 */
342
+	public static function get_template_packs()
343
+	{
344
+		EE_Registry::instance()->load_helper('MSG_Template');
345
+
346
+		//for backward compat, let's make sure this returns in the same format as originally.
347
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
348
+		$template_pack_collection->rewind();
349
+		$template_packs = array();
350
+		while ($template_pack_collection->valid()) {
351
+			$template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
352
+			$template_pack_collection->next();
353
+		}
354
+		return $template_packs;
355
+	}
356
+
357
+
358
+	/**
359
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
360
+	 *
361
+	 * @since 4.5.0
362
+	 * @return void
363
+	 * @throws EE_Error
364
+	 */
365
+	public static function set_autoloaders()
366
+	{
367
+		if (empty(self::$_MSG_PATHS)) {
368
+			self::_set_messages_paths();
369
+			foreach (self::$_MSG_PATHS as $path) {
370
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
371
+			}
372
+			// add aliases
373
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
374
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
375
+		}
376
+	}
377
+
378
+
379
+	/**
380
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
381
+	 * for use by the Messages Autoloaders
382
+	 *
383
+	 * @since 4.5.0
384
+	 * @return void.
385
+	 */
386
+	protected static function _set_messages_paths()
387
+	{
388
+		$dir_ref = array(
389
+			'messages/message_type',
390
+			'messages/messenger',
391
+			'messages/defaults',
392
+			'messages/defaults/email',
393
+			'messages/data_class',
394
+			'messages/validators',
395
+			'messages/validators/email',
396
+			'messages/validators/html',
397
+			'shortcodes',
398
+		);
399
+		$paths   = array();
400
+		foreach ($dir_ref as $index => $dir) {
401
+			$paths[$index] = EE_LIBRARIES . $dir;
402
+		}
403
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Takes care of loading dependencies
409
+	 *
410
+	 * @since 4.5.0
411
+	 * @return void
412
+	 * @throws EE_Error
413
+	 * @throws InvalidArgumentException
414
+	 * @throws ReflectionException
415
+	 * @throws InvalidDataTypeException
416
+	 * @throws InvalidInterfaceException
417
+	 */
418
+	protected static function _load_controller()
419
+	{
420
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
421
+			EE_Registry::instance()->load_core('Request_Handler');
422
+			self::set_autoloaders();
423
+			self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
424
+			self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
425
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
426
+		}
427
+	}
428
+
429
+
430
+	/**
431
+	 * @param EE_Transaction $transaction
432
+	 * @throws EE_Error
433
+	 * @throws InvalidArgumentException
434
+	 * @throws InvalidDataTypeException
435
+	 * @throws InvalidInterfaceException
436
+	 * @throws ReflectionException
437
+	 */
438
+	public static function payment_reminder(EE_Transaction $transaction)
439
+	{
440
+		self::_load_controller();
441
+		$data = array($transaction, null);
442
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
443
+	}
444
+
445
+
446
+	/**
447
+	 * Any messages triggers for after successful gateway payments should go in here.
448
+	 *
449
+	 * @param EE_Transaction $transaction object
450
+	 * @param EE_Payment     $payment     object
451
+	 * @return void
452
+	 * @throws EE_Error
453
+	 * @throws InvalidArgumentException
454
+	 * @throws ReflectionException
455
+	 * @throws InvalidDataTypeException
456
+	 * @throws InvalidInterfaceException
457
+	 */
458
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment)
459
+	{
460
+		self::_load_controller();
461
+		$data = array($transaction, $payment);
462
+		EE_Registry::instance()->load_helper('MSG_Template');
463
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
464
+		//if payment amount is less than 0 then switch to payment_refund message type.
465
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
466
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
467
+	}
468
+
469
+
470
+	/**
471
+	 * @param EE_Transaction $transaction
472
+	 * @throws EE_Error
473
+	 * @throws InvalidArgumentException
474
+	 * @throws InvalidDataTypeException
475
+	 * @throws InvalidInterfaceException
476
+	 * @throws ReflectionException
477
+	 */
478
+	public static function cancelled_registration(EE_Transaction $transaction)
479
+	{
480
+		self::_load_controller();
481
+		$data = array($transaction, null);
482
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
483
+	}
484
+
485
+
486
+
487
+	/**
488
+	 * Trigger for Registration messages
489
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
490
+	 * incoming transaction.
491
+	 *
492
+	 * @param EE_Registration $registration
493
+	 * @param array           $extra_details
494
+	 * @return void
495
+	 * @throws EE_Error
496
+	 * @throws InvalidArgumentException
497
+	 * @throws InvalidDataTypeException
498
+	 * @throws InvalidInterfaceException
499
+	 * @throws ReflectionException
500
+	 * @throws EntityNotFoundException
501
+	 */
502
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
503
+	{
504
+
505
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
506
+			//no messages please
507
+			return;
508
+		}
509
+
510
+		// get all non-trashed registrations so we make sure we send messages for the right status.
511
+		$all_registrations = $registration->transaction()->registrations(
512
+			array(
513
+				array('REG_deleted' => false),
514
+				'order_by' => array(
515
+					'Event.EVT_name'     => 'ASC',
516
+					'Attendee.ATT_lname' => 'ASC',
517
+					'Attendee.ATT_fname' => 'ASC'
518
+				)
519
+			)
520
+		);
521
+		//cached array of statuses so we only trigger messages once per status.
522
+		$statuses_sent = array();
523
+		self::_load_controller();
524
+		$mtgs = array();
525
+
526
+		//loop through registrations and trigger messages once per status.
527
+		foreach ($all_registrations as $reg) {
528
+
529
+			//already triggered?
530
+			if (in_array($reg->status_ID(), $statuses_sent)) {
531
+				continue;
532
+			}
533
+
534
+			$message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
535
+			$mtgs            = array_merge(
536
+					$mtgs,
537
+					self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
538
+							$message_type,
539
+							array($registration->transaction(), null, $reg->status_ID())
540
+					)
541
+			);
542
+			$statuses_sent[] = $reg->status_ID();
543
+		}
544
+
545
+		if (count($statuses_sent) > 1) {
546
+			$mtgs = array_merge(
547
+				$mtgs,
548
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
549
+					'registration_summary',
550
+					array($registration->transaction(), null)
551
+				)
552
+			);
553
+		}
554
+
555
+		//batch queue and initiate request
556
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
557
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
558
+	}
559
+
560
+
561
+	/**
562
+	 * This is a helper method used to very whether a registration notification should be sent or
563
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
564
+	 *
565
+	 * @param EE_Registration $registration  [description]
566
+	 * @param array           $extra_details [description]
567
+	 * @return bool          true = send away, false = nope halt the presses.
568
+	 */
569
+	protected static function _verify_registration_notification_send(
570
+		EE_Registration $registration,
571
+		$extra_details = array()
572
+	) {
573
+		//self::log(
574
+		//	__CLASS__, __FUNCTION__, __LINE__,
575
+		//	$registration->transaction(),
576
+		//	array( '$extra_details' => $extra_details )
577
+		//);
578
+		// currently only using this to send messages for the primary registrant
579
+		if (! $registration->is_primary_registrant()) {
580
+			return false;
581
+		}
582
+		// first we check if we're in admin and not doing front ajax
583
+		if (is_admin() && ! EE_FRONT_AJAX) {
584
+			//make sure appropriate admin params are set for sending messages
585
+			if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
586
+				//no messages sent please.
587
+				return false;
588
+			}
589
+		} else {
590
+			// frontend request (either regular or via AJAX)
591
+			// TXN is NOT finalized ?
592
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
593
+				return false;
594
+			}
595
+			// return visit but nothing changed ???
596
+			if (
597
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
598
+				$extra_details['revisit'] && ! $extra_details['status_updates']
599
+			) {
600
+				return false;
601
+			}
602
+			// NOT sending messages && reg status is something other than "Not-Approved"
603
+			if (
604
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
605
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
606
+			) {
607
+				return false;
608
+			}
609
+		}
610
+		// release the kraken
611
+		return true;
612
+	}
613
+
614
+
615
+	/**
616
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
617
+	 * status id.
618
+	 *
619
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
620
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
621
+	 * @param string $reg_status
622
+	 * @return array
623
+	 * @throws EE_Error
624
+	 * @throws InvalidArgumentException
625
+	 * @throws ReflectionException
626
+	 * @throws InvalidDataTypeException
627
+	 * @throws InvalidInterfaceException
628
+	 */
629
+	protected static function _get_reg_status_array($reg_status = '')
630
+	{
631
+		EE_Registry::instance()->load_helper('MSG_Template');
632
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
633
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
634
+			: EEH_MSG_Template::reg_status_to_message_type_array();
635
+	}
636
+
637
+
638
+	/**
639
+	 * Simply returns the payment message type for the given payment status.
640
+	 *
641
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
642
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
643
+	 * @param string $payment_status The payment status being matched.
644
+	 * @return bool|string The payment message type slug matching the status or false if no match.
645
+	 * @throws EE_Error
646
+	 * @throws InvalidArgumentException
647
+	 * @throws ReflectionException
648
+	 * @throws InvalidDataTypeException
649
+	 * @throws InvalidInterfaceException
650
+	 */
651
+	protected static function _get_payment_message_type($payment_status)
652
+	{
653
+		EE_Registry::instance()->load_helper('MSG_Template');
654
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
655
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
656
+			: false;
657
+	}
658
+
659
+
660
+	/**
661
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
662
+	 *
663
+	 * @access public
664
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
665
+	 * @return bool success/fail
666
+	 * @throws EE_Error
667
+	 * @throws InvalidArgumentException
668
+	 * @throws InvalidDataTypeException
669
+	 * @throws InvalidInterfaceException
670
+	 * @throws ReflectionException
671
+	 */
672
+	public static function process_resend($req_data)
673
+	{
674
+		self::_load_controller();
675
+
676
+		//if $msgID in this request then skip to the new resend_message
677
+		if (EE_Registry::instance()->REQ->get('MSG_ID')) {
678
+			return self::resend_message();
679
+		}
680
+
681
+		//make sure any incoming request data is set on the REQ so that it gets picked up later.
682
+		$req_data = (array)$req_data;
683
+		foreach ($req_data as $request_key => $request_value) {
684
+			EE_Registry::instance()->REQ->set($request_key, $request_value);
685
+		}
686
+
687
+		if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
688
+			return false;
689
+		}
690
+
691
+		try {
692
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
693
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
694
+		} catch (EE_Error $e) {
695
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
696
+			return false;
697
+		}
698
+		EE_Error::add_success(
699
+			__('Messages have been successfully queued for generation and sending.', 'event_espresso')
700
+		);
701
+		return true; //everything got queued.
702
+	}
703
+
704
+
705
+	/**
706
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
707
+	 *
708
+	 * @return bool
709
+	 * @throws EE_Error
710
+	 * @throws InvalidArgumentException
711
+	 * @throws InvalidDataTypeException
712
+	 * @throws InvalidInterfaceException
713
+	 * @throws ReflectionException
714
+	 */
715
+	public static function resend_message()
716
+	{
717
+		self::_load_controller();
718
+
719
+		$msgID = EE_Registry::instance()->REQ->get('MSG_ID');
720
+		if (! $msgID) {
721
+			EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
722
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
723
+			return false;
724
+		}
725
+
726
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
727
+
728
+		//setup success message.
729
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
730
+		EE_Error::add_success(sprintf(
731
+			_n(
732
+				'There was %d message queued for resending.',
733
+				'There were %d messages queued for resending.',
734
+				$count_ready_for_resend,
735
+				'event_espresso'
736
+			),
737
+			$count_ready_for_resend
738
+		));
739
+		return true;
740
+	}
741
+
742
+
743
+	/**
744
+	 * Message triggers for manual payment applied by admin
745
+	 *
746
+	 * @param  EE_Payment $payment EE_payment object
747
+	 * @return bool success/fail
748
+	 * @throws EE_Error
749
+	 * @throws InvalidArgumentException
750
+	 * @throws ReflectionException
751
+	 * @throws InvalidDataTypeException
752
+	 * @throws InvalidInterfaceException
753
+	 */
754
+	public static function process_admin_payment(EE_Payment $payment)
755
+	{
756
+		EE_Registry::instance()->load_helper('MSG_Template');
757
+		//we need to get the transaction object
758
+		$transaction = $payment->transaction();
759
+		if ($transaction instanceof EE_Transaction) {
760
+			$data         = array($transaction, $payment);
761
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
762
+
763
+			//if payment amount is less than 0 then switch to payment_refund message type.
764
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
765
+
766
+			//if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
767
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
768
+
769
+			self::_load_controller();
770
+
771
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
772
+
773
+			//get count of queued for generation
774
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
775
+				EEM_Message::status_incomplete,
776
+				EEM_Message::status_idle,
777
+			));
778
+
779
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
780
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
781
+				return true;
782
+			} else {
783
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
784
+				/**
785
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
786
+				 * IMMEDIATE generation.
787
+				 */
788
+				if ($count_failed > 0) {
789
+					EE_Error::add_error(sprintf(
790
+						_n(
791
+							'The payment notification generation failed.',
792
+							'%d payment notifications failed being sent.',
793
+							$count_failed,
794
+							'event_espresso'
795
+						),
796
+						$count_failed
797
+					), __FILE__, __FUNCTION__, __LINE__);
798
+
799
+					return false;
800
+				} else {
801
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
802
+					return true;
803
+				}
804
+			}
805
+		} else {
806
+			EE_Error::add_error(
807
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
808
+				'event_espresso'
809
+			);
810
+			return false;
811
+		}
812
+	}
813
+
814
+
815
+	/**
816
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
817
+	 *
818
+	 * @since   4.3.0
819
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
820
+	 * @param  int               $grp_id        a specific message template group id.
821
+	 * @return void
822
+	 * @throws EE_Error
823
+	 * @throws InvalidArgumentException
824
+	 * @throws InvalidDataTypeException
825
+	 * @throws InvalidInterfaceException
826
+	 * @throws ReflectionException
827
+	 */
828
+	public static function send_newsletter_message($registrations, $grp_id)
829
+	{
830
+		//make sure mtp is id and set it in the EE_Request Handler later messages setup.
831
+		EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
832
+		self::_load_controller();
833
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
834
+	}
835
+
836
+
837
+	/**
838
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
839
+	 *
840
+	 * @since   4.3.0
841
+	 * @param    string          $registration_message_trigger_url
842
+	 * @param    EE_Registration $registration
843
+	 * @param string             $messenger
844
+	 * @param string             $message_type
845
+	 * @return string
846
+	 * @throws EE_Error
847
+	 * @throws InvalidArgumentException
848
+	 * @throws InvalidDataTypeException
849
+	 * @throws InvalidInterfaceException
850
+	 */
851
+	public static function registration_message_trigger_url(
852
+		$registration_message_trigger_url,
853
+		EE_Registration $registration,
854
+		$messenger = 'html',
855
+		$message_type = 'invoice'
856
+	) {
857
+		// whitelist $messenger
858
+		switch ($messenger) {
859
+			case 'pdf' :
860
+				$sending_messenger    = 'pdf';
861
+				$generating_messenger = 'html';
862
+				break;
863
+			case 'html' :
864
+			default :
865
+				$sending_messenger    = 'html';
866
+				$generating_messenger = 'html';
867
+				break;
868
+		}
869
+		// whitelist $message_type
870
+		switch ($message_type) {
871
+			case 'receipt' :
872
+				$message_type = 'receipt';
873
+				break;
874
+			case 'invoice' :
875
+			default :
876
+				$message_type = 'invoice';
877
+				break;
878
+		}
879
+		// verify that both the messenger AND the message type are active
880
+		if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
881
+			//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?)
882
+			$template_query_params = array(
883
+				'MTP_is_active'    => true,
884
+				'MTP_messenger'    => $generating_messenger,
885
+				'MTP_message_type' => $message_type,
886
+				'Event.EVT_ID'     => $registration->event_ID(),
887
+			);
888
+			//get the message template group.
889
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
890
+			//if we don't have an EE_Message_Template_Group then return
891
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
892
+				// remove EVT_ID from query params so that global templates get picked up
893
+				unset($template_query_params['Event.EVT_ID']);
894
+				//get global template as the fallback
895
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
896
+			}
897
+			//if we don't have an EE_Message_Template_Group then return
898
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
899
+				return '';
900
+			}
901
+			// generate the URL
902
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
903
+				$sending_messenger,
904
+				$generating_messenger,
905
+				'purchaser',
906
+				$message_type,
907
+				$registration,
908
+				$msg_template_group->ID(),
909
+				$registration->transaction_ID()
910
+			);
911
+
912
+		}
913
+		return $registration_message_trigger_url;
914
+	}
915
+
916
+
917
+	/**
918
+	 * Use to generate and return a message preview!
919
+	 *
920
+	 * @param  string $type      This should correspond with a valid message type
921
+	 * @param  string $context   This should correspond with a valid context for the message type
922
+	 * @param  string $messenger This should correspond with a valid messenger.
923
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
924
+	 *                           preview
925
+	 * @return bool|string The body of the message or if send is requested, sends.
926
+	 * @throws EE_Error
927
+	 * @throws InvalidArgumentException
928
+	 * @throws InvalidDataTypeException
929
+	 * @throws InvalidInterfaceException
930
+	 * @throws ReflectionException
931
+	 */
932
+	public static function preview_message($type, $context, $messenger, $send = false)
933
+	{
934
+		self::_load_controller();
935
+		$mtg                     = new EE_Message_To_Generate(
936
+			$messenger,
937
+			$type,
938
+			array(),
939
+			$context,
940
+			true
941
+		);
942
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
943
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
944
+			//loop through all content for the preview and remove any persisted records.
945
+			$content = '';
946
+			foreach ($generated_preview_queue->get_message_repository() as $message) {
947
+				$content = $message->content();
948
+				if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
949
+					$message->delete();
950
+				}
951
+			}
952
+			return $content;
953
+		} else {
954
+			return $generated_preview_queue;
955
+		}
956
+	}
957
+
958
+
959
+	/**
960
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
961
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
962
+	 * content found in the EE_Message objects in the queue.
963
+	 *
964
+	 * @since 4.9.0
965
+	 * @param string            $messenger            a string matching a valid active messenger in the system
966
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
967
+	 *                                                type name is still required to send along the message type to the
968
+	 *                                                messenger because this is used for determining what specific
969
+	 *                                                variations might be loaded for the generated message.
970
+	 * @param EE_Messages_Queue $queue
971
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
972
+	 *                                                aggregate EE_Message object.
973
+	 * @return bool success or fail.
974
+	 * @throws EE_Error
975
+	 * @throws InvalidArgumentException
976
+	 * @throws ReflectionException
977
+	 * @throws InvalidDataTypeException
978
+	 * @throws InvalidInterfaceException
979
+	 */
980
+	public static function send_message_with_messenger_only(
981
+		$messenger,
982
+		$message_type,
983
+		EE_Messages_Queue $queue,
984
+		$custom_subject = ''
985
+	) {
986
+		self::_load_controller();
987
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
988
+		$message_to_generate = EE_Registry::instance()->load_lib(
989
+			'Message_To_Generate_From_Queue',
990
+			array(
991
+				$messenger,
992
+				$message_type,
993
+				$queue,
994
+				$custom_subject,
995
+			)
996
+		);
997
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1003
+	 *
1004
+	 * @since 4.9.0
1005
+	 * @param array $message_ids An array of message ids
1006
+	 * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1007
+	 *                           messages.
1008
+	 * @throws EE_Error
1009
+	 * @throws InvalidArgumentException
1010
+	 * @throws InvalidDataTypeException
1011
+	 * @throws InvalidInterfaceException
1012
+	 * @throws ReflectionException
1013
+	 */
1014
+	public static function generate_now($message_ids)
1015
+	{
1016
+		self::_load_controller();
1017
+		$messages        = EEM_Message::instance()->get_all(
1018
+			array(
1019
+				0 => array(
1020
+					'MSG_ID' => array('IN', $message_ids),
1021
+					'STS_ID' => EEM_Message::status_incomplete,
1022
+				),
1023
+			)
1024
+		);
1025
+		$generated_queue = false;
1026
+		if ($messages) {
1027
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1028
+		}
1029
+
1030
+		if (! $generated_queue instanceof EE_Messages_Queue) {
1031
+			EE_Error::add_error(
1032
+				__('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.',
1033
+					'event_espresso'),
1034
+				__FILE__, __FUNCTION__, __LINE__
1035
+			);
1036
+		}
1037
+		return $generated_queue;
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1043
+	 * EEM_Message::status_idle
1044
+	 *
1045
+	 * @since 4.9.0
1046
+	 * @param $message_ids
1047
+	 * @return bool|EE_Messages_Queue false if no messages sent.
1048
+	 * @throws EE_Error
1049
+	 * @throws InvalidArgumentException
1050
+	 * @throws InvalidDataTypeException
1051
+	 * @throws InvalidInterfaceException
1052
+	 * @throws ReflectionException
1053
+	 */
1054
+	public static function send_now($message_ids)
1055
+	{
1056
+		self::_load_controller();
1057
+		$messages   = EEM_Message::instance()->get_all(
1058
+			array(
1059
+				0 => array(
1060
+					'MSG_ID' => array('IN', $message_ids),
1061
+					'STS_ID' => array(
1062
+						'IN',
1063
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1064
+					),
1065
+				),
1066
+			)
1067
+		);
1068
+		$sent_queue = false;
1069
+		if ($messages) {
1070
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1071
+		}
1072
+
1073
+		if (! $sent_queue instanceof EE_Messages_Queue) {
1074
+			EE_Error::add_error(
1075
+				__('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.',
1076
+					'event_espresso'),
1077
+				__FILE__, __FUNCTION__, __LINE__
1078
+			);
1079
+		} else {
1080
+			//can count how many sent by using the messages in the queue
1081
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1082
+			if ($sent_count > 0) {
1083
+				EE_Error::add_success(
1084
+					sprintf(
1085
+						_n(
1086
+							'There was %d message successfully sent.',
1087
+							'There were %d messages successfully sent.',
1088
+							$sent_count,
1089
+							'event_espresso'
1090
+						),
1091
+						$sent_count
1092
+					)
1093
+				);
1094
+			} else {
1095
+				EE_Error::overwrite_errors();
1096
+				EE_Error::add_error(
1097
+					__('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.
1098 1098
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
1099
-                        'event_espresso'),
1100
-                    __FILE__, __FUNCTION__, __LINE__
1101
-                );
1102
-            }
1103
-        }
1104
-        return $sent_queue;
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * Generate and send immediately from the given $message_ids
1110
-     *
1111
-     * @param array $message_ids EE_Message entity ids.
1112
-     * @throws EE_Error
1113
-     * @throws InvalidArgumentException
1114
-     * @throws InvalidDataTypeException
1115
-     * @throws InvalidInterfaceException
1116
-     * @throws ReflectionException
1117
-     */
1118
-    public static function generate_and_send_now(array $message_ids)
1119
-    {
1120
-        $generated_queue = self::generate_now($message_ids);
1121
-        //now let's just trigger sending immediately from this queue.
1122
-        $messages_sent = $generated_queue->execute();
1123
-        if ($messages_sent) {
1124
-            EE_Error::add_success(
1125
-                esc_html(
1126
-                    sprintf(
1127
-                        _n(
1128
-                            'There was %d message successfully generated and sent.',
1129
-                            'There were %d messages successfully generated and sent.',
1130
-                            $messages_sent,
1131
-                            'event_espresso'
1132
-                        ),
1133
-                        $messages_sent
1134
-                    )
1135
-                )
1136
-            );
1137
-            //errors would be added via the generate_now method.
1138
-        }
1139
-    }
1140
-
1141
-
1142
-    /**
1143
-     * This will queue the incoming message ids for resending.
1144
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1145
-     *
1146
-     * @since 4.9.0
1147
-     * @param array $message_ids An array of EE_Message IDs
1148
-     * @return bool true means messages were successfully queued for resending, false means none were queued for
1149
-     *                           resending.
1150
-     * @throws EE_Error
1151
-     * @throws InvalidArgumentException
1152
-     * @throws InvalidDataTypeException
1153
-     * @throws InvalidInterfaceException
1154
-     * @throws ReflectionException
1155
-     */
1156
-    public static function queue_for_resending($message_ids)
1157
-    {
1158
-        self::_load_controller();
1159
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1160
-
1161
-        //get queue and count
1162
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1163
-
1164
-        if (
1165
-            $queue_count > 0
1166
-        ) {
1167
-            EE_Error::add_success(
1168
-                sprintf(
1169
-                    _n(
1170
-                        '%d message successfully queued for resending.',
1171
-                        '%d messages successfully queued for resending.',
1172
-                        $queue_count,
1173
-                        'event_espresso'
1174
-                    ),
1175
-                    $queue_count
1176
-                )
1177
-            );
1178
-            /**
1179
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1180
-             */
1181
-        } elseif (
1182
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1183
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1184
-        ) {
1185
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1186
-            if ($queue_count > 0) {
1187
-                EE_Error::add_success(
1188
-                    sprintf(
1189
-                        _n(
1190
-                            '%d message successfully sent.',
1191
-                            '%d messages successfully sent.',
1192
-                            $queue_count,
1193
-                            'event_espresso'
1194
-                        ),
1195
-                        $queue_count
1196
-                    )
1197
-                );
1198
-            } else {
1199
-                EE_Error::add_error(
1200
-                    __('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.',
1201
-                        'event_espresso'),
1202
-                    __FILE__, __FUNCTION__, __LINE__
1203
-                );
1204
-            }
1205
-        } else {
1206
-            EE_Error::add_error(
1207
-                __('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.',
1208
-                    'event_espresso'),
1209
-                __FILE__, __FUNCTION__, __LINE__
1210
-            );
1211
-        }
1212
-        return (bool)$queue_count;
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * debug
1218
-     *
1219
-     * @param string          $class
1220
-     * @param string          $func
1221
-     * @param string          $line
1222
-     * @param \EE_Transaction $transaction
1223
-     * @param array           $info
1224
-     * @param bool            $display_request
1225
-     * @throws EE_Error
1226
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1227
-     */
1228
-    protected static function log(
1229
-        $class = '',
1230
-        $func = '',
1231
-        $line = '',
1232
-        EE_Transaction $transaction,
1233
-        $info = array(),
1234
-        $display_request = false
1235
-    ) {
1236
-        if (defined('EE_DEBUG') && EE_DEBUG) {
1237
-            if ($transaction instanceof EE_Transaction) {
1238
-                // don't serialize objects
1239
-                $info                  = EEH_Debug_Tools::strip_objects($info);
1240
-                $info['TXN_status']    = $transaction->status_ID();
1241
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1242
-                if ($transaction->ID()) {
1243
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1244
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1245
-                }
1246
-            }
1247
-        }
1248
-
1249
-    }
1250
-
1251
-
1252
-    /**
1253
-     *  Resets all the static properties in this class when called.
1254
-     */
1255
-    public static function reset()
1256
-    {
1257
-        self::$_EEMSG                    = null;
1258
-        self::$_message_resource_manager = null;
1259
-        self::$_MSG_PROCESSOR            = null;
1260
-        self::$_MSG_PATHS                = null;
1261
-        self::$_TMP_PACKS                = array();
1262
-    }
1099
+						'event_espresso'),
1100
+					__FILE__, __FUNCTION__, __LINE__
1101
+				);
1102
+			}
1103
+		}
1104
+		return $sent_queue;
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * Generate and send immediately from the given $message_ids
1110
+	 *
1111
+	 * @param array $message_ids EE_Message entity ids.
1112
+	 * @throws EE_Error
1113
+	 * @throws InvalidArgumentException
1114
+	 * @throws InvalidDataTypeException
1115
+	 * @throws InvalidInterfaceException
1116
+	 * @throws ReflectionException
1117
+	 */
1118
+	public static function generate_and_send_now(array $message_ids)
1119
+	{
1120
+		$generated_queue = self::generate_now($message_ids);
1121
+		//now let's just trigger sending immediately from this queue.
1122
+		$messages_sent = $generated_queue->execute();
1123
+		if ($messages_sent) {
1124
+			EE_Error::add_success(
1125
+				esc_html(
1126
+					sprintf(
1127
+						_n(
1128
+							'There was %d message successfully generated and sent.',
1129
+							'There were %d messages successfully generated and sent.',
1130
+							$messages_sent,
1131
+							'event_espresso'
1132
+						),
1133
+						$messages_sent
1134
+					)
1135
+				)
1136
+			);
1137
+			//errors would be added via the generate_now method.
1138
+		}
1139
+	}
1140
+
1141
+
1142
+	/**
1143
+	 * This will queue the incoming message ids for resending.
1144
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1145
+	 *
1146
+	 * @since 4.9.0
1147
+	 * @param array $message_ids An array of EE_Message IDs
1148
+	 * @return bool true means messages were successfully queued for resending, false means none were queued for
1149
+	 *                           resending.
1150
+	 * @throws EE_Error
1151
+	 * @throws InvalidArgumentException
1152
+	 * @throws InvalidDataTypeException
1153
+	 * @throws InvalidInterfaceException
1154
+	 * @throws ReflectionException
1155
+	 */
1156
+	public static function queue_for_resending($message_ids)
1157
+	{
1158
+		self::_load_controller();
1159
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1160
+
1161
+		//get queue and count
1162
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1163
+
1164
+		if (
1165
+			$queue_count > 0
1166
+		) {
1167
+			EE_Error::add_success(
1168
+				sprintf(
1169
+					_n(
1170
+						'%d message successfully queued for resending.',
1171
+						'%d messages successfully queued for resending.',
1172
+						$queue_count,
1173
+						'event_espresso'
1174
+					),
1175
+					$queue_count
1176
+				)
1177
+			);
1178
+			/**
1179
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1180
+			 */
1181
+		} elseif (
1182
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1183
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1184
+		) {
1185
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1186
+			if ($queue_count > 0) {
1187
+				EE_Error::add_success(
1188
+					sprintf(
1189
+						_n(
1190
+							'%d message successfully sent.',
1191
+							'%d messages successfully sent.',
1192
+							$queue_count,
1193
+							'event_espresso'
1194
+						),
1195
+						$queue_count
1196
+					)
1197
+				);
1198
+			} else {
1199
+				EE_Error::add_error(
1200
+					__('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.',
1201
+						'event_espresso'),
1202
+					__FILE__, __FUNCTION__, __LINE__
1203
+				);
1204
+			}
1205
+		} else {
1206
+			EE_Error::add_error(
1207
+				__('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.',
1208
+					'event_espresso'),
1209
+				__FILE__, __FUNCTION__, __LINE__
1210
+			);
1211
+		}
1212
+		return (bool)$queue_count;
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * debug
1218
+	 *
1219
+	 * @param string          $class
1220
+	 * @param string          $func
1221
+	 * @param string          $line
1222
+	 * @param \EE_Transaction $transaction
1223
+	 * @param array           $info
1224
+	 * @param bool            $display_request
1225
+	 * @throws EE_Error
1226
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1227
+	 */
1228
+	protected static function log(
1229
+		$class = '',
1230
+		$func = '',
1231
+		$line = '',
1232
+		EE_Transaction $transaction,
1233
+		$info = array(),
1234
+		$display_request = false
1235
+	) {
1236
+		if (defined('EE_DEBUG') && EE_DEBUG) {
1237
+			if ($transaction instanceof EE_Transaction) {
1238
+				// don't serialize objects
1239
+				$info                  = EEH_Debug_Tools::strip_objects($info);
1240
+				$info['TXN_status']    = $transaction->status_ID();
1241
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1242
+				if ($transaction->ID()) {
1243
+					$index = 'EE_Transaction: ' . $transaction->ID();
1244
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1245
+				}
1246
+			}
1247
+		}
1248
+
1249
+	}
1250
+
1251
+
1252
+	/**
1253
+	 *  Resets all the static properties in this class when called.
1254
+	 */
1255
+	public static function reset()
1256
+	{
1257
+		self::$_EEMSG                    = null;
1258
+		self::$_message_resource_manager = null;
1259
+		self::$_MSG_PROCESSOR            = null;
1260
+		self::$_MSG_PATHS                = null;
1261
+		self::$_TMP_PACKS                = array();
1262
+	}
1263 1263
 
1264 1264
 }
1265 1265
 // End of file EED_Messages.module.php
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +4060 added lines, -4060 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidInterfaceException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('NO direct script access allowed');
8
+	exit('NO direct script access allowed');
9 9
 }
10 10
 
11 11
 /**
@@ -23,2559 +23,2559 @@  discard block
 block discarded – undo
23 23
 class Messages_Admin_Page extends EE_Admin_Page
24 24
 {
25 25
     
26
-    /**
27
-     * @type EE_Message_Resource_Manager $_message_resource_manager
28
-     */
29
-    protected $_message_resource_manager;
26
+	/**
27
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
28
+	 */
29
+	protected $_message_resource_manager;
30 30
     
31
-    /**
32
-     * @type string $_active_message_type_name
33
-     */
34
-    protected $_active_message_type_name = '';
31
+	/**
32
+	 * @type string $_active_message_type_name
33
+	 */
34
+	protected $_active_message_type_name = '';
35 35
     
36
-    /**
37
-     * @type EE_messenger $_active_messenger
38
-     */
39
-    protected $_active_messenger;
40
-    protected $_activate_state;
41
-    protected $_activate_meta_box_type;
42
-    protected $_current_message_meta_box;
43
-    protected $_current_message_meta_box_object;
44
-    protected $_context_switcher;
45
-    protected $_shortcodes = array();
46
-    protected $_active_messengers = array();
47
-    protected $_active_message_types = array();
36
+	/**
37
+	 * @type EE_messenger $_active_messenger
38
+	 */
39
+	protected $_active_messenger;
40
+	protected $_activate_state;
41
+	protected $_activate_meta_box_type;
42
+	protected $_current_message_meta_box;
43
+	protected $_current_message_meta_box_object;
44
+	protected $_context_switcher;
45
+	protected $_shortcodes = array();
46
+	protected $_active_messengers = array();
47
+	protected $_active_message_types = array();
48 48
     
49
-    /**
50
-     * @var EE_Message_Template_Group $_message_template_group
51
-     */
52
-    protected $_message_template_group;
53
-    protected $_m_mt_settings = array();
49
+	/**
50
+	 * @var EE_Message_Template_Group $_message_template_group
51
+	 */
52
+	protected $_message_template_group;
53
+	protected $_m_mt_settings = array();
54 54
     
55 55
     
56
-    /**
57
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
-     * IF there is no group then it gets automatically set to the Default template pack.
59
-     *
60
-     * @since 4.5.0
61
-     *
62
-     * @var EE_Messages_Template_Pack
63
-     */
64
-    protected $_template_pack;
56
+	/**
57
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
+	 * IF there is no group then it gets automatically set to the Default template pack.
59
+	 *
60
+	 * @since 4.5.0
61
+	 *
62
+	 * @var EE_Messages_Template_Pack
63
+	 */
64
+	protected $_template_pack;
65 65
     
66 66
     
67
-    /**
68
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
-     * group is.  If there is no group then it automatically gets set to default.
70
-     *
71
-     * @since 4.5.0
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_variation;
67
+	/**
68
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
+	 * group is.  If there is no group then it automatically gets set to default.
70
+	 *
71
+	 * @since 4.5.0
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_variation;
76 76
 
77 77
 
78
-    /**
79
-     * @param bool $routing
80
-     * @throws EE_Error
81
-     */
82
-    public function __construct($routing = true)
83
-    {
84
-        //make sure messages autoloader is running
85
-        EED_Messages::set_autoloaders();
86
-        parent::__construct($routing);
87
-    }
78
+	/**
79
+	 * @param bool $routing
80
+	 * @throws EE_Error
81
+	 */
82
+	public function __construct($routing = true)
83
+	{
84
+		//make sure messages autoloader is running
85
+		EED_Messages::set_autoloaders();
86
+		parent::__construct($routing);
87
+	}
88 88
     
89 89
     
90
-    protected function _init_page_props()
91
-    {
92
-        $this->page_slug        = EE_MSG_PG_SLUG;
93
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
-        $this->_admin_base_path = EE_MSG_ADMIN;
96
-        
97
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
-        
99
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
-        $this->_load_message_resource_manager();
101
-    }
90
+	protected function _init_page_props()
91
+	{
92
+		$this->page_slug        = EE_MSG_PG_SLUG;
93
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
+		$this->_admin_base_path = EE_MSG_ADMIN;
96
+        
97
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
+        
99
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
+		$this->_load_message_resource_manager();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
-     *
107
-     * @throws EE_Error
108
-     * @throws InvalidDataTypeException
109
-     * @throws InvalidInterfaceException
110
-     * @throws InvalidArgumentException
111
-     * @throws ReflectionException
112
-     */
113
-    protected function _load_message_resource_manager()
114
-    {
115
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
-    }
104
+	/**
105
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
+	 *
107
+	 * @throws EE_Error
108
+	 * @throws InvalidDataTypeException
109
+	 * @throws InvalidInterfaceException
110
+	 * @throws InvalidArgumentException
111
+	 * @throws ReflectionException
112
+	 */
113
+	protected function _load_message_resource_manager()
114
+	{
115
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * @deprecated 4.9.9.rc.014
121
-     * @return array
122
-     * @throws EE_Error
123
-     * @throws InvalidArgumentException
124
-     * @throws InvalidDataTypeException
125
-     * @throws InvalidInterfaceException
126
-     */
127
-    public function get_messengers_for_list_table()
128
-    {
129
-        EE_Error::doing_it_wrong(
130
-            __METHOD__,
131
-            sprintf(
132
-                esc_html__(
133
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
134
-                    'event_espresso'
135
-                ),
136
-                'Messages_Admin_Page::get_messengers_select_input()'
137
-            ),
138
-            '4.9.9.rc.014'
139
-        );
140
-        
141
-        $m_values          = array();
142
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
-        //setup messengers for selects
144
-        $i = 1;
145
-        foreach ($active_messengers as $active_messenger) {
146
-            if ($active_messenger instanceof EE_Message) {
147
-                $m_values[$i]['id']   = $active_messenger->messenger();
148
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
-                $i++;
150
-            }
151
-        }
152
-        
153
-        return $m_values;
154
-    }
119
+	/**
120
+	 * @deprecated 4.9.9.rc.014
121
+	 * @return array
122
+	 * @throws EE_Error
123
+	 * @throws InvalidArgumentException
124
+	 * @throws InvalidDataTypeException
125
+	 * @throws InvalidInterfaceException
126
+	 */
127
+	public function get_messengers_for_list_table()
128
+	{
129
+		EE_Error::doing_it_wrong(
130
+			__METHOD__,
131
+			sprintf(
132
+				esc_html__(
133
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
134
+					'event_espresso'
135
+				),
136
+				'Messages_Admin_Page::get_messengers_select_input()'
137
+			),
138
+			'4.9.9.rc.014'
139
+		);
140
+        
141
+		$m_values          = array();
142
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
+		//setup messengers for selects
144
+		$i = 1;
145
+		foreach ($active_messengers as $active_messenger) {
146
+			if ($active_messenger instanceof EE_Message) {
147
+				$m_values[$i]['id']   = $active_messenger->messenger();
148
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
+				$i++;
150
+			}
151
+		}
152
+        
153
+		return $m_values;
154
+	}
155 155
 
156 156
 
157
-    /**
158
-     * @deprecated 4.9.9.rc.014
159
-     * @return array
160
-     * @throws EE_Error
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     */
165
-    public function get_message_types_for_list_table()
166
-    {
167
-        EE_Error::doing_it_wrong(
168
-            __METHOD__,
169
-            sprintf(
170
-                esc_html__(
171
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
172
-                    'event_espresso'
173
-                ),
174
-                'Messages_Admin_Page::get_message_types_select_input()'
175
-            ),
176
-            '4.9.9.rc.014'
177
-        );
178
-        
179
-        $mt_values       = array();
180
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
-        $i               = 1;
182
-        foreach ($active_messages as $active_message) {
183
-            if ($active_message instanceof EE_Message) {
184
-                $mt_values[$i]['id']   = $active_message->message_type();
185
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
-                $i++;
187
-            }
188
-        }
189
-        
190
-        return $mt_values;
191
-    }
157
+	/**
158
+	 * @deprecated 4.9.9.rc.014
159
+	 * @return array
160
+	 * @throws EE_Error
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 */
165
+	public function get_message_types_for_list_table()
166
+	{
167
+		EE_Error::doing_it_wrong(
168
+			__METHOD__,
169
+			sprintf(
170
+				esc_html__(
171
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
172
+					'event_espresso'
173
+				),
174
+				'Messages_Admin_Page::get_message_types_select_input()'
175
+			),
176
+			'4.9.9.rc.014'
177
+		);
178
+        
179
+		$mt_values       = array();
180
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
+		$i               = 1;
182
+		foreach ($active_messages as $active_message) {
183
+			if ($active_message instanceof EE_Message) {
184
+				$mt_values[$i]['id']   = $active_message->message_type();
185
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
+				$i++;
187
+			}
188
+		}
189
+        
190
+		return $mt_values;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * @deprecated 4.9.9.rc.014
196
-     * @return array
197
-     * @throws EE_Error
198
-     * @throws InvalidArgumentException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     */
202
-    public function get_contexts_for_message_types_for_list_table()
203
-    {
204
-        EE_Error::doing_it_wrong(
205
-            __METHOD__,
206
-            sprintf(
207
-                esc_html__(
208
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
209
-                    'event_espresso'
210
-                ),
211
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
-            ),
213
-            '4.9.9.rc.014'
214
-        );
215
-        
216
-        $contexts                = array();
217
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
-        foreach ($active_message_contexts as $active_message) {
219
-            if ($active_message instanceof EE_Message) {
220
-                $message_type = $active_message->message_type_object();
221
-                if ($message_type instanceof EE_message_type) {
222
-                    $message_type_contexts = $message_type->get_contexts();
223
-                    foreach ($message_type_contexts as $context => $context_details) {
224
-                        $contexts[$context] = $context_details['label'];
225
-                    }
226
-                }
227
-            }
228
-        }
229
-        
230
-        return $contexts;
231
-    }
194
+	/**
195
+	 * @deprecated 4.9.9.rc.014
196
+	 * @return array
197
+	 * @throws EE_Error
198
+	 * @throws InvalidArgumentException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 */
202
+	public function get_contexts_for_message_types_for_list_table()
203
+	{
204
+		EE_Error::doing_it_wrong(
205
+			__METHOD__,
206
+			sprintf(
207
+				esc_html__(
208
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
209
+					'event_espresso'
210
+				),
211
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
+			),
213
+			'4.9.9.rc.014'
214
+		);
215
+        
216
+		$contexts                = array();
217
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
+		foreach ($active_message_contexts as $active_message) {
219
+			if ($active_message instanceof EE_Message) {
220
+				$message_type = $active_message->message_type_object();
221
+				if ($message_type instanceof EE_message_type) {
222
+					$message_type_contexts = $message_type->get_contexts();
223
+					foreach ($message_type_contexts as $context => $context_details) {
224
+						$contexts[$context] = $context_details['label'];
225
+					}
226
+				}
227
+			}
228
+		}
229
+        
230
+		return $contexts;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * Generate select input with provided messenger options array.
236
-     *
237
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
-     *                                 labels.
239
-     * @return string
240
-     * @throws EE_Error
241
-     */
242
-    public function get_messengers_select_input($messenger_options)
243
-    {
244
-        //if empty or just one value then just return an empty string
245
-        if (empty($messenger_options)
246
-            || ! is_array($messenger_options)
247
-            || count($messenger_options) === 1
248
-        ) {
249
-            return '';
250
-        }
251
-        //merge in default
252
-        $messenger_options = array_merge(
253
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
-            $messenger_options
255
-        );
256
-        $input             = new EE_Select_Input(
257
-            $messenger_options,
258
-            array(
259
-                'html_name'  => 'ee_messenger_filter_by',
260
-                'html_id'    => 'ee_messenger_filter_by',
261
-                'html_class' => 'wide',
262
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
-                    : 'none_selected'
265
-            )
266
-        );
267
-        
268
-        return $input->get_html_for_input();
269
-    }
234
+	/**
235
+	 * Generate select input with provided messenger options array.
236
+	 *
237
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
+	 *                                 labels.
239
+	 * @return string
240
+	 * @throws EE_Error
241
+	 */
242
+	public function get_messengers_select_input($messenger_options)
243
+	{
244
+		//if empty or just one value then just return an empty string
245
+		if (empty($messenger_options)
246
+			|| ! is_array($messenger_options)
247
+			|| count($messenger_options) === 1
248
+		) {
249
+			return '';
250
+		}
251
+		//merge in default
252
+		$messenger_options = array_merge(
253
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
+			$messenger_options
255
+		);
256
+		$input             = new EE_Select_Input(
257
+			$messenger_options,
258
+			array(
259
+				'html_name'  => 'ee_messenger_filter_by',
260
+				'html_id'    => 'ee_messenger_filter_by',
261
+				'html_class' => 'wide',
262
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
+					: 'none_selected'
265
+			)
266
+		);
267
+        
268
+		return $input->get_html_for_input();
269
+	}
270 270
 
271 271
 
272
-    /**
273
-     * Generate select input with provided message type options array.
274
-     *
275
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
-     *                                    message type labels
277
-     * @return string
278
-     * @throws EE_Error
279
-     */
280
-    public function get_message_types_select_input($message_type_options)
281
-    {
282
-        //if empty or count of options is 1 then just return an empty string
283
-        if (empty($message_type_options)
284
-            || ! is_array($message_type_options)
285
-            || count($message_type_options) === 1
286
-        ) {
287
-            return '';
288
-        }
289
-        //merge in default
290
-        $message_type_options = array_merge(
291
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
-            $message_type_options
293
-        );
294
-        $input                = new EE_Select_Input(
295
-            $message_type_options,
296
-            array(
297
-                'html_name'  => 'ee_message_type_filter_by',
298
-                'html_id'    => 'ee_message_type_filter_by',
299
-                'html_class' => 'wide',
300
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
-                    : 'none_selected',
303
-            )
304
-        );
305
-        
306
-        return $input->get_html_for_input();
307
-    }
272
+	/**
273
+	 * Generate select input with provided message type options array.
274
+	 *
275
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
+	 *                                    message type labels
277
+	 * @return string
278
+	 * @throws EE_Error
279
+	 */
280
+	public function get_message_types_select_input($message_type_options)
281
+	{
282
+		//if empty or count of options is 1 then just return an empty string
283
+		if (empty($message_type_options)
284
+			|| ! is_array($message_type_options)
285
+			|| count($message_type_options) === 1
286
+		) {
287
+			return '';
288
+		}
289
+		//merge in default
290
+		$message_type_options = array_merge(
291
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
+			$message_type_options
293
+		);
294
+		$input                = new EE_Select_Input(
295
+			$message_type_options,
296
+			array(
297
+				'html_name'  => 'ee_message_type_filter_by',
298
+				'html_id'    => 'ee_message_type_filter_by',
299
+				'html_class' => 'wide',
300
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
+					: 'none_selected',
303
+			)
304
+		);
305
+        
306
+		return $input->get_html_for_input();
307
+	}
308 308
 
309 309
 
310
-    /**
311
-     * Generate select input with provide message type contexts array.
312
-     *
313
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
-     *                               context label.
315
-     * @return string
316
-     * @throws EE_Error
317
-     */
318
-    public function get_contexts_for_message_types_select_input($context_options)
319
-    {
320
-        //if empty or count of options is one then just return empty string
321
-        if (empty($context_options)
322
-            || ! is_array($context_options)
323
-            || count($context_options) === 1
324
-        ) {
325
-            return '';
326
-        }
327
-        //merge in default
328
-        $context_options = array_merge(
329
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
-            $context_options
331
-        );
332
-        $input           = new EE_Select_Input(
333
-            $context_options,
334
-            array(
335
-                'html_name'  => 'ee_context_filter_by',
336
-                'html_id'    => 'ee_context_filter_by',
337
-                'html_class' => 'wide',
338
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
339
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
340
-                    : 'none_selected',
341
-            )
342
-        );
343
-        
344
-        return $input->get_html_for_input();
345
-    }
310
+	/**
311
+	 * Generate select input with provide message type contexts array.
312
+	 *
313
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
+	 *                               context label.
315
+	 * @return string
316
+	 * @throws EE_Error
317
+	 */
318
+	public function get_contexts_for_message_types_select_input($context_options)
319
+	{
320
+		//if empty or count of options is one then just return empty string
321
+		if (empty($context_options)
322
+			|| ! is_array($context_options)
323
+			|| count($context_options) === 1
324
+		) {
325
+			return '';
326
+		}
327
+		//merge in default
328
+		$context_options = array_merge(
329
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
+			$context_options
331
+		);
332
+		$input           = new EE_Select_Input(
333
+			$context_options,
334
+			array(
335
+				'html_name'  => 'ee_context_filter_by',
336
+				'html_id'    => 'ee_context_filter_by',
337
+				'html_class' => 'wide',
338
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
339
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
340
+					: 'none_selected',
341
+			)
342
+		);
343
+        
344
+		return $input->get_html_for_input();
345
+	}
346 346
     
347 347
     
348
-    protected function _ajax_hooks()
349
-    {
350
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
-    }
348
+	protected function _ajax_hooks()
349
+	{
350
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
+	}
357 357
     
358 358
     
359
-    protected function _define_page_props()
360
-    {
361
-        $this->_admin_page_title = $this->page_label;
362
-        $this->_labels           = array(
363
-            'buttons'    => array(
364
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
-                'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
-            ),
368
-            'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
-        );
370
-    }
359
+	protected function _define_page_props()
360
+	{
361
+		$this->_admin_page_title = $this->page_label;
362
+		$this->_labels           = array(
363
+			'buttons'    => array(
364
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
+				'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
+			),
368
+			'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
+		);
370
+	}
371 371
     
372 372
     
373
-    /**
374
-     *        an array for storing key => value pairs of request actions and their corresponding methods
375
-     * @access protected
376
-     * @return void
377
-     */
378
-    protected function _set_page_routes()
379
-    {
380
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
-            ? $this->_req_data['GRP_ID']
382
-            : 0;
383
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
-            ? $this->_req_data['id']
385
-            : $grp_id;
386
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
-            ? $this->_req_data['MSG_ID']
388
-            : 0;
389
-        
390
-        $this->_page_routes = array(
391
-            'default'                          => array(
392
-                'func'       => '_message_queue_list_table',
393
-                'capability' => 'ee_read_global_messages'
394
-            ),
395
-            'global_mtps'                      => array(
396
-                'func'       => '_ee_default_messages_overview_list_table',
397
-                'capability' => 'ee_read_global_messages'
398
-            ),
399
-            'custom_mtps'                      => array(
400
-                'func'       => '_custom_mtps_preview',
401
-                'capability' => 'ee_read_messages'
402
-            ),
403
-            'add_new_message_template'         => array(
404
-                'func'       => '_add_message_template',
405
-                'capability' => 'ee_edit_messages',
406
-                'noheader'   => true
407
-            ),
408
-            'edit_message_template'            => array(
409
-                'func'       => '_edit_message_template',
410
-                'capability' => 'ee_edit_message',
411
-                'obj_id'     => $grp_id
412
-            ),
413
-            'preview_message'                  => array(
414
-                'func'               => '_preview_message',
415
-                'capability'         => 'ee_read_message',
416
-                'obj_id'             => $grp_id,
417
-                'noheader'           => true,
418
-                'headers_sent_route' => 'display_preview_message'
419
-            ),
420
-            'display_preview_message'          => array(
421
-                'func'       => '_display_preview_message',
422
-                'capability' => 'ee_read_message',
423
-                'obj_id'     => $grp_id
424
-            ),
425
-            'insert_message_template'          => array(
426
-                'func'       => '_insert_or_update_message_template',
427
-                'capability' => 'ee_edit_messages',
428
-                'args'       => array('new_template' => true),
429
-                'noheader'   => true
430
-            ),
431
-            'update_message_template'          => array(
432
-                'func'       => '_insert_or_update_message_template',
433
-                'capability' => 'ee_edit_message',
434
-                'obj_id'     => $grp_id,
435
-                'args'       => array('new_template' => false),
436
-                'noheader'   => true
437
-            ),
438
-            'trash_message_template'           => array(
439
-                'func'       => '_trash_or_restore_message_template',
440
-                'capability' => 'ee_delete_message',
441
-                'obj_id'     => $grp_id,
442
-                'args'       => array('trash' => true, 'all' => true),
443
-                'noheader'   => true
444
-            ),
445
-            'trash_message_template_context'   => array(
446
-                'func'       => '_trash_or_restore_message_template',
447
-                'capability' => 'ee_delete_message',
448
-                'obj_id'     => $grp_id,
449
-                'args'       => array('trash' => true),
450
-                'noheader'   => true
451
-            ),
452
-            'restore_message_template'         => array(
453
-                'func'       => '_trash_or_restore_message_template',
454
-                'capability' => 'ee_delete_message',
455
-                'obj_id'     => $grp_id,
456
-                'args'       => array('trash' => false, 'all' => true),
457
-                'noheader'   => true
458
-            ),
459
-            'restore_message_template_context' => array(
460
-                'func'       => '_trash_or_restore_message_template',
461
-                'capability' => 'ee_delete_message',
462
-                'obj_id'     => $grp_id,
463
-                'args'       => array('trash' => false),
464
-                'noheader'   => true
465
-            ),
466
-            'delete_message_template'          => array(
467
-                'func'       => '_delete_message_template',
468
-                'capability' => 'ee_delete_message',
469
-                'obj_id'     => $grp_id,
470
-                'noheader'   => true
471
-            ),
472
-            'reset_to_default'                 => array(
473
-                'func'       => '_reset_to_default_template',
474
-                'capability' => 'ee_edit_message',
475
-                'obj_id'     => $grp_id,
476
-                'noheader'   => true
477
-            ),
478
-            'settings'                         => array(
479
-                'func'       => '_settings',
480
-                'capability' => 'manage_options'
481
-            ),
482
-            'update_global_settings'           => array(
483
-                'func'       => '_update_global_settings',
484
-                'capability' => 'manage_options',
485
-                'noheader'   => true
486
-            ),
487
-            'generate_now'                     => array(
488
-                'func'       => '_generate_now',
489
-                'capability' => 'ee_send_message',
490
-                'noheader'   => true
491
-            ),
492
-            'generate_and_send_now'            => array(
493
-                'func'       => '_generate_and_send_now',
494
-                'capability' => 'ee_send_message',
495
-                'noheader'   => true
496
-            ),
497
-            'queue_for_resending'              => array(
498
-                'func'       => '_queue_for_resending',
499
-                'capability' => 'ee_send_message',
500
-                'noheader'   => true
501
-            ),
502
-            'send_now'                         => array(
503
-                'func'       => '_send_now',
504
-                'capability' => 'ee_send_message',
505
-                'noheader'   => true
506
-            ),
507
-            'delete_ee_message'                => array(
508
-                'func'       => '_delete_ee_messages',
509
-                'capability' => 'ee_delete_messages',
510
-                'noheader'   => true
511
-            ),
512
-            'delete_ee_messages'               => array(
513
-                'func'       => '_delete_ee_messages',
514
-                'capability' => 'ee_delete_messages',
515
-                'noheader'   => true,
516
-                'obj_id'     => $msg_id
517
-            )
518
-        );
519
-    }
373
+	/**
374
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
375
+	 * @access protected
376
+	 * @return void
377
+	 */
378
+	protected function _set_page_routes()
379
+	{
380
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
+			? $this->_req_data['GRP_ID']
382
+			: 0;
383
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
+			? $this->_req_data['id']
385
+			: $grp_id;
386
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
+			? $this->_req_data['MSG_ID']
388
+			: 0;
389
+        
390
+		$this->_page_routes = array(
391
+			'default'                          => array(
392
+				'func'       => '_message_queue_list_table',
393
+				'capability' => 'ee_read_global_messages'
394
+			),
395
+			'global_mtps'                      => array(
396
+				'func'       => '_ee_default_messages_overview_list_table',
397
+				'capability' => 'ee_read_global_messages'
398
+			),
399
+			'custom_mtps'                      => array(
400
+				'func'       => '_custom_mtps_preview',
401
+				'capability' => 'ee_read_messages'
402
+			),
403
+			'add_new_message_template'         => array(
404
+				'func'       => '_add_message_template',
405
+				'capability' => 'ee_edit_messages',
406
+				'noheader'   => true
407
+			),
408
+			'edit_message_template'            => array(
409
+				'func'       => '_edit_message_template',
410
+				'capability' => 'ee_edit_message',
411
+				'obj_id'     => $grp_id
412
+			),
413
+			'preview_message'                  => array(
414
+				'func'               => '_preview_message',
415
+				'capability'         => 'ee_read_message',
416
+				'obj_id'             => $grp_id,
417
+				'noheader'           => true,
418
+				'headers_sent_route' => 'display_preview_message'
419
+			),
420
+			'display_preview_message'          => array(
421
+				'func'       => '_display_preview_message',
422
+				'capability' => 'ee_read_message',
423
+				'obj_id'     => $grp_id
424
+			),
425
+			'insert_message_template'          => array(
426
+				'func'       => '_insert_or_update_message_template',
427
+				'capability' => 'ee_edit_messages',
428
+				'args'       => array('new_template' => true),
429
+				'noheader'   => true
430
+			),
431
+			'update_message_template'          => array(
432
+				'func'       => '_insert_or_update_message_template',
433
+				'capability' => 'ee_edit_message',
434
+				'obj_id'     => $grp_id,
435
+				'args'       => array('new_template' => false),
436
+				'noheader'   => true
437
+			),
438
+			'trash_message_template'           => array(
439
+				'func'       => '_trash_or_restore_message_template',
440
+				'capability' => 'ee_delete_message',
441
+				'obj_id'     => $grp_id,
442
+				'args'       => array('trash' => true, 'all' => true),
443
+				'noheader'   => true
444
+			),
445
+			'trash_message_template_context'   => array(
446
+				'func'       => '_trash_or_restore_message_template',
447
+				'capability' => 'ee_delete_message',
448
+				'obj_id'     => $grp_id,
449
+				'args'       => array('trash' => true),
450
+				'noheader'   => true
451
+			),
452
+			'restore_message_template'         => array(
453
+				'func'       => '_trash_or_restore_message_template',
454
+				'capability' => 'ee_delete_message',
455
+				'obj_id'     => $grp_id,
456
+				'args'       => array('trash' => false, 'all' => true),
457
+				'noheader'   => true
458
+			),
459
+			'restore_message_template_context' => array(
460
+				'func'       => '_trash_or_restore_message_template',
461
+				'capability' => 'ee_delete_message',
462
+				'obj_id'     => $grp_id,
463
+				'args'       => array('trash' => false),
464
+				'noheader'   => true
465
+			),
466
+			'delete_message_template'          => array(
467
+				'func'       => '_delete_message_template',
468
+				'capability' => 'ee_delete_message',
469
+				'obj_id'     => $grp_id,
470
+				'noheader'   => true
471
+			),
472
+			'reset_to_default'                 => array(
473
+				'func'       => '_reset_to_default_template',
474
+				'capability' => 'ee_edit_message',
475
+				'obj_id'     => $grp_id,
476
+				'noheader'   => true
477
+			),
478
+			'settings'                         => array(
479
+				'func'       => '_settings',
480
+				'capability' => 'manage_options'
481
+			),
482
+			'update_global_settings'           => array(
483
+				'func'       => '_update_global_settings',
484
+				'capability' => 'manage_options',
485
+				'noheader'   => true
486
+			),
487
+			'generate_now'                     => array(
488
+				'func'       => '_generate_now',
489
+				'capability' => 'ee_send_message',
490
+				'noheader'   => true
491
+			),
492
+			'generate_and_send_now'            => array(
493
+				'func'       => '_generate_and_send_now',
494
+				'capability' => 'ee_send_message',
495
+				'noheader'   => true
496
+			),
497
+			'queue_for_resending'              => array(
498
+				'func'       => '_queue_for_resending',
499
+				'capability' => 'ee_send_message',
500
+				'noheader'   => true
501
+			),
502
+			'send_now'                         => array(
503
+				'func'       => '_send_now',
504
+				'capability' => 'ee_send_message',
505
+				'noheader'   => true
506
+			),
507
+			'delete_ee_message'                => array(
508
+				'func'       => '_delete_ee_messages',
509
+				'capability' => 'ee_delete_messages',
510
+				'noheader'   => true
511
+			),
512
+			'delete_ee_messages'               => array(
513
+				'func'       => '_delete_ee_messages',
514
+				'capability' => 'ee_delete_messages',
515
+				'noheader'   => true,
516
+				'obj_id'     => $msg_id
517
+			)
518
+		);
519
+	}
520 520
     
521 521
     
522
-    protected function _set_page_config()
523
-    {
524
-        $this->_page_config = array(
525
-            'default'                  => array(
526
-                'nav'           => array(
527
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
528
-                    'order' => 10
529
-                ),
530
-                'list_table'    => 'EE_Message_List_Table',
531
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
-                'require_nonce' => false
533
-            ),
534
-            'global_mtps'              => array(
535
-                'nav'           => array(
536
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
-                    'order' => 20
538
-                ),
539
-                'list_table'    => 'Messages_Template_List_Table',
540
-                'help_tabs'     => array(
541
-                    'messages_overview_help_tab'                                => array(
542
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
-                        'filename' => 'messages_overview'
544
-                    ),
545
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
546
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
-                        'filename' => 'messages_overview_table_column_headings'
548
-                    ),
549
-                    'messages_overview_messages_filters_help_tab'               => array(
550
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
551
-                        'filename' => 'messages_overview_filters'
552
-                    ),
553
-                    'messages_overview_messages_views_help_tab'                 => array(
554
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
555
-                        'filename' => 'messages_overview_views'
556
-                    ),
557
-                    'message_overview_message_types_help_tab'                   => array(
558
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
559
-                        'filename' => 'messages_overview_types'
560
-                    ),
561
-                    'messages_overview_messengers_help_tab'                     => array(
562
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
563
-                        'filename' => 'messages_overview_messengers',
564
-                    ),
565
-                ),
566
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
567
-                'require_nonce' => false
568
-            ),
569
-            'custom_mtps'              => array(
570
-                'nav'           => array(
571
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
-                    'order' => 30
573
-                ),
574
-                'help_tabs'     => array(),
575
-                'help_tour'     => array(),
576
-                'require_nonce' => false
577
-            ),
578
-            'add_new_message_template' => array(
579
-                'nav'           => array(
580
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
-                    'order'      => 5,
582
-                    'persistent' => false
583
-                ),
584
-                'require_nonce' => false
585
-            ),
586
-            'edit_message_template'    => array(
587
-                'labels'        => array(
588
-                    'buttons'    => array(
589
-                        'reset' => esc_html__('Reset Templates'),
590
-                    ),
591
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
-                ),
593
-                'nav'           => array(
594
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
-                    'order'      => 5,
596
-                    'persistent' => false,
597
-                    'url'        => ''
598
-                ),
599
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
-                'has_metaboxes' => true,
601
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
-                'help_tabs'     => array(
603
-                    'edit_message_template'       => array(
604
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
-                        'callback' => 'edit_message_template_help_tab'
606
-                    ),
607
-                    'message_templates_help_tab'  => array(
608
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
609
-                        'filename' => 'messages_templates'
610
-                    ),
611
-                    'message_template_shortcodes' => array(
612
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
-                        'callback' => 'message_template_shortcodes_help_tab'
614
-                    ),
615
-                    'message_preview_help_tab'    => array(
616
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
617
-                        'filename' => 'messages_preview'
618
-                    ),
619
-                    'messages_overview_other_help_tab'                          => array(
620
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
621
-                        'filename' => 'messages_overview_other',
622
-                    ),
623
-                ),
624
-                'require_nonce' => false
625
-            ),
626
-            'display_preview_message'  => array(
627
-                'nav'           => array(
628
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
629
-                    'order'      => 5,
630
-                    'url'        => '',
631
-                    'persistent' => false
632
-                ),
633
-                'help_tabs'     => array(
634
-                    'preview_message' => array(
635
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
636
-                        'callback' => 'preview_message_help_tab'
637
-                    )
638
-                ),
639
-                'require_nonce' => false
640
-            ),
641
-            'settings'                 => array(
642
-                'nav'           => array(
643
-                    'label' => esc_html__('Settings', 'event_espresso'),
644
-                    'order' => 40
645
-                ),
646
-                'metaboxes'     => array('_messages_settings_metaboxes'),
647
-                'help_tabs'     => array(
648
-                    'messages_settings_help_tab'               => array(
649
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
-                        'filename' => 'messages_settings'
651
-                    ),
652
-                    'messages_settings_message_types_help_tab' => array(
653
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
-                        'filename' => 'messages_settings_message_types'
655
-                    ),
656
-                    'messages_settings_messengers_help_tab'    => array(
657
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
-                        'filename' => 'messages_settings_messengers'
659
-                    ),
660
-                ),
661
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
662
-                'require_nonce' => false
663
-            )
664
-        );
665
-    }
522
+	protected function _set_page_config()
523
+	{
524
+		$this->_page_config = array(
525
+			'default'                  => array(
526
+				'nav'           => array(
527
+					'label' => esc_html__('Message Activity', 'event_espresso'),
528
+					'order' => 10
529
+				),
530
+				'list_table'    => 'EE_Message_List_Table',
531
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
+				'require_nonce' => false
533
+			),
534
+			'global_mtps'              => array(
535
+				'nav'           => array(
536
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
+					'order' => 20
538
+				),
539
+				'list_table'    => 'Messages_Template_List_Table',
540
+				'help_tabs'     => array(
541
+					'messages_overview_help_tab'                                => array(
542
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
+						'filename' => 'messages_overview'
544
+					),
545
+					'messages_overview_messages_table_column_headings_help_tab' => array(
546
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
+						'filename' => 'messages_overview_table_column_headings'
548
+					),
549
+					'messages_overview_messages_filters_help_tab'               => array(
550
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
551
+						'filename' => 'messages_overview_filters'
552
+					),
553
+					'messages_overview_messages_views_help_tab'                 => array(
554
+						'title'    => esc_html__('Message Views', 'event_espresso'),
555
+						'filename' => 'messages_overview_views'
556
+					),
557
+					'message_overview_message_types_help_tab'                   => array(
558
+						'title'    => esc_html__('Message Types', 'event_espresso'),
559
+						'filename' => 'messages_overview_types'
560
+					),
561
+					'messages_overview_messengers_help_tab'                     => array(
562
+						'title'    => esc_html__('Messengers', 'event_espresso'),
563
+						'filename' => 'messages_overview_messengers',
564
+					),
565
+				),
566
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
567
+				'require_nonce' => false
568
+			),
569
+			'custom_mtps'              => array(
570
+				'nav'           => array(
571
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
+					'order' => 30
573
+				),
574
+				'help_tabs'     => array(),
575
+				'help_tour'     => array(),
576
+				'require_nonce' => false
577
+			),
578
+			'add_new_message_template' => array(
579
+				'nav'           => array(
580
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
+					'order'      => 5,
582
+					'persistent' => false
583
+				),
584
+				'require_nonce' => false
585
+			),
586
+			'edit_message_template'    => array(
587
+				'labels'        => array(
588
+					'buttons'    => array(
589
+						'reset' => esc_html__('Reset Templates'),
590
+					),
591
+					'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
+				),
593
+				'nav'           => array(
594
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
+					'order'      => 5,
596
+					'persistent' => false,
597
+					'url'        => ''
598
+				),
599
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
+				'has_metaboxes' => true,
601
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
+				'help_tabs'     => array(
603
+					'edit_message_template'       => array(
604
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
+						'callback' => 'edit_message_template_help_tab'
606
+					),
607
+					'message_templates_help_tab'  => array(
608
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
609
+						'filename' => 'messages_templates'
610
+					),
611
+					'message_template_shortcodes' => array(
612
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
+						'callback' => 'message_template_shortcodes_help_tab'
614
+					),
615
+					'message_preview_help_tab'    => array(
616
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
617
+						'filename' => 'messages_preview'
618
+					),
619
+					'messages_overview_other_help_tab'                          => array(
620
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
621
+						'filename' => 'messages_overview_other',
622
+					),
623
+				),
624
+				'require_nonce' => false
625
+			),
626
+			'display_preview_message'  => array(
627
+				'nav'           => array(
628
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
629
+					'order'      => 5,
630
+					'url'        => '',
631
+					'persistent' => false
632
+				),
633
+				'help_tabs'     => array(
634
+					'preview_message' => array(
635
+						'title'    => esc_html__('About Previews', 'event_espresso'),
636
+						'callback' => 'preview_message_help_tab'
637
+					)
638
+				),
639
+				'require_nonce' => false
640
+			),
641
+			'settings'                 => array(
642
+				'nav'           => array(
643
+					'label' => esc_html__('Settings', 'event_espresso'),
644
+					'order' => 40
645
+				),
646
+				'metaboxes'     => array('_messages_settings_metaboxes'),
647
+				'help_tabs'     => array(
648
+					'messages_settings_help_tab'               => array(
649
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
+						'filename' => 'messages_settings'
651
+					),
652
+					'messages_settings_message_types_help_tab' => array(
653
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
+						'filename' => 'messages_settings_message_types'
655
+					),
656
+					'messages_settings_messengers_help_tab'    => array(
657
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
+						'filename' => 'messages_settings_messengers'
659
+					),
660
+				),
661
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
662
+				'require_nonce' => false
663
+			)
664
+		);
665
+	}
666 666
     
667 667
     
668
-    protected function _add_screen_options()
669
-    {
670
-        //todo
671
-    }
668
+	protected function _add_screen_options()
669
+	{
670
+		//todo
671
+	}
672 672
     
673 673
     
674
-    protected function _add_screen_options_global_mtps()
675
-    {
676
-        /**
677
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
679
-         */
680
-        $page_title              = $this->_admin_page_title;
681
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
-        $this->_per_page_screen_option();
683
-        $this->_admin_page_title = $page_title;
684
-    }
674
+	protected function _add_screen_options_global_mtps()
675
+	{
676
+		/**
677
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
679
+		 */
680
+		$page_title              = $this->_admin_page_title;
681
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
+		$this->_per_page_screen_option();
683
+		$this->_admin_page_title = $page_title;
684
+	}
685 685
     
686 686
     
687
-    protected function _add_screen_options_default()
688
-    {
689
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
-        $this->_per_page_screen_option();
691
-    }
687
+	protected function _add_screen_options_default()
688
+	{
689
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
+		$this->_per_page_screen_option();
691
+	}
692 692
     
693 693
     
694
-    //none of the below group are currently used for Messages
695
-    protected function _add_feature_pointers()
696
-    {
697
-    }
694
+	//none of the below group are currently used for Messages
695
+	protected function _add_feature_pointers()
696
+	{
697
+	}
698 698
     
699
-    public function admin_init()
700
-    {
701
-    }
699
+	public function admin_init()
700
+	{
701
+	}
702 702
     
703
-    public function admin_notices()
704
-    {
705
-    }
703
+	public function admin_notices()
704
+	{
705
+	}
706 706
     
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710 710
     
711 711
     
712
-    public function messages_help_tab()
713
-    {
714
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
-    }
712
+	public function messages_help_tab()
713
+	{
714
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
+	}
716 716
     
717 717
     
718
-    public function messengers_help_tab()
719
-    {
720
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
-    }
718
+	public function messengers_help_tab()
719
+	{
720
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
+	}
722 722
     
723 723
     
724
-    public function message_types_help_tab()
725
-    {
726
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
-    }
724
+	public function message_types_help_tab()
725
+	{
726
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
+	}
728 728
     
729 729
     
730
-    public function messages_overview_help_tab()
731
-    {
732
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
-    }
730
+	public function messages_overview_help_tab()
731
+	{
732
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
+	}
734 734
     
735 735
     
736
-    public function message_templates_help_tab()
737
-    {
738
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
-    }
736
+	public function message_templates_help_tab()
737
+	{
738
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
+	}
740 740
     
741 741
     
742
-    public function edit_message_template_help_tab()
743
-    {
744
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
-                        . esc_attr__('Editor Title', 'event_espresso')
746
-                        . '" />';
747
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
749
-                        . '" />';
750
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
752
-                        . '" />';
753
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
755
-                        . '" />';
756
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
-                        . esc_attr__('Publish Metabox', 'event_espresso')
758
-                        . '" />';
759
-        EEH_Template::display_template(
760
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
-            $args
762
-        );
763
-    }
742
+	public function edit_message_template_help_tab()
743
+	{
744
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
+						. esc_attr__('Editor Title', 'event_espresso')
746
+						. '" />';
747
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
749
+						. '" />';
750
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
752
+						. '" />';
753
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
755
+						. '" />';
756
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
+						. esc_attr__('Publish Metabox', 'event_espresso')
758
+						. '" />';
759
+		EEH_Template::display_template(
760
+			EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
+			$args
762
+		);
763
+	}
764 764
     
765 765
     
766
-    public function message_template_shortcodes_help_tab()
767
-    {
768
-        $this->_set_shortcodes();
769
-        $args['shortcodes'] = $this->_shortcodes;
770
-        EEH_Template::display_template(
771
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
-            $args
773
-        );
774
-    }
766
+	public function message_template_shortcodes_help_tab()
767
+	{
768
+		$this->_set_shortcodes();
769
+		$args['shortcodes'] = $this->_shortcodes;
770
+		EEH_Template::display_template(
771
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
+			$args
773
+		);
774
+	}
775 775
     
776 776
     
777
-    public function preview_message_help_tab()
778
-    {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
-    }
777
+	public function preview_message_help_tab()
778
+	{
779
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
+	}
781 781
     
782 782
     
783
-    public function settings_help_tab()
784
-    {
785
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
-        $args['img3'] = '<div class="switch">'
790
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
-                        . ' type="checkbox" checked="checked">'
792
-                        . '<label for="ee-on-off-toggle-on"></label>'
793
-                        . '</div>';
794
-        $args['img4'] = '<div class="switch">'
795
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
-                        . ' type="checkbox">'
797
-                        . '<label for="ee-on-off-toggle-on"></label>'
798
-                        . '</div>';
799
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
-    }
783
+	public function settings_help_tab()
784
+	{
785
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
+		$args['img3'] = '<div class="switch">'
790
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
+						. ' type="checkbox" checked="checked">'
792
+						. '<label for="ee-on-off-toggle-on"></label>'
793
+						. '</div>';
794
+		$args['img4'] = '<div class="switch">'
795
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
+						. ' type="checkbox">'
797
+						. '<label for="ee-on-off-toggle-on"></label>'
798
+						. '</div>';
799
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
+	}
801 801
     
802 802
     
803
-    public function load_scripts_styles()
804
-    {
805
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
-        wp_enqueue_style('espresso_ee_msg');
807
-        
808
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
-    }
803
+	public function load_scripts_styles()
804
+	{
805
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
+		wp_enqueue_style('espresso_ee_msg');
807
+        
808
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
+	}
813 813
     
814 814
     
815
-    public function load_scripts_styles_default()
816
-    {
817
-        wp_enqueue_script('ee-msg-list-table-js');
818
-    }
815
+	public function load_scripts_styles_default()
816
+	{
817
+		wp_enqueue_script('ee-msg-list-table-js');
818
+	}
819 819
     
820 820
     
821
-    public function wp_editor_css($mce_css)
822
-    {
823
-        //if we're on the edit_message_template route
824
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
-            $message_type_name = $this->_active_message_type_name;
821
+	public function wp_editor_css($mce_css)
822
+	{
823
+		//if we're on the edit_message_template route
824
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
+			$message_type_name = $this->_active_message_type_name;
826 826
             
827
-            //we're going to REPLACE the existing mce css
828
-            //we need to get the css file location from the active messenger
829
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
-                'wpeditor', $this->_variation);
831
-        }
832
-        
833
-        return $mce_css;
834
-    }
827
+			//we're going to REPLACE the existing mce css
828
+			//we need to get the css file location from the active messenger
829
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
+				'wpeditor', $this->_variation);
831
+		}
832
+        
833
+		return $mce_css;
834
+	}
835 835
     
836 836
     
837
-    public function load_scripts_styles_edit_message_template()
838
-    {
839
-        
840
-        $this->_set_shortcodes();
841
-        
842
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
-            esc_html__(
844
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
845
-                'event_espresso'
846
-            ),
847
-            $this->_message_template_group->messenger_obj()->label['singular'],
848
-            $this->_message_template_group->message_type_obj()->label['singular']
849
-        );
850
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
852
-            'event_espresso'
853
-        );
854
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
-            'event_espresso'
857
-        );
858
-        
859
-        wp_register_script(
860
-            'ee_msgs_edit_js',
861
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
-            array('jquery'),
863
-            EVENT_ESPRESSO_VERSION
864
-        );
865
-        
866
-        wp_enqueue_script('ee_admin_js');
867
-        wp_enqueue_script('ee_msgs_edit_js');
868
-        
869
-        //add in special css for tiny_mce
870
-        add_filter('mce_css', array($this, 'wp_editor_css'));
871
-    }
837
+	public function load_scripts_styles_edit_message_template()
838
+	{
839
+        
840
+		$this->_set_shortcodes();
841
+        
842
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
+			esc_html__(
844
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
845
+				'event_espresso'
846
+			),
847
+			$this->_message_template_group->messenger_obj()->label['singular'],
848
+			$this->_message_template_group->message_type_obj()->label['singular']
849
+		);
850
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
852
+			'event_espresso'
853
+		);
854
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
+			'event_espresso'
857
+		);
858
+        
859
+		wp_register_script(
860
+			'ee_msgs_edit_js',
861
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
+			array('jquery'),
863
+			EVENT_ESPRESSO_VERSION
864
+		);
865
+        
866
+		wp_enqueue_script('ee_admin_js');
867
+		wp_enqueue_script('ee_msgs_edit_js');
868
+        
869
+		//add in special css for tiny_mce
870
+		add_filter('mce_css', array($this, 'wp_editor_css'));
871
+	}
872 872
     
873 873
     
874
-    public function load_scripts_styles_display_preview_message()
875
-    {
876
-        
877
-        $this->_set_message_template_group();
878
-        
879
-        if (isset($this->_req_data['messenger'])) {
880
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
-                $this->_req_data['messenger']
882
-            );
883
-        }
884
-        
885
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
-        
887
-        
888
-        wp_enqueue_style('espresso_preview_css',
889
-            $this->_active_messenger->get_variation(
890
-                $this->_template_pack,
891
-                $message_type_name,
892
-                true,
893
-                'preview',
894
-                $this->_variation
895
-            )
896
-        );
897
-    }
874
+	public function load_scripts_styles_display_preview_message()
875
+	{
876
+        
877
+		$this->_set_message_template_group();
878
+        
879
+		if (isset($this->_req_data['messenger'])) {
880
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
+				$this->_req_data['messenger']
882
+			);
883
+		}
884
+        
885
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
+        
887
+        
888
+		wp_enqueue_style('espresso_preview_css',
889
+			$this->_active_messenger->get_variation(
890
+				$this->_template_pack,
891
+				$message_type_name,
892
+				true,
893
+				'preview',
894
+				$this->_variation
895
+			)
896
+		);
897
+	}
898 898
     
899 899
     
900
-    public function load_scripts_styles_settings()
901
-    {
902
-        wp_register_style(
903
-            'ee-message-settings',
904
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
-            array(),
906
-            EVENT_ESPRESSO_VERSION
907
-        );
908
-        wp_enqueue_style('ee-text-links');
909
-        wp_enqueue_style('ee-message-settings');
910
-        wp_enqueue_script('ee-messages-settings');
911
-    }
900
+	public function load_scripts_styles_settings()
901
+	{
902
+		wp_register_style(
903
+			'ee-message-settings',
904
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
+			array(),
906
+			EVENT_ESPRESSO_VERSION
907
+		);
908
+		wp_enqueue_style('ee-text-links');
909
+		wp_enqueue_style('ee-message-settings');
910
+		wp_enqueue_script('ee-messages-settings');
911
+	}
912 912
     
913 913
     
914
-    /**
915
-     * set views array for List Table
916
-     */
917
-    public function _set_list_table_views_global_mtps()
918
-    {
919
-        $this->_views = array(
920
-            'in_use' => array(
921
-                'slug'        => 'in_use',
922
-                'label'       => esc_html__('In Use', 'event_espresso'),
923
-                'count'       => 0,
924
-            )
925
-        );
926
-    }
914
+	/**
915
+	 * set views array for List Table
916
+	 */
917
+	public function _set_list_table_views_global_mtps()
918
+	{
919
+		$this->_views = array(
920
+			'in_use' => array(
921
+				'slug'        => 'in_use',
922
+				'label'       => esc_html__('In Use', 'event_espresso'),
923
+				'count'       => 0,
924
+			)
925
+		);
926
+	}
927 927
 
928 928
 
929
-    /**
930
-     * Set views array for the Custom Template List Table
931
-     */
932
-    public function _set_list_table_views_custom_mtps()
933
-    {
934
-        $this->_set_list_table_views_global_mtps();
935
-        $this->_views['in_use']['bulk_action'] = array(
936
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
-        );
938
-    }
929
+	/**
930
+	 * Set views array for the Custom Template List Table
931
+	 */
932
+	public function _set_list_table_views_custom_mtps()
933
+	{
934
+		$this->_set_list_table_views_global_mtps();
935
+		$this->_views['in_use']['bulk_action'] = array(
936
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
+		);
938
+	}
939 939
 
940 940
 
941
-    /**
942
-     * set views array for message queue list table
943
-     *
944
-     * @throws InvalidDataTypeException
945
-     * @throws InvalidInterfaceException
946
-     * @throws InvalidArgumentException
947
-     * @throws EE_Error
948
-     * @throws ReflectionException
949
-     */
950
-    public function _set_list_table_views_default()
951
-    {
952
-        EE_Registry::instance()->load_helper('Template');
953
-        
954
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
-            'ee_send_message',
956
-            'message_list_table_bulk_actions'
957
-        )
958
-            ? array(
959
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
-                'send_now'              => esc_html__('Send Now', 'event_espresso')
963
-            )
964
-            : array();
965
-        
966
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
-            'ee_delete_messages',
968
-            'message_list_table_bulk_actions'
969
-        )
970
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
-            : array();
972
-        
973
-        
974
-        $this->_views = array(
975
-            'all' => array(
976
-                'slug'        => 'all',
977
-                'label'       => esc_html__('All', 'event_espresso'),
978
-                'count'       => 0,
979
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
-            )
981
-        );
982
-        
983
-        
984
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
985
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
-                continue;
987
-            }
988
-            $status_bulk_actions = $common_bulk_actions;
989
-            //unset bulk actions not applying to status
990
-            if (! empty($status_bulk_actions)) {
991
-                switch ($status) {
992
-                    case EEM_Message::status_idle:
993
-                    case EEM_Message::status_resend:
994
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
-                        break;
941
+	/**
942
+	 * set views array for message queue list table
943
+	 *
944
+	 * @throws InvalidDataTypeException
945
+	 * @throws InvalidInterfaceException
946
+	 * @throws InvalidArgumentException
947
+	 * @throws EE_Error
948
+	 * @throws ReflectionException
949
+	 */
950
+	public function _set_list_table_views_default()
951
+	{
952
+		EE_Registry::instance()->load_helper('Template');
953
+        
954
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
+			'ee_send_message',
956
+			'message_list_table_bulk_actions'
957
+		)
958
+			? array(
959
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
+				'send_now'              => esc_html__('Send Now', 'event_espresso')
963
+			)
964
+			: array();
965
+        
966
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
+			'ee_delete_messages',
968
+			'message_list_table_bulk_actions'
969
+		)
970
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
+			: array();
972
+        
973
+        
974
+		$this->_views = array(
975
+			'all' => array(
976
+				'slug'        => 'all',
977
+				'label'       => esc_html__('All', 'event_espresso'),
978
+				'count'       => 0,
979
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
+			)
981
+		);
982
+        
983
+        
984
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
985
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
+				continue;
987
+			}
988
+			$status_bulk_actions = $common_bulk_actions;
989
+			//unset bulk actions not applying to status
990
+			if (! empty($status_bulk_actions)) {
991
+				switch ($status) {
992
+					case EEM_Message::status_idle:
993
+					case EEM_Message::status_resend:
994
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
+						break;
996 996
                     
997
-                    case EEM_Message::status_failed:
998
-                    case EEM_Message::status_debug_only:
999
-                    case EEM_Message::status_messenger_executing:
1000
-                        $status_bulk_actions = array();
1001
-                        break;
997
+					case EEM_Message::status_failed:
998
+					case EEM_Message::status_debug_only:
999
+					case EEM_Message::status_messenger_executing:
1000
+						$status_bulk_actions = array();
1001
+						break;
1002 1002
                     
1003
-                    case EEM_Message::status_incomplete:
1004
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
-                        break;
1003
+					case EEM_Message::status_incomplete:
1004
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
+						break;
1006 1006
                     
1007
-                    case EEM_Message::status_retry:
1008
-                    case EEM_Message::status_sent:
1009
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
-                        break;
1011
-                }
1012
-            }
1007
+					case EEM_Message::status_retry:
1008
+					case EEM_Message::status_sent:
1009
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
+						break;
1011
+				}
1012
+			}
1013 1013
 
1014
-            //skip adding messenger executing status to views because it will be included with the Failed view.
1015
-            if ( $status === EEM_Message::status_messenger_executing ) {
1016
-                continue;
1017
-            }
1014
+			//skip adding messenger executing status to views because it will be included with the Failed view.
1015
+			if ( $status === EEM_Message::status_messenger_executing ) {
1016
+				continue;
1017
+			}
1018 1018
             
1019
-            $this->_views[strtolower($status)] = array(
1020
-                'slug'        => strtolower($status),
1021
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
-                'count'       => 0,
1023
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
-            );
1025
-        }
1026
-    }
1019
+			$this->_views[strtolower($status)] = array(
1020
+				'slug'        => strtolower($status),
1021
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
+				'count'       => 0,
1023
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
+			);
1025
+		}
1026
+	}
1027 1027
     
1028 1028
     
1029
-    protected function _ee_default_messages_overview_list_table()
1030
-    {
1031
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
-        $this->display_admin_list_table_page_with_no_sidebar();
1033
-    }
1029
+	protected function _ee_default_messages_overview_list_table()
1030
+	{
1031
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
+		$this->display_admin_list_table_page_with_no_sidebar();
1033
+	}
1034 1034
     
1035 1035
     
1036
-    protected function _message_queue_list_table()
1037
-    {
1038
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
-        $this->_template_args['per_column']        = 6;
1040
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
-        $this->_template_args['before_list_table'] = '<h3>'
1042
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1043
-                                                     . '</h3>';
1044
-        $this->display_admin_list_table_page_with_no_sidebar();
1045
-    }
1036
+	protected function _message_queue_list_table()
1037
+	{
1038
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
+		$this->_template_args['per_column']        = 6;
1040
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
+		$this->_template_args['before_list_table'] = '<h3>'
1042
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1043
+													 . '</h3>';
1044
+		$this->display_admin_list_table_page_with_no_sidebar();
1045
+	}
1046 1046
     
1047 1047
     
1048
-    protected function _message_legend_items()
1049
-    {
1050
-        
1051
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
-        $action_items       = array();
1053
-        
1054
-        foreach ($action_css_classes as $action_item => $action_details) {
1055
-            if ($action_item === 'see_notifications_for') {
1056
-                continue;
1057
-            }
1058
-            $action_items[$action_item] = array(
1059
-                'class' => $action_details['css_class'],
1060
-                'desc'  => $action_details['label']
1061
-            );
1062
-        }
1063
-        
1064
-        /** @type array $status_items status legend setup */
1065
-        $status_items = array(
1066
-            'sent_status'       => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
-            ),
1070
-            'idle_status'       => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
-            ),
1074
-            'failed_status'     => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
-            ),
1078
-            'messenger_executing_status' => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
-            ),
1082
-            'resend_status'     => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
-            ),
1086
-            'incomplete_status' => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
-            ),
1090
-            'retry_status'      => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
-            )
1094
-        );
1095
-        if (EEM_Message::debug()) {
1096
-            $status_items['debug_only_status'] = array(
1097
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
-            );
1100
-        }
1101
-        
1102
-        return array_merge($action_items, $status_items);
1103
-    }
1048
+	protected function _message_legend_items()
1049
+	{
1050
+        
1051
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
+		$action_items       = array();
1053
+        
1054
+		foreach ($action_css_classes as $action_item => $action_details) {
1055
+			if ($action_item === 'see_notifications_for') {
1056
+				continue;
1057
+			}
1058
+			$action_items[$action_item] = array(
1059
+				'class' => $action_details['css_class'],
1060
+				'desc'  => $action_details['label']
1061
+			);
1062
+		}
1063
+        
1064
+		/** @type array $status_items status legend setup */
1065
+		$status_items = array(
1066
+			'sent_status'       => array(
1067
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
+			),
1070
+			'idle_status'       => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
+			),
1074
+			'failed_status'     => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
+			),
1078
+			'messenger_executing_status' => array(
1079
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
+			),
1082
+			'resend_status'     => array(
1083
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
+			),
1086
+			'incomplete_status' => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
+			),
1090
+			'retry_status'      => array(
1091
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
+			)
1094
+		);
1095
+		if (EEM_Message::debug()) {
1096
+			$status_items['debug_only_status'] = array(
1097
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
+			);
1100
+		}
1101
+        
1102
+		return array_merge($action_items, $status_items);
1103
+	}
1104 1104
     
1105 1105
     
1106
-    protected function _custom_mtps_preview()
1107
-    {
1108
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
-        $this->_template_args['preview_text'] = '<strong>'
1112
-            . esc_html__(
1113
-                'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1114
-                'event_espresso'
1115
-            )
1116
-            . '</strong>';
1106
+	protected function _custom_mtps_preview()
1107
+	{
1108
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
+			. ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
+		$this->_template_args['preview_text'] = '<strong>'
1112
+			. esc_html__(
1113
+				'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1114
+				'event_espresso'
1115
+			)
1116
+			. '</strong>';
1117 1117
 
1118
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1119
-    }
1118
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1119
+	}
1120 1120
 
1121 1121
 
1122
-    /**
1123
-     * get_message_templates
1124
-     * This gets all the message templates for listing on the overview list.
1125
-     *
1126
-     * @access public
1127
-     * @param int    $perpage the amount of templates groups to show per page
1128
-     * @param string $type    the current _view we're getting templates for
1129
-     * @param bool   $count   return count?
1130
-     * @param bool   $all     disregard any paging info (get all data);
1131
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
-     * @return array
1133
-     * @throws EE_Error
1134
-     * @throws InvalidArgumentException
1135
-     * @throws InvalidDataTypeException
1136
-     * @throws InvalidInterfaceException
1137
-     */
1138
-    public function get_message_templates(
1139
-        $perpage = 10,
1140
-        $type = 'in_use',
1141
-        $count = false,
1142
-        $all = false,
1143
-        $global = true)
1144
-    {
1145
-        
1146
-        $MTP = EEM_Message_Template_Group::instance();
1147
-        
1148
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
-        $orderby                    = $this->_req_data['orderby'];
1150
-        
1151
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
-            ? $this->_req_data['order']
1153
-            : 'ASC';
1154
-        
1155
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
-            ? $this->_req_data['paged']
1157
-            : 1;
1158
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
-            ? $this->_req_data['perpage']
1160
-            : $perpage;
1161
-        
1162
-        $offset = ($current_page - 1) * $per_page;
1163
-        $limit  = $all ? null : array($offset, $per_page);
1164
-        
1165
-        
1166
-        //options will match what is in the _views array property
1167
-        switch ($type) {
1168
-            case 'in_use':
1169
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
-                break;
1171
-            default:
1172
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
-        }
1174
-        
1175
-        return $templates;
1176
-    }
1122
+	/**
1123
+	 * get_message_templates
1124
+	 * This gets all the message templates for listing on the overview list.
1125
+	 *
1126
+	 * @access public
1127
+	 * @param int    $perpage the amount of templates groups to show per page
1128
+	 * @param string $type    the current _view we're getting templates for
1129
+	 * @param bool   $count   return count?
1130
+	 * @param bool   $all     disregard any paging info (get all data);
1131
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
+	 * @return array
1133
+	 * @throws EE_Error
1134
+	 * @throws InvalidArgumentException
1135
+	 * @throws InvalidDataTypeException
1136
+	 * @throws InvalidInterfaceException
1137
+	 */
1138
+	public function get_message_templates(
1139
+		$perpage = 10,
1140
+		$type = 'in_use',
1141
+		$count = false,
1142
+		$all = false,
1143
+		$global = true)
1144
+	{
1145
+        
1146
+		$MTP = EEM_Message_Template_Group::instance();
1147
+        
1148
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
+		$orderby                    = $this->_req_data['orderby'];
1150
+        
1151
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
+			? $this->_req_data['order']
1153
+			: 'ASC';
1154
+        
1155
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
+			? $this->_req_data['paged']
1157
+			: 1;
1158
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
+			? $this->_req_data['perpage']
1160
+			: $perpage;
1161
+        
1162
+		$offset = ($current_page - 1) * $per_page;
1163
+		$limit  = $all ? null : array($offset, $per_page);
1164
+        
1165
+        
1166
+		//options will match what is in the _views array property
1167
+		switch ($type) {
1168
+			case 'in_use':
1169
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
+				break;
1171
+			default:
1172
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
+		}
1174
+        
1175
+		return $templates;
1176
+	}
1177 1177
     
1178 1178
     
1179
-    /**
1180
-     * filters etc might need a list of installed message_types
1181
-     * @return array an array of message type objects
1182
-     */
1183
-    public function get_installed_message_types()
1184
-    {
1185
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
-        $installed               = array();
1187
-        
1188
-        foreach ($installed_message_types as $message_type) {
1189
-            $installed[$message_type->name] = $message_type;
1190
-        }
1191
-        
1192
-        return $installed;
1193
-    }
1179
+	/**
1180
+	 * filters etc might need a list of installed message_types
1181
+	 * @return array an array of message type objects
1182
+	 */
1183
+	public function get_installed_message_types()
1184
+	{
1185
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
+		$installed               = array();
1187
+        
1188
+		foreach ($installed_message_types as $message_type) {
1189
+			$installed[$message_type->name] = $message_type;
1190
+		}
1191
+        
1192
+		return $installed;
1193
+	}
1194 1194
     
1195 1195
     
1196
-    /**
1197
-     * _add_message_template
1198
-     *
1199
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1200
-     *
1201
-     * @param string $message_type
1202
-     * @param string $messenger
1203
-     * @param string $GRP_ID
1204
-     *
1205
-     * @throws EE_error
1206
-     */
1207
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
-    {
1209
-        //set values override any request data
1210
-        $message_type = ! empty($message_type) ? $message_type : '';
1211
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
-            ? $this->_req_data['message_type']
1213
-            : $message_type;
1214
-        
1215
-        $messenger = ! empty($messenger) ? $messenger : '';
1216
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
-            ? $this->_req_data['messenger']
1218
-            : $messenger;
1219
-        
1220
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
-        
1223
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
-        if (empty($message_type) || empty($messenger)) {
1225
-            throw new EE_Error(
1226
-                esc_html__(
1227
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
-                    'event_espresso'
1229
-                )
1230
-            );
1231
-        }
1232
-        
1233
-        //we need the GRP_ID for the template being used as the base for the new template
1234
-        if (empty($GRP_ID)) {
1235
-            throw new EE_Error(
1236
-                esc_html__(
1237
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
-                    'event_espresso'
1239
-                )
1240
-            );
1241
-        }
1242
-        
1243
-        //let's just make sure the template gets generated!
1244
-        
1245
-        //we need to reassign some variables for what the insert is expecting
1246
-        $this->_req_data['MTP_messenger']    = $messenger;
1247
-        $this->_req_data['MTP_message_type'] = $message_type;
1248
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1249
-        $this->_insert_or_update_message_template(true);
1250
-    }
1196
+	/**
1197
+	 * _add_message_template
1198
+	 *
1199
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1200
+	 *
1201
+	 * @param string $message_type
1202
+	 * @param string $messenger
1203
+	 * @param string $GRP_ID
1204
+	 *
1205
+	 * @throws EE_error
1206
+	 */
1207
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
+	{
1209
+		//set values override any request data
1210
+		$message_type = ! empty($message_type) ? $message_type : '';
1211
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
+			? $this->_req_data['message_type']
1213
+			: $message_type;
1214
+        
1215
+		$messenger = ! empty($messenger) ? $messenger : '';
1216
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
+			? $this->_req_data['messenger']
1218
+			: $messenger;
1219
+        
1220
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
+        
1223
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
+		if (empty($message_type) || empty($messenger)) {
1225
+			throw new EE_Error(
1226
+				esc_html__(
1227
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
+					'event_espresso'
1229
+				)
1230
+			);
1231
+		}
1232
+        
1233
+		//we need the GRP_ID for the template being used as the base for the new template
1234
+		if (empty($GRP_ID)) {
1235
+			throw new EE_Error(
1236
+				esc_html__(
1237
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
+					'event_espresso'
1239
+				)
1240
+			);
1241
+		}
1242
+        
1243
+		//let's just make sure the template gets generated!
1244
+        
1245
+		//we need to reassign some variables for what the insert is expecting
1246
+		$this->_req_data['MTP_messenger']    = $messenger;
1247
+		$this->_req_data['MTP_message_type'] = $message_type;
1248
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1249
+		$this->_insert_or_update_message_template(true);
1250
+	}
1251 1251
 
1252 1252
 
1253
-    /**
1254
-     * public wrapper for the _add_message_template method
1255
-     *
1256
-     * @param string $message_type     message type slug
1257
-     * @param string $messenger        messenger slug
1258
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
-     *                                 off of.
1260
-     * @throws EE_error
1261
-     */
1262
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1263
-    {
1264
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
-    }
1253
+	/**
1254
+	 * public wrapper for the _add_message_template method
1255
+	 *
1256
+	 * @param string $message_type     message type slug
1257
+	 * @param string $messenger        messenger slug
1258
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
+	 *                                 off of.
1260
+	 * @throws EE_error
1261
+	 */
1262
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1263
+	{
1264
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
+	}
1266 1266
 
1267 1267
 
1268
-    /**
1269
-     * _edit_message_template
1270
-     *
1271
-     * @access protected
1272
-     * @return void
1273
-     * @throws InvalidIdentifierException
1274
-     * @throws DomainException
1275
-     * @throws EE_Error
1276
-     * @throws InvalidArgumentException
1277
-     * @throws ReflectionException
1278
-     * @throws InvalidDataTypeException
1279
-     * @throws InvalidInterfaceException
1280
-     */
1281
-    protected function _edit_message_template()
1282
-    {
1283
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
-        $template_fields = '';
1285
-        $sidebar_fields  = '';
1286
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
-        // valid html in the templates.
1288
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
-        
1290
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
-            ? absint($this->_req_data['id'])
1292
-            : false;
1293
-        
1294
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1295
-        $message_template_group = $this->_message_template_group;
1296
-        $c_label                = $message_template_group->context_label();
1297
-        $c_config               = $message_template_group->contexts_config();
1298
-        
1299
-        reset($c_config);
1300
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
-            ? strtolower($this->_req_data['context'])
1302
-            : key($c_config);
1303
-        
1304
-        
1305
-        if (empty($GRP_ID)) {
1306
-            $action = 'insert_message_template';
1307
-            $edit_message_template_form_url = add_query_arg(
1308
-                array('action' => $action, 'noheader' => true),
1309
-                EE_MSG_ADMIN_URL
1310
-            );
1311
-        } else {
1312
-            $action = 'update_message_template';
1313
-            $edit_message_template_form_url = add_query_arg(
1314
-                array('action' => $action, 'noheader' => true),
1315
-                EE_MSG_ADMIN_URL
1316
-            );
1317
-        }
1318
-        
1319
-        //set active messenger for this view
1320
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
-            $message_template_group->messenger()
1322
-        );
1323
-        $this->_active_message_type_name = $message_template_group->message_type();
1324
-        
1325
-        
1326
-        //Do we have any validation errors?
1327
-        $validators = $this->_get_transient();
1328
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
-        
1330
-        
1331
-        //we need to assemble the title from Various details
1332
-        $context_label = sprintf(
1333
-            esc_html__('(%s %s)', 'event_espresso'),
1334
-            $c_config[$context]['label'],
1335
-            ucwords($c_label['label'])
1336
-        );
1337
-        
1338
-        $title = sprintf(
1339
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1340
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1341
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1342
-            $context_label
1343
-        );
1344
-        
1345
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1346
-        $this->_template_args['message_template'] = $message_template_group;
1347
-        $this->_template_args['is_extra_fields']  = false;
1348
-        
1349
-        
1350
-        //let's get EEH_MSG_Template so we can get template form fields
1351
-        $template_field_structure = EEH_MSG_Template::get_fields(
1352
-            $message_template_group->messenger(),
1353
-            $message_template_group->message_type()
1354
-        );
1355
-        
1356
-        if ( ! $template_field_structure) {
1357
-            $template_field_structure = false;
1358
-            $template_fields          = esc_html__(
1359
-                'There was an error in assembling the fields for this display (you should see an error message)',
1360
-                'event_espresso'
1361
-            );
1362
-        }
1363
-        
1364
-        
1365
-        $message_templates = $message_template_group->context_templates();
1366
-        
1367
-        
1368
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
-        // will get handled in the "extra" array.
1370
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
-                unset($template_field_structure[$context][$reference_field]);
1373
-            }
1374
-        }
1375
-        
1376
-        //let's loop through the template_field_structure and actually assemble the input fields!
1377
-        if ( ! empty($template_field_structure)) {
1378
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
-                // the extra array and reset them.
1381
-                if ($template_field === 'extra') {
1382
-                    $this->_template_args['is_extra_fields'] = true;
1383
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
-                        $message_template = $message_templates[$context][$reference_field];
1385
-                        $content          = $message_template instanceof EE_Message_Template
1386
-                            ? $message_template->get('MTP_content')
1387
-                            : '';
1388
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1389
-                            //let's verify if we need this extra field via the shortcodes parameter.
1390
-                            $continue = false;
1391
-                            if (isset($extra_array['shortcodes_required'])) {
1392
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
-                                        $continue = true;
1395
-                                    }
1396
-                                }
1397
-                                if ($continue) {
1398
-                                    continue;
1399
-                                }
1400
-                            }
1268
+	/**
1269
+	 * _edit_message_template
1270
+	 *
1271
+	 * @access protected
1272
+	 * @return void
1273
+	 * @throws InvalidIdentifierException
1274
+	 * @throws DomainException
1275
+	 * @throws EE_Error
1276
+	 * @throws InvalidArgumentException
1277
+	 * @throws ReflectionException
1278
+	 * @throws InvalidDataTypeException
1279
+	 * @throws InvalidInterfaceException
1280
+	 */
1281
+	protected function _edit_message_template()
1282
+	{
1283
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
+		$template_fields = '';
1285
+		$sidebar_fields  = '';
1286
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
+		// valid html in the templates.
1288
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
+        
1290
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
+			? absint($this->_req_data['id'])
1292
+			: false;
1293
+        
1294
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1295
+		$message_template_group = $this->_message_template_group;
1296
+		$c_label                = $message_template_group->context_label();
1297
+		$c_config               = $message_template_group->contexts_config();
1298
+        
1299
+		reset($c_config);
1300
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
+			? strtolower($this->_req_data['context'])
1302
+			: key($c_config);
1303
+        
1304
+        
1305
+		if (empty($GRP_ID)) {
1306
+			$action = 'insert_message_template';
1307
+			$edit_message_template_form_url = add_query_arg(
1308
+				array('action' => $action, 'noheader' => true),
1309
+				EE_MSG_ADMIN_URL
1310
+			);
1311
+		} else {
1312
+			$action = 'update_message_template';
1313
+			$edit_message_template_form_url = add_query_arg(
1314
+				array('action' => $action, 'noheader' => true),
1315
+				EE_MSG_ADMIN_URL
1316
+			);
1317
+		}
1318
+        
1319
+		//set active messenger for this view
1320
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
+			$message_template_group->messenger()
1322
+		);
1323
+		$this->_active_message_type_name = $message_template_group->message_type();
1324
+        
1325
+        
1326
+		//Do we have any validation errors?
1327
+		$validators = $this->_get_transient();
1328
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
+        
1330
+        
1331
+		//we need to assemble the title from Various details
1332
+		$context_label = sprintf(
1333
+			esc_html__('(%s %s)', 'event_espresso'),
1334
+			$c_config[$context]['label'],
1335
+			ucwords($c_label['label'])
1336
+		);
1337
+        
1338
+		$title = sprintf(
1339
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1340
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1341
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1342
+			$context_label
1343
+		);
1344
+        
1345
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1346
+		$this->_template_args['message_template'] = $message_template_group;
1347
+		$this->_template_args['is_extra_fields']  = false;
1348
+        
1349
+        
1350
+		//let's get EEH_MSG_Template so we can get template form fields
1351
+		$template_field_structure = EEH_MSG_Template::get_fields(
1352
+			$message_template_group->messenger(),
1353
+			$message_template_group->message_type()
1354
+		);
1355
+        
1356
+		if ( ! $template_field_structure) {
1357
+			$template_field_structure = false;
1358
+			$template_fields          = esc_html__(
1359
+				'There was an error in assembling the fields for this display (you should see an error message)',
1360
+				'event_espresso'
1361
+			);
1362
+		}
1363
+        
1364
+        
1365
+		$message_templates = $message_template_group->context_templates();
1366
+        
1367
+        
1368
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
+		// will get handled in the "extra" array.
1370
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
+				unset($template_field_structure[$context][$reference_field]);
1373
+			}
1374
+		}
1375
+        
1376
+		//let's loop through the template_field_structure and actually assemble the input fields!
1377
+		if ( ! empty($template_field_structure)) {
1378
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
+				// the extra array and reset them.
1381
+				if ($template_field === 'extra') {
1382
+					$this->_template_args['is_extra_fields'] = true;
1383
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
+						$message_template = $message_templates[$context][$reference_field];
1385
+						$content          = $message_template instanceof EE_Message_Template
1386
+							? $message_template->get('MTP_content')
1387
+							: '';
1388
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1389
+							//let's verify if we need this extra field via the shortcodes parameter.
1390
+							$continue = false;
1391
+							if (isset($extra_array['shortcodes_required'])) {
1392
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
+										$continue = true;
1395
+									}
1396
+								}
1397
+								if ($continue) {
1398
+									continue;
1399
+								}
1400
+							}
1401 1401
                             
1402
-                            $field_id                                = $reference_field
1403
-                                                                       . '-'
1404
-                                                                       . $extra_field
1405
-                                                                       . '-content';
1406
-                            $template_form_fields[$field_id]         = $extra_array;
1407
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
-                                                                       . $reference_field
1409
-                                                                       . '][content]['
1410
-                                                                       . $extra_field . ']';
1411
-                            $css_class                               = isset($extra_array['css_class'])
1412
-                                ? $extra_array['css_class']
1413
-                                : '';
1402
+							$field_id                                = $reference_field
1403
+																	   . '-'
1404
+																	   . $extra_field
1405
+																	   . '-content';
1406
+							$template_form_fields[$field_id]         = $extra_array;
1407
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
+																	   . $reference_field
1409
+																	   . '][content]['
1410
+																	   . $extra_field . ']';
1411
+							$css_class                               = isset($extra_array['css_class'])
1412
+								? $extra_array['css_class']
1413
+								: '';
1414 1414
                             
1415
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
-                                && in_array($extra_field, $v_fields, true)
1417
-                                &&
1418
-                                (
1419
-                                    is_array($validators[$extra_field])
1420
-                                    && isset($validators[$extra_field]['msg'])
1421
-                                )
1422
-                                ? 'validate-error ' . $css_class
1423
-                                : $css_class;
1415
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
+								&& in_array($extra_field, $v_fields, true)
1417
+								&&
1418
+								(
1419
+									is_array($validators[$extra_field])
1420
+									&& isset($validators[$extra_field]['msg'])
1421
+								)
1422
+								? 'validate-error ' . $css_class
1423
+								: $css_class;
1424 1424
                             
1425
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
-                                                                        && isset($content[$extra_field])
1427
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1428
-                                : '';
1425
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
+																		&& isset($content[$extra_field])
1427
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1428
+								: '';
1429 1429
                             
1430
-                            //do we have a validation error?  if we do then let's use that value instead
1431
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
-                                ? $validators[$extra_field]['value']
1433
-                                : $template_form_fields[$field_id]['value'];
1430
+							//do we have a validation error?  if we do then let's use that value instead
1431
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
+								? $validators[$extra_field]['value']
1433
+								: $template_form_fields[$field_id]['value'];
1434 1434
                             
1435 1435
                             
1436
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1436
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1437 1437
                             
1438
-                            //shortcode selector
1439
-                            $field_name_to_use                                 = $extra_field === 'main'
1440
-                                ? 'content'
1441
-                                : $extra_field;
1442
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
-                                $field_name_to_use,
1444
-                                $field_id
1445
-                            );
1438
+							//shortcode selector
1439
+							$field_name_to_use                                 = $extra_field === 'main'
1440
+								? 'content'
1441
+								: $extra_field;
1442
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
+								$field_name_to_use,
1444
+								$field_id
1445
+							);
1446 1446
                             
1447
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
-                                //we want to decode the entities
1449
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1450
-                                    html_entity_decode(
1451
-                                        $template_form_fields[$field_id]['value'],
1452
-                                        ENT_QUOTES,
1453
-                                        "UTF-8")
1454
-                                );
1447
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
+								//we want to decode the entities
1449
+								$template_form_fields[$field_id]['value'] = stripslashes(
1450
+									html_entity_decode(
1451
+										$template_form_fields[$field_id]['value'],
1452
+										ENT_QUOTES,
1453
+										"UTF-8")
1454
+								);
1455 1455
                                 
1456
-                            }/**/
1457
-                        }
1458
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1459
-                        $templatefield_templatename_id = $reference_field . '-name';
1456
+							}/**/
1457
+						}
1458
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1459
+						$templatefield_templatename_id = $reference_field . '-name';
1460 1460
                         
1461
-                        $template_form_fields[$templatefield_MTP_id] = array(
1462
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1463
-                            'label'      => null,
1464
-                            'input'      => 'hidden',
1465
-                            'type'       => 'int',
1466
-                            'required'   => false,
1467
-                            'validation' => false,
1468
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1469
-                            'css_class'  => '',
1470
-                            'format'     => '%d',
1471
-                            'db-col'     => 'MTP_ID'
1472
-                        );
1461
+						$template_form_fields[$templatefield_MTP_id] = array(
1462
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1463
+							'label'      => null,
1464
+							'input'      => 'hidden',
1465
+							'type'       => 'int',
1466
+							'required'   => false,
1467
+							'validation' => false,
1468
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1469
+							'css_class'  => '',
1470
+							'format'     => '%d',
1471
+							'db-col'     => 'MTP_ID'
1472
+						);
1473 1473
                         
1474
-                        $template_form_fields[$templatefield_templatename_id] = array(
1475
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1476
-                            'label'      => null,
1477
-                            'input'      => 'hidden',
1478
-                            'type'       => 'string',
1479
-                            'required'   => false,
1480
-                            'validation' => true,
1481
-                            'value'      => $reference_field,
1482
-                            'css_class'  => '',
1483
-                            'format'     => '%s',
1484
-                            'db-col'     => 'MTP_template_field'
1485
-                        );
1486
-                    }
1487
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1488
-                } else {
1489
-                    $field_id                                 = $template_field . '-content';
1490
-                    $template_form_fields[$field_id]          = $field_setup_array;
1491
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1492
-                    $message_template                         = isset($message_templates[$context][$template_field])
1493
-                        ? $message_templates[$context][$template_field]
1494
-                        : null;
1495
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
-                                                                && is_array($message_templates[$context])
1497
-                                                                && $message_template instanceof EE_Message_Template
1498
-                        ? $message_template->get('MTP_content')
1499
-                        : '';
1474
+						$template_form_fields[$templatefield_templatename_id] = array(
1475
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1476
+							'label'      => null,
1477
+							'input'      => 'hidden',
1478
+							'type'       => 'string',
1479
+							'required'   => false,
1480
+							'validation' => true,
1481
+							'value'      => $reference_field,
1482
+							'css_class'  => '',
1483
+							'format'     => '%s',
1484
+							'db-col'     => 'MTP_template_field'
1485
+						);
1486
+					}
1487
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1488
+				} else {
1489
+					$field_id                                 = $template_field . '-content';
1490
+					$template_form_fields[$field_id]          = $field_setup_array;
1491
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1492
+					$message_template                         = isset($message_templates[$context][$template_field])
1493
+						? $message_templates[$context][$template_field]
1494
+						: null;
1495
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
+																&& is_array($message_templates[$context])
1497
+																&& $message_template instanceof EE_Message_Template
1498
+						? $message_template->get('MTP_content')
1499
+						: '';
1500 1500
                     
1501
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1502
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1503
-                        ? $validators[$template_field]['value']
1504
-                        : $template_form_fields[$field_id]['value'];
1501
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1502
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1503
+						? $validators[$template_field]['value']
1504
+						: $template_form_fields[$field_id]['value'];
1505 1505
                     
1506 1506
                     
1507
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1508
-                    $css_class                                    = isset($field_setup_array['css_class'])
1509
-                        ? $field_setup_array['css_class']
1510
-                        : '';
1511
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1512
-                                                                    && in_array($template_field, $v_fields, true)
1513
-                                                                    && isset($validators[$template_field]['msg'])
1514
-                        ? 'validate-error ' . $css_class
1515
-                        : $css_class;
1507
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1508
+					$css_class                                    = isset($field_setup_array['css_class'])
1509
+						? $field_setup_array['css_class']
1510
+						: '';
1511
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1512
+																	&& in_array($template_field, $v_fields, true)
1513
+																	&& isset($validators[$template_field]['msg'])
1514
+						? 'validate-error ' . $css_class
1515
+						: $css_class;
1516 1516
                     
1517
-                    //shortcode selector
1518
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1519
-                        $template_field, $field_id
1520
-                    );
1521
-                }
1517
+					//shortcode selector
1518
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1519
+						$template_field, $field_id
1520
+					);
1521
+				}
1522 1522
                 
1523
-                //k took care of content field(s) now let's take care of others.
1523
+				//k took care of content field(s) now let's take care of others.
1524 1524
                 
1525
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1526
-                $templatefield_field_templatename_id = $template_field . '-name';
1525
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1526
+				$templatefield_field_templatename_id = $template_field . '-name';
1527 1527
                 
1528
-                //foreach template field there are actually two form fields created
1529
-                $template_form_fields[$templatefield_MTP_id] = array(
1530
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1531
-                    'label'      => null,
1532
-                    'input'      => 'hidden',
1533
-                    'type'       => 'int',
1534
-                    'required'   => false,
1535
-                    'validation' => true,
1536
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1537
-                    'css_class'  => '',
1538
-                    'format'     => '%d',
1539
-                    'db-col'     => 'MTP_ID'
1540
-                );
1528
+				//foreach template field there are actually two form fields created
1529
+				$template_form_fields[$templatefield_MTP_id] = array(
1530
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1531
+					'label'      => null,
1532
+					'input'      => 'hidden',
1533
+					'type'       => 'int',
1534
+					'required'   => false,
1535
+					'validation' => true,
1536
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1537
+					'css_class'  => '',
1538
+					'format'     => '%d',
1539
+					'db-col'     => 'MTP_ID'
1540
+				);
1541 1541
                 
1542
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1543
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1544
-                    'label'      => null,
1545
-                    'input'      => 'hidden',
1546
-                    'type'       => 'string',
1547
-                    'required'   => false,
1548
-                    'validation' => true,
1549
-                    'value'      => $template_field,
1550
-                    'css_class'  => '',
1551
-                    'format'     => '%s',
1552
-                    'db-col'     => 'MTP_template_field'
1553
-                );
1542
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1543
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1544
+					'label'      => null,
1545
+					'input'      => 'hidden',
1546
+					'type'       => 'string',
1547
+					'required'   => false,
1548
+					'validation' => true,
1549
+					'value'      => $template_field,
1550
+					'css_class'  => '',
1551
+					'format'     => '%s',
1552
+					'db-col'     => 'MTP_template_field'
1553
+				);
1554 1554
                 
1555
-            }
1555
+			}
1556 1556
             
1557
-            //add other fields
1558
-            $template_form_fields['ee-msg-current-context'] = array(
1559
-                'name'       => 'MTP_context',
1560
-                'label'      => null,
1561
-                'input'      => 'hidden',
1562
-                'type'       => 'string',
1563
-                'required'   => false,
1564
-                'validation' => true,
1565
-                'value'      => $context,
1566
-                'css_class'  => '',
1567
-                'format'     => '%s',
1568
-                'db-col'     => 'MTP_context'
1569
-            );
1557
+			//add other fields
1558
+			$template_form_fields['ee-msg-current-context'] = array(
1559
+				'name'       => 'MTP_context',
1560
+				'label'      => null,
1561
+				'input'      => 'hidden',
1562
+				'type'       => 'string',
1563
+				'required'   => false,
1564
+				'validation' => true,
1565
+				'value'      => $context,
1566
+				'css_class'  => '',
1567
+				'format'     => '%s',
1568
+				'db-col'     => 'MTP_context'
1569
+			);
1570 1570
             
1571
-            $template_form_fields['ee-msg-grp-id'] = array(
1572
-                'name'       => 'GRP_ID',
1573
-                'label'      => null,
1574
-                'input'      => 'hidden',
1575
-                'type'       => 'int',
1576
-                'required'   => false,
1577
-                'validation' => true,
1578
-                'value'      => $GRP_ID,
1579
-                'css_class'  => '',
1580
-                'format'     => '%d',
1581
-                'db-col'     => 'GRP_ID'
1582
-            );
1571
+			$template_form_fields['ee-msg-grp-id'] = array(
1572
+				'name'       => 'GRP_ID',
1573
+				'label'      => null,
1574
+				'input'      => 'hidden',
1575
+				'type'       => 'int',
1576
+				'required'   => false,
1577
+				'validation' => true,
1578
+				'value'      => $GRP_ID,
1579
+				'css_class'  => '',
1580
+				'format'     => '%d',
1581
+				'db-col'     => 'GRP_ID'
1582
+			);
1583 1583
             
1584
-            $template_form_fields['ee-msg-messenger'] = array(
1585
-                'name'       => 'MTP_messenger',
1586
-                'label'      => null,
1587
-                'input'      => 'hidden',
1588
-                'type'       => 'string',
1589
-                'required'   => false,
1590
-                'validation' => true,
1591
-                'value'      => $message_template_group->messenger(),
1592
-                'css_class'  => '',
1593
-                'format'     => '%s',
1594
-                'db-col'     => 'MTP_messenger'
1595
-            );
1584
+			$template_form_fields['ee-msg-messenger'] = array(
1585
+				'name'       => 'MTP_messenger',
1586
+				'label'      => null,
1587
+				'input'      => 'hidden',
1588
+				'type'       => 'string',
1589
+				'required'   => false,
1590
+				'validation' => true,
1591
+				'value'      => $message_template_group->messenger(),
1592
+				'css_class'  => '',
1593
+				'format'     => '%s',
1594
+				'db-col'     => 'MTP_messenger'
1595
+			);
1596 1596
             
1597
-            $template_form_fields['ee-msg-message-type'] = array(
1598
-                'name'       => 'MTP_message_type',
1599
-                'label'      => null,
1600
-                'input'      => 'hidden',
1601
-                'type'       => 'string',
1602
-                'required'   => false,
1603
-                'validation' => true,
1604
-                'value'      => $message_template_group->message_type(),
1605
-                'css_class'  => '',
1606
-                'format'     => '%s',
1607
-                'db-col'     => 'MTP_message_type'
1608
-            );
1597
+			$template_form_fields['ee-msg-message-type'] = array(
1598
+				'name'       => 'MTP_message_type',
1599
+				'label'      => null,
1600
+				'input'      => 'hidden',
1601
+				'type'       => 'string',
1602
+				'required'   => false,
1603
+				'validation' => true,
1604
+				'value'      => $message_template_group->message_type(),
1605
+				'css_class'  => '',
1606
+				'format'     => '%s',
1607
+				'db-col'     => 'MTP_message_type'
1608
+			);
1609 1609
             
1610
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1611
-                'name'       => 'MTP_is_global',
1612
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1613
-                'input'      => 'hidden',
1614
-                'type'       => 'int',
1615
-                'required'   => false,
1616
-                'validation' => true,
1617
-                'value'      => $message_template_group->get('MTP_is_global'),
1618
-                'css_class'  => '',
1619
-                'format'     => '%d',
1620
-                'db-col'     => 'MTP_is_global'
1621
-            );
1610
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1611
+				'name'       => 'MTP_is_global',
1612
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1613
+				'input'      => 'hidden',
1614
+				'type'       => 'int',
1615
+				'required'   => false,
1616
+				'validation' => true,
1617
+				'value'      => $message_template_group->get('MTP_is_global'),
1618
+				'css_class'  => '',
1619
+				'format'     => '%d',
1620
+				'db-col'     => 'MTP_is_global'
1621
+			);
1622 1622
             
1623
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1624
-                'name'       => 'MTP_is_override',
1625
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1626
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1627
-                'type'       => 'int',
1628
-                'required'   => false,
1629
-                'validation' => true,
1630
-                'value'      => $message_template_group->get('MTP_is_override'),
1631
-                'css_class'  => '',
1632
-                'format'     => '%d',
1633
-                'db-col'     => 'MTP_is_override'
1634
-            );
1623
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1624
+				'name'       => 'MTP_is_override',
1625
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1626
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1627
+				'type'       => 'int',
1628
+				'required'   => false,
1629
+				'validation' => true,
1630
+				'value'      => $message_template_group->get('MTP_is_override'),
1631
+				'css_class'  => '',
1632
+				'format'     => '%d',
1633
+				'db-col'     => 'MTP_is_override'
1634
+			);
1635 1635
             
1636
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1637
-                'name'       => 'MTP_is_active',
1638
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1639
-                'input'      => 'hidden',
1640
-                'type'       => 'int',
1641
-                'required'   => false,
1642
-                'validation' => true,
1643
-                'value'      => $message_template_group->is_active(),
1644
-                'css_class'  => '',
1645
-                'format'     => '%d',
1646
-                'db-col'     => 'MTP_is_active'
1647
-            );
1636
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1637
+				'name'       => 'MTP_is_active',
1638
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1639
+				'input'      => 'hidden',
1640
+				'type'       => 'int',
1641
+				'required'   => false,
1642
+				'validation' => true,
1643
+				'value'      => $message_template_group->is_active(),
1644
+				'css_class'  => '',
1645
+				'format'     => '%d',
1646
+				'db-col'     => 'MTP_is_active'
1647
+			);
1648 1648
             
1649
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1650
-                'name'       => 'MTP_deleted',
1651
-                'label'      => null,
1652
-                'input'      => 'hidden',
1653
-                'type'       => 'int',
1654
-                'required'   => false,
1655
-                'validation' => true,
1656
-                'value'      => $message_template_group->get('MTP_deleted'),
1657
-                'css_class'  => '',
1658
-                'format'     => '%d',
1659
-                'db-col'     => 'MTP_deleted'
1660
-            );
1661
-            $sidebar_form_fields['ee-msg-author']  = array(
1662
-                'name'       => 'MTP_user_id',
1663
-                'label'      => esc_html__('Author', 'event_espresso'),
1664
-                'input'      => 'hidden',
1665
-                'type'       => 'int',
1666
-                'required'   => false,
1667
-                'validation' => false,
1668
-                'value'      => $message_template_group->user(),
1669
-                'format'     => '%d',
1670
-                'db-col'     => 'MTP_user_id'
1671
-            );
1649
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1650
+				'name'       => 'MTP_deleted',
1651
+				'label'      => null,
1652
+				'input'      => 'hidden',
1653
+				'type'       => 'int',
1654
+				'required'   => false,
1655
+				'validation' => true,
1656
+				'value'      => $message_template_group->get('MTP_deleted'),
1657
+				'css_class'  => '',
1658
+				'format'     => '%d',
1659
+				'db-col'     => 'MTP_deleted'
1660
+			);
1661
+			$sidebar_form_fields['ee-msg-author']  = array(
1662
+				'name'       => 'MTP_user_id',
1663
+				'label'      => esc_html__('Author', 'event_espresso'),
1664
+				'input'      => 'hidden',
1665
+				'type'       => 'int',
1666
+				'required'   => false,
1667
+				'validation' => false,
1668
+				'value'      => $message_template_group->user(),
1669
+				'format'     => '%d',
1670
+				'db-col'     => 'MTP_user_id'
1671
+			);
1672 1672
             
1673
-            $sidebar_form_fields['ee-msg-route'] = array(
1674
-                'name'  => 'action',
1675
-                'input' => 'hidden',
1676
-                'type'  => 'string',
1677
-                'value' => $action
1678
-            );
1673
+			$sidebar_form_fields['ee-msg-route'] = array(
1674
+				'name'  => 'action',
1675
+				'input' => 'hidden',
1676
+				'type'  => 'string',
1677
+				'value' => $action
1678
+			);
1679 1679
             
1680
-            $sidebar_form_fields['ee-msg-id']        = array(
1681
-                'name'  => 'id',
1682
-                'input' => 'hidden',
1683
-                'type'  => 'int',
1684
-                'value' => $GRP_ID
1685
-            );
1686
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1687
-                'name'  => $action . '_nonce',
1688
-                'input' => 'hidden',
1689
-                'type'  => 'string',
1690
-                'value' => wp_create_nonce($action . '_nonce')
1691
-            );
1680
+			$sidebar_form_fields['ee-msg-id']        = array(
1681
+				'name'  => 'id',
1682
+				'input' => 'hidden',
1683
+				'type'  => 'int',
1684
+				'value' => $GRP_ID
1685
+			);
1686
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1687
+				'name'  => $action . '_nonce',
1688
+				'input' => 'hidden',
1689
+				'type'  => 'string',
1690
+				'value' => wp_create_nonce($action . '_nonce')
1691
+			);
1692 1692
             
1693
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1694
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1695
-                    'name'  => 'template_switch',
1696
-                    'input' => 'hidden',
1697
-                    'type'  => 'int',
1698
-                    'value' => 1
1699
-                );
1700
-            }
1693
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1694
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1695
+					'name'  => 'template_switch',
1696
+					'input' => 'hidden',
1697
+					'type'  => 'int',
1698
+					'value' => 1
1699
+				);
1700
+			}
1701 1701
             
1702 1702
             
1703
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1704
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1703
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1704
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1705 1705
             
1706 1706
             
1707
-        } //end if ( !empty($template_field_structure) )
1708
-        
1709
-        //set extra content for publish box
1710
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1711
-        $this->_set_publish_post_box_vars(
1712
-            'id',
1713
-            $GRP_ID,
1714
-            false,
1715
-            add_query_arg(
1716
-                array('action' => 'global_mtps'),
1717
-                $this->_admin_base_url
1718
-            )
1719
-        );
1720
-        
1721
-        //add preview button
1722
-        $preview_url    = parent::add_query_args_and_nonce(
1723
-            array(
1724
-                'message_type' => $message_template_group->message_type(),
1725
-                'messenger'    => $message_template_group->messenger(),
1726
-                'context'      => $context,
1727
-                'GRP_ID'       => $GRP_ID,
1728
-                'action'       => 'preview_message'
1729
-            ),
1730
-            $this->_admin_base_url
1731
-        );
1732
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1733
-                          . esc_html__('Preview', 'event_espresso')
1734
-                          . '</a>';
1735
-        
1736
-        
1737
-        //setup context switcher
1738
-        $context_switcher_args = array(
1739
-            'page'    => 'espresso_messages',
1740
-            'action'  => 'edit_message_template',
1741
-            'id'      => $GRP_ID,
1742
-            'context' => $context,
1743
-            'extra'   => $preview_button
1744
-        );
1745
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1746
-        
1747
-        
1748
-        //main box
1749
-        $this->_template_args['template_fields']                         = $template_fields;
1750
-        $this->_template_args['sidebar_box_id']                          = 'details';
1751
-        $this->_template_args['action']                                  = $action;
1752
-        $this->_template_args['context']                                 = $context;
1753
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1754
-        $this->_template_args['learn_more_about_message_templates_link'] =
1755
-            $this->_learn_more_about_message_templates_link();
1756
-        
1757
-        
1758
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1759
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1760
-            $message_template_group,
1761
-            $context,
1762
-            $context_label
1763
-        );
1764
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1765
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1766
-        
1767
-        $this->_template_path = $this->_template_args['GRP_ID']
1768
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1769
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1770
-        
1771
-        //send along EE_Message_Template_Group object for further template use.
1772
-        $this->_template_args['MTP'] = $message_template_group;
1773
-        
1774
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1775
-            $this->_template_path,
1776
-            $this->_template_args,
1777
-            true
1778
-        );
1779
-        
1780
-        
1781
-        //finally, let's set the admin_page title
1782
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1783
-        
1784
-        
1785
-        //we need to take care of setting the shortcodes property for use elsewhere.
1786
-        $this->_set_shortcodes();
1787
-        
1788
-        
1789
-        //final template wrapper
1790
-        $this->display_admin_page_with_sidebar();
1791
-    }
1707
+		} //end if ( !empty($template_field_structure) )
1708
+        
1709
+		//set extra content for publish box
1710
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1711
+		$this->_set_publish_post_box_vars(
1712
+			'id',
1713
+			$GRP_ID,
1714
+			false,
1715
+			add_query_arg(
1716
+				array('action' => 'global_mtps'),
1717
+				$this->_admin_base_url
1718
+			)
1719
+		);
1720
+        
1721
+		//add preview button
1722
+		$preview_url    = parent::add_query_args_and_nonce(
1723
+			array(
1724
+				'message_type' => $message_template_group->message_type(),
1725
+				'messenger'    => $message_template_group->messenger(),
1726
+				'context'      => $context,
1727
+				'GRP_ID'       => $GRP_ID,
1728
+				'action'       => 'preview_message'
1729
+			),
1730
+			$this->_admin_base_url
1731
+		);
1732
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1733
+						  . esc_html__('Preview', 'event_espresso')
1734
+						  . '</a>';
1735
+        
1736
+        
1737
+		//setup context switcher
1738
+		$context_switcher_args = array(
1739
+			'page'    => 'espresso_messages',
1740
+			'action'  => 'edit_message_template',
1741
+			'id'      => $GRP_ID,
1742
+			'context' => $context,
1743
+			'extra'   => $preview_button
1744
+		);
1745
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1746
+        
1747
+        
1748
+		//main box
1749
+		$this->_template_args['template_fields']                         = $template_fields;
1750
+		$this->_template_args['sidebar_box_id']                          = 'details';
1751
+		$this->_template_args['action']                                  = $action;
1752
+		$this->_template_args['context']                                 = $context;
1753
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1754
+		$this->_template_args['learn_more_about_message_templates_link'] =
1755
+			$this->_learn_more_about_message_templates_link();
1756
+        
1757
+        
1758
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1759
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1760
+			$message_template_group,
1761
+			$context,
1762
+			$context_label
1763
+		);
1764
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1765
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1766
+        
1767
+		$this->_template_path = $this->_template_args['GRP_ID']
1768
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1769
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1770
+        
1771
+		//send along EE_Message_Template_Group object for further template use.
1772
+		$this->_template_args['MTP'] = $message_template_group;
1773
+        
1774
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1775
+			$this->_template_path,
1776
+			$this->_template_args,
1777
+			true
1778
+		);
1779
+        
1780
+        
1781
+		//finally, let's set the admin_page title
1782
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1783
+        
1784
+        
1785
+		//we need to take care of setting the shortcodes property for use elsewhere.
1786
+		$this->_set_shortcodes();
1787
+        
1788
+        
1789
+		//final template wrapper
1790
+		$this->display_admin_page_with_sidebar();
1791
+	}
1792 1792
     
1793 1793
     
1794
-    public function filter_tinymce_init($mceInit, $editor_id)
1795
-    {
1796
-        return $mceInit;
1797
-    }
1794
+	public function filter_tinymce_init($mceInit, $editor_id)
1795
+	{
1796
+		return $mceInit;
1797
+	}
1798 1798
     
1799 1799
     
1800
-    public function add_context_switcher()
1801
-    {
1802
-        return $this->_context_switcher;
1803
-    }
1800
+	public function add_context_switcher()
1801
+	{
1802
+		return $this->_context_switcher;
1803
+	}
1804 1804
 
1805 1805
 
1806
-    /**
1807
-     * Adds the activation/deactivation toggle for the message template context.
1808
-     *
1809
-     * @param EE_Message_Template_Group $message_template_group
1810
-     * @param string                    $context
1811
-     * @param string                    $context_label
1812
-     * @return string
1813
-     * @throws DomainException
1814
-     * @throws EE_Error
1815
-     * @throws InvalidIdentifierException
1816
-     */
1817
-    protected function add_active_context_element(
1818
-        EE_Message_Template_Group $message_template_group,
1819
-        $context,
1820
-        $context_label
1821
-    ) {
1822
-        $template_args = array(
1823
-            'context' => $context,
1824
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1825
-            'is_active' => $message_template_group->is_context_active($context),
1826
-            'on_off_action' => $message_template_group->is_context_active($context)
1827
-                ? 'context-off'
1828
-                : 'context-on',
1829
-            'context_label' => str_replace(array('(', ')'), '', $context_label),
1830
-            'message_template_group_id' => $message_template_group->ID()
1831
-        );
1832
-        return EEH_Template::display_template(
1833
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1834
-          $template_args,
1835
-          true
1836
-        );
1837
-    }
1806
+	/**
1807
+	 * Adds the activation/deactivation toggle for the message template context.
1808
+	 *
1809
+	 * @param EE_Message_Template_Group $message_template_group
1810
+	 * @param string                    $context
1811
+	 * @param string                    $context_label
1812
+	 * @return string
1813
+	 * @throws DomainException
1814
+	 * @throws EE_Error
1815
+	 * @throws InvalidIdentifierException
1816
+	 */
1817
+	protected function add_active_context_element(
1818
+		EE_Message_Template_Group $message_template_group,
1819
+		$context,
1820
+		$context_label
1821
+	) {
1822
+		$template_args = array(
1823
+			'context' => $context,
1824
+			'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1825
+			'is_active' => $message_template_group->is_context_active($context),
1826
+			'on_off_action' => $message_template_group->is_context_active($context)
1827
+				? 'context-off'
1828
+				: 'context-on',
1829
+			'context_label' => str_replace(array('(', ')'), '', $context_label),
1830
+			'message_template_group_id' => $message_template_group->ID()
1831
+		);
1832
+		return EEH_Template::display_template(
1833
+		  EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1834
+		  $template_args,
1835
+		  true
1836
+		);
1837
+	}
1838 1838
 
1839 1839
 
1840
-    /**
1841
-     * Ajax callback for `toggle_context_template` ajax action.
1842
-     * Handles toggling the message context on or off.
1843
-     * @throws EE_Error
1844
-     * @throws InvalidArgumentException
1845
-     * @throws InvalidDataTypeException
1846
-     * @throws InvalidIdentifierException
1847
-     * @throws InvalidInterfaceException
1848
-     */
1849
-    public function toggle_context_template()
1850
-    {
1851
-        $success = true;
1852
-        //check for required data
1853
-        if (!isset(
1854
-            $this->_req_data['message_template_group_id'],
1855
-            $this->_req_data['context'],
1856
-            $this->_req_data['status']
1857
-        )) {
1858
-            EE_Error::add_error(
1859
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1860
-                __FILE__,
1861
-                __FUNCTION__,
1862
-                __LINE__
1863
-            );
1864
-            $success = false;
1865
-        }
1840
+	/**
1841
+	 * Ajax callback for `toggle_context_template` ajax action.
1842
+	 * Handles toggling the message context on or off.
1843
+	 * @throws EE_Error
1844
+	 * @throws InvalidArgumentException
1845
+	 * @throws InvalidDataTypeException
1846
+	 * @throws InvalidIdentifierException
1847
+	 * @throws InvalidInterfaceException
1848
+	 */
1849
+	public function toggle_context_template()
1850
+	{
1851
+		$success = true;
1852
+		//check for required data
1853
+		if (!isset(
1854
+			$this->_req_data['message_template_group_id'],
1855
+			$this->_req_data['context'],
1856
+			$this->_req_data['status']
1857
+		)) {
1858
+			EE_Error::add_error(
1859
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1860
+				__FILE__,
1861
+				__FUNCTION__,
1862
+				__LINE__
1863
+			);
1864
+			$success = false;
1865
+		}
1866 1866
 
1867
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1868
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1869
-            : '';
1870
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1871
-        $this->_verify_nonce($nonce, $nonce_ref);
1872
-        $status = $this->_req_data['status'];
1873
-        if ($status !== 'off' && $status !=='on') {
1874
-            EE_Error::add_error(
1875
-                sprintf(
1876
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1877
-                    $this->_req_data['status']
1878
-                ),
1879
-                __FILE__,
1880
-                __FUNCTION__,
1881
-                __LINE__
1882
-            );
1883
-            $success = false;
1884
-        }
1885
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1886
-            $this->_req_data['message_template_group_id']
1887
-        );
1888
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1889
-            EE_Error::add_error(
1890
-                sprintf(
1891
-                    esc_html__(
1892
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1893
-                        'event_espresso'
1894
-                    ),
1895
-                    $this->_req_data['message_template_group_id'],
1896
-                    'EE_Message_Template_Group'
1897
-                ),
1898
-                __FILE__,
1899
-                __FUNCTION__,
1900
-                __LINE__
1901
-            );
1902
-            $success = false;
1903
-        }
1904
-        if ($success) {
1905
-            $success = $status === 'off'
1906
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1907
-                : $message_template_group->activate_context($this->_req_data['context']);
1908
-        }
1909
-        $this->_template_args['success'] = $success;
1910
-        $this->_return_json();
1911
-    }
1867
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1868
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1869
+			: '';
1870
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1871
+		$this->_verify_nonce($nonce, $nonce_ref);
1872
+		$status = $this->_req_data['status'];
1873
+		if ($status !== 'off' && $status !=='on') {
1874
+			EE_Error::add_error(
1875
+				sprintf(
1876
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1877
+					$this->_req_data['status']
1878
+				),
1879
+				__FILE__,
1880
+				__FUNCTION__,
1881
+				__LINE__
1882
+			);
1883
+			$success = false;
1884
+		}
1885
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1886
+			$this->_req_data['message_template_group_id']
1887
+		);
1888
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1889
+			EE_Error::add_error(
1890
+				sprintf(
1891
+					esc_html__(
1892
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1893
+						'event_espresso'
1894
+					),
1895
+					$this->_req_data['message_template_group_id'],
1896
+					'EE_Message_Template_Group'
1897
+				),
1898
+				__FILE__,
1899
+				__FUNCTION__,
1900
+				__LINE__
1901
+			);
1902
+			$success = false;
1903
+		}
1904
+		if ($success) {
1905
+			$success = $status === 'off'
1906
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1907
+				: $message_template_group->activate_context($this->_req_data['context']);
1908
+		}
1909
+		$this->_template_args['success'] = $success;
1910
+		$this->_return_json();
1911
+	}
1912 1912
 
1913 1913
 
1914 1914
     
1915
-    public function _add_form_element_before()
1916
-    {
1917
-        return '<form method="post" action="'
1918
-               . $this->_template_args["edit_message_template_form_url"]
1919
-               . '" id="ee-msg-edit-frm">';
1920
-    }
1915
+	public function _add_form_element_before()
1916
+	{
1917
+		return '<form method="post" action="'
1918
+			   . $this->_template_args["edit_message_template_form_url"]
1919
+			   . '" id="ee-msg-edit-frm">';
1920
+	}
1921 1921
     
1922
-    public function _add_form_element_after()
1923
-    {
1924
-        return '</form>';
1925
-    }
1922
+	public function _add_form_element_after()
1923
+	{
1924
+		return '</form>';
1925
+	}
1926 1926
 
1927 1927
 
1928
-    /**
1929
-     * This executes switching the template pack for a message template.
1930
-     *
1931
-     * @since 4.5.0
1932
-     * @throws EE_Error
1933
-     * @throws InvalidDataTypeException
1934
-     * @throws InvalidInterfaceException
1935
-     * @throws InvalidArgumentException
1936
-     * @throws ReflectionException
1937
-     */
1938
-    public function switch_template_pack()
1939
-    {
1940
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1941
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1942
-        
1943
-        //verify we have needed values.
1944
-        if (empty($GRP_ID) || empty($template_pack)) {
1945
-            $this->_template_args['error'] = true;
1946
-            EE_Error::add_error(
1947
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1948
-                __FILE__,
1949
-                __FUNCTION__,
1950
-                __LINE__
1951
-            );
1952
-        } else {
1953
-            //get template, set the new template_pack and then reset to default
1954
-            /** @type EE_Message_Template_Group $message_template_group */
1955
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1928
+	/**
1929
+	 * This executes switching the template pack for a message template.
1930
+	 *
1931
+	 * @since 4.5.0
1932
+	 * @throws EE_Error
1933
+	 * @throws InvalidDataTypeException
1934
+	 * @throws InvalidInterfaceException
1935
+	 * @throws InvalidArgumentException
1936
+	 * @throws ReflectionException
1937
+	 */
1938
+	public function switch_template_pack()
1939
+	{
1940
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1941
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1942
+        
1943
+		//verify we have needed values.
1944
+		if (empty($GRP_ID) || empty($template_pack)) {
1945
+			$this->_template_args['error'] = true;
1946
+			EE_Error::add_error(
1947
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1948
+				__FILE__,
1949
+				__FUNCTION__,
1950
+				__LINE__
1951
+			);
1952
+		} else {
1953
+			//get template, set the new template_pack and then reset to default
1954
+			/** @type EE_Message_Template_Group $message_template_group */
1955
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1956 1956
             
1957
-            $message_template_group->set_template_pack_name($template_pack);
1958
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1959
-            $this->_req_data['mt']   = $message_template_group->message_type();
1957
+			$message_template_group->set_template_pack_name($template_pack);
1958
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1959
+			$this->_req_data['mt']   = $message_template_group->message_type();
1960 1960
             
1961
-            $query_args = $this->_reset_to_default_template();
1961
+			$query_args = $this->_reset_to_default_template();
1962 1962
             
1963
-            if (empty($query_args['id'])) {
1964
-                EE_Error::add_error(
1965
-                    esc_html__(
1966
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1967
-                        'event_espresso'
1968
-                    ),
1969
-                    __FILE__,
1970
-                    __FUNCTION__,
1971
-                    __LINE__
1972
-                );
1973
-                $this->_template_args['error'] = true;
1974
-            } else {
1975
-                $template_label       = $message_template_group->get_template_pack()->label;
1976
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1977
-                EE_Error::add_success(
1978
-                    sprintf(
1979
-                        esc_html__(
1980
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1981
-                            'event_espresso'
1982
-                        ),
1983
-                        $template_label,
1984
-                        $template_pack_labels->template_pack
1985
-                    )
1986
-                );
1987
-                //generate the redirect url for js.
1988
-                $url                                          = self::add_query_args_and_nonce($query_args,
1989
-                    $this->_admin_base_url);
1990
-                $this->_template_args['data']['redirect_url'] = $url;
1991
-                $this->_template_args['success']              = true;
1992
-            }
1963
+			if (empty($query_args['id'])) {
1964
+				EE_Error::add_error(
1965
+					esc_html__(
1966
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1967
+						'event_espresso'
1968
+					),
1969
+					__FILE__,
1970
+					__FUNCTION__,
1971
+					__LINE__
1972
+				);
1973
+				$this->_template_args['error'] = true;
1974
+			} else {
1975
+				$template_label       = $message_template_group->get_template_pack()->label;
1976
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1977
+				EE_Error::add_success(
1978
+					sprintf(
1979
+						esc_html__(
1980
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1981
+							'event_espresso'
1982
+						),
1983
+						$template_label,
1984
+						$template_pack_labels->template_pack
1985
+					)
1986
+				);
1987
+				//generate the redirect url for js.
1988
+				$url                                          = self::add_query_args_and_nonce($query_args,
1989
+					$this->_admin_base_url);
1990
+				$this->_template_args['data']['redirect_url'] = $url;
1991
+				$this->_template_args['success']              = true;
1992
+			}
1993 1993
             
1994
-            $this->_return_json();
1994
+			$this->_return_json();
1995 1995
             
1996
-        }
1997
-    }
1996
+		}
1997
+	}
1998 1998
 
1999 1999
 
2000
-    /**
2001
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2002
-     * they want.
2003
-     *
2004
-     * @access protected
2005
-     * @return array|null
2006
-     * @throws EE_Error
2007
-     * @throws InvalidArgumentException
2008
-     * @throws InvalidDataTypeException
2009
-     * @throws InvalidInterfaceException
2010
-     */
2011
-    protected function _reset_to_default_template()
2012
-    {
2013
-        
2014
-        $templates = array();
2015
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2016
-        //we need to make sure we've got the info we need.
2017
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2018
-            EE_Error::add_error(
2019
-                esc_html__(
2020
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2021
-                    'event_espresso'
2022
-                ),
2023
-                __FILE__, __FUNCTION__, __LINE__
2024
-            );
2025
-        }
2026
-        
2027
-        // all templates will be reset to whatever the defaults are
2028
-        // for the global template matching the messenger and message type.
2029
-        $success = ! empty($GRP_ID) ? true : false;
2030
-        
2031
-        if ($success) {
2000
+	/**
2001
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2002
+	 * they want.
2003
+	 *
2004
+	 * @access protected
2005
+	 * @return array|null
2006
+	 * @throws EE_Error
2007
+	 * @throws InvalidArgumentException
2008
+	 * @throws InvalidDataTypeException
2009
+	 * @throws InvalidInterfaceException
2010
+	 */
2011
+	protected function _reset_to_default_template()
2012
+	{
2013
+        
2014
+		$templates = array();
2015
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2016
+		//we need to make sure we've got the info we need.
2017
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2018
+			EE_Error::add_error(
2019
+				esc_html__(
2020
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2021
+					'event_espresso'
2022
+				),
2023
+				__FILE__, __FUNCTION__, __LINE__
2024
+			);
2025
+		}
2026
+        
2027
+		// all templates will be reset to whatever the defaults are
2028
+		// for the global template matching the messenger and message type.
2029
+		$success = ! empty($GRP_ID) ? true : false;
2030
+        
2031
+		if ($success) {
2032 2032
             
2033
-            //let's first determine if the incoming template is a global template,
2034
-            // if it isn't then we need to get the global template matching messenger and message type.
2035
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2033
+			//let's first determine if the incoming template is a global template,
2034
+			// if it isn't then we need to get the global template matching messenger and message type.
2035
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2036 2036
             
2037 2037
             
2038
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2039
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2038
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2039
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2040 2040
             
2041
-            if ($success) {
2042
-                // if successfully deleted, lets generate the new ones.
2043
-                // Note. We set GLOBAL to true, because resets on ANY template
2044
-                // will use the related global template defaults for regeneration.
2045
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2046
-                // HOWEVER, we DO keep the template pack and template variation set
2047
-                // for the current custom template when resetting.
2048
-                $templates = $this->_generate_new_templates(
2049
-                    $this->_req_data['msgr'],
2050
-                    $this->_req_data['mt'],
2051
-                    $GRP_ID,
2052
-                    true
2053
-                );
2054
-            }
2041
+			if ($success) {
2042
+				// if successfully deleted, lets generate the new ones.
2043
+				// Note. We set GLOBAL to true, because resets on ANY template
2044
+				// will use the related global template defaults for regeneration.
2045
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2046
+				// HOWEVER, we DO keep the template pack and template variation set
2047
+				// for the current custom template when resetting.
2048
+				$templates = $this->_generate_new_templates(
2049
+					$this->_req_data['msgr'],
2050
+					$this->_req_data['mt'],
2051
+					$GRP_ID,
2052
+					true
2053
+				);
2054
+			}
2055 2055
             
2056
-        }
2057
-        
2058
-        //any error messages?
2059
-        if ( ! $success) {
2060
-            EE_Error::add_error(
2061
-                esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2062
-                    'event_espresso'),
2063
-                __FILE__, __FUNCTION__, __LINE__
2064
-            );
2065
-        }
2066
-        
2067
-        //all good, let's add a success message!
2068
-        if ($success && ! empty($templates)) {
2069
-            //the info for the template we generated is the first element in the returned array
2070
-            // $templates = $templates[0];
2071
-            EE_Error::overwrite_success();
2072
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2073
-        }
2074
-        
2075
-        
2076
-        $query_args = array(
2077
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2078
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2079
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2080
-        );
2081
-        
2082
-        //if called via ajax then we return query args otherwise redirect
2083
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2084
-            return $query_args;
2085
-        } else {
2086
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2056
+		}
2057
+        
2058
+		//any error messages?
2059
+		if ( ! $success) {
2060
+			EE_Error::add_error(
2061
+				esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2062
+					'event_espresso'),
2063
+				__FILE__, __FUNCTION__, __LINE__
2064
+			);
2065
+		}
2066
+        
2067
+		//all good, let's add a success message!
2068
+		if ($success && ! empty($templates)) {
2069
+			//the info for the template we generated is the first element in the returned array
2070
+			// $templates = $templates[0];
2071
+			EE_Error::overwrite_success();
2072
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2073
+		}
2074
+        
2075
+        
2076
+		$query_args = array(
2077
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2078
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2079
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2080
+		);
2081
+        
2082
+		//if called via ajax then we return query args otherwise redirect
2083
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2084
+			return $query_args;
2085
+		} else {
2086
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2087 2087
 
2088
-            return null;
2089
-        }
2090
-    }
2088
+			return null;
2089
+		}
2090
+	}
2091 2091
 
2092 2092
 
2093
-    /**
2094
-     * Retrieve and set the message preview for display.
2095
-     *
2096
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2097
-     * @return string
2098
-     * @throws ReflectionException
2099
-     * @throws EE_Error
2100
-     * @throws InvalidArgumentException
2101
-     * @throws InvalidDataTypeException
2102
-     * @throws InvalidInterfaceException
2103
-     */
2104
-    public function _preview_message($send = false)
2105
-    {
2106
-        //first make sure we've got the necessary parameters
2107
-        if (
2108
-        ! isset(
2109
-            $this->_req_data['message_type'],
2110
-            $this->_req_data['messenger'],
2111
-            $this->_req_data['messenger'],
2112
-            $this->_req_data['GRP_ID']
2113
-        )
2114
-        ) {
2115
-            EE_Error::add_error(
2116
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2117
-                __FILE__, __FUNCTION__, __LINE__
2118
-            );
2119
-        }
2120
-        
2121
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2122
-        
2123
-        
2124
-        //get the preview!
2125
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2126
-            $this->_req_data['messenger'], $send);
2127
-        
2128
-        if ($send) {
2129
-            return $preview;
2130
-        }
2131
-        
2132
-        //let's add a button to go back to the edit view
2133
-        $query_args             = array(
2134
-            'id'      => $this->_req_data['GRP_ID'],
2135
-            'context' => $this->_req_data['context'],
2136
-            'action'  => 'edit_message_template'
2137
-        );
2138
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2139
-        $preview_button         = '<a href="'
2140
-                                  . $go_back_url
2141
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2142
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2143
-                                  . '</a>';
2144
-        $message_types          = $this->get_installed_message_types();
2145
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger(
2146
-                $this->_req_data['messenger']
2147
-        );
2148
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2149
-            ? ucwords($active_messenger->label['singular'])
2150
-            : esc_html__('Unknown Messenger', 'event_espresso');
2151
-        //let's provide a helpful title for context
2152
-        $preview_title = sprintf(
2153
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2154
-            $active_messenger_label,
2155
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2156
-        );
2157
-        //setup display of preview.
2158
-        $this->_admin_page_title                    = $preview_title;
2159
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2160
-        $this->_template_args['data']['force_json'] = true;
2161
-        
2162
-        return '';
2163
-    }
2093
+	/**
2094
+	 * Retrieve and set the message preview for display.
2095
+	 *
2096
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2097
+	 * @return string
2098
+	 * @throws ReflectionException
2099
+	 * @throws EE_Error
2100
+	 * @throws InvalidArgumentException
2101
+	 * @throws InvalidDataTypeException
2102
+	 * @throws InvalidInterfaceException
2103
+	 */
2104
+	public function _preview_message($send = false)
2105
+	{
2106
+		//first make sure we've got the necessary parameters
2107
+		if (
2108
+		! isset(
2109
+			$this->_req_data['message_type'],
2110
+			$this->_req_data['messenger'],
2111
+			$this->_req_data['messenger'],
2112
+			$this->_req_data['GRP_ID']
2113
+		)
2114
+		) {
2115
+			EE_Error::add_error(
2116
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2117
+				__FILE__, __FUNCTION__, __LINE__
2118
+			);
2119
+		}
2120
+        
2121
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2122
+        
2123
+        
2124
+		//get the preview!
2125
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2126
+			$this->_req_data['messenger'], $send);
2127
+        
2128
+		if ($send) {
2129
+			return $preview;
2130
+		}
2131
+        
2132
+		//let's add a button to go back to the edit view
2133
+		$query_args             = array(
2134
+			'id'      => $this->_req_data['GRP_ID'],
2135
+			'context' => $this->_req_data['context'],
2136
+			'action'  => 'edit_message_template'
2137
+		);
2138
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2139
+		$preview_button         = '<a href="'
2140
+								  . $go_back_url
2141
+								  . '" class="button-secondary messages-preview-go-back-button">'
2142
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2143
+								  . '</a>';
2144
+		$message_types          = $this->get_installed_message_types();
2145
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger(
2146
+				$this->_req_data['messenger']
2147
+		);
2148
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2149
+			? ucwords($active_messenger->label['singular'])
2150
+			: esc_html__('Unknown Messenger', 'event_espresso');
2151
+		//let's provide a helpful title for context
2152
+		$preview_title = sprintf(
2153
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2154
+			$active_messenger_label,
2155
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2156
+		);
2157
+		//setup display of preview.
2158
+		$this->_admin_page_title                    = $preview_title;
2159
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2160
+		$this->_template_args['data']['force_json'] = true;
2161
+        
2162
+		return '';
2163
+	}
2164 2164
     
2165 2165
     
2166
-    /**
2167
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2168
-     * gets called automatically.
2169
-     *
2170
-     * @since 4.5.0
2171
-     *
2172
-     * @return string
2173
-     */
2174
-    protected function _display_preview_message()
2175
-    {
2176
-        $this->display_admin_page_with_no_sidebar();
2177
-    }
2166
+	/**
2167
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2168
+	 * gets called automatically.
2169
+	 *
2170
+	 * @since 4.5.0
2171
+	 *
2172
+	 * @return string
2173
+	 */
2174
+	protected function _display_preview_message()
2175
+	{
2176
+		$this->display_admin_page_with_no_sidebar();
2177
+	}
2178 2178
     
2179 2179
     
2180
-    /**
2181
-     * registers metaboxes that should show up on the "edit_message_template" page
2182
-     *
2183
-     * @access protected
2184
-     * @return void
2185
-     */
2186
-    protected function _register_edit_meta_boxes()
2187
-    {
2188
-        add_meta_box(
2189
-            'mtp_valid_shortcodes',
2190
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2191
-            array($this, 'shortcode_meta_box'),
2192
-            $this->_current_screen->id,
2193
-            'side',
2194
-            'default');
2195
-        add_meta_box(
2196
-            'mtp_extra_actions',
2197
-            esc_html__('Extra Actions', 'event_espresso'),
2198
-            array($this, 'extra_actions_meta_box'),
2199
-            $this->_current_screen->id,
2200
-            'side',
2201
-            'high'
2202
-        );
2203
-        add_meta_box(
2204
-            'mtp_templates',
2205
-            esc_html__('Template Styles', 'event_espresso'),
2206
-            array($this, 'template_pack_meta_box'),
2207
-            $this->_current_screen->id,
2208
-            'side',
2209
-            'high'
2210
-        );
2211
-    }
2180
+	/**
2181
+	 * registers metaboxes that should show up on the "edit_message_template" page
2182
+	 *
2183
+	 * @access protected
2184
+	 * @return void
2185
+	 */
2186
+	protected function _register_edit_meta_boxes()
2187
+	{
2188
+		add_meta_box(
2189
+			'mtp_valid_shortcodes',
2190
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2191
+			array($this, 'shortcode_meta_box'),
2192
+			$this->_current_screen->id,
2193
+			'side',
2194
+			'default');
2195
+		add_meta_box(
2196
+			'mtp_extra_actions',
2197
+			esc_html__('Extra Actions', 'event_espresso'),
2198
+			array($this, 'extra_actions_meta_box'),
2199
+			$this->_current_screen->id,
2200
+			'side',
2201
+			'high'
2202
+		);
2203
+		add_meta_box(
2204
+			'mtp_templates',
2205
+			esc_html__('Template Styles', 'event_espresso'),
2206
+			array($this, 'template_pack_meta_box'),
2207
+			$this->_current_screen->id,
2208
+			'side',
2209
+			'high'
2210
+		);
2211
+	}
2212 2212
 
2213 2213
 
2214
-    /**
2215
-     * metabox content for all template pack and variation selection.
2216
-     *
2217
-     * @since 4.5.0
2218
-     * @return string
2219
-     * @throws DomainException
2220
-     * @throws EE_Error
2221
-     * @throws InvalidArgumentException
2222
-     * @throws ReflectionException
2223
-     * @throws InvalidDataTypeException
2224
-     * @throws InvalidInterfaceException
2225
-     */
2226
-    public function template_pack_meta_box()
2227
-    {
2228
-        $this->_set_message_template_group();
2229
-        
2230
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2231
-        
2232
-        $tp_select_values = array();
2233
-        
2234
-        foreach ($tp_collection as $tp) {
2235
-            //only include template packs that support this messenger and message type!
2236
-            $supports = $tp->get_supports();
2237
-            if (
2238
-                ! isset($supports[$this->_message_template_group->messenger()])
2239
-                || ! in_array(
2240
-                    $this->_message_template_group->message_type(),
2241
-                    $supports[$this->_message_template_group->messenger()],
2242
-                    true
2243
-                )
2244
-            ) {
2245
-                //not supported
2246
-                continue;
2247
-            }
2214
+	/**
2215
+	 * metabox content for all template pack and variation selection.
2216
+	 *
2217
+	 * @since 4.5.0
2218
+	 * @return string
2219
+	 * @throws DomainException
2220
+	 * @throws EE_Error
2221
+	 * @throws InvalidArgumentException
2222
+	 * @throws ReflectionException
2223
+	 * @throws InvalidDataTypeException
2224
+	 * @throws InvalidInterfaceException
2225
+	 */
2226
+	public function template_pack_meta_box()
2227
+	{
2228
+		$this->_set_message_template_group();
2229
+        
2230
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2231
+        
2232
+		$tp_select_values = array();
2233
+        
2234
+		foreach ($tp_collection as $tp) {
2235
+			//only include template packs that support this messenger and message type!
2236
+			$supports = $tp->get_supports();
2237
+			if (
2238
+				! isset($supports[$this->_message_template_group->messenger()])
2239
+				|| ! in_array(
2240
+					$this->_message_template_group->message_type(),
2241
+					$supports[$this->_message_template_group->messenger()],
2242
+					true
2243
+				)
2244
+			) {
2245
+				//not supported
2246
+				continue;
2247
+			}
2248 2248
             
2249
-            $tp_select_values[] = array(
2250
-                'text' => $tp->label,
2251
-                'id'   => $tp->dbref
2252
-            );
2253
-        }
2254
-        
2255
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2256
-        // the default template pack.  This still allows for the odd template pack to override.
2257
-        if (empty($tp_select_values)) {
2258
-            $tp_select_values[] = array(
2259
-                'text' => esc_html__('Default', 'event_espresso'),
2260
-                'id'   => 'default'
2261
-            );
2262
-        }
2263
-        
2264
-        //setup variation select values for the currently selected template.
2265
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2266
-            $this->_message_template_group->messenger(),
2267
-            $this->_message_template_group->message_type()
2268
-        );
2269
-        $variations_select_values = array();
2270
-        foreach ($variations as $variation => $label) {
2271
-            $variations_select_values[] = array(
2272
-                'text' => $label,
2273
-                'id'   => $variation
2274
-            );
2275
-        }
2276
-        
2277
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2278
-        
2279
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2280
-            'MTP_template_pack',
2281
-            $tp_select_values,
2282
-            $this->_message_template_group->get_template_pack_name()
2283
-        );
2284
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2285
-            'MTP_template_variation',
2286
-            $variations_select_values,
2287
-            $this->_message_template_group->get_template_pack_variation()
2288
-        );
2289
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2290
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2291
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2292
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2293
-        
2294
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2295
-        
2296
-        EEH_Template::display_template($template, $template_args);
2297
-    }
2249
+			$tp_select_values[] = array(
2250
+				'text' => $tp->label,
2251
+				'id'   => $tp->dbref
2252
+			);
2253
+		}
2254
+        
2255
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2256
+		// the default template pack.  This still allows for the odd template pack to override.
2257
+		if (empty($tp_select_values)) {
2258
+			$tp_select_values[] = array(
2259
+				'text' => esc_html__('Default', 'event_espresso'),
2260
+				'id'   => 'default'
2261
+			);
2262
+		}
2263
+        
2264
+		//setup variation select values for the currently selected template.
2265
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2266
+			$this->_message_template_group->messenger(),
2267
+			$this->_message_template_group->message_type()
2268
+		);
2269
+		$variations_select_values = array();
2270
+		foreach ($variations as $variation => $label) {
2271
+			$variations_select_values[] = array(
2272
+				'text' => $label,
2273
+				'id'   => $variation
2274
+			);
2275
+		}
2276
+        
2277
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2278
+        
2279
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2280
+			'MTP_template_pack',
2281
+			$tp_select_values,
2282
+			$this->_message_template_group->get_template_pack_name()
2283
+		);
2284
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2285
+			'MTP_template_variation',
2286
+			$variations_select_values,
2287
+			$this->_message_template_group->get_template_pack_variation()
2288
+		);
2289
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2290
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2291
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2292
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2293
+        
2294
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2295
+        
2296
+		EEH_Template::display_template($template, $template_args);
2297
+	}
2298 2298
     
2299 2299
     
2300
-    /**
2301
-     * This meta box holds any extra actions related to Message Templates
2302
-     * For now, this includes Resetting templates to defaults and sending a test email.
2303
-     *
2304
-     * @access  public
2305
-     * @return void
2306
-     * @throws EE_Error
2307
-     */
2308
-    public function extra_actions_meta_box()
2309
-    {
2310
-        $template_form_fields = array();
2311
-        
2312
-        $extra_args = array(
2313
-            'msgr'   => $this->_message_template_group->messenger(),
2314
-            'mt'     => $this->_message_template_group->message_type(),
2315
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2316
-        );
2317
-        //first we need to see if there are any fields
2318
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2319
-        
2320
-        if ( ! empty($fields)) {
2321
-            //yup there be fields
2322
-            foreach ($fields as $field => $config) {
2323
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2324
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2325
-                $default  = isset($config['default']) ? $config['default'] : '';
2326
-                $default  = isset($config['value']) ? $config['value'] : $default;
2300
+	/**
2301
+	 * This meta box holds any extra actions related to Message Templates
2302
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2303
+	 *
2304
+	 * @access  public
2305
+	 * @return void
2306
+	 * @throws EE_Error
2307
+	 */
2308
+	public function extra_actions_meta_box()
2309
+	{
2310
+		$template_form_fields = array();
2311
+        
2312
+		$extra_args = array(
2313
+			'msgr'   => $this->_message_template_group->messenger(),
2314
+			'mt'     => $this->_message_template_group->message_type(),
2315
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2316
+		);
2317
+		//first we need to see if there are any fields
2318
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2319
+        
2320
+		if ( ! empty($fields)) {
2321
+			//yup there be fields
2322
+			foreach ($fields as $field => $config) {
2323
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2324
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2325
+				$default  = isset($config['default']) ? $config['default'] : '';
2326
+				$default  = isset($config['value']) ? $config['value'] : $default;
2327 2327
                 
2328
-                // if type is hidden and the value is empty
2329
-                // something may have gone wrong so let's correct with the defaults
2330
-                $fix              = $config['input'] === 'hidden'
2331
-                                    && isset($existing[$field])
2332
-                                    && empty($existing[$field])
2333
-                    ? $default
2334
-                    : '';
2335
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2336
-                    ? $existing[$field]
2337
-                    : $fix;
2328
+				// if type is hidden and the value is empty
2329
+				// something may have gone wrong so let's correct with the defaults
2330
+				$fix              = $config['input'] === 'hidden'
2331
+									&& isset($existing[$field])
2332
+									&& empty($existing[$field])
2333
+					? $default
2334
+					: '';
2335
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2336
+					? $existing[$field]
2337
+					: $fix;
2338 2338
                 
2339
-                $template_form_fields[$field_id] = array(
2340
-                    'name'       => 'test_settings_fld[' . $field . ']',
2341
-                    'label'      => $config['label'],
2342
-                    'input'      => $config['input'],
2343
-                    'type'       => $config['type'],
2344
-                    'required'   => $config['required'],
2345
-                    'validation' => $config['validation'],
2346
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2347
-                    'css_class'  => $config['css_class'],
2348
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2349
-                    'default'    => $default,
2350
-                    'format'     => $config['format']
2351
-                );
2352
-            }
2353
-        }
2354
-        
2355
-        $test_settings_fields = ! empty($template_form_fields)
2356
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2357
-            : '';
2358
-        
2359
-        $test_settings_html = '';
2360
-        //print out $test_settings_fields
2361
-        if ( ! empty($test_settings_fields)) {
2362
-            echo $test_settings_fields;
2363
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2364
-            $test_settings_html .= 'name="test_button" value="';
2365
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2366
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2367
-        }
2368
-        
2369
-        //and button
2370
-        $test_settings_html .= '<p>'
2371
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2372
-                               . '</p>';
2373
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2374
-        $test_settings_html .= $this->get_action_link_or_button(
2375
-            'reset_to_default',
2376
-            'reset',
2377
-            $extra_args,
2378
-            'button-primary reset-default-button'
2379
-        );
2380
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2381
-        echo $test_settings_html;
2382
-    }
2339
+				$template_form_fields[$field_id] = array(
2340
+					'name'       => 'test_settings_fld[' . $field . ']',
2341
+					'label'      => $config['label'],
2342
+					'input'      => $config['input'],
2343
+					'type'       => $config['type'],
2344
+					'required'   => $config['required'],
2345
+					'validation' => $config['validation'],
2346
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2347
+					'css_class'  => $config['css_class'],
2348
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2349
+					'default'    => $default,
2350
+					'format'     => $config['format']
2351
+				);
2352
+			}
2353
+		}
2354
+        
2355
+		$test_settings_fields = ! empty($template_form_fields)
2356
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2357
+			: '';
2358
+        
2359
+		$test_settings_html = '';
2360
+		//print out $test_settings_fields
2361
+		if ( ! empty($test_settings_fields)) {
2362
+			echo $test_settings_fields;
2363
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2364
+			$test_settings_html .= 'name="test_button" value="';
2365
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2366
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2367
+		}
2368
+        
2369
+		//and button
2370
+		$test_settings_html .= '<p>'
2371
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2372
+							   . '</p>';
2373
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2374
+		$test_settings_html .= $this->get_action_link_or_button(
2375
+			'reset_to_default',
2376
+			'reset',
2377
+			$extra_args,
2378
+			'button-primary reset-default-button'
2379
+		);
2380
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2381
+		echo $test_settings_html;
2382
+	}
2383 2383
 
2384 2384
 
2385
-    /**
2386
-     * This returns the shortcode selector skeleton for a given context and field.
2387
-     *
2388
-     * @since 4.9.rc.000
2389
-     * @param string $field           The name of the field retrieving shortcodes for.
2390
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2391
-     * @return string
2392
-     * @throws DomainException
2393
-     * @throws EE_Error
2394
-     * @throws InvalidArgumentException
2395
-     * @throws ReflectionException
2396
-     * @throws InvalidDataTypeException
2397
-     * @throws InvalidInterfaceException
2398
-     */
2399
-    protected function _get_shortcode_selector($field, $linked_input_id)
2400
-    {
2401
-        $template_args = array(
2402
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2403
-            'fieldname'       => $field,
2404
-            'linked_input_id' => $linked_input_id
2405
-        );
2406
-        
2407
-        return EEH_Template::display_template(
2408
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2409
-            $template_args,
2410
-            true
2411
-        );
2412
-    }
2385
+	/**
2386
+	 * This returns the shortcode selector skeleton for a given context and field.
2387
+	 *
2388
+	 * @since 4.9.rc.000
2389
+	 * @param string $field           The name of the field retrieving shortcodes for.
2390
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2391
+	 * @return string
2392
+	 * @throws DomainException
2393
+	 * @throws EE_Error
2394
+	 * @throws InvalidArgumentException
2395
+	 * @throws ReflectionException
2396
+	 * @throws InvalidDataTypeException
2397
+	 * @throws InvalidInterfaceException
2398
+	 */
2399
+	protected function _get_shortcode_selector($field, $linked_input_id)
2400
+	{
2401
+		$template_args = array(
2402
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2403
+			'fieldname'       => $field,
2404
+			'linked_input_id' => $linked_input_id
2405
+		);
2406
+        
2407
+		return EEH_Template::display_template(
2408
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2409
+			$template_args,
2410
+			true
2411
+		);
2412
+	}
2413 2413
 
2414 2414
 
2415
-    /**
2416
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2417
-     * page)
2418
-     *
2419
-     * @access public
2420
-     * @return void
2421
-     * @throws EE_Error
2422
-     * @throws InvalidArgumentException
2423
-     * @throws ReflectionException
2424
-     * @throws InvalidDataTypeException
2425
-     * @throws InvalidInterfaceException
2426
-     */
2427
-    public function shortcode_meta_box()
2428
-    {
2429
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2430
-        //$messenger = $this->_message_template_group->messenger_obj();
2431
-        //now let's set the content depending on the status of the shortcodes array
2432
-        if (empty($shortcodes)) {
2433
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2434
-            echo $content;
2435
-        } else {
2436
-            //$alt = 0;
2437
-            ?>
2415
+	/**
2416
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2417
+	 * page)
2418
+	 *
2419
+	 * @access public
2420
+	 * @return void
2421
+	 * @throws EE_Error
2422
+	 * @throws InvalidArgumentException
2423
+	 * @throws ReflectionException
2424
+	 * @throws InvalidDataTypeException
2425
+	 * @throws InvalidInterfaceException
2426
+	 */
2427
+	public function shortcode_meta_box()
2428
+	{
2429
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2430
+		//$messenger = $this->_message_template_group->messenger_obj();
2431
+		//now let's set the content depending on the status of the shortcodes array
2432
+		if (empty($shortcodes)) {
2433
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2434
+			echo $content;
2435
+		} else {
2436
+			//$alt = 0;
2437
+			?>
2438 2438
             <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2439 2439
             <p class="small-text"><?php printf(
2440
-                    esc_html__(
2441
-                        'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2442
-                        'event_espresso'
2443
-                    ),
2444
-                    '<span class="dashicons dashicons-menu"></span>'
2445
-                ); ?></p>
2440
+					esc_html__(
2441
+						'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2442
+						'event_espresso'
2443
+					),
2444
+					'<span class="dashicons dashicons-menu"></span>'
2445
+				); ?></p>
2446 2446
             <?php
2447
-        }
2447
+		}
2448 2448
         
2449 2449
         
2450
-    }
2450
+	}
2451 2451
 
2452 2452
 
2453
-    /**
2454
-     * used to set the $_shortcodes property for when its needed elsewhere.
2455
-     *
2456
-     * @access protected
2457
-     * @return void
2458
-     * @throws EE_Error
2459
-     * @throws InvalidArgumentException
2460
-     * @throws ReflectionException
2461
-     * @throws InvalidDataTypeException
2462
-     * @throws InvalidInterfaceException
2463
-     */
2464
-    protected function _set_shortcodes()
2465
-    {
2466
-        
2467
-        //no need to run this if the property is already set
2468
-        if ( ! empty($this->_shortcodes)) {
2469
-            return;
2470
-        }
2471
-        
2472
-        $this->_shortcodes = $this->_get_shortcodes();
2473
-    }
2453
+	/**
2454
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2455
+	 *
2456
+	 * @access protected
2457
+	 * @return void
2458
+	 * @throws EE_Error
2459
+	 * @throws InvalidArgumentException
2460
+	 * @throws ReflectionException
2461
+	 * @throws InvalidDataTypeException
2462
+	 * @throws InvalidInterfaceException
2463
+	 */
2464
+	protected function _set_shortcodes()
2465
+	{
2466
+        
2467
+		//no need to run this if the property is already set
2468
+		if ( ! empty($this->_shortcodes)) {
2469
+			return;
2470
+		}
2471
+        
2472
+		$this->_shortcodes = $this->_get_shortcodes();
2473
+	}
2474 2474
 
2475 2475
 
2476
-    /**
2477
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2478
-     * property)
2479
-     *
2480
-     * @access  protected
2481
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2482
-     *                         for. Defaults to all (for the given context)
2483
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2484
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2485
-     *                         true just an array of shortcode/label pairs.
2486
-     * @throws EE_Error
2487
-     * @throws InvalidArgumentException
2488
-     * @throws ReflectionException
2489
-     * @throws InvalidDataTypeException
2490
-     * @throws InvalidInterfaceException
2491
-     */
2492
-    protected function _get_shortcodes($fields = array(), $merged = true)
2493
-    {
2494
-        $this->_set_message_template_group();
2495
-        
2496
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2497
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2498
-            ? absint($this->_req_data['id'])
2499
-            : false;
2500
-        $context = isset($this->_req_data['context'])
2501
-            ? $this->_req_data['context']
2502
-            : key($this->_message_template_group->contexts_config());
2503
-        
2504
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2505
-    }
2476
+	/**
2477
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2478
+	 * property)
2479
+	 *
2480
+	 * @access  protected
2481
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2482
+	 *                         for. Defaults to all (for the given context)
2483
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2484
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2485
+	 *                         true just an array of shortcode/label pairs.
2486
+	 * @throws EE_Error
2487
+	 * @throws InvalidArgumentException
2488
+	 * @throws ReflectionException
2489
+	 * @throws InvalidDataTypeException
2490
+	 * @throws InvalidInterfaceException
2491
+	 */
2492
+	protected function _get_shortcodes($fields = array(), $merged = true)
2493
+	{
2494
+		$this->_set_message_template_group();
2495
+        
2496
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2497
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2498
+			? absint($this->_req_data['id'])
2499
+			: false;
2500
+		$context = isset($this->_req_data['context'])
2501
+			? $this->_req_data['context']
2502
+			: key($this->_message_template_group->contexts_config());
2503
+        
2504
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2505
+	}
2506 2506
 
2507 2507
 
2508
-    /**
2509
-     * This sets the _message_template property (containing the called message_template object)
2510
-     *
2511
-     * @access protected
2512
-     * @return void
2513
-     * @throws EE_Error
2514
-     * @throws InvalidArgumentException
2515
-     * @throws ReflectionException
2516
-     * @throws InvalidDataTypeException
2517
-     * @throws InvalidInterfaceException
2518
-     */
2519
-    protected function _set_message_template_group()
2520
-    {
2521
-        
2522
-        if ( ! empty($this->_message_template_group)) {
2523
-            return;
2524
-        } //get out if this is already set.
2525
-        
2526
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2527
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2528
-        
2529
-        //let's get the message templates
2530
-        $MTP = EEM_Message_Template_Group::instance();
2531
-        
2532
-        if (empty($GRP_ID)) {
2533
-            $this->_message_template_group = $MTP->create_default_object();
2534
-        } else {
2535
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2536
-        }
2537
-        
2538
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2539
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2540
-        
2541
-    }
2508
+	/**
2509
+	 * This sets the _message_template property (containing the called message_template object)
2510
+	 *
2511
+	 * @access protected
2512
+	 * @return void
2513
+	 * @throws EE_Error
2514
+	 * @throws InvalidArgumentException
2515
+	 * @throws ReflectionException
2516
+	 * @throws InvalidDataTypeException
2517
+	 * @throws InvalidInterfaceException
2518
+	 */
2519
+	protected function _set_message_template_group()
2520
+	{
2521
+        
2522
+		if ( ! empty($this->_message_template_group)) {
2523
+			return;
2524
+		} //get out if this is already set.
2525
+        
2526
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2527
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2528
+        
2529
+		//let's get the message templates
2530
+		$MTP = EEM_Message_Template_Group::instance();
2531
+        
2532
+		if (empty($GRP_ID)) {
2533
+			$this->_message_template_group = $MTP->create_default_object();
2534
+		} else {
2535
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2536
+		}
2537
+        
2538
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2539
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2540
+        
2541
+	}
2542 2542
 
2543 2543
 
2544
-    /**
2545
-     * sets up a context switcher for edit forms
2546
-     *
2547
-     * @access  protected
2548
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2549
-     * @param array                      $args                  various things the context switcher needs.
2550
-     * @throws EE_Error
2551
-     */
2552
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2553
-    {
2554
-        $context_details = $template_group_object->contexts_config();
2555
-        $context_label   = $template_group_object->context_label();
2556
-        ob_start();
2557
-        ?>
2544
+	/**
2545
+	 * sets up a context switcher for edit forms
2546
+	 *
2547
+	 * @access  protected
2548
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2549
+	 * @param array                      $args                  various things the context switcher needs.
2550
+	 * @throws EE_Error
2551
+	 */
2552
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2553
+	{
2554
+		$context_details = $template_group_object->contexts_config();
2555
+		$context_label   = $template_group_object->context_label();
2556
+		ob_start();
2557
+		?>
2558 2558
         <div class="ee-msg-switcher-container">
2559 2559
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2560 2560
                 <?php
2561
-                foreach ($args as $name => $value) {
2562
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2563
-                        continue;
2564
-                    }
2565
-                    ?>
2561
+				foreach ($args as $name => $value) {
2562
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2563
+						continue;
2564
+					}
2565
+					?>
2566 2566
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2567 2567
                     <?php
2568
-                }
2569
-                //setup nonce_url
2570
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2571
-                ?>
2568
+				}
2569
+				//setup nonce_url
2570
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2571
+				?>
2572 2572
                 <select name="context">
2573 2573
                     <?php
2574
-                    $context_templates = $template_group_object->context_templates();
2575
-                    if (is_array($context_templates)) :
2576
-                        foreach ($context_templates as $context => $template_fields) :
2577
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2578
-                            ?>
2574
+					$context_templates = $template_group_object->context_templates();
2575
+					if (is_array($context_templates)) :
2576
+						foreach ($context_templates as $context => $template_fields) :
2577
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2578
+							?>
2579 2579
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2580 2580
                                 <?php echo $context_details[$context]['label']; ?>
2581 2581
                             </option>
@@ -2588,1838 +2588,1838 @@  discard block
 block discarded – undo
2588 2588
             <?php echo $args['extra']; ?>
2589 2589
         </div> <!-- end .ee-msg-switcher-container -->
2590 2590
         <?php
2591
-        $output = ob_get_contents();
2592
-        ob_clean();
2593
-        $this->_context_switcher = $output;
2594
-    }
2591
+		$output = ob_get_contents();
2592
+		ob_clean();
2593
+		$this->_context_switcher = $output;
2594
+	}
2595 2595
     
2596 2596
     
2597
-    /**
2598
-     * utility for sanitizing new values coming in.
2599
-     * Note: this is only used when updating a context.
2600
-     *
2601
-     * @access protected
2602
-     *
2603
-     * @param int $index This helps us know which template field to select from the request array.
2604
-     *
2605
-     * @return array
2606
-     */
2607
-    protected function _set_message_template_column_values($index)
2608
-    {
2609
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2610
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2611
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2612
-            }
2613
-        }
2614
-        
2615
-        
2616
-        $set_column_values = array(
2617
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2618
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2619
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2620
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2621
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2622
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2623
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2624
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2625
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2626
-                ? absint($this->_req_data['MTP_is_global'])
2627
-                : 0,
2628
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2629
-                ? absint($this->_req_data['MTP_is_override'])
2630
-                : 0,
2631
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2632
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2633
-        );
2634
-        
2635
-        
2636
-        return $set_column_values;
2637
-    }
2597
+	/**
2598
+	 * utility for sanitizing new values coming in.
2599
+	 * Note: this is only used when updating a context.
2600
+	 *
2601
+	 * @access protected
2602
+	 *
2603
+	 * @param int $index This helps us know which template field to select from the request array.
2604
+	 *
2605
+	 * @return array
2606
+	 */
2607
+	protected function _set_message_template_column_values($index)
2608
+	{
2609
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2610
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2611
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2612
+			}
2613
+		}
2614
+        
2615
+        
2616
+		$set_column_values = array(
2617
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2618
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2619
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2620
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2621
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2622
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2623
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2624
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2625
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2626
+				? absint($this->_req_data['MTP_is_global'])
2627
+				: 0,
2628
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2629
+				? absint($this->_req_data['MTP_is_override'])
2630
+				: 0,
2631
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2632
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2633
+		);
2634
+        
2635
+        
2636
+		return $set_column_values;
2637
+	}
2638 2638
     
2639 2639
     
2640
-    protected function _insert_or_update_message_template($new = false)
2641
-    {
2642
-        
2643
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2644
-        $success  = 0;
2645
-        $override = false;
2646
-        
2647
-        //setup notices description
2648
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2649
-        
2650
-        //need the message type and messenger objects to be able to use the labels for the notices
2651
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2652
-        $messenger_label  = $messenger_object instanceof EE_messenger
2653
-            ? ucwords($messenger_object->label['singular'])
2654
-            : '';
2655
-        
2656
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2657
-            ? $this->_req_data['MTP_message_type']
2658
-            : '';
2659
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2660
-        
2661
-        $message_type_label = $message_type_object instanceof EE_message_type
2662
-            ? ucwords($message_type_object->label['singular'])
2663
-            : '';
2664
-        
2665
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2666
-            ? $this->_req_data['MTP_context']
2667
-            : '';
2668
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2669
-        
2670
-        $item_desc = $messenger_label && $message_type_label
2671
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2672
-            : '';
2673
-        $item_desc .= 'Message Template';
2674
-        $query_args  = array();
2675
-        $edit_array  = array();
2676
-        $action_desc = '';
2677
-        
2678
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2679
-        // user to edit.
2680
-        if ($new) {
2681
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2682
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2683
-                if (empty($edit_array)) {
2684
-                    $success = 0;
2685
-                } else {
2686
-                    $success    = 1;
2687
-                    $edit_array = $edit_array[0];
2688
-                    $query_args = array(
2689
-                        'id'      => $edit_array['GRP_ID'],
2690
-                        'context' => $edit_array['MTP_context'],
2691
-                        'action'  => 'edit_message_template'
2692
-                    );
2693
-                }
2694
-            }
2695
-            $action_desc = 'created';
2696
-        } else {
2697
-            $MTPG = EEM_Message_Template_Group::instance();
2698
-            $MTP  = EEM_Message_Template::instance();
2640
+	protected function _insert_or_update_message_template($new = false)
2641
+	{
2642
+        
2643
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2644
+		$success  = 0;
2645
+		$override = false;
2646
+        
2647
+		//setup notices description
2648
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2649
+        
2650
+		//need the message type and messenger objects to be able to use the labels for the notices
2651
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2652
+		$messenger_label  = $messenger_object instanceof EE_messenger
2653
+			? ucwords($messenger_object->label['singular'])
2654
+			: '';
2655
+        
2656
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2657
+			? $this->_req_data['MTP_message_type']
2658
+			: '';
2659
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2660
+        
2661
+		$message_type_label = $message_type_object instanceof EE_message_type
2662
+			? ucwords($message_type_object->label['singular'])
2663
+			: '';
2664
+        
2665
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2666
+			? $this->_req_data['MTP_context']
2667
+			: '';
2668
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2669
+        
2670
+		$item_desc = $messenger_label && $message_type_label
2671
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2672
+			: '';
2673
+		$item_desc .= 'Message Template';
2674
+		$query_args  = array();
2675
+		$edit_array  = array();
2676
+		$action_desc = '';
2677
+        
2678
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2679
+		// user to edit.
2680
+		if ($new) {
2681
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2682
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2683
+				if (empty($edit_array)) {
2684
+					$success = 0;
2685
+				} else {
2686
+					$success    = 1;
2687
+					$edit_array = $edit_array[0];
2688
+					$query_args = array(
2689
+						'id'      => $edit_array['GRP_ID'],
2690
+						'context' => $edit_array['MTP_context'],
2691
+						'action'  => 'edit_message_template'
2692
+					);
2693
+				}
2694
+			}
2695
+			$action_desc = 'created';
2696
+		} else {
2697
+			$MTPG = EEM_Message_Template_Group::instance();
2698
+			$MTP  = EEM_Message_Template::instance();
2699 2699
             
2700 2700
             
2701
-            //run update for each template field in displayed context
2702
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2703
-                EE_Error::add_error(
2704
-                    esc_html__(
2705
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2706
-                        'event_espresso'
2707
-                    ),
2708
-                    __FILE__,
2709
-                    __FUNCTION__,
2710
-                    __LINE__
2711
-                );
2712
-                $success = 0;
2701
+			//run update for each template field in displayed context
2702
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2703
+				EE_Error::add_error(
2704
+					esc_html__(
2705
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2706
+						'event_espresso'
2707
+					),
2708
+					__FILE__,
2709
+					__FUNCTION__,
2710
+					__LINE__
2711
+				);
2712
+				$success = 0;
2713 2713
                 
2714
-            } else {
2715
-                //first validate all fields!
2716
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2717
-                    $message_type_slug);
2714
+			} else {
2715
+				//first validate all fields!
2716
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2717
+					$message_type_slug);
2718 2718
                 
2719
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2720
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2721
-                //  WE need to make sure there is no actual error messages in validates.
2722
-                if (is_array($validates) && ! empty($validates)) {
2723
-                    //add the transient so when the form loads we know which fields to highlight
2724
-                    $this->_add_transient('edit_message_template', $validates);
2719
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2720
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2721
+				//  WE need to make sure there is no actual error messages in validates.
2722
+				if (is_array($validates) && ! empty($validates)) {
2723
+					//add the transient so when the form loads we know which fields to highlight
2724
+					$this->_add_transient('edit_message_template', $validates);
2725 2725
                     
2726
-                    $success = 0;
2726
+					$success = 0;
2727 2727
                     
2728
-                    //setup notices
2729
-                    foreach ($validates as $field => $error) {
2730
-                        if (isset($error['msg'])) {
2731
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2732
-                        }
2733
-                    }
2728
+					//setup notices
2729
+					foreach ($validates as $field => $error) {
2730
+						if (isset($error['msg'])) {
2731
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2732
+						}
2733
+					}
2734 2734
                     
2735
-                } else {
2736
-                    $set_column_values = array();
2737
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2738
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2735
+				} else {
2736
+					$set_column_values = array();
2737
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2738
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2739 2739
                         
2740
-                        $where_cols_n_values = array(
2741
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2742
-                        );
2740
+						$where_cols_n_values = array(
2741
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2742
+						);
2743 2743
                         
2744
-                        $message_template_fields = array(
2745
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2746
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2747
-                            'MTP_context'        => $set_column_values['MTP_context'],
2748
-                            'MTP_content'        => $set_column_values['MTP_content']
2749
-                        );
2750
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2751
-                            if ($updated === false) {
2752
-                                EE_Error::add_error(
2753
-                                    sprintf(
2754
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2755
-                                        $template_field
2756
-                                    ),
2757
-                                    __FILE__,
2758
-                                    __FUNCTION__,
2759
-                                    __LINE__
2760
-                                );
2761
-                            } else {
2762
-                                $success = 1;
2763
-                            }
2764
-                        } else {
2765
-                            //only do this logic if we don't have a MTP_ID for this field
2766
-                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2767
-                                //this has already been through the template field validator and sanitized, so it will be
2768
-                                //safe to insert this field.  Why insert?  This typically happens when we introduce a new
2769
-                                //message template field in a messenger/message type and existing users don't have the
2770
-                                //default setup for it.
2771
-                                //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2772
-                                $updated = $MTP->insert($message_template_fields);
2773
-                                if (! $updated || is_wp_error($updated)) {
2774
-                                    EE_Error::add_error(
2775
-                                        sprintf(
2776
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2777
-                                            $template_field
2778
-                                        ),
2779
-                                        __FILE__,
2780
-                                        __FUNCTION__,
2781
-                                        __LINE__
2782
-                                    );
2783
-                                    $success = 0;
2784
-                                } else {
2785
-                                    $success = 1;
2786
-                                }
2787
-                            }
2788
-                        }
2789
-                        $action_desc = 'updated';
2790
-                    }
2744
+						$message_template_fields = array(
2745
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2746
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2747
+							'MTP_context'        => $set_column_values['MTP_context'],
2748
+							'MTP_content'        => $set_column_values['MTP_content']
2749
+						);
2750
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2751
+							if ($updated === false) {
2752
+								EE_Error::add_error(
2753
+									sprintf(
2754
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2755
+										$template_field
2756
+									),
2757
+									__FILE__,
2758
+									__FUNCTION__,
2759
+									__LINE__
2760
+								);
2761
+							} else {
2762
+								$success = 1;
2763
+							}
2764
+						} else {
2765
+							//only do this logic if we don't have a MTP_ID for this field
2766
+							if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2767
+								//this has already been through the template field validator and sanitized, so it will be
2768
+								//safe to insert this field.  Why insert?  This typically happens when we introduce a new
2769
+								//message template field in a messenger/message type and existing users don't have the
2770
+								//default setup for it.
2771
+								//@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2772
+								$updated = $MTP->insert($message_template_fields);
2773
+								if (! $updated || is_wp_error($updated)) {
2774
+									EE_Error::add_error(
2775
+										sprintf(
2776
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2777
+											$template_field
2778
+										),
2779
+										__FILE__,
2780
+										__FUNCTION__,
2781
+										__LINE__
2782
+									);
2783
+									$success = 0;
2784
+								} else {
2785
+									$success = 1;
2786
+								}
2787
+							}
2788
+						}
2789
+						$action_desc = 'updated';
2790
+					}
2791 2791
                     
2792
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2793
-                    $mtpg_fields = array(
2794
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2795
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2796
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2797
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2798
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2799
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2800
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2801
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2802
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2803
-                            : '',
2804
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2805
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2806
-                            : ''
2807
-                    );
2792
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2793
+					$mtpg_fields = array(
2794
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2795
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2796
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2797
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2798
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2799
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2800
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2801
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2802
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2803
+							: '',
2804
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2805
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2806
+							: ''
2807
+					);
2808 2808
                     
2809
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2810
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2809
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2810
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2811 2811
                     
2812
-                    if ($updated === false) {
2813
-                        EE_Error::add_error(
2814
-                            sprintf(
2815
-                                esc_html__(
2816
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2817
-                                    'event_espresso'
2818
-                                ),
2819
-                                $set_column_values['GRP_ID']
2820
-                            ),
2821
-                            __FILE__,
2822
-                            __FUNCTION__,
2823
-                            __LINE__
2824
-                        );
2825
-                    } else {
2826
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2827
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2828
-                            ? $this->_req_data['MTP_template_pack']
2829
-                            : 'default';
2812
+					if ($updated === false) {
2813
+						EE_Error::add_error(
2814
+							sprintf(
2815
+								esc_html__(
2816
+									'The Message Template Group (%d) was NOT updated for some reason',
2817
+									'event_espresso'
2818
+								),
2819
+								$set_column_values['GRP_ID']
2820
+							),
2821
+							__FILE__,
2822
+							__FUNCTION__,
2823
+							__LINE__
2824
+						);
2825
+					} else {
2826
+						//k now we need to ensure the template_pack and template_variation fields are set.
2827
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2828
+							? $this->_req_data['MTP_template_pack']
2829
+							: 'default';
2830 2830
                         
2831
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2832
-                            ? $this->_req_data['MTP_template_variation']
2833
-                            : 'default';
2831
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2832
+							? $this->_req_data['MTP_template_variation']
2833
+							: 'default';
2834 2834
                         
2835
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2836
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2837
-                            $mtpg_obj->set_template_pack_name($template_pack);
2838
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2839
-                        }
2840
-                        $success = 1;
2841
-                    }
2842
-                }
2843
-            }
2835
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2836
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2837
+							$mtpg_obj->set_template_pack_name($template_pack);
2838
+							$mtpg_obj->set_template_pack_variation($template_variation);
2839
+						}
2840
+						$success = 1;
2841
+					}
2842
+				}
2843
+			}
2844 2844
             
2845
-        }
2846
-        
2847
-        //we return things differently if doing ajax
2848
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2849
-            $this->_template_args['success'] = $success;
2850
-            $this->_template_args['error']   = ! $success ? true : false;
2851
-            $this->_template_args['content'] = '';
2852
-            $this->_template_args['data']    = array(
2853
-                'grpID'        => $edit_array['GRP_ID'],
2854
-                'templateName' => $edit_array['template_name']
2855
-            );
2856
-            if ($success) {
2857
-                EE_Error::overwrite_success();
2858
-                EE_Error::add_success(
2859
-                    esc_html__(
2860
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2861
-                        'event_espresso'
2862
-                    )
2863
-                );
2864
-            }
2845
+		}
2846
+        
2847
+		//we return things differently if doing ajax
2848
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2849
+			$this->_template_args['success'] = $success;
2850
+			$this->_template_args['error']   = ! $success ? true : false;
2851
+			$this->_template_args['content'] = '';
2852
+			$this->_template_args['data']    = array(
2853
+				'grpID'        => $edit_array['GRP_ID'],
2854
+				'templateName' => $edit_array['template_name']
2855
+			);
2856
+			if ($success) {
2857
+				EE_Error::overwrite_success();
2858
+				EE_Error::add_success(
2859
+					esc_html__(
2860
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2861
+						'event_espresso'
2862
+					)
2863
+				);
2864
+			}
2865 2865
             
2866
-            $this->_return_json();
2867
-        }
2868
-        
2869
-        
2870
-        //was a test send triggered?
2871
-        if (isset($this->_req_data['test_button'])) {
2872
-            EE_Error::overwrite_success();
2873
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2874
-            $override = true;
2875
-        }
2876
-        
2877
-        if (empty($query_args)) {
2878
-            $query_args = array(
2879
-                'id'      => $this->_req_data['GRP_ID'],
2880
-                'context' => $context_slug,
2881
-                'action'  => 'edit_message_template'
2882
-            );
2883
-        }
2884
-        
2885
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2886
-    }
2866
+			$this->_return_json();
2867
+		}
2868
+        
2869
+        
2870
+		//was a test send triggered?
2871
+		if (isset($this->_req_data['test_button'])) {
2872
+			EE_Error::overwrite_success();
2873
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2874
+			$override = true;
2875
+		}
2876
+        
2877
+		if (empty($query_args)) {
2878
+			$query_args = array(
2879
+				'id'      => $this->_req_data['GRP_ID'],
2880
+				'context' => $context_slug,
2881
+				'action'  => 'edit_message_template'
2882
+			);
2883
+		}
2884
+        
2885
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2886
+	}
2887 2887
 
2888 2888
 
2889
-    /**
2890
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2891
-     *
2892
-     * @param  string $context      what context being tested
2893
-     * @param  string $messenger    messenger being tested
2894
-     * @param  string $message_type message type being tested
2895
-     * @throws EE_Error
2896
-     * @throws InvalidArgumentException
2897
-     * @throws InvalidDataTypeException
2898
-     * @throws InvalidInterfaceException
2899
-     */
2900
-    protected function _do_test_send($context, $messenger, $message_type)
2901
-    {
2902
-        //set things up for preview
2903
-        $this->_req_data['messenger']    = $messenger;
2904
-        $this->_req_data['message_type'] = $message_type;
2905
-        $this->_req_data['context']      = $context;
2906
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2907
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2908
-        
2909
-        //let's save any existing fields that might be required by the messenger
2910
-        if (
2911
-            isset($this->_req_data['test_settings_fld'])
2912
-            && $active_messenger instanceof EE_messenger
2913
-            && apply_filters(
2914
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2915
-                true,
2916
-                $this->_req_data['test_settings_fld'],
2917
-                $active_messenger
2918
-            )
2919
-        ) {
2920
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2921
-        }
2922
-        
2923
-        $success = $this->_preview_message(true);
2924
-        
2925
-        if ($success) {
2926
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2927
-        } else {
2928
-            EE_Error::add_error(
2929
-                esc_html__('The test message was not sent', 'event_espresso'),
2930
-                __FILE__,
2931
-                __FUNCTION__,
2932
-                __LINE__
2933
-            );
2934
-        }
2935
-    }
2889
+	/**
2890
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2891
+	 *
2892
+	 * @param  string $context      what context being tested
2893
+	 * @param  string $messenger    messenger being tested
2894
+	 * @param  string $message_type message type being tested
2895
+	 * @throws EE_Error
2896
+	 * @throws InvalidArgumentException
2897
+	 * @throws InvalidDataTypeException
2898
+	 * @throws InvalidInterfaceException
2899
+	 */
2900
+	protected function _do_test_send($context, $messenger, $message_type)
2901
+	{
2902
+		//set things up for preview
2903
+		$this->_req_data['messenger']    = $messenger;
2904
+		$this->_req_data['message_type'] = $message_type;
2905
+		$this->_req_data['context']      = $context;
2906
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2907
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2908
+        
2909
+		//let's save any existing fields that might be required by the messenger
2910
+		if (
2911
+			isset($this->_req_data['test_settings_fld'])
2912
+			&& $active_messenger instanceof EE_messenger
2913
+			&& apply_filters(
2914
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2915
+				true,
2916
+				$this->_req_data['test_settings_fld'],
2917
+				$active_messenger
2918
+			)
2919
+		) {
2920
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2921
+		}
2922
+        
2923
+		$success = $this->_preview_message(true);
2924
+        
2925
+		if ($success) {
2926
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2927
+		} else {
2928
+			EE_Error::add_error(
2929
+				esc_html__('The test message was not sent', 'event_espresso'),
2930
+				__FILE__,
2931
+				__FUNCTION__,
2932
+				__LINE__
2933
+			);
2934
+		}
2935
+	}
2936 2936
     
2937 2937
     
2938
-    /**
2939
-     * _generate_new_templates
2940
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2941
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2942
-     * for the event.
2943
-     *
2944
-     *
2945
-     * @param  string $messenger     the messenger we are generating templates for
2946
-     * @param array   $message_types array of message types that the templates are generated for.
2947
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2948
-     *                               indicate the message_template_group being used as the base.
2949
-     *
2950
-     * @param bool    $global
2951
-     *
2952
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2953
-     *                               encountering problems.
2954
-     * @throws EE_Error
2955
-     */
2956
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2957
-    {
2958
-        
2959
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2960
-        // just don't generate any templates.
2961
-        if (empty($message_types)) {
2962
-            return true;
2963
-        }
2964
-        
2965
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2966
-    }
2938
+	/**
2939
+	 * _generate_new_templates
2940
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2941
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2942
+	 * for the event.
2943
+	 *
2944
+	 *
2945
+	 * @param  string $messenger     the messenger we are generating templates for
2946
+	 * @param array   $message_types array of message types that the templates are generated for.
2947
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2948
+	 *                               indicate the message_template_group being used as the base.
2949
+	 *
2950
+	 * @param bool    $global
2951
+	 *
2952
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2953
+	 *                               encountering problems.
2954
+	 * @throws EE_Error
2955
+	 */
2956
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2957
+	{
2958
+        
2959
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2960
+		// just don't generate any templates.
2961
+		if (empty($message_types)) {
2962
+			return true;
2963
+		}
2964
+        
2965
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2966
+	}
2967 2967
 
2968 2968
 
2969
-    /**
2970
-     * [_trash_or_restore_message_template]
2971
-     *
2972
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2973
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2974
-     *                        an individual context (FALSE).
2975
-     * @return void
2976
-     * @throws EE_Error
2977
-     * @throws InvalidArgumentException
2978
-     * @throws InvalidDataTypeException
2979
-     * @throws InvalidInterfaceException
2980
-     */
2981
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2982
-    {
2983
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2984
-        $MTP = EEM_Message_Template_Group::instance();
2985
-        
2986
-        $success = 1;
2987
-        
2988
-        //incoming GRP_IDs
2989
-        if ($all) {
2990
-            //Checkboxes
2991
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2992
-                //if array has more than one element then success message should be plural.
2993
-                //todo: what about nonce?
2994
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2969
+	/**
2970
+	 * [_trash_or_restore_message_template]
2971
+	 *
2972
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2973
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2974
+	 *                        an individual context (FALSE).
2975
+	 * @return void
2976
+	 * @throws EE_Error
2977
+	 * @throws InvalidArgumentException
2978
+	 * @throws InvalidDataTypeException
2979
+	 * @throws InvalidInterfaceException
2980
+	 */
2981
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2982
+	{
2983
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2984
+		$MTP = EEM_Message_Template_Group::instance();
2985
+        
2986
+		$success = 1;
2987
+        
2988
+		//incoming GRP_IDs
2989
+		if ($all) {
2990
+			//Checkboxes
2991
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2992
+				//if array has more than one element then success message should be plural.
2993
+				//todo: what about nonce?
2994
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2995 2995
                 
2996
-                //cycle through checkboxes
2997
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2998
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2999
-                    if ( ! $trashed_or_restored) {
3000
-                        $success = 0;
3001
-                    }
3002
-                }
3003
-            } else {
3004
-                //grab single GRP_ID and handle
3005
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3006
-                if ( ! empty($GRP_ID)) {
3007
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3008
-                    if ( ! $trashed_or_restored) {
3009
-                        $success = 0;
3010
-                    }
3011
-                } else {
3012
-                    $success = 0;
3013
-                }
3014
-            }
2996
+				//cycle through checkboxes
2997
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2998
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2999
+					if ( ! $trashed_or_restored) {
3000
+						$success = 0;
3001
+					}
3002
+				}
3003
+			} else {
3004
+				//grab single GRP_ID and handle
3005
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3006
+				if ( ! empty($GRP_ID)) {
3007
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3008
+					if ( ! $trashed_or_restored) {
3009
+						$success = 0;
3010
+					}
3011
+				} else {
3012
+					$success = 0;
3013
+				}
3014
+			}
3015 3015
             
3016
-        }
3016
+		}
3017 3017
         
3018
-        $action_desc = $trash
3019
-            ? esc_html__('moved to the trash', 'event_espresso')
3020
-            : esc_html__('restored', 'event_espresso');
3018
+		$action_desc = $trash
3019
+			? esc_html__('moved to the trash', 'event_espresso')
3020
+			: esc_html__('restored', 'event_espresso');
3021 3021
         
3022
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3022
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3023 3023
         
3024
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3025
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3024
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3025
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3026 3026
         
3027
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3028
-            'event_espresso') : $item_desc;
3027
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3028
+			'event_espresso') : $item_desc;
3029 3029
         
3030
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3030
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3031 3031
         
3032
-    }
3032
+	}
3033 3033
 
3034 3034
 
3035
-    /**
3036
-     * [_delete_message_template]
3037
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3038
-     *
3039
-     * @return void
3040
-     * @throws EE_Error
3041
-     * @throws InvalidArgumentException
3042
-     * @throws InvalidDataTypeException
3043
-     * @throws InvalidInterfaceException
3044
-     */
3045
-    protected function _delete_message_template()
3046
-    {
3047
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3048
-        
3049
-        //checkboxes
3050
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3051
-            //if array has more than one element then success message should be plural
3052
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3035
+	/**
3036
+	 * [_delete_message_template]
3037
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3038
+	 *
3039
+	 * @return void
3040
+	 * @throws EE_Error
3041
+	 * @throws InvalidArgumentException
3042
+	 * @throws InvalidDataTypeException
3043
+	 * @throws InvalidInterfaceException
3044
+	 */
3045
+	protected function _delete_message_template()
3046
+	{
3047
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3048
+        
3049
+		//checkboxes
3050
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3051
+			//if array has more than one element then success message should be plural
3052
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3053 3053
             
3054
-            //cycle through bulk action checkboxes
3055
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3056
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3057
-            }
3058
-        } else {
3059
-            //grab single grp_id and delete
3060
-            $GRP_ID  = absint($this->_req_data['id']);
3061
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3062
-        }
3063
-        
3064
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3065
-        
3066
-    }
3054
+			//cycle through bulk action checkboxes
3055
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3056
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3057
+			}
3058
+		} else {
3059
+			//grab single grp_id and delete
3060
+			$GRP_ID  = absint($this->_req_data['id']);
3061
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3062
+		}
3063
+        
3064
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3065
+        
3066
+	}
3067 3067
 
3068 3068
 
3069
-    /**
3070
-     * helper for permanently deleting a mtP group and all related message_templates
3071
-     *
3072
-     * @param  int  $GRP_ID        The group being deleted
3073
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3074
-     * @return bool boolean to indicate the success of the deletes or not.
3075
-     * @throws EE_Error
3076
-     * @throws InvalidArgumentException
3077
-     * @throws InvalidDataTypeException
3078
-     * @throws InvalidInterfaceException
3079
-     */
3080
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3081
-    {
3082
-        $success = 1;
3083
-        $MTPG    = EEM_Message_Template_Group::instance();
3084
-        //first let's GET this group
3085
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3086
-        //then delete permanently all the related Message Templates
3087
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3088
-        
3089
-        if ($deleted === 0) {
3090
-            $success = 0;
3091
-        }
3092
-        
3093
-        //now delete permanently this particular group
3094
-        
3095
-        if ($include_group && ! $MTG->delete_permanently()) {
3096
-            $success = 0;
3097
-        }
3098
-        
3099
-        return $success;
3100
-    }
3069
+	/**
3070
+	 * helper for permanently deleting a mtP group and all related message_templates
3071
+	 *
3072
+	 * @param  int  $GRP_ID        The group being deleted
3073
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3074
+	 * @return bool boolean to indicate the success of the deletes or not.
3075
+	 * @throws EE_Error
3076
+	 * @throws InvalidArgumentException
3077
+	 * @throws InvalidDataTypeException
3078
+	 * @throws InvalidInterfaceException
3079
+	 */
3080
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3081
+	{
3082
+		$success = 1;
3083
+		$MTPG    = EEM_Message_Template_Group::instance();
3084
+		//first let's GET this group
3085
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3086
+		//then delete permanently all the related Message Templates
3087
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3088
+        
3089
+		if ($deleted === 0) {
3090
+			$success = 0;
3091
+		}
3092
+        
3093
+		//now delete permanently this particular group
3094
+        
3095
+		if ($include_group && ! $MTG->delete_permanently()) {
3096
+			$success = 0;
3097
+		}
3098
+        
3099
+		return $success;
3100
+	}
3101 3101
     
3102 3102
     
3103
-    /**
3104
-     *    _learn_more_about_message_templates_link
3105
-     * @access protected
3106
-     * @return string
3107
-     */
3108
-    protected function _learn_more_about_message_templates_link()
3109
-    {
3110
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3111
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3112
-               . '</a>';
3113
-    }
3103
+	/**
3104
+	 *    _learn_more_about_message_templates_link
3105
+	 * @access protected
3106
+	 * @return string
3107
+	 */
3108
+	protected function _learn_more_about_message_templates_link()
3109
+	{
3110
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3111
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3112
+			   . '</a>';
3113
+	}
3114 3114
 
3115 3115
 
3116
-    /**
3117
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3118
-     * ajax and other routes.
3119
-     *
3120
-     * @return void
3121
-     * @throws DomainException
3122
-     */
3123
-    protected function _settings()
3124
-    {
3125
-        
3126
-        
3127
-        $this->_set_m_mt_settings();
3128
-        
3129
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3130
-            ? $this->_req_data['selected_messenger']
3131
-            : 'email';
3132
-        
3133
-        //let's setup the messenger tabs
3134
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3135
-            $this->_m_mt_settings['messenger_tabs'],
3136
-            'messenger_links',
3137
-            '|',
3138
-            $selected_messenger
3139
-        );
3140
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3141
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3142
-        
3143
-        $this->display_admin_page_with_sidebar();
3144
-        
3145
-    }
3116
+	/**
3117
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3118
+	 * ajax and other routes.
3119
+	 *
3120
+	 * @return void
3121
+	 * @throws DomainException
3122
+	 */
3123
+	protected function _settings()
3124
+	{
3125
+        
3126
+        
3127
+		$this->_set_m_mt_settings();
3128
+        
3129
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3130
+			? $this->_req_data['selected_messenger']
3131
+			: 'email';
3132
+        
3133
+		//let's setup the messenger tabs
3134
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3135
+			$this->_m_mt_settings['messenger_tabs'],
3136
+			'messenger_links',
3137
+			'|',
3138
+			$selected_messenger
3139
+		);
3140
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3141
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3142
+        
3143
+		$this->display_admin_page_with_sidebar();
3144
+        
3145
+	}
3146 3146
 
3147 3147
 
3148
-    /**
3149
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3150
-     *
3151
-     * @access protected
3152
-     * @return void
3153
-     * @throws DomainException
3154
-     */
3155
-    protected function _set_m_mt_settings()
3156
-    {
3157
-        //first if this is already set then lets get out no need to regenerate data.
3158
-        if ( ! empty($this->_m_mt_settings)) {
3159
-            return;
3160
-        }
3161
-        
3162
-        //get all installed messengers and message_types
3163
-        /** @type EE_messenger[] $messengers */
3164
-        $messengers = $this->_message_resource_manager->installed_messengers();
3165
-        /** @type EE_message_type[] $message_types */
3166
-        $message_types = $this->_message_resource_manager->installed_message_types();
3167
-        
3168
-        
3169
-        //assemble the array for the _tab_text_links helper
3170
-        
3171
-        foreach ($messengers as $messenger) {
3172
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3173
-                'label' => ucwords($messenger->label['singular']),
3174
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3175
-                    ? 'messenger-active'
3176
-                    : '',
3177
-                'href'  => $messenger->name,
3178
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3179
-                'slug'  => $messenger->name,
3180
-                'obj'   => $messenger
3181
-            );
3148
+	/**
3149
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3150
+	 *
3151
+	 * @access protected
3152
+	 * @return void
3153
+	 * @throws DomainException
3154
+	 */
3155
+	protected function _set_m_mt_settings()
3156
+	{
3157
+		//first if this is already set then lets get out no need to regenerate data.
3158
+		if ( ! empty($this->_m_mt_settings)) {
3159
+			return;
3160
+		}
3161
+        
3162
+		//get all installed messengers and message_types
3163
+		/** @type EE_messenger[] $messengers */
3164
+		$messengers = $this->_message_resource_manager->installed_messengers();
3165
+		/** @type EE_message_type[] $message_types */
3166
+		$message_types = $this->_message_resource_manager->installed_message_types();
3167
+        
3168
+        
3169
+		//assemble the array for the _tab_text_links helper
3170
+        
3171
+		foreach ($messengers as $messenger) {
3172
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3173
+				'label' => ucwords($messenger->label['singular']),
3174
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3175
+					? 'messenger-active'
3176
+					: '',
3177
+				'href'  => $messenger->name,
3178
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3179
+				'slug'  => $messenger->name,
3180
+				'obj'   => $messenger
3181
+			);
3182 3182
             
3183 3183
             
3184
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3184
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3185 3185
             
3186
-            foreach ($message_types as $message_type) {
3187
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3188
-                // it shouldn't show in either the inactive OR active metabox.
3189
-                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3190
-                    continue;
3191
-                }
3186
+			foreach ($message_types as $message_type) {
3187
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3188
+				// it shouldn't show in either the inactive OR active metabox.
3189
+				if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3190
+					continue;
3191
+				}
3192 3192
                 
3193
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3194
-                    $messenger->name,
3195
-                    $message_type->name
3196
-                )
3197
-                    ? 'active'
3198
-                    : 'inactive';
3193
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3194
+					$messenger->name,
3195
+					$message_type->name
3196
+				)
3197
+					? 'active'
3198
+					: 'inactive';
3199 3199
                 
3200
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3201
-                    'label'    => ucwords($message_type->label['singular']),
3202
-                    'class'    => 'message-type-' . $a_or_i,
3203
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3204
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3205
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3206
-                    'title'    => $a_or_i === 'active'
3207
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3208
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3209
-                    'content'  => $a_or_i === 'active'
3210
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3211
-                        : $this->_message_type_settings_content($message_type, $messenger),
3212
-                    'slug'     => $message_type->name,
3213
-                    'active'   => $a_or_i === 'active',
3214
-                    'obj'      => $message_type
3215
-                );
3216
-            }
3217
-        }
3218
-    }
3200
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3201
+					'label'    => ucwords($message_type->label['singular']),
3202
+					'class'    => 'message-type-' . $a_or_i,
3203
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3204
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3205
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3206
+					'title'    => $a_or_i === 'active'
3207
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3208
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3209
+					'content'  => $a_or_i === 'active'
3210
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3211
+						: $this->_message_type_settings_content($message_type, $messenger),
3212
+					'slug'     => $message_type->name,
3213
+					'active'   => $a_or_i === 'active',
3214
+					'obj'      => $message_type
3215
+				);
3216
+			}
3217
+		}
3218
+	}
3219 3219
 
3220 3220
 
3221
-    /**
3222
-     * This just prepares the content for the message type settings
3223
-     *
3224
-     * @param  EE_message_type  $message_type The message type object
3225
-     * @param  EE_messenger  $messenger    The messenger object
3226
-     * @param  boolean $active       Whether the message type is active or not
3227
-     * @return string html output for the content
3228
-     * @throws DomainException
3229
-     */
3230
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3231
-    {
3232
-        //get message type fields
3233
-        $fields                                         = $message_type->get_admin_settings_fields();
3234
-        $settings_template_args['template_form_fields'] = '';
3235
-        
3236
-        if ( ! empty($fields) && $active) {
3221
+	/**
3222
+	 * This just prepares the content for the message type settings
3223
+	 *
3224
+	 * @param  EE_message_type  $message_type The message type object
3225
+	 * @param  EE_messenger  $messenger    The messenger object
3226
+	 * @param  boolean $active       Whether the message type is active or not
3227
+	 * @return string html output for the content
3228
+	 * @throws DomainException
3229
+	 */
3230
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3231
+	{
3232
+		//get message type fields
3233
+		$fields                                         = $message_type->get_admin_settings_fields();
3234
+		$settings_template_args['template_form_fields'] = '';
3235
+        
3236
+		if ( ! empty($fields) && $active) {
3237 3237
             
3238
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3238
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3239 3239
             
3240
-            foreach ($fields as $fldname => $fldprops) {
3241
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3242
-                $template_form_field[$field_id] = array(
3243
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3244
-                    'label'      => $fldprops['label'],
3245
-                    'input'      => $fldprops['field_type'],
3246
-                    'type'       => $fldprops['value_type'],
3247
-                    'required'   => $fldprops['required'],
3248
-                    'validation' => $fldprops['validation'],
3249
-                    'value'      => isset($existing_settings[$fldname])
3250
-                        ? $existing_settings[$fldname]
3251
-                        : $fldprops['default'],
3252
-                    'options'    => isset($fldprops['options'])
3253
-                        ? $fldprops['options']
3254
-                        : array(),
3255
-                    'default'    => isset($existing_settings[$fldname])
3256
-                        ? $existing_settings[$fldname]
3257
-                        : $fldprops['default'],
3258
-                    'css_class'  => 'no-drag',
3259
-                    'format'     => $fldprops['format']
3260
-                );
3261
-            }
3240
+			foreach ($fields as $fldname => $fldprops) {
3241
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3242
+				$template_form_field[$field_id] = array(
3243
+					'name'       => 'message_type_settings[' . $fldname . ']',
3244
+					'label'      => $fldprops['label'],
3245
+					'input'      => $fldprops['field_type'],
3246
+					'type'       => $fldprops['value_type'],
3247
+					'required'   => $fldprops['required'],
3248
+					'validation' => $fldprops['validation'],
3249
+					'value'      => isset($existing_settings[$fldname])
3250
+						? $existing_settings[$fldname]
3251
+						: $fldprops['default'],
3252
+					'options'    => isset($fldprops['options'])
3253
+						? $fldprops['options']
3254
+						: array(),
3255
+					'default'    => isset($existing_settings[$fldname])
3256
+						? $existing_settings[$fldname]
3257
+						: $fldprops['default'],
3258
+					'css_class'  => 'no-drag',
3259
+					'format'     => $fldprops['format']
3260
+				);
3261
+			}
3262 3262
             
3263 3263
             
3264
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3265
-                ? $this->_generate_admin_form_fields(
3266
-                    $template_form_field,
3267
-                    'string',
3268
-                    'ee_mt_activate_form'
3269
-                )
3270
-                : '';
3271
-        }
3272
-        
3273
-        $settings_template_args['description'] = $message_type->description;
3274
-        //we also need some hidden fields
3275
-        $settings_template_args['hidden_fields'] = array(
3276
-            'message_type_settings[messenger]'    => array(
3277
-                'type'  => 'hidden',
3278
-                'value' => $messenger->name
3279
-            ),
3280
-            'message_type_settings[message_type]' => array(
3281
-                'type'  => 'hidden',
3282
-                'value' => $message_type->name
3283
-            ),
3284
-            'type'                                => array(
3285
-                'type'  => 'hidden',
3286
-                'value' => 'message_type'
3287
-            )
3288
-        );
3289
-        
3290
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3291
-            $settings_template_args['hidden_fields'],
3292
-            'array'
3293
-        );
3294
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3295
-            ? ' hidden'
3296
-            : '';
3297
-        
3298
-        
3299
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3300
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
3301
-        
3302
-        return $content;
3303
-    }
3264
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3265
+				? $this->_generate_admin_form_fields(
3266
+					$template_form_field,
3267
+					'string',
3268
+					'ee_mt_activate_form'
3269
+				)
3270
+				: '';
3271
+		}
3272
+        
3273
+		$settings_template_args['description'] = $message_type->description;
3274
+		//we also need some hidden fields
3275
+		$settings_template_args['hidden_fields'] = array(
3276
+			'message_type_settings[messenger]'    => array(
3277
+				'type'  => 'hidden',
3278
+				'value' => $messenger->name
3279
+			),
3280
+			'message_type_settings[message_type]' => array(
3281
+				'type'  => 'hidden',
3282
+				'value' => $message_type->name
3283
+			),
3284
+			'type'                                => array(
3285
+				'type'  => 'hidden',
3286
+				'value' => 'message_type'
3287
+			)
3288
+		);
3289
+        
3290
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3291
+			$settings_template_args['hidden_fields'],
3292
+			'array'
3293
+		);
3294
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3295
+			? ' hidden'
3296
+			: '';
3297
+        
3298
+        
3299
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3300
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
3301
+        
3302
+		return $content;
3303
+	}
3304 3304
 
3305 3305
 
3306
-    /**
3307
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3308
-     *
3309
-     * @access protected
3310
-     * @return void
3311
-     * @throws DomainException
3312
-     */
3313
-    protected function _messages_settings_metaboxes()
3314
-    {
3315
-        $this->_set_m_mt_settings();
3316
-        $m_boxes         = $mt_boxes = array();
3317
-        $m_template_args = $mt_template_args = array();
3318
-        
3319
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3320
-            ? $this->_req_data['selected_messenger']
3321
-            : 'email';
3322
-        
3323
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3324
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3325
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3326
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3327
-                //messenger meta boxes
3328
-                $active                                 = $selected_messenger === $messenger;
3329
-                $active_mt_tabs                         = isset(
3330
-                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
-                )
3332
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3333
-                    : '';
3334
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3335
-                    esc_html__('%s Settings', 'event_espresso'),
3336
-                    $tab_array['label']
3337
-                );
3338
-                $m_template_args[$messenger . '_a_box'] = array(
3339
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3340
-                    'inactive_message_types' => isset(
3341
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3342
-                    )
3343
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3344
-                        : '',
3345
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3346
-                    'hidden'                 => $active ? '' : ' hidden',
3347
-                    'hide_on_message'        => $hide_on_message,
3348
-                    'messenger'              => $messenger,
3349
-                    'active'                 => $active
3350
-                );
3351
-                // message type meta boxes
3352
-                // (which is really just the inactive container for each messenger
3353
-                // showing inactive message types for that messenger)
3354
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3355
-                $mt_template_args[$messenger . '_i_box'] = array(
3356
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3357
-                    'inactive_message_types' => isset(
3358
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3359
-                    )
3360
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3361
-                        : '',
3362
-                    'hidden'                 => $active ? '' : ' hidden',
3363
-                    'hide_on_message'        => $hide_on_message,
3364
-                    'hide_off_message'       => $hide_off_message,
3365
-                    'messenger'              => $messenger,
3366
-                    'active'                 => $active
3367
-                );
3368
-            }
3369
-        }
3370
-        
3371
-        
3372
-        //register messenger metaboxes
3373
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3374
-        foreach ($m_boxes as $box => $label) {
3375
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3376
-            $msgr          = str_replace('_a_box', '', $box);
3377
-            add_meta_box(
3378
-                'espresso_' . $msgr . '_settings',
3379
-                $label,
3380
-                function ($post, $metabox) {
3381
-                    echo EEH_Template::display_template(
3382
-                            $metabox["args"]["template_path"],
3383
-                            $metabox["args"]["template_args"],
3384
-                            true
3385
-                    );
3386
-                },
3387
-                $this->_current_screen->id,
3388
-                'normal',
3389
-                'high',
3390
-                $callback_args
3391
-            );
3392
-        }
3393
-        
3394
-        //register message type metaboxes
3395
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3396
-        foreach ($mt_boxes as $box => $label) {
3397
-            $callback_args = array(
3398
-                'template_path' => $mt_template_path,
3399
-                'template_args' => $mt_template_args[$box]
3400
-            );
3401
-            $mt            = str_replace('_i_box', '', $box);
3402
-            add_meta_box(
3403
-                'espresso_' . $mt . '_inactive_mts',
3404
-                $label,
3405
-                function ($post, $metabox) {
3406
-                    echo EEH_Template::display_template(
3407
-                            $metabox["args"]["template_path"],
3408
-                            $metabox["args"]["template_args"],
3409
-                            true
3410
-                    );
3411
-                },
3412
-                $this->_current_screen->id,
3413
-                'side',
3414
-                'high',
3415
-                $callback_args
3416
-            );
3417
-        }
3418
-        
3419
-        //register metabox for global messages settings but only when on the main site.  On single site installs this
3420
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3421
-        if (is_main_site()) {
3422
-            add_meta_box(
3423
-                'espresso_global_message_settings',
3424
-                esc_html__('Global Message Settings', 'event_espresso'),
3425
-                array($this, 'global_messages_settings_metabox_content'),
3426
-                $this->_current_screen->id,
3427
-                'normal',
3428
-                'low',
3429
-                array()
3430
-            );
3431
-        }
3432
-        
3433
-    }
3306
+	/**
3307
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3308
+	 *
3309
+	 * @access protected
3310
+	 * @return void
3311
+	 * @throws DomainException
3312
+	 */
3313
+	protected function _messages_settings_metaboxes()
3314
+	{
3315
+		$this->_set_m_mt_settings();
3316
+		$m_boxes         = $mt_boxes = array();
3317
+		$m_template_args = $mt_template_args = array();
3318
+        
3319
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3320
+			? $this->_req_data['selected_messenger']
3321
+			: 'email';
3322
+        
3323
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3324
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3325
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3326
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3327
+				//messenger meta boxes
3328
+				$active                                 = $selected_messenger === $messenger;
3329
+				$active_mt_tabs                         = isset(
3330
+					$this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
+				)
3332
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3333
+					: '';
3334
+				$m_boxes[$messenger . '_a_box']         = sprintf(
3335
+					esc_html__('%s Settings', 'event_espresso'),
3336
+					$tab_array['label']
3337
+				);
3338
+				$m_template_args[$messenger . '_a_box'] = array(
3339
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3340
+					'inactive_message_types' => isset(
3341
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3342
+					)
3343
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3344
+						: '',
3345
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3346
+					'hidden'                 => $active ? '' : ' hidden',
3347
+					'hide_on_message'        => $hide_on_message,
3348
+					'messenger'              => $messenger,
3349
+					'active'                 => $active
3350
+				);
3351
+				// message type meta boxes
3352
+				// (which is really just the inactive container for each messenger
3353
+				// showing inactive message types for that messenger)
3354
+				$mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3355
+				$mt_template_args[$messenger . '_i_box'] = array(
3356
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3357
+					'inactive_message_types' => isset(
3358
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3359
+					)
3360
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3361
+						: '',
3362
+					'hidden'                 => $active ? '' : ' hidden',
3363
+					'hide_on_message'        => $hide_on_message,
3364
+					'hide_off_message'       => $hide_off_message,
3365
+					'messenger'              => $messenger,
3366
+					'active'                 => $active
3367
+				);
3368
+			}
3369
+		}
3370
+        
3371
+        
3372
+		//register messenger metaboxes
3373
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3374
+		foreach ($m_boxes as $box => $label) {
3375
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3376
+			$msgr          = str_replace('_a_box', '', $box);
3377
+			add_meta_box(
3378
+				'espresso_' . $msgr . '_settings',
3379
+				$label,
3380
+				function ($post, $metabox) {
3381
+					echo EEH_Template::display_template(
3382
+							$metabox["args"]["template_path"],
3383
+							$metabox["args"]["template_args"],
3384
+							true
3385
+					);
3386
+				},
3387
+				$this->_current_screen->id,
3388
+				'normal',
3389
+				'high',
3390
+				$callback_args
3391
+			);
3392
+		}
3393
+        
3394
+		//register message type metaboxes
3395
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3396
+		foreach ($mt_boxes as $box => $label) {
3397
+			$callback_args = array(
3398
+				'template_path' => $mt_template_path,
3399
+				'template_args' => $mt_template_args[$box]
3400
+			);
3401
+			$mt            = str_replace('_i_box', '', $box);
3402
+			add_meta_box(
3403
+				'espresso_' . $mt . '_inactive_mts',
3404
+				$label,
3405
+				function ($post, $metabox) {
3406
+					echo EEH_Template::display_template(
3407
+							$metabox["args"]["template_path"],
3408
+							$metabox["args"]["template_args"],
3409
+							true
3410
+					);
3411
+				},
3412
+				$this->_current_screen->id,
3413
+				'side',
3414
+				'high',
3415
+				$callback_args
3416
+			);
3417
+		}
3418
+        
3419
+		//register metabox for global messages settings but only when on the main site.  On single site installs this
3420
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3421
+		if (is_main_site()) {
3422
+			add_meta_box(
3423
+				'espresso_global_message_settings',
3424
+				esc_html__('Global Message Settings', 'event_espresso'),
3425
+				array($this, 'global_messages_settings_metabox_content'),
3426
+				$this->_current_screen->id,
3427
+				'normal',
3428
+				'low',
3429
+				array()
3430
+			);
3431
+		}
3432
+        
3433
+	}
3434 3434
 
3435 3435
 
3436
-    /**
3437
-     *  This generates the content for the global messages settings metabox.
3438
-     *
3439
-     * @return string
3440
-     * @throws EE_Error
3441
-     * @throws InvalidArgumentException
3442
-     * @throws ReflectionException
3443
-     * @throws InvalidDataTypeException
3444
-     * @throws InvalidInterfaceException
3445
-     */
3446
-    public function global_messages_settings_metabox_content()
3447
-    {
3448
-        $form = $this->_generate_global_settings_form();
3449
-        echo $form->form_open(
3450
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3451
-                'POST'
3452
-            )
3453
-             . $form->get_html()
3454
-             . $form->form_close();
3455
-    }
3436
+	/**
3437
+	 *  This generates the content for the global messages settings metabox.
3438
+	 *
3439
+	 * @return string
3440
+	 * @throws EE_Error
3441
+	 * @throws InvalidArgumentException
3442
+	 * @throws ReflectionException
3443
+	 * @throws InvalidDataTypeException
3444
+	 * @throws InvalidInterfaceException
3445
+	 */
3446
+	public function global_messages_settings_metabox_content()
3447
+	{
3448
+		$form = $this->_generate_global_settings_form();
3449
+		echo $form->form_open(
3450
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3451
+				'POST'
3452
+			)
3453
+			 . $form->get_html()
3454
+			 . $form->form_close();
3455
+	}
3456 3456
 
3457 3457
 
3458
-    /**
3459
-     * This generates and returns the form object for the global messages settings.
3460
-     *
3461
-     * @return EE_Form_Section_Proper
3462
-     * @throws EE_Error
3463
-     * @throws InvalidArgumentException
3464
-     * @throws ReflectionException
3465
-     * @throws InvalidDataTypeException
3466
-     * @throws InvalidInterfaceException
3467
-     */
3468
-    protected function _generate_global_settings_form()
3469
-    {
3470
-        EE_Registry::instance()->load_helper('HTML');
3471
-        /** @var EE_Network_Core_Config $network_config */
3472
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3473
-        
3474
-        return new EE_Form_Section_Proper(
3475
-            array(
3476
-                'name'            => 'global_messages_settings',
3477
-                'html_id'         => 'global_messages_settings',
3478
-                'html_class'      => 'form-table',
3479
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3480
-                'subsections'     => apply_filters(
3481
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3482
-                    array(
3483
-                        'do_messages_on_same_request' => new EE_Select_Input(
3484
-                            array(
3485
-                                true  => esc_html__("On the same request", "event_espresso"),
3486
-                                false => esc_html__("On a separate request", "event_espresso")
3487
-                            ),
3488
-                            array(
3489
-                                'default'         => $network_config->do_messages_on_same_request,
3490
-                                'html_label_text' => esc_html__(
3491
-                                    'Generate and send all messages:',
3492
-                                    'event_espresso'
3493
-                                ),
3494
-                                'html_help_text'  => esc_html__(
3495
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3496
-                                    'event_espresso'
3497
-                                ),
3498
-                            )
3499
-                        ),
3500
-                        'delete_threshold' => new EE_Select_Input(
3501
-                            array(
3502
-                                0 => esc_html__('Forever', 'event_espresso'),
3503
-                                3 => esc_html__('3 Months', 'event_espresso'),
3504
-                                6 => esc_html__('6 Months', 'event_espresso'),
3505
-                                9 => esc_html__('9 Months', 'event_espresso'),
3506
-                                12 => esc_html__('12 Months', 'event_espresso'),
3507
-                                24 => esc_html__('24 Months', 'event_espresso'),
3508
-                                36 => esc_html__('36 Months', 'event_espresso')
3509
-                            ),
3510
-                            array(
3511
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3512
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3513
-                                'html_help_text' => esc_html__(
3514
-                                    'You can control how long a record of processed messages is kept via this option.',
3515
-                                    'event_espresso'
3516
-                                ),
3517
-                            )
3518
-                        ),
3519
-                        'update_settings'             => new EE_Submit_Input(
3520
-                            array(
3521
-                                'default'         => esc_html__('Update', 'event_espresso'),
3522
-                                'html_label_text' => '&nbsp'
3523
-                            )
3524
-                        )
3525
-                    )
3526
-                )
3527
-            )
3528
-        );
3529
-    }
3458
+	/**
3459
+	 * This generates and returns the form object for the global messages settings.
3460
+	 *
3461
+	 * @return EE_Form_Section_Proper
3462
+	 * @throws EE_Error
3463
+	 * @throws InvalidArgumentException
3464
+	 * @throws ReflectionException
3465
+	 * @throws InvalidDataTypeException
3466
+	 * @throws InvalidInterfaceException
3467
+	 */
3468
+	protected function _generate_global_settings_form()
3469
+	{
3470
+		EE_Registry::instance()->load_helper('HTML');
3471
+		/** @var EE_Network_Core_Config $network_config */
3472
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3473
+        
3474
+		return new EE_Form_Section_Proper(
3475
+			array(
3476
+				'name'            => 'global_messages_settings',
3477
+				'html_id'         => 'global_messages_settings',
3478
+				'html_class'      => 'form-table',
3479
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3480
+				'subsections'     => apply_filters(
3481
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3482
+					array(
3483
+						'do_messages_on_same_request' => new EE_Select_Input(
3484
+							array(
3485
+								true  => esc_html__("On the same request", "event_espresso"),
3486
+								false => esc_html__("On a separate request", "event_espresso")
3487
+							),
3488
+							array(
3489
+								'default'         => $network_config->do_messages_on_same_request,
3490
+								'html_label_text' => esc_html__(
3491
+									'Generate and send all messages:',
3492
+									'event_espresso'
3493
+								),
3494
+								'html_help_text'  => esc_html__(
3495
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3496
+									'event_espresso'
3497
+								),
3498
+							)
3499
+						),
3500
+						'delete_threshold' => new EE_Select_Input(
3501
+							array(
3502
+								0 => esc_html__('Forever', 'event_espresso'),
3503
+								3 => esc_html__('3 Months', 'event_espresso'),
3504
+								6 => esc_html__('6 Months', 'event_espresso'),
3505
+								9 => esc_html__('9 Months', 'event_espresso'),
3506
+								12 => esc_html__('12 Months', 'event_espresso'),
3507
+								24 => esc_html__('24 Months', 'event_espresso'),
3508
+								36 => esc_html__('36 Months', 'event_espresso')
3509
+							),
3510
+							array(
3511
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3512
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3513
+								'html_help_text' => esc_html__(
3514
+									'You can control how long a record of processed messages is kept via this option.',
3515
+									'event_espresso'
3516
+								),
3517
+							)
3518
+						),
3519
+						'update_settings'             => new EE_Submit_Input(
3520
+							array(
3521
+								'default'         => esc_html__('Update', 'event_espresso'),
3522
+								'html_label_text' => '&nbsp'
3523
+							)
3524
+						)
3525
+					)
3526
+				)
3527
+			)
3528
+		);
3529
+	}
3530 3530
 
3531 3531
 
3532
-    /**
3533
-     * This handles updating the global settings set on the admin page.
3534
-     *
3535
-     * @throws EE_Error
3536
-     * @throws InvalidDataTypeException
3537
-     * @throws InvalidInterfaceException
3538
-     * @throws InvalidArgumentException
3539
-     * @throws ReflectionException
3540
-     */
3541
-    protected function _update_global_settings()
3542
-    {
3543
-        /** @var EE_Network_Core_Config $network_config */
3544
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3545
-        $messages_config = EE_Registry::instance()->CFG->messages;
3546
-        $form           = $this->_generate_global_settings_form();
3547
-        if ($form->was_submitted()) {
3548
-            $form->receive_form_submission();
3549
-            if ($form->is_valid()) {
3550
-                $valid_data = $form->valid_data();
3551
-                foreach ($valid_data as $property => $value) {
3552
-                    $setter = 'set_' . $property;
3553
-                    if (method_exists($network_config, $setter)) {
3554
-                        $network_config->{$setter}($value);
3555
-                    } else if (
3556
-                        property_exists($network_config, $property)
3557
-                        && $network_config->{$property} !== $value
3558
-                    ) {
3559
-                        $network_config->{$property} = $value;
3560
-                    } else if (
3561
-                        property_exists($messages_config, $property)
3562
-                        && $messages_config->{$property} !== $value
3563
-                    ) {
3564
-                        $messages_config->{$property} = $value;
3565
-                    }
3566
-                }
3567
-                //only update if the form submission was valid!
3568
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3569
-                EE_Registry::instance()->CFG->update_espresso_config();
3570
-                EE_Error::overwrite_success();
3571
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3572
-            }
3573
-        }
3574
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3575
-    }
3532
+	/**
3533
+	 * This handles updating the global settings set on the admin page.
3534
+	 *
3535
+	 * @throws EE_Error
3536
+	 * @throws InvalidDataTypeException
3537
+	 * @throws InvalidInterfaceException
3538
+	 * @throws InvalidArgumentException
3539
+	 * @throws ReflectionException
3540
+	 */
3541
+	protected function _update_global_settings()
3542
+	{
3543
+		/** @var EE_Network_Core_Config $network_config */
3544
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3545
+		$messages_config = EE_Registry::instance()->CFG->messages;
3546
+		$form           = $this->_generate_global_settings_form();
3547
+		if ($form->was_submitted()) {
3548
+			$form->receive_form_submission();
3549
+			if ($form->is_valid()) {
3550
+				$valid_data = $form->valid_data();
3551
+				foreach ($valid_data as $property => $value) {
3552
+					$setter = 'set_' . $property;
3553
+					if (method_exists($network_config, $setter)) {
3554
+						$network_config->{$setter}($value);
3555
+					} else if (
3556
+						property_exists($network_config, $property)
3557
+						&& $network_config->{$property} !== $value
3558
+					) {
3559
+						$network_config->{$property} = $value;
3560
+					} else if (
3561
+						property_exists($messages_config, $property)
3562
+						&& $messages_config->{$property} !== $value
3563
+					) {
3564
+						$messages_config->{$property} = $value;
3565
+					}
3566
+				}
3567
+				//only update if the form submission was valid!
3568
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3569
+				EE_Registry::instance()->CFG->update_espresso_config();
3570
+				EE_Error::overwrite_success();
3571
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3572
+			}
3573
+		}
3574
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3575
+	}
3576 3576
 
3577 3577
 
3578
-    /**
3579
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3580
-     *
3581
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3582
-     * @return string html formatted tabs
3583
-     * @throws DomainException
3584
-     */
3585
-    protected function _get_mt_tabs($tab_array)
3586
-    {
3587
-        $tab_array = (array)$tab_array;
3588
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3589
-        $tabs      = '';
3590
-        
3591
-        foreach ($tab_array as $tab) {
3592
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3593
-        }
3594
-        
3595
-        return $tabs;
3596
-    }
3578
+	/**
3579
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3580
+	 *
3581
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3582
+	 * @return string html formatted tabs
3583
+	 * @throws DomainException
3584
+	 */
3585
+	protected function _get_mt_tabs($tab_array)
3586
+	{
3587
+		$tab_array = (array)$tab_array;
3588
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3589
+		$tabs      = '';
3590
+        
3591
+		foreach ($tab_array as $tab) {
3592
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3593
+		}
3594
+        
3595
+		return $tabs;
3596
+	}
3597 3597
 
3598 3598
 
3599
-    /**
3600
-     * This prepares the content of the messenger meta box admin settings
3601
-     *
3602
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3603
-     * @return string html formatted content
3604
-     * @throws DomainException
3605
-     */
3606
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3607
-    {
3599
+	/**
3600
+	 * This prepares the content of the messenger meta box admin settings
3601
+	 *
3602
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3603
+	 * @return string html formatted content
3604
+	 * @throws DomainException
3605
+	 */
3606
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3607
+	{
3608 3608
         
3609
-        $fields                                         = $messenger->get_admin_settings_fields();
3610
-        $settings_template_args['template_form_fields'] = '';
3609
+		$fields                                         = $messenger->get_admin_settings_fields();
3610
+		$settings_template_args['template_form_fields'] = '';
3611 3611
         
3612
-        //is $messenger active?
3613
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3612
+		//is $messenger active?
3613
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3614 3614
         
3615 3615
         
3616
-        if ( ! empty($fields)) {
3616
+		if ( ! empty($fields)) {
3617 3617
             
3618
-            $existing_settings = $messenger->get_existing_admin_settings();
3618
+			$existing_settings = $messenger->get_existing_admin_settings();
3619 3619
             
3620
-            foreach ($fields as $fldname => $fldprops) {
3621
-                $field_id                       = $messenger->name . '-' . $fldname;
3622
-                $template_form_field[$field_id] = array(
3623
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3624
-                    'label'      => $fldprops['label'],
3625
-                    'input'      => $fldprops['field_type'],
3626
-                    'type'       => $fldprops['value_type'],
3627
-                    'required'   => $fldprops['required'],
3628
-                    'validation' => $fldprops['validation'],
3629
-                    'value'      => isset($existing_settings[$field_id])
3630
-                        ? $existing_settings[$field_id]
3631
-                        : $fldprops['default'],
3632
-                    'css_class'  => '',
3633
-                    'format'     => $fldprops['format']
3634
-                );
3635
-            }
3620
+			foreach ($fields as $fldname => $fldprops) {
3621
+				$field_id                       = $messenger->name . '-' . $fldname;
3622
+				$template_form_field[$field_id] = array(
3623
+					'name'       => 'messenger_settings[' . $field_id . ']',
3624
+					'label'      => $fldprops['label'],
3625
+					'input'      => $fldprops['field_type'],
3626
+					'type'       => $fldprops['value_type'],
3627
+					'required'   => $fldprops['required'],
3628
+					'validation' => $fldprops['validation'],
3629
+					'value'      => isset($existing_settings[$field_id])
3630
+						? $existing_settings[$field_id]
3631
+						: $fldprops['default'],
3632
+					'css_class'  => '',
3633
+					'format'     => $fldprops['format']
3634
+				);
3635
+			}
3636 3636
             
3637 3637
             
3638
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3639
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3640
-                : '';
3641
-        }
3642
-        
3643
-        //we also need some hidden fields
3644
-        $settings_template_args['hidden_fields'] = array(
3645
-            'messenger_settings[messenger]' => array(
3646
-                'type'  => 'hidden',
3647
-                'value' => $messenger->name
3648
-            ),
3649
-            'type'                          => array(
3650
-                'type'  => 'hidden',
3651
-                'value' => 'messenger'
3652
-            )
3653
-        );
3654
-        
3655
-        //make sure any active message types that are existing are included in the hidden fields
3656
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3657
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3658
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3659
-                    'type'  => 'hidden',
3660
-                    'value' => $mt
3661
-                );
3662
-            }
3663
-        }
3664
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3665
-            $settings_template_args['hidden_fields'],
3666
-            'array'
3667
-        );
3668
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3669
-        
3670
-        $settings_template_args['messenger']           = $messenger->name;
3671
-        $settings_template_args['description']         = $messenger->description;
3672
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3673
-        
3674
-        
3675
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3676
-            $messenger->name
3677
-        )
3678
-            ? $settings_template_args['show_hide_edit_form']
3679
-            : ' hidden';
3680
-        
3681
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3682
-            ? ' hidden'
3683
-            : $settings_template_args['show_hide_edit_form'];
3684
-        
3685
-        
3686
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3687
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3688
-        $settings_template_args['on_off_status'] = $active ? true : false;
3689
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3690
-        $content                                 = EEH_Template::display_template(
3691
-            $template,
3692
-            $settings_template_args,
3693
-            true
3694
-        );
3695
-        
3696
-        return $content;
3697
-    }
3638
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3639
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3640
+				: '';
3641
+		}
3642
+        
3643
+		//we also need some hidden fields
3644
+		$settings_template_args['hidden_fields'] = array(
3645
+			'messenger_settings[messenger]' => array(
3646
+				'type'  => 'hidden',
3647
+				'value' => $messenger->name
3648
+			),
3649
+			'type'                          => array(
3650
+				'type'  => 'hidden',
3651
+				'value' => 'messenger'
3652
+			)
3653
+		);
3654
+        
3655
+		//make sure any active message types that are existing are included in the hidden fields
3656
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3657
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3658
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3659
+					'type'  => 'hidden',
3660
+					'value' => $mt
3661
+				);
3662
+			}
3663
+		}
3664
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3665
+			$settings_template_args['hidden_fields'],
3666
+			'array'
3667
+		);
3668
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3669
+        
3670
+		$settings_template_args['messenger']           = $messenger->name;
3671
+		$settings_template_args['description']         = $messenger->description;
3672
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3673
+        
3674
+        
3675
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3676
+			$messenger->name
3677
+		)
3678
+			? $settings_template_args['show_hide_edit_form']
3679
+			: ' hidden';
3680
+        
3681
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3682
+			? ' hidden'
3683
+			: $settings_template_args['show_hide_edit_form'];
3684
+        
3685
+        
3686
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3687
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3688
+		$settings_template_args['on_off_status'] = $active ? true : false;
3689
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3690
+		$content                                 = EEH_Template::display_template(
3691
+			$template,
3692
+			$settings_template_args,
3693
+			true
3694
+		);
3695
+        
3696
+		return $content;
3697
+	}
3698 3698
 
3699 3699
 
3700
-    /**
3701
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3702
-     *
3703
-     * @throws DomainException
3704
-     * @throws EE_Error
3705
-     * @throws InvalidDataTypeException
3706
-     * @throws InvalidInterfaceException
3707
-     * @throws InvalidArgumentException
3708
-     * @throws ReflectionException
3709
-     */
3710
-    public function activate_messenger_toggle()
3711
-    {
3712
-        $success = true;
3713
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3714
-        //let's check that we have required data
3715
-        if ( ! isset($this->_req_data['messenger'])) {
3716
-            EE_Error::add_error(
3717
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3718
-                __FILE__,
3719
-                __FUNCTION__,
3720
-                __LINE__
3721
-            );
3722
-            $success = false;
3723
-        }
3724
-        
3725
-        //do a nonce check here since we're not arriving via a normal route
3726
-        $nonce     = isset($this->_req_data['activate_nonce'])
3727
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3728
-            : '';
3729
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3730
-        
3731
-        $this->_verify_nonce($nonce, $nonce_ref);
3732
-        
3733
-        
3734
-        if ( ! isset($this->_req_data['status'])) {
3735
-            EE_Error::add_error(
3736
-                esc_html__(
3737
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3738
-                    'event_espresso'
3739
-                ),
3740
-                __FILE__,
3741
-                __FUNCTION__,
3742
-                __LINE__
3743
-            );
3744
-            $success = false;
3745
-        }
3746
-        
3747
-        //do check to verify we have a valid status.
3748
-        $status = $this->_req_data['status'];
3749
-        
3750
-        if ($status !== 'off' && $status !== 'on') {
3751
-            EE_Error::add_error(
3752
-                sprintf(
3753
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3754
-                    $this->_req_data['status']
3755
-                ),
3756
-                __FILE__,
3757
-                __FUNCTION__,
3758
-                __LINE__
3759
-            );
3760
-            $success = false;
3761
-        }
3762
-        
3763
-        if ($success) {
3764
-            //made it here?  Stop dawdling then!!
3765
-            $success = $status === 'off'
3766
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3767
-                : $this->_activate_messenger($this->_req_data['messenger']);
3768
-        }
3769
-        
3770
-        $this->_template_args['success'] = $success;
3771
-        
3772
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3773
-        $this->_return_json();
3774
-        
3775
-    }
3700
+	/**
3701
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3702
+	 *
3703
+	 * @throws DomainException
3704
+	 * @throws EE_Error
3705
+	 * @throws InvalidDataTypeException
3706
+	 * @throws InvalidInterfaceException
3707
+	 * @throws InvalidArgumentException
3708
+	 * @throws ReflectionException
3709
+	 */
3710
+	public function activate_messenger_toggle()
3711
+	{
3712
+		$success = true;
3713
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3714
+		//let's check that we have required data
3715
+		if ( ! isset($this->_req_data['messenger'])) {
3716
+			EE_Error::add_error(
3717
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3718
+				__FILE__,
3719
+				__FUNCTION__,
3720
+				__LINE__
3721
+			);
3722
+			$success = false;
3723
+		}
3724
+        
3725
+		//do a nonce check here since we're not arriving via a normal route
3726
+		$nonce     = isset($this->_req_data['activate_nonce'])
3727
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3728
+			: '';
3729
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3730
+        
3731
+		$this->_verify_nonce($nonce, $nonce_ref);
3732
+        
3733
+        
3734
+		if ( ! isset($this->_req_data['status'])) {
3735
+			EE_Error::add_error(
3736
+				esc_html__(
3737
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3738
+					'event_espresso'
3739
+				),
3740
+				__FILE__,
3741
+				__FUNCTION__,
3742
+				__LINE__
3743
+			);
3744
+			$success = false;
3745
+		}
3746
+        
3747
+		//do check to verify we have a valid status.
3748
+		$status = $this->_req_data['status'];
3749
+        
3750
+		if ($status !== 'off' && $status !== 'on') {
3751
+			EE_Error::add_error(
3752
+				sprintf(
3753
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3754
+					$this->_req_data['status']
3755
+				),
3756
+				__FILE__,
3757
+				__FUNCTION__,
3758
+				__LINE__
3759
+			);
3760
+			$success = false;
3761
+		}
3762
+        
3763
+		if ($success) {
3764
+			//made it here?  Stop dawdling then!!
3765
+			$success = $status === 'off'
3766
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3767
+				: $this->_activate_messenger($this->_req_data['messenger']);
3768
+		}
3769
+        
3770
+		$this->_template_args['success'] = $success;
3771
+        
3772
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3773
+		$this->_return_json();
3774
+        
3775
+	}
3776 3776
 
3777 3777
 
3778
-    /**
3779
-     * used by ajax from the messages settings page to activate|deactivate a message type
3780
-     *
3781
-     * @throws DomainException
3782
-     * @throws EE_Error
3783
-     * @throws ReflectionException
3784
-     * @throws InvalidDataTypeException
3785
-     * @throws InvalidInterfaceException
3786
-     * @throws InvalidArgumentException
3787
-     */
3788
-    public function activate_mt_toggle()
3789
-    {
3790
-        $success = true;
3791
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3792
-        
3793
-        //let's make sure we have the necessary data
3794
-        if ( ! isset($this->_req_data['message_type'])) {
3795
-            EE_Error::add_error(
3796
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3797
-                __FILE__,
3798
-                __FUNCTION__,
3799
-                __LINE__
3800
-            );
3801
-            $success = false;
3802
-        }
3803
-        
3804
-        if ( ! isset($this->_req_data['messenger'])) {
3805
-            EE_Error::add_error(
3806
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3807
-                __FILE__,
3808
-                __FUNCTION__,
3809
-                __LINE__
3810
-            );
3811
-            $success = false;
3812
-        }
3813
-        
3814
-        if ( ! isset($this->_req_data['status'])) {
3815
-            EE_Error::add_error(
3816
-                esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3817
-                    'event_espresso'),
3818
-                __FILE__,
3819
-                __FUNCTION__,
3820
-                __LINE__
3821
-            );
3822
-            $success = false;
3823
-        }
3824
-        
3825
-        
3826
-        //do check to verify we have a valid status.
3827
-        $status = $this->_req_data['status'];
3828
-        
3829
-        if ($status !== 'activate' && $status !== 'deactivate') {
3830
-            EE_Error::add_error(
3831
-                sprintf(
3832
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3833
-                    $this->_req_data['status']
3834
-                ),
3835
-                __FILE__,
3836
-                __FUNCTION__,
3837
-                __LINE__
3838
-            );
3839
-            $success = false;
3840
-        }
3841
-        
3842
-        
3843
-        //do a nonce check here since we're not arriving via a normal route
3844
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3845
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3846
-        
3847
-        $this->_verify_nonce($nonce, $nonce_ref);
3848
-        
3849
-        if ($success) {
3850
-            //made it here? um, what are you waiting for then?
3851
-            $success = $status === 'deactivate'
3852
-                ? $this->_deactivate_message_type_for_messenger(
3853
-                    $this->_req_data['messenger'],
3854
-                    $this->_req_data['message_type']
3855
-                )
3856
-                : $this->_activate_message_type_for_messenger(
3857
-                    $this->_req_data['messenger'],
3858
-                    $this->_req_data['message_type']
3859
-                );
3860
-        }
3861
-        
3862
-        $this->_template_args['success'] = $success;
3863
-        $this->_return_json();
3864
-    }
3778
+	/**
3779
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3780
+	 *
3781
+	 * @throws DomainException
3782
+	 * @throws EE_Error
3783
+	 * @throws ReflectionException
3784
+	 * @throws InvalidDataTypeException
3785
+	 * @throws InvalidInterfaceException
3786
+	 * @throws InvalidArgumentException
3787
+	 */
3788
+	public function activate_mt_toggle()
3789
+	{
3790
+		$success = true;
3791
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3792
+        
3793
+		//let's make sure we have the necessary data
3794
+		if ( ! isset($this->_req_data['message_type'])) {
3795
+			EE_Error::add_error(
3796
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3797
+				__FILE__,
3798
+				__FUNCTION__,
3799
+				__LINE__
3800
+			);
3801
+			$success = false;
3802
+		}
3803
+        
3804
+		if ( ! isset($this->_req_data['messenger'])) {
3805
+			EE_Error::add_error(
3806
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3807
+				__FILE__,
3808
+				__FUNCTION__,
3809
+				__LINE__
3810
+			);
3811
+			$success = false;
3812
+		}
3813
+        
3814
+		if ( ! isset($this->_req_data['status'])) {
3815
+			EE_Error::add_error(
3816
+				esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3817
+					'event_espresso'),
3818
+				__FILE__,
3819
+				__FUNCTION__,
3820
+				__LINE__
3821
+			);
3822
+			$success = false;
3823
+		}
3824
+        
3825
+        
3826
+		//do check to verify we have a valid status.
3827
+		$status = $this->_req_data['status'];
3828
+        
3829
+		if ($status !== 'activate' && $status !== 'deactivate') {
3830
+			EE_Error::add_error(
3831
+				sprintf(
3832
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3833
+					$this->_req_data['status']
3834
+				),
3835
+				__FILE__,
3836
+				__FUNCTION__,
3837
+				__LINE__
3838
+			);
3839
+			$success = false;
3840
+		}
3841
+        
3842
+        
3843
+		//do a nonce check here since we're not arriving via a normal route
3844
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3845
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3846
+        
3847
+		$this->_verify_nonce($nonce, $nonce_ref);
3848
+        
3849
+		if ($success) {
3850
+			//made it here? um, what are you waiting for then?
3851
+			$success = $status === 'deactivate'
3852
+				? $this->_deactivate_message_type_for_messenger(
3853
+					$this->_req_data['messenger'],
3854
+					$this->_req_data['message_type']
3855
+				)
3856
+				: $this->_activate_message_type_for_messenger(
3857
+					$this->_req_data['messenger'],
3858
+					$this->_req_data['message_type']
3859
+				);
3860
+		}
3861
+        
3862
+		$this->_template_args['success'] = $success;
3863
+		$this->_return_json();
3864
+	}
3865 3865
 
3866 3866
 
3867
-    /**
3868
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3869
-     *
3870
-     * @param string $messenger_name The name of the messenger being activated
3871
-     * @return bool
3872
-     * @throws DomainException
3873
-     * @throws EE_Error
3874
-     * @throws InvalidArgumentException
3875
-     * @throws ReflectionException
3876
-     * @throws InvalidDataTypeException
3877
-     * @throws InvalidInterfaceException
3878
-     */
3879
-    protected function _activate_messenger($messenger_name)
3880
-    {
3881
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3882
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3883
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3884
-            ? $active_messenger->get_default_message_types()
3885
-            : array();
3886
-        
3887
-        //ensure is active
3888
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3889
-        
3890
-        //set response_data for reload
3891
-        foreach ($message_types_to_activate as $message_type_name) {
3892
-            /** @var EE_message_type $message_type */
3893
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3894
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3895
-                    $messenger_name,
3896
-                    $message_type_name
3897
-                )
3898
-                && $message_type instanceof EE_message_type
3899
-            ) {
3900
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3901
-                if ($message_type->get_admin_settings_fields()) {
3902
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3903
-                }
3904
-            }
3905
-        }
3906
-        
3907
-        //add success message for activating messenger
3908
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3909
-        
3910
-    }
3867
+	/**
3868
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3869
+	 *
3870
+	 * @param string $messenger_name The name of the messenger being activated
3871
+	 * @return bool
3872
+	 * @throws DomainException
3873
+	 * @throws EE_Error
3874
+	 * @throws InvalidArgumentException
3875
+	 * @throws ReflectionException
3876
+	 * @throws InvalidDataTypeException
3877
+	 * @throws InvalidInterfaceException
3878
+	 */
3879
+	protected function _activate_messenger($messenger_name)
3880
+	{
3881
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3882
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3883
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3884
+			? $active_messenger->get_default_message_types()
3885
+			: array();
3886
+        
3887
+		//ensure is active
3888
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3889
+        
3890
+		//set response_data for reload
3891
+		foreach ($message_types_to_activate as $message_type_name) {
3892
+			/** @var EE_message_type $message_type */
3893
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3894
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3895
+					$messenger_name,
3896
+					$message_type_name
3897
+				)
3898
+				&& $message_type instanceof EE_message_type
3899
+			) {
3900
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3901
+				if ($message_type->get_admin_settings_fields()) {
3902
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3903
+				}
3904
+			}
3905
+		}
3906
+        
3907
+		//add success message for activating messenger
3908
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3909
+        
3910
+	}
3911 3911
 
3912 3912
 
3913
-    /**
3914
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3915
-     *
3916
-     * @param string $messenger_name The name of the messenger being activated
3917
-     * @return bool
3918
-     * @throws DomainException
3919
-     * @throws EE_Error
3920
-     * @throws InvalidArgumentException
3921
-     * @throws ReflectionException
3922
-     * @throws InvalidDataTypeException
3923
-     * @throws InvalidInterfaceException
3924
-     */
3925
-    protected function _deactivate_messenger($messenger_name)
3926
-    {
3927
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3928
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3929
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3930
-        
3931
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3932
-    }
3913
+	/**
3914
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3915
+	 *
3916
+	 * @param string $messenger_name The name of the messenger being activated
3917
+	 * @return bool
3918
+	 * @throws DomainException
3919
+	 * @throws EE_Error
3920
+	 * @throws InvalidArgumentException
3921
+	 * @throws ReflectionException
3922
+	 * @throws InvalidDataTypeException
3923
+	 * @throws InvalidInterfaceException
3924
+	 */
3925
+	protected function _deactivate_messenger($messenger_name)
3926
+	{
3927
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3928
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3929
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3930
+        
3931
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3932
+	}
3933 3933
 
3934 3934
 
3935
-    /**
3936
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3937
-     *
3938
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3939
-     * @param string $message_type_name The name of the message type being activated for the messenger
3940
-     * @return bool
3941
-     * @throws DomainException
3942
-     * @throws EE_Error
3943
-     * @throws InvalidArgumentException
3944
-     * @throws ReflectionException
3945
-     * @throws InvalidDataTypeException
3946
-     * @throws InvalidInterfaceException
3947
-     */
3948
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3949
-    {
3950
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3951
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3952
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3953
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3954
-        
3955
-        //ensure is active
3956
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3957
-        
3958
-        //set response for load
3959
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3960
-            $message_type_name)
3961
-        ) {
3962
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3963
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3964
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3965
-            }
3966
-        }
3967
-        
3968
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3969
-            $message_type_to_activate);
3970
-    }
3935
+	/**
3936
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3937
+	 *
3938
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3939
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3940
+	 * @return bool
3941
+	 * @throws DomainException
3942
+	 * @throws EE_Error
3943
+	 * @throws InvalidArgumentException
3944
+	 * @throws ReflectionException
3945
+	 * @throws InvalidDataTypeException
3946
+	 * @throws InvalidInterfaceException
3947
+	 */
3948
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3949
+	{
3950
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3951
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3952
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3953
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3954
+        
3955
+		//ensure is active
3956
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3957
+        
3958
+		//set response for load
3959
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3960
+			$message_type_name)
3961
+		) {
3962
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3963
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3964
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3965
+			}
3966
+		}
3967
+        
3968
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3969
+			$message_type_to_activate);
3970
+	}
3971 3971
 
3972 3972
 
3973
-    /**
3974
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3975
-     *
3976
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3977
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3978
-     * @return bool
3979
-     * @throws DomainException
3980
-     * @throws EE_Error
3981
-     * @throws InvalidArgumentException
3982
-     * @throws ReflectionException
3983
-     * @throws InvalidDataTypeException
3984
-     * @throws InvalidInterfaceException
3985
-     */
3986
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3987
-    {
3988
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3989
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3990
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3991
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3992
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3993
-        
3994
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3995
-            $message_type_to_deactivate);
3996
-    }
3973
+	/**
3974
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3975
+	 *
3976
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3977
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3978
+	 * @return bool
3979
+	 * @throws DomainException
3980
+	 * @throws EE_Error
3981
+	 * @throws InvalidArgumentException
3982
+	 * @throws ReflectionException
3983
+	 * @throws InvalidDataTypeException
3984
+	 * @throws InvalidInterfaceException
3985
+	 */
3986
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3987
+	{
3988
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3989
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3990
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3991
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3992
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3993
+        
3994
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3995
+			$message_type_to_deactivate);
3996
+	}
3997 3997
     
3998 3998
     
3999
-    /**
4000
-     * This just initializes the defaults for activating messenger and message type responses.
4001
-     */
4002
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4003
-    {
4004
-        $this->_template_args['data']['active_mts'] = array();
4005
-        $this->_template_args['data']['mt_reload']  = array();
4006
-    }
3999
+	/**
4000
+	 * This just initializes the defaults for activating messenger and message type responses.
4001
+	 */
4002
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4003
+	{
4004
+		$this->_template_args['data']['active_mts'] = array();
4005
+		$this->_template_args['data']['mt_reload']  = array();
4006
+	}
4007 4007
 
4008 4008
 
4009
-    /**
4010
-     * Setup appropriate response for activating a messenger and/or message types
4011
-     *
4012
-     * @param EE_messenger         $messenger
4013
-     * @param EE_message_type|null $message_type
4014
-     * @return bool
4015
-     * @throws DomainException
4016
-     * @throws EE_Error
4017
-     * @throws InvalidArgumentException
4018
-     * @throws ReflectionException
4019
-     * @throws InvalidDataTypeException
4020
-     * @throws InvalidInterfaceException
4021
-     */
4022
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4023
-        $messenger,
4024
-        EE_Message_Type $message_type = null
4025
-    ) {
4026
-        //if $messenger isn't a valid messenger object then get out.
4027
-        if ( ! $messenger instanceof EE_Messenger) {
4028
-            EE_Error::add_error(
4029
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4009
+	/**
4010
+	 * Setup appropriate response for activating a messenger and/or message types
4011
+	 *
4012
+	 * @param EE_messenger         $messenger
4013
+	 * @param EE_message_type|null $message_type
4014
+	 * @return bool
4015
+	 * @throws DomainException
4016
+	 * @throws EE_Error
4017
+	 * @throws InvalidArgumentException
4018
+	 * @throws ReflectionException
4019
+	 * @throws InvalidDataTypeException
4020
+	 * @throws InvalidInterfaceException
4021
+	 */
4022
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4023
+		$messenger,
4024
+		EE_Message_Type $message_type = null
4025
+	) {
4026
+		//if $messenger isn't a valid messenger object then get out.
4027
+		if ( ! $messenger instanceof EE_Messenger) {
4028
+			EE_Error::add_error(
4029
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034 4034
             
4035
-            return false;
4036
-        }
4037
-        //activated
4038
-        if ($this->_template_args['data']['active_mts']) {
4039
-            EE_Error::overwrite_success();
4040
-            //activated a message type with the messenger
4041
-            if ($message_type instanceof EE_message_type) {
4042
-                EE_Error::add_success(
4043
-                    sprintf(
4044
-                        esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4045
-                        ucwords($message_type->label['singular']),
4046
-                        ucwords($messenger->label['singular'])
4047
-                    )
4048
-                );
4035
+			return false;
4036
+		}
4037
+		//activated
4038
+		if ($this->_template_args['data']['active_mts']) {
4039
+			EE_Error::overwrite_success();
4040
+			//activated a message type with the messenger
4041
+			if ($message_type instanceof EE_message_type) {
4042
+				EE_Error::add_success(
4043
+					sprintf(
4044
+						esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4045
+						ucwords($message_type->label['singular']),
4046
+						ucwords($messenger->label['singular'])
4047
+					)
4048
+				);
4049 4049
                 
4050
-                //if message type was invoice then let's make sure we activate the invoice payment method.
4051
-                if ($message_type->name === 'invoice') {
4052
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4053
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4054
-                    if ($pm instanceof EE_Payment_Method) {
4055
-                        EE_Error::add_attention(
4056
-                            esc_html__(
4057
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4058
-                                'event_espresso'
4059
-                            )
4060
-                        );
4061
-                    }
4062
-                }
4063
-                //just toggles the entire messenger
4064
-            } else {
4065
-                EE_Error::add_success(
4066
-                    sprintf(
4067
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4068
-                        ucwords($messenger->label['singular'])
4069
-                    )
4070
-                );
4071
-            }
4050
+				//if message type was invoice then let's make sure we activate the invoice payment method.
4051
+				if ($message_type->name === 'invoice') {
4052
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4053
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4054
+					if ($pm instanceof EE_Payment_Method) {
4055
+						EE_Error::add_attention(
4056
+							esc_html__(
4057
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4058
+								'event_espresso'
4059
+							)
4060
+						);
4061
+					}
4062
+				}
4063
+				//just toggles the entire messenger
4064
+			} else {
4065
+				EE_Error::add_success(
4066
+					sprintf(
4067
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4068
+						ucwords($messenger->label['singular'])
4069
+					)
4070
+				);
4071
+			}
4072 4072
             
4073
-            return true;
4073
+			return true;
4074 4074
             
4075
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4076
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4077
-            //in which case we just give a success message for the messenger being successfully activated.
4078
-        } else {
4079
-            if ( ! $messenger->get_default_message_types()) {
4080
-                //messenger doesn't have any default message types so still a success.
4081
-                EE_Error::add_success(
4082
-                    sprintf(
4083
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4084
-                        ucwords($messenger->label['singular'])
4085
-                    )
4086
-                );
4075
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4076
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4077
+			//in which case we just give a success message for the messenger being successfully activated.
4078
+		} else {
4079
+			if ( ! $messenger->get_default_message_types()) {
4080
+				//messenger doesn't have any default message types so still a success.
4081
+				EE_Error::add_success(
4082
+					sprintf(
4083
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4084
+						ucwords($messenger->label['singular'])
4085
+					)
4086
+				);
4087 4087
                 
4088
-                return true;
4089
-            } else {
4090
-                EE_Error::add_error(
4091
-                    $message_type instanceof EE_message_type
4092
-                        ? sprintf(
4093
-                        esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4094
-                        ucwords($message_type->label['singular']),
4095
-                        ucwords($messenger->label['singular'])
4096
-                    )
4097
-                        : sprintf(
4098
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4099
-                        ucwords($messenger->label['singular'])
4100
-                    ),
4101
-                    __FILE__,
4102
-                    __FUNCTION__,
4103
-                    __LINE__
4104
-                );
4088
+				return true;
4089
+			} else {
4090
+				EE_Error::add_error(
4091
+					$message_type instanceof EE_message_type
4092
+						? sprintf(
4093
+						esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4094
+						ucwords($message_type->label['singular']),
4095
+						ucwords($messenger->label['singular'])
4096
+					)
4097
+						: sprintf(
4098
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4099
+						ucwords($messenger->label['singular'])
4100
+					),
4101
+					__FILE__,
4102
+					__FUNCTION__,
4103
+					__LINE__
4104
+				);
4105 4105
                 
4106
-                return false;
4107
-            }
4108
-        }
4109
-    }
4106
+				return false;
4107
+			}
4108
+		}
4109
+	}
4110 4110
 
4111 4111
 
4112
-    /**
4113
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4114
-     *
4115
-     * @param EE_messenger         $messenger
4116
-     * @param EE_message_type|null $message_type
4117
-     * @return bool
4118
-     * @throws DomainException
4119
-     * @throws EE_Error
4120
-     * @throws InvalidArgumentException
4121
-     * @throws ReflectionException
4122
-     * @throws InvalidDataTypeException
4123
-     * @throws InvalidInterfaceException
4124
-     */
4125
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4126
-        $messenger,
4127
-        EE_message_type $message_type = null
4128
-    ) {
4129
-        EE_Error::overwrite_success();
4130
-        
4131
-        //if $messenger isn't a valid messenger object then get out.
4132
-        if ( ! $messenger instanceof EE_Messenger) {
4133
-            EE_Error::add_error(
4134
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4135
-                __FILE__,
4136
-                __FUNCTION__,
4137
-                __LINE__
4138
-            );
4112
+	/**
4113
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4114
+	 *
4115
+	 * @param EE_messenger         $messenger
4116
+	 * @param EE_message_type|null $message_type
4117
+	 * @return bool
4118
+	 * @throws DomainException
4119
+	 * @throws EE_Error
4120
+	 * @throws InvalidArgumentException
4121
+	 * @throws ReflectionException
4122
+	 * @throws InvalidDataTypeException
4123
+	 * @throws InvalidInterfaceException
4124
+	 */
4125
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4126
+		$messenger,
4127
+		EE_message_type $message_type = null
4128
+	) {
4129
+		EE_Error::overwrite_success();
4130
+        
4131
+		//if $messenger isn't a valid messenger object then get out.
4132
+		if ( ! $messenger instanceof EE_Messenger) {
4133
+			EE_Error::add_error(
4134
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4135
+				__FILE__,
4136
+				__FUNCTION__,
4137
+				__LINE__
4138
+			);
4139 4139
             
4140
-            return false;
4141
-        }
4142
-        
4143
-        if ($message_type instanceof EE_message_type) {
4144
-            $message_type_name = $message_type->name;
4145
-            EE_Error::add_success(
4146
-                sprintf(
4147
-                    esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4148
-                    ucwords($message_type->label['singular']),
4149
-                    ucwords($messenger->label['singular'])
4150
-                )
4151
-            );
4152
-        } else {
4153
-            $message_type_name = '';
4154
-            EE_Error::add_success(
4155
-                sprintf(
4156
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4157
-                    ucwords($messenger->label['singular'])
4158
-                )
4159
-            );
4160
-        }
4161
-        
4162
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4163
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4164
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4165
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4166
-            if ($count_updated > 0) {
4167
-                $msg = $message_type_name === 'invoice'
4168
-                    ? esc_html__(
4169
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4170
-                        'event_espresso'
4171
-                    )
4172
-                    : esc_html__(
4173
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4174
-                        'event_espresso'
4175
-                    );
4176
-                EE_Error::add_attention($msg);
4177
-            }
4178
-        }
4179
-        
4180
-        return true;
4181
-    }
4140
+			return false;
4141
+		}
4142
+        
4143
+		if ($message_type instanceof EE_message_type) {
4144
+			$message_type_name = $message_type->name;
4145
+			EE_Error::add_success(
4146
+				sprintf(
4147
+					esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4148
+					ucwords($message_type->label['singular']),
4149
+					ucwords($messenger->label['singular'])
4150
+				)
4151
+			);
4152
+		} else {
4153
+			$message_type_name = '';
4154
+			EE_Error::add_success(
4155
+				sprintf(
4156
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4157
+					ucwords($messenger->label['singular'])
4158
+				)
4159
+			);
4160
+		}
4161
+        
4162
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4163
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4164
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4165
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4166
+			if ($count_updated > 0) {
4167
+				$msg = $message_type_name === 'invoice'
4168
+					? esc_html__(
4169
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4170
+						'event_espresso'
4171
+					)
4172
+					: esc_html__(
4173
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4174
+						'event_espresso'
4175
+					);
4176
+				EE_Error::add_attention($msg);
4177
+			}
4178
+		}
4179
+        
4180
+		return true;
4181
+	}
4182 4182
 
4183 4183
 
4184
-    /**
4185
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4186
-     *
4187
-     * @throws DomainException
4188
-     */
4189
-    public function update_mt_form()
4190
-    {
4191
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4192
-            EE_Error::add_error(
4193
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4194
-                __FILE__,
4195
-                __FUNCTION__,
4196
-                __LINE__
4197
-            );
4198
-            $this->_return_json();
4199
-        }
4200
-        
4201
-        $message_types = $this->get_installed_message_types();
4202
-        
4203
-        $message_type = $message_types[$this->_req_data['message_type']];
4204
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4205
-        
4206
-        $content                         = $this->_message_type_settings_content(
4207
-            $message_type,
4208
-            $messenger,
4209
-            true
4210
-        );
4211
-        $this->_template_args['success'] = true;
4212
-        $this->_template_args['content'] = $content;
4213
-        $this->_return_json();
4214
-    }
4184
+	/**
4185
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4186
+	 *
4187
+	 * @throws DomainException
4188
+	 */
4189
+	public function update_mt_form()
4190
+	{
4191
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4192
+			EE_Error::add_error(
4193
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4194
+				__FILE__,
4195
+				__FUNCTION__,
4196
+				__LINE__
4197
+			);
4198
+			$this->_return_json();
4199
+		}
4200
+        
4201
+		$message_types = $this->get_installed_message_types();
4202
+        
4203
+		$message_type = $message_types[$this->_req_data['message_type']];
4204
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4205
+        
4206
+		$content                         = $this->_message_type_settings_content(
4207
+			$message_type,
4208
+			$messenger,
4209
+			true
4210
+		);
4211
+		$this->_template_args['success'] = true;
4212
+		$this->_template_args['content'] = $content;
4213
+		$this->_return_json();
4214
+	}
4215 4215
     
4216 4216
     
4217
-    /**
4218
-     * this handles saving the settings for a messenger or message type
4219
-     *
4220
-     */
4221
-    public function save_settings()
4222
-    {
4223
-        if ( ! isset($this->_req_data['type'])) {
4224
-            EE_Error::add_error(
4225
-                esc_html__(
4226
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4227
-                    'event_espresso'
4228
-                ),
4229
-                __FILE__,
4230
-                __FUNCTION__,
4231
-                __LINE__
4232
-            );
4233
-            $this->_template_args['error'] = true;
4234
-            $this->_return_json();
4235
-        }
4236
-        
4237
-        
4238
-        if ($this->_req_data['type'] === 'messenger') {
4239
-            //this should be an array.
4240
-            $settings  = $this->_req_data['messenger_settings'];
4241
-            $messenger = $settings['messenger'];
4242
-            //let's setup the settings data
4243
-            foreach ($settings as $key => $value) {
4244
-                switch ($key) {
4245
-                    case 'messenger' :
4246
-                        unset($settings['messenger']);
4247
-                        break;
4248
-                    case 'message_types' :
4249
-                        unset($settings['message_types']);
4250
-                        break;
4251
-                    default :
4252
-                        $settings[$key] = $value;
4253
-                        break;
4254
-                }
4255
-            }
4256
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4257
-        } elseif ($this->_req_data['type'] === 'message_type') {
4258
-            $settings     = $this->_req_data['message_type_settings'];
4259
-            $messenger    = $settings['messenger'];
4260
-            $message_type = $settings['message_type'];
4217
+	/**
4218
+	 * this handles saving the settings for a messenger or message type
4219
+	 *
4220
+	 */
4221
+	public function save_settings()
4222
+	{
4223
+		if ( ! isset($this->_req_data['type'])) {
4224
+			EE_Error::add_error(
4225
+				esc_html__(
4226
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4227
+					'event_espresso'
4228
+				),
4229
+				__FILE__,
4230
+				__FUNCTION__,
4231
+				__LINE__
4232
+			);
4233
+			$this->_template_args['error'] = true;
4234
+			$this->_return_json();
4235
+		}
4236
+        
4237
+        
4238
+		if ($this->_req_data['type'] === 'messenger') {
4239
+			//this should be an array.
4240
+			$settings  = $this->_req_data['messenger_settings'];
4241
+			$messenger = $settings['messenger'];
4242
+			//let's setup the settings data
4243
+			foreach ($settings as $key => $value) {
4244
+				switch ($key) {
4245
+					case 'messenger' :
4246
+						unset($settings['messenger']);
4247
+						break;
4248
+					case 'message_types' :
4249
+						unset($settings['message_types']);
4250
+						break;
4251
+					default :
4252
+						$settings[$key] = $value;
4253
+						break;
4254
+				}
4255
+			}
4256
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4257
+		} elseif ($this->_req_data['type'] === 'message_type') {
4258
+			$settings     = $this->_req_data['message_type_settings'];
4259
+			$messenger    = $settings['messenger'];
4260
+			$message_type = $settings['message_type'];
4261 4261
             
4262
-            foreach ($settings as $key => $value) {
4263
-                switch ($key) {
4264
-                    case 'messenger' :
4265
-                        unset($settings['messenger']);
4266
-                        break;
4267
-                    case 'message_type' :
4268
-                        unset($settings['message_type']);
4269
-                        break;
4270
-                    default :
4271
-                        $settings[$key] = $value;
4272
-                        break;
4273
-                }
4274
-            }
4262
+			foreach ($settings as $key => $value) {
4263
+				switch ($key) {
4264
+					case 'messenger' :
4265
+						unset($settings['messenger']);
4266
+						break;
4267
+					case 'message_type' :
4268
+						unset($settings['message_type']);
4269
+						break;
4270
+					default :
4271
+						$settings[$key] = $value;
4272
+						break;
4273
+				}
4274
+			}
4275 4275
             
4276
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4277
-        }
4278
-        
4279
-        //okay we should have the data all setup.  Now we just update!
4280
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4281
-        
4282
-        if ($success) {
4283
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4284
-        } else {
4285
-            EE_Error::add_error(
4286
-                esc_html__(
4287
-                    'Settings did not get updated',
4288
-                    'event_espresso'
4289
-                ),
4290
-                __FILE__,
4291
-                __FUNCTION__,
4292
-                __LINE__
4293
-            );
4294
-        }
4295
-        
4296
-        $this->_template_args['success'] = $success;
4297
-        $this->_return_json();
4298
-    }
4276
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4277
+		}
4278
+        
4279
+		//okay we should have the data all setup.  Now we just update!
4280
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4281
+        
4282
+		if ($success) {
4283
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4284
+		} else {
4285
+			EE_Error::add_error(
4286
+				esc_html__(
4287
+					'Settings did not get updated',
4288
+					'event_espresso'
4289
+				),
4290
+				__FILE__,
4291
+				__FUNCTION__,
4292
+				__LINE__
4293
+			);
4294
+		}
4295
+        
4296
+		$this->_template_args['success'] = $success;
4297
+		$this->_return_json();
4298
+	}
4299 4299
     
4300 4300
     
4301 4301
     
4302 4302
     
4303
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4303
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4304 4304
 
4305 4305
 
4306
-    /**
4307
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4308
-     * However, this does not send immediately, it just queues for sending.
4309
-     *
4310
-     * @since 4.9.0
4311
-     * @throws EE_Error
4312
-     * @throws InvalidDataTypeException
4313
-     * @throws InvalidInterfaceException
4314
-     * @throws InvalidArgumentException
4315
-     * @throws ReflectionException
4316
-     */
4317
-    protected function _generate_now()
4318
-    {
4319
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4320
-        $this->_redirect_after_action(false, '', '', array(), true);
4321
-    }
4306
+	/**
4307
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4308
+	 * However, this does not send immediately, it just queues for sending.
4309
+	 *
4310
+	 * @since 4.9.0
4311
+	 * @throws EE_Error
4312
+	 * @throws InvalidDataTypeException
4313
+	 * @throws InvalidInterfaceException
4314
+	 * @throws InvalidArgumentException
4315
+	 * @throws ReflectionException
4316
+	 */
4317
+	protected function _generate_now()
4318
+	{
4319
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4320
+		$this->_redirect_after_action(false, '', '', array(), true);
4321
+	}
4322 4322
 
4323 4323
 
4324
-    /**
4325
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4326
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4327
-     *
4328
-     * @since 4.9.0
4329
-     * @throws EE_Error
4330
-     * @throws InvalidDataTypeException
4331
-     * @throws InvalidInterfaceException
4332
-     * @throws InvalidArgumentException
4333
-     * @throws ReflectionException
4334
-     */
4335
-    protected function _generate_and_send_now()
4336
-    {
4337
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4338
-        $this->_redirect_after_action(false, '', '', array(), true);
4339
-    }
4324
+	/**
4325
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4326
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4327
+	 *
4328
+	 * @since 4.9.0
4329
+	 * @throws EE_Error
4330
+	 * @throws InvalidDataTypeException
4331
+	 * @throws InvalidInterfaceException
4332
+	 * @throws InvalidArgumentException
4333
+	 * @throws ReflectionException
4334
+	 */
4335
+	protected function _generate_and_send_now()
4336
+	{
4337
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4338
+		$this->_redirect_after_action(false, '', '', array(), true);
4339
+	}
4340 4340
 
4341 4341
 
4342
-    /**
4343
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4344
-     *
4345
-     * @since 4.9.0
4346
-     * @throws EE_Error
4347
-     * @throws InvalidDataTypeException
4348
-     * @throws InvalidInterfaceException
4349
-     * @throws InvalidArgumentException
4350
-     * @throws ReflectionException
4351
-     */
4352
-    protected function _queue_for_resending()
4353
-    {
4354
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4355
-        $this->_redirect_after_action(false, '', '', array(), true);
4356
-    }
4342
+	/**
4343
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4344
+	 *
4345
+	 * @since 4.9.0
4346
+	 * @throws EE_Error
4347
+	 * @throws InvalidDataTypeException
4348
+	 * @throws InvalidInterfaceException
4349
+	 * @throws InvalidArgumentException
4350
+	 * @throws ReflectionException
4351
+	 */
4352
+	protected function _queue_for_resending()
4353
+	{
4354
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4355
+		$this->_redirect_after_action(false, '', '', array(), true);
4356
+	}
4357 4357
 
4358 4358
 
4359
-    /**
4360
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4361
-     *
4362
-     * @since 4.9.0
4363
-     * @throws EE_Error
4364
-     * @throws InvalidDataTypeException
4365
-     * @throws InvalidInterfaceException
4366
-     * @throws InvalidArgumentException
4367
-     * @throws ReflectionException
4368
-     */
4369
-    protected function _send_now()
4370
-    {
4371
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4372
-        $this->_redirect_after_action(false, '', '', array(), true);
4373
-    }
4359
+	/**
4360
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4361
+	 *
4362
+	 * @since 4.9.0
4363
+	 * @throws EE_Error
4364
+	 * @throws InvalidDataTypeException
4365
+	 * @throws InvalidInterfaceException
4366
+	 * @throws InvalidArgumentException
4367
+	 * @throws ReflectionException
4368
+	 */
4369
+	protected function _send_now()
4370
+	{
4371
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4372
+		$this->_redirect_after_action(false, '', '', array(), true);
4373
+	}
4374 4374
 
4375 4375
 
4376
-    /**
4377
-     * Deletes EE_messages for IDs in the request.
4378
-     *
4379
-     * @since 4.9.0
4380
-     * @throws EE_Error
4381
-     * @throws InvalidDataTypeException
4382
-     * @throws InvalidInterfaceException
4383
-     * @throws InvalidArgumentException
4384
-     */
4385
-    protected function _delete_ee_messages()
4386
-    {
4387
-        $msg_ids       = $this->_get_msg_ids_from_request();
4388
-        $deleted_count = 0;
4389
-        foreach ($msg_ids as $msg_id) {
4390
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4391
-                $deleted_count++;
4392
-            }
4393
-        }
4394
-        if ($deleted_count) {
4395
-            $this->_redirect_after_action(
4396
-                true,
4397
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
4398
-                esc_html__('deleted', 'event_espresso')
4399
-            );
4400
-        } else {
4401
-            EE_Error::add_error(
4402
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4403
-                __FILE__, __FUNCTION__, __LINE__
4404
-            );
4405
-            $this->_redirect_after_action(false, '', '', array(), true);
4406
-        }
4407
-    }
4376
+	/**
4377
+	 * Deletes EE_messages for IDs in the request.
4378
+	 *
4379
+	 * @since 4.9.0
4380
+	 * @throws EE_Error
4381
+	 * @throws InvalidDataTypeException
4382
+	 * @throws InvalidInterfaceException
4383
+	 * @throws InvalidArgumentException
4384
+	 */
4385
+	protected function _delete_ee_messages()
4386
+	{
4387
+		$msg_ids       = $this->_get_msg_ids_from_request();
4388
+		$deleted_count = 0;
4389
+		foreach ($msg_ids as $msg_id) {
4390
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4391
+				$deleted_count++;
4392
+			}
4393
+		}
4394
+		if ($deleted_count) {
4395
+			$this->_redirect_after_action(
4396
+				true,
4397
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
4398
+				esc_html__('deleted', 'event_espresso')
4399
+			);
4400
+		} else {
4401
+			EE_Error::add_error(
4402
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4403
+				__FILE__, __FUNCTION__, __LINE__
4404
+			);
4405
+			$this->_redirect_after_action(false, '', '', array(), true);
4406
+		}
4407
+	}
4408 4408
     
4409 4409
     
4410
-    /**
4411
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4412
-     * @since 4.9.0
4413
-     * @return array
4414
-     */
4415
-    protected function _get_msg_ids_from_request()
4416
-    {
4417
-        if ( ! isset($this->_req_data['MSG_ID'])) {
4418
-            return array();
4419
-        }
4420
-        
4421
-        return is_array($this->_req_data['MSG_ID'])
4422
-            ? array_keys($this->_req_data['MSG_ID'])
4423
-            : array($this->_req_data['MSG_ID']);
4424
-    }
4410
+	/**
4411
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4412
+	 * @since 4.9.0
4413
+	 * @return array
4414
+	 */
4415
+	protected function _get_msg_ids_from_request()
4416
+	{
4417
+		if ( ! isset($this->_req_data['MSG_ID'])) {
4418
+			return array();
4419
+		}
4420
+        
4421
+		return is_array($this->_req_data['MSG_ID'])
4422
+			? array_keys($this->_req_data['MSG_ID'])
4423
+			: array($this->_req_data['MSG_ID']);
4424
+	}
4425 4425
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Transaction_Shortcodes.lib.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
                    && isset($this->_extra_data['data'])
275 275
                    && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
276 276
             : $payment;
277
-        if (! $transaction instanceof EE_Transaction) {
277
+        if ( ! $transaction instanceof EE_Transaction) {
278 278
             return '';
279 279
         }
280 280
         switch ($shortcode) {
@@ -289,16 +289,16 @@  discard block
 block discarded – undo
289 289
                 break;
290 290
             case '[INVOICE_LINK]':
291 291
                 $invoice_url = $transaction->invoice_url();
292
-                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
292
+                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
293 293
                 return sprintf(
294 294
                     esc_html__('%sClick here for Invoice%s', 'event_espresso'),
295
-                    '<a href="' . $invoice_url . '">',
295
+                    '<a href="'.$invoice_url.'">',
296 296
                     '</a>'
297 297
                 );
298 298
                 break;
299 299
             case '[INVOICE_URL]':
300 300
                 $invoice_url = $transaction->invoice_url();
301
-                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
301
+                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
302 302
                 break;
303 303
             case '[INVOICE_LOGO_URL]':
304 304
                 return $this->_get_invoice_logo();
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
                 break;
321 321
             case '[TOTAL_COST]':
322 322
                 $total = $transaction->total();
323
-                return ! empty($total) ? EEH_Template::format_currency($total): '';
323
+                return ! empty($total) ? EEH_Template::format_currency($total) : '';
324 324
                 break;
325 325
             case '[PAYMENT_STATUS]':
326 326
                 $status = $transaction->pretty_status();
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
                 return $this->_data->total_ticket_count;
367 367
                 break;
368 368
             case '[TRANSACTION_ADMIN_URL]':
369
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
369
+                require_once EE_CORE.'admin/EE_Admin_Page.core.php';
370 370
                 $query_args = array(
371 371
                     'page'   => 'espresso_transactions',
372 372
                     'action' => 'view_transaction',
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
             case '[RECEIPT_URL]':
379 379
                 //get primary_registration
380 380
                 $reg = $this->_data->primary_reg_obj;
381
-                if (! $reg instanceof EE_Registration) {
381
+                if ( ! $reg instanceof EE_Registration) {
382 382
                     return '';
383 383
                 }
384 384
                 return $reg->receipt_url();
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
      */
463 463
     private function _get_payment_gateway($transaction)
464 464
     {
465
-        if ($transaction instanceof EE_Transaction){
465
+        if ($transaction instanceof EE_Transaction) {
466 466
             $pm = $transaction->payment_method();
467 467
         } else {
468 468
             $pm = null;
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
         if (empty($invoice_logo_url)) {
498 498
             return '';
499 499
         }
500
-        if (! $img_tags) {
500
+        if ( ! $img_tags) {
501 501
             return $invoice_logo_url;
502 502
         }
503 503
         //image tags have been requested.
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
         } else {
509 509
             $image_width = $image_size[0];
510 510
         }
511
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
511
+        return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />';
512 512
     }
513 513
 
514 514
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
      */
546 546
     private function _get_invoice_payment_method()
547 547
     {
548
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
548
+        if ( ! $this->_invoice_pm instanceof EE_Payment_Method) {
549 549
             $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
550 550
             $transaction = ! $transaction instanceof EE_Transaction
551 551
                            && is_array($this->_extra_data)
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
         $attrs = $this->_get_shortcode_attrs($shortcode);
614 614
         //prefix?
615 615
         $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
616
-        return $prefix . $payee_tax_number;
616
+        return $prefix.$payee_tax_number;
617 617
     }
618 618
 
619 619
 
@@ -637,16 +637,16 @@  discard block
 block discarded – undo
637 637
         }
638 638
         if (empty($payee_address)) {
639 639
             $organization = EE_Registry::instance()->CFG->organization;
640
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
640
+            $payee_address = $organization->get_pretty('address_1').'<br>';
641 641
             $payee_address .= ! empty($organization->address_2)
642
-                ? $organization->get_pretty('address_2') . '<br>'
642
+                ? $organization->get_pretty('address_2').'<br>'
643 643
                 : '';
644
-            $payee_address .= $organization->get_pretty('city') . '<br>';
644
+            $payee_address .= $organization->get_pretty('city').'<br>';
645 645
             //state
646 646
             $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
647 647
             $payee_address .= $state instanceof EE_State ? $state->name() : '';
648 648
             //Country
649
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
649
+            $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : '';
650 650
             $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
651 651
         }
652 652
         return $payee_address;
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
     {
683 683
         $reg = $this->_data->primary_reg_obj;
684 684
         $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
685
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
685
+        if ( ! $reg instanceof EE_Registration || empty($message_type)) {
686 686
             return '';
687 687
         }
688 688
         $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
             ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
691 691
         $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
692 692
         $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
693
-        if (! $button) {
693
+        if ( ! $button) {
694 694
             return $switch_to_url;
695 695
         }
696
-        if (! empty($switch_to_url)) {
696
+        if ( ! empty($switch_to_url)) {
697 697
             return '
698
-	<form method="post" action="' . $switch_to_url . '" >
699
-		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
698
+	<form method="post" action="' . $switch_to_url.'" >
699
+		<input class="print_button" type="submit" value="' . $switch_to_label.'" />
700 700
 	</form>
701 701
 			';
702 702
         }
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
     private function _get_subtotal($tax = false)
715 715
     {
716 716
         $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
717
-        if (! $grand_total instanceof EE_Line_Item) {
717
+        if ( ! $grand_total instanceof EE_Line_Item) {
718 718
             return 0;
719 719
         }
720 720
         return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
@@ -741,11 +741,11 @@  discard block
 block discarded – undo
741 741
             $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
742 742
             $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
743 743
             $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
744
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
745
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
744
+            $opening_tag = ! empty($container_tag) ? '<'.$container_tag : '';
745
+            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag;
746 746
             $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
747
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
748
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
747
+            $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : '';
748
+            $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag;
749 749
             //we need to re run this string through the parser to catch any shortcodes that are in it.
750 750
             $owing_content = $this->_shortcode_helper->parse_message_template(
751 751
                 $content,
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
         }
780 780
         $attrs = $this->_get_shortcode_attrs($shortcode);
781 781
         $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
782
-        $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
782
+        $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
783 783
         $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
784 784
             : esc_html__('Payment in full due by: ', 'event_espresso');
785 785
         $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
         try {
788 788
             if ($transaction_created instanceof DateTime) {
789 789
                 $date_due = $transaction_created->add(
790
-                    new DateInterval('P' . $days_until_due . 'D')
790
+                    new DateInterval('P'.$days_until_due.'D')
791 791
                 )->format($format);
792 792
             } else {
793 793
                 throw new Exception();
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
                 'event_espresso'
800 800
             );
801 801
         }
802
-        return $prefix_text . $date_due;
802
+        return $prefix_text.$date_due;
803 803
     }
804 804
 
805 805
 }
Please login to merge, or discard this patch.
Indentation   +776 added lines, -776 removed lines patch added patch discarded remove patch
@@ -21,785 +21,785 @@
 block discarded – undo
21 21
 class EE_Transaction_Shortcodes extends EE_Shortcodes
22 22
 {
23 23
 
24
-    /**
25
-     * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
26
-     */
27
-    protected $_invoice_pm;
28
-
29
-
30
-
31
-    protected function _init_props()
32
-    {
33
-        $this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
34
-        $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
35
-        $this->_shortcodes = array(
36
-            '[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
37
-            '[PAYMENT_URL]'                     => esc_html__(
38
-                'This is a link to make a payment for the event',
39
-                'event_espresso'
40
-            ),
41
-            '[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
42
-                'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
43
-                'event_espresso'
44
-            )
45
-               . '<ul>'
46
-               . '<li>'
47
-               . sprintf(
48
-                   esc_html__(
49
-                       '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
50
-                       'event_espresso'
51
-                   ),
52
-                   '<strong>',
53
-                   '</strong>'
54
-               )
55
-               . '</li>'
56
-               . '<li>'
57
-               . sprintf(
58
-                   esc_html__(
59
-                       '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
60
-                       'event_espresso'
61
-                   ),
62
-                   '<strong>',
63
-                   '</strong>'
64
-               )
65
-               . '</li>'
66
-               . '<li>'
67
-               . sprintf(
68
-                   esc_html__(
69
-                       '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
70
-                       'event_espresso'
71
-                   ),
72
-                   '<strong>',
73
-                   '</strong>'
74
-               )
75
-               . '</li>'
76
-               . '</ul>',
77
-            '[PAYMENT_DUE_DATE_*]'              => esc_html__(
78
-                'This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
79
-                'event_espresso'
80
-            )
81
-               . '<ul>'
82
-               . '<li>'
83
-               . sprintf(
84
-                   esc_html__(
85
-                       '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
86
-                       'event_espresso'
87
-                   ),
88
-                   '<strong>',
89
-                   '</strong>'
90
-               )
91
-               . '</li>'
92
-               . '<li>'
93
-               . sprintf(
94
-                   esc_html__(
95
-                       '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
96
-                       'event_espresso'
97
-                   ),
98
-                   '<strong>',
99
-                   '</strong>'
100
-               )
101
-               . '</li>'
102
-               . '<li>'
103
-               . sprintf(
104
-                   esc_html__(
105
-                       '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
106
-                       'event_espresso'
107
-                   ),
108
-                   '<strong>',
109
-                   '</strong>'
110
-               )
111
-               . '</li>',
112
-            '[INVOICE_LINK]'                    => esc_html__(
113
-                'This is a full html link to the invoice',
114
-                'event_espresso'
115
-            ),
116
-            '[INVOICE_URL]'                     => esc_html__(
117
-                'This is just the url for the invoice',
118
-                'event_espresso'
119
-            ),
120
-            '[INVOICE_LOGO_URL]'                => esc_html__(
121
-                'This returns the url for the logo uploaded via the invoice settings page.',
122
-                'event_espresso'
123
-            ),
124
-            '[INVOICE_LOGO]'                    => esc_html__(
125
-                'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
126
-                'event_espresso'
127
-            ),
128
-            '[INVOICE_PAYEE_NAME]'              => esc_html__(
129
-                'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
130
-                'event_espresso'
131
-            ),
132
-            '[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
133
-                'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
134
-                'event_espresso'
135
-            ),
136
-            '[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
137
-                'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
138
-                'event_espresso'
139
-            ),
140
-            '[INVOICE_PAYEE_EMAIL]'             => esc_html__(
141
-                'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
142
-                'event_espresso'
143
-            ),
144
-            '[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
145
-                esc_html__(
146
-                    'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
147
-                    'event_espresso'
148
-                ),
149
-                '<code>',
150
-                '</code>'
151
-            ),
152
-            '[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
153
-            '[TXN_STATUS]'                      => esc_html__(
154
-                'The transaction status for the transaction.',
155
-                'event_espresso'
156
-            ),
157
-            '[TXN_STATUS_ID]'                   => esc_html__(
158
-                'The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
159
-                'event_espresso'
160
-            ),
161
-            '[PAYMENT_STATUS]'                  => esc_html__(
162
-                'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
163
-                'event_espresso'
164
-            ),
165
-            '[PAYMENT_GATEWAY]'                 => esc_html__(
166
-                'The payment gateway used for the transaction',
167
-                'event_espresso'
168
-            ),
169
-            '[AMOUNT_PAID]'                     => esc_html__(
170
-                'The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
171
-                'event_espresso'
172
-            ),
173
-            '[LAST_AMOUNT_PAID]'                => esc_html__(
174
-                'This is the last payment or refund made on the transaction related to the message being generated.',
175
-                'event_espresso'
176
-            ),
177
-            '[TOTAL_AMOUNT_PAID]'               => esc_html__(
178
-                'This parses to the total amount paid over all payments',
179
-                'event_espresso'
180
-            ),
181
-            '[TOTAL_OWING]'                     => esc_html__(
182
-                'The total owing on a transaction with no attributes.',
183
-                'event_espresso'
184
-            ),
185
-            '[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
186
-            '[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
187
-            '[OWING_STATUS_MESSAGE_*]'          => esc_html__(
188
-                'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
189
-                'event_espresso'
190
-            )
191
-               . '<p></ul>'
192
-               . '<li><strong>still_owing</strong>:'
193
-               . esc_html__(
194
-                   'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
195
-                   'event_espresso'
196
-               )
197
-               . sprintf(
198
-                   esc_html__('%sPlease make a payment.%s', 'event_espresso'),
199
-                   '<a href="[PAYMENT_URL]" class="noPrint">',
200
-                   '</a>'
201
-               )
202
-               . '</li>'
203
-               .
204
-               '<li><strong>none_owing</strong>:'
205
-               . esc_html__(
206
-                   'If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
207
-                   'event_espresso'
208
-               )
209
-               . '</li></ul></p>',
210
-            '[TXN_TOTAL_TICKETS]'               => esc_html__(
211
-                'The total number of all tickets purchased in a transaction',
212
-                'event_espresso'
213
-            ),
214
-            '[TKT_QTY_PURCHASED]'               => sprintf(
215
-                esc_html__(
216
-                    'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
217
-                    'event_espresso'
218
-                ),
219
-                '<strong>',
220
-                '</strong>'
221
-            ),
222
-            '[TRANSACTION_ADMIN_URL]'           => esc_html__(
223
-                'The url to the admin page for this transaction',
224
-                'event_espresso'
225
-            ),
226
-            '[RECEIPT_URL]'                     => esc_html__(
227
-                'This parses to the generated url for retrieving the receipt for the transaction',
228
-                'event_espresso'
229
-            ),
230
-            '[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
231
-                'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
232
-                'event_espresso'
233
-            ),
234
-            '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
235
-                esc_html__(
236
-                    'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
237
-                    'event_espresso'
238
-                ),
239
-                '<code>[INVOICE_RECEIPT_SWITCHER_URL]',
240
-                '</code>'
241
-            ),
242
-            '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__(
243
-                'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.',
244
-                'event_espresso'
245
-            ),
246
-        );
247
-    }
248
-
249
-
250
-    /**
251
-     * @param  string $shortcode the shortcode to be parsed.
252
-     * @return string parsed shortcode
253
-     * @throws EE_Error
254
-     * @throws InvalidArgumentException
255
-     * @throws ReflectionException
256
-     * @throws InvalidDataTypeException
257
-     * @throws InvalidInterfaceException
258
-     */
259
-    protected function _parser($shortcode)
260
-    {
261
-        //attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
262
-        // _extra_data for the transaction.
263
-        $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
264
-        $transaction = ! $transaction instanceof EE_Transaction
265
-                       && is_array($this->_extra_data)
266
-                       && isset($this->_extra_data['data'])
267
-                       && $this->_extra_data['data'] instanceof EE_Messages_Addressee
268
-                            ? $this->_extra_data['data']->txn
269
-                            : $transaction;
270
-        //payment
271
-        $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
272
-        $payment = ! $payment instanceof EE_Payment
273
-                   && is_array($this->_extra_data)
274
-                   && isset($this->_extra_data['data'])
275
-                   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
276
-            : $payment;
277
-        if (! $transaction instanceof EE_Transaction) {
278
-            return '';
279
-        }
280
-        switch ($shortcode) {
281
-            case '[TXN_ID]':
282
-                return $transaction->ID();
283
-                break;
284
-            case '[PAYMENT_URL]':
285
-                $payment_url = $transaction->payment_overview_url();
286
-                return empty($payment_url)
287
-                    ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
288
-                    : $payment_url;
289
-                break;
290
-            case '[INVOICE_LINK]':
291
-                $invoice_url = $transaction->invoice_url();
292
-                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
293
-                return sprintf(
294
-                    esc_html__('%sClick here for Invoice%s', 'event_espresso'),
295
-                    '<a href="' . $invoice_url . '">',
296
-                    '</a>'
297
-                );
298
-                break;
299
-            case '[INVOICE_URL]':
300
-                $invoice_url = $transaction->invoice_url();
301
-                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
302
-                break;
303
-            case '[INVOICE_LOGO_URL]':
304
-                return $this->_get_invoice_logo();
305
-                break;
306
-            case '[INVOICE_LOGO]':
307
-                return $this->_get_invoice_logo(true);
308
-                break;
309
-            case '[INVOICE_PAYEE_NAME]':
310
-                return $this->_get_invoice_payee_name();
311
-                break;
312
-            case '[INVOICE_PAYEE_ADDRESS]':
313
-                return $this->_get_invoice_payee_address();
314
-                break;
315
-            case '[INVOICE_PAYMENT_INSTRUCTIONS]':
316
-                return $this->_get_invoice_payment_instructions();
317
-                break;
318
-            case '[INVOICE_PAYEE_EMAIL]':
319
-                return $this->_get_invoice_payee_email();
320
-                break;
321
-            case '[TOTAL_COST]':
322
-                $total = $transaction->total();
323
-                return ! empty($total) ? EEH_Template::format_currency($total): '';
324
-                break;
325
-            case '[PAYMENT_STATUS]':
326
-                $status = $transaction->pretty_status();
327
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
328
-                break; /**/
329
-            // note the [payment_status] shortcode is kind of misleading because payment status might be different
330
-            // from txn status so I'm adding this here for clarity.
331
-            case '[TXN_STATUS]':
332
-                $status = $transaction->pretty_status();
333
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
334
-                break;
335
-            case '[TXN_STATUS_ID]':
336
-                return $transaction->status_ID();
337
-                break;
338
-            case '[PAYMENT_GATEWAY]':
339
-                return $this->_get_payment_gateway($transaction);
340
-                break;
341
-            case '[AMOUNT_PAID]':
342
-                return $payment instanceof EE_Payment
343
-                    ? EEH_Template::format_currency($payment->amount())
344
-                    : EEH_Template::format_currency(0);
345
-                break;
346
-            case '[LAST_AMOUNT_PAID]':
347
-                $last_payment = $transaction->last_payment();
348
-                return $last_payment instanceof EE_Payment
349
-                    ? EEH_Template::format_currency($last_payment->amount())
350
-                    : EEH_Template::format_currency(0);
351
-            case '[TOTAL_AMOUNT_PAID]':
352
-                return EEH_Template::format_currency($transaction->paid());
353
-                break;
354
-            case '[TOTAL_OWING]':
355
-                $total_owing = $transaction->remaining();
356
-                return EEH_Template::format_currency($total_owing);
357
-                break;
358
-            case '[TXN_SUBTOTAL]':
359
-                return EEH_Template::format_currency($this->_get_subtotal());
360
-                break;
361
-            case '[TXN_TAX_SUBTOTAL]':
362
-                return EEH_Template::format_currency($this->_get_subtotal(true));
363
-                break;
364
-            case '[TKT_QTY_PURCHASED]':
365
-            case '[TXN_TOTAL_TICKETS]':
366
-                return $this->_data->total_ticket_count;
367
-                break;
368
-            case '[TRANSACTION_ADMIN_URL]':
369
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
370
-                $query_args = array(
371
-                    'page'   => 'espresso_transactions',
372
-                    'action' => 'view_transaction',
373
-                    'TXN_ID' => $transaction->ID(),
374
-                );
375
-                $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
376
-                return $url;
377
-                break;
378
-            case '[RECEIPT_URL]':
379
-                //get primary_registration
380
-                $reg = $this->_data->primary_reg_obj;
381
-                if (! $reg instanceof EE_Registration) {
382
-                    return '';
383
-                }
384
-                return $reg->receipt_url();
385
-                break;
386
-            case '[INVOICE_RECEIPT_SWITCHER_URL]':
387
-                return $this->_get_invoice_receipt_switcher(false);
388
-                break;
389
-            case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
390
-                return $this->_get_invoice_receipt_switcher();
391
-                break;
392
-            case '[LAST_PAYMENT_TRANSACTION_ID]':
393
-                $id = '';
394
-                $payment = $payment instanceof EE_Payment && $payment->ID() !== 0
395
-                    ? $payment
396
-                    : $transaction->last_payment();
397
-                if ($payment instanceof EE_Payment) {
398
-                    $id = $payment->txn_id_chq_nmbr();
399
-                }
400
-                return $id;
401
-                break;
402
-        }
403
-        if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
404
-            return $this->_get_custom_total_owing($shortcode);
405
-        }
406
-        if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
407
-            return $this->_get_invoice_payee_tax_number($shortcode);
408
-        }
409
-        if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
410
-            return $this->_get_payment_link_if_needed($shortcode);
411
-        }
412
-        if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
413
-            return $this->_get_payment_due_date($shortcode, $transaction);
414
-        }
415
-        return '';
416
-    }
417
-
418
-
419
-    /**
420
-     * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
421
-     *
422
-     * @since 4.5.0
423
-     * @param string $shortcode the incoming shortcode
424
-     * @return string parsed.
425
-     * @throws EE_Error
426
-     */
427
-    private function _get_custom_total_owing($shortcode)
428
-    {
429
-        $valid_shortcodes = array('transaction');
430
-        $attrs = $this->_get_shortcode_attrs($shortcode);
431
-        //ensure default is set.
432
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
433
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
434
-            ? $addressee->txn->remaining() : 0;
435
-        if ($total_owing > 0) {
436
-            $owing_content = ! empty($attrs['still_owing'])
437
-                ? $attrs['still_owing']
438
-                : sprintf(
439
-                    esc_html__('%sPlease make a payment.%s', 'event_espresso'),
440
-                    '<a href="[PAYMENT_URL]" class="noPrint">',
441
-                    '</a>'
442
-                );
443
-            $owing_content = $this->_shortcode_helper->parse_message_template(
444
-                $owing_content,
445
-                $addressee,
446
-                $valid_shortcodes,
447
-                $this->_message_type,
448
-                $this->_messenger,
449
-                $this->_message
450
-            );
451
-        } else {
452
-            $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
453
-        }
454
-        return $owing_content;
455
-    }
456
-
457
-
458
-    /**
459
-     * @param EE_Transaction $transaction
460
-     * @return string
461
-     * @throws EE_Error
462
-     */
463
-    private function _get_payment_gateway($transaction)
464
-    {
465
-        if ($transaction instanceof EE_Transaction){
466
-            $pm = $transaction->payment_method();
467
-        } else {
468
-            $pm = null;
469
-        }
470
-        return $pm instanceof EE_Payment_Method ? $pm->name() : '';
471
-    }
472
-
473
-
474
-    /**
475
-     * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
476
-     * not present then the organization logo is used if its found (set on the organization settings page).
477
-     *
478
-     * @since 4.5.0
479
-     * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
480
-     * @return string url or html
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     */
486
-    private function _get_invoice_logo($img_tags = false)
487
-    {
488
-        $invoice_logo_url = '';
489
-        //try to get the invoice payment method's logo for this transaction image first
490
-        $pm = $this->_get_invoice_payment_method();
491
-        if ($pm instanceof EE_Payment_Method) {
492
-            $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
493
-        }
494
-        if (empty($invoice_logo_url)) {
495
-            $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
496
-        }
497
-        if (empty($invoice_logo_url)) {
498
-            return '';
499
-        }
500
-        if (! $img_tags) {
501
-            return $invoice_logo_url;
502
-        }
503
-        //image tags have been requested.
504
-        $image_size = getimagesize($invoice_logo_url);
505
-        //if image is wider than 300px, set the width to 300
506
-        if ($image_size[0] > 300) {
507
-            $image_width = 300;
508
-        } else {
509
-            $image_width = $image_size[0];
510
-        }
511
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
512
-    }
513
-
514
-
515
-    /**
516
-     * Used to retrieve the appropriate content for the invoice payee name shortcode
517
-     *
518
-     * @since 4.5.0
519
-     * @return string
520
-     * @throws EE_Error
521
-     * @throws InvalidArgumentException
522
-     * @throws InvalidDataTypeException
523
-     * @throws InvalidInterfaceException
524
-     */
525
-    private function _get_invoice_payee_name()
526
-    {
527
-        $payee_name = null;
528
-        $pm = $this->_get_invoice_payment_method();
529
-        if ($pm instanceof EE_Payment_Method) {
530
-            $payee_name = $pm->get_extra_meta('pdf_payee_name', true);
531
-        }
532
-        $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
533
-        return $payee_name;
534
-    }
535
-
536
-
537
-    /**
538
-     * gets the default invoice payment method, but has a filter so it can be overridden
539
-     *
540
-     * @return EE_Payment_Method|null
541
-     * @throws EE_Error
542
-     * @throws InvalidArgumentException
543
-     * @throws InvalidDataTypeException
544
-     * @throws InvalidInterfaceException
545
-     */
546
-    private function _get_invoice_payment_method()
547
-    {
548
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
549
-            $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
550
-            $transaction = ! $transaction instanceof EE_Transaction
551
-                           && is_array($this->_extra_data)
552
-                           && isset($this->_extra_data['data'])
553
-                           && $this->_extra_data['data'] instanceof EE_Messages_Addressee
554
-                ? $this->_extra_data['data']->txn : $transaction;
555
-            //get the invoice payment method, and remember it for the next call too
556
-            $this->_invoice_pm = apply_filters(
557
-                'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
558
-                EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
559
-                $transaction
560
-            );
561
-        }
562
-        return $this->_invoice_pm;
563
-    }
564
-
565
-
566
-    /**
567
-     * Used to retrieve the appropriate content for the invoice payee email shortcode
568
-     *
569
-     * @since 4.5.0
570
-     * @return string
571
-     * @throws EE_Error
572
-     * @throws InvalidArgumentException
573
-     * @throws InvalidDataTypeException
574
-     * @throws InvalidInterfaceException
575
-     */
576
-    private function _get_invoice_payee_email()
577
-    {
578
-        $payee_email = null;
579
-        $pm = $this->_get_invoice_payment_method();
580
-        if ($pm instanceof EE_Payment_Method) {
581
-            $payee_email = $pm->get_extra_meta('pdf_payee_email', true);
582
-        }
583
-        $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
584
-            : $payee_email;
585
-        return $payee_email;
586
-    }
587
-
588
-
589
-    /**
590
-     * Used to retrieve the appropriate content for the invoice payee tax number shortcode
591
-     *
592
-     * @since 4.5.0
593
-     * @param string $shortcode
594
-     * @return string
595
-     * @throws EE_Error
596
-     * @throws InvalidArgumentException
597
-     * @throws InvalidDataTypeException
598
-     * @throws InvalidInterfaceException
599
-     */
600
-    private function _get_invoice_payee_tax_number($shortcode)
601
-    {
602
-        $payee_tax_number = null;
603
-        $pm = $this->_get_invoice_payment_method();
604
-        if ($pm instanceof EE_Payment_Method) {
605
-            $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
606
-        }
607
-        $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
608
-            : $payee_tax_number;
609
-        if (empty($payee_tax_number)) {
610
-            return '';
611
-        }
612
-        //any attributes?
613
-        $attrs = $this->_get_shortcode_attrs($shortcode);
614
-        //prefix?
615
-        $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
616
-        return $prefix . $payee_tax_number;
617
-    }
618
-
619
-
620
-    /**
621
-     * Used to retrieve the appropriate content for the invoice payee address shortcode.
622
-     *
623
-     * @since 4.5.0
624
-     * @return string
625
-     * @throws EE_Error
626
-     * @throws InvalidArgumentException
627
-     * @throws ReflectionException
628
-     * @throws InvalidDataTypeException
629
-     * @throws InvalidInterfaceException
630
-     */
631
-    private function _get_invoice_payee_address()
632
-    {
633
-        $payee_address = null;
634
-        $pm = $this->_get_invoice_payment_method();
635
-        if ($pm instanceof EE_Payment_Method) {
636
-            $payee_address = $pm->get_extra_meta('pdf_payee_address', true);
637
-        }
638
-        if (empty($payee_address)) {
639
-            $organization = EE_Registry::instance()->CFG->organization;
640
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
641
-            $payee_address .= ! empty($organization->address_2)
642
-                ? $organization->get_pretty('address_2') . '<br>'
643
-                : '';
644
-            $payee_address .= $organization->get_pretty('city') . '<br>';
645
-            //state
646
-            $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
647
-            $payee_address .= $state instanceof EE_State ? $state->name() : '';
648
-            //Country
649
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
650
-            $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
651
-        }
652
-        return $payee_address;
653
-    }
654
-
655
-
656
-    /**
657
-     * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
658
-     *
659
-     * @since 4.5.0
660
-     * @return string
661
-     * @throws EE_Error
662
-     * @throws InvalidArgumentException
663
-     * @throws InvalidDataTypeException
664
-     * @throws InvalidInterfaceException
665
-     */
666
-    private function _get_invoice_payment_instructions()
667
-    {
668
-        $instructions = null;
669
-        $pm = $this->_get_invoice_payment_method();
670
-        return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
671
-    }
672
-
673
-
674
-    /**
675
-     * get invoice/receipt switch button or url.
676
-     *
677
-     * @param bool $button true (default) returns the html for a button, false just returns the url.
678
-     * @return string
679
-     * @throws EE_Error
680
-     */
681
-    protected function _get_invoice_receipt_switcher($button = true)
682
-    {
683
-        $reg = $this->_data->primary_reg_obj;
684
-        $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
685
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
686
-            return '';
687
-        }
688
-        $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
689
-        $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
690
-            ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
691
-        $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
692
-        $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
693
-        if (! $button) {
694
-            return $switch_to_url;
695
-        }
696
-        if (! empty($switch_to_url)) {
697
-            return '
24
+	/**
25
+	 * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc
26
+	 */
27
+	protected $_invoice_pm;
28
+
29
+
30
+
31
+	protected function _init_props()
32
+	{
33
+		$this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
34
+		$this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
35
+		$this->_shortcodes = array(
36
+			'[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
37
+			'[PAYMENT_URL]'                     => esc_html__(
38
+				'This is a link to make a payment for the event',
39
+				'event_espresso'
40
+			),
41
+			'[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__(
42
+				'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
43
+				'event_espresso'
44
+			)
45
+			   . '<ul>'
46
+			   . '<li>'
47
+			   . sprintf(
48
+				   esc_html__(
49
+					   '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
50
+					   'event_espresso'
51
+				   ),
52
+				   '<strong>',
53
+				   '</strong>'
54
+			   )
55
+			   . '</li>'
56
+			   . '<li>'
57
+			   . sprintf(
58
+				   esc_html__(
59
+					   '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
60
+					   'event_espresso'
61
+				   ),
62
+				   '<strong>',
63
+				   '</strong>'
64
+			   )
65
+			   . '</li>'
66
+			   . '<li>'
67
+			   . sprintf(
68
+				   esc_html__(
69
+					   '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
70
+					   'event_espresso'
71
+				   ),
72
+				   '<strong>',
73
+				   '</strong>'
74
+			   )
75
+			   . '</li>'
76
+			   . '</ul>',
77
+			'[PAYMENT_DUE_DATE_*]'              => esc_html__(
78
+				'This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
79
+				'event_espresso'
80
+			)
81
+			   . '<ul>'
82
+			   . '<li>'
83
+			   . sprintf(
84
+				   esc_html__(
85
+					   '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
86
+					   'event_espresso'
87
+				   ),
88
+				   '<strong>',
89
+				   '</strong>'
90
+			   )
91
+			   . '</li>'
92
+			   . '<li>'
93
+			   . sprintf(
94
+				   esc_html__(
95
+					   '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
96
+					   'event_espresso'
97
+				   ),
98
+				   '<strong>',
99
+				   '</strong>'
100
+			   )
101
+			   . '</li>'
102
+			   . '<li>'
103
+			   . sprintf(
104
+				   esc_html__(
105
+					   '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
106
+					   'event_espresso'
107
+				   ),
108
+				   '<strong>',
109
+				   '</strong>'
110
+			   )
111
+			   . '</li>',
112
+			'[INVOICE_LINK]'                    => esc_html__(
113
+				'This is a full html link to the invoice',
114
+				'event_espresso'
115
+			),
116
+			'[INVOICE_URL]'                     => esc_html__(
117
+				'This is just the url for the invoice',
118
+				'event_espresso'
119
+			),
120
+			'[INVOICE_LOGO_URL]'                => esc_html__(
121
+				'This returns the url for the logo uploaded via the invoice settings page.',
122
+				'event_espresso'
123
+			),
124
+			'[INVOICE_LOGO]'                    => esc_html__(
125
+				'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
126
+				'event_espresso'
127
+			),
128
+			'[INVOICE_PAYEE_NAME]'              => esc_html__(
129
+				'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
130
+				'event_espresso'
131
+			),
132
+			'[INVOICE_PAYEE_ADDRESS]'           => esc_html__(
133
+				'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
134
+				'event_espresso'
135
+			),
136
+			'[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__(
137
+				'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
138
+				'event_espresso'
139
+			),
140
+			'[INVOICE_PAYEE_EMAIL]'             => esc_html__(
141
+				'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
142
+				'event_espresso'
143
+			),
144
+			'[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(
145
+				esc_html__(
146
+					'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
147
+					'event_espresso'
148
+				),
149
+				'<code>',
150
+				'</code>'
151
+			),
152
+			'[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
153
+			'[TXN_STATUS]'                      => esc_html__(
154
+				'The transaction status for the transaction.',
155
+				'event_espresso'
156
+			),
157
+			'[TXN_STATUS_ID]'                   => esc_html__(
158
+				'The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
159
+				'event_espresso'
160
+			),
161
+			'[PAYMENT_STATUS]'                  => esc_html__(
162
+				'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
163
+				'event_espresso'
164
+			),
165
+			'[PAYMENT_GATEWAY]'                 => esc_html__(
166
+				'The payment gateway used for the transaction',
167
+				'event_espresso'
168
+			),
169
+			'[AMOUNT_PAID]'                     => esc_html__(
170
+				'The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
171
+				'event_espresso'
172
+			),
173
+			'[LAST_AMOUNT_PAID]'                => esc_html__(
174
+				'This is the last payment or refund made on the transaction related to the message being generated.',
175
+				'event_espresso'
176
+			),
177
+			'[TOTAL_AMOUNT_PAID]'               => esc_html__(
178
+				'This parses to the total amount paid over all payments',
179
+				'event_espresso'
180
+			),
181
+			'[TOTAL_OWING]'                     => esc_html__(
182
+				'The total owing on a transaction with no attributes.',
183
+				'event_espresso'
184
+			),
185
+			'[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
186
+			'[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
187
+			'[OWING_STATUS_MESSAGE_*]'          => esc_html__(
188
+				'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
189
+				'event_espresso'
190
+			)
191
+			   . '<p></ul>'
192
+			   . '<li><strong>still_owing</strong>:'
193
+			   . esc_html__(
194
+				   'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
195
+				   'event_espresso'
196
+			   )
197
+			   . sprintf(
198
+				   esc_html__('%sPlease make a payment.%s', 'event_espresso'),
199
+				   '<a href="[PAYMENT_URL]" class="noPrint">',
200
+				   '</a>'
201
+			   )
202
+			   . '</li>'
203
+			   .
204
+			   '<li><strong>none_owing</strong>:'
205
+			   . esc_html__(
206
+				   'If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
207
+				   'event_espresso'
208
+			   )
209
+			   . '</li></ul></p>',
210
+			'[TXN_TOTAL_TICKETS]'               => esc_html__(
211
+				'The total number of all tickets purchased in a transaction',
212
+				'event_espresso'
213
+			),
214
+			'[TKT_QTY_PURCHASED]'               => sprintf(
215
+				esc_html__(
216
+					'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
217
+					'event_espresso'
218
+				),
219
+				'<strong>',
220
+				'</strong>'
221
+			),
222
+			'[TRANSACTION_ADMIN_URL]'           => esc_html__(
223
+				'The url to the admin page for this transaction',
224
+				'event_espresso'
225
+			),
226
+			'[RECEIPT_URL]'                     => esc_html__(
227
+				'This parses to the generated url for retrieving the receipt for the transaction',
228
+				'event_espresso'
229
+			),
230
+			'[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__(
231
+				'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
232
+				'event_espresso'
233
+			),
234
+			'[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(
235
+				esc_html__(
236
+					'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.',
237
+					'event_espresso'
238
+				),
239
+				'<code>[INVOICE_RECEIPT_SWITCHER_URL]',
240
+				'</code>'
241
+			),
242
+			'[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__(
243
+				'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.',
244
+				'event_espresso'
245
+			),
246
+		);
247
+	}
248
+
249
+
250
+	/**
251
+	 * @param  string $shortcode the shortcode to be parsed.
252
+	 * @return string parsed shortcode
253
+	 * @throws EE_Error
254
+	 * @throws InvalidArgumentException
255
+	 * @throws ReflectionException
256
+	 * @throws InvalidDataTypeException
257
+	 * @throws InvalidInterfaceException
258
+	 */
259
+	protected function _parser($shortcode)
260
+	{
261
+		//attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the
262
+		// _extra_data for the transaction.
263
+		$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
264
+		$transaction = ! $transaction instanceof EE_Transaction
265
+					   && is_array($this->_extra_data)
266
+					   && isset($this->_extra_data['data'])
267
+					   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
268
+							? $this->_extra_data['data']->txn
269
+							: $transaction;
270
+		//payment
271
+		$payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
272
+		$payment = ! $payment instanceof EE_Payment
273
+				   && is_array($this->_extra_data)
274
+				   && isset($this->_extra_data['data'])
275
+				   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
276
+			: $payment;
277
+		if (! $transaction instanceof EE_Transaction) {
278
+			return '';
279
+		}
280
+		switch ($shortcode) {
281
+			case '[TXN_ID]':
282
+				return $transaction->ID();
283
+				break;
284
+			case '[PAYMENT_URL]':
285
+				$payment_url = $transaction->payment_overview_url();
286
+				return empty($payment_url)
287
+					? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
288
+					: $payment_url;
289
+				break;
290
+			case '[INVOICE_LINK]':
291
+				$invoice_url = $transaction->invoice_url();
292
+				$invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
293
+				return sprintf(
294
+					esc_html__('%sClick here for Invoice%s', 'event_espresso'),
295
+					'<a href="' . $invoice_url . '">',
296
+					'</a>'
297
+				);
298
+				break;
299
+			case '[INVOICE_URL]':
300
+				$invoice_url = $transaction->invoice_url();
301
+				return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url;
302
+				break;
303
+			case '[INVOICE_LOGO_URL]':
304
+				return $this->_get_invoice_logo();
305
+				break;
306
+			case '[INVOICE_LOGO]':
307
+				return $this->_get_invoice_logo(true);
308
+				break;
309
+			case '[INVOICE_PAYEE_NAME]':
310
+				return $this->_get_invoice_payee_name();
311
+				break;
312
+			case '[INVOICE_PAYEE_ADDRESS]':
313
+				return $this->_get_invoice_payee_address();
314
+				break;
315
+			case '[INVOICE_PAYMENT_INSTRUCTIONS]':
316
+				return $this->_get_invoice_payment_instructions();
317
+				break;
318
+			case '[INVOICE_PAYEE_EMAIL]':
319
+				return $this->_get_invoice_payee_email();
320
+				break;
321
+			case '[TOTAL_COST]':
322
+				$total = $transaction->total();
323
+				return ! empty($total) ? EEH_Template::format_currency($total): '';
324
+				break;
325
+			case '[PAYMENT_STATUS]':
326
+				$status = $transaction->pretty_status();
327
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
328
+				break; /**/
329
+			// note the [payment_status] shortcode is kind of misleading because payment status might be different
330
+			// from txn status so I'm adding this here for clarity.
331
+			case '[TXN_STATUS]':
332
+				$status = $transaction->pretty_status();
333
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
334
+				break;
335
+			case '[TXN_STATUS_ID]':
336
+				return $transaction->status_ID();
337
+				break;
338
+			case '[PAYMENT_GATEWAY]':
339
+				return $this->_get_payment_gateway($transaction);
340
+				break;
341
+			case '[AMOUNT_PAID]':
342
+				return $payment instanceof EE_Payment
343
+					? EEH_Template::format_currency($payment->amount())
344
+					: EEH_Template::format_currency(0);
345
+				break;
346
+			case '[LAST_AMOUNT_PAID]':
347
+				$last_payment = $transaction->last_payment();
348
+				return $last_payment instanceof EE_Payment
349
+					? EEH_Template::format_currency($last_payment->amount())
350
+					: EEH_Template::format_currency(0);
351
+			case '[TOTAL_AMOUNT_PAID]':
352
+				return EEH_Template::format_currency($transaction->paid());
353
+				break;
354
+			case '[TOTAL_OWING]':
355
+				$total_owing = $transaction->remaining();
356
+				return EEH_Template::format_currency($total_owing);
357
+				break;
358
+			case '[TXN_SUBTOTAL]':
359
+				return EEH_Template::format_currency($this->_get_subtotal());
360
+				break;
361
+			case '[TXN_TAX_SUBTOTAL]':
362
+				return EEH_Template::format_currency($this->_get_subtotal(true));
363
+				break;
364
+			case '[TKT_QTY_PURCHASED]':
365
+			case '[TXN_TOTAL_TICKETS]':
366
+				return $this->_data->total_ticket_count;
367
+				break;
368
+			case '[TRANSACTION_ADMIN_URL]':
369
+				require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
370
+				$query_args = array(
371
+					'page'   => 'espresso_transactions',
372
+					'action' => 'view_transaction',
373
+					'TXN_ID' => $transaction->ID(),
374
+				);
375
+				$url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
376
+				return $url;
377
+				break;
378
+			case '[RECEIPT_URL]':
379
+				//get primary_registration
380
+				$reg = $this->_data->primary_reg_obj;
381
+				if (! $reg instanceof EE_Registration) {
382
+					return '';
383
+				}
384
+				return $reg->receipt_url();
385
+				break;
386
+			case '[INVOICE_RECEIPT_SWITCHER_URL]':
387
+				return $this->_get_invoice_receipt_switcher(false);
388
+				break;
389
+			case '[INVOICE_RECEIPT_SWITCHER_BUTTON]':
390
+				return $this->_get_invoice_receipt_switcher();
391
+				break;
392
+			case '[LAST_PAYMENT_TRANSACTION_ID]':
393
+				$id = '';
394
+				$payment = $payment instanceof EE_Payment && $payment->ID() !== 0
395
+					? $payment
396
+					: $transaction->last_payment();
397
+				if ($payment instanceof EE_Payment) {
398
+					$id = $payment->txn_id_chq_nmbr();
399
+				}
400
+				return $id;
401
+				break;
402
+		}
403
+		if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
404
+			return $this->_get_custom_total_owing($shortcode);
405
+		}
406
+		if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
407
+			return $this->_get_invoice_payee_tax_number($shortcode);
408
+		}
409
+		if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
410
+			return $this->_get_payment_link_if_needed($shortcode);
411
+		}
412
+		if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
413
+			return $this->_get_payment_due_date($shortcode, $transaction);
414
+		}
415
+		return '';
416
+	}
417
+
418
+
419
+	/**
420
+	 * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
421
+	 *
422
+	 * @since 4.5.0
423
+	 * @param string $shortcode the incoming shortcode
424
+	 * @return string parsed.
425
+	 * @throws EE_Error
426
+	 */
427
+	private function _get_custom_total_owing($shortcode)
428
+	{
429
+		$valid_shortcodes = array('transaction');
430
+		$attrs = $this->_get_shortcode_attrs($shortcode);
431
+		//ensure default is set.
432
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
433
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
434
+			? $addressee->txn->remaining() : 0;
435
+		if ($total_owing > 0) {
436
+			$owing_content = ! empty($attrs['still_owing'])
437
+				? $attrs['still_owing']
438
+				: sprintf(
439
+					esc_html__('%sPlease make a payment.%s', 'event_espresso'),
440
+					'<a href="[PAYMENT_URL]" class="noPrint">',
441
+					'</a>'
442
+				);
443
+			$owing_content = $this->_shortcode_helper->parse_message_template(
444
+				$owing_content,
445
+				$addressee,
446
+				$valid_shortcodes,
447
+				$this->_message_type,
448
+				$this->_messenger,
449
+				$this->_message
450
+			);
451
+		} else {
452
+			$owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
453
+		}
454
+		return $owing_content;
455
+	}
456
+
457
+
458
+	/**
459
+	 * @param EE_Transaction $transaction
460
+	 * @return string
461
+	 * @throws EE_Error
462
+	 */
463
+	private function _get_payment_gateway($transaction)
464
+	{
465
+		if ($transaction instanceof EE_Transaction){
466
+			$pm = $transaction->payment_method();
467
+		} else {
468
+			$pm = null;
469
+		}
470
+		return $pm instanceof EE_Payment_Method ? $pm->name() : '';
471
+	}
472
+
473
+
474
+	/**
475
+	 * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
476
+	 * not present then the organization logo is used if its found (set on the organization settings page).
477
+	 *
478
+	 * @since 4.5.0
479
+	 * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
480
+	 * @return string url or html
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 */
486
+	private function _get_invoice_logo($img_tags = false)
487
+	{
488
+		$invoice_logo_url = '';
489
+		//try to get the invoice payment method's logo for this transaction image first
490
+		$pm = $this->_get_invoice_payment_method();
491
+		if ($pm instanceof EE_Payment_Method) {
492
+			$invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
493
+		}
494
+		if (empty($invoice_logo_url)) {
495
+			$invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
496
+		}
497
+		if (empty($invoice_logo_url)) {
498
+			return '';
499
+		}
500
+		if (! $img_tags) {
501
+			return $invoice_logo_url;
502
+		}
503
+		//image tags have been requested.
504
+		$image_size = getimagesize($invoice_logo_url);
505
+		//if image is wider than 300px, set the width to 300
506
+		if ($image_size[0] > 300) {
507
+			$image_width = 300;
508
+		} else {
509
+			$image_width = $image_size[0];
510
+		}
511
+		return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
512
+	}
513
+
514
+
515
+	/**
516
+	 * Used to retrieve the appropriate content for the invoice payee name shortcode
517
+	 *
518
+	 * @since 4.5.0
519
+	 * @return string
520
+	 * @throws EE_Error
521
+	 * @throws InvalidArgumentException
522
+	 * @throws InvalidDataTypeException
523
+	 * @throws InvalidInterfaceException
524
+	 */
525
+	private function _get_invoice_payee_name()
526
+	{
527
+		$payee_name = null;
528
+		$pm = $this->_get_invoice_payment_method();
529
+		if ($pm instanceof EE_Payment_Method) {
530
+			$payee_name = $pm->get_extra_meta('pdf_payee_name', true);
531
+		}
532
+		$payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
533
+		return $payee_name;
534
+	}
535
+
536
+
537
+	/**
538
+	 * gets the default invoice payment method, but has a filter so it can be overridden
539
+	 *
540
+	 * @return EE_Payment_Method|null
541
+	 * @throws EE_Error
542
+	 * @throws InvalidArgumentException
543
+	 * @throws InvalidDataTypeException
544
+	 * @throws InvalidInterfaceException
545
+	 */
546
+	private function _get_invoice_payment_method()
547
+	{
548
+		if (! $this->_invoice_pm instanceof EE_Payment_Method) {
549
+			$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
550
+			$transaction = ! $transaction instanceof EE_Transaction
551
+						   && is_array($this->_extra_data)
552
+						   && isset($this->_extra_data['data'])
553
+						   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
554
+				? $this->_extra_data['data']->txn : $transaction;
555
+			//get the invoice payment method, and remember it for the next call too
556
+			$this->_invoice_pm = apply_filters(
557
+				'FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
558
+				EEM_Payment_Method::instance()->get_one_of_type('Invoice'),
559
+				$transaction
560
+			);
561
+		}
562
+		return $this->_invoice_pm;
563
+	}
564
+
565
+
566
+	/**
567
+	 * Used to retrieve the appropriate content for the invoice payee email shortcode
568
+	 *
569
+	 * @since 4.5.0
570
+	 * @return string
571
+	 * @throws EE_Error
572
+	 * @throws InvalidArgumentException
573
+	 * @throws InvalidDataTypeException
574
+	 * @throws InvalidInterfaceException
575
+	 */
576
+	private function _get_invoice_payee_email()
577
+	{
578
+		$payee_email = null;
579
+		$pm = $this->_get_invoice_payment_method();
580
+		if ($pm instanceof EE_Payment_Method) {
581
+			$payee_email = $pm->get_extra_meta('pdf_payee_email', true);
582
+		}
583
+		$payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
584
+			: $payee_email;
585
+		return $payee_email;
586
+	}
587
+
588
+
589
+	/**
590
+	 * Used to retrieve the appropriate content for the invoice payee tax number shortcode
591
+	 *
592
+	 * @since 4.5.0
593
+	 * @param string $shortcode
594
+	 * @return string
595
+	 * @throws EE_Error
596
+	 * @throws InvalidArgumentException
597
+	 * @throws InvalidDataTypeException
598
+	 * @throws InvalidInterfaceException
599
+	 */
600
+	private function _get_invoice_payee_tax_number($shortcode)
601
+	{
602
+		$payee_tax_number = null;
603
+		$pm = $this->_get_invoice_payment_method();
604
+		if ($pm instanceof EE_Payment_Method) {
605
+			$payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
606
+		}
607
+		$payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
608
+			: $payee_tax_number;
609
+		if (empty($payee_tax_number)) {
610
+			return '';
611
+		}
612
+		//any attributes?
613
+		$attrs = $this->_get_shortcode_attrs($shortcode);
614
+		//prefix?
615
+		$prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
616
+		return $prefix . $payee_tax_number;
617
+	}
618
+
619
+
620
+	/**
621
+	 * Used to retrieve the appropriate content for the invoice payee address shortcode.
622
+	 *
623
+	 * @since 4.5.0
624
+	 * @return string
625
+	 * @throws EE_Error
626
+	 * @throws InvalidArgumentException
627
+	 * @throws ReflectionException
628
+	 * @throws InvalidDataTypeException
629
+	 * @throws InvalidInterfaceException
630
+	 */
631
+	private function _get_invoice_payee_address()
632
+	{
633
+		$payee_address = null;
634
+		$pm = $this->_get_invoice_payment_method();
635
+		if ($pm instanceof EE_Payment_Method) {
636
+			$payee_address = $pm->get_extra_meta('pdf_payee_address', true);
637
+		}
638
+		if (empty($payee_address)) {
639
+			$organization = EE_Registry::instance()->CFG->organization;
640
+			$payee_address = $organization->get_pretty('address_1') . '<br>';
641
+			$payee_address .= ! empty($organization->address_2)
642
+				? $organization->get_pretty('address_2') . '<br>'
643
+				: '';
644
+			$payee_address .= $organization->get_pretty('city') . '<br>';
645
+			//state
646
+			$state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
647
+			$payee_address .= $state instanceof EE_State ? $state->name() : '';
648
+			//Country
649
+			$payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
650
+			$payee_address .= ! empty($organization->zip) ? $organization->zip : '';
651
+		}
652
+		return $payee_address;
653
+	}
654
+
655
+
656
+	/**
657
+	 * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
658
+	 *
659
+	 * @since 4.5.0
660
+	 * @return string
661
+	 * @throws EE_Error
662
+	 * @throws InvalidArgumentException
663
+	 * @throws InvalidDataTypeException
664
+	 * @throws InvalidInterfaceException
665
+	 */
666
+	private function _get_invoice_payment_instructions()
667
+	{
668
+		$instructions = null;
669
+		$pm = $this->_get_invoice_payment_method();
670
+		return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
671
+	}
672
+
673
+
674
+	/**
675
+	 * get invoice/receipt switch button or url.
676
+	 *
677
+	 * @param bool $button true (default) returns the html for a button, false just returns the url.
678
+	 * @return string
679
+	 * @throws EE_Error
680
+	 */
681
+	protected function _get_invoice_receipt_switcher($button = true)
682
+	{
683
+		$reg = $this->_data->primary_reg_obj;
684
+		$message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
685
+		if (! $reg instanceof EE_Registration || empty($message_type)) {
686
+			return '';
687
+		}
688
+		$switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
689
+		$switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
690
+			? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
691
+		$switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
692
+		$switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
693
+		if (! $button) {
694
+			return $switch_to_url;
695
+		}
696
+		if (! empty($switch_to_url)) {
697
+			return '
698 698
 	<form method="post" action="' . $switch_to_url . '" >
699 699
 		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
700 700
 	</form>
701 701
 			';
702
-        }
703
-        return '';
704
-    }
705
-
706
-
707
-    /**
708
-     * This returns a subtotal.
709
-     *
710
-     * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
711
-     * @return int
712
-     * @throws EE_Error
713
-     */
714
-    private function _get_subtotal($tax = false)
715
-    {
716
-        $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
717
-        if (! $grand_total instanceof EE_Line_Item) {
718
-            return 0;
719
-        }
720
-        return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
721
-    }
722
-
723
-
724
-    /**
725
-     * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
726
-     *
727
-     * @since 4.7.0
728
-     * @param string $shortcode the incoming shortcode
729
-     * @return string parsed.
730
-     * @throws EE_Error
731
-     */
732
-    private function _get_payment_link_if_needed($shortcode)
733
-    {
734
-        $valid_shortcodes = array('transaction');
735
-        $attrs = $this->_get_shortcode_attrs($shortcode);
736
-        //ensure default is set.
737
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
738
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
739
-            ? $addressee->txn->remaining() : 0;
740
-        if ($total_owing > 0) {
741
-            $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
742
-            $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
743
-            $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
744
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
745
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
746
-            $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
747
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
748
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
749
-            //we need to re run this string through the parser to catch any shortcodes that are in it.
750
-            $owing_content = $this->_shortcode_helper->parse_message_template(
751
-                $content,
752
-                $addressee,
753
-                $valid_shortcodes,
754
-                $this->_message_type,
755
-                $this->_messenger,
756
-                $this->_message
757
-            );
758
-        } else {
759
-            return '';
760
-        }
761
-        return $owing_content;
762
-    }
763
-
764
-
765
-    /**
766
-     * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
767
-     *
768
-     * @since 4.8.28.rc.011
769
-     * @param string         $shortcode The shortcode being parsed.
770
-     * @param EE_Transaction $transaction
771
-     * @return string
772
-     * @throws EE_Error
773
-     */
774
-    protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
775
-    {
776
-        //if transaction is paid in full then we can just return an empty string
777
-        if ($transaction->remaining() === 0) {
778
-            return '';
779
-        }
780
-        $attrs = $this->_get_shortcode_attrs($shortcode);
781
-        $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
782
-        $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
783
-        $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
784
-            : esc_html__('Payment in full due by: ', 'event_espresso');
785
-        $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
786
-        //setup date due:
787
-        try {
788
-            if ($transaction_created instanceof DateTime) {
789
-                $date_due = $transaction_created->add(
790
-                    new DateInterval('P' . $days_until_due . 'D')
791
-                )->format($format);
792
-            } else {
793
-                throw new Exception();
794
-            }
795
-        } catch (Exception $e) {
796
-            //format was likely invalid.
797
-            $date_due = esc_html__(
798
-                'Unable to calculate date due, likely the format string is invalid.',
799
-                'event_espresso'
800
-            );
801
-        }
802
-        return $prefix_text . $date_due;
803
-    }
702
+		}
703
+		return '';
704
+	}
705
+
706
+
707
+	/**
708
+	 * This returns a subtotal.
709
+	 *
710
+	 * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
711
+	 * @return int
712
+	 * @throws EE_Error
713
+	 */
714
+	private function _get_subtotal($tax = false)
715
+	{
716
+		$grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
717
+		if (! $grand_total instanceof EE_Line_Item) {
718
+			return 0;
719
+		}
720
+		return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
721
+	}
722
+
723
+
724
+	/**
725
+	 * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
726
+	 *
727
+	 * @since 4.7.0
728
+	 * @param string $shortcode the incoming shortcode
729
+	 * @return string parsed.
730
+	 * @throws EE_Error
731
+	 */
732
+	private function _get_payment_link_if_needed($shortcode)
733
+	{
734
+		$valid_shortcodes = array('transaction');
735
+		$attrs = $this->_get_shortcode_attrs($shortcode);
736
+		//ensure default is set.
737
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
738
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
739
+			? $addressee->txn->remaining() : 0;
740
+		if ($total_owing > 0) {
741
+			$class = isset($attrs['class']) ? $attrs['class'] : 'callout';
742
+			$custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
743
+			$container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
744
+			$opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
745
+			$opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
746
+			$opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
747
+			$closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
748
+			$content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
749
+			//we need to re run this string through the parser to catch any shortcodes that are in it.
750
+			$owing_content = $this->_shortcode_helper->parse_message_template(
751
+				$content,
752
+				$addressee,
753
+				$valid_shortcodes,
754
+				$this->_message_type,
755
+				$this->_messenger,
756
+				$this->_message
757
+			);
758
+		} else {
759
+			return '';
760
+		}
761
+		return $owing_content;
762
+	}
763
+
764
+
765
+	/**
766
+	 * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
767
+	 *
768
+	 * @since 4.8.28.rc.011
769
+	 * @param string         $shortcode The shortcode being parsed.
770
+	 * @param EE_Transaction $transaction
771
+	 * @return string
772
+	 * @throws EE_Error
773
+	 */
774
+	protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
775
+	{
776
+		//if transaction is paid in full then we can just return an empty string
777
+		if ($transaction->remaining() === 0) {
778
+			return '';
779
+		}
780
+		$attrs = $this->_get_shortcode_attrs($shortcode);
781
+		$format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
782
+		$days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
783
+		$prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
784
+			: esc_html__('Payment in full due by: ', 'event_espresso');
785
+		$transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
786
+		//setup date due:
787
+		try {
788
+			if ($transaction_created instanceof DateTime) {
789
+				$date_due = $transaction_created->add(
790
+					new DateInterval('P' . $days_until_due . 'D')
791
+				)->format($format);
792
+			} else {
793
+				throw new Exception();
794
+			}
795
+		} catch (Exception $e) {
796
+			//format was likely invalid.
797
+			$date_due = esc_html__(
798
+				'Unable to calculate date due, likely the format string is invalid.',
799
+				'event_espresso'
800
+			);
801
+		}
802
+		return $prefix_text . $date_due;
803
+	}
804 804
 
805 805
 }
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 block discarded – undo
20 20
      * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21 21
      * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22 22
      * @param $string
23
-     * @param $start
24
-     * @param $length
23
+     * @param integer $start
24
+     * @param integer $length
25 25
      * @return bool|string
26 26
      */
27 27
     function mb_strcut($string, $start, $length = null)
Please login to merge, or discard this patch.
Indentation   +599 added lines, -599 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,608 +16,608 @@  discard block
 block discarded – undo
16 16
  */
17 17
 //Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
18 18
 if (! function_exists('mb_strcut')) {
19
-    /**
20
-     * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21
-     * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22
-     * @param $string
23
-     * @param $start
24
-     * @param $length
25
-     * @return bool|string
26
-     */
27
-    function mb_strcut($string, $start, $length = null)
28
-    {
29
-        return mb_substr($string, $start, $length);
30
-    }
19
+	/**
20
+	 * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21
+	 * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22
+	 * @param $string
23
+	 * @param $start
24
+	 * @param $length
25
+	 * @return bool|string
26
+	 */
27
+	function mb_strcut($string, $start, $length = null)
28
+	{
29
+		return mb_substr($string, $start, $length);
30
+	}
31 31
 }
32 32
 class EEG_Paypal_Express extends EE_Offsite_Gateway
33 33
 {
34 34
 
35
-    /**
36
-     * Merchant API Username.
37
-     *
38
-     * @var string
39
-     */
40
-    protected $_api_username;
41
-
42
-    /**
43
-     * Merchant API Password.
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_api_password;
48
-
49
-    /**
50
-     * API Signature.
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_api_signature;
55
-
56
-    /**
57
-     * Request Shipping address on PP checkout page.
58
-     *
59
-     * @var string
60
-     */
61
-    protected $_request_shipping_addr;
62
-
63
-    /**
64
-     * Business/personal logo.
65
-     *
66
-     * @var string
67
-     */
68
-    protected $_image_url;
69
-
70
-    /**
71
-     * gateway URL variable
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_base_gateway_url = '';
76
-
77
-
78
-
79
-    /**
80
-     * EEG_Paypal_Express constructor.
81
-     */
82
-    public function __construct()
83
-    {
84
-        $this->_currencies_supported = array(
85
-            'USD',
86
-            'AUD',
87
-            'BRL',
88
-            'CAD',
89
-            'CZK',
90
-            'DKK',
91
-            'EUR',
92
-            'HKD',
93
-            'HUF',
94
-            'ILS',
95
-            'JPY',
96
-            'MYR',
97
-            'MXN',
98
-            'NOK',
99
-            'NZD',
100
-            'PHP',
101
-            'PLN',
102
-            'GBP',
103
-            'RUB',
104
-            'SGD',
105
-            'SEK',
106
-            'CHF',
107
-            'TWD',
108
-            'THB',
109
-            'TRY',
110
-        );
111
-        parent::__construct();
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * Sets the gateway URL variable based on whether debug mode is enabled or not.
118
-     *
119
-     * @param array $settings_array
120
-     */
121
-    public function set_settings($settings_array)
122
-    {
123
-        parent::set_settings($settings_array);
124
-        // Redirect URL.
125
-        $this->_base_gateway_url = $this->_debug_mode
126
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
127
-            : 'https://api-3t.paypal.com/nvp';
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @param EEI_Payment $payment
134
-     * @param array       $billing_info
135
-     * @param string      $return_url
136
-     * @param string      $notify_url
137
-     * @param string      $cancel_url
138
-     * @return \EE_Payment|\EEI_Payment
139
-     * @throws \EE_Error
140
-     */
141
-    public function set_redirection_info(
142
-        $payment,
143
-        $billing_info = array(),
144
-        $return_url = null,
145
-        $notify_url = null,
146
-        $cancel_url = null
147
-    ) {
148
-        if (! $payment instanceof EEI_Payment) {
149
-            $payment->set_gateway_response(
150
-                esc_html__(
151
-                    'Error. No associated payment was found.',
152
-                    'event_espresso'
153
-                )
154
-            );
155
-            $payment->set_status($this->_pay_model->failed_status());
156
-            return $payment;
157
-        }
158
-        $transaction = $payment->transaction();
159
-        if (! $transaction instanceof EEI_Transaction) {
160
-            $payment->set_gateway_response(
161
-                esc_html__(
162
-                    'Could not process this payment because it has no associated transaction.',
163
-                    'event_espresso'
164
-                )
165
-            );
166
-            $payment->set_status($this->_pay_model->failed_status());
167
-            return $payment;
168
-        }
169
-        $order_description = mb_strcut($this->_format_order_description($payment), 0, 127);
170
-        $primary_registration = $transaction->primary_registration();
171
-        $primary_attendee = $primary_registration instanceof EE_Registration
172
-            ? $primary_registration->attendee()
173
-            : false;
174
-        $locale = explode('-', get_bloginfo('language'));
175
-        // Gather request parameters.
176
-        $token_request_dtls = array(
177
-            'METHOD'                         => 'SetExpressCheckout',
178
-            'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
179
-            'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
180
-            'PAYMENTREQUEST_0_DESC'          => $order_description,
181
-            'RETURNURL'                      => $return_url,
182
-            'CANCELURL'                      => $cancel_url,
183
-            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
184
-            // Buyer does not need to create a PayPal account to check out.
185
-            // This is referred to as PayPal Account Optional.
186
-            'SOLUTIONTYPE'                   => 'Sole',
187
-            //EE will blow up if you change this
188
-            'BUTTONSOURCE'                   => 'EventEspresso_SP',
189
-            // Locale of the pages displayed by PayPal during Express Checkout.
190
-            'LOCALECODE'                     => $locale[1]
191
-        );
192
-        // Show itemized list.
193
-        if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
194
-            $item_num = 0;
195
-            $itemized_sum = 0;
196
-            $total_line_items = $transaction->total_line_item();
197
-            // Go through each item in the list.
198
-            foreach ($total_line_items->get_items() as $line_item) {
199
-                if ($line_item instanceof EE_Line_Item) {
200
-                    // PayPal doesn't like line items with 0.00 amount, so we may skip those.
201
-                    if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
202
-                        continue;
203
-                    }
204
-                    $unit_price = $line_item->unit_price();
205
-                    $line_item_quantity = $line_item->quantity();
206
-                    // This is a discount.
207
-                    if ($line_item->is_percent()) {
208
-                        $unit_price = $line_item->total();
209
-                        $line_item_quantity = 1;
210
-                    }
211
-                    // Item Name.
212
-                    $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
213
-                        $this->_format_line_item_name($line_item, $payment),
214
-                        0,
215
-                        127
216
-                    );
217
-                    // Item description.
218
-                    $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
219
-                        $this->_format_line_item_desc($line_item, $payment),
220
-                        0,
221
-                        127
222
-                    );
223
-                    // Cost of individual item.
224
-                    $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price);
225
-                    // Item Number.
226
-                    $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
227
-                    // Item quantity.
228
-                    $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
229
-                    // Digital item is sold.
230
-                    $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
231
-                    $itemized_sum += $line_item->total();
232
-                    ++$item_num;
233
-                }
234
-            }
235
-            // Item's sales S/H and tax amount.
236
-            $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
237
-            $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
238
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
239
-            $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
240
-            $itemized_sum_diff_from_txn_total = round(
241
-                $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
242
-                2
243
-            );
244
-            // If we were not able to recognize some item like promotion, surcharge or cancellation,
245
-            // add the difference as an extra line item.
246
-            if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
247
-                // Item Name.
248
-                $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
249
-                    esc_html__(
250
-                        'Other (promotion/surcharge/cancellation)',
251
-                        'event_espresso'
252
-                    ),
253
-                    0,
254
-                    127
255
-                );
256
-                // Item description.
257
-                $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
258
-                // Cost of individual item.
259
-                $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency(
260
-                    $itemized_sum_diff_from_txn_total
261
-                );
262
-                // Item Number.
263
-                $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
264
-                // Item quantity.
265
-                $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
266
-                // Digital item is sold.
267
-                $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
268
-                $item_num++;
269
-            }
270
-        } else {
271
-            // Just one Item.
272
-            // Item Name.
273
-            $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
274
-                $this->_format_partial_payment_line_item_name($payment),
275
-                0,
276
-                127
277
-            );
278
-            // Item description.
279
-            $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
280
-                $this->_format_partial_payment_line_item_desc($payment),
281
-                0,
282
-                127
283
-            );
284
-            // Cost of individual item.
285
-            $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount());
286
-            // Item Number.
287
-            $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
288
-            // Item quantity.
289
-            $token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1;
290
-            // Digital item is sold.
291
-            $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
292
-            // Item's sales S/H and tax amount.
293
-            $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount());
294
-            $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0';
295
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
296
-            $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
297
-        }
298
-        // Automatically filling out shipping and contact information.
299
-        if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
300
-            //  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
301
-            $token_request_dtls['NOSHIPPING'] = '2';
302
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
303
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
304
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
305
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
306
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
307
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
308
-            $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
309
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
310
-        } elseif (! $this->_request_shipping_addr) {
311
-            // Do not request shipping details on the PP Checkout page.
312
-            $token_request_dtls['NOSHIPPING'] = '1';
313
-            $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
314
-        }
315
-        // Used a business/personal logo on the PayPal page.
316
-        if (! empty($this->_image_url)) {
317
-            $token_request_dtls['LOGOIMG'] = $this->_image_url;
318
-        }
319
-        $token_request_dtls = apply_filters(
320
-            'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
321
-            $token_request_dtls,
322
-            $this
323
-        );
324
-        // Request PayPal token.
325
-        $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
326
-        $token_rstatus = $this->_ppExpress_check_response($token_request_response);
327
-        $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
328
-            ? $token_rstatus['args']
329
-            : array();
330
-        if ($token_rstatus['status']) {
331
-            // We got the Token so we may continue with the payment and redirect the client.
332
-            $payment->set_details($response_args);
333
-            $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
334
-            $payment->set_redirect_url(
335
-                $gateway_url
336
-                . '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
337
-                . $response_args['TOKEN']
338
-            );
339
-        } else {
340
-            if (isset($response_args['L_ERRORCODE'])) {
341
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
342
-            } else {
343
-                $payment->set_gateway_response(
344
-                    esc_html__(
345
-                        'Error occurred while trying to setup the Express Checkout.',
346
-                        'event_espresso'
347
-                    )
348
-                );
349
-            }
350
-            $payment->set_details($response_args);
351
-            $payment->set_status($this->_pay_model->failed_status());
352
-        }
353
-        return $payment;
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * @param array           $update_info {
360
-     * @type string           $gateway_txn_id
361
-     * @type string status an EEMI_Payment status
362
-     *                                     }
363
-     * @param EEI_Transaction $transaction
364
-     * @return EEI_Payment
365
-     */
366
-    public function handle_payment_update($update_info, $transaction)
367
-    {
368
-        $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
369
-        if ($payment instanceof EEI_Payment) {
370
-            $this->log(array('Return from Authorization' => $update_info), $payment);
371
-            $transaction = $payment->transaction();
372
-            if (! $transaction instanceof EEI_Transaction) {
373
-                $payment->set_gateway_response(
374
-                    esc_html__(
375
-                        'Could not process this payment because it has no associated transaction.',
376
-                        'event_espresso'
377
-                    )
378
-                );
379
-                $payment->set_status($this->_pay_model->failed_status());
380
-                return $payment;
381
-            }
382
-            $primary_registrant = $transaction->primary_registration();
383
-            $payment_details = $payment->details();
384
-            // Check if we still have the token.
385
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
386
-                $payment->set_status($this->_pay_model->failed_status());
387
-                return $payment;
388
-            }
389
-            $cdetails_request_dtls = array(
390
-                'METHOD' => 'GetExpressCheckoutDetails',
391
-                'TOKEN'  => $payment_details['TOKEN'],
392
-            );
393
-            // Request Customer Details.
394
-            $cdetails_request_response = $this->_ppExpress_request(
395
-                $cdetails_request_dtls,
396
-                'Customer Details',
397
-                $payment
398
-            );
399
-            $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
400
-            $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
401
-                ? $cdetails_rstatus['args']
402
-                : array();
403
-            if ($cdetails_rstatus['status']) {
404
-                // We got the PayerID so now we can Complete the transaction.
405
-                $docheckout_request_dtls = array(
406
-                    'METHOD'                         => 'DoExpressCheckoutPayment',
407
-                    'PAYERID'                        => $cdata_response_args['PAYERID'],
408
-                    'TOKEN'                          => $payment_details['TOKEN'],
409
-                    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
410
-                    'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
411
-                    'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
412
-                    //EE will blow up if you change this
413
-                    'BUTTONSOURCE'                   => 'EventEspresso_SP',
414
-                );
415
-                // Payment Checkout/Capture.
416
-                $docheckout_request_response = $this->_ppExpress_request(
417
-                    $docheckout_request_dtls,
418
-                    'Do Payment',
419
-                    $payment
420
-                );
421
-                $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
422
-                $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
423
-                    ? $docheckout_rstatus['args']
424
-                    : array();
425
-                if ($docheckout_rstatus['status']) {
426
-                    // All is well, payment approved.
427
-                    $primary_registration_code = $primary_registrant instanceof EE_Registration ?
428
-                        $primary_registrant->reg_code()
429
-                        : '';
430
-                    $payment->set_extra_accntng($primary_registration_code);
431
-                    $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
432
-                        ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
433
-                        : 0);
434
-                    $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
435
-                        ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
436
-                        : null);
437
-                    $payment->set_details($cdata_response_args);
438
-                    $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
439
-                        ? $docheckout_response_args['PAYMENTINFO_0_ACK']
440
-                        : '');
441
-                    $payment->set_status($this->_pay_model->approved_status());
442
-                } else {
443
-                    if (isset($docheckout_response_args['L_ERRORCODE'])) {
444
-                        $payment->set_gateway_response(
445
-                            $docheckout_response_args['L_ERRORCODE']
446
-                            . '; '
447
-                            . $docheckout_response_args['L_SHORTMESSAGE']
448
-                        );
449
-                    } else {
450
-                        $payment->set_gateway_response(
451
-                            esc_html__(
452
-                                'Error occurred while trying to Capture the funds.',
453
-                                'event_espresso'
454
-                            )
455
-                        );
456
-                    }
457
-                    $payment->set_details($docheckout_response_args);
458
-                    $payment->set_status($this->_pay_model->declined_status());
459
-                }
460
-            } else {
461
-                if (isset($cdata_response_args['L_ERRORCODE'])) {
462
-                    $payment->set_gateway_response(
463
-                        $cdata_response_args['L_ERRORCODE']
464
-                        . '; '
465
-                        . $cdata_response_args['L_SHORTMESSAGE']
466
-                    );
467
-                } else {
468
-                    $payment->set_gateway_response(
469
-                        esc_html__(
470
-                            'Error occurred while trying to get payment Details from PayPal.',
471
-                            'event_espresso'
472
-                        )
473
-                    );
474
-                }
475
-                $payment->set_details($cdata_response_args);
476
-                $payment->set_status($this->_pay_model->failed_status());
477
-            }
478
-        } else {
479
-            $payment->set_gateway_response(
480
-                esc_html__(
481
-                    'Error occurred while trying to process the payment.',
482
-                    'event_espresso'
483
-                )
484
-            );
485
-            $payment->set_status($this->_pay_model->failed_status());
486
-        }
487
-        return $payment;
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     *  Make the Express checkout request.
494
-     *
495
-     * @param array       $request_params
496
-     * @param string      $request_text
497
-     * @param EEI_Payment $payment
498
-     * @return mixed
499
-     */
500
-    public function _ppExpress_request($request_params, $request_text, $payment)
501
-    {
502
-        $request_dtls = array(
503
-            'VERSION'   => '204.0',
504
-            'USER'      => urlencode($this->_api_username),
505
-            'PWD'       => urlencode($this->_api_password),
506
-            'SIGNATURE' => urlencode($this->_api_signature),
507
-        );
508
-        $dtls = array_merge($request_dtls, $request_params);
509
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
510
-        // Request Customer Details.
511
-        $request_response = wp_remote_post(
512
-            $this->_base_gateway_url,
513
-            array(
514
-                'method'      => 'POST',
515
-                'timeout'     => 45,
516
-                'httpversion' => '1.1',
517
-                'cookies'     => array(),
518
-                'headers'     => array(),
519
-                'body'        => http_build_query($dtls),
520
-            )
521
-        );
522
-        // Log the response.
523
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
524
-        return $request_response;
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     *  Check the response status.
531
-     *
532
-     * @param mixed $request_response
533
-     * @return array
534
-     */
535
-    public function _ppExpress_check_response($request_response)
536
-    {
537
-        if (is_wp_error($request_response) || empty($request_response['body'])) {
538
-            // If we got here then there was an error in this request.
539
-            return array('status' => false, 'args' => $request_response);
540
-        }
541
-        $response_args = array();
542
-        parse_str(urldecode($request_response['body']), $response_args);
543
-        if (! isset($response_args['ACK'])) {
544
-            return array('status' => false, 'args' => $request_response);
545
-        }
546
-        if (
547
-            (
548
-                isset($response_args['PAYERID'])
549
-                || isset($response_args['TOKEN'])
550
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
551
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
552
-            )
553
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
554
-        ) {
555
-            // Response status OK, return response parameters for further processing.
556
-            return array('status' => true, 'args' => $response_args);
557
-        }
558
-        $errors = $this->_get_errors($response_args);
559
-        return array('status' => false, 'args' => $errors);
560
-    }
561
-
562
-
563
-
564
-    /**
565
-     *  Log a "Cleared" request.
566
-     *
567
-     * @param array       $request
568
-     * @param EEI_Payment $payment
569
-     * @param string      $info
570
-     * @return void
571
-     */
572
-    private function _log_clean_request($request, $payment, $info)
573
-    {
574
-        $cleaned_request_data = $request;
575
-        unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
576
-        $this->log(array($info => $cleaned_request_data), $payment);
577
-    }
578
-
579
-
580
-
581
-    /**
582
-     *  Get error from the response data.
583
-     *
584
-     * @param array $data_array
585
-     * @return array
586
-     */
587
-    private function _get_errors($data_array)
588
-    {
589
-        $errors = array();
590
-        $n = 0;
591
-        while (isset($data_array["L_ERRORCODE{$n}"])) {
592
-            $l_error_code = isset($data_array["L_ERRORCODE{$n}"])
593
-                ? $data_array["L_ERRORCODE{$n}"]
594
-                : '';
595
-            $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
596
-                ? $data_array["L_SEVERITYCODE{$n}"]
597
-                : '';
598
-            $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
599
-                ? $data_array["L_SHORTMESSAGE{$n}"]
600
-                : '';
601
-            $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
602
-                ? $data_array["L_LONGMESSAGE{$n}"]
603
-                : '';
604
-            if ($n === 0) {
605
-                $errors = array(
606
-                    'L_ERRORCODE'    => $l_error_code,
607
-                    'L_SHORTMESSAGE' => $l_short_message,
608
-                    'L_LONGMESSAGE'  => $l_long_message,
609
-                    'L_SEVERITYCODE' => $l_severity_code,
610
-                );
611
-            } else {
612
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
613
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
614
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
615
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
616
-            }
617
-            $n++;
618
-        }
619
-        return $errors;
620
-    }
35
+	/**
36
+	 * Merchant API Username.
37
+	 *
38
+	 * @var string
39
+	 */
40
+	protected $_api_username;
41
+
42
+	/**
43
+	 * Merchant API Password.
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_api_password;
48
+
49
+	/**
50
+	 * API Signature.
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_api_signature;
55
+
56
+	/**
57
+	 * Request Shipping address on PP checkout page.
58
+	 *
59
+	 * @var string
60
+	 */
61
+	protected $_request_shipping_addr;
62
+
63
+	/**
64
+	 * Business/personal logo.
65
+	 *
66
+	 * @var string
67
+	 */
68
+	protected $_image_url;
69
+
70
+	/**
71
+	 * gateway URL variable
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_base_gateway_url = '';
76
+
77
+
78
+
79
+	/**
80
+	 * EEG_Paypal_Express constructor.
81
+	 */
82
+	public function __construct()
83
+	{
84
+		$this->_currencies_supported = array(
85
+			'USD',
86
+			'AUD',
87
+			'BRL',
88
+			'CAD',
89
+			'CZK',
90
+			'DKK',
91
+			'EUR',
92
+			'HKD',
93
+			'HUF',
94
+			'ILS',
95
+			'JPY',
96
+			'MYR',
97
+			'MXN',
98
+			'NOK',
99
+			'NZD',
100
+			'PHP',
101
+			'PLN',
102
+			'GBP',
103
+			'RUB',
104
+			'SGD',
105
+			'SEK',
106
+			'CHF',
107
+			'TWD',
108
+			'THB',
109
+			'TRY',
110
+		);
111
+		parent::__construct();
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
118
+	 *
119
+	 * @param array $settings_array
120
+	 */
121
+	public function set_settings($settings_array)
122
+	{
123
+		parent::set_settings($settings_array);
124
+		// Redirect URL.
125
+		$this->_base_gateway_url = $this->_debug_mode
126
+			? 'https://api-3t.sandbox.paypal.com/nvp'
127
+			: 'https://api-3t.paypal.com/nvp';
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @param EEI_Payment $payment
134
+	 * @param array       $billing_info
135
+	 * @param string      $return_url
136
+	 * @param string      $notify_url
137
+	 * @param string      $cancel_url
138
+	 * @return \EE_Payment|\EEI_Payment
139
+	 * @throws \EE_Error
140
+	 */
141
+	public function set_redirection_info(
142
+		$payment,
143
+		$billing_info = array(),
144
+		$return_url = null,
145
+		$notify_url = null,
146
+		$cancel_url = null
147
+	) {
148
+		if (! $payment instanceof EEI_Payment) {
149
+			$payment->set_gateway_response(
150
+				esc_html__(
151
+					'Error. No associated payment was found.',
152
+					'event_espresso'
153
+				)
154
+			);
155
+			$payment->set_status($this->_pay_model->failed_status());
156
+			return $payment;
157
+		}
158
+		$transaction = $payment->transaction();
159
+		if (! $transaction instanceof EEI_Transaction) {
160
+			$payment->set_gateway_response(
161
+				esc_html__(
162
+					'Could not process this payment because it has no associated transaction.',
163
+					'event_espresso'
164
+				)
165
+			);
166
+			$payment->set_status($this->_pay_model->failed_status());
167
+			return $payment;
168
+		}
169
+		$order_description = mb_strcut($this->_format_order_description($payment), 0, 127);
170
+		$primary_registration = $transaction->primary_registration();
171
+		$primary_attendee = $primary_registration instanceof EE_Registration
172
+			? $primary_registration->attendee()
173
+			: false;
174
+		$locale = explode('-', get_bloginfo('language'));
175
+		// Gather request parameters.
176
+		$token_request_dtls = array(
177
+			'METHOD'                         => 'SetExpressCheckout',
178
+			'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
179
+			'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
180
+			'PAYMENTREQUEST_0_DESC'          => $order_description,
181
+			'RETURNURL'                      => $return_url,
182
+			'CANCELURL'                      => $cancel_url,
183
+			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
184
+			// Buyer does not need to create a PayPal account to check out.
185
+			// This is referred to as PayPal Account Optional.
186
+			'SOLUTIONTYPE'                   => 'Sole',
187
+			//EE will blow up if you change this
188
+			'BUTTONSOURCE'                   => 'EventEspresso_SP',
189
+			// Locale of the pages displayed by PayPal during Express Checkout.
190
+			'LOCALECODE'                     => $locale[1]
191
+		);
192
+		// Show itemized list.
193
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
194
+			$item_num = 0;
195
+			$itemized_sum = 0;
196
+			$total_line_items = $transaction->total_line_item();
197
+			// Go through each item in the list.
198
+			foreach ($total_line_items->get_items() as $line_item) {
199
+				if ($line_item instanceof EE_Line_Item) {
200
+					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
201
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
202
+						continue;
203
+					}
204
+					$unit_price = $line_item->unit_price();
205
+					$line_item_quantity = $line_item->quantity();
206
+					// This is a discount.
207
+					if ($line_item->is_percent()) {
208
+						$unit_price = $line_item->total();
209
+						$line_item_quantity = 1;
210
+					}
211
+					// Item Name.
212
+					$token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
213
+						$this->_format_line_item_name($line_item, $payment),
214
+						0,
215
+						127
216
+					);
217
+					// Item description.
218
+					$token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
219
+						$this->_format_line_item_desc($line_item, $payment),
220
+						0,
221
+						127
222
+					);
223
+					// Cost of individual item.
224
+					$token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price);
225
+					// Item Number.
226
+					$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
227
+					// Item quantity.
228
+					$token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
229
+					// Digital item is sold.
230
+					$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
231
+					$itemized_sum += $line_item->total();
232
+					++$item_num;
233
+				}
234
+			}
235
+			// Item's sales S/H and tax amount.
236
+			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
237
+			$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
238
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
239
+			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
240
+			$itemized_sum_diff_from_txn_total = round(
241
+				$transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
242
+				2
243
+			);
244
+			// If we were not able to recognize some item like promotion, surcharge or cancellation,
245
+			// add the difference as an extra line item.
246
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
247
+				// Item Name.
248
+				$token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
249
+					esc_html__(
250
+						'Other (promotion/surcharge/cancellation)',
251
+						'event_espresso'
252
+					),
253
+					0,
254
+					127
255
+				);
256
+				// Item description.
257
+				$token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
258
+				// Cost of individual item.
259
+				$token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency(
260
+					$itemized_sum_diff_from_txn_total
261
+				);
262
+				// Item Number.
263
+				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
264
+				// Item quantity.
265
+				$token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
266
+				// Digital item is sold.
267
+				$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
268
+				$item_num++;
269
+			}
270
+		} else {
271
+			// Just one Item.
272
+			// Item Name.
273
+			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
274
+				$this->_format_partial_payment_line_item_name($payment),
275
+				0,
276
+				127
277
+			);
278
+			// Item description.
279
+			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
280
+				$this->_format_partial_payment_line_item_desc($payment),
281
+				0,
282
+				127
283
+			);
284
+			// Cost of individual item.
285
+			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount());
286
+			// Item Number.
287
+			$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
288
+			// Item quantity.
289
+			$token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1;
290
+			// Digital item is sold.
291
+			$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
292
+			// Item's sales S/H and tax amount.
293
+			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount());
294
+			$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0';
295
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
296
+			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
297
+		}
298
+		// Automatically filling out shipping and contact information.
299
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
300
+			//  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
301
+			$token_request_dtls['NOSHIPPING'] = '2';
302
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
303
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
304
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
305
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
306
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
307
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
308
+			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
309
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
310
+		} elseif (! $this->_request_shipping_addr) {
311
+			// Do not request shipping details on the PP Checkout page.
312
+			$token_request_dtls['NOSHIPPING'] = '1';
313
+			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
314
+		}
315
+		// Used a business/personal logo on the PayPal page.
316
+		if (! empty($this->_image_url)) {
317
+			$token_request_dtls['LOGOIMG'] = $this->_image_url;
318
+		}
319
+		$token_request_dtls = apply_filters(
320
+			'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
321
+			$token_request_dtls,
322
+			$this
323
+		);
324
+		// Request PayPal token.
325
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
326
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
327
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
328
+			? $token_rstatus['args']
329
+			: array();
330
+		if ($token_rstatus['status']) {
331
+			// We got the Token so we may continue with the payment and redirect the client.
332
+			$payment->set_details($response_args);
333
+			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
334
+			$payment->set_redirect_url(
335
+				$gateway_url
336
+				. '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
337
+				. $response_args['TOKEN']
338
+			);
339
+		} else {
340
+			if (isset($response_args['L_ERRORCODE'])) {
341
+				$payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
342
+			} else {
343
+				$payment->set_gateway_response(
344
+					esc_html__(
345
+						'Error occurred while trying to setup the Express Checkout.',
346
+						'event_espresso'
347
+					)
348
+				);
349
+			}
350
+			$payment->set_details($response_args);
351
+			$payment->set_status($this->_pay_model->failed_status());
352
+		}
353
+		return $payment;
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * @param array           $update_info {
360
+	 * @type string           $gateway_txn_id
361
+	 * @type string status an EEMI_Payment status
362
+	 *                                     }
363
+	 * @param EEI_Transaction $transaction
364
+	 * @return EEI_Payment
365
+	 */
366
+	public function handle_payment_update($update_info, $transaction)
367
+	{
368
+		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
369
+		if ($payment instanceof EEI_Payment) {
370
+			$this->log(array('Return from Authorization' => $update_info), $payment);
371
+			$transaction = $payment->transaction();
372
+			if (! $transaction instanceof EEI_Transaction) {
373
+				$payment->set_gateway_response(
374
+					esc_html__(
375
+						'Could not process this payment because it has no associated transaction.',
376
+						'event_espresso'
377
+					)
378
+				);
379
+				$payment->set_status($this->_pay_model->failed_status());
380
+				return $payment;
381
+			}
382
+			$primary_registrant = $transaction->primary_registration();
383
+			$payment_details = $payment->details();
384
+			// Check if we still have the token.
385
+			if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
386
+				$payment->set_status($this->_pay_model->failed_status());
387
+				return $payment;
388
+			}
389
+			$cdetails_request_dtls = array(
390
+				'METHOD' => 'GetExpressCheckoutDetails',
391
+				'TOKEN'  => $payment_details['TOKEN'],
392
+			);
393
+			// Request Customer Details.
394
+			$cdetails_request_response = $this->_ppExpress_request(
395
+				$cdetails_request_dtls,
396
+				'Customer Details',
397
+				$payment
398
+			);
399
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
400
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
401
+				? $cdetails_rstatus['args']
402
+				: array();
403
+			if ($cdetails_rstatus['status']) {
404
+				// We got the PayerID so now we can Complete the transaction.
405
+				$docheckout_request_dtls = array(
406
+					'METHOD'                         => 'DoExpressCheckoutPayment',
407
+					'PAYERID'                        => $cdata_response_args['PAYERID'],
408
+					'TOKEN'                          => $payment_details['TOKEN'],
409
+					'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
410
+					'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
411
+					'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
412
+					//EE will blow up if you change this
413
+					'BUTTONSOURCE'                   => 'EventEspresso_SP',
414
+				);
415
+				// Payment Checkout/Capture.
416
+				$docheckout_request_response = $this->_ppExpress_request(
417
+					$docheckout_request_dtls,
418
+					'Do Payment',
419
+					$payment
420
+				);
421
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
422
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
423
+					? $docheckout_rstatus['args']
424
+					: array();
425
+				if ($docheckout_rstatus['status']) {
426
+					// All is well, payment approved.
427
+					$primary_registration_code = $primary_registrant instanceof EE_Registration ?
428
+						$primary_registrant->reg_code()
429
+						: '';
430
+					$payment->set_extra_accntng($primary_registration_code);
431
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
432
+						? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
433
+						: 0);
434
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
435
+						? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
436
+						: null);
437
+					$payment->set_details($cdata_response_args);
438
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
439
+						? $docheckout_response_args['PAYMENTINFO_0_ACK']
440
+						: '');
441
+					$payment->set_status($this->_pay_model->approved_status());
442
+				} else {
443
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
444
+						$payment->set_gateway_response(
445
+							$docheckout_response_args['L_ERRORCODE']
446
+							. '; '
447
+							. $docheckout_response_args['L_SHORTMESSAGE']
448
+						);
449
+					} else {
450
+						$payment->set_gateway_response(
451
+							esc_html__(
452
+								'Error occurred while trying to Capture the funds.',
453
+								'event_espresso'
454
+							)
455
+						);
456
+					}
457
+					$payment->set_details($docheckout_response_args);
458
+					$payment->set_status($this->_pay_model->declined_status());
459
+				}
460
+			} else {
461
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
462
+					$payment->set_gateway_response(
463
+						$cdata_response_args['L_ERRORCODE']
464
+						. '; '
465
+						. $cdata_response_args['L_SHORTMESSAGE']
466
+					);
467
+				} else {
468
+					$payment->set_gateway_response(
469
+						esc_html__(
470
+							'Error occurred while trying to get payment Details from PayPal.',
471
+							'event_espresso'
472
+						)
473
+					);
474
+				}
475
+				$payment->set_details($cdata_response_args);
476
+				$payment->set_status($this->_pay_model->failed_status());
477
+			}
478
+		} else {
479
+			$payment->set_gateway_response(
480
+				esc_html__(
481
+					'Error occurred while trying to process the payment.',
482
+					'event_espresso'
483
+				)
484
+			);
485
+			$payment->set_status($this->_pay_model->failed_status());
486
+		}
487
+		return $payment;
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 *  Make the Express checkout request.
494
+	 *
495
+	 * @param array       $request_params
496
+	 * @param string      $request_text
497
+	 * @param EEI_Payment $payment
498
+	 * @return mixed
499
+	 */
500
+	public function _ppExpress_request($request_params, $request_text, $payment)
501
+	{
502
+		$request_dtls = array(
503
+			'VERSION'   => '204.0',
504
+			'USER'      => urlencode($this->_api_username),
505
+			'PWD'       => urlencode($this->_api_password),
506
+			'SIGNATURE' => urlencode($this->_api_signature),
507
+		);
508
+		$dtls = array_merge($request_dtls, $request_params);
509
+		$this->_log_clean_request($dtls, $payment, $request_text . ' Request');
510
+		// Request Customer Details.
511
+		$request_response = wp_remote_post(
512
+			$this->_base_gateway_url,
513
+			array(
514
+				'method'      => 'POST',
515
+				'timeout'     => 45,
516
+				'httpversion' => '1.1',
517
+				'cookies'     => array(),
518
+				'headers'     => array(),
519
+				'body'        => http_build_query($dtls),
520
+			)
521
+		);
522
+		// Log the response.
523
+		$this->log(array($request_text . ' Response' => $request_response), $payment);
524
+		return $request_response;
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 *  Check the response status.
531
+	 *
532
+	 * @param mixed $request_response
533
+	 * @return array
534
+	 */
535
+	public function _ppExpress_check_response($request_response)
536
+	{
537
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
538
+			// If we got here then there was an error in this request.
539
+			return array('status' => false, 'args' => $request_response);
540
+		}
541
+		$response_args = array();
542
+		parse_str(urldecode($request_response['body']), $response_args);
543
+		if (! isset($response_args['ACK'])) {
544
+			return array('status' => false, 'args' => $request_response);
545
+		}
546
+		if (
547
+			(
548
+				isset($response_args['PAYERID'])
549
+				|| isset($response_args['TOKEN'])
550
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
551
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
552
+			)
553
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
554
+		) {
555
+			// Response status OK, return response parameters for further processing.
556
+			return array('status' => true, 'args' => $response_args);
557
+		}
558
+		$errors = $this->_get_errors($response_args);
559
+		return array('status' => false, 'args' => $errors);
560
+	}
561
+
562
+
563
+
564
+	/**
565
+	 *  Log a "Cleared" request.
566
+	 *
567
+	 * @param array       $request
568
+	 * @param EEI_Payment $payment
569
+	 * @param string      $info
570
+	 * @return void
571
+	 */
572
+	private function _log_clean_request($request, $payment, $info)
573
+	{
574
+		$cleaned_request_data = $request;
575
+		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
576
+		$this->log(array($info => $cleaned_request_data), $payment);
577
+	}
578
+
579
+
580
+
581
+	/**
582
+	 *  Get error from the response data.
583
+	 *
584
+	 * @param array $data_array
585
+	 * @return array
586
+	 */
587
+	private function _get_errors($data_array)
588
+	{
589
+		$errors = array();
590
+		$n = 0;
591
+		while (isset($data_array["L_ERRORCODE{$n}"])) {
592
+			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
593
+				? $data_array["L_ERRORCODE{$n}"]
594
+				: '';
595
+			$l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
596
+				? $data_array["L_SEVERITYCODE{$n}"]
597
+				: '';
598
+			$l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
599
+				? $data_array["L_SHORTMESSAGE{$n}"]
600
+				: '';
601
+			$l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
602
+				? $data_array["L_LONGMESSAGE{$n}"]
603
+				: '';
604
+			if ($n === 0) {
605
+				$errors = array(
606
+					'L_ERRORCODE'    => $l_error_code,
607
+					'L_SHORTMESSAGE' => $l_short_message,
608
+					'L_LONGMESSAGE'  => $l_long_message,
609
+					'L_SEVERITYCODE' => $l_severity_code,
610
+				);
611
+			} else {
612
+				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
613
+				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
614
+				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
615
+				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
616
+			}
617
+			$n++;
618
+		}
619
+		return $errors;
620
+	}
621 621
 
622 622
 }
623 623
 // End of file EEG_Paypal_Express.gateway.php
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 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
 
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * ----------------------------------------------
16 16
  */
17 17
 //Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
18
-if (! function_exists('mb_strcut')) {
18
+if ( ! function_exists('mb_strcut')) {
19 19
     /**
20 20
      * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21 21
      * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         $notify_url = null,
146 146
         $cancel_url = null
147 147
     ) {
148
-        if (! $payment instanceof EEI_Payment) {
148
+        if ( ! $payment instanceof EEI_Payment) {
149 149
             $payment->set_gateway_response(
150 150
                 esc_html__(
151 151
                     'Error. No associated payment was found.',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             return $payment;
157 157
         }
158 158
         $transaction = $payment->transaction();
159
-        if (! $transaction instanceof EEI_Transaction) {
159
+        if ( ! $transaction instanceof EEI_Transaction) {
160 160
             $payment->set_gateway_response(
161 161
                 esc_html__(
162 162
                     'Could not process this payment because it has no associated transaction.',
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
                         $line_item_quantity = 1;
210 210
                     }
211 211
                     // Item Name.
212
-                    $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
212
+                    $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
213 213
                         $this->_format_line_item_name($line_item, $payment),
214 214
                         0,
215 215
                         127
216 216
                     );
217 217
                     // Item description.
218
-                    $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
218
+                    $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut(
219 219
                         $this->_format_line_item_desc($line_item, $payment),
220 220
                         0,
221 221
                         127
222 222
                     );
223 223
                     // Cost of individual item.
224
-                    $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price);
224
+                    $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price);
225 225
                     // Item Number.
226
-                    $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
226
+                    $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
227 227
                     // Item quantity.
228
-                    $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
228
+                    $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity;
229 229
                     // Digital item is sold.
230
-                    $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
230
+                    $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
231 231
                     $itemized_sum += $line_item->total();
232 232
                     ++$item_num;
233 233
                 }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
             // add the difference as an extra line item.
246 246
             if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
247 247
                 // Item Name.
248
-                $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
248
+                $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
249 249
                     esc_html__(
250 250
                         'Other (promotion/surcharge/cancellation)',
251 251
                         'event_espresso'
@@ -254,17 +254,17 @@  discard block
 block discarded – undo
254 254
                     127
255 255
                 );
256 256
                 // Item description.
257
-                $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
257
+                $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = '';
258 258
                 // Cost of individual item.
259
-                $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency(
259
+                $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency(
260 260
                     $itemized_sum_diff_from_txn_total
261 261
                 );
262 262
                 // Item Number.
263
-                $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
263
+                $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
264 264
                 // Item quantity.
265
-                $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
265
+                $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
266 266
                 // Digital item is sold.
267
-                $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
267
+                $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
268 268
                 $item_num++;
269 269
             }
270 270
         } else {
@@ -307,13 +307,13 @@  discard block
 block discarded – undo
307 307
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
308 308
             $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
309 309
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
310
-        } elseif (! $this->_request_shipping_addr) {
310
+        } elseif ( ! $this->_request_shipping_addr) {
311 311
             // Do not request shipping details on the PP Checkout page.
312 312
             $token_request_dtls['NOSHIPPING'] = '1';
313 313
             $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
314 314
         }
315 315
         // Used a business/personal logo on the PayPal page.
316
-        if (! empty($this->_image_url)) {
316
+        if ( ! empty($this->_image_url)) {
317 317
             $token_request_dtls['LOGOIMG'] = $this->_image_url;
318 318
         }
319 319
         $token_request_dtls = apply_filters(
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
             );
339 339
         } else {
340 340
             if (isset($response_args['L_ERRORCODE'])) {
341
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
341
+                $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']);
342 342
             } else {
343 343
                 $payment->set_gateway_response(
344 344
                     esc_html__(
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         if ($payment instanceof EEI_Payment) {
370 370
             $this->log(array('Return from Authorization' => $update_info), $payment);
371 371
             $transaction = $payment->transaction();
372
-            if (! $transaction instanceof EEI_Transaction) {
372
+            if ( ! $transaction instanceof EEI_Transaction) {
373 373
                 $payment->set_gateway_response(
374 374
                     esc_html__(
375 375
                         'Could not process this payment because it has no associated transaction.',
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
             $primary_registrant = $transaction->primary_registration();
383 383
             $payment_details = $payment->details();
384 384
             // Check if we still have the token.
385
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
385
+            if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
386 386
                 $payment->set_status($this->_pay_model->failed_status());
387 387
                 return $payment;
388 388
             }
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
                         : '';
430 430
                     $payment->set_extra_accntng($primary_registration_code);
431 431
                     $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
432
-                        ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
432
+                        ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
433 433
                         : 0);
434 434
                     $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
435 435
                         ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
             'SIGNATURE' => urlencode($this->_api_signature),
507 507
         );
508 508
         $dtls = array_merge($request_dtls, $request_params);
509
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
509
+        $this->_log_clean_request($dtls, $payment, $request_text.' Request');
510 510
         // Request Customer Details.
511 511
         $request_response = wp_remote_post(
512 512
             $this->_base_gateway_url,
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
             )
521 521
         );
522 522
         // Log the response.
523
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
523
+        $this->log(array($request_text.' Response' => $request_response), $payment);
524 524
         return $request_response;
525 525
     }
526 526
 
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
         }
541 541
         $response_args = array();
542 542
         parse_str(urldecode($request_response['body']), $response_args);
543
-        if (! isset($response_args['ACK'])) {
543
+        if ( ! isset($response_args['ACK'])) {
544 544
             return array('status' => false, 'args' => $request_response);
545 545
         }
546 546
         if (
@@ -609,10 +609,10 @@  discard block
 block discarded – undo
609 609
                     'L_SEVERITYCODE' => $l_severity_code,
610 610
                 );
611 611
             } else {
612
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
613
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
614
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
615
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
612
+                $errors['L_ERRORCODE'] .= ', '.$l_error_code;
613
+                $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message;
614
+                $errors['L_LONGMESSAGE'] .= ', '.$l_long_message;
615
+                $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code;
616 616
             }
617 617
             $n++;
618 618
         }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         *
70
-         * @return void
71
-         */
72
-        function espresso_minimum_php_version_error()
73
-        {
74
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 *
70
+		 * @return void
71
+		 */
72
+		function espresso_minimum_php_version_error()
73
+		{
74
+			?>
75 75
             <div class="error">
76 76
                 <p>
77 77
                     <?php
78
-                    printf(
79
-                        esc_html__(
80
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
81
-                            'event_espresso'
82
-                        ),
83
-                        EE_MIN_PHP_VER_REQUIRED,
84
-                        PHP_VERSION,
85
-                        '<br/>',
86
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
-                    );
88
-                    ?>
78
+					printf(
79
+						esc_html__(
80
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
81
+							'event_espresso'
82
+						),
83
+						EE_MIN_PHP_VER_REQUIRED,
84
+						PHP_VERSION,
85
+						'<br/>',
86
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
+					);
88
+					?>
89 89
                 </p>
90 90
             </div>
91 91
             <?php
92
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
-        }
92
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
93
+		}
94 94
 
95
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
-    } else {
97
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
-        /**
99
-         * espresso_version
100
-         * Returns the plugin version
101
-         *
102
-         * @return string
103
-         */
104
-        function espresso_version()
105
-        {
106
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.49.rc.000');
107
-        }
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
+	} else {
97
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
+		/**
99
+		 * espresso_version
100
+		 * Returns the plugin version
101
+		 *
102
+		 * @return string
103
+		 */
104
+		function espresso_version()
105
+		{
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.49.rc.000');
107
+		}
108 108
 
109
-        /**
110
-         * espresso_plugin_activation
111
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
-         */
113
-        function espresso_plugin_activation()
114
-        {
115
-            update_option('ee_espresso_activation', true);
116
-        }
109
+		/**
110
+		 * espresso_plugin_activation
111
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
+		 */
113
+		function espresso_plugin_activation()
114
+		{
115
+			update_option('ee_espresso_activation', true);
116
+		}
117 117
 
118
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
-        /**
120
-         *    espresso_load_error_handling
121
-         *    this function loads EE's class for handling exceptions and errors
122
-         */
123
-        function espresso_load_error_handling()
124
-        {
125
-            static $error_handling_loaded = false;
126
-            if ($error_handling_loaded) {
127
-                return;
128
-            }
129
-            // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
-                \EEH_Debug_Tools::instance();
133
-            }
134
-            // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once EE_CORE . 'EE_Error.core.php';
137
-            } else {
138
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
-            }
140
-            $error_handling_loaded = true;
141
-        }
118
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
+		/**
120
+		 *    espresso_load_error_handling
121
+		 *    this function loads EE's class for handling exceptions and errors
122
+		 */
123
+		function espresso_load_error_handling()
124
+		{
125
+			static $error_handling_loaded = false;
126
+			if ($error_handling_loaded) {
127
+				return;
128
+			}
129
+			// load debugging tools
130
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
+				\EEH_Debug_Tools::instance();
133
+			}
134
+			// load error handling
135
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
+				require_once EE_CORE . 'EE_Error.core.php';
137
+			} else {
138
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
+			}
140
+			$error_handling_loaded = true;
141
+		}
142 142
 
143
-        /**
144
-         *    espresso_load_required
145
-         *    given a class name and path, this function will load that file or throw an exception
146
-         *
147
-         * @param    string $classname
148
-         * @param    string $full_path_to_file
149
-         * @throws    EE_Error
150
-         */
151
-        function espresso_load_required($classname, $full_path_to_file)
152
-        {
153
-            if (is_readable($full_path_to_file)) {
154
-                require_once $full_path_to_file;
155
-            } else {
156
-                throw new \EE_Error (
157
-                    sprintf(
158
-                        esc_html__(
159
-                            'The %s class file could not be located or is not readable due to file permissions.',
160
-                            'event_espresso'
161
-                        ),
162
-                        $classname
163
-                    )
164
-                );
165
-            }
166
-        }
143
+		/**
144
+		 *    espresso_load_required
145
+		 *    given a class name and path, this function will load that file or throw an exception
146
+		 *
147
+		 * @param    string $classname
148
+		 * @param    string $full_path_to_file
149
+		 * @throws    EE_Error
150
+		 */
151
+		function espresso_load_required($classname, $full_path_to_file)
152
+		{
153
+			if (is_readable($full_path_to_file)) {
154
+				require_once $full_path_to_file;
155
+			} else {
156
+				throw new \EE_Error (
157
+					sprintf(
158
+						esc_html__(
159
+							'The %s class file could not be located or is not readable due to file permissions.',
160
+							'event_espresso'
161
+						),
162
+						$classname
163
+					)
164
+				);
165
+			}
166
+		}
167 167
 
168
-        /**
169
-         * @since 4.9.27
170
-         * @throws \EE_Error
171
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
-         * @throws \OutOfBoundsException
179
-         */
180
-        function bootstrap_espresso()
181
-        {
182
-            require_once __DIR__ . '/core/espresso_definitions.php';
183
-            try {
184
-                espresso_load_error_handling();
185
-                espresso_load_required(
186
-                    'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
-                );
189
-                espresso_load_required(
190
-                    'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
-                );
193
-                espresso_load_required(
194
-                    'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
-                );
197
-                espresso_load_required(
198
-                    'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
-                );
201
-                // instantiate and configure PSR4 autoloader
202
-                espresso_load_required(
203
-                    'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
205
-                );
206
-                espresso_load_required(
207
-                    'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
-                );
210
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
-                $AutoloaderInit->initializeAutoloader();
212
-                espresso_load_required(
213
-                    'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
-                );
216
-                espresso_load_required(
217
-                    'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
-                );
220
-                espresso_load_required(
221
-                    'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
223
-                );
224
-                // bootstrap EE and the request stack
225
-                new EE_Bootstrap(
226
-                    new EE_Request($_GET, $_POST, $_COOKIE),
227
-                    new EE_Response()
228
-                );
229
-            } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
-            }
233
-        }
234
-        bootstrap_espresso();
235
-    }
168
+		/**
169
+		 * @since 4.9.27
170
+		 * @throws \EE_Error
171
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
175
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
+		 * @throws \OutOfBoundsException
179
+		 */
180
+		function bootstrap_espresso()
181
+		{
182
+			require_once __DIR__ . '/core/espresso_definitions.php';
183
+			try {
184
+				espresso_load_error_handling();
185
+				espresso_load_required(
186
+					'EEH_Base',
187
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
+				);
189
+				espresso_load_required(
190
+					'EEH_File',
191
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
+				);
193
+				espresso_load_required(
194
+					'EEH_File',
195
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
+				);
197
+				espresso_load_required(
198
+					'EEH_Array',
199
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
+				);
201
+				// instantiate and configure PSR4 autoloader
202
+				espresso_load_required(
203
+					'Psr4Autoloader',
204
+					EE_CORE . 'Psr4Autoloader.php'
205
+				);
206
+				espresso_load_required(
207
+					'EE_Psr4AutoloaderInit',
208
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
+				);
210
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
211
+				$AutoloaderInit->initializeAutoloader();
212
+				espresso_load_required(
213
+					'EE_Request',
214
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
+				);
216
+				espresso_load_required(
217
+					'EE_Response',
218
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
+				);
220
+				espresso_load_required(
221
+					'EE_Bootstrap',
222
+					EE_CORE . 'EE_Bootstrap.core.php'
223
+				);
224
+				// bootstrap EE and the request stack
225
+				new EE_Bootstrap(
226
+					new EE_Request($_GET, $_POST, $_COOKIE),
227
+					new EE_Response()
228
+				);
229
+			} catch (Exception $e) {
230
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
+			}
233
+		}
234
+		bootstrap_espresso();
235
+	}
236 236
 }
237 237
 if (! function_exists('espresso_deactivate_plugin')) {
238
-    /**
239
-     *    deactivate_plugin
240
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
-     *
242
-     * @access public
243
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
-     * @return    void
245
-     */
246
-    function espresso_deactivate_plugin($plugin_basename = '')
247
-    {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
-        }
251
-        unset($_GET['activate'], $_REQUEST['activate']);
252
-        deactivate_plugins($plugin_basename);
253
-    }
238
+	/**
239
+	 *    deactivate_plugin
240
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
+	 *
242
+	 * @access public
243
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
+	 * @return    void
245
+	 */
246
+	function espresso_deactivate_plugin($plugin_basename = '')
247
+	{
248
+		if (! function_exists('deactivate_plugins')) {
249
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
+		}
251
+		unset($_GET['activate'], $_REQUEST['activate']);
252
+		deactivate_plugins($plugin_basename);
253
+	}
254 254
 }
Please login to merge, or discard this patch.
core/EE_PUE.core.php 2 patches
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -17,247 +17,247 @@  discard block
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     *    class constructor
22
-     *
23
-     * @access public
24
-     */
25
-    public function __construct()
26
-    {
20
+	/**
21
+	 *    class constructor
22
+	 *
23
+	 * @access public
24
+	 */
25
+	public function __construct()
26
+	{
27 27
 //		throw new EE_Error('error');
28 28
 
29
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
30
-
31
-        //wp have no MONTH_IN_SECONDS constant.  So we approximate our own assuming all months are 4 weeks long.
32
-        if (! defined('MONTH_IN_SECONDS')) {
33
-            define('MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4);
34
-        }
35
-
36
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
37
-            $this->_uxip_hooks();
38
-        }
39
-
40
-
41
-        $ueip_optin        = EE_Registry::instance()->CFG->core->ee_ueip_optin;
42
-        $ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified;
43
-
44
-        //has optin been selected for data collection?
45
-        $espresso_data_optin = ! empty($ueip_optin) ? $ueip_optin : null;
46
-
47
-        if (empty($ueip_has_notified)
48
-            && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance
49
-        ) {
50
-            add_action('admin_notices', array($this, 'espresso_data_collection_optin_notice'), 10);
51
-            add_action('admin_enqueue_scripts', array($this, 'espresso_data_collection_enqueue_scripts'), 10);
52
-            add_action('wp_ajax_espresso_data_optin', array($this, 'espresso_data_optin_ajax_handler'), 10);
53
-            update_option('ee_ueip_optin', 'yes');
54
-            $espresso_data_optin = 'yes';
55
-        }
56
-
57
-        //let's prepare extra stats
58
-        $extra_stats = array();
59
-
60
-        //only collect extra stats if the plugin user has opted in and transient is expired.
61
-        if (! empty($espresso_data_optin) && $espresso_data_optin == 'yes') {
62
-            if (false === ($transient = get_transient('ee_extra_data'))
63
-                && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance
64
-            ) {
65
-
66
-                $current_site = is_multisite() ? get_current_site() : null;
67
-                $site_pre     = ! is_main_site() && ! empty($current_site)
68
-                    ? trim(
69
-                        preg_replace('/\b\w\S\w\b/', '', $current_site->domain),
70
-                        '.'
71
-                    ) . '_'
72
-                    : '';
73
-
74
-
75
-                //active gateways
76
-                $active_gateways = get_option('event_espresso_active_gateways');
77
-                if (! empty($active_gateways)) {
78
-                    foreach ((array)$active_gateways as $gateway => $ignore) {
79
-                        $extra_stats[$site_pre . $gateway . '_gateway_active'] = 1;
80
-                    }
81
-                }
82
-
83
-                if (is_multisite() && is_main_site()) {
84
-                    $extra_stats['is_multisite'] = true;
85
-                }
86
-
87
-                //what is the current active theme?
88
-                $active_theme = get_option('uxip_ee_active_theme');
89
-                if (! empty($active_theme)) {
90
-                    $extra_stats[$site_pre . 'active_theme'] = $active_theme;
91
-                }
92
-
93
-                //event info regarding an all event count and all "active" event count
94
-                $all_events_count = get_option('uxip_ee4_all_events_count');
95
-                if (! empty($all_events_count)) {
96
-                    $extra_stats[$site_pre . 'ee4_all_events_count'] = $all_events_count;
97
-                }
98
-                $active_events_count = get_option('uxip_ee4_active_events_count');
99
-                if (! empty($active_events_count)) {
100
-                    $extra_stats[$site_pre . 'ee4_active_events_count'] = $active_events_count;
101
-                }
102
-
103
-                //datetime stuff
104
-                $dtt_count = get_option('uxip_ee_all_dtts_count');
105
-                if (! empty($dtt_count)) {
106
-                    $extra_stats[$site_pre . 'all_dtts_count'] = $dtt_count;
107
-                }
108
-
109
-                $dtt_sold = get_option('uxip_ee_dtt_sold');
110
-                if (! empty($dtt_sold)) {
111
-                    $extra_stats[$site_pre . 'dtt_sold'] = $dtt_sold;
112
-                }
113
-
114
-                //ticket stuff
115
-                $all_tkt_count = get_option('uxip_ee_all_tkt_count');
116
-                if (! empty($all_tkt_count)) {
117
-                    $extra_stats[$site_pre . 'all_tkt_count'] = $all_tkt_count;
118
-                }
119
-
120
-                $free_tkt_count = get_option('uxip_ee_free_tkt_count');
121
-                if (! empty($free_tkt_count)) {
122
-                    $extra_stats[$site_pre . 'free_tkt_count'] = $free_tkt_count;
123
-                }
124
-
125
-                $paid_tkt_count = get_option('uxip_ee_paid_tkt_count');
126
-                if (! empty($paid_tkt_count)) {
127
-                    $extra_stats[$site_pre . 'paid_tkt_count'] = $paid_tkt_count;
128
-                }
129
-
130
-                $tkt_sold = get_option('uxip_ee_tkt_sold');
131
-                if (! empty($tkt_sold)) {
132
-                    $extra_stats[$site_pre . 'tkt_sold'] = $tkt_sold;
133
-                }
134
-
135
-                //phpversion checking
136
-                $extra_stats['phpversion'] = function_exists('phpversion') ? phpversion() : 'unknown';
137
-
138
-                //set transient
139
-                set_transient('ee_extra_data', $extra_stats, WEEK_IN_SECONDS);
140
-            }
141
-        }
142
-
143
-
144
-        // PUE Auto Upgrades stuff
145
-        if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file
146
-            require_once(EE_THIRD_PARTY . 'pue/pue-client.php');
147
-
148
-            $api_key         = isset(EE_Registry::instance()->NET_CFG->core->site_license_key)
149
-                ? EE_Registry::instance()->NET_CFG->core->site_license_key
150
-                : '';
151
-            //this needs to be the host server where plugin update engine is installed. Note, if you leave this blank
152
-            // then it is assumed the WordPress repo will be used and we'll just check there.
153
-            $host_server_url = 'https://eventespresso.com';
154
-
155
-            //Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
156
-            //  So it's important that you use a key for the version type that is unique and not found in another key.
157
-            //For example:
158
-            //$plugin_slug['premium']['p'] = 'some-premium-slug';
159
-            //$plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
160
-            //The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
161
-            // so doing something like:
162
-            //$plugin_slug['premium']['p'] = 'some-premium-slug';
163
-            //$plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
164
-            //..WOULD work!
165
-            $plugin_slug = array(
166
-                'free'       => array('decaf' => 'event-espresso-core-decaf'),
167
-                'premium'    => array('p' => 'event-espresso-core-reg'),
168
-                'prerelease' => array('beta' => 'event-espresso-core-pr'),
169
-            );
170
-
171
-
172
-            //$options needs to be an array with the included keys as listed.
173
-            $options = array(
174
-                //	'optionName' => '', //(optional) - used as the reference for saving update information in the
175
-                // clients options table.  Will be automatically set if left blank.
176
-                'apikey'                => $api_key,
177
-                //(required), you will need to obtain the apikey that the client gets from your site and
178
-                // then saves in their sites options table (see 'getting an api-key' below)
179
-                'lang_domain'           => 'event_espresso',
180
-                //(optional) - put here whatever reference you are using for the localization of your plugin (if it's
181
-                // localized).  That way strings in this file will be included in the translation for your plugin.
182
-                'checkPeriod'           => '24',
183
-                //(optional) - use this parameter to indicate how often you want the client's install to ping your
184
-                // server for update checks.  The integer indicates hours.  If you don't include this parameter it will
185
-                // default to 12 hours.
186
-                'option_key'            => 'site_license_key',
187
-                //this is what is used to reference the api_key in your plugin options.  PUE uses this to trigger
188
-                // updating your information message whenever this option_key is modified.
189
-                'options_page_slug'     => 'espresso_general_settings',
190
-                'plugin_basename'       => EE_PLUGIN_BASENAME,
191
-                'use_wp_update'         => true,
192
-                //if TRUE then you want FREE versions of the plugin to be updated from WP
193
-                'extra_stats'           => $extra_stats,
194
-                'turn_on_notices_saved' => true,
195
-            );
196
-            //initiate the class and start the plugin update engine!
197
-            new PluginUpdateEngineChecker($host_server_url, $plugin_slug, $options);
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * The purpose of this function is to display information about Event Espresso data collection
204
-     * and a optin selection for extra data collecting by users.
205
-     *
206
-     * @param bool $extra
207
-     * @return string html.
208
-     */
209
-    public static function espresso_data_collection_optin_text($extra = true)
210
-    {
211
-        if (! $extra) {
212
-            echo '<h2 class="ee-admin-settings-hdr" '
213
-                 . (! $extra ? 'id="UXIP_settings"' : '')
214
-                 . '>'
215
-                 . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso')
216
-                 . EEH_Template::get_help_tab_link('organization_logo_info')
217
-                 . '</h2>';
218
-            printf(
219
-                esc_html__(
220
-                    '%sPlease help us make Event Espresso better and vote for your favorite features.%s The %sUser eXperience Improvement Program (UXIP)%s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary but it is enabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %sPlease see our %sPrivacy Policy%s for more information.',
221
-                    'event_espresso'
222
-                ),
223
-                '<p><em>',
224
-                '</em></p>',
225
-                '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">',
226
-                '</a>',
227
-                '<br><br>',
228
-                '<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">',
229
-                '</a>'
230
-            );
231
-        } else {
232
-            $settings_url = EE_Admin_Page::add_query_args_and_nonce(
233
-                array('action' => 'default'),
234
-                admin_url('admin.php?page=espresso_general_settings')
235
-            );
236
-            $settings_url .= '#UXIP_settings';
237
-            printf(
238
-                esc_html__(
239
-                    'The Event Espresso UXIP feature is active on your site. For %smore info%s and to opt-out %sclick here%s.',
240
-                    'event_espresso'
241
-                ),
242
-                '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">',
243
-                '</a>',
244
-                '<a href="' . $settings_url . '" target="_blank">',
245
-                '</a>'
246
-            );
247
-        }
248
-    }
249
-
250
-
251
-    public function espresso_data_collection_optin_notice()
252
-    {
253
-        $ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified;
254
-        if ($ueip_has_notified) {
255
-            return;
256
-        }
257
-        // $settings_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default'),
258
-        // admin_url( 'admin.php?page=espresso_general_settings') );
259
-        // $settings_url = $settings_url . '#UXIP_settings';
260
-        ?>
29
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
30
+
31
+		//wp have no MONTH_IN_SECONDS constant.  So we approximate our own assuming all months are 4 weeks long.
32
+		if (! defined('MONTH_IN_SECONDS')) {
33
+			define('MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4);
34
+		}
35
+
36
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
37
+			$this->_uxip_hooks();
38
+		}
39
+
40
+
41
+		$ueip_optin        = EE_Registry::instance()->CFG->core->ee_ueip_optin;
42
+		$ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified;
43
+
44
+		//has optin been selected for data collection?
45
+		$espresso_data_optin = ! empty($ueip_optin) ? $ueip_optin : null;
46
+
47
+		if (empty($ueip_has_notified)
48
+			&& EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance
49
+		) {
50
+			add_action('admin_notices', array($this, 'espresso_data_collection_optin_notice'), 10);
51
+			add_action('admin_enqueue_scripts', array($this, 'espresso_data_collection_enqueue_scripts'), 10);
52
+			add_action('wp_ajax_espresso_data_optin', array($this, 'espresso_data_optin_ajax_handler'), 10);
53
+			update_option('ee_ueip_optin', 'yes');
54
+			$espresso_data_optin = 'yes';
55
+		}
56
+
57
+		//let's prepare extra stats
58
+		$extra_stats = array();
59
+
60
+		//only collect extra stats if the plugin user has opted in and transient is expired.
61
+		if (! empty($espresso_data_optin) && $espresso_data_optin == 'yes') {
62
+			if (false === ($transient = get_transient('ee_extra_data'))
63
+				&& EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance
64
+			) {
65
+
66
+				$current_site = is_multisite() ? get_current_site() : null;
67
+				$site_pre     = ! is_main_site() && ! empty($current_site)
68
+					? trim(
69
+						preg_replace('/\b\w\S\w\b/', '', $current_site->domain),
70
+						'.'
71
+					) . '_'
72
+					: '';
73
+
74
+
75
+				//active gateways
76
+				$active_gateways = get_option('event_espresso_active_gateways');
77
+				if (! empty($active_gateways)) {
78
+					foreach ((array)$active_gateways as $gateway => $ignore) {
79
+						$extra_stats[$site_pre . $gateway . '_gateway_active'] = 1;
80
+					}
81
+				}
82
+
83
+				if (is_multisite() && is_main_site()) {
84
+					$extra_stats['is_multisite'] = true;
85
+				}
86
+
87
+				//what is the current active theme?
88
+				$active_theme = get_option('uxip_ee_active_theme');
89
+				if (! empty($active_theme)) {
90
+					$extra_stats[$site_pre . 'active_theme'] = $active_theme;
91
+				}
92
+
93
+				//event info regarding an all event count and all "active" event count
94
+				$all_events_count = get_option('uxip_ee4_all_events_count');
95
+				if (! empty($all_events_count)) {
96
+					$extra_stats[$site_pre . 'ee4_all_events_count'] = $all_events_count;
97
+				}
98
+				$active_events_count = get_option('uxip_ee4_active_events_count');
99
+				if (! empty($active_events_count)) {
100
+					$extra_stats[$site_pre . 'ee4_active_events_count'] = $active_events_count;
101
+				}
102
+
103
+				//datetime stuff
104
+				$dtt_count = get_option('uxip_ee_all_dtts_count');
105
+				if (! empty($dtt_count)) {
106
+					$extra_stats[$site_pre . 'all_dtts_count'] = $dtt_count;
107
+				}
108
+
109
+				$dtt_sold = get_option('uxip_ee_dtt_sold');
110
+				if (! empty($dtt_sold)) {
111
+					$extra_stats[$site_pre . 'dtt_sold'] = $dtt_sold;
112
+				}
113
+
114
+				//ticket stuff
115
+				$all_tkt_count = get_option('uxip_ee_all_tkt_count');
116
+				if (! empty($all_tkt_count)) {
117
+					$extra_stats[$site_pre . 'all_tkt_count'] = $all_tkt_count;
118
+				}
119
+
120
+				$free_tkt_count = get_option('uxip_ee_free_tkt_count');
121
+				if (! empty($free_tkt_count)) {
122
+					$extra_stats[$site_pre . 'free_tkt_count'] = $free_tkt_count;
123
+				}
124
+
125
+				$paid_tkt_count = get_option('uxip_ee_paid_tkt_count');
126
+				if (! empty($paid_tkt_count)) {
127
+					$extra_stats[$site_pre . 'paid_tkt_count'] = $paid_tkt_count;
128
+				}
129
+
130
+				$tkt_sold = get_option('uxip_ee_tkt_sold');
131
+				if (! empty($tkt_sold)) {
132
+					$extra_stats[$site_pre . 'tkt_sold'] = $tkt_sold;
133
+				}
134
+
135
+				//phpversion checking
136
+				$extra_stats['phpversion'] = function_exists('phpversion') ? phpversion() : 'unknown';
137
+
138
+				//set transient
139
+				set_transient('ee_extra_data', $extra_stats, WEEK_IN_SECONDS);
140
+			}
141
+		}
142
+
143
+
144
+		// PUE Auto Upgrades stuff
145
+		if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file
146
+			require_once(EE_THIRD_PARTY . 'pue/pue-client.php');
147
+
148
+			$api_key         = isset(EE_Registry::instance()->NET_CFG->core->site_license_key)
149
+				? EE_Registry::instance()->NET_CFG->core->site_license_key
150
+				: '';
151
+			//this needs to be the host server where plugin update engine is installed. Note, if you leave this blank
152
+			// then it is assumed the WordPress repo will be used and we'll just check there.
153
+			$host_server_url = 'https://eventespresso.com';
154
+
155
+			//Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
156
+			//  So it's important that you use a key for the version type that is unique and not found in another key.
157
+			//For example:
158
+			//$plugin_slug['premium']['p'] = 'some-premium-slug';
159
+			//$plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
160
+			//The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
161
+			// so doing something like:
162
+			//$plugin_slug['premium']['p'] = 'some-premium-slug';
163
+			//$plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
164
+			//..WOULD work!
165
+			$plugin_slug = array(
166
+				'free'       => array('decaf' => 'event-espresso-core-decaf'),
167
+				'premium'    => array('p' => 'event-espresso-core-reg'),
168
+				'prerelease' => array('beta' => 'event-espresso-core-pr'),
169
+			);
170
+
171
+
172
+			//$options needs to be an array with the included keys as listed.
173
+			$options = array(
174
+				//	'optionName' => '', //(optional) - used as the reference for saving update information in the
175
+				// clients options table.  Will be automatically set if left blank.
176
+				'apikey'                => $api_key,
177
+				//(required), you will need to obtain the apikey that the client gets from your site and
178
+				// then saves in their sites options table (see 'getting an api-key' below)
179
+				'lang_domain'           => 'event_espresso',
180
+				//(optional) - put here whatever reference you are using for the localization of your plugin (if it's
181
+				// localized).  That way strings in this file will be included in the translation for your plugin.
182
+				'checkPeriod'           => '24',
183
+				//(optional) - use this parameter to indicate how often you want the client's install to ping your
184
+				// server for update checks.  The integer indicates hours.  If you don't include this parameter it will
185
+				// default to 12 hours.
186
+				'option_key'            => 'site_license_key',
187
+				//this is what is used to reference the api_key in your plugin options.  PUE uses this to trigger
188
+				// updating your information message whenever this option_key is modified.
189
+				'options_page_slug'     => 'espresso_general_settings',
190
+				'plugin_basename'       => EE_PLUGIN_BASENAME,
191
+				'use_wp_update'         => true,
192
+				//if TRUE then you want FREE versions of the plugin to be updated from WP
193
+				'extra_stats'           => $extra_stats,
194
+				'turn_on_notices_saved' => true,
195
+			);
196
+			//initiate the class and start the plugin update engine!
197
+			new PluginUpdateEngineChecker($host_server_url, $plugin_slug, $options);
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * The purpose of this function is to display information about Event Espresso data collection
204
+	 * and a optin selection for extra data collecting by users.
205
+	 *
206
+	 * @param bool $extra
207
+	 * @return string html.
208
+	 */
209
+	public static function espresso_data_collection_optin_text($extra = true)
210
+	{
211
+		if (! $extra) {
212
+			echo '<h2 class="ee-admin-settings-hdr" '
213
+				 . (! $extra ? 'id="UXIP_settings"' : '')
214
+				 . '>'
215
+				 . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso')
216
+				 . EEH_Template::get_help_tab_link('organization_logo_info')
217
+				 . '</h2>';
218
+			printf(
219
+				esc_html__(
220
+					'%sPlease help us make Event Espresso better and vote for your favorite features.%s The %sUser eXperience Improvement Program (UXIP)%s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary but it is enabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %sPlease see our %sPrivacy Policy%s for more information.',
221
+					'event_espresso'
222
+				),
223
+				'<p><em>',
224
+				'</em></p>',
225
+				'<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">',
226
+				'</a>',
227
+				'<br><br>',
228
+				'<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">',
229
+				'</a>'
230
+			);
231
+		} else {
232
+			$settings_url = EE_Admin_Page::add_query_args_and_nonce(
233
+				array('action' => 'default'),
234
+				admin_url('admin.php?page=espresso_general_settings')
235
+			);
236
+			$settings_url .= '#UXIP_settings';
237
+			printf(
238
+				esc_html__(
239
+					'The Event Espresso UXIP feature is active on your site. For %smore info%s and to opt-out %sclick here%s.',
240
+					'event_espresso'
241
+				),
242
+				'<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">',
243
+				'</a>',
244
+				'<a href="' . $settings_url . '" target="_blank">',
245
+				'</a>'
246
+			);
247
+		}
248
+	}
249
+
250
+
251
+	public function espresso_data_collection_optin_notice()
252
+	{
253
+		$ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified;
254
+		if ($ueip_has_notified) {
255
+			return;
256
+		}
257
+		// $settings_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default'),
258
+		// admin_url( 'admin.php?page=espresso_general_settings') );
259
+		// $settings_url = $settings_url . '#UXIP_settings';
260
+		?>
261 261
         <div class="updated data-collect-optin" id="espresso-data-collect-optin-container">
262 262
             <div id="data-collect-optin-options-container">
263 263
                 <span class="dashicons dashicons-admin-site"></span>
@@ -270,186 +270,186 @@  discard block
 block discarded – undo
270 270
             </div>
271 271
         </div>
272 272
         <?php
273
-    }
274
-
275
-
276
-    /**
277
-     * enqueue scripts/styles needed for data collection optin
278
-     *
279
-     * @return void
280
-     */
281
-    public function espresso_data_collection_enqueue_scripts()
282
-    {
283
-        wp_register_script(
284
-            'ee-data-optin-js',
285
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js',
286
-            array('jquery'),
287
-            EVENT_ESPRESSO_VERSION,
288
-            true
289
-        );
290
-        wp_register_style(
291
-            'ee-data-optin-css',
292
-            EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css',
293
-            array(),
294
-            EVENT_ESPRESSO_VERSION
295
-        );
296
-
297
-        wp_enqueue_script('ee-data-optin-js');
298
-        wp_enqueue_style('ee-data-optin-css');
299
-    }
300
-
301
-
302
-    /**
303
-     * This just handles the setting of the selected option for data optin via ajax
304
-     *
305
-     * @return void
306
-     * @throws InvalidArgumentException
307
-     * @throws InvalidDataTypeException
308
-     * @throws InvalidInterfaceException
309
-     */
310
-    public function espresso_data_optin_ajax_handler()
311
-    {
312
-
313
-        //verify nonce
314
-        if (isset($_POST['nonce']) && ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) {
315
-            exit();
316
-        }
317
-
318
-        //update_option('ee_ueip_optin', $ueip_optin);
319
-        EE_Registry::instance()->CFG->core->ee_ueip_has_notified = 1;
320
-        EE_Registry::instance()->CFG->update_espresso_config(false, false);
321
-        exit();
322
-    }
323
-
324
-
325
-    /**
326
-     * This is a handy helper method for retrieving whether there is an update available for the given plugin.
327
-     *
328
-     * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
329
-     *                          identify plugins. Defaults to core update
330
-     * @return boolean           True if update available, false if not.
331
-     */
332
-    public static function is_update_available($basename = '')
333
-    {
334
-
335
-        $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME;
336
-
337
-        $update = false;
338
-
339
-        // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core"
340
-        $folder = DS . dirname($basename);
341
-
342
-        $plugins = get_plugins($folder);
343
-        $current = get_site_transient('update_plugins');
344
-
345
-        foreach ((array)$plugins as $plugin_file => $plugin_data) {
346
-            if (isset($current->response['plugin_file'])) {
347
-                $update = true;
348
-            }
349
-        }
350
-
351
-        //it's possible that there is an update but an invalid site-license-key is in use
352
-        if (get_site_option('pue_json_error_' . $basename)) {
353
-            $update = true;
354
-        }
355
-
356
-        return $update;
357
-    }
358
-
359
-
360
-    /**
361
-     * UXIP TRACKING *******
362
-     */
363
-
364
-
365
-    /**
366
-     * This method contains all the hooks into EE for gathering stats that will be reported with the PUE uxip system
367
-     *
368
-     * @public
369
-     * @return void
370
-     */
371
-    public function _uxip_hooks()
372
-    {
373
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
374
-            add_action('admin_init', array($this, 'track_active_theme'));
375
-            add_action('admin_init', array($this, 'track_event_info'));
376
-        }
377
-    }
378
-
379
-
380
-    public function track_active_theme()
381
-    {
382
-        //we only check this once a month.
383
-        if (false === ($transient = get_transient('ee_active_theme_check'))) {
384
-            $theme = wp_get_theme();
385
-            update_option('uxip_ee_active_theme', $theme->get('Name'));
386
-            set_transient('ee_active_theme_check', 1, MONTH_IN_SECONDS);
387
-        }
388
-    }
389
-
390
-
391
-    public function track_event_info()
392
-    {
393
-        //we only check this once every couple weeks.
394
-        if (false === ($transient = get_transient('ee4_event_info_check'))) {
395
-            //first let's get the number for ALL events
396
-            /** @var EEM_Event $EVT */
397
-            $EVT   = EE_Registry::instance()->load_model('Event');
398
-            $DTT   = EE_Registry::instance()->load_model('Datetime');
399
-            $TKT   = EE_Registry::instance()->load_model('Ticket');
400
-            $count = $EVT->count();
401
-            if ($count > 0) {
402
-                update_option('uxip_ee4_all_events_count', $count);
403
-            }
404
-
405
-            //next let's just get the number of ACTIVE events
406
-            $count_active = $EVT->get_active_events(array(), true);
407
-            if ($count_active > 0) {
408
-                update_option('uxip_ee4_active_events_count', $count_active);
409
-            }
410
-
411
-            //datetimes!
412
-            $dtt_count = $DTT->count();
413
-            if ($dtt_count > 0) {
414
-                update_option('uxip_ee_all_dtts_count', $dtt_count);
415
-            }
416
-
417
-
418
-            //dttsold
419
-            $dtt_sold = $DTT->sum(array(), 'DTT_sold');
420
-            if ($dtt_sold > 0) {
421
-                update_option('uxip_ee_dtt_sold', $dtt_sold);
422
-            }
423
-
424
-            //allticketcount
425
-            $all_tkt_count = $TKT->count();
426
-            if ($all_tkt_count > 0) {
427
-                update_option('uxip_ee_all_tkt_count', $all_tkt_count);
428
-            }
429
-
430
-            //freetktcount
431
-            $_where         = array('TKT_price' => 0);
432
-            $free_tkt_count = $TKT->count(array($_where));
433
-            if ($free_tkt_count > 0) {
434
-                update_option('uxip_ee_free_tkt_count', $free_tkt_count);
435
-            }
436
-
437
-            //paidtktcount
438
-            $_where         = array('TKT_price' => array('>', 0));
439
-            $paid_tkt_count = $TKT->count(array($_where));
440
-            if ($paid_tkt_count > 0) {
441
-                update_option('uxip_ee_paid_tkt_count', $paid_tkt_count);
442
-            }
443
-
444
-            //tktsold
445
-            $tkt_sold = $TKT->sum(array(), 'TKT_sold');
446
-            if ($tkt_sold > 0) {
447
-                update_option('uxip_ee_tkt_sold', $tkt_sold);
448
-            }
449
-
450
-
451
-            set_transient('ee4_event_info_check', 1, WEEK_IN_SECONDS * 2);
452
-        }
453
-    }
273
+	}
274
+
275
+
276
+	/**
277
+	 * enqueue scripts/styles needed for data collection optin
278
+	 *
279
+	 * @return void
280
+	 */
281
+	public function espresso_data_collection_enqueue_scripts()
282
+	{
283
+		wp_register_script(
284
+			'ee-data-optin-js',
285
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js',
286
+			array('jquery'),
287
+			EVENT_ESPRESSO_VERSION,
288
+			true
289
+		);
290
+		wp_register_style(
291
+			'ee-data-optin-css',
292
+			EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css',
293
+			array(),
294
+			EVENT_ESPRESSO_VERSION
295
+		);
296
+
297
+		wp_enqueue_script('ee-data-optin-js');
298
+		wp_enqueue_style('ee-data-optin-css');
299
+	}
300
+
301
+
302
+	/**
303
+	 * This just handles the setting of the selected option for data optin via ajax
304
+	 *
305
+	 * @return void
306
+	 * @throws InvalidArgumentException
307
+	 * @throws InvalidDataTypeException
308
+	 * @throws InvalidInterfaceException
309
+	 */
310
+	public function espresso_data_optin_ajax_handler()
311
+	{
312
+
313
+		//verify nonce
314
+		if (isset($_POST['nonce']) && ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) {
315
+			exit();
316
+		}
317
+
318
+		//update_option('ee_ueip_optin', $ueip_optin);
319
+		EE_Registry::instance()->CFG->core->ee_ueip_has_notified = 1;
320
+		EE_Registry::instance()->CFG->update_espresso_config(false, false);
321
+		exit();
322
+	}
323
+
324
+
325
+	/**
326
+	 * This is a handy helper method for retrieving whether there is an update available for the given plugin.
327
+	 *
328
+	 * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
329
+	 *                          identify plugins. Defaults to core update
330
+	 * @return boolean           True if update available, false if not.
331
+	 */
332
+	public static function is_update_available($basename = '')
333
+	{
334
+
335
+		$basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME;
336
+
337
+		$update = false;
338
+
339
+		// should take "event-espresso-core/espresso.php" and change to "/event-espresso-core"
340
+		$folder = DS . dirname($basename);
341
+
342
+		$plugins = get_plugins($folder);
343
+		$current = get_site_transient('update_plugins');
344
+
345
+		foreach ((array)$plugins as $plugin_file => $plugin_data) {
346
+			if (isset($current->response['plugin_file'])) {
347
+				$update = true;
348
+			}
349
+		}
350
+
351
+		//it's possible that there is an update but an invalid site-license-key is in use
352
+		if (get_site_option('pue_json_error_' . $basename)) {
353
+			$update = true;
354
+		}
355
+
356
+		return $update;
357
+	}
358
+
359
+
360
+	/**
361
+	 * UXIP TRACKING *******
362
+	 */
363
+
364
+
365
+	/**
366
+	 * This method contains all the hooks into EE for gathering stats that will be reported with the PUE uxip system
367
+	 *
368
+	 * @public
369
+	 * @return void
370
+	 */
371
+	public function _uxip_hooks()
372
+	{
373
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
374
+			add_action('admin_init', array($this, 'track_active_theme'));
375
+			add_action('admin_init', array($this, 'track_event_info'));
376
+		}
377
+	}
378
+
379
+
380
+	public function track_active_theme()
381
+	{
382
+		//we only check this once a month.
383
+		if (false === ($transient = get_transient('ee_active_theme_check'))) {
384
+			$theme = wp_get_theme();
385
+			update_option('uxip_ee_active_theme', $theme->get('Name'));
386
+			set_transient('ee_active_theme_check', 1, MONTH_IN_SECONDS);
387
+		}
388
+	}
389
+
390
+
391
+	public function track_event_info()
392
+	{
393
+		//we only check this once every couple weeks.
394
+		if (false === ($transient = get_transient('ee4_event_info_check'))) {
395
+			//first let's get the number for ALL events
396
+			/** @var EEM_Event $EVT */
397
+			$EVT   = EE_Registry::instance()->load_model('Event');
398
+			$DTT   = EE_Registry::instance()->load_model('Datetime');
399
+			$TKT   = EE_Registry::instance()->load_model('Ticket');
400
+			$count = $EVT->count();
401
+			if ($count > 0) {
402
+				update_option('uxip_ee4_all_events_count', $count);
403
+			}
404
+
405
+			//next let's just get the number of ACTIVE events
406
+			$count_active = $EVT->get_active_events(array(), true);
407
+			if ($count_active > 0) {
408
+				update_option('uxip_ee4_active_events_count', $count_active);
409
+			}
410
+
411
+			//datetimes!
412
+			$dtt_count = $DTT->count();
413
+			if ($dtt_count > 0) {
414
+				update_option('uxip_ee_all_dtts_count', $dtt_count);
415
+			}
416
+
417
+
418
+			//dttsold
419
+			$dtt_sold = $DTT->sum(array(), 'DTT_sold');
420
+			if ($dtt_sold > 0) {
421
+				update_option('uxip_ee_dtt_sold', $dtt_sold);
422
+			}
423
+
424
+			//allticketcount
425
+			$all_tkt_count = $TKT->count();
426
+			if ($all_tkt_count > 0) {
427
+				update_option('uxip_ee_all_tkt_count', $all_tkt_count);
428
+			}
429
+
430
+			//freetktcount
431
+			$_where         = array('TKT_price' => 0);
432
+			$free_tkt_count = $TKT->count(array($_where));
433
+			if ($free_tkt_count > 0) {
434
+				update_option('uxip_ee_free_tkt_count', $free_tkt_count);
435
+			}
436
+
437
+			//paidtktcount
438
+			$_where         = array('TKT_price' => array('>', 0));
439
+			$paid_tkt_count = $TKT->count(array($_where));
440
+			if ($paid_tkt_count > 0) {
441
+				update_option('uxip_ee_paid_tkt_count', $paid_tkt_count);
442
+			}
443
+
444
+			//tktsold
445
+			$tkt_sold = $TKT->sum(array(), 'TKT_sold');
446
+			if ($tkt_sold > 0) {
447
+				update_option('uxip_ee_tkt_sold', $tkt_sold);
448
+			}
449
+
450
+
451
+			set_transient('ee4_event_info_check', 1, WEEK_IN_SECONDS * 2);
452
+		}
453
+	}
454 454
 
455 455
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         do_action('AHEE_log', __CLASS__, __FUNCTION__);
30 30
 
31 31
         //wp have no MONTH_IN_SECONDS constant.  So we approximate our own assuming all months are 4 weeks long.
32
-        if (! defined('MONTH_IN_SECONDS')) {
32
+        if ( ! defined('MONTH_IN_SECONDS')) {
33 33
             define('MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4);
34 34
         }
35 35
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $extra_stats = array();
59 59
 
60 60
         //only collect extra stats if the plugin user has opted in and transient is expired.
61
-        if (! empty($espresso_data_optin) && $espresso_data_optin == 'yes') {
61
+        if ( ! empty($espresso_data_optin) && $espresso_data_optin == 'yes') {
62 62
             if (false === ($transient = get_transient('ee_extra_data'))
63 63
                 && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance
64 64
             ) {
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
                     ? trim(
69 69
                         preg_replace('/\b\w\S\w\b/', '', $current_site->domain),
70 70
                         '.'
71
-                    ) . '_'
71
+                    ).'_'
72 72
                     : '';
73 73
 
74 74
 
75 75
                 //active gateways
76 76
                 $active_gateways = get_option('event_espresso_active_gateways');
77
-                if (! empty($active_gateways)) {
78
-                    foreach ((array)$active_gateways as $gateway => $ignore) {
79
-                        $extra_stats[$site_pre . $gateway . '_gateway_active'] = 1;
77
+                if ( ! empty($active_gateways)) {
78
+                    foreach ((array) $active_gateways as $gateway => $ignore) {
79
+                        $extra_stats[$site_pre.$gateway.'_gateway_active'] = 1;
80 80
                     }
81 81
                 }
82 82
 
@@ -86,50 +86,50 @@  discard block
 block discarded – undo
86 86
 
87 87
                 //what is the current active theme?
88 88
                 $active_theme = get_option('uxip_ee_active_theme');
89
-                if (! empty($active_theme)) {
90
-                    $extra_stats[$site_pre . 'active_theme'] = $active_theme;
89
+                if ( ! empty($active_theme)) {
90
+                    $extra_stats[$site_pre.'active_theme'] = $active_theme;
91 91
                 }
92 92
 
93 93
                 //event info regarding an all event count and all "active" event count
94 94
                 $all_events_count = get_option('uxip_ee4_all_events_count');
95
-                if (! empty($all_events_count)) {
96
-                    $extra_stats[$site_pre . 'ee4_all_events_count'] = $all_events_count;
95
+                if ( ! empty($all_events_count)) {
96
+                    $extra_stats[$site_pre.'ee4_all_events_count'] = $all_events_count;
97 97
                 }
98 98
                 $active_events_count = get_option('uxip_ee4_active_events_count');
99
-                if (! empty($active_events_count)) {
100
-                    $extra_stats[$site_pre . 'ee4_active_events_count'] = $active_events_count;
99
+                if ( ! empty($active_events_count)) {
100
+                    $extra_stats[$site_pre.'ee4_active_events_count'] = $active_events_count;
101 101
                 }
102 102
 
103 103
                 //datetime stuff
104 104
                 $dtt_count = get_option('uxip_ee_all_dtts_count');
105
-                if (! empty($dtt_count)) {
106
-                    $extra_stats[$site_pre . 'all_dtts_count'] = $dtt_count;
105
+                if ( ! empty($dtt_count)) {
106
+                    $extra_stats[$site_pre.'all_dtts_count'] = $dtt_count;
107 107
                 }
108 108
 
109 109
                 $dtt_sold = get_option('uxip_ee_dtt_sold');
110
-                if (! empty($dtt_sold)) {
111
-                    $extra_stats[$site_pre . 'dtt_sold'] = $dtt_sold;
110
+                if ( ! empty($dtt_sold)) {
111
+                    $extra_stats[$site_pre.'dtt_sold'] = $dtt_sold;
112 112
                 }
113 113
 
114 114
                 //ticket stuff
115 115
                 $all_tkt_count = get_option('uxip_ee_all_tkt_count');
116
-                if (! empty($all_tkt_count)) {
117
-                    $extra_stats[$site_pre . 'all_tkt_count'] = $all_tkt_count;
116
+                if ( ! empty($all_tkt_count)) {
117
+                    $extra_stats[$site_pre.'all_tkt_count'] = $all_tkt_count;
118 118
                 }
119 119
 
120 120
                 $free_tkt_count = get_option('uxip_ee_free_tkt_count');
121
-                if (! empty($free_tkt_count)) {
122
-                    $extra_stats[$site_pre . 'free_tkt_count'] = $free_tkt_count;
121
+                if ( ! empty($free_tkt_count)) {
122
+                    $extra_stats[$site_pre.'free_tkt_count'] = $free_tkt_count;
123 123
                 }
124 124
 
125 125
                 $paid_tkt_count = get_option('uxip_ee_paid_tkt_count');
126
-                if (! empty($paid_tkt_count)) {
127
-                    $extra_stats[$site_pre . 'paid_tkt_count'] = $paid_tkt_count;
126
+                if ( ! empty($paid_tkt_count)) {
127
+                    $extra_stats[$site_pre.'paid_tkt_count'] = $paid_tkt_count;
128 128
                 }
129 129
 
130 130
                 $tkt_sold = get_option('uxip_ee_tkt_sold');
131
-                if (! empty($tkt_sold)) {
132
-                    $extra_stats[$site_pre . 'tkt_sold'] = $tkt_sold;
131
+                if ( ! empty($tkt_sold)) {
132
+                    $extra_stats[$site_pre.'tkt_sold'] = $tkt_sold;
133 133
                 }
134 134
 
135 135
                 //phpversion checking
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 
143 143
 
144 144
         // PUE Auto Upgrades stuff
145
-        if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file
146
-            require_once(EE_THIRD_PARTY . 'pue/pue-client.php');
145
+        if (is_readable(EE_THIRD_PARTY.'pue/pue-client.php')) { //include the file
146
+            require_once(EE_THIRD_PARTY.'pue/pue-client.php');
147 147
 
148
-            $api_key         = isset(EE_Registry::instance()->NET_CFG->core->site_license_key)
148
+            $api_key = isset(EE_Registry::instance()->NET_CFG->core->site_license_key)
149 149
                 ? EE_Registry::instance()->NET_CFG->core->site_license_key
150 150
                 : '';
151 151
             //this needs to be the host server where plugin update engine is installed. Note, if you leave this blank
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
      */
209 209
     public static function espresso_data_collection_optin_text($extra = true)
210 210
     {
211
-        if (! $extra) {
211
+        if ( ! $extra) {
212 212
             echo '<h2 class="ee-admin-settings-hdr" '
213
-                 . (! $extra ? 'id="UXIP_settings"' : '')
213
+                 . ( ! $extra ? 'id="UXIP_settings"' : '')
214 214
                  . '>'
215 215
                  . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso')
216 216
                  . EEH_Template::get_help_tab_link('organization_logo_info')
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
                 ),
242 242
                 '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">',
243 243
                 '</a>',
244
-                '<a href="' . $settings_url . '" target="_blank">',
244
+                '<a href="'.$settings_url.'" target="_blank">',
245 245
                 '</a>'
246 246
             );
247 247
         }
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
     {
283 283
         wp_register_script(
284 284
             'ee-data-optin-js',
285
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js',
285
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-data-optin.js',
286 286
             array('jquery'),
287 287
             EVENT_ESPRESSO_VERSION,
288 288
             true
289 289
         );
290 290
         wp_register_style(
291 291
             'ee-data-optin-css',
292
-            EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css',
292
+            EE_GLOBAL_ASSETS_URL.'css/ee-data-optin.css',
293 293
             array(),
294 294
             EVENT_ESPRESSO_VERSION
295 295
         );
@@ -337,19 +337,19 @@  discard block
 block discarded – undo
337 337
         $update = false;
338 338
 
339 339
         // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core"
340
-        $folder = DS . dirname($basename);
340
+        $folder = DS.dirname($basename);
341 341
 
342 342
         $plugins = get_plugins($folder);
343 343
         $current = get_site_transient('update_plugins');
344 344
 
345
-        foreach ((array)$plugins as $plugin_file => $plugin_data) {
345
+        foreach ((array) $plugins as $plugin_file => $plugin_data) {
346 346
             if (isset($current->response['plugin_file'])) {
347 347
                 $update = true;
348 348
             }
349 349
         }
350 350
 
351 351
         //it's possible that there is an update but an invalid site-license-key is in use
352
-        if (get_site_option('pue_json_error_' . $basename)) {
352
+        if (get_site_option('pue_json_error_'.$basename)) {
353 353
             $update = true;
354 354
         }
355 355
 
Please login to merge, or discard this patch.