Completed
Branch BUG/fixed-undefined-index-duri... (f9235f)
by
unknown
28:55 queued 20:12
created
caffeinated/payment_methods/Aim/EE_PMT_Aim.pm.php 1 patch
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -12,275 +12,275 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @param EE_Payment_Method $pm_instance
17
-     * @return EE_PMT_Aim
18
-     * @throws \EE_Error
19
-     */
20
-    public function __construct($pm_instance = null)
21
-    {
22
-        $this->_setup_properties();
23
-        parent::__construct($pm_instance);
24
-    }
15
+	/**
16
+	 * @param EE_Payment_Method $pm_instance
17
+	 * @return EE_PMT_Aim
18
+	 * @throws \EE_Error
19
+	 */
20
+	public function __construct($pm_instance = null)
21
+	{
22
+		$this->_setup_properties();
23
+		parent::__construct($pm_instance);
24
+	}
25 25
     
26
-    /**
27
-     * Sets up payment method type properties for this gateway, which is normally
28
-     * done in the constructor, but we want this to be easy for similar gateways to override
29
-     * while still calling the parent constructor.
30
-     * So children should override this method instead of __construct
31
-     */
32
-    protected function _setup_properties()
33
-    {
34
-        require_once($this->file_folder().'EEG_Aim.gateway.php');
35
-        $this->_gateway = new EEG_Aim();
36
-        $this->_pretty_name = __("Authorize.net AIM", 'event_espresso');
37
-        $this->_default_description = __('Please provide the following billing information.', 'event_espresso');
38
-        $this->_requires_https = true;
39
-    }
26
+	/**
27
+	 * Sets up payment method type properties for this gateway, which is normally
28
+	 * done in the constructor, but we want this to be easy for similar gateways to override
29
+	 * while still calling the parent constructor.
30
+	 * So children should override this method instead of __construct
31
+	 */
32
+	protected function _setup_properties()
33
+	{
34
+		require_once($this->file_folder().'EEG_Aim.gateway.php');
35
+		$this->_gateway = new EEG_Aim();
36
+		$this->_pretty_name = __("Authorize.net AIM", 'event_espresso');
37
+		$this->_default_description = __('Please provide the following billing information.', 'event_espresso');
38
+		$this->_requires_https = true;
39
+	}
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * Creates the billing form for this payment method type
45
-     *
46
-     * @param \EE_Transaction $transaction
47
-     * @return EE_Billing_Info_Form
48
-     * @throws \EE_Error
49
-     */
50
-    public function generate_new_billing_form(EE_Transaction $transaction = null)
51
-    {
52
-        $billing_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, array(
53
-            'name'=>'AIM_Form',
54
-            'subsections'=>array(
55
-                'credit_card'=>new EE_Credit_Card_Input(array(
56
-                    'required'=>true,
57
-                    'html_label_text' => __('Card Number', 'event_espresso')
58
-                )),
59
-                'exp_month'=>new EE_Credit_Card_Month_Input(true, array(
60
-                    'required'=>true,
61
-                    'html_label_text' => __('Expiry Month', 'event_espresso')
62
-                )),
63
-                'exp_year'=>new EE_Credit_Card_Year_Input(array(
64
-                    'required'=>true,
65
-                    'html_label_text' => __('Expiry Year', 'event_espresso')
66
-                )),
67
-                'cvv'=>new EE_CVV_Input(array(
68
-                    'required'=>true,
69
-                    'html_label_text' => __('CVV', 'event_espresso') )),
70
-            )
71
-        ));
72
-        $billing_form->add_subsections(array(
73
-            'company' => new EE_Text_Input(array(
74
-                'html_label_text' => __('Company', 'event_espresso')
75
-            ))
76
-        ), 'email', false);
77
-        $billing_form->add_subsections(
78
-            array(
79
-                    'fax' => new EE_Text_Input(array(
80
-                        'html_label_text' => __('Fax', 'event_espresso')
81
-                    ))
82
-                ),
83
-            'phone',
84
-            false
85
-        );
86
-        $settings_form = $this->settings_form();
87
-        if ($settings_form->get_input('excluded_billing_inputs') instanceof EE_Checkbox_Multi_Input) {
88
-                $billing_form->exclude($settings_form->get_input('excluded_billing_inputs')->normalized_value());
89
-        }
90
-        if ($settings_form->get_input('required_billing_inputs') instanceof EE_Checkbox_Multi_Input) {
91
-            $required_inputs = $settings_form->get_input('required_billing_inputs')->normalized_value();
92
-            // only change the requirement of inputs which are allowed to be changed
93
-            /** @var EE_Form_Input_Base[] $inputs_to_evaluate */
94
-            $inputs_to_evaluate = array_intersect_key(
95
-                $billing_form->inputs(),
96
-                $this->billing_input_names()
97
-            );
98
-            foreach ($inputs_to_evaluate as $input_name => $input) {
99
-                if (in_array($input_name, $required_inputs)) {
100
-                    $input->set_required(true);
101
-                } else {
102
-                    $input->set_required(false);
103
-                }
104
-            }
105
-        }
106
-        return $this->apply_billing_form_debug_settings($billing_form);
107
-    }
43
+	/**
44
+	 * Creates the billing form for this payment method type
45
+	 *
46
+	 * @param \EE_Transaction $transaction
47
+	 * @return EE_Billing_Info_Form
48
+	 * @throws \EE_Error
49
+	 */
50
+	public function generate_new_billing_form(EE_Transaction $transaction = null)
51
+	{
52
+		$billing_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, array(
53
+			'name'=>'AIM_Form',
54
+			'subsections'=>array(
55
+				'credit_card'=>new EE_Credit_Card_Input(array(
56
+					'required'=>true,
57
+					'html_label_text' => __('Card Number', 'event_espresso')
58
+				)),
59
+				'exp_month'=>new EE_Credit_Card_Month_Input(true, array(
60
+					'required'=>true,
61
+					'html_label_text' => __('Expiry Month', 'event_espresso')
62
+				)),
63
+				'exp_year'=>new EE_Credit_Card_Year_Input(array(
64
+					'required'=>true,
65
+					'html_label_text' => __('Expiry Year', 'event_espresso')
66
+				)),
67
+				'cvv'=>new EE_CVV_Input(array(
68
+					'required'=>true,
69
+					'html_label_text' => __('CVV', 'event_espresso') )),
70
+			)
71
+		));
72
+		$billing_form->add_subsections(array(
73
+			'company' => new EE_Text_Input(array(
74
+				'html_label_text' => __('Company', 'event_espresso')
75
+			))
76
+		), 'email', false);
77
+		$billing_form->add_subsections(
78
+			array(
79
+					'fax' => new EE_Text_Input(array(
80
+						'html_label_text' => __('Fax', 'event_espresso')
81
+					))
82
+				),
83
+			'phone',
84
+			false
85
+		);
86
+		$settings_form = $this->settings_form();
87
+		if ($settings_form->get_input('excluded_billing_inputs') instanceof EE_Checkbox_Multi_Input) {
88
+				$billing_form->exclude($settings_form->get_input('excluded_billing_inputs')->normalized_value());
89
+		}
90
+		if ($settings_form->get_input('required_billing_inputs') instanceof EE_Checkbox_Multi_Input) {
91
+			$required_inputs = $settings_form->get_input('required_billing_inputs')->normalized_value();
92
+			// only change the requirement of inputs which are allowed to be changed
93
+			/** @var EE_Form_Input_Base[] $inputs_to_evaluate */
94
+			$inputs_to_evaluate = array_intersect_key(
95
+				$billing_form->inputs(),
96
+				$this->billing_input_names()
97
+			);
98
+			foreach ($inputs_to_evaluate as $input_name => $input) {
99
+				if (in_array($input_name, $required_inputs)) {
100
+					$input->set_required(true);
101
+				} else {
102
+					$input->set_required(false);
103
+				}
104
+			}
105
+		}
106
+		return $this->apply_billing_form_debug_settings($billing_form);
107
+	}
108 108
 
109 109
 
110 110
 
111
-    /**
112
-     * apply_billing_form_debug_settings
113
-     * applies debug data to the form
114
-     *
115
-     * @param \EE_Billing_Info_Form $billing_form
116
-     * @return \EE_Billing_Info_Form
117
-     * @throws \EE_Error
118
-     */
119
-    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
120
-    {
121
-        if ($this->_pm_instance->debug_mode()
122
-            || $this->_pm_instance->get_extra_meta('test_transactions', true, false)
123
-        ) {
124
-            $billing_form->get_input('credit_card')->set_default('4007000000027');
125
-            $billing_form->get_input('exp_year')->set_default('2020');
126
-            if ($billing_form->get_subsection('cvv') instanceof EE_Form_Input_Base) {
127
-                $billing_form->get_input('cvv')->set_default('123');
128
-            }
129
-            $billing_form->add_subsections(
130
-                array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ),
131
-                'credit_card'
132
-            );
133
-            $billing_form->add_subsections(
134
-                array(
135
-                    'debug_content' => new EE_Form_Section_HTML_From_Template(
136
-                        __DIR__.DS.'templates'.DS.'authorize_net_aim_debug_info.template.php'
137
-                    )
138
-                ),
139
-                'first_name'
140
-            );
141
-        }
142
-        return $billing_form;
143
-    }
111
+	/**
112
+	 * apply_billing_form_debug_settings
113
+	 * applies debug data to the form
114
+	 *
115
+	 * @param \EE_Billing_Info_Form $billing_form
116
+	 * @return \EE_Billing_Info_Form
117
+	 * @throws \EE_Error
118
+	 */
119
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
120
+	{
121
+		if ($this->_pm_instance->debug_mode()
122
+			|| $this->_pm_instance->get_extra_meta('test_transactions', true, false)
123
+		) {
124
+			$billing_form->get_input('credit_card')->set_default('4007000000027');
125
+			$billing_form->get_input('exp_year')->set_default('2020');
126
+			if ($billing_form->get_subsection('cvv') instanceof EE_Form_Input_Base) {
127
+				$billing_form->get_input('cvv')->set_default('123');
128
+			}
129
+			$billing_form->add_subsections(
130
+				array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ),
131
+				'credit_card'
132
+			);
133
+			$billing_form->add_subsections(
134
+				array(
135
+					'debug_content' => new EE_Form_Section_HTML_From_Template(
136
+						__DIR__.DS.'templates'.DS.'authorize_net_aim_debug_info.template.php'
137
+					)
138
+				),
139
+				'first_name'
140
+			);
141
+		}
142
+		return $billing_form;
143
+	}
144 144
 
145 145
 
146 146
 
147
-    /**
148
-     * Gets the form for all the settings related to this payment method type
149
-     * @return EE_Payment_Method_Form
150
-     */
151
-    public function generate_new_settings_form()
152
-    {
153
-        $billing_input_names = $this->billing_input_names();
154
-        return new EE_Payment_Method_Form(
155
-            array(
156
-                'extra_meta_inputs'=>array(
157
-                    'login_id'=>new EE_Text_Input(
158
-                        array(
159
-                            'html_label_text'=>  sprintf(__("Authorize.net API Login ID %s", "event_espresso"), $this->get_help_tab_link()),
160
-                            'required' => true )
161
-                    ),
162
-                    'transaction_key'=>new EE_Text_Input(
163
-                        array(
164
-                            'html_label_text'=> sprintf(__("Authorize.net Transaction Key %s", "event_espresso"), $this->get_help_tab_link()),
165
-                            'required' => true )
166
-                    ),
167
-                    'test_transactions'=>new EE_Yes_No_Input(
168
-                        array(
169
-                            'html_label_text'=>  sprintf(__("Send test transactions? %s", 'event_espresso'), $this->get_help_tab_link()),
170
-                            'html_help_text'=>  __("Send test transactions, even to live server", 'event_espresso'),
171
-                            'default' => false,
172
-                            'required' => true
173
-                        )
174
-                    ),
175
-                    'excluded_billing_inputs' => new EE_Checkbox_Multi_Input(
176
-                        $billing_input_names,
177
-                        array(
178
-                        'html_label_text' => sprintf(__("Excluded Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link()),
179
-                        'default' => array(
180
-                            'company',
181
-                            'fax',
182
-                        )
183
-                        )
184
-                    ),
185
-                    'required_billing_inputs' => new EE_Checkbox_Multi_Input(
186
-                        $billing_input_names,
187
-                        array(
188
-                            'html_label_text' => sprintf(__("Required Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link()),
189
-                            'default' => array_diff(
190
-                                array_keys($billing_input_names),
191
-                                array( 'address2', 'phone', 'company', 'fax' )
192
-                            ),
193
-                            'html_help_text' => __('Note: if fields are excluded they cannot be required.', 'event_espresso')
194
-                        )
195
-                    ),
196
-                    'server' => new EE_Select_Input(
197
-                        apply_filters(
198
-                            'FHEE__EE_PMT_Aim__generate_new_settings_form__server_select_input__options',
199
-                            array(
200
-                                'akamai' => __('Authorize.net/Akamai (default)', 'event_espresso'),
201
-                                'authorize.net' => __('Authorize.net (deprecated)', 'event_espresso'),
202
-                            ),
203
-                            $this
204
-                        ),
205
-                        array(
206
-                            'html_label_text' => __('Server', 'event_espresso'),
207
-                            'html_help_text' => __('The Gateway Server where payment requests will be sent', 'event_espresso')
208
-                        )
209
-                    )
147
+	/**
148
+	 * Gets the form for all the settings related to this payment method type
149
+	 * @return EE_Payment_Method_Form
150
+	 */
151
+	public function generate_new_settings_form()
152
+	{
153
+		$billing_input_names = $this->billing_input_names();
154
+		return new EE_Payment_Method_Form(
155
+			array(
156
+				'extra_meta_inputs'=>array(
157
+					'login_id'=>new EE_Text_Input(
158
+						array(
159
+							'html_label_text'=>  sprintf(__("Authorize.net API Login ID %s", "event_espresso"), $this->get_help_tab_link()),
160
+							'required' => true )
161
+					),
162
+					'transaction_key'=>new EE_Text_Input(
163
+						array(
164
+							'html_label_text'=> sprintf(__("Authorize.net Transaction Key %s", "event_espresso"), $this->get_help_tab_link()),
165
+							'required' => true )
166
+					),
167
+					'test_transactions'=>new EE_Yes_No_Input(
168
+						array(
169
+							'html_label_text'=>  sprintf(__("Send test transactions? %s", 'event_espresso'), $this->get_help_tab_link()),
170
+							'html_help_text'=>  __("Send test transactions, even to live server", 'event_espresso'),
171
+							'default' => false,
172
+							'required' => true
173
+						)
174
+					),
175
+					'excluded_billing_inputs' => new EE_Checkbox_Multi_Input(
176
+						$billing_input_names,
177
+						array(
178
+						'html_label_text' => sprintf(__("Excluded Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link()),
179
+						'default' => array(
180
+							'company',
181
+							'fax',
182
+						)
183
+						)
184
+					),
185
+					'required_billing_inputs' => new EE_Checkbox_Multi_Input(
186
+						$billing_input_names,
187
+						array(
188
+							'html_label_text' => sprintf(__("Required Payment Form Fields %s", 'event_espresso'), $this->get_help_tab_link()),
189
+							'default' => array_diff(
190
+								array_keys($billing_input_names),
191
+								array( 'address2', 'phone', 'company', 'fax' )
192
+							),
193
+							'html_help_text' => __('Note: if fields are excluded they cannot be required.', 'event_espresso')
194
+						)
195
+					),
196
+					'server' => new EE_Select_Input(
197
+						apply_filters(
198
+							'FHEE__EE_PMT_Aim__generate_new_settings_form__server_select_input__options',
199
+							array(
200
+								'akamai' => __('Authorize.net/Akamai (default)', 'event_espresso'),
201
+								'authorize.net' => __('Authorize.net (deprecated)', 'event_espresso'),
202
+							),
203
+							$this
204
+						),
205
+						array(
206
+							'html_label_text' => __('Server', 'event_espresso'),
207
+							'html_help_text' => __('The Gateway Server where payment requests will be sent', 'event_espresso')
208
+						)
209
+					)
210 210
                         
211
-                )
212
-            )
213
-        );
214
-    }
211
+				)
212
+			)
213
+		);
214
+	}
215 215
     
216
-    /**
217
-     * Returns an array where keys are the slugs for billing inputs, and values
218
-     * are their i18n names
219
-     * @return array
220
-     */
221
-    public function billing_input_names()
222
-    {
223
-        return array(
224
-            'first_name' => __('First Name', 'event_espresso'),
225
-            'last_name' => __('Last Name', 'event_espresso'),
226
-            'email' => __('Email', 'event_espresso'),
227
-            'company' => __('Company', 'event_espresso'),
228
-            'address' => __('Address', 'event_espresso'),
229
-            'address2' => __('Address2', 'event_espresso'),
230
-            'city' => __('City', 'event_espresso'),
231
-            'state' => __('State', 'event_espresso'),
232
-            'country' => __('Country', 'event_espresso'),
233
-            'zip' =>  __('Zip', 'event_espresso'),
234
-            'phone' => __('Phone', 'event_espresso'),
235
-            'fax' => __('Fax', 'event_espresso'),
236
-            'cvv' => __('CVV', 'event_espresso')
237
-        );
238
-    }
216
+	/**
217
+	 * Returns an array where keys are the slugs for billing inputs, and values
218
+	 * are their i18n names
219
+	 * @return array
220
+	 */
221
+	public function billing_input_names()
222
+	{
223
+		return array(
224
+			'first_name' => __('First Name', 'event_espresso'),
225
+			'last_name' => __('Last Name', 'event_espresso'),
226
+			'email' => __('Email', 'event_espresso'),
227
+			'company' => __('Company', 'event_espresso'),
228
+			'address' => __('Address', 'event_espresso'),
229
+			'address2' => __('Address2', 'event_espresso'),
230
+			'city' => __('City', 'event_espresso'),
231
+			'state' => __('State', 'event_espresso'),
232
+			'country' => __('Country', 'event_espresso'),
233
+			'zip' =>  __('Zip', 'event_espresso'),
234
+			'phone' => __('Phone', 'event_espresso'),
235
+			'fax' => __('Fax', 'event_espresso'),
236
+			'cvv' => __('CVV', 'event_espresso')
237
+		);
238
+	}
239 239
     
240
-    /**
241
-     * Overrides parent so we always have all billing inputs in the returned array,
242
-     * not just the ones included at the time. This helps simplify the gateway code
243
-     *
244
-     * @param EE_Billing_Info_Form $billing_form
245
-     * @return array
246
-     */
247
-    protected function _get_billing_values_from_form($billing_form)
248
-    {
249
-        $all_billing_values_empty = array();
250
-        foreach (array_keys($this->billing_input_names()) as $input_name) {
251
-            $all_billing_values_empty[ $input_name ] = '';
252
-        }
253
-        return array_merge(
254
-            $all_billing_values_empty,
255
-            parent::_get_billing_values_from_form($billing_form)
256
-        );
257
-    }
240
+	/**
241
+	 * Overrides parent so we always have all billing inputs in the returned array,
242
+	 * not just the ones included at the time. This helps simplify the gateway code
243
+	 *
244
+	 * @param EE_Billing_Info_Form $billing_form
245
+	 * @return array
246
+	 */
247
+	protected function _get_billing_values_from_form($billing_form)
248
+	{
249
+		$all_billing_values_empty = array();
250
+		foreach (array_keys($this->billing_input_names()) as $input_name) {
251
+			$all_billing_values_empty[ $input_name ] = '';
252
+		}
253
+		return array_merge(
254
+			$all_billing_values_empty,
255
+			parent::_get_billing_values_from_form($billing_form)
256
+		);
257
+	}
258 258
 
259 259
 
260 260
 
261
-    /**
262
-     * Adds the help tab
263
-     * @see EE_PMT_Base::help_tabs_config()
264
-     * @return array
265
-     */
266
-    public function help_tabs_config()
267
-    {
268
-        return array(
269
-            $this->get_help_tab_name() => array(
270
-                'title' => __('Authorize.net AIM Settings', 'event_espresso'),
271
-                'filename' => 'payment_methods_overview_aim'
272
-            ),
273
-        );
274
-    }
261
+	/**
262
+	 * Adds the help tab
263
+	 * @see EE_PMT_Base::help_tabs_config()
264
+	 * @return array
265
+	 */
266
+	public function help_tabs_config()
267
+	{
268
+		return array(
269
+			$this->get_help_tab_name() => array(
270
+				'title' => __('Authorize.net AIM Settings', 'event_espresso'),
271
+				'filename' => 'payment_methods_overview_aim'
272
+			),
273
+		);
274
+	}
275 275
 
276 276
 
277 277
 
278
-    /**
279
-     * Gets a list of instructions and/or information regarding how the payment is to be completed
280
-     * @return string
281
-     */
282
-    public function payment_information()
283
-    {
284
-        // TODO: Implement payment_information() method.
285
-    }
278
+	/**
279
+	 * Gets a list of instructions and/or information regarding how the payment is to be completed
280
+	 * @return string
281
+	 */
282
+	public function payment_information()
283
+	{
284
+		// TODO: Implement payment_information() method.
285
+	}
286 286
 }
Please login to merge, or discard this patch.
payment_methods/Aim/help_tabs/payment_methods_overview_aim.help_tab.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
         <?php _e('Change the image that is used for this payment gateway.', 'event_espresso'); ?>
76 76
     </li>
77 77
     <li>
78
-        <strong><?php esc_html_e('Note About Special Characters', 'event_espresso');?></strong>
79
-        <?php esc_html_e('If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', 'event_espresso');?></li>
78
+        <strong><?php esc_html_e('Note About Special Characters', 'event_espresso'); ?></strong>
79
+        <?php esc_html_e('If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', 'event_espresso'); ?></li>
80 80
     </li>
81 81
 </ul>
82 82
\ No newline at end of file
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 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
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            '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.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'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.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.002');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.002');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 1 patch
Indentation   +1322 added lines, -1322 removed lines patch added patch discarded remove patch
@@ -16,1335 +16,1335 @@
 block discarded – undo
16 16
 class EED_Messages extends EED_Module
17 17
 {
18 18
 
19
-    /**
20
-     * This holds the EE_messages controller
21
-     *
22
-     * @deprecated 4.9.0
23
-     * @var EE_messages $_EEMSG
24
-     */
25
-    protected static $_EEMSG;
26
-
27
-    /**
28
-     * @type EE_Message_Resource_Manager $_message_resource_manager
29
-     */
30
-    protected static $_message_resource_manager;
31
-
32
-    /**
33
-     * This holds the EE_Messages_Processor business class.
34
-     *
35
-     * @type EE_Messages_Processor
36
-     */
37
-    protected static $_MSG_PROCESSOR;
38
-
39
-    /**
40
-     * holds all the paths for various messages components.
41
-     * Utilized by autoloader registry
42
-     *
43
-     * @var array
44
-     */
45
-    protected static $_MSG_PATHS;
46
-
47
-
48
-    /**
49
-     * This will hold an array of messages template packs that are registered in the messages system.
50
-     * Format is:
51
-     * array(
52
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
-     * )
54
-     *
55
-     * @var EE_Messages_Template_Pack[]
56
-     */
57
-    protected static $_TMP_PACKS = array();
58
-
59
-
60
-    /**
61
-     * @return EED_Messages
62
-     */
63
-    public static function instance()
64
-    {
65
-        return parent::get_instance(__CLASS__);
66
-    }
67
-
68
-
69
-    /**
70
-     *  set_hooks - for hooking into EE Core, other modules, etc
71
-     *
72
-     * @since 4.5.0
73
-     * @return    void
74
-     */
75
-    public static function set_hooks()
76
-    {
77
-        // actions
78
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
79
-        add_action(
80
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
81
-            array('EED_Messages', 'maybe_registration'),
82
-            10,
83
-            2
84
-        );
85
-        // filters
86
-        add_filter(
87
-            'FHEE__EE_Registration__receipt_url__receipt_url',
88
-            array('EED_Messages', 'registration_message_trigger_url'),
89
-            10,
90
-            4
91
-        );
92
-        add_filter(
93
-            'FHEE__EE_Registration__invoice_url__invoice_url',
94
-            array('EED_Messages', 'registration_message_trigger_url'),
95
-            10,
96
-            4
97
-        );
98
-        // register routes
99
-        self::_register_routes();
100
-    }
101
-
102
-    /**
103
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
104
-     *
105
-     * @access    public
106
-     * @return    void
107
-     */
108
-    public static function set_hooks_admin()
109
-    {
110
-        // actions
111
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
112
-        add_action(
113
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
114
-            array('EED_Messages', 'payment_reminder'),
115
-            10
116
-        );
117
-        add_action(
118
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
119
-            array('EED_Messages', 'maybe_registration'),
120
-            10,
121
-            3
122
-        );
123
-        add_action(
124
-            'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
125
-            array('EED_Messages', 'send_newsletter_message'),
126
-            10,
127
-            2
128
-        );
129
-        add_action(
130
-            'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
131
-            array('EED_Messages', 'cancelled_registration'),
132
-            10
133
-        );
134
-        add_action(
135
-            'AHEE__EE_Admin_Page___process_admin_payment_notification',
136
-            array('EED_Messages', 'process_admin_payment'),
137
-            10,
138
-            1
139
-        );
140
-        // filters
141
-        add_filter(
142
-            'FHEE__EE_Admin_Page___process_resend_registration__success',
143
-            array('EED_Messages', 'process_resend'),
144
-            10,
145
-            2
146
-        );
147
-        add_filter(
148
-            'FHEE__EE_Registration__receipt_url__receipt_url',
149
-            array('EED_Messages', 'registration_message_trigger_url'),
150
-            10,
151
-            4
152
-        );
153
-        add_filter(
154
-            'FHEE__EE_Registration__invoice_url__invoice_url',
155
-            array('EED_Messages', 'registration_message_trigger_url'),
156
-            10,
157
-            4
158
-        );
159
-    }
160
-
161
-
162
-    /**
163
-     * All the message triggers done by route go in here.
164
-     *
165
-     * @since 4.5.0
166
-     * @return void
167
-     */
168
-    protected static function _register_routes()
169
-    {
170
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
171
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
172
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
173
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
174
-        do_action('AHEE__EED_Messages___register_routes');
175
-    }
176
-
177
-
178
-    /**
179
-     * This is called when a browser display trigger is executed.
180
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
181
-     * browser.
182
-     *
183
-     * @since 4.9.0
184
-     * @param WP $WP
185
-     * @throws EE_Error
186
-     * @throws InvalidArgumentException
187
-     * @throws ReflectionException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     */
191
-    public function browser_trigger($WP)
192
-    {
193
-        // ensure controller is loaded
194
-        self::_load_controller();
195
-        $token = EE_Registry::instance()->REQ->get('token');
196
-        try {
197
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
198
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
199
-        } catch (EE_Error $e) {
200
-            $error_msg = __(
201
-                'Please note that a system message failed to send due to a technical issue.',
202
-                'event_espresso'
203
-            );
204
-            // add specific message for developers if WP_DEBUG in on
205
-            $error_msg .= '||' . $e->getMessage();
206
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
207
-        }
208
-    }
209
-
210
-
211
-    /**
212
-     * This is called when a browser error trigger is executed.
213
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
214
-     * message and display it.
215
-     *
216
-     * @since 4.9.0
217
-     * @param $WP
218
-     * @throws EE_Error
219
-     * @throws InvalidArgumentException
220
-     * @throws InvalidDataTypeException
221
-     * @throws InvalidInterfaceException
222
-     */
223
-    public function browser_error_trigger($WP)
224
-    {
225
-        $token = EE_Registry::instance()->REQ->get('token');
226
-        if ($token) {
227
-            $message = EEM_Message::instance()->get_one_by_token($token);
228
-            if ($message instanceof EE_Message) {
229
-                header('HTTP/1.1 200 OK');
230
-                $error_msg = nl2br($message->error_message());
231
-                ?>
19
+	/**
20
+	 * This holds the EE_messages controller
21
+	 *
22
+	 * @deprecated 4.9.0
23
+	 * @var EE_messages $_EEMSG
24
+	 */
25
+	protected static $_EEMSG;
26
+
27
+	/**
28
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
29
+	 */
30
+	protected static $_message_resource_manager;
31
+
32
+	/**
33
+	 * This holds the EE_Messages_Processor business class.
34
+	 *
35
+	 * @type EE_Messages_Processor
36
+	 */
37
+	protected static $_MSG_PROCESSOR;
38
+
39
+	/**
40
+	 * holds all the paths for various messages components.
41
+	 * Utilized by autoloader registry
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected static $_MSG_PATHS;
46
+
47
+
48
+	/**
49
+	 * This will hold an array of messages template packs that are registered in the messages system.
50
+	 * Format is:
51
+	 * array(
52
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
+	 * )
54
+	 *
55
+	 * @var EE_Messages_Template_Pack[]
56
+	 */
57
+	protected static $_TMP_PACKS = array();
58
+
59
+
60
+	/**
61
+	 * @return EED_Messages
62
+	 */
63
+	public static function instance()
64
+	{
65
+		return parent::get_instance(__CLASS__);
66
+	}
67
+
68
+
69
+	/**
70
+	 *  set_hooks - for hooking into EE Core, other modules, etc
71
+	 *
72
+	 * @since 4.5.0
73
+	 * @return    void
74
+	 */
75
+	public static function set_hooks()
76
+	{
77
+		// actions
78
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
79
+		add_action(
80
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
81
+			array('EED_Messages', 'maybe_registration'),
82
+			10,
83
+			2
84
+		);
85
+		// filters
86
+		add_filter(
87
+			'FHEE__EE_Registration__receipt_url__receipt_url',
88
+			array('EED_Messages', 'registration_message_trigger_url'),
89
+			10,
90
+			4
91
+		);
92
+		add_filter(
93
+			'FHEE__EE_Registration__invoice_url__invoice_url',
94
+			array('EED_Messages', 'registration_message_trigger_url'),
95
+			10,
96
+			4
97
+		);
98
+		// register routes
99
+		self::_register_routes();
100
+	}
101
+
102
+	/**
103
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
104
+	 *
105
+	 * @access    public
106
+	 * @return    void
107
+	 */
108
+	public static function set_hooks_admin()
109
+	{
110
+		// actions
111
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
112
+		add_action(
113
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
114
+			array('EED_Messages', 'payment_reminder'),
115
+			10
116
+		);
117
+		add_action(
118
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
119
+			array('EED_Messages', 'maybe_registration'),
120
+			10,
121
+			3
122
+		);
123
+		add_action(
124
+			'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
125
+			array('EED_Messages', 'send_newsletter_message'),
126
+			10,
127
+			2
128
+		);
129
+		add_action(
130
+			'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
131
+			array('EED_Messages', 'cancelled_registration'),
132
+			10
133
+		);
134
+		add_action(
135
+			'AHEE__EE_Admin_Page___process_admin_payment_notification',
136
+			array('EED_Messages', 'process_admin_payment'),
137
+			10,
138
+			1
139
+		);
140
+		// filters
141
+		add_filter(
142
+			'FHEE__EE_Admin_Page___process_resend_registration__success',
143
+			array('EED_Messages', 'process_resend'),
144
+			10,
145
+			2
146
+		);
147
+		add_filter(
148
+			'FHEE__EE_Registration__receipt_url__receipt_url',
149
+			array('EED_Messages', 'registration_message_trigger_url'),
150
+			10,
151
+			4
152
+		);
153
+		add_filter(
154
+			'FHEE__EE_Registration__invoice_url__invoice_url',
155
+			array('EED_Messages', 'registration_message_trigger_url'),
156
+			10,
157
+			4
158
+		);
159
+	}
160
+
161
+
162
+	/**
163
+	 * All the message triggers done by route go in here.
164
+	 *
165
+	 * @since 4.5.0
166
+	 * @return void
167
+	 */
168
+	protected static function _register_routes()
169
+	{
170
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
171
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
172
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
173
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
174
+		do_action('AHEE__EED_Messages___register_routes');
175
+	}
176
+
177
+
178
+	/**
179
+	 * This is called when a browser display trigger is executed.
180
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
181
+	 * browser.
182
+	 *
183
+	 * @since 4.9.0
184
+	 * @param WP $WP
185
+	 * @throws EE_Error
186
+	 * @throws InvalidArgumentException
187
+	 * @throws ReflectionException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 */
191
+	public function browser_trigger($WP)
192
+	{
193
+		// ensure controller is loaded
194
+		self::_load_controller();
195
+		$token = EE_Registry::instance()->REQ->get('token');
196
+		try {
197
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
198
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
199
+		} catch (EE_Error $e) {
200
+			$error_msg = __(
201
+				'Please note that a system message failed to send due to a technical issue.',
202
+				'event_espresso'
203
+			);
204
+			// add specific message for developers if WP_DEBUG in on
205
+			$error_msg .= '||' . $e->getMessage();
206
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
207
+		}
208
+	}
209
+
210
+
211
+	/**
212
+	 * This is called when a browser error trigger is executed.
213
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
214
+	 * message and display it.
215
+	 *
216
+	 * @since 4.9.0
217
+	 * @param $WP
218
+	 * @throws EE_Error
219
+	 * @throws InvalidArgumentException
220
+	 * @throws InvalidDataTypeException
221
+	 * @throws InvalidInterfaceException
222
+	 */
223
+	public function browser_error_trigger($WP)
224
+	{
225
+		$token = EE_Registry::instance()->REQ->get('token');
226
+		if ($token) {
227
+			$message = EEM_Message::instance()->get_one_by_token($token);
228
+			if ($message instanceof EE_Message) {
229
+				header('HTTP/1.1 200 OK');
230
+				$error_msg = nl2br($message->error_message());
231
+				?>
232 232
                 <!DOCTYPE html>
233 233
                 <html>
234 234
                 <head></head>
235 235
                 <body>
236 236
                 <?php echo empty($error_msg)
237
-                    ? esc_html__(
238
-                        'Unfortunately, we were unable to capture the error message for this message.',
239
-                        'event_espresso'
240
-                    )
241
-                    : wp_kses(
242
-                        $error_msg,
243
-                        array(
244
-                            'a'      => array(
245
-                                'href'  => array(),
246
-                                'title' => array(),
247
-                            ),
248
-                            'span'   => array(),
249
-                            'div'    => array(),
250
-                            'p'      => array(),
251
-                            'strong' => array(),
252
-                            'em'     => array(),
253
-                            'br'     => array(),
254
-                        )
255
-                    ); ?>
237
+					? esc_html__(
238
+						'Unfortunately, we were unable to capture the error message for this message.',
239
+						'event_espresso'
240
+					)
241
+					: wp_kses(
242
+						$error_msg,
243
+						array(
244
+							'a'      => array(
245
+								'href'  => array(),
246
+								'title' => array(),
247
+							),
248
+							'span'   => array(),
249
+							'div'    => array(),
250
+							'p'      => array(),
251
+							'strong' => array(),
252
+							'em'     => array(),
253
+							'br'     => array(),
254
+						)
255
+					); ?>
256 256
                 </body>
257 257
                 </html>
258 258
                 <?php
259
-                exit;
260
-            }
261
-        }
262
-        return;
263
-    }
264
-
265
-
266
-    /**
267
-     *  This runs when the msg_url_trigger route has initiated.
268
-     *
269
-     * @since 4.5.0
270
-     * @param WP $WP
271
-     * @throws EE_Error
272
-     * @throws InvalidArgumentException
273
-     * @throws ReflectionException
274
-     * @throws InvalidDataTypeException
275
-     * @throws InvalidInterfaceException
276
-     */
277
-    public function run($WP)
278
-    {
279
-        // ensure controller is loaded
280
-        self::_load_controller();
281
-        // attempt to process message
282
-        try {
283
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
284
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
285
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
286
-        } catch (EE_Error $e) {
287
-            $error_msg = __(
288
-                'Please note that a system message failed to send due to a technical issue.',
289
-                'event_espresso'
290
-            );
291
-            // add specific message for developers if WP_DEBUG in on
292
-            $error_msg .= '||' . $e->getMessage();
293
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
294
-        }
295
-    }
296
-
297
-
298
-    /**
299
-     * This is triggered by the 'msg_cron_trigger' route.
300
-     *
301
-     * @param WP $WP
302
-     */
303
-    public function execute_batch_request($WP)
304
-    {
305
-        $this->run_cron();
306
-        header('HTTP/1.1 200 OK');
307
-        exit();
308
-    }
309
-
310
-
311
-    /**
312
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
313
-     * request.
314
-     */
315
-    public function run_cron()
316
-    {
317
-        self::_load_controller();
318
-        // get required vars
319
-        $cron_type = EE_Registry::instance()->REQ->get('type');
320
-        $transient_key = EE_Registry::instance()->REQ->get('key');
321
-
322
-        // now let's verify transient, if not valid exit immediately
323
-        if (! get_transient($transient_key)) {
324
-            /**
325
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user
326
-             * request.
327
-             */
328
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
329
-        }
330
-
331
-        // if made it here, lets' delete the transient to keep the db clean
332
-        delete_transient($transient_key);
333
-
334
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
335
-            $method = 'batch_' . $cron_type . '_from_queue';
336
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
337
-                self::$_MSG_PROCESSOR->$method();
338
-            } else {
339
-                // no matching task
340
-                /**
341
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user
342
-                 * request.
343
-                 */
344
-                trigger_error(
345
-                    esc_attr(
346
-                        sprintf(
347
-                            __('There is no task corresponding to this route %s', 'event_espresso'),
348
-                            $cron_type
349
-                        )
350
-                    )
351
-                );
352
-            }
353
-        }
354
-
355
-        do_action('FHEE__EED_Messages__run_cron__end');
356
-    }
357
-
358
-
359
-    /**
360
-     * This is used to retrieve the template pack for the given name.
361
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
362
-     * the default template pack is returned.
363
-     *
364
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
365
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
366
-     *                                   in generating the Pack class name).
367
-     * @return EE_Messages_Template_Pack
368
-     * @throws EE_Error
369
-     * @throws InvalidArgumentException
370
-     * @throws ReflectionException
371
-     * @throws InvalidDataTypeException
372
-     * @throws InvalidInterfaceException
373
-     */
374
-    public static function get_template_pack($template_pack_name)
375
-    {
376
-        EE_Registry::instance()->load_helper('MSG_Template');
377
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
378
-    }
379
-
380
-
381
-    /**
382
-     * Retrieves an array of all template packs.
383
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
384
-     *
385
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
386
-     * @return EE_Messages_Template_Pack[]
387
-     * @throws EE_Error
388
-     * @throws InvalidArgumentException
389
-     * @throws ReflectionException
390
-     * @throws InvalidDataTypeException
391
-     * @throws InvalidInterfaceException
392
-     */
393
-    public static function get_template_packs()
394
-    {
395
-        EE_Registry::instance()->load_helper('MSG_Template');
396
-
397
-        // for backward compat, let's make sure this returns in the same format as originally.
398
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
399
-        $template_pack_collection->rewind();
400
-        $template_packs = array();
401
-        while ($template_pack_collection->valid()) {
402
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
403
-            $template_pack_collection->next();
404
-        }
405
-        return $template_packs;
406
-    }
407
-
408
-
409
-    /**
410
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
411
-     *
412
-     * @since 4.5.0
413
-     * @return void
414
-     * @throws EE_Error
415
-     */
416
-    public static function set_autoloaders()
417
-    {
418
-        if (empty(self::$_MSG_PATHS)) {
419
-            self::_set_messages_paths();
420
-            foreach (self::$_MSG_PATHS as $path) {
421
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
422
-            }
423
-            // add aliases
424
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
425
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
426
-        }
427
-    }
428
-
429
-
430
-    /**
431
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
432
-     * for use by the Messages Autoloaders
433
-     *
434
-     * @since 4.5.0
435
-     * @return void.
436
-     */
437
-    protected static function _set_messages_paths()
438
-    {
439
-        $dir_ref = array(
440
-            'messages/message_type',
441
-            'messages/messenger',
442
-            'messages/defaults',
443
-            'messages/defaults/email',
444
-            'messages/data_class',
445
-            'messages/validators',
446
-            'messages/validators/email',
447
-            'messages/validators/html',
448
-            'shortcodes',
449
-        );
450
-        $paths = array();
451
-        foreach ($dir_ref as $index => $dir) {
452
-            $paths[ $index ] = EE_LIBRARIES . $dir;
453
-        }
454
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
455
-    }
456
-
457
-
458
-    /**
459
-     * Takes care of loading dependencies
460
-     *
461
-     * @since 4.5.0
462
-     * @return void
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws ReflectionException
466
-     * @throws InvalidDataTypeException
467
-     * @throws InvalidInterfaceException
468
-     */
469
-    protected static function _load_controller()
470
-    {
471
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
472
-            EE_Registry::instance()->load_core('Request_Handler');
473
-            self::set_autoloaders();
474
-            self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
475
-            self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
476
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
477
-        }
478
-    }
479
-
480
-
481
-    /**
482
-     * @param EE_Transaction $transaction
483
-     * @throws EE_Error
484
-     * @throws InvalidArgumentException
485
-     * @throws InvalidDataTypeException
486
-     * @throws InvalidInterfaceException
487
-     * @throws ReflectionException
488
-     */
489
-    public static function payment_reminder(EE_Transaction $transaction)
490
-    {
491
-        self::_load_controller();
492
-        $data = array($transaction, null);
493
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
494
-    }
495
-
496
-
497
-    /**
498
-     * Any messages triggers for after successful gateway payments should go in here.
499
-     *
500
-     * @param EE_Transaction  $transaction object
501
-     * @param EE_Payment|null $payment     object
502
-     * @return void
503
-     * @throws EE_Error
504
-     * @throws InvalidArgumentException
505
-     * @throws ReflectionException
506
-     * @throws InvalidDataTypeException
507
-     * @throws InvalidInterfaceException
508
-     */
509
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
510
-    {
511
-        // if there's no payment object, then we cannot do a payment type message!
512
-        if (! $payment instanceof EE_Payment) {
513
-            return;
514
-        }
515
-        self::_load_controller();
516
-        $data = array($transaction, $payment);
517
-        EE_Registry::instance()->load_helper('MSG_Template');
518
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
519
-        // if payment amount is less than 0 then switch to payment_refund message type.
520
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
521
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
522
-    }
523
-
524
-
525
-    /**
526
-     * @param EE_Transaction $transaction
527
-     * @throws EE_Error
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidDataTypeException
530
-     * @throws InvalidInterfaceException
531
-     * @throws ReflectionException
532
-     */
533
-    public static function cancelled_registration(EE_Transaction $transaction)
534
-    {
535
-        self::_load_controller();
536
-        $data = array($transaction, null);
537
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
538
-    }
539
-
540
-
541
-    /**
542
-     * Trigger for Registration messages
543
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
544
-     * incoming transaction.
545
-     *
546
-     * @param EE_Registration $registration
547
-     * @param array           $extra_details
548
-     * @return void
549
-     * @throws EE_Error
550
-     * @throws InvalidArgumentException
551
-     * @throws InvalidDataTypeException
552
-     * @throws InvalidInterfaceException
553
-     * @throws ReflectionException
554
-     * @throws EntityNotFoundException
555
-     */
556
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
557
-    {
558
-
559
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
560
-            // no messages please
561
-            return;
562
-        }
563
-
564
-        // get all non-trashed registrations so we make sure we send messages for the right status.
565
-        $all_registrations = $registration->transaction()->registrations(
566
-            array(
567
-                array('REG_deleted' => false),
568
-                'order_by' => array(
569
-                    'Event.EVT_name'     => 'ASC',
570
-                    'Attendee.ATT_lname' => 'ASC',
571
-                    'Attendee.ATT_fname' => 'ASC',
572
-                ),
573
-            )
574
-        );
575
-        // cached array of statuses so we only trigger messages once per status.
576
-        $statuses_sent = array();
577
-        self::_load_controller();
578
-        $mtgs = array();
579
-
580
-        // loop through registrations and trigger messages once per status.
581
-        foreach ($all_registrations as $reg) {
582
-            // already triggered?
583
-            if (in_array($reg->status_ID(), $statuses_sent)) {
584
-                continue;
585
-            }
586
-
587
-            $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
588
-            $mtgs = array_merge(
589
-                $mtgs,
590
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
591
-                    $message_type,
592
-                    array($registration->transaction(), null, $reg->status_ID())
593
-                )
594
-            );
595
-            $statuses_sent[] = $reg->status_ID();
596
-        }
597
-
598
-        if (count($statuses_sent) > 1) {
599
-            $mtgs = array_merge(
600
-                $mtgs,
601
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
602
-                    'registration_summary',
603
-                    array($registration->transaction(), null)
604
-                )
605
-            );
606
-        }
607
-
608
-        // batch queue and initiate request
609
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
610
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
611
-    }
612
-
613
-
614
-    /**
615
-     * This is a helper method used to very whether a registration notification should be sent or
616
-     * not.  Prevents duplicate notifications going out for registration context notifications.
617
-     *
618
-     * @param EE_Registration $registration  [description]
619
-     * @param array           $extra_details [description]
620
-     * @return bool          true = send away, false = nope halt the presses.
621
-     */
622
-    protected static function _verify_registration_notification_send(
623
-        EE_Registration $registration,
624
-        $extra_details = array()
625
-    ) {
626
-        if (! $registration->is_primary_registrant()) {
627
-            return false;
628
-        }
629
-        // first we check if we're in admin and not doing front ajax
630
-        if (is_admin() && ! EE_FRONT_AJAX) {
631
-            // make sure appropriate admin params are set for sending messages
632
-            if (empty($_REQUEST['txn_reg_status_change']['send_notifications'])
633
-                || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])
634
-            ) {
635
-                // no messages sent please.
636
-                return false;
637
-            }
638
-        } else {
639
-            // frontend request (either regular or via AJAX)
640
-            // TXN is NOT finalized ?
641
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
642
-                return false;
643
-            }
644
-            // return visit but nothing changed ???
645
-            if (isset($extra_details['revisit'], $extra_details['status_updates']) &&
646
-                $extra_details['revisit'] && ! $extra_details['status_updates']
647
-            ) {
648
-                return false;
649
-            }
650
-            // NOT sending messages && reg status is something other than "Not-Approved"
651
-            if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
652
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
653
-            ) {
654
-                return false;
655
-            }
656
-        }
657
-        // release the kraken
658
-        return true;
659
-    }
660
-
661
-
662
-    /**
663
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
664
-     * status id.
665
-     *
666
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
667
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
668
-     * @param string $reg_status
669
-     * @return array
670
-     * @throws EE_Error
671
-     * @throws InvalidArgumentException
672
-     * @throws ReflectionException
673
-     * @throws InvalidDataTypeException
674
-     * @throws InvalidInterfaceException
675
-     */
676
-    protected static function _get_reg_status_array($reg_status = '')
677
-    {
678
-        EE_Registry::instance()->load_helper('MSG_Template');
679
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
680
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
681
-            : EEH_MSG_Template::reg_status_to_message_type_array();
682
-    }
683
-
684
-
685
-    /**
686
-     * Simply returns the payment message type for the given payment status.
687
-     *
688
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
689
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
690
-     * @param string $payment_status The payment status being matched.
691
-     * @return bool|string The payment message type slug matching the status or false if no match.
692
-     * @throws EE_Error
693
-     * @throws InvalidArgumentException
694
-     * @throws ReflectionException
695
-     * @throws InvalidDataTypeException
696
-     * @throws InvalidInterfaceException
697
-     */
698
-    protected static function _get_payment_message_type($payment_status)
699
-    {
700
-        EE_Registry::instance()->load_helper('MSG_Template');
701
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
702
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
703
-            : false;
704
-    }
705
-
706
-
707
-    /**
708
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
709
-     *
710
-     * @access public
711
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
712
-     * @return bool success/fail
713
-     * @throws EE_Error
714
-     * @throws InvalidArgumentException
715
-     * @throws InvalidDataTypeException
716
-     * @throws InvalidInterfaceException
717
-     * @throws ReflectionException
718
-     */
719
-    public static function process_resend($req_data)
720
-    {
721
-        self::_load_controller();
722
-
723
-        // if $msgID in this request then skip to the new resend_message
724
-        if (EE_Registry::instance()->REQ->get('MSG_ID')) {
725
-            return self::resend_message();
726
-        }
727
-
728
-        // make sure any incoming request data is set on the REQ so that it gets picked up later.
729
-        $req_data = (array) $req_data;
730
-        foreach ($req_data as $request_key => $request_value) {
731
-            EE_Registry::instance()->REQ->set($request_key, $request_value);
732
-        }
733
-
734
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request(
735
-        )) {
736
-            return false;
737
-        }
738
-
739
-        try {
740
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
741
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
742
-        } catch (EE_Error $e) {
743
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
744
-            return false;
745
-        }
746
-        EE_Error::add_success(
747
-            __('Messages have been successfully queued for generation and sending.', 'event_espresso')
748
-        );
749
-        return true; // everything got queued.
750
-    }
751
-
752
-
753
-    /**
754
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
755
-     *
756
-     * @return bool
757
-     * @throws EE_Error
758
-     * @throws InvalidArgumentException
759
-     * @throws InvalidDataTypeException
760
-     * @throws InvalidInterfaceException
761
-     * @throws ReflectionException
762
-     */
763
-    public static function resend_message()
764
-    {
765
-        self::_load_controller();
766
-
767
-        $msgID = EE_Registry::instance()->REQ->get('MSG_ID');
768
-        if (! $msgID) {
769
-            EE_Error::add_error(
770
-                __(
771
-                    'Something went wrong because there is no "MSG_ID" value in the request',
772
-                    'event_espresso'
773
-                ),
774
-                __FILE__,
775
-                __FUNCTION__,
776
-                __LINE__
777
-            );
778
-            return false;
779
-        }
780
-
781
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
782
-
783
-        // setup success message.
784
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
785
-        EE_Error::add_success(
786
-            sprintf(
787
-                _n(
788
-                    'There was %d message queued for resending.',
789
-                    'There were %d messages queued for resending.',
790
-                    $count_ready_for_resend,
791
-                    'event_espresso'
792
-                ),
793
-                $count_ready_for_resend
794
-            )
795
-        );
796
-        return true;
797
-    }
798
-
799
-
800
-    /**
801
-     * Message triggers for manual payment applied by admin
802
-     *
803
-     * @param  EE_Payment $payment EE_payment object
804
-     * @return bool success/fail
805
-     * @throws EE_Error
806
-     * @throws InvalidArgumentException
807
-     * @throws ReflectionException
808
-     * @throws InvalidDataTypeException
809
-     * @throws InvalidInterfaceException
810
-     */
811
-    public static function process_admin_payment(EE_Payment $payment)
812
-    {
813
-        EE_Registry::instance()->load_helper('MSG_Template');
814
-        // we need to get the transaction object
815
-        $transaction = $payment->transaction();
816
-        if ($transaction instanceof EE_Transaction) {
817
-            $data = array($transaction, $payment);
818
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
819
-
820
-            // if payment amount is less than 0 then switch to payment_refund message type.
821
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
822
-
823
-            // if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
824
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
825
-                ? false : $message_type;
826
-
827
-            self::_load_controller();
828
-
829
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
830
-
831
-            // get count of queued for generation
832
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
833
-                array(
834
-                    EEM_Message::status_incomplete,
835
-                    EEM_Message::status_idle,
836
-                )
837
-            );
838
-
839
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
840
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
841
-                return true;
842
-            } else {
843
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
844
-                    EEM_Message::instance()->stati_indicating_failed_sending()
845
-                );
846
-                /**
847
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
848
-                 * IMMEDIATE generation.
849
-                 */
850
-                if ($count_failed > 0) {
851
-                    EE_Error::add_error(
852
-                        sprintf(
853
-                            _n(
854
-                                'The payment notification generation failed.',
855
-                                '%d payment notifications failed being sent.',
856
-                                $count_failed,
857
-                                'event_espresso'
858
-                            ),
859
-                            $count_failed
860
-                        ),
861
-                        __FILE__,
862
-                        __FUNCTION__,
863
-                        __LINE__
864
-                    );
865
-
866
-                    return false;
867
-                } else {
868
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
869
-                    return true;
870
-                }
871
-            }
872
-        } else {
873
-            EE_Error::add_error(
874
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
875
-                'event_espresso'
876
-            );
877
-            return false;
878
-        }
879
-    }
880
-
881
-
882
-    /**
883
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
884
-     *
885
-     * @since   4.3.0
886
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
887
-     * @param  int               $grp_id        a specific message template group id.
888
-     * @return void
889
-     * @throws EE_Error
890
-     * @throws InvalidArgumentException
891
-     * @throws InvalidDataTypeException
892
-     * @throws InvalidInterfaceException
893
-     * @throws ReflectionException
894
-     */
895
-    public static function send_newsletter_message($registrations, $grp_id)
896
-    {
897
-        // make sure mtp is id and set it in the EE_Request Handler later messages setup.
898
-        EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id);
899
-        self::_load_controller();
900
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
901
-    }
902
-
903
-
904
-    /**
905
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
906
-     *
907
-     * @since   4.3.0
908
-     * @param    string          $registration_message_trigger_url
909
-     * @param    EE_Registration $registration
910
-     * @param string             $messenger
911
-     * @param string             $message_type
912
-     * @return string
913
-     * @throws EE_Error
914
-     * @throws InvalidArgumentException
915
-     * @throws InvalidDataTypeException
916
-     * @throws InvalidInterfaceException
917
-     */
918
-    public static function registration_message_trigger_url(
919
-        $registration_message_trigger_url,
920
-        EE_Registration $registration,
921
-        $messenger = 'html',
922
-        $message_type = 'invoice'
923
-    ) {
924
-        // whitelist $messenger
925
-        switch ($messenger) {
926
-            case 'pdf':
927
-                $sending_messenger = 'pdf';
928
-                $generating_messenger = 'html';
929
-                break;
930
-            case 'html':
931
-            default:
932
-                $sending_messenger = 'html';
933
-                $generating_messenger = 'html';
934
-                break;
935
-        }
936
-        // whitelist $message_type
937
-        switch ($message_type) {
938
-            case 'receipt':
939
-                $message_type = 'receipt';
940
-                break;
941
-            case 'invoice':
942
-            default:
943
-                $message_type = 'invoice';
944
-                break;
945
-        }
946
-        // verify that both the messenger AND the message type are active
947
-        if (EEH_MSG_Template::is_messenger_active($sending_messenger)
948
-            && EEH_MSG_Template::is_mt_active($message_type)
949
-        ) {
950
-            // 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?)
951
-            $template_query_params = array(
952
-                'MTP_is_active'    => true,
953
-                'MTP_messenger'    => $generating_messenger,
954
-                'MTP_message_type' => $message_type,
955
-                'Event.EVT_ID'     => $registration->event_ID(),
956
-            );
957
-            // get the message template group.
958
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
959
-            // if we don't have an EE_Message_Template_Group then return
960
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
961
-                // remove EVT_ID from query params so that global templates get picked up
962
-                unset($template_query_params['Event.EVT_ID']);
963
-                // get global template as the fallback
964
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
965
-            }
966
-            // if we don't have an EE_Message_Template_Group then return
967
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
968
-                return '';
969
-            }
970
-            // generate the URL
971
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
972
-                $sending_messenger,
973
-                $generating_messenger,
974
-                'purchaser',
975
-                $message_type,
976
-                $registration,
977
-                $msg_template_group->ID(),
978
-                $registration->transaction_ID()
979
-            );
980
-        }
981
-        return $registration_message_trigger_url;
982
-    }
983
-
984
-
985
-    /**
986
-     * Use to generate and return a message preview!
987
-     *
988
-     * @param  string $type      This should correspond with a valid message type
989
-     * @param  string $context   This should correspond with a valid context for the message type
990
-     * @param  string $messenger This should correspond with a valid messenger.
991
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
992
-     *                           preview
993
-     * @return bool|string The body of the message or if send is requested, sends.
994
-     * @throws EE_Error
995
-     * @throws InvalidArgumentException
996
-     * @throws InvalidDataTypeException
997
-     * @throws InvalidInterfaceException
998
-     * @throws ReflectionException
999
-     */
1000
-    public static function preview_message($type, $context, $messenger, $send = false)
1001
-    {
1002
-        self::_load_controller();
1003
-        $mtg = new EE_Message_To_Generate(
1004
-            $messenger,
1005
-            $type,
1006
-            array(),
1007
-            $context,
1008
-            true
1009
-        );
1010
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1011
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
1012
-            // loop through all content for the preview and remove any persisted records.
1013
-            $content = '';
1014
-            foreach ($generated_preview_queue->get_message_repository() as $message) {
1015
-                $content = $message->content();
1016
-                if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1017
-                    $message->delete();
1018
-                }
1019
-            }
1020
-            return $content;
1021
-        } else {
1022
-            return $generated_preview_queue;
1023
-        }
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
1029
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1030
-     * content found in the EE_Message objects in the queue.
1031
-     *
1032
-     * @since 4.9.0
1033
-     * @param string            $messenger            a string matching a valid active messenger in the system
1034
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
1035
-     *                                                type name is still required to send along the message type to the
1036
-     *                                                messenger because this is used for determining what specific
1037
-     *                                                variations might be loaded for the generated message.
1038
-     * @param EE_Messages_Queue $queue
1039
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1040
-     *                                                aggregate EE_Message object.
1041
-     * @return bool success or fail.
1042
-     * @throws EE_Error
1043
-     * @throws InvalidArgumentException
1044
-     * @throws ReflectionException
1045
-     * @throws InvalidDataTypeException
1046
-     * @throws InvalidInterfaceException
1047
-     */
1048
-    public static function send_message_with_messenger_only(
1049
-        $messenger,
1050
-        $message_type,
1051
-        EE_Messages_Queue $queue,
1052
-        $custom_subject = ''
1053
-    ) {
1054
-        self::_load_controller();
1055
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1056
-        $message_to_generate = EE_Registry::instance()->load_lib(
1057
-            'Message_To_Generate_From_Queue',
1058
-            array(
1059
-                $messenger,
1060
-                $message_type,
1061
-                $queue,
1062
-                $custom_subject,
1063
-            )
1064
-        );
1065
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1066
-    }
1067
-
1068
-
1069
-    /**
1070
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1071
-     *
1072
-     * @since 4.9.0
1073
-     * @param array $message_ids An array of message ids
1074
-     * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1075
-     *                           messages.
1076
-     * @throws EE_Error
1077
-     * @throws InvalidArgumentException
1078
-     * @throws InvalidDataTypeException
1079
-     * @throws InvalidInterfaceException
1080
-     * @throws ReflectionException
1081
-     */
1082
-    public static function generate_now($message_ids)
1083
-    {
1084
-        self::_load_controller();
1085
-        $messages = EEM_Message::instance()->get_all(
1086
-            array(
1087
-                0 => array(
1088
-                    'MSG_ID' => array('IN', $message_ids),
1089
-                    'STS_ID' => EEM_Message::status_incomplete,
1090
-                ),
1091
-            )
1092
-        );
1093
-        $generated_queue = false;
1094
-        if ($messages) {
1095
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1096
-        }
1097
-
1098
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1099
-            EE_Error::add_error(
1100
-                __(
1101
-                    '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.',
1102
-                    'event_espresso'
1103
-                ),
1104
-                __FILE__,
1105
-                __FUNCTION__,
1106
-                __LINE__
1107
-            );
1108
-        }
1109
-        return $generated_queue;
1110
-    }
1111
-
1112
-
1113
-    /**
1114
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1115
-     * EEM_Message::status_idle
1116
-     *
1117
-     * @since 4.9.0
1118
-     * @param $message_ids
1119
-     * @return bool|EE_Messages_Queue false if no messages sent.
1120
-     * @throws EE_Error
1121
-     * @throws InvalidArgumentException
1122
-     * @throws InvalidDataTypeException
1123
-     * @throws InvalidInterfaceException
1124
-     * @throws ReflectionException
1125
-     */
1126
-    public static function send_now($message_ids)
1127
-    {
1128
-        self::_load_controller();
1129
-        $messages = EEM_Message::instance()->get_all(
1130
-            array(
1131
-                0 => array(
1132
-                    'MSG_ID' => array('IN', $message_ids),
1133
-                    'STS_ID' => array(
1134
-                        'IN',
1135
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1136
-                    ),
1137
-                ),
1138
-            )
1139
-        );
1140
-        $sent_queue = false;
1141
-        if ($messages) {
1142
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1143
-        }
1144
-
1145
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1146
-            EE_Error::add_error(
1147
-                __(
1148
-                    '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.',
1149
-                    'event_espresso'
1150
-                ),
1151
-                __FILE__,
1152
-                __FUNCTION__,
1153
-                __LINE__
1154
-            );
1155
-        } else {
1156
-            // can count how many sent by using the messages in the queue
1157
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1158
-            if ($sent_count > 0) {
1159
-                EE_Error::add_success(
1160
-                    sprintf(
1161
-                        _n(
1162
-                            'There was %d message successfully sent.',
1163
-                            'There were %d messages successfully sent.',
1164
-                            $sent_count,
1165
-                            'event_espresso'
1166
-                        ),
1167
-                        $sent_count
1168
-                    )
1169
-                );
1170
-            } else {
1171
-                EE_Error::overwrite_errors();
1172
-                EE_Error::add_error(
1173
-                    __(
1174
-                        '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.
259
+				exit;
260
+			}
261
+		}
262
+		return;
263
+	}
264
+
265
+
266
+	/**
267
+	 *  This runs when the msg_url_trigger route has initiated.
268
+	 *
269
+	 * @since 4.5.0
270
+	 * @param WP $WP
271
+	 * @throws EE_Error
272
+	 * @throws InvalidArgumentException
273
+	 * @throws ReflectionException
274
+	 * @throws InvalidDataTypeException
275
+	 * @throws InvalidInterfaceException
276
+	 */
277
+	public function run($WP)
278
+	{
279
+		// ensure controller is loaded
280
+		self::_load_controller();
281
+		// attempt to process message
282
+		try {
283
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
284
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
285
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
286
+		} catch (EE_Error $e) {
287
+			$error_msg = __(
288
+				'Please note that a system message failed to send due to a technical issue.',
289
+				'event_espresso'
290
+			);
291
+			// add specific message for developers if WP_DEBUG in on
292
+			$error_msg .= '||' . $e->getMessage();
293
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
294
+		}
295
+	}
296
+
297
+
298
+	/**
299
+	 * This is triggered by the 'msg_cron_trigger' route.
300
+	 *
301
+	 * @param WP $WP
302
+	 */
303
+	public function execute_batch_request($WP)
304
+	{
305
+		$this->run_cron();
306
+		header('HTTP/1.1 200 OK');
307
+		exit();
308
+	}
309
+
310
+
311
+	/**
312
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
313
+	 * request.
314
+	 */
315
+	public function run_cron()
316
+	{
317
+		self::_load_controller();
318
+		// get required vars
319
+		$cron_type = EE_Registry::instance()->REQ->get('type');
320
+		$transient_key = EE_Registry::instance()->REQ->get('key');
321
+
322
+		// now let's verify transient, if not valid exit immediately
323
+		if (! get_transient($transient_key)) {
324
+			/**
325
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user
326
+			 * request.
327
+			 */
328
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
329
+		}
330
+
331
+		// if made it here, lets' delete the transient to keep the db clean
332
+		delete_transient($transient_key);
333
+
334
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
335
+			$method = 'batch_' . $cron_type . '_from_queue';
336
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
337
+				self::$_MSG_PROCESSOR->$method();
338
+			} else {
339
+				// no matching task
340
+				/**
341
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user
342
+				 * request.
343
+				 */
344
+				trigger_error(
345
+					esc_attr(
346
+						sprintf(
347
+							__('There is no task corresponding to this route %s', 'event_espresso'),
348
+							$cron_type
349
+						)
350
+					)
351
+				);
352
+			}
353
+		}
354
+
355
+		do_action('FHEE__EED_Messages__run_cron__end');
356
+	}
357
+
358
+
359
+	/**
360
+	 * This is used to retrieve the template pack for the given name.
361
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
362
+	 * the default template pack is returned.
363
+	 *
364
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
365
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
366
+	 *                                   in generating the Pack class name).
367
+	 * @return EE_Messages_Template_Pack
368
+	 * @throws EE_Error
369
+	 * @throws InvalidArgumentException
370
+	 * @throws ReflectionException
371
+	 * @throws InvalidDataTypeException
372
+	 * @throws InvalidInterfaceException
373
+	 */
374
+	public static function get_template_pack($template_pack_name)
375
+	{
376
+		EE_Registry::instance()->load_helper('MSG_Template');
377
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
378
+	}
379
+
380
+
381
+	/**
382
+	 * Retrieves an array of all template packs.
383
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
384
+	 *
385
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
386
+	 * @return EE_Messages_Template_Pack[]
387
+	 * @throws EE_Error
388
+	 * @throws InvalidArgumentException
389
+	 * @throws ReflectionException
390
+	 * @throws InvalidDataTypeException
391
+	 * @throws InvalidInterfaceException
392
+	 */
393
+	public static function get_template_packs()
394
+	{
395
+		EE_Registry::instance()->load_helper('MSG_Template');
396
+
397
+		// for backward compat, let's make sure this returns in the same format as originally.
398
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
399
+		$template_pack_collection->rewind();
400
+		$template_packs = array();
401
+		while ($template_pack_collection->valid()) {
402
+			$template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
403
+			$template_pack_collection->next();
404
+		}
405
+		return $template_packs;
406
+	}
407
+
408
+
409
+	/**
410
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
411
+	 *
412
+	 * @since 4.5.0
413
+	 * @return void
414
+	 * @throws EE_Error
415
+	 */
416
+	public static function set_autoloaders()
417
+	{
418
+		if (empty(self::$_MSG_PATHS)) {
419
+			self::_set_messages_paths();
420
+			foreach (self::$_MSG_PATHS as $path) {
421
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
422
+			}
423
+			// add aliases
424
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
425
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
426
+		}
427
+	}
428
+
429
+
430
+	/**
431
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
432
+	 * for use by the Messages Autoloaders
433
+	 *
434
+	 * @since 4.5.0
435
+	 * @return void.
436
+	 */
437
+	protected static function _set_messages_paths()
438
+	{
439
+		$dir_ref = array(
440
+			'messages/message_type',
441
+			'messages/messenger',
442
+			'messages/defaults',
443
+			'messages/defaults/email',
444
+			'messages/data_class',
445
+			'messages/validators',
446
+			'messages/validators/email',
447
+			'messages/validators/html',
448
+			'shortcodes',
449
+		);
450
+		$paths = array();
451
+		foreach ($dir_ref as $index => $dir) {
452
+			$paths[ $index ] = EE_LIBRARIES . $dir;
453
+		}
454
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
455
+	}
456
+
457
+
458
+	/**
459
+	 * Takes care of loading dependencies
460
+	 *
461
+	 * @since 4.5.0
462
+	 * @return void
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws ReflectionException
466
+	 * @throws InvalidDataTypeException
467
+	 * @throws InvalidInterfaceException
468
+	 */
469
+	protected static function _load_controller()
470
+	{
471
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
472
+			EE_Registry::instance()->load_core('Request_Handler');
473
+			self::set_autoloaders();
474
+			self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
475
+			self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
476
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
477
+		}
478
+	}
479
+
480
+
481
+	/**
482
+	 * @param EE_Transaction $transaction
483
+	 * @throws EE_Error
484
+	 * @throws InvalidArgumentException
485
+	 * @throws InvalidDataTypeException
486
+	 * @throws InvalidInterfaceException
487
+	 * @throws ReflectionException
488
+	 */
489
+	public static function payment_reminder(EE_Transaction $transaction)
490
+	{
491
+		self::_load_controller();
492
+		$data = array($transaction, null);
493
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
494
+	}
495
+
496
+
497
+	/**
498
+	 * Any messages triggers for after successful gateway payments should go in here.
499
+	 *
500
+	 * @param EE_Transaction  $transaction object
501
+	 * @param EE_Payment|null $payment     object
502
+	 * @return void
503
+	 * @throws EE_Error
504
+	 * @throws InvalidArgumentException
505
+	 * @throws ReflectionException
506
+	 * @throws InvalidDataTypeException
507
+	 * @throws InvalidInterfaceException
508
+	 */
509
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
510
+	{
511
+		// if there's no payment object, then we cannot do a payment type message!
512
+		if (! $payment instanceof EE_Payment) {
513
+			return;
514
+		}
515
+		self::_load_controller();
516
+		$data = array($transaction, $payment);
517
+		EE_Registry::instance()->load_helper('MSG_Template');
518
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
519
+		// if payment amount is less than 0 then switch to payment_refund message type.
520
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
521
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
522
+	}
523
+
524
+
525
+	/**
526
+	 * @param EE_Transaction $transaction
527
+	 * @throws EE_Error
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidDataTypeException
530
+	 * @throws InvalidInterfaceException
531
+	 * @throws ReflectionException
532
+	 */
533
+	public static function cancelled_registration(EE_Transaction $transaction)
534
+	{
535
+		self::_load_controller();
536
+		$data = array($transaction, null);
537
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
538
+	}
539
+
540
+
541
+	/**
542
+	 * Trigger for Registration messages
543
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
544
+	 * incoming transaction.
545
+	 *
546
+	 * @param EE_Registration $registration
547
+	 * @param array           $extra_details
548
+	 * @return void
549
+	 * @throws EE_Error
550
+	 * @throws InvalidArgumentException
551
+	 * @throws InvalidDataTypeException
552
+	 * @throws InvalidInterfaceException
553
+	 * @throws ReflectionException
554
+	 * @throws EntityNotFoundException
555
+	 */
556
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
557
+	{
558
+
559
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
560
+			// no messages please
561
+			return;
562
+		}
563
+
564
+		// get all non-trashed registrations so we make sure we send messages for the right status.
565
+		$all_registrations = $registration->transaction()->registrations(
566
+			array(
567
+				array('REG_deleted' => false),
568
+				'order_by' => array(
569
+					'Event.EVT_name'     => 'ASC',
570
+					'Attendee.ATT_lname' => 'ASC',
571
+					'Attendee.ATT_fname' => 'ASC',
572
+				),
573
+			)
574
+		);
575
+		// cached array of statuses so we only trigger messages once per status.
576
+		$statuses_sent = array();
577
+		self::_load_controller();
578
+		$mtgs = array();
579
+
580
+		// loop through registrations and trigger messages once per status.
581
+		foreach ($all_registrations as $reg) {
582
+			// already triggered?
583
+			if (in_array($reg->status_ID(), $statuses_sent)) {
584
+				continue;
585
+			}
586
+
587
+			$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
588
+			$mtgs = array_merge(
589
+				$mtgs,
590
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
591
+					$message_type,
592
+					array($registration->transaction(), null, $reg->status_ID())
593
+				)
594
+			);
595
+			$statuses_sent[] = $reg->status_ID();
596
+		}
597
+
598
+		if (count($statuses_sent) > 1) {
599
+			$mtgs = array_merge(
600
+				$mtgs,
601
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
602
+					'registration_summary',
603
+					array($registration->transaction(), null)
604
+				)
605
+			);
606
+		}
607
+
608
+		// batch queue and initiate request
609
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
610
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
611
+	}
612
+
613
+
614
+	/**
615
+	 * This is a helper method used to very whether a registration notification should be sent or
616
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
617
+	 *
618
+	 * @param EE_Registration $registration  [description]
619
+	 * @param array           $extra_details [description]
620
+	 * @return bool          true = send away, false = nope halt the presses.
621
+	 */
622
+	protected static function _verify_registration_notification_send(
623
+		EE_Registration $registration,
624
+		$extra_details = array()
625
+	) {
626
+		if (! $registration->is_primary_registrant()) {
627
+			return false;
628
+		}
629
+		// first we check if we're in admin and not doing front ajax
630
+		if (is_admin() && ! EE_FRONT_AJAX) {
631
+			// make sure appropriate admin params are set for sending messages
632
+			if (empty($_REQUEST['txn_reg_status_change']['send_notifications'])
633
+				|| ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])
634
+			) {
635
+				// no messages sent please.
636
+				return false;
637
+			}
638
+		} else {
639
+			// frontend request (either regular or via AJAX)
640
+			// TXN is NOT finalized ?
641
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
642
+				return false;
643
+			}
644
+			// return visit but nothing changed ???
645
+			if (isset($extra_details['revisit'], $extra_details['status_updates']) &&
646
+				$extra_details['revisit'] && ! $extra_details['status_updates']
647
+			) {
648
+				return false;
649
+			}
650
+			// NOT sending messages && reg status is something other than "Not-Approved"
651
+			if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
652
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
653
+			) {
654
+				return false;
655
+			}
656
+		}
657
+		// release the kraken
658
+		return true;
659
+	}
660
+
661
+
662
+	/**
663
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
664
+	 * status id.
665
+	 *
666
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
667
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
668
+	 * @param string $reg_status
669
+	 * @return array
670
+	 * @throws EE_Error
671
+	 * @throws InvalidArgumentException
672
+	 * @throws ReflectionException
673
+	 * @throws InvalidDataTypeException
674
+	 * @throws InvalidInterfaceException
675
+	 */
676
+	protected static function _get_reg_status_array($reg_status = '')
677
+	{
678
+		EE_Registry::instance()->load_helper('MSG_Template');
679
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
680
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
681
+			: EEH_MSG_Template::reg_status_to_message_type_array();
682
+	}
683
+
684
+
685
+	/**
686
+	 * Simply returns the payment message type for the given payment status.
687
+	 *
688
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
689
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
690
+	 * @param string $payment_status The payment status being matched.
691
+	 * @return bool|string The payment message type slug matching the status or false if no match.
692
+	 * @throws EE_Error
693
+	 * @throws InvalidArgumentException
694
+	 * @throws ReflectionException
695
+	 * @throws InvalidDataTypeException
696
+	 * @throws InvalidInterfaceException
697
+	 */
698
+	protected static function _get_payment_message_type($payment_status)
699
+	{
700
+		EE_Registry::instance()->load_helper('MSG_Template');
701
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
702
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
703
+			: false;
704
+	}
705
+
706
+
707
+	/**
708
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
709
+	 *
710
+	 * @access public
711
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
712
+	 * @return bool success/fail
713
+	 * @throws EE_Error
714
+	 * @throws InvalidArgumentException
715
+	 * @throws InvalidDataTypeException
716
+	 * @throws InvalidInterfaceException
717
+	 * @throws ReflectionException
718
+	 */
719
+	public static function process_resend($req_data)
720
+	{
721
+		self::_load_controller();
722
+
723
+		// if $msgID in this request then skip to the new resend_message
724
+		if (EE_Registry::instance()->REQ->get('MSG_ID')) {
725
+			return self::resend_message();
726
+		}
727
+
728
+		// make sure any incoming request data is set on the REQ so that it gets picked up later.
729
+		$req_data = (array) $req_data;
730
+		foreach ($req_data as $request_key => $request_value) {
731
+			EE_Registry::instance()->REQ->set($request_key, $request_value);
732
+		}
733
+
734
+		if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request(
735
+		)) {
736
+			return false;
737
+		}
738
+
739
+		try {
740
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
741
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
742
+		} catch (EE_Error $e) {
743
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
744
+			return false;
745
+		}
746
+		EE_Error::add_success(
747
+			__('Messages have been successfully queued for generation and sending.', 'event_espresso')
748
+		);
749
+		return true; // everything got queued.
750
+	}
751
+
752
+
753
+	/**
754
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
755
+	 *
756
+	 * @return bool
757
+	 * @throws EE_Error
758
+	 * @throws InvalidArgumentException
759
+	 * @throws InvalidDataTypeException
760
+	 * @throws InvalidInterfaceException
761
+	 * @throws ReflectionException
762
+	 */
763
+	public static function resend_message()
764
+	{
765
+		self::_load_controller();
766
+
767
+		$msgID = EE_Registry::instance()->REQ->get('MSG_ID');
768
+		if (! $msgID) {
769
+			EE_Error::add_error(
770
+				__(
771
+					'Something went wrong because there is no "MSG_ID" value in the request',
772
+					'event_espresso'
773
+				),
774
+				__FILE__,
775
+				__FUNCTION__,
776
+				__LINE__
777
+			);
778
+			return false;
779
+		}
780
+
781
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
782
+
783
+		// setup success message.
784
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
785
+		EE_Error::add_success(
786
+			sprintf(
787
+				_n(
788
+					'There was %d message queued for resending.',
789
+					'There were %d messages queued for resending.',
790
+					$count_ready_for_resend,
791
+					'event_espresso'
792
+				),
793
+				$count_ready_for_resend
794
+			)
795
+		);
796
+		return true;
797
+	}
798
+
799
+
800
+	/**
801
+	 * Message triggers for manual payment applied by admin
802
+	 *
803
+	 * @param  EE_Payment $payment EE_payment object
804
+	 * @return bool success/fail
805
+	 * @throws EE_Error
806
+	 * @throws InvalidArgumentException
807
+	 * @throws ReflectionException
808
+	 * @throws InvalidDataTypeException
809
+	 * @throws InvalidInterfaceException
810
+	 */
811
+	public static function process_admin_payment(EE_Payment $payment)
812
+	{
813
+		EE_Registry::instance()->load_helper('MSG_Template');
814
+		// we need to get the transaction object
815
+		$transaction = $payment->transaction();
816
+		if ($transaction instanceof EE_Transaction) {
817
+			$data = array($transaction, $payment);
818
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
819
+
820
+			// if payment amount is less than 0 then switch to payment_refund message type.
821
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
822
+
823
+			// if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
824
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
825
+				? false : $message_type;
826
+
827
+			self::_load_controller();
828
+
829
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
830
+
831
+			// get count of queued for generation
832
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
833
+				array(
834
+					EEM_Message::status_incomplete,
835
+					EEM_Message::status_idle,
836
+				)
837
+			);
838
+
839
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
840
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
841
+				return true;
842
+			} else {
843
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
844
+					EEM_Message::instance()->stati_indicating_failed_sending()
845
+				);
846
+				/**
847
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
848
+				 * IMMEDIATE generation.
849
+				 */
850
+				if ($count_failed > 0) {
851
+					EE_Error::add_error(
852
+						sprintf(
853
+							_n(
854
+								'The payment notification generation failed.',
855
+								'%d payment notifications failed being sent.',
856
+								$count_failed,
857
+								'event_espresso'
858
+							),
859
+							$count_failed
860
+						),
861
+						__FILE__,
862
+						__FUNCTION__,
863
+						__LINE__
864
+					);
865
+
866
+					return false;
867
+				} else {
868
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
869
+					return true;
870
+				}
871
+			}
872
+		} else {
873
+			EE_Error::add_error(
874
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
875
+				'event_espresso'
876
+			);
877
+			return false;
878
+		}
879
+	}
880
+
881
+
882
+	/**
883
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
884
+	 *
885
+	 * @since   4.3.0
886
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
887
+	 * @param  int               $grp_id        a specific message template group id.
888
+	 * @return void
889
+	 * @throws EE_Error
890
+	 * @throws InvalidArgumentException
891
+	 * @throws InvalidDataTypeException
892
+	 * @throws InvalidInterfaceException
893
+	 * @throws ReflectionException
894
+	 */
895
+	public static function send_newsletter_message($registrations, $grp_id)
896
+	{
897
+		// make sure mtp is id and set it in the EE_Request Handler later messages setup.
898
+		EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id);
899
+		self::_load_controller();
900
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
901
+	}
902
+
903
+
904
+	/**
905
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
906
+	 *
907
+	 * @since   4.3.0
908
+	 * @param    string          $registration_message_trigger_url
909
+	 * @param    EE_Registration $registration
910
+	 * @param string             $messenger
911
+	 * @param string             $message_type
912
+	 * @return string
913
+	 * @throws EE_Error
914
+	 * @throws InvalidArgumentException
915
+	 * @throws InvalidDataTypeException
916
+	 * @throws InvalidInterfaceException
917
+	 */
918
+	public static function registration_message_trigger_url(
919
+		$registration_message_trigger_url,
920
+		EE_Registration $registration,
921
+		$messenger = 'html',
922
+		$message_type = 'invoice'
923
+	) {
924
+		// whitelist $messenger
925
+		switch ($messenger) {
926
+			case 'pdf':
927
+				$sending_messenger = 'pdf';
928
+				$generating_messenger = 'html';
929
+				break;
930
+			case 'html':
931
+			default:
932
+				$sending_messenger = 'html';
933
+				$generating_messenger = 'html';
934
+				break;
935
+		}
936
+		// whitelist $message_type
937
+		switch ($message_type) {
938
+			case 'receipt':
939
+				$message_type = 'receipt';
940
+				break;
941
+			case 'invoice':
942
+			default:
943
+				$message_type = 'invoice';
944
+				break;
945
+		}
946
+		// verify that both the messenger AND the message type are active
947
+		if (EEH_MSG_Template::is_messenger_active($sending_messenger)
948
+			&& EEH_MSG_Template::is_mt_active($message_type)
949
+		) {
950
+			// 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?)
951
+			$template_query_params = array(
952
+				'MTP_is_active'    => true,
953
+				'MTP_messenger'    => $generating_messenger,
954
+				'MTP_message_type' => $message_type,
955
+				'Event.EVT_ID'     => $registration->event_ID(),
956
+			);
957
+			// get the message template group.
958
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
959
+			// if we don't have an EE_Message_Template_Group then return
960
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
961
+				// remove EVT_ID from query params so that global templates get picked up
962
+				unset($template_query_params['Event.EVT_ID']);
963
+				// get global template as the fallback
964
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
965
+			}
966
+			// if we don't have an EE_Message_Template_Group then return
967
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
968
+				return '';
969
+			}
970
+			// generate the URL
971
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
972
+				$sending_messenger,
973
+				$generating_messenger,
974
+				'purchaser',
975
+				$message_type,
976
+				$registration,
977
+				$msg_template_group->ID(),
978
+				$registration->transaction_ID()
979
+			);
980
+		}
981
+		return $registration_message_trigger_url;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Use to generate and return a message preview!
987
+	 *
988
+	 * @param  string $type      This should correspond with a valid message type
989
+	 * @param  string $context   This should correspond with a valid context for the message type
990
+	 * @param  string $messenger This should correspond with a valid messenger.
991
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
992
+	 *                           preview
993
+	 * @return bool|string The body of the message or if send is requested, sends.
994
+	 * @throws EE_Error
995
+	 * @throws InvalidArgumentException
996
+	 * @throws InvalidDataTypeException
997
+	 * @throws InvalidInterfaceException
998
+	 * @throws ReflectionException
999
+	 */
1000
+	public static function preview_message($type, $context, $messenger, $send = false)
1001
+	{
1002
+		self::_load_controller();
1003
+		$mtg = new EE_Message_To_Generate(
1004
+			$messenger,
1005
+			$type,
1006
+			array(),
1007
+			$context,
1008
+			true
1009
+		);
1010
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1011
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
1012
+			// loop through all content for the preview and remove any persisted records.
1013
+			$content = '';
1014
+			foreach ($generated_preview_queue->get_message_repository() as $message) {
1015
+				$content = $message->content();
1016
+				if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1017
+					$message->delete();
1018
+				}
1019
+			}
1020
+			return $content;
1021
+		} else {
1022
+			return $generated_preview_queue;
1023
+		}
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
1029
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1030
+	 * content found in the EE_Message objects in the queue.
1031
+	 *
1032
+	 * @since 4.9.0
1033
+	 * @param string            $messenger            a string matching a valid active messenger in the system
1034
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
1035
+	 *                                                type name is still required to send along the message type to the
1036
+	 *                                                messenger because this is used for determining what specific
1037
+	 *                                                variations might be loaded for the generated message.
1038
+	 * @param EE_Messages_Queue $queue
1039
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1040
+	 *                                                aggregate EE_Message object.
1041
+	 * @return bool success or fail.
1042
+	 * @throws EE_Error
1043
+	 * @throws InvalidArgumentException
1044
+	 * @throws ReflectionException
1045
+	 * @throws InvalidDataTypeException
1046
+	 * @throws InvalidInterfaceException
1047
+	 */
1048
+	public static function send_message_with_messenger_only(
1049
+		$messenger,
1050
+		$message_type,
1051
+		EE_Messages_Queue $queue,
1052
+		$custom_subject = ''
1053
+	) {
1054
+		self::_load_controller();
1055
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1056
+		$message_to_generate = EE_Registry::instance()->load_lib(
1057
+			'Message_To_Generate_From_Queue',
1058
+			array(
1059
+				$messenger,
1060
+				$message_type,
1061
+				$queue,
1062
+				$custom_subject,
1063
+			)
1064
+		);
1065
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1066
+	}
1067
+
1068
+
1069
+	/**
1070
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1071
+	 *
1072
+	 * @since 4.9.0
1073
+	 * @param array $message_ids An array of message ids
1074
+	 * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1075
+	 *                           messages.
1076
+	 * @throws EE_Error
1077
+	 * @throws InvalidArgumentException
1078
+	 * @throws InvalidDataTypeException
1079
+	 * @throws InvalidInterfaceException
1080
+	 * @throws ReflectionException
1081
+	 */
1082
+	public static function generate_now($message_ids)
1083
+	{
1084
+		self::_load_controller();
1085
+		$messages = EEM_Message::instance()->get_all(
1086
+			array(
1087
+				0 => array(
1088
+					'MSG_ID' => array('IN', $message_ids),
1089
+					'STS_ID' => EEM_Message::status_incomplete,
1090
+				),
1091
+			)
1092
+		);
1093
+		$generated_queue = false;
1094
+		if ($messages) {
1095
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1096
+		}
1097
+
1098
+		if (! $generated_queue instanceof EE_Messages_Queue) {
1099
+			EE_Error::add_error(
1100
+				__(
1101
+					'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.',
1102
+					'event_espresso'
1103
+				),
1104
+				__FILE__,
1105
+				__FUNCTION__,
1106
+				__LINE__
1107
+			);
1108
+		}
1109
+		return $generated_queue;
1110
+	}
1111
+
1112
+
1113
+	/**
1114
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1115
+	 * EEM_Message::status_idle
1116
+	 *
1117
+	 * @since 4.9.0
1118
+	 * @param $message_ids
1119
+	 * @return bool|EE_Messages_Queue false if no messages sent.
1120
+	 * @throws EE_Error
1121
+	 * @throws InvalidArgumentException
1122
+	 * @throws InvalidDataTypeException
1123
+	 * @throws InvalidInterfaceException
1124
+	 * @throws ReflectionException
1125
+	 */
1126
+	public static function send_now($message_ids)
1127
+	{
1128
+		self::_load_controller();
1129
+		$messages = EEM_Message::instance()->get_all(
1130
+			array(
1131
+				0 => array(
1132
+					'MSG_ID' => array('IN', $message_ids),
1133
+					'STS_ID' => array(
1134
+						'IN',
1135
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1136
+					),
1137
+				),
1138
+			)
1139
+		);
1140
+		$sent_queue = false;
1141
+		if ($messages) {
1142
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1143
+		}
1144
+
1145
+		if (! $sent_queue instanceof EE_Messages_Queue) {
1146
+			EE_Error::add_error(
1147
+				__(
1148
+					'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.',
1149
+					'event_espresso'
1150
+				),
1151
+				__FILE__,
1152
+				__FUNCTION__,
1153
+				__LINE__
1154
+			);
1155
+		} else {
1156
+			// can count how many sent by using the messages in the queue
1157
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1158
+			if ($sent_count > 0) {
1159
+				EE_Error::add_success(
1160
+					sprintf(
1161
+						_n(
1162
+							'There was %d message successfully sent.',
1163
+							'There were %d messages successfully sent.',
1164
+							$sent_count,
1165
+							'event_espresso'
1166
+						),
1167
+						$sent_count
1168
+					)
1169
+				);
1170
+			} else {
1171
+				EE_Error::overwrite_errors();
1172
+				EE_Error::add_error(
1173
+					__(
1174
+						'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.
1175 1175
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
1176
-                        'event_espresso'
1177
-                    ),
1178
-                    __FILE__,
1179
-                    __FUNCTION__,
1180
-                    __LINE__
1181
-                );
1182
-            }
1183
-        }
1184
-        return $sent_queue;
1185
-    }
1186
-
1187
-
1188
-    /**
1189
-     * Generate and send immediately from the given $message_ids
1190
-     *
1191
-     * @param array $message_ids EE_Message entity ids.
1192
-     * @throws EE_Error
1193
-     * @throws InvalidArgumentException
1194
-     * @throws InvalidDataTypeException
1195
-     * @throws InvalidInterfaceException
1196
-     * @throws ReflectionException
1197
-     */
1198
-    public static function generate_and_send_now(array $message_ids)
1199
-    {
1200
-        $generated_queue = self::generate_now($message_ids);
1201
-        // now let's just trigger sending immediately from this queue.
1202
-        $messages_sent = $generated_queue instanceof EE_Messages_Queue
1203
-            ? $generated_queue->execute()
1204
-            : 0;
1205
-        if ($messages_sent) {
1206
-            EE_Error::add_success(
1207
-                esc_html(
1208
-                    sprintf(
1209
-                        _n(
1210
-                            'There was %d message successfully generated and sent.',
1211
-                            'There were %d messages successfully generated and sent.',
1212
-                            $messages_sent,
1213
-                            'event_espresso'
1214
-                        ),
1215
-                        $messages_sent
1216
-                    )
1217
-                )
1218
-            );
1219
-            // errors would be added via the generate_now method.
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * This will queue the incoming message ids for resending.
1226
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1227
-     *
1228
-     * @since 4.9.0
1229
-     * @param array $message_ids An array of EE_Message IDs
1230
-     * @return bool true means messages were successfully queued for resending, false means none were queued for
1231
-     *                           resending.
1232
-     * @throws EE_Error
1233
-     * @throws InvalidArgumentException
1234
-     * @throws InvalidDataTypeException
1235
-     * @throws InvalidInterfaceException
1236
-     * @throws ReflectionException
1237
-     */
1238
-    public static function queue_for_resending($message_ids)
1239
-    {
1240
-        self::_load_controller();
1241
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1242
-
1243
-        // get queue and count
1244
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1245
-
1246
-        if ($queue_count > 0
1247
-        ) {
1248
-            EE_Error::add_success(
1249
-                sprintf(
1250
-                    _n(
1251
-                        '%d message successfully queued for resending.',
1252
-                        '%d messages successfully queued for resending.',
1253
-                        $queue_count,
1254
-                        'event_espresso'
1255
-                    ),
1256
-                    $queue_count
1257
-                )
1258
-            );
1259
-            /**
1260
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1261
-             */
1262
-        } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1263
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1264
-        ) {
1265
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1266
-            if ($queue_count > 0) {
1267
-                EE_Error::add_success(
1268
-                    sprintf(
1269
-                        _n(
1270
-                            '%d message successfully sent.',
1271
-                            '%d messages successfully sent.',
1272
-                            $queue_count,
1273
-                            'event_espresso'
1274
-                        ),
1275
-                        $queue_count
1276
-                    )
1277
-                );
1278
-            } else {
1279
-                EE_Error::add_error(
1280
-                    __(
1281
-                        '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.',
1282
-                        'event_espresso'
1283
-                    ),
1284
-                    __FILE__,
1285
-                    __FUNCTION__,
1286
-                    __LINE__
1287
-                );
1288
-            }
1289
-        } else {
1290
-            EE_Error::add_error(
1291
-                __(
1292
-                    '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.',
1293
-                    'event_espresso'
1294
-                ),
1295
-                __FILE__,
1296
-                __FUNCTION__,
1297
-                __LINE__
1298
-            );
1299
-        }
1300
-        return (bool) $queue_count;
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     * debug
1306
-     *
1307
-     * @param string          $class
1308
-     * @param string          $func
1309
-     * @param string          $line
1310
-     * @param \EE_Transaction $transaction
1311
-     * @param array           $info
1312
-     * @param bool            $display_request
1313
-     * @throws EE_Error
1314
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1315
-     */
1316
-    protected static function log(
1317
-        $class = '',
1318
-        $func = '',
1319
-        $line = '',
1320
-        EE_Transaction $transaction,
1321
-        $info = array(),
1322
-        $display_request = false
1323
-    ) {
1324
-        if (defined('EE_DEBUG') && EE_DEBUG) {
1325
-            if ($transaction instanceof EE_Transaction) {
1326
-                // don't serialize objects
1327
-                $info = EEH_Debug_Tools::strip_objects($info);
1328
-                $info['TXN_status'] = $transaction->status_ID();
1329
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1330
-                if ($transaction->ID()) {
1331
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1332
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1333
-                }
1334
-            }
1335
-        }
1336
-    }
1337
-
1338
-
1339
-    /**
1340
-     *  Resets all the static properties in this class when called.
1341
-     */
1342
-    public static function reset()
1343
-    {
1344
-        self::$_EEMSG = null;
1345
-        self::$_message_resource_manager = null;
1346
-        self::$_MSG_PROCESSOR = null;
1347
-        self::$_MSG_PATHS = null;
1348
-        self::$_TMP_PACKS = array();
1349
-    }
1176
+						'event_espresso'
1177
+					),
1178
+					__FILE__,
1179
+					__FUNCTION__,
1180
+					__LINE__
1181
+				);
1182
+			}
1183
+		}
1184
+		return $sent_queue;
1185
+	}
1186
+
1187
+
1188
+	/**
1189
+	 * Generate and send immediately from the given $message_ids
1190
+	 *
1191
+	 * @param array $message_ids EE_Message entity ids.
1192
+	 * @throws EE_Error
1193
+	 * @throws InvalidArgumentException
1194
+	 * @throws InvalidDataTypeException
1195
+	 * @throws InvalidInterfaceException
1196
+	 * @throws ReflectionException
1197
+	 */
1198
+	public static function generate_and_send_now(array $message_ids)
1199
+	{
1200
+		$generated_queue = self::generate_now($message_ids);
1201
+		// now let's just trigger sending immediately from this queue.
1202
+		$messages_sent = $generated_queue instanceof EE_Messages_Queue
1203
+			? $generated_queue->execute()
1204
+			: 0;
1205
+		if ($messages_sent) {
1206
+			EE_Error::add_success(
1207
+				esc_html(
1208
+					sprintf(
1209
+						_n(
1210
+							'There was %d message successfully generated and sent.',
1211
+							'There were %d messages successfully generated and sent.',
1212
+							$messages_sent,
1213
+							'event_espresso'
1214
+						),
1215
+						$messages_sent
1216
+					)
1217
+				)
1218
+			);
1219
+			// errors would be added via the generate_now method.
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * This will queue the incoming message ids for resending.
1226
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1227
+	 *
1228
+	 * @since 4.9.0
1229
+	 * @param array $message_ids An array of EE_Message IDs
1230
+	 * @return bool true means messages were successfully queued for resending, false means none were queued for
1231
+	 *                           resending.
1232
+	 * @throws EE_Error
1233
+	 * @throws InvalidArgumentException
1234
+	 * @throws InvalidDataTypeException
1235
+	 * @throws InvalidInterfaceException
1236
+	 * @throws ReflectionException
1237
+	 */
1238
+	public static function queue_for_resending($message_ids)
1239
+	{
1240
+		self::_load_controller();
1241
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1242
+
1243
+		// get queue and count
1244
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1245
+
1246
+		if ($queue_count > 0
1247
+		) {
1248
+			EE_Error::add_success(
1249
+				sprintf(
1250
+					_n(
1251
+						'%d message successfully queued for resending.',
1252
+						'%d messages successfully queued for resending.',
1253
+						$queue_count,
1254
+						'event_espresso'
1255
+					),
1256
+					$queue_count
1257
+				)
1258
+			);
1259
+			/**
1260
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1261
+			 */
1262
+		} elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1263
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1264
+		) {
1265
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1266
+			if ($queue_count > 0) {
1267
+				EE_Error::add_success(
1268
+					sprintf(
1269
+						_n(
1270
+							'%d message successfully sent.',
1271
+							'%d messages successfully sent.',
1272
+							$queue_count,
1273
+							'event_espresso'
1274
+						),
1275
+						$queue_count
1276
+					)
1277
+				);
1278
+			} else {
1279
+				EE_Error::add_error(
1280
+					__(
1281
+						'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.',
1282
+						'event_espresso'
1283
+					),
1284
+					__FILE__,
1285
+					__FUNCTION__,
1286
+					__LINE__
1287
+				);
1288
+			}
1289
+		} else {
1290
+			EE_Error::add_error(
1291
+				__(
1292
+					'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.',
1293
+					'event_espresso'
1294
+				),
1295
+				__FILE__,
1296
+				__FUNCTION__,
1297
+				__LINE__
1298
+			);
1299
+		}
1300
+		return (bool) $queue_count;
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 * debug
1306
+	 *
1307
+	 * @param string          $class
1308
+	 * @param string          $func
1309
+	 * @param string          $line
1310
+	 * @param \EE_Transaction $transaction
1311
+	 * @param array           $info
1312
+	 * @param bool            $display_request
1313
+	 * @throws EE_Error
1314
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1315
+	 */
1316
+	protected static function log(
1317
+		$class = '',
1318
+		$func = '',
1319
+		$line = '',
1320
+		EE_Transaction $transaction,
1321
+		$info = array(),
1322
+		$display_request = false
1323
+	) {
1324
+		if (defined('EE_DEBUG') && EE_DEBUG) {
1325
+			if ($transaction instanceof EE_Transaction) {
1326
+				// don't serialize objects
1327
+				$info = EEH_Debug_Tools::strip_objects($info);
1328
+				$info['TXN_status'] = $transaction->status_ID();
1329
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1330
+				if ($transaction->ID()) {
1331
+					$index = 'EE_Transaction: ' . $transaction->ID();
1332
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1333
+				}
1334
+			}
1335
+		}
1336
+	}
1337
+
1338
+
1339
+	/**
1340
+	 *  Resets all the static properties in this class when called.
1341
+	 */
1342
+	public static function reset()
1343
+	{
1344
+		self::$_EEMSG = null;
1345
+		self::$_message_resource_manager = null;
1346
+		self::$_MSG_PROCESSOR = null;
1347
+		self::$_MSG_PATHS = null;
1348
+		self::$_TMP_PACKS = array();
1349
+	}
1350 1350
 }
Please login to merge, or discard this patch.