Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +735 added lines, -735 removed lines patch added patch discarded remove patch
@@ -19,182 +19,182 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
24
-     * This property gets set by the _set_default_message_types() method.
25
-     *
26
-     * @var array
27
-     */
28
-    protected $_default_message_types = array();
22
+	/**
23
+	 * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
24
+	 * This property gets set by the _set_default_message_types() method.
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected $_default_message_types = array();
29 29
 
30 30
 
31 31
 
32 32
 
33
-    /**
34
-     * This property holds the message types that are valid for use with this messenger.
35
-     * It gets set by the _set_valid_message_types() method.
36
-     *
37
-     * @var array
38
-     */
39
-    protected $_valid_message_types = array();
33
+	/**
34
+	 * This property holds the message types that are valid for use with this messenger.
35
+	 * It gets set by the _set_valid_message_types() method.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $_valid_message_types = array();
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
45
-     *
46
-     * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
47
-     *
48
-     * Array should be in this format:
49
-     *
50
-     * array(
51
-     *  'field_name(i.e.to)' => array(
52
-     *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
53
-     *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
54
-     *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
55
-     *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
56
-     *  )
57
-     * )
58
-     *
59
-     * @var array
60
-     */
61
-    protected $_validator_config = array();
43
+	/**
44
+	 * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
45
+	 *
46
+	 * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
47
+	 *
48
+	 * Array should be in this format:
49
+	 *
50
+	 * array(
51
+	 *  'field_name(i.e.to)' => array(
52
+	 *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
53
+	 *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
54
+	 *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
55
+	 *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
56
+	 *  )
57
+	 * )
58
+	 *
59
+	 * @var array
60
+	 */
61
+	protected $_validator_config = array();
62 62
 
63 63
 
64 64
 
65
-    /**
66
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
67
-     * @var object
68
-     */
69
-    protected $_EEM_data;
65
+	/**
66
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
67
+	 * @var object
68
+	 */
69
+	protected $_EEM_data;
70 70
 
71 71
 
72 72
 
73
-    /**
74
-     * this property just holds an array of the various template refs.
75
-     * @var array
76
-     */
77
-    protected $_template_fields = array();
73
+	/**
74
+	 * this property just holds an array of the various template refs.
75
+	 * @var array
76
+	 */
77
+	protected $_template_fields = array();
78 78
 
79 79
 
80 80
 
81 81
 
82
-    /**
83
-     * This holds an array of the arguments used in parsing a template for the sender.
84
-     * @var array
85
-     */
86
-    protected $_template_args = array();
82
+	/**
83
+	 * This holds an array of the arguments used in parsing a template for the sender.
84
+	 * @var array
85
+	 */
86
+	protected $_template_args = array();
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
95
-     *
96
-     * @protected
97
-     * @var array
98
-     */
99
-    protected $_test_settings_fields = array();
93
+	/**
94
+	 * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
95
+	 *
96
+	 * @protected
97
+	 * @var array
98
+	 */
99
+	protected $_test_settings_fields = array();
100 100
 
101 101
 
102 102
 
103 103
 
104 104
 
105 105
 
106
-    /**
107
-     * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
108
-     *
109
-     * @since 4.5.0
110
-     *
111
-     * @var EE_Messages_Template_Pack
112
-     */
113
-    protected $_tmp_pack;
106
+	/**
107
+	 * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
108
+	 *
109
+	 * @since 4.5.0
110
+	 *
111
+	 * @var EE_Messages_Template_Pack
112
+	 */
113
+	protected $_tmp_pack;
114 114
 
115 115
 
116 116
 
117 117
 
118
-    /**
119
-     * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
120
-     *
121
-     * @since 4.5.0
122
-     *
123
-     * @var string
124
-     */
125
-    protected $_variation;
118
+	/**
119
+	 * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
120
+	 *
121
+	 * @since 4.5.0
122
+	 *
123
+	 * @var string
124
+	 */
125
+	protected $_variation;
126 126
 
127 127
 
128 128
 
129 129
 
130 130
 
131
-    /**
132
-     * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
133
-     *
134
-     *  - template pack
135
-     *  - template variation
136
-     *
137
-     * @since 4.5.0
138
-     *
139
-     * @var stdClass
140
-     */
141
-    protected $_supports_labels;
131
+	/**
132
+	 * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
133
+	 *
134
+	 *  - template pack
135
+	 *  - template variation
136
+	 *
137
+	 * @since 4.5.0
138
+	 *
139
+	 * @var stdClass
140
+	 */
141
+	protected $_supports_labels;
142 142
 
143 143
 
144 144
 
145 145
 
146 146
 
147
-    /**
148
-     * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
149
-     *
150
-     * @var EE_message_type
151
-     */
152
-    protected $_incoming_message_type;
147
+	/**
148
+	 * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
149
+	 *
150
+	 * @var EE_message_type
151
+	 */
152
+	protected $_incoming_message_type;
153 153
 
154 154
 
155 155
 
156
-    /**
157
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
158
-     *
159
-     * @var bool
160
-     */
161
-    public $activate_on_install = false;
156
+	/**
157
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
158
+	 *
159
+	 * @var bool
160
+	 */
161
+	public $activate_on_install = false;
162 162
 
163 163
 
164 164
 
165 165
 
166 166
 
167
-    public function __construct()
168
-    {
169
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
170
-        $this->_messages_item_type = 'messenger';
167
+	public function __construct()
168
+	{
169
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
170
+		$this->_messages_item_type = 'messenger';
171 171
 
172
-        parent::__construct();
172
+		parent::__construct();
173 173
 
174
-        $this->_set_test_settings_fields();
175
-        $this->_set_template_fields();
176
-        $this->_set_default_message_types();
177
-        $this->_set_valid_message_types();
178
-        $this->_set_validator_config();
174
+		$this->_set_test_settings_fields();
175
+		$this->_set_template_fields();
176
+		$this->_set_default_message_types();
177
+		$this->_set_valid_message_types();
178
+		$this->_set_validator_config();
179 179
 
180 180
 
181
-        $this->_supports_labels = new stdClass();
182
-        $this->_set_supports_labels();
183
-    }
181
+		$this->_supports_labels = new stdClass();
182
+		$this->_set_supports_labels();
183
+	}
184 184
 
185 185
 
186 186
 
187 187
 
188 188
 
189
-    /**
190
-     * _set_template_fields
191
-     * This sets up the fields that a messenger requires for the message to go out.
192
-     *
193
-     * @abstract
194
-     * @access  protected
195
-     * @return void
196
-     */
197
-    abstract protected function _set_template_fields();
189
+	/**
190
+	 * _set_template_fields
191
+	 * This sets up the fields that a messenger requires for the message to go out.
192
+	 *
193
+	 * @abstract
194
+	 * @access  protected
195
+	 * @return void
196
+	 */
197
+	abstract protected function _set_template_fields();
198 198
 
199 199
 
200 200
 
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 
205 205
 
206 206
 
207
-    /**
208
-     * This method sets the _default_message_type property (see definition in docs attached to property)
209
-     *
210
-     * @abstract
211
-     * @access protected
212
-     * @return void
213
-     */
214
-    abstract protected function _set_default_message_types();
207
+	/**
208
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
209
+	 *
210
+	 * @abstract
211
+	 * @access protected
212
+	 * @return void
213
+	 */
214
+	abstract protected function _set_default_message_types();
215 215
 
216 216
 
217 217
 
@@ -219,15 +219,15 @@  discard block
 block discarded – undo
219 219
 
220 220
 
221 221
 
222
-    /**
223
-     * Sets the _valid_message_types property (see definition in cods attached to property)
224
-     *
225
-     * @since 4.5.0
226
-     *
227
-     * @abstract
228
-     * @return void
229
-     */
230
-    abstract protected function _set_valid_message_types();
222
+	/**
223
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
224
+	 *
225
+	 * @since 4.5.0
226
+	 *
227
+	 * @abstract
228
+	 * @return void
229
+	 */
230
+	abstract protected function _set_valid_message_types();
231 231
 
232 232
 
233 233
 
@@ -235,171 +235,171 @@  discard block
 block discarded – undo
235 235
 
236 236
 
237 237
 
238
-    /**
239
-     * Child classes must declare the $_validator_config property using this method.
240
-     * See comments for $_validator_config for details on what it is used for.
241
-     *
242
-     * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
243
-     *
244
-     * @access protected
245
-     * @return void
246
-     */
247
-    abstract protected function _set_validator_config();
238
+	/**
239
+	 * Child classes must declare the $_validator_config property using this method.
240
+	 * See comments for $_validator_config for details on what it is used for.
241
+	 *
242
+	 * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
243
+	 *
244
+	 * @access protected
245
+	 * @return void
246
+	 */
247
+	abstract protected function _set_validator_config();
248 248
 
249 249
 
250 250
 
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
256
-     *
257
-     * @return bool|WP_Error
258
-     * @throw \Exception
259
-     */
260
-    abstract protected function _send_message();
254
+	/**
255
+	 * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
256
+	 *
257
+	 * @return bool|WP_Error
258
+	 * @throw \Exception
259
+	 */
260
+	abstract protected function _send_message();
261 261
 
262 262
 
263 263
 
264 264
 
265
-    /**
266
-     * We give you pretty previews of the messages!
267
-     * @return string html body for message content.
268
-     */
269
-    abstract protected function _preview();
265
+	/**
266
+	 * We give you pretty previews of the messages!
267
+	 * @return string html body for message content.
268
+	 */
269
+	abstract protected function _preview();
270 270
 
271 271
 
272 272
 
273 273
 
274
-    /**
275
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
276
-     *
277
-     * @since 4.5.0
278
-     *
279
-     * @return void
280
-     */
281
-    public function enqueue_scripts_styles()
282
-    {
283
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
284
-    }
274
+	/**
275
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
276
+	 *
277
+	 * @since 4.5.0
278
+	 *
279
+	 * @return void
280
+	 */
281
+	public function enqueue_scripts_styles()
282
+	{
283
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
284
+	}
285 285
 
286 286
 
287 287
 
288 288
 
289 289
 
290
-    /**
291
-     * This is used to indicate whether a messenger must be sent immediately or not.
292
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
293
-     * away.  The PDF messenger is similar.
294
-     *
295
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
296
-     *
297
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
298
-     *
299
-     * @since  4.9.0
300
-     * @return bool
301
-     */
302
-    public function send_now()
303
-    {
304
-        return false;
305
-    }
290
+	/**
291
+	 * This is used to indicate whether a messenger must be sent immediately or not.
292
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
293
+	 * away.  The PDF messenger is similar.
294
+	 *
295
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
296
+	 *
297
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
298
+	 *
299
+	 * @since  4.9.0
300
+	 * @return bool
301
+	 */
302
+	public function send_now()
303
+	{
304
+		return false;
305
+	}
306 306
 
307 307
 
308 308
 
309 309
 
310 310
 
311
-    /**
312
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
313
-     * Note: If the generated message is a for a preview, this value is ignored.
314
-     * @since 4.9.0
315
-     * @return bool
316
-     */
317
-    public function allow_empty_to_field()
318
-    {
319
-        return false;
320
-    }
311
+	/**
312
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
313
+	 * Note: If the generated message is a for a preview, this value is ignored.
314
+	 * @since 4.9.0
315
+	 * @return bool
316
+	 */
317
+	public function allow_empty_to_field()
318
+	{
319
+		return false;
320
+	}
321 321
 
322 322
 
323 323
 
324 324
 
325 325
 
326
-    /**
327
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
328
-     * @see property definition for info on how its formatted.
329
-     *
330
-     * @since 4.5.0;
331
-     * @return void
332
-     */
333
-    protected function _set_supports_labels()
334
-    {
335
-        $this->_set_supports_labels_defaults();
336
-    }
326
+	/**
327
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
328
+	 * @see property definition for info on how its formatted.
329
+	 *
330
+	 * @since 4.5.0;
331
+	 * @return void
332
+	 */
333
+	protected function _set_supports_labels()
334
+	{
335
+		$this->_set_supports_labels_defaults();
336
+	}
337 337
 
338 338
 
339 339
 
340 340
 
341 341
 
342
-    /**
343
-     * Sets the defaults for the _supports_labels property.
344
-     *
345
-     * @since 4.5.0
346
-     *
347
-     * @return void
348
-     */
349
-    private function _set_supports_labels_defaults()
350
-    {
351
-        $this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso');
352
-        $this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso');
353
-        $this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso');
342
+	/**
343
+	 * Sets the defaults for the _supports_labels property.
344
+	 *
345
+	 * @since 4.5.0
346
+	 *
347
+	 * @return void
348
+	 */
349
+	private function _set_supports_labels_defaults()
350
+	{
351
+		$this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso');
352
+		$this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso');
353
+		$this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso');
354 354
 
355
-        $this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
355
+		$this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
356 356
 
357
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
358
-    }
357
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
358
+	}
359 359
 
360 360
 
361 361
 
362 362
 
363 363
 
364
-    /**
365
-     * This returns the _supports_labels property.
366
-     *
367
-     * @since 4.5.0
368
-     *
369
-     * @return stdClass
370
-     */
371
-    public function get_supports_labels()
372
-    {
373
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
374
-            $this->_set_supports_labels_defaults();
375
-        }
376
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
377
-    }
364
+	/**
365
+	 * This returns the _supports_labels property.
366
+	 *
367
+	 * @since 4.5.0
368
+	 *
369
+	 * @return stdClass
370
+	 */
371
+	public function get_supports_labels()
372
+	{
373
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
374
+			$this->_set_supports_labels_defaults();
375
+		}
376
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
377
+	}
378 378
 
379 379
 
380 380
 
381 381
 
382
-    /**
383
-     * Used to retrieve a variation (typically the path/url to a css file)
384
-     *
385
-     * @since 4.5.0
386
-     *
387
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
388
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
389
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
390
-     * @param string                    $type What variation type to return. Default is 'main'.
391
-     * @param string               $variation What variation for the template pack
392
-     * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
393
-     *
394
-     * @return string                    path or url for the requested variation.
395
-     */
396
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
397
-    {
398
-        $this->_tmp_pack = $pack;
399
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
400
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
401
-        return $variation_path;
402
-    }
382
+	/**
383
+	 * Used to retrieve a variation (typically the path/url to a css file)
384
+	 *
385
+	 * @since 4.5.0
386
+	 *
387
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
388
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
389
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
390
+	 * @param string                    $type What variation type to return. Default is 'main'.
391
+	 * @param string               $variation What variation for the template pack
392
+	 * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
393
+	 *
394
+	 * @return string                    path or url for the requested variation.
395
+	 */
396
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
397
+	{
398
+		$this->_tmp_pack = $pack;
399
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
400
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
401
+		return $variation_path;
402
+	}
403 403
 
404 404
 
405 405
 
@@ -407,492 +407,492 @@  discard block
 block discarded – undo
407 407
 
408 408
 
409 409
 
410
-    /**
411
-     * This just returns the default message types associated with this messenger when it is first activated.
412
-     *
413
-     * @access public
414
-     * @return array
415
-     */
416
-    public function get_default_message_types()
417
-    {
418
-        $class = get_class($this);
410
+	/**
411
+	 * This just returns the default message types associated with this messenger when it is first activated.
412
+	 *
413
+	 * @access public
414
+	 * @return array
415
+	 */
416
+	public function get_default_message_types()
417
+	{
418
+		$class = get_class($this);
419 419
 
420
-        // messenger specific filter
421
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
420
+		// messenger specific filter
421
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
422 422
 
423
-        // all messengers filter
424
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
425
-        return $default_types;
426
-    }
423
+		// all messengers filter
424
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
425
+		return $default_types;
426
+	}
427 427
 
428 428
 
429 429
 
430 430
 
431
-    /**
432
-     * Returns the valid message types associated with this messenger.
433
-     *
434
-     * @since 4.5.0
435
-     *
436
-     * @return array
437
-     */
438
-    public function get_valid_message_types()
439
-    {
440
-        $class = get_class($this);
441
-
442
-        // messenger specific filter
443
-        // messenger specific filter
444
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
445
-
446
-        // all messengers filter
447
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
448
-        return $valid_types;
449
-    }
450
-
451
-
452
-
453
-
454
-
455
-    /**
456
-     * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
457
-     *
458
-     * @access public
459
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
460
-     */
461
-    public function set_validator_config($new_config)
462
-    {
463
-        $this->_validator_config = $new_config;
464
-    }
465
-
466
-
467
-
468
-
469
-    /**
470
-     * This returns the _validator_config property
471
-     *
472
-     * @access public
473
-     * @return array
474
-     */
475
-    public function get_validator_config()
476
-    {
477
-        $class = get_class($this);
478
-
479
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
480
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
481
-        return $config;
482
-    }
483
-
484
-
485
-
486
-
487
-    /**
488
-     * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
489
-     *
490
-     * @param string $page the slug of the EE admin page
491
-     * @param array $message_types an array of active message type objects
492
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
493
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
494
-     * @access public
495
-     * @return string content for page
496
-     */
497
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
498
-    {
499
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
500
-    }
501
-
502
-
503
-
504
-    /**
505
-     * @param $message_types
506
-     * @param array $extra
507
-     * @return mixed|string
508
-     */
509
-    protected function _get_admin_content_events_edit($message_types, $extra)
510
-    {
511
-        // defaults
512
-        $template_args = array();
513
-        $selector_rows = '';
514
-
515
-        // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
516
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
517
-
518
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
519
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
520
-
521
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
522
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
523
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
524
-        );
525
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
526
-            $event_id,
527
-            array(
528
-                'MTP_messenger' => $this->name,
529
-                'MTP_is_active' => true
530
-            )
531
-        );
532
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
533
-
534
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
535
-        foreach ($global_templates as $mtpgID => $mtpg) {
536
-            if ($mtpg instanceof EE_Message_Template_Group) {
537
-                // verify this message type is supposed to show on this page
538
-                $mtp_obj = $mtpg->message_type_obj();
539
-                if (! $mtp_obj instanceof EE_message_type) {
540
-                    continue;
541
-                }
542
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
543
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
544
-                    continue;
545
-                }
546
-                $select_values = array();
547
-                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
548
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
549
-                // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
550
-                if (! $mtpg->get('MTP_is_override')) {
551
-                    // any custom templates for this message type?
552
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
553
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
554
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
555
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
556
-                    }
557
-                }
558
-                // if there is no $default_value then we set it as the global
559
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
560
-                $edit_url_query_args = [
561
-                    'page' => 'espresso_messages',
562
-                    'action' => 'edit_message_template',
563
-                    'id' => $default_value,
564
-                    'evt_id' => $event_id
565
-                ];
566
-                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
567
-                $create_url_query_args = [
568
-                    'page' => 'espresso_messages',
569
-                    'action' => 'add_new_message_template',
570
-                    'GRP_ID' => $default_value
571
-                ];
572
-                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
573
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
574
-                $st_args['mt_slug'] = $mtpg->message_type();
575
-                $st_args['messenger_slug'] = $this->name;
576
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
577
-                // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
578
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . esc_html__('Create New Custom', 'event_espresso') . '</a>';
579
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
580
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . esc_html__('Edit', 'event_espresso') . '</a>' : '';
581
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
582
-            }
583
-        }
584
-
585
-        // if no selectors present then get out.
586
-        if (empty($selector_rows)) {
587
-            return '';
588
-        }
589
-
590
-        $template_args['selector_rows'] = $selector_rows;
591
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
592
-    }
593
-
594
-
595
-
596
-
597
-
598
-
599
-    /**
600
-     * get_template_fields
601
-     *
602
-     * @access public
603
-     * @return array $this->_template_fields
604
-     */
605
-    public function get_template_fields()
606
-    {
607
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
608
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
609
-        return $template_fields;
610
-    }
611
-
612
-
613
-
614
-
615
-    /** SETUP METHODS **/
616
-    /**
617
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
618
-     * @param string $item
619
-     * @param mixed $value
620
-     */
621
-    protected function _set_template_value($item, $value)
622
-    {
623
-        if (array_key_exists($item, $this->_template_fields)) {
624
-            $prop = '_' . $item;
625
-            $this->{$prop} = $value;
626
-        }
627
-    }
628
-
629
-    /**
630
-     * Sets up the message for sending.
631
-     *
632
-     * @param  EE_message $message the message object that contains details about the message.
633
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
634
-     *
635
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
636
-     *              added to EE_Error.
637
-     *              true = message sent successfully
638
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
639
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
640
-     *
641
-     * @throws SendMessageException
642
-     */
643
-    final public function send_message($message, EE_message_type $message_type)
644
-    {
645
-        try {
646
-            $this->_validate_and_setup($message);
647
-            $this->_incoming_message_type = $message_type;
648
-            $response = $this->_send_message();
649
-            if ($response instanceof WP_Error) {
650
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
651
-                $response = false;
652
-            }
653
-        } catch (\Exception $e) {
654
-            // convert to an instance of SendMessageException
655
-            throw new SendMessageException($e->getMessage());
656
-        }
657
-        return $response;
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * Sets up and returns message preview
664
-     * @param  EE_Message $message incoming message object
665
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
666
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
667
-     * @return string          return the message html content
668
-     */
669
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
670
-    {
671
-        $this->_validate_and_setup($message);
672
-
673
-        $this->_incoming_message_type = $message_type;
674
-
675
-        if ($send) {
676
-            // are we overriding any existing template fields?
677
-            $settings = apply_filters(
678
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
679
-                $this->get_existing_test_settings(),
680
-                $this,
681
-                $send,
682
-                $message,
683
-                $message_type
684
-            );
685
-            if (! empty($settings)) {
686
-                foreach ($settings as $field => $value) {
687
-                    $this->_set_template_value($field, $value);
688
-                }
689
-            }
690
-        }
691
-
692
-        // enqueue preview js so that any links/buttons on the page are disabled.
693
-        if (! $send) {
694
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
695
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
696
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
698
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
699
-        }
700
-
701
-        return $send ? $this->_send_message() : $this->_preview();
702
-    }
703
-
704
-
705
-
706
-
707
-    /**
708
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
709
-     *
710
-     * @since 4.5.0
711
-     *
712
-     * @return void
713
-     */
714
-    public function add_preview_script()
715
-    {
716
-        // error message
717
-        EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
718
-            __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
719
-        );
720
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
721
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
722
-        wp_enqueue_script('ee-messages-preview-js');
723
-    }
724
-
725
-
726
-
727
-
728
-    /**
729
-     * simply validates the incoming message object and then sets up the properties for the messenger
730
-     * @param  EE_Message $message
731
-     * @throws EE_Error
732
-     */
733
-    protected function _validate_and_setup(EE_Message $message)
734
-    {
735
-        $template_pack = $message->get_template_pack();
736
-        $variation = $message->get_template_pack_variation();
737
-
738
-        // verify we have the required template pack value on the $message object.
739
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
740
-            throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
741
-        }
742
-
743
-        $this->_tmp_pack = $template_pack;
744
-
745
-        $this->_variation = $variation ? $variation : 'default';
746
-
747
-        $template_fields = $this->get_template_fields();
748
-
749
-        foreach ($template_fields as $template => $value) {
750
-            if ($template !== 'extra') {
751
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
752
-                $message_template_value = $column_value ? $column_value : null;
753
-                $this->_set_template_value($template, $message_template_value);
754
-            }
755
-        }
756
-    }
757
-
758
-
759
-
760
-    /**
761
-     * Utility method for child classes to get the contents of a template file and return
762
-     *
763
-     * We're assuming the child messenger class has already setup template args!
764
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
765
-     * @return string
766
-     * @throws \EE_Error
767
-     */
768
-    protected function _get_main_template($preview = false)
769
-    {
770
-        $type = $preview ? 'preview' : 'main';
771
-
772
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
773
-
774
-        // check file exists and is readable
775
-        if (!is_readable($wrapper_template)) {
776
-            throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
777
-        }
778
-
779
-        // add message type to template args
780
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
781
-
782
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
783
-    }
784
-
785
-
786
-
787
-    /**
788
-     * set the _test_settings_fields property
789
-     *
790
-     * @access protected
791
-     * @return void
792
-     */
793
-    protected function _set_test_settings_fields()
794
-    {
795
-        $this->_test_settings_fields = array();
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     * return the _test_settings_fields property
802
-     * @return array
803
-     */
804
-    public function get_test_settings_fields()
805
-    {
806
-        return $this->_test_settings_fields;
807
-    }
808
-
809
-
810
-
811
-
812
-    /**
813
-     * This just returns any existing test settings that might be saved in the database
814
-     *
815
-     * @access public
816
-     * @return array
817
-     */
818
-    public function get_existing_test_settings()
819
-    {
820
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
821
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
822
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
823
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
824
-    }
825
-
826
-
827
-
828
-    /**
829
-     * All this does is set the existing test settings (in the db) for the messenger
830
-     *
831
-     * @access public
832
-     * @param $settings
833
-     * @return bool success/fail
834
-     */
835
-    public function set_existing_test_settings($settings)
836
-    {
837
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
838
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
839
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
840
-        $existing[ $this->name ]['test_settings'] = $settings;
841
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * This just returns the field label for a given field setup in the _template_fields property.
848
-     *
849
-     * @since   4.3.0
850
-     *
851
-     * @param string $field The field to retrieve the label for
852
-     * @return string             The label
853
-     */
854
-    public function get_field_label($field)
855
-    {
856
-        // first let's see if the field requests is in the top level array.
857
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
858
-            return $this->_template[ $field ]['label'];
859
-        }
860
-
861
-        // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
862
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
863
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
864
-        }
865
-
866
-        // now it's possible this field may just be existing in any of the extra array items.
867
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
868
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
869
-                if (!is_array($subfields)) {
870
-                    continue;
871
-                }
872
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
873
-                    return $subfields[ $field ]['label'];
874
-                }
875
-            }
876
-        }
877
-
878
-        // if we made it here then there's no label set so let's just return the $field.
879
-        return $field;
880
-    }
881
-
882
-
883
-
884
-
885
-    /**
886
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
887
-     *
888
-     * @since 4.5.0
889
-     *
890
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
891
-     *
892
-     * @return void
893
-     */
894
-    public function do_secondary_messenger_hooks($sending_messenger_name)
895
-    {
896
-        return;
897
-    }
431
+	/**
432
+	 * Returns the valid message types associated with this messenger.
433
+	 *
434
+	 * @since 4.5.0
435
+	 *
436
+	 * @return array
437
+	 */
438
+	public function get_valid_message_types()
439
+	{
440
+		$class = get_class($this);
441
+
442
+		// messenger specific filter
443
+		// messenger specific filter
444
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
445
+
446
+		// all messengers filter
447
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
448
+		return $valid_types;
449
+	}
450
+
451
+
452
+
453
+
454
+
455
+	/**
456
+	 * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
457
+	 *
458
+	 * @access public
459
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
460
+	 */
461
+	public function set_validator_config($new_config)
462
+	{
463
+		$this->_validator_config = $new_config;
464
+	}
465
+
466
+
467
+
468
+
469
+	/**
470
+	 * This returns the _validator_config property
471
+	 *
472
+	 * @access public
473
+	 * @return array
474
+	 */
475
+	public function get_validator_config()
476
+	{
477
+		$class = get_class($this);
478
+
479
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
480
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
481
+		return $config;
482
+	}
483
+
484
+
485
+
486
+
487
+	/**
488
+	 * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
489
+	 *
490
+	 * @param string $page the slug of the EE admin page
491
+	 * @param array $message_types an array of active message type objects
492
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
493
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
494
+	 * @access public
495
+	 * @return string content for page
496
+	 */
497
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
498
+	{
499
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
500
+	}
501
+
502
+
503
+
504
+	/**
505
+	 * @param $message_types
506
+	 * @param array $extra
507
+	 * @return mixed|string
508
+	 */
509
+	protected function _get_admin_content_events_edit($message_types, $extra)
510
+	{
511
+		// defaults
512
+		$template_args = array();
513
+		$selector_rows = '';
514
+
515
+		// we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
516
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
517
+
518
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
519
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
520
+
521
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
522
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
523
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
524
+		);
525
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
526
+			$event_id,
527
+			array(
528
+				'MTP_messenger' => $this->name,
529
+				'MTP_is_active' => true
530
+			)
531
+		);
532
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
533
+
534
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
535
+		foreach ($global_templates as $mtpgID => $mtpg) {
536
+			if ($mtpg instanceof EE_Message_Template_Group) {
537
+				// verify this message type is supposed to show on this page
538
+				$mtp_obj = $mtpg->message_type_obj();
539
+				if (! $mtp_obj instanceof EE_message_type) {
540
+					continue;
541
+				}
542
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
543
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
544
+					continue;
545
+				}
546
+				$select_values = array();
547
+				$select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
548
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
549
+				// if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
550
+				if (! $mtpg->get('MTP_is_override')) {
551
+					// any custom templates for this message type?
552
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
553
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
554
+						$select_values[ $cmtpgID ] = $cmtpg->name();
555
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
556
+					}
557
+				}
558
+				// if there is no $default_value then we set it as the global
559
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
560
+				$edit_url_query_args = [
561
+					'page' => 'espresso_messages',
562
+					'action' => 'edit_message_template',
563
+					'id' => $default_value,
564
+					'evt_id' => $event_id
565
+				];
566
+				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
567
+				$create_url_query_args = [
568
+					'page' => 'espresso_messages',
569
+					'action' => 'add_new_message_template',
570
+					'GRP_ID' => $default_value
571
+				];
572
+				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
573
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
574
+				$st_args['mt_slug'] = $mtpg->message_type();
575
+				$st_args['messenger_slug'] = $this->name;
576
+				$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
577
+				// note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
578
+				$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . esc_html__('Create New Custom', 'event_espresso') . '</a>';
579
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
580
+				$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . esc_html__('Edit', 'event_espresso') . '</a>' : '';
581
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
582
+			}
583
+		}
584
+
585
+		// if no selectors present then get out.
586
+		if (empty($selector_rows)) {
587
+			return '';
588
+		}
589
+
590
+		$template_args['selector_rows'] = $selector_rows;
591
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
592
+	}
593
+
594
+
595
+
596
+
597
+
598
+
599
+	/**
600
+	 * get_template_fields
601
+	 *
602
+	 * @access public
603
+	 * @return array $this->_template_fields
604
+	 */
605
+	public function get_template_fields()
606
+	{
607
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
608
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
609
+		return $template_fields;
610
+	}
611
+
612
+
613
+
614
+
615
+	/** SETUP METHODS **/
616
+	/**
617
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
618
+	 * @param string $item
619
+	 * @param mixed $value
620
+	 */
621
+	protected function _set_template_value($item, $value)
622
+	{
623
+		if (array_key_exists($item, $this->_template_fields)) {
624
+			$prop = '_' . $item;
625
+			$this->{$prop} = $value;
626
+		}
627
+	}
628
+
629
+	/**
630
+	 * Sets up the message for sending.
631
+	 *
632
+	 * @param  EE_message $message the message object that contains details about the message.
633
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
634
+	 *
635
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
636
+	 *              added to EE_Error.
637
+	 *              true = message sent successfully
638
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
639
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
640
+	 *
641
+	 * @throws SendMessageException
642
+	 */
643
+	final public function send_message($message, EE_message_type $message_type)
644
+	{
645
+		try {
646
+			$this->_validate_and_setup($message);
647
+			$this->_incoming_message_type = $message_type;
648
+			$response = $this->_send_message();
649
+			if ($response instanceof WP_Error) {
650
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
651
+				$response = false;
652
+			}
653
+		} catch (\Exception $e) {
654
+			// convert to an instance of SendMessageException
655
+			throw new SendMessageException($e->getMessage());
656
+		}
657
+		return $response;
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * Sets up and returns message preview
664
+	 * @param  EE_Message $message incoming message object
665
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
666
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
667
+	 * @return string          return the message html content
668
+	 */
669
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
670
+	{
671
+		$this->_validate_and_setup($message);
672
+
673
+		$this->_incoming_message_type = $message_type;
674
+
675
+		if ($send) {
676
+			// are we overriding any existing template fields?
677
+			$settings = apply_filters(
678
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
679
+				$this->get_existing_test_settings(),
680
+				$this,
681
+				$send,
682
+				$message,
683
+				$message_type
684
+			);
685
+			if (! empty($settings)) {
686
+				foreach ($settings as $field => $value) {
687
+					$this->_set_template_value($field, $value);
688
+				}
689
+			}
690
+		}
691
+
692
+		// enqueue preview js so that any links/buttons on the page are disabled.
693
+		if (! $send) {
694
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
695
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
696
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
698
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
699
+		}
700
+
701
+		return $send ? $this->_send_message() : $this->_preview();
702
+	}
703
+
704
+
705
+
706
+
707
+	/**
708
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
709
+	 *
710
+	 * @since 4.5.0
711
+	 *
712
+	 * @return void
713
+	 */
714
+	public function add_preview_script()
715
+	{
716
+		// error message
717
+		EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
718
+			__('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
719
+		);
720
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
721
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
722
+		wp_enqueue_script('ee-messages-preview-js');
723
+	}
724
+
725
+
726
+
727
+
728
+	/**
729
+	 * simply validates the incoming message object and then sets up the properties for the messenger
730
+	 * @param  EE_Message $message
731
+	 * @throws EE_Error
732
+	 */
733
+	protected function _validate_and_setup(EE_Message $message)
734
+	{
735
+		$template_pack = $message->get_template_pack();
736
+		$variation = $message->get_template_pack_variation();
737
+
738
+		// verify we have the required template pack value on the $message object.
739
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
740
+			throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
741
+		}
742
+
743
+		$this->_tmp_pack = $template_pack;
744
+
745
+		$this->_variation = $variation ? $variation : 'default';
746
+
747
+		$template_fields = $this->get_template_fields();
748
+
749
+		foreach ($template_fields as $template => $value) {
750
+			if ($template !== 'extra') {
751
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
752
+				$message_template_value = $column_value ? $column_value : null;
753
+				$this->_set_template_value($template, $message_template_value);
754
+			}
755
+		}
756
+	}
757
+
758
+
759
+
760
+	/**
761
+	 * Utility method for child classes to get the contents of a template file and return
762
+	 *
763
+	 * We're assuming the child messenger class has already setup template args!
764
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
765
+	 * @return string
766
+	 * @throws \EE_Error
767
+	 */
768
+	protected function _get_main_template($preview = false)
769
+	{
770
+		$type = $preview ? 'preview' : 'main';
771
+
772
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
773
+
774
+		// check file exists and is readable
775
+		if (!is_readable($wrapper_template)) {
776
+			throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
777
+		}
778
+
779
+		// add message type to template args
780
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
781
+
782
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
783
+	}
784
+
785
+
786
+
787
+	/**
788
+	 * set the _test_settings_fields property
789
+	 *
790
+	 * @access protected
791
+	 * @return void
792
+	 */
793
+	protected function _set_test_settings_fields()
794
+	{
795
+		$this->_test_settings_fields = array();
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 * return the _test_settings_fields property
802
+	 * @return array
803
+	 */
804
+	public function get_test_settings_fields()
805
+	{
806
+		return $this->_test_settings_fields;
807
+	}
808
+
809
+
810
+
811
+
812
+	/**
813
+	 * This just returns any existing test settings that might be saved in the database
814
+	 *
815
+	 * @access public
816
+	 * @return array
817
+	 */
818
+	public function get_existing_test_settings()
819
+	{
820
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
821
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
822
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
823
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
824
+	}
825
+
826
+
827
+
828
+	/**
829
+	 * All this does is set the existing test settings (in the db) for the messenger
830
+	 *
831
+	 * @access public
832
+	 * @param $settings
833
+	 * @return bool success/fail
834
+	 */
835
+	public function set_existing_test_settings($settings)
836
+	{
837
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
838
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
839
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
840
+		$existing[ $this->name ]['test_settings'] = $settings;
841
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * This just returns the field label for a given field setup in the _template_fields property.
848
+	 *
849
+	 * @since   4.3.0
850
+	 *
851
+	 * @param string $field The field to retrieve the label for
852
+	 * @return string             The label
853
+	 */
854
+	public function get_field_label($field)
855
+	{
856
+		// first let's see if the field requests is in the top level array.
857
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
858
+			return $this->_template[ $field ]['label'];
859
+		}
860
+
861
+		// nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
862
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
863
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
864
+		}
865
+
866
+		// now it's possible this field may just be existing in any of the extra array items.
867
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
868
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
869
+				if (!is_array($subfields)) {
870
+					continue;
871
+				}
872
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
873
+					return $subfields[ $field ]['label'];
874
+				}
875
+			}
876
+		}
877
+
878
+		// if we made it here then there's no label set so let's just return the $field.
879
+		return $field;
880
+	}
881
+
882
+
883
+
884
+
885
+	/**
886
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
887
+	 *
888
+	 * @since 4.5.0
889
+	 *
890
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
891
+	 *
892
+	 * @return void
893
+	 */
894
+	public function do_secondary_messenger_hooks($sending_messenger_name)
895
+	{
896
+		return;
897
+	}
898 898
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
         $class = get_class($this);
419 419
 
420 420
         // messenger specific filter
421
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
421
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
422 422
 
423 423
         // all messengers filter
424 424
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 
442 442
         // messenger specific filter
443 443
         // messenger specific filter
444
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
445 445
 
446 446
         // all messengers filter
447 447
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
     {
477 477
         $class = get_class($this);
478 478
 
479
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
480 480
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
481 481
         return $config;
482 482
     }
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
         // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
516 516
         $event_id = isset($extra['event']) ? $extra['event'] : null;
517 517
 
518
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
519
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
518
+        $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
519
+        $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
520 520
 
521 521
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
522 522
         $global_templates = EEM_Message_Template_Group::instance()->get_all(
523
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
524 524
         );
525 525
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
526 526
             $event_id,
@@ -529,29 +529,29 @@  discard block
 block discarded – undo
529 529
                 'MTP_is_active' => true
530 530
             )
531 531
         );
532
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
533 533
 
534 534
         // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
535 535
         foreach ($global_templates as $mtpgID => $mtpg) {
536 536
             if ($mtpg instanceof EE_Message_Template_Group) {
537 537
                 // verify this message type is supposed to show on this page
538 538
                 $mtp_obj = $mtpg->message_type_obj();
539
-                if (! $mtp_obj instanceof EE_message_type) {
539
+                if ( ! $mtp_obj instanceof EE_message_type) {
540 540
                     continue;
541 541
                 }
542 542
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
543
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
544 544
                     continue;
545 545
                 }
546 546
                 $select_values = array();
547
-                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
547
+                $select_values[$mtpgID] = esc_html__('Global', 'event_espresso');
548 548
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
549 549
                 // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
550
-                if (! $mtpg->get('MTP_is_override')) {
550
+                if ( ! $mtpg->get('MTP_is_override')) {
551 551
                     // any custom templates for this message type?
552 552
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
553 553
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
554
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
554
+                        $select_values[$cmtpgID] = $cmtpg->name();
555 555
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
556 556
                     }
557 557
                 }
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
574 574
                 $st_args['mt_slug'] = $mtpg->message_type();
575 575
                 $st_args['messenger_slug'] = $this->name;
576
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
576
+                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector');
577 577
                 // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
578
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . esc_html__('Create New Custom', 'event_espresso') . '</a>';
578
+                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.esc_html__('Create New Custom', 'event_espresso').'</a>';
579 579
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
580
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . esc_html__('Edit', 'event_espresso') . '</a>' : '';
580
+                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.esc_html__('Edit', 'event_espresso').'</a>' : '';
581 581
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
582 582
             }
583 583
         }
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
      */
605 605
     public function get_template_fields()
606 606
     {
607
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
607
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
608 608
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
609 609
         return $template_fields;
610 610
     }
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
     protected function _set_template_value($item, $value)
622 622
     {
623 623
         if (array_key_exists($item, $this->_template_fields)) {
624
-            $prop = '_' . $item;
624
+            $prop = '_'.$item;
625 625
             $this->{$prop} = $value;
626 626
         }
627 627
     }
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                 $message,
683 683
                 $message_type
684 684
             );
685
-            if (! empty($settings)) {
685
+            if ( ! empty($settings)) {
686 686
                 foreach ($settings as $field => $value) {
687 687
                     $this->_set_template_value($field, $value);
688 688
                 }
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
         }
691 691
 
692 692
         // enqueue preview js so that any links/buttons on the page are disabled.
693
-        if (! $send) {
693
+        if ( ! $send) {
694 694
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
695 695
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
696
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
698
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
696
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
697
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
698
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
699 699
         }
700 700
 
701 701
         return $send ? $this->_send_message() : $this->_preview();
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
         EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
718 718
             __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
719 719
         );
720
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
720
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
721 721
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
722 722
         wp_enqueue_script('ee-messages-preview-js');
723 723
     }
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
         $variation = $message->get_template_pack_variation();
737 737
 
738 738
         // verify we have the required template pack value on the $message object.
739
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
739
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
740 740
             throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
741 741
         }
742 742
 
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 
749 749
         foreach ($template_fields as $template => $value) {
750 750
             if ($template !== 'extra') {
751
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
751
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
752 752
                 $message_template_value = $column_value ? $column_value : null;
753 753
                 $this->_set_template_value($template, $message_template_value);
754 754
             }
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
773 773
 
774 774
         // check file exists and is readable
775
-        if (!is_readable($wrapper_template)) {
775
+        if ( ! is_readable($wrapper_template)) {
776 776
             throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
777 777
         }
778 778
 
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
821 821
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
822 822
         $settings = $Message_Resource_Manager->get_active_messengers_option();
823
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
823
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
824 824
     }
825 825
 
826 826
 
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
838 838
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
839 839
         $existing = $Message_Resource_Manager->get_active_messengers_option();
840
-        $existing[ $this->name ]['test_settings'] = $settings;
840
+        $existing[$this->name]['test_settings'] = $settings;
841 841
         return $Message_Resource_Manager->update_active_messengers_option($existing);
842 842
     }
843 843
 
@@ -854,23 +854,23 @@  discard block
 block discarded – undo
854 854
     public function get_field_label($field)
855 855
     {
856 856
         // first let's see if the field requests is in the top level array.
857
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
858
-            return $this->_template[ $field ]['label'];
857
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
858
+            return $this->_template[$field]['label'];
859 859
         }
860 860
 
861 861
         // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
862
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
863
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
862
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
863
+            return $this->_template_fields['extra'][$field]['main']['label'];
864 864
         }
865 865
 
866 866
         // now it's possible this field may just be existing in any of the extra array items.
867
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
867
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
868 868
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
869
-                if (!is_array($subfields)) {
869
+                if ( ! is_array($subfields)) {
870 870
                     continue;
871 871
                 }
872
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
873
-                    return $subfields[ $field ]['label'];
872
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
873
+                    return $subfields[$field]['label'];
874 874
                 }
875 875
             }
876 876
         }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Payment_Base_message_type.lib.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -15,67 +15,67 @@
 block discarded – undo
15 15
 
16 16
 
17 17
 
18
-    /**
19
-     * @see parent::get_priority() for documentation.
20
-     * @return int
21
-     */
22
-    public function get_priority()
23
-    {
24
-        return EEM_Message::priority_high;
25
-    }
18
+	/**
19
+	 * @see parent::get_priority() for documentation.
20
+	 * @return int
21
+	 */
22
+	public function get_priority()
23
+	{
24
+		return EEM_Message::priority_high;
25
+	}
26 26
 
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * see abstract declaration in parent class for details.
32
-     */
33
-    protected function _set_admin_pages()
34
-    {
35
-        $this->admin_registered_pages = array(
36
-            'events_edit' => true
37
-            );
38
-    }
30
+	/**
31
+	 * see abstract declaration in parent class for details.
32
+	 */
33
+	protected function _set_admin_pages()
34
+	{
35
+		$this->admin_registered_pages = array(
36
+			'events_edit' => true
37
+			);
38
+	}
39 39
 
40 40
 
41 41
 
42
-    protected function _set_data_handler()
43
-    {
44
-        $this->_data_handler = 'Gateways';
45
-    }
42
+	protected function _set_data_handler()
43
+	{
44
+		$this->_data_handler = 'Gateways';
45
+	}
46 46
 
47 47
 
48 48
 
49 49
 
50
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
51
-    {
50
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
51
+	{
52 52
 
53
-        // use the registration to get the transaction.
54
-        $transaction = $registration->transaction();
53
+		// use the registration to get the transaction.
54
+		$transaction = $registration->transaction();
55 55
 
56
-        // bail early if no transaction
57
-        if (! $transaction instanceof EE_Transaction) {
58
-            throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
59
-        }
56
+		// bail early if no transaction
57
+		if (! $transaction instanceof EE_Transaction) {
58
+			throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
59
+		}
60 60
 
61
-        $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
61
+		$payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
62 62
 
63
-        return array( $transaction, $payment );
64
-    }
63
+		return array( $transaction, $payment );
64
+	}
65 65
 
66 66
 
67 67
 
68
-    protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
69
-    {
70
-        // this is just a test
71
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
72
-    }
68
+	protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
69
+	{
70
+		// this is just a test
71
+		return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
72
+	}
73 73
 
74
-    /**
75
-     * This message type doesn't need any settings so we are just setting to empty array.
76
-     */
77
-    protected function _set_admin_settings_fields()
78
-    {
79
-        $this->_admin_settings_fields = array();
80
-    }
74
+	/**
75
+	 * This message type doesn't need any settings so we are just setting to empty array.
76
+	 */
77
+	protected function _set_admin_settings_fields()
78
+	{
79
+		$this->_admin_settings_fields = array();
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
         $transaction = $registration->transaction();
55 55
 
56 56
         // bail early if no transaction
57
-        if (! $transaction instanceof EE_Transaction) {
57
+        if ( ! $transaction instanceof EE_Transaction) {
58 58
             throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
59 59
         }
60 60
 
61
-        $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
61
+        $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0;
62 62
 
63
-        return array( $transaction, $payment );
63
+        return array($transaction, $payment);
64 64
     }
65 65
 
66 66
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
69 69
     {
70 70
         // this is just a test
71
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
71
+        return $this->name.' Message Type for '.$messenger->name.' Messenger ';
72 72
     }
73 73
 
74 74
     /**
Please login to merge, or discard this patch.
libraries/messages/message_type/EE_Payment_Refund_message_type.class.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -15,50 +15,50 @@
 block discarded – undo
15 15
 class EE_Payment_Refund_message_type extends EE_Payment_Base_message_type
16 16
 {
17 17
 
18
-    public function __construct()
19
-    {
18
+	public function __construct()
19
+	{
20 20
 
21
-        // setup type details for reference
22
-        $this->name = 'payment_refund';
23
-        $this->description = esc_html__('This message type is used for all payment notification messages that go out for refunds.', 'event_espresso');
24
-        $this->label = array(
25
-            'singular' => esc_html__('refund issued', 'event_espresso'),
26
-            'plural' => esc_html__('refunds issued', 'event_espresso')
27
-            );
21
+		// setup type details for reference
22
+		$this->name = 'payment_refund';
23
+		$this->description = esc_html__('This message type is used for all payment notification messages that go out for refunds.', 'event_espresso');
24
+		$this->label = array(
25
+			'singular' => esc_html__('refund issued', 'event_espresso'),
26
+			'plural' => esc_html__('refunds issued', 'event_espresso')
27
+			);
28 28
 
29
-        $this->_master_templates = array(
30
-            'email' => 'payment'
31
-            );
29
+		$this->_master_templates = array(
30
+			'email' => 'payment'
31
+			);
32 32
 
33
-        parent::__construct();
34
-    }
33
+		parent::__construct();
34
+	}
35 35
 
36 36
 
37 37
 
38
-    /**
39
-     * _set_contexts
40
-     * This sets up the contexts associated with the message_type
41
-     *
42
-     * @access  protected
43
-     * @return  void
44
-     */
45
-    protected function _set_contexts()
46
-    {
47
-        $this->_context_label = array(
48
-            'label' => esc_html__('recipient', 'event_espresso'),
49
-            'plural' => esc_html__('recipients', 'event_espresso'),
50
-            'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different payment details sent out depending on who the recipient is', 'event_espresso')
51
-            );
38
+	/**
39
+	 * _set_contexts
40
+	 * This sets up the contexts associated with the message_type
41
+	 *
42
+	 * @access  protected
43
+	 * @return  void
44
+	 */
45
+	protected function _set_contexts()
46
+	{
47
+		$this->_context_label = array(
48
+			'label' => esc_html__('recipient', 'event_espresso'),
49
+			'plural' => esc_html__('recipients', 'event_espresso'),
50
+			'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different payment details sent out depending on who the recipient is', 'event_espresso')
51
+			);
52 52
 
53
-        $this->_contexts = array(
54
-            'admin' => array(
55
-                'label' => esc_html__('Event Admin', 'event_espresso'),
56
-                'description' => esc_html__('This template is what event administrators will receive on a successful refund.', 'event_espresso')
57
-                ),
58
-            'primary_attendee' => array(
59
-                'label' => esc_html__('Primary Registrant', 'event_espresso'),
60
-                'description' => esc_html__('This template is what the primary registrant (the person who made the main registration) will receive on successful refund.', 'event_espresso')
61
-                )
62
-            );
63
-    }
53
+		$this->_contexts = array(
54
+			'admin' => array(
55
+				'label' => esc_html__('Event Admin', 'event_espresso'),
56
+				'description' => esc_html__('This template is what event administrators will receive on a successful refund.', 'event_espresso')
57
+				),
58
+			'primary_attendee' => array(
59
+				'label' => esc_html__('Primary Registrant', 'event_espresso'),
60
+				'description' => esc_html__('This template is what the primary registrant (the person who made the main registration) will receive on successful refund.', 'event_espresso')
61
+				)
62
+			);
63
+	}
64 64
 }
Please login to merge, or discard this patch.
core/libraries/messages/message_type/EE_Registration_message_type.class.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -14,48 +14,48 @@
 block discarded – undo
14 14
 class EE_Registration_message_type extends EE_Registration_Base_message_type
15 15
 {
16 16
 
17
-    public function __construct()
18
-    {
19
-        $this->name = 'registration';
20
-        $this->description = esc_html__('This message type is for messages sent to attendees when their registration is approved.', 'event_espresso');
21
-        $this->label = array(
22
-            'singular' => esc_html__('registration approved', 'event_espresso'),
23
-            'plural' => esc_html__('registrations approved', 'event_espresso')
24
-            );
17
+	public function __construct()
18
+	{
19
+		$this->name = 'registration';
20
+		$this->description = esc_html__('This message type is for messages sent to attendees when their registration is approved.', 'event_espresso');
21
+		$this->label = array(
22
+			'singular' => esc_html__('registration approved', 'event_espresso'),
23
+			'plural' => esc_html__('registrations approved', 'event_espresso')
24
+			);
25 25
 
26
-        parent::__construct();
27
-    }
26
+		parent::__construct();
27
+	}
28 28
 
29 29
 
30 30
 
31
-    /**
32
-     * _set_contexts
33
-     * This sets up the contexts associated with the message_type
34
-     *
35
-     * @access  protected
36
-     * @return  void
37
-     */
38
-    protected function _set_contexts()
39
-    {
40
-        $this->_context_label = array(
41
-            'label' => esc_html__('recipient', 'event_espresso'),
42
-            'plural' => esc_html__('recipients', 'event_espresso'),
43
-            'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
44
-            );
31
+	/**
32
+	 * _set_contexts
33
+	 * This sets up the contexts associated with the message_type
34
+	 *
35
+	 * @access  protected
36
+	 * @return  void
37
+	 */
38
+	protected function _set_contexts()
39
+	{
40
+		$this->_context_label = array(
41
+			'label' => esc_html__('recipient', 'event_espresso'),
42
+			'plural' => esc_html__('recipients', 'event_espresso'),
43
+			'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
44
+			);
45 45
 
46
-        $this->_contexts = array(
47
-            'admin' => array(
48
-                'label' => esc_html__('Event Admin', 'event_espresso'),
49
-                'description' => esc_html__('This template is what event administrators will receive with an approved registration', 'event_espresso')
50
-                ),
51
-            'primary_attendee' => array(
52
-                'label' => esc_html__('Primary Registrant', 'event_espresso'),
53
-                'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive with approved registration', 'event_espresso')
54
-                ),
55
-            'attendee' => array(
56
-                'label' => esc_html__('Registrant', 'event_espresso'),
57
-                'description' => esc_html__('This template is what each registrant for the event will receive when their registration is approved.', 'event_espresso')
58
-                )
59
-            );
60
-    }
46
+		$this->_contexts = array(
47
+			'admin' => array(
48
+				'label' => esc_html__('Event Admin', 'event_espresso'),
49
+				'description' => esc_html__('This template is what event administrators will receive with an approved registration', 'event_espresso')
50
+				),
51
+			'primary_attendee' => array(
52
+				'label' => esc_html__('Primary Registrant', 'event_espresso'),
53
+				'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive with approved registration', 'event_espresso')
54
+				),
55
+			'attendee' => array(
56
+				'label' => esc_html__('Registrant', 'event_espresso'),
57
+				'description' => esc_html__('This template is what each registrant for the event will receive when their registration is approved.', 'event_espresso')
58
+				)
59
+			);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
libraries/messages/message_type/EE_Pending_Approval_message_type.class.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
 class EE_Pending_Approval_message_type extends EE_Registration_Base_message_type
15 15
 {
16 16
 
17
-    public function __construct()
18
-    {
19
-        $this->name = 'pending_approval';
20
-        $this->description = esc_html__('This message type is used for recipients who have Pending Payment registration status.', 'event_espresso');
21
-        $this->label = array(
22
-            'singular' => esc_html__('registration pending payment', 'event_espresso'),
23
-            'plural' => esc_html__('registrations pending payment', 'event_espresso')
24
-            );
17
+	public function __construct()
18
+	{
19
+		$this->name = 'pending_approval';
20
+		$this->description = esc_html__('This message type is used for recipients who have Pending Payment registration status.', 'event_espresso');
21
+		$this->label = array(
22
+			'singular' => esc_html__('registration pending payment', 'event_espresso'),
23
+			'plural' => esc_html__('registrations pending payment', 'event_espresso')
24
+			);
25 25
 
26
-        $this->_master_templates = array(
27
-            'email' => 'registration'
28
-            );
26
+		$this->_master_templates = array(
27
+			'email' => 'registration'
28
+			);
29 29
 
30
-        parent::__construct();
31
-    }
30
+		parent::__construct();
31
+	}
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * _set_contexts
37
-     * This sets up the contexts associated with the message_type
38
-     *
39
-     * @access  protected
40
-     * @return  void
41
-     */
42
-    protected function _set_contexts()
43
-    {
44
-        $this->_context_label = array(
45
-            'label' => esc_html__('recipient', 'event_espresso'),
46
-            'plural' => esc_html__('recipients', 'event_espresso'),
47
-            'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different pending approval details sent out depending on who the recipient is.  To "turn off" a recipient from receiving message, simply remove any content from the "to" field in the template.', 'event_espresso')
48
-            );
35
+	/**
36
+	 * _set_contexts
37
+	 * This sets up the contexts associated with the message_type
38
+	 *
39
+	 * @access  protected
40
+	 * @return  void
41
+	 */
42
+	protected function _set_contexts()
43
+	{
44
+		$this->_context_label = array(
45
+			'label' => esc_html__('recipient', 'event_espresso'),
46
+			'plural' => esc_html__('recipients', 'event_espresso'),
47
+			'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different pending approval details sent out depending on who the recipient is.  To "turn off" a recipient from receiving message, simply remove any content from the "to" field in the template.', 'event_espresso')
48
+			);
49 49
 
50
-        $this->_contexts = array(
51
-            'admin' => array(
52
-                'label' => esc_html__('Event Admin', 'event_espresso'),
53
-                'description' => esc_html__('This template is what event administrators will receive when a message is sent to registrants with the pending payment registration status.', 'event_espresso')
54
-                ),
55
-            'primary_attendee' => array(
56
-                'label' => esc_html__('Primary Registrant', 'event_espresso'),
57
-                'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive on when their registration status is pending payment.', 'event_espresso')
58
-                )
59
-            );
60
-    }
50
+		$this->_contexts = array(
51
+			'admin' => array(
52
+				'label' => esc_html__('Event Admin', 'event_espresso'),
53
+				'description' => esc_html__('This template is what event administrators will receive when a message is sent to registrants with the pending payment registration status.', 'event_espresso')
54
+				),
55
+			'primary_attendee' => array(
56
+				'label' => esc_html__('Primary Registrant', 'event_espresso'),
57
+				'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive on when their registration status is pending payment.', 'event_espresso')
58
+				)
59
+			);
60
+	}
61 61
 
62 62
 
63 63
 
64
-    protected function _primary_attendee_addressees()
65
-    {
66
-        $cached = $this->_single_message;
67
-        $this->_single_message = false;
68
-        $addressees = parent::_primary_attendee_addressees();
69
-        $this->_single_message = $cached;
70
-        return $addressees;
71
-    }
64
+	protected function _primary_attendee_addressees()
65
+	{
66
+		$cached = $this->_single_message;
67
+		$this->_single_message = false;
68
+		$addressees = parent::_primary_attendee_addressees();
69
+		$this->_single_message = $cached;
70
+		return $addressees;
71
+	}
72 72
 }
Please login to merge, or discard this patch.
messages/message_type/EE_Registration_Summary_message_type.class.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,59 +16,59 @@
 block discarded – undo
16 16
 class EE_Registration_Summary_message_type extends EE_Registration_Base_message_type
17 17
 {
18 18
 
19
-    public function __construct()
20
-    {
21
-        $this->name = 'registration_summary';
22
-        $this->description = esc_html__('This message type provides a summary notification to Primary Registrants and Admin recipients when there are multiple registrations in a transaction with different statuses.', 'event_espresso');
23
-        $this->label = array(
24
-            'singular' => esc_html__('registration multi-status summary', 'event_espresso'),
25
-            'plural' => esc_html__('registrations multi-status summary', 'event_espresso')
26
-            );
19
+	public function __construct()
20
+	{
21
+		$this->name = 'registration_summary';
22
+		$this->description = esc_html__('This message type provides a summary notification to Primary Registrants and Admin recipients when there are multiple registrations in a transaction with different statuses.', 'event_espresso');
23
+		$this->label = array(
24
+			'singular' => esc_html__('registration multi-status summary', 'event_espresso'),
25
+			'plural' => esc_html__('registrations multi-status summary', 'event_espresso')
26
+			);
27 27
 
28
-        $this->_master_templates = array(
29
-            'email' => 'registration'
30
-            );
28
+		$this->_master_templates = array(
29
+			'email' => 'registration'
30
+			);
31 31
 
32
-        parent::__construct();
33
-    }
32
+		parent::__construct();
33
+	}
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * _set_contexts
39
-     * This sets up the contexts associated with the message_type
40
-     *
41
-     * @access  protected
42
-     * @return  void
43
-     */
44
-    protected function _set_contexts()
45
-    {
46
-        $this->_context_label = array(
47
-            'label' => esc_html__('recipient', 'event_espresso'),
48
-            'plural' => esc_html__('recipients', 'event_espresso'),
49
-            'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different details sent out depending on who the recipient is.  To "turn off" a recipient from receiving message, simply remove any content from the "to" field in the template.', 'event_espresso')
50
-            );
37
+	/**
38
+	 * _set_contexts
39
+	 * This sets up the contexts associated with the message_type
40
+	 *
41
+	 * @access  protected
42
+	 * @return  void
43
+	 */
44
+	protected function _set_contexts()
45
+	{
46
+		$this->_context_label = array(
47
+			'label' => esc_html__('recipient', 'event_espresso'),
48
+			'plural' => esc_html__('recipients', 'event_espresso'),
49
+			'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different details sent out depending on who the recipient is.  To "turn off" a recipient from receiving message, simply remove any content from the "to" field in the template.', 'event_espresso')
50
+			);
51 51
 
52
-        $this->_contexts = array(
53
-            'admin' => array(
54
-                'label' => esc_html__('Event Admin', 'event_espresso'),
55
-                'description' => esc_html__('This template is what event administrators will receive when a transaction is finalized that has registrations with multiple different statuses.', 'event_espresso')
56
-                ),
57
-            'primary_attendee' => array(
58
-                'label' => esc_html__('Primary Registrant', 'event_espresso'),
59
-                'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive when the transaction completed has registrations with different statuses.  By default it is a summary email of all registrations for all events on the transaction and their status.', 'event_espresso')
60
-                )
61
-            );
62
-    }
52
+		$this->_contexts = array(
53
+			'admin' => array(
54
+				'label' => esc_html__('Event Admin', 'event_espresso'),
55
+				'description' => esc_html__('This template is what event administrators will receive when a transaction is finalized that has registrations with multiple different statuses.', 'event_espresso')
56
+				),
57
+			'primary_attendee' => array(
58
+				'label' => esc_html__('Primary Registrant', 'event_espresso'),
59
+				'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive when the transaction completed has registrations with different statuses.  By default it is a summary email of all registrations for all events on the transaction and their status.', 'event_espresso')
60
+				)
61
+			);
62
+	}
63 63
 
64 64
 
65 65
 
66
-    protected function _primary_attendee_addressees()
67
-    {
68
-        $cached = $this->_single_message;
69
-        $this->_single_message = false;
70
-        $addressees = parent::_primary_attendee_addressees();
71
-        $this->_single_message = $cached;
72
-        return $addressees;
73
-    }
66
+	protected function _primary_attendee_addressees()
67
+	{
68
+		$cached = $this->_single_message;
69
+		$this->_single_message = false;
70
+		$addressees = parent::_primary_attendee_addressees();
71
+		$this->_single_message = $cached;
72
+		return $addressees;
73
+	}
74 74
 }
Please login to merge, or discard this patch.
core/libraries/messages/message_type/EE_Payment_message_type.class.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -14,44 +14,44 @@
 block discarded – undo
14 14
 class EE_Payment_message_type extends EE_Payment_Base_message_type
15 15
 {
16 16
 
17
-    public function __construct()
18
-    {
17
+	public function __construct()
18
+	{
19 19
 
20
-        // setup type details for reference
21
-        $this->name = 'payment';
22
-        $this->description = esc_html__('This message type is used for all payment notification messages that go out including any manual payments entered by an event administrator.', 'event_espresso');
23
-        $this->label = array(
24
-            'singular' => esc_html__('payment received', 'event_espresso'),
25
-            'plural' => esc_html__('payments received', 'event_espresso')
26
-            );
20
+		// setup type details for reference
21
+		$this->name = 'payment';
22
+		$this->description = esc_html__('This message type is used for all payment notification messages that go out including any manual payments entered by an event administrator.', 'event_espresso');
23
+		$this->label = array(
24
+			'singular' => esc_html__('payment received', 'event_espresso'),
25
+			'plural' => esc_html__('payments received', 'event_espresso')
26
+			);
27 27
 
28
-        parent::__construct();
29
-    }
28
+		parent::__construct();
29
+	}
30 30
 
31
-    /**
32
-     * _set_contexts
33
-     * This sets up the contexts associated with the message_type
34
-     *
35
-     * @access  protected
36
-     * @return  void
37
-     */
38
-    protected function _set_contexts()
39
-    {
40
-        $this->_context_label = array(
41
-            'label' => esc_html__('recipient', 'event_espresso'),
42
-            'plural' => esc_html__('recipients', 'event_espresso'),
43
-            'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different payment details sent out depending on who the recipient is', 'event_espresso')
44
-            );
31
+	/**
32
+	 * _set_contexts
33
+	 * This sets up the contexts associated with the message_type
34
+	 *
35
+	 * @access  protected
36
+	 * @return  void
37
+	 */
38
+	protected function _set_contexts()
39
+	{
40
+		$this->_context_label = array(
41
+			'label' => esc_html__('recipient', 'event_espresso'),
42
+			'plural' => esc_html__('recipients', 'event_espresso'),
43
+			'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different payment details sent out depending on who the recipient is', 'event_espresso')
44
+			);
45 45
 
46
-        $this->_contexts = array(
47
-            'admin' => array(
48
-                'label' => esc_html__('Event Admin', 'event_espresso'),
49
-                'description' => esc_html__('This template is what event administrators will receive on a successful payment', 'event_espresso')
50
-                ),
51
-            'primary_attendee' => array(
52
-                'label' => esc_html__('Primary Registrant', 'event_espresso'),
53
-                'description' => esc_html__('This template is what the primary registrant (the person who made the main registration) will receive on successful payment', 'event_espresso')
54
-                )
55
-            );
56
-    }
46
+		$this->_contexts = array(
47
+			'admin' => array(
48
+				'label' => esc_html__('Event Admin', 'event_espresso'),
49
+				'description' => esc_html__('This template is what event administrators will receive on a successful payment', 'event_espresso')
50
+				),
51
+			'primary_attendee' => array(
52
+				'label' => esc_html__('Primary Registrant', 'event_espresso'),
53
+				'description' => esc_html__('This template is what the primary registrant (the person who made the main registration) will receive on successful payment', 'event_espresso')
54
+				)
55
+			);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
messages/message_type/EE_Not_Approved_Registration_message_type.class.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,60 +14,60 @@
 block discarded – undo
14 14
 class EE_Not_Approved_Registration_message_type extends EE_Registration_Base_message_type
15 15
 {
16 16
 
17
-    public function __construct()
18
-    {
19
-        $this->name = 'not_approved_registration';
20
-        $this->description = esc_html__('This message type is for messages sent to registrants when their registration is set to the not approved status.', 'event_espresso');
21
-        $this->label = array(
22
-            'singular' => esc_html__('not approved registration', 'event_espresso'),
23
-            'plural' => esc_html__('not approved registrations', 'event_espresso')
24
-            );
17
+	public function __construct()
18
+	{
19
+		$this->name = 'not_approved_registration';
20
+		$this->description = esc_html__('This message type is for messages sent to registrants when their registration is set to the not approved status.', 'event_espresso');
21
+		$this->label = array(
22
+			'singular' => esc_html__('not approved registration', 'event_espresso'),
23
+			'plural' => esc_html__('not approved registrations', 'event_espresso')
24
+			);
25 25
 
26
-        $this->_master_templates = array(
27
-            'email' => 'registration'
28
-            );
26
+		$this->_master_templates = array(
27
+			'email' => 'registration'
28
+			);
29 29
 
30
-        parent::__construct();
31
-    }
30
+		parent::__construct();
31
+	}
32 32
 
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * _set_contexts
38
-     * This sets up the contexts associated with the message_type
39
-     *
40
-     * @access  protected
41
-     * @return  void
42
-     */
43
-    protected function _set_contexts()
44
-    {
45
-        $this->_context_label = array(
46
-            'label' => esc_html__('recipient', 'event_espresso'),
47
-            'plural' => esc_html__('recipients', 'event_espresso'),
48
-            'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
49
-            );
36
+	/**
37
+	 * _set_contexts
38
+	 * This sets up the contexts associated with the message_type
39
+	 *
40
+	 * @access  protected
41
+	 * @return  void
42
+	 */
43
+	protected function _set_contexts()
44
+	{
45
+		$this->_context_label = array(
46
+			'label' => esc_html__('recipient', 'event_espresso'),
47
+			'plural' => esc_html__('recipients', 'event_espresso'),
48
+			'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
49
+			);
50 50
 
51
-        $this->_contexts = array(
52
-            'admin' => array(
53
-                'label' => esc_html__('Event Admin', 'event_espresso'),
54
-                'description' => esc_html__('This template is what event administrators will receive when registration status is set to not approved.', 'event_espresso')
55
-                ),
56
-            'primary_attendee' => array(
57
-                'label' => esc_html__('Primary Registrant', 'event_espresso'),
58
-                'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive when the registration status is not approved.', 'event_espresso')
59
-                )
60
-            );
61
-    }
51
+		$this->_contexts = array(
52
+			'admin' => array(
53
+				'label' => esc_html__('Event Admin', 'event_espresso'),
54
+				'description' => esc_html__('This template is what event administrators will receive when registration status is set to not approved.', 'event_espresso')
55
+				),
56
+			'primary_attendee' => array(
57
+				'label' => esc_html__('Primary Registrant', 'event_espresso'),
58
+				'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive when the registration status is not approved.', 'event_espresso')
59
+				)
60
+			);
61
+	}
62 62
 
63 63
 
64 64
 
65
-    protected function _primary_attendee_addressees()
66
-    {
67
-        $cached = $this->_single_message;
68
-        $this->_single_message = false;
69
-        $addressees = parent::_primary_attendee_addressees();
70
-        $this->_single_message = $cached;
71
-        return $addressees;
72
-    }
65
+	protected function _primary_attendee_addressees()
66
+	{
67
+		$cached = $this->_single_message;
68
+		$this->_single_message = false;
69
+		$addressees = parent::_primary_attendee_addressees();
70
+		$this->_single_message = $cached;
71
+		return $addressees;
72
+	}
73 73
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Indentation   +1118 added lines, -1118 removed lines patch added patch discarded remove patch
@@ -12,1122 +12,1122 @@
 block discarded – undo
12 12
 class EE_Message_Resource_Manager
13 13
 {
14 14
 
15
-    /**
16
-     * This option in the database is used to keep a record of message types that have been activated for a messenger
17
-     * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
18
-     * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
19
-     * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
20
-     * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
21
-     * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
22
-     * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
23
-     * automated process (when an add-on registering the message type deactivates, or when some other code calls the
24
-     * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
25
-     * the "force" flag is respected if that message type is later re-registered.
26
-     *
27
-     * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
28
-     *
29
-     * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
30
-     * option that got superseded by later behaviour requirements.
31
-     */
32
-    const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
33
-
34
-    /**
35
-     * @type boolean $_initialized
36
-     */
37
-    protected $_initialized = false;
38
-
39
-    /**
40
-     * @type EE_Messenger_Collection $_messenger_collection_loader
41
-     */
42
-    protected $_messenger_collection_loader;
43
-
44
-    /**
45
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
46
-     */
47
-    protected $_message_type_collection_loader;
48
-
49
-    /**
50
-     * @type EEM_Message_Template_Group $_message_template_group_model
51
-     */
52
-    protected $_message_template_group_model;
53
-
54
-    /**
55
-     * @type EE_messenger[]
56
-     */
57
-    protected $_installed_messengers = array();
58
-
59
-    /**
60
-     * @type EE_message_type[]
61
-     */
62
-    protected $_installed_message_types = array();
63
-
64
-    /**
65
-     * Array of active messengers.
66
-     * Format is this:
67
-     * array(
68
-     *      'messenger_name' => EE_messenger
69
-     * )
70
-     *
71
-     * @type EE_messenger[]
72
-     */
73
-    protected $_active_messengers = array();
74
-
75
-    /**
76
-     * Formatted array of active message types grouped per messenger.
77
-     * Format is this:
78
-     * array(
79
-     *      'messenger_name' => array(
80
-     *          'settings' => array(
81
-     *              '{messenger_name}-message_types' => array(
82
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
83
-     *              )
84
-     *          )
85
-     *      )
86
-     * )
87
-     *
88
-     * @type array
89
-     */
90
-    protected $_active_message_types = array();
91
-
92
-
93
-    /**
94
-     * This holds the array of messengers and their corresponding message types that have
95
-     * been activated on a site at some point.  This is an important record that helps the messages system
96
-     * not accidentally reactivate something that was intentionally deactivated by a user.
97
-     *
98
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
99
-     *
100
-     * @type array
101
-     */
102
-    protected $_has_activated_messengers_and_message_types = array();
103
-
104
-    /**
105
-     * An array of unique message type contexts across all active message types.
106
-     * The array will be indexed by either 'slugs' or 'all'.
107
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
108
-     * slug. array(
109
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
110
-     * );
111
-     * The all index returns an array in this format:
112
-     * array(
113
-     *      'message_type_name' => array(
114
-     *          'context_slug' => array(
115
-     *              'label' => 'localized label for context',
116
-     *              'description' => 'localized description for context'
117
-     *          )
118
-     *      )
119
-     * );
120
-     *
121
-     * @type array
122
-     */
123
-    protected $_contexts = array();
124
-
125
-
126
-    /**
127
-     * EE_Message_Resource_Manager constructor.
128
-     *
129
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
130
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
131
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
132
-     */
133
-    public function __construct(
134
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
135
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
136
-        EEM_Message_Template_Group $Message_Template_Group_Model
137
-    ) {
138
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
139
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
140
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
141
-    }
142
-
143
-
144
-    /**
145
-     * @return void
146
-     */
147
-    protected function _initialize_collections()
148
-    {
149
-        if ($this->_initialized) {
150
-            return;
151
-        }
152
-        $this->_initialized = true;
153
-        $this->_messenger_collection_loader->load_messengers_from_folder();
154
-        $this->_message_type_collection_loader->load_message_types_from_folder();
155
-        $this->get_has_activated_messengers_option(true);
156
-        $this->_set_active_messengers_and_message_types();
157
-    }
158
-
159
-
160
-    /**
161
-     * @return EE_Messenger_Collection
162
-     */
163
-    public function messenger_collection()
164
-    {
165
-        $this->_initialize_collections();
166
-        return $this->_messenger_collection_loader->messenger_collection();
167
-    }
168
-
169
-
170
-    /**
171
-     * @return EE_messenger[]
172
-     */
173
-    public function active_messengers()
174
-    {
175
-        $this->_initialize_collections();
176
-        return $this->_active_messengers;
177
-    }
178
-
179
-
180
-    /**
181
-     * @param string $messenger_name
182
-     * @return \EE_messenger
183
-     */
184
-    public function get_messenger($messenger_name)
185
-    {
186
-        return $this->messenger_collection()->get_by_info($messenger_name);
187
-    }
188
-
189
-
190
-    /**
191
-     * This returns the corresponding EE_messenger object for the given string if it is active.
192
-     *
193
-     * @param string $messenger
194
-     * @return EE_messenger | null
195
-     */
196
-    public function get_active_messenger($messenger)
197
-    {
198
-        $this->_initialize_collections();
199
-        return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null;
200
-    }
201
-
202
-
203
-    /**
204
-     * @return \EE_messenger[]
205
-     */
206
-    public function installed_messengers()
207
-    {
208
-        if (empty($this->_installed_messengers)) {
209
-            $this->_installed_messengers = array();
210
-            $this->messenger_collection()->rewind();
211
-            while ($this->messenger_collection()->valid()) {
212
-                $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current();
213
-                $this->messenger_collection()->next();
214
-            }
215
-        }
216
-        return $this->_installed_messengers;
217
-    }
218
-
219
-
220
-    /**
221
-     * @param string $messenger_name
222
-     * @return \EE_messenger
223
-     * @throws EE_Error
224
-     */
225
-    public function valid_messenger($messenger_name)
226
-    {
227
-        $messenger = $this->get_messenger($messenger_name);
228
-        if ($messenger instanceof EE_messenger) {
229
-            return $messenger;
230
-        }
231
-        throw new EE_Error(
232
-            sprintf(
233
-                esc_html__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
234
-                $messenger_name
235
-            )
236
-        );
237
-    }
238
-
239
-
240
-    /**
241
-     * @return EE_Message_Type_Collection
242
-     */
243
-    public function message_type_collection()
244
-    {
245
-        $this->_initialize_collections();
246
-        return $this->_message_type_collection_loader->message_type_collection();
247
-    }
248
-
249
-
250
-    /**
251
-     * @return array
252
-     */
253
-    public function active_message_types()
254
-    {
255
-        $this->_initialize_collections();
256
-        return $this->_active_message_types;
257
-    }
258
-
259
-
260
-    /**
261
-     * @param string $message_type_name
262
-     * @return \EE_message_type
263
-     */
264
-    public function get_message_type($message_type_name)
265
-    {
266
-        return $this->message_type_collection()->get_by_info($message_type_name);
267
-    }
268
-
269
-
270
-    /**
271
-     * This returns the EE_message_type from the active message types array ( if present );
272
-     *
273
-     * @param string $messenger_name
274
-     * @param string $message_type_name
275
-     * @return \EE_message_type|null
276
-     */
277
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
278
-    {
279
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
280
-            ? $this->get_message_type($message_type_name)
281
-            : null;
282
-    }
283
-
284
-
285
-    /**
286
-     * Returns whether the given message type is active for the given messenger.
287
-     *
288
-     * @param string $messenger_name
289
-     * @param string $message_type_name
290
-     * @return bool
291
-     */
292
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
293
-    {
294
-        $this->_initialize_collections();
295
-        return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
296
-    }
297
-
298
-
299
-    /**
300
-     * Returns whether the given messenger is active.
301
-     *
302
-     * @param string $messenger_name the name of the messenger to check if active.
303
-     * @return bool
304
-     */
305
-    public function is_messenger_active($messenger_name)
306
-    {
307
-        $this->_initialize_collections();
308
-        return ! empty($this->_active_message_types[ $messenger_name ]);
309
-    }
310
-
311
-
312
-    /**
313
-     * This returns any settings that might be on a message type for a messenger
314
-     *
315
-     * @param string $messenger_name    The slug of the messenger
316
-     * @param string $message_type_name The slug of the message type getting the settings for.
317
-     * @return array
318
-     */
319
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
320
-    {
321
-        $settings = array();
322
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
323
-            $settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'])
324
-                ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']
325
-                : array();
326
-        }
327
-        return $settings;
328
-    }
329
-
330
-
331
-    /**
332
-     * Returns whether the given messenger name has active message types on it.
333
-     * Infers whether the messenger is active or not as well.
334
-     *
335
-     * @param string $messenger_name
336
-     * @return bool
337
-     */
338
-    public function messenger_has_active_message_types($messenger_name)
339
-    {
340
-        $this->_initialize_collections();
341
-        return
342
-            ! empty($this->_active_message_types[ $messenger_name ])
343
-            && ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]);
344
-    }
345
-
346
-
347
-    /**
348
-     * This checks the _active_message_types property for any active message types
349
-     * that are present for the given messenger and returns them.
350
-     *
351
-     * @since 4.9.0
352
-     * @param string $messenger_name The messenger being checked
353
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
354
-     */
355
-    public function get_active_message_types_for_messenger($messenger_name)
356
-    {
357
-        $message_types = array();
358
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
359
-            return $message_types;
360
-        }
361
-        $installed_message_types = $this->installed_message_types();
362
-        foreach ($installed_message_types as $message_type_name => $message_type) {
363
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
364
-                $message_types[ $message_type_name ] = $message_type;
365
-            }
366
-        }
367
-        return $message_types;
368
-    }
369
-
370
-
371
-    /**
372
-     * This does NOT return the _active_message_types property but
373
-     * simply returns an array of active message type names from that property.
374
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
375
-     *
376
-     * @return array message_type references (string)
377
-     */
378
-    public function list_of_active_message_types()
379
-    {
380
-        $active_message_type_names = array();
381
-        $this->_initialize_collections();
382
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
383
-            if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) {
384
-                continue;
385
-            }
386
-            foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) {
387
-                if (! in_array($message_type_name, $active_message_type_names)) {
388
-                    $active_message_type_names[] = $message_type_name;
389
-                }
390
-            }
391
-        }
392
-        return $active_message_type_names;
393
-    }
394
-
395
-
396
-    /**
397
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
398
-     *
399
-     * @since 4.9.0
400
-     * @return \EE_message_type[]
401
-     */
402
-    public function get_active_message_type_objects()
403
-    {
404
-        $active_message_types      = array();
405
-        $installed_message_types   = $this->installed_message_types();
406
-        $active_message_type_names = $this->list_of_active_message_types();
407
-        foreach ($active_message_type_names as $active_message_type_name) {
408
-            if (isset($installed_message_types[ $active_message_type_name ])) {
409
-                $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ];
410
-            }
411
-        }
412
-        return $active_message_types;
413
-    }
414
-
415
-
416
-    /**
417
-     * @return \EE_message_type[]
418
-     */
419
-    public function installed_message_types()
420
-    {
421
-        if (empty($this->_installed_message_types)) {
422
-            $this->message_type_collection()->rewind();
423
-            while ($this->message_type_collection()->valid()) {
424
-                $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current();
425
-                $this->message_type_collection()->next();
426
-            }
427
-        }
428
-        return $this->_installed_message_types;
429
-    }
430
-
431
-
432
-    /**
433
-     * @param string $message_type_name
434
-     * @return \EE_message_type
435
-     * @throws EE_Error
436
-     */
437
-    public function valid_message_type($message_type_name)
438
-    {
439
-        $message_type = $this->get_message_type($message_type_name);
440
-        if ($message_type instanceof EE_message_type) {
441
-            return $message_type;
442
-        }
443
-        throw new EE_Error(
444
-            sprintf(
445
-                esc_html__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
446
-                $message_type_name
447
-            )
448
-        );
449
-    }
450
-
451
-
452
-    /**
453
-     * valid_message_type_for_messenger
454
-     *
455
-     * @param EE_messenger $messenger
456
-     * @param string       $message_type_name
457
-     * @return boolean
458
-     * @throws EE_Error
459
-     */
460
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
461
-    {
462
-        $valid_message_types = $messenger->get_valid_message_types();
463
-        if (! in_array($message_type_name, $valid_message_types)) {
464
-            throw new EE_Error(
465
-                sprintf(
466
-                    esc_html__(
467
-                        'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
468
-                        'event_espresso'
469
-                    ),
470
-                    $message_type_name,
471
-                    __METHOD__,
472
-                    $messenger->name
473
-                )
474
-            );
475
-        }
476
-        return true;
477
-    }
478
-
479
-
480
-    /**
481
-     * Used to return active messengers array stored in the wp options table.
482
-     * If no value is present in the option then an empty array is returned.
483
-     *
484
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
485
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
486
-     *                          $_active_message_types property is pulled.
487
-     * @return array
488
-     */
489
-    public function get_active_messengers_option($reset = false)
490
-    {
491
-        if ($reset) {
492
-            $this->_active_message_types = get_option('ee_active_messengers', array());
493
-        }
494
-        return $this->_active_message_types;
495
-    }
496
-
497
-
498
-    /**
499
-     * Used to update the active messengers array stored in the wp options table.
500
-     *
501
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
502
-     *                                         representing this data is used.
503
-     * @return bool FALSE if not updated, TRUE if updated.
504
-     */
505
-    public function update_active_messengers_option($active_messenger_settings = array())
506
-    {
507
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
508
-        // make sure _active_message_types is updated (this is the internal cache for the settings).
509
-        $this->_active_message_types = $active_messenger_settings;
510
-        return update_option('ee_active_messengers', $active_messenger_settings);
511
-    }
512
-
513
-
514
-    /**
515
-     * Used to return has activated message types for messengers array stored in the wp options table.
516
-     * If no value is present in the option then an empty array is returned.
517
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
518
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
519
-     *
520
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
521
-     * @return array
522
-     */
523
-    public function get_has_activated_messengers_option($reset = false)
524
-    {
525
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
526
-            $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
527
-        }
528
-        return $this->_has_activated_messengers_and_message_types;
529
-    }
530
-
531
-
532
-    /**
533
-     * Used to update the has activated option in the db.
534
-     *
535
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
536
-     *
537
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
538
-     *                                        representing this data is used.
539
-     * @return bool FALSE if not updated, TRUE if updated.
540
-     */
541
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
542
-    {
543
-        // make sure the option has been retrieved from first so we don't overwrite it accidentally.
544
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
545
-            $this->get_has_activated_messengers_option();
546
-        }
547
-        $has_activated_messengers = empty($has_activated_messengers)
548
-            ? $this->_has_activated_messengers_and_message_types
549
-            : $has_activated_messengers;
550
-        return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
551
-    }
552
-
553
-
554
-    /**
555
-     * wrapper for _set_active_messengers_and_message_types()
556
-     */
557
-    public function reset_active_messengers_and_message_types()
558
-    {
559
-        $this->_set_active_messengers_and_message_types();
560
-    }
561
-
562
-
563
-    /**
564
-     * Generate list of active messengers and message types from collection.
565
-     * This sets up the active messengers from what is present in the database.
566
-     */
567
-    protected function _set_active_messengers_and_message_types()
568
-    {
569
-        // echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
570
-        // list of activated messengers as set via the admin
571
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
572
-        $this->get_active_messengers_option(true);
573
-        $this->ensure_messengers_are_active(array(), false, true);
574
-        $this->update_active_messengers_option();
575
-        $this->update_has_activated_messengers_option();
576
-    }
577
-
578
-
579
-    /**
580
-     * Ensures that the specified messenger is currently active.
581
-     * If not, activates it and its default message types.
582
-     *
583
-     * @param string $messenger_name
584
-     * @param bool   $update_option Whether to update the option in the db or not.
585
-     * @return boolean true if either already active or successfully activated.
586
-     */
587
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
588
-    {
589
-        if (! isset($this->_active_messengers[ $messenger_name ])) {
590
-            try {
591
-                $this->activate_messenger($messenger_name, array(), $update_option);
592
-            } catch (EE_Error $e) {
593
-                EE_Error::add_error(
594
-                    $e->getMessage(),
595
-                    __FILE__,
596
-                    __FUNCTION__,
597
-                    __LINE__
598
-                );
599
-                return false;
600
-            }
601
-        }
602
-        return true;
603
-    }
604
-
605
-
606
-    /**
607
-     * This ensures the given array of messenger names is active in the system.
608
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
609
-     * it will automatically activate the default message types for the messenger if its not active.
610
-     *
611
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
612
-     *                                (default) then will attempt to set the active messengers from the
613
-     *                                activated_messengers option
614
-     *                                (stored in $_active_message_types property).
615
-     * @param bool  $update_option    Whether to update the related active messengers option.
616
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
617
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
618
-     *                                will automatically be deactivated.
619
-     */
620
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
621
-    {
622
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
623
-
624
-        $not_installed = array();
625
-        foreach ($messenger_names as $messenger_name) {
626
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
627
-                $not_installed[] = $messenger_name;
628
-                $this->deactivate_messenger($messenger_name);
629
-                continue;
630
-            }
631
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
632
-        }
633
-
634
-        if (! empty($not_installed)) {
635
-            EE_Error::add_error(
636
-                sprintf(
637
-                    esc_html__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
638
-                    '<br />',
639
-                    implode(', ', $not_installed)
640
-                ),
641
-                __FILE__,
642
-                __FUNCTION__,
643
-                __LINE__
644
-            );
645
-        }
646
-    }
647
-
648
-
649
-    /**
650
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
651
-     * This ALSO ensures that the given messenger is active as well!
652
-     *
653
-     * @param string $message_type_name message type name.
654
-     * @param        $messenger_name
655
-     * @param bool   $update_option     Whether to update the option in the db or not.
656
-     * @return bool  Returns true if already is active or if was activated successfully.
657
-     * @throws EE_Error
658
-     */
659
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
660
-    {
661
-        // grab the messenger to work with.
662
-        $messenger = $this->valid_messenger($messenger_name);
663
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
664
-            // ensure messenger is active (that's an inherent coupling between active message types and the
665
-            // messenger they are being activated for.
666
-            try {
667
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
668
-                    // all is good so let's just get it active
669
-                    $this->activate_messenger($messenger, array($message_type_name), $update_option);
670
-                }
671
-            } catch (EE_Error $e) {
672
-                EE_Error::add_error(
673
-                    $e->getMessage(),
674
-                    __FILE__,
675
-                    __FUNCTION__,
676
-                    __LINE__
677
-                );
678
-                return false;
679
-            }
680
-        }
681
-        return true;
682
-    }
683
-
684
-
685
-    /**
686
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
687
-     * messenger are active in one go.
688
-     *
689
-     * @param array  $message_type_names Array of message type names to ensure are active.
690
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
691
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
692
-     */
693
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
694
-    {
695
-        $message_type_names = (array) $message_type_names;
696
-        foreach ($message_type_names as $message_type_name) {
697
-            // note, intentionally not updating option here because we're in a loop.
698
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
699
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
700
-        }
701
-        if ($update_option) {
702
-            $this->update_active_messengers_option();
703
-            $this->update_has_activated_messengers_option();
704
-        }
705
-    }
706
-
707
-
708
-    /**
709
-     * Activates the specified messenger.
710
-     *
711
-     * @param EE_messenger|string $messenger    Instantiated EE_messenger OR messenger name if not already loaded!
712
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
713
-     *                                          If included we do NOT setup the default message types
714
-     *                                          (assuming they are already setup.)
715
-     * @param bool   $update_active_messengers_option
716
-     * @return array of generated templates
717
-     * @throws EE_Error
718
-     */
719
-    public function activate_messenger(
720
-        $messenger,
721
-        $message_type_names = array(),
722
-        $update_active_messengers_option = true
723
-    ) {
724
-        $templates = array();
725
-        // grab the messenger to work with.
726
-        $messenger = $messenger instanceof EE_messenger
727
-            ? $messenger
728
-            : $this->messenger_collection()->get_by_info($messenger);
729
-        // it's inactive. Activate it.
730
-        if ($messenger instanceof EE_messenger) {
731
-            $this->_active_messengers[ $messenger->name ] = $messenger;
732
-            // activate incoming message types set to be activated with messenger.
733
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
734
-            // setup any initial settings for the messenger if necessary.
735
-            $this->add_settings_for_messenger($messenger->name);
736
-            if ($update_active_messengers_option) {
737
-                $this->update_active_messengers_option();
738
-                $this->update_has_activated_messengers_option();
739
-            }
740
-            // generate new templates if necessary and ensure all related templates that are already in the database are
741
-            // marked active.  Note, this will also deactivate a message type for a messenger if the template
742
-            // cannot be successfully created during its attempt (only happens for global template attempts).
743
-            if (! empty($message_type_names)) {
744
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
745
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
746
-            }
747
-        }
748
-        return $templates;
749
-    }
750
-
751
-
752
-    /**
753
-     * Activates given message types for the given EE_messenger object.
754
-     * Note: (very important) This method does not persist the activation to the database.
755
-     * See code implementing this method in this class for examples of how to persist.
756
-     *
757
-     * @param \EE_messenger $messenger
758
-     * @param  array        $message_type_names
759
-     * @return array
760
-     */
761
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
762
-    {
763
-        // If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
764
-        // things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
765
-        // So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
766
-        // only override _active_message_types when an explicit array of $message_type_names has been provided.
767
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ])
768
-            ? $messenger->get_default_message_types()
769
-            : (array) $message_type_names;
770
-
771
-        // now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
772
-        if (! isset($this->_active_message_types[ $messenger->name ])) {
773
-            $this->_active_message_types[ $messenger->name ]['settings'] = array();
774
-        }
775
-
776
-        if ($message_type_names) {
777
-            // cycle thru message types
778
-            foreach ($message_type_names as $message_type_name) {
779
-                // only register the message type as active IF it isn't already active
780
-                // and if its actually installed.
781
-                if (
782
-                    ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
783
-                ) {
784
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
785
-                    $this->_set_messenger_has_activated_message_type(
786
-                        $messenger,
787
-                        $message_type_name
788
-                    );
789
-                }
790
-            }
791
-        }
792
-        return $message_type_names;
793
-    }
794
-
795
-
796
-    /**
797
-     * add_settings_for_message_type
798
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
799
-     * $this->update_active_messengers_option to persist.
800
-     *
801
-     * @param  string $messenger_name    The name of the messenger adding the settings for
802
-     * @param  string $message_type_name The name of the message type adding the settings for
803
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
804
-     */
805
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
806
-    {
807
-        // get installed message type from collection
808
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
809
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
810
-        // we need to setup any initial settings for message types
811
-        if ($message_type instanceof EE_message_type) {
812
-            $default_settings = $message_type->get_admin_settings_fields();
813
-            foreach ($default_settings as $field => $values) {
814
-                if (isset($new_settings[ $field ])) {
815
-                    $existing_settings[ $field ] = $new_settings[ $field ];
816
-                    continue;
817
-                }
818
-                if (! isset($existing_settings[ $field ])) {
819
-                    $existing_settings[ $field ] = $values['default'];
820
-                }
821
-            }
822
-        }
823
-        $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings;
824
-    }
825
-
826
-
827
-    /**
828
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
829
-     * and message type.
830
-     *
831
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
832
-     *
833
-     * @access protected
834
-     * @param \EE_messenger $messenger
835
-     * @param string        $message_type_name
836
-     */
837
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
838
-    {
839
-
840
-        // if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
841
-        if (empty($this->_has_activated_messengers_and_message_types)) {
842
-            $this->get_has_activated_messengers_option();
843
-        }
844
-
845
-        // make sure this messenger has a record in the has_activated array
846
-        if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
847
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array();
848
-        }
849
-        // check if message type has already been added
850
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
851
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name;
852
-        }
853
-    }
854
-
855
-
856
-    /**
857
-     * add_settings_for_messenger
858
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
859
-     * $this->update_active_messengers_option to persist.
860
-     *
861
-     * @param string $messenger_name The name of the messenger the settings is being added for.
862
-     * @param array  $new_settings   An array of settings to update the existing settings.
863
-     */
864
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
865
-    {
866
-        $messenger = $this->get_messenger($messenger_name);
867
-        if ($messenger instanceof EE_messenger) {
868
-            $msgr_settings = $messenger->get_admin_settings_fields();
869
-            if (! empty($msgr_settings)) {
870
-                foreach ($msgr_settings as $field => $value) {
871
-                    // is there a new setting for this?
872
-                    if (isset($new_settings[ $field ])) {
873
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ];
874
-                        continue;
875
-                    }
876
-                    // only set the default if it isn't already set.
877
-                    if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) {
878
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value;
879
-                    }
880
-                }
881
-            }
882
-        }
883
-    }
884
-
885
-
886
-    /**
887
-     * deactivate_messenger
888
-     *
889
-     * @param  string|EE_messenger $messenger_name name of messenger
890
-     * @return void
891
-     */
892
-    public function deactivate_messenger($messenger_name)
893
-    {
894
-        $this->_initialize_collections();
895
-        if ($messenger_name instanceof EE_messenger) {
896
-            $messenger_name = $messenger_name->name;
897
-        }
898
-        unset($this->_active_messengers[ $messenger_name ]);
899
-        unset($this->_active_message_types[ $messenger_name ]);
900
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
901
-        $this->update_active_messengers_option();
902
-    }
903
-
904
-
905
-    /**
906
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
907
-     *
908
-     * @param  string $message_type_name     name of message type being deactivated
909
-     * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
910
-     *                                       type.  However, this can be overridden if we don't want this set (usually when
911
-     *                                       this is called as a part of deregistration of a custom message type)
912
-     */
913
-    public function deactivate_message_type($message_type_name, $set_has_active_record = true)
914
-    {
915
-        $this->_initialize_collections();
916
-        if ($message_type_name instanceof EE_message_type) {
917
-            $message_type_name = $message_type_name->name;
918
-        }
919
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
920
-            unset(
921
-                $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]
922
-            );
923
-
924
-            // we always record (even on deactivation) that a message type has been activated because there should at
925
-            // least be a record in the "has_activated" option that it WAS active at one point.
926
-            if ($set_has_active_record) {
927
-                $messenger = $this->get_messenger($messenger_name);
928
-                $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
929
-            }
930
-        }
931
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
932
-        $this->update_active_messengers_option();
933
-        $this->update_has_activated_messengers_option();
934
-    }
935
-
936
-
937
-    /**
938
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
939
-     *
940
-     * @param string $message_type_name Name of message type being deactivated.
941
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
942
-     */
943
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
944
-    {
945
-        $this->_initialize_collections();
946
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
947
-            unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
948
-        }
949
-        $this->_message_template_group_model->deactivate_message_template_groups_for(
950
-            array($messenger_name),
951
-            array($message_type_name)
952
-        );
953
-        $this->update_active_messengers_option();
954
-    }
955
-
956
-
957
-    /**
958
-     * Used to verify if a message can be sent for the given messenger and message type
959
-     * and that it is a generating messenger (used for generating message templates).
960
-     *
961
-     * @param EE_messenger    $messenger    messenger used in trigger
962
-     * @param EE_message_type $message_type message type used in trigger
963
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
964
-     */
965
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
966
-    {
967
-        // get the $messengers the message type says it can be used with.
968
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
969
-            if (
970
-                $messenger->name === $generating_messenger
971
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
972
-            ) {
973
-                return true;
974
-            }
975
-        }
976
-        return false;
977
-    }
978
-
979
-
980
-    /**
981
-     * This returns all the contexts that are registered by all message types.
982
-     * If $slugs_only is true,
983
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
984
-     * array(
985
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
986
-     * );
987
-     * If $slugs_only is false, then the format is:
988
-     * array(
989
-     *      'message_type_name' => array(
990
-     *          'context_slug' => array(
991
-     *              'label' => 'localized label for context',
992
-     *              'description' => 'localized description for context'
993
-     *          )
994
-     *      )
995
-     * );
996
-     * Keep in mind that although different message types may share the same context slugs,
997
-     * it is possible that the context is described differently by the message type.
998
-     *
999
-     * @since 4.9.0
1000
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1001
-     *                           or all contexts indexed by message type.
1002
-     * @return array
1003
-     */
1004
-    public function get_all_contexts($slugs_only = true)
1005
-    {
1006
-        $key = $slugs_only ? 'slugs' : 'all';
1007
-        // check if contexts has been setup yet.
1008
-        if (empty($this->_contexts[ $key ])) {
1009
-            // So let's get all active message type objects and loop through to get all unique contexts
1010
-            foreach ($this->get_active_message_type_objects() as $message_type) {
1011
-                if ($message_type instanceof EE_message_type) {
1012
-                    $message_type_contexts = $message_type->get_contexts();
1013
-                    if ($slugs_only) {
1014
-                        foreach ($message_type_contexts as $context => $context_details) {
1015
-                            $this->_contexts[ $key ][ $context ] = $context_details['label'];
1016
-                        }
1017
-                    } else {
1018
-                        $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts;
1019
-                    }
1020
-                }
1021
-            }
1022
-        }
1023
-        return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array();
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * This checks the internal record of what message types are considered "active" and verifies that
1029
-     * there is an installed class definition for that message type.  If the active message type does not have a
1030
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1031
-     * any related message templates will be inactivated as well.
1032
-     *
1033
-     * @return bool   true means all active message types are valid, false means at least one message type was
1034
-     *                deactivated.
1035
-     */
1036
-    public function validate_active_message_types_are_installed()
1037
-    {
1038
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1039
-        $installed_message_types           = $this->installed_message_types();
1040
-        $all_message_types_valid           = true;
1041
-        // loop through list of active message types and verify they are installed.
1042
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1043
-            if (! isset($installed_message_types[ $message_type_name ])) {
1044
-                $this->remove_message_type_has_been_activated_from_all_messengers(
1045
-                    $message_type_name,
1046
-                    true
1047
-                );
1048
-                $this->deactivate_message_type($message_type_name, false);
1049
-                $all_message_types_valid = false;
1050
-            }
1051
-        }
1052
-        return $all_message_types_valid;
1053
-    }
1054
-
1055
-
1056
-    /**
1057
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1058
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1059
-     * to attempt automatically reactivating message types that should be activated by default or not.
1060
-     *
1061
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1062
-     *
1063
-     * @param $message_type_name
1064
-     * @param $messenger_name
1065
-     * @return bool
1066
-     */
1067
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1068
-    {
1069
-        $has_activated = $this->get_has_activated_messengers_option();
1070
-        return isset($has_activated[ $messenger_name ])
1071
-               && in_array($message_type_name, $has_activated[ $messenger_name ]);
1072
-    }
1073
-
1074
-
1075
-    /**
1076
-     * This method unsets a message type from the given messenger has activated option.
1077
-     *
1078
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1079
-     *
1080
-     * @param string $message_type_name
1081
-     * @param string $messenger_name
1082
-     * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1083
-     *                                        If it is currently active, then remove.  Otherwise leave it alone.
1084
-     */
1085
-    public function remove_message_type_has_been_activated_for_messenger(
1086
-        $message_type_name,
1087
-        $messenger_name,
1088
-        $consider_current_state = false
1089
-    ) {
1090
-        if (
1091
-            $consider_current_state
1092
-            && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1093
-        ) {
1094
-            // when consider current state is true, this means we don't want to change anything on the "has_activated"
1095
-            // record if the message type is currently active for this messenger.  This is used when we want to retain
1096
-            // the record for user initiated inactivations of the message type.
1097
-            return;
1098
-        }
1099
-        $has_activated = $this->get_has_activated_messengers_option();
1100
-        $key_for_message_type = isset($has_activated[ $messenger_name ])
1101
-            ? array_search($message_type_name, $has_activated[ $messenger_name ], true)
1102
-            : false;
1103
-        if ($key_for_message_type !== false) {
1104
-            unset($has_activated[ $messenger_name ][ $key_for_message_type ]);
1105
-            $this->update_has_activated_messengers_option($has_activated);
1106
-            // reset the internal cached property
1107
-            $this->get_has_activated_messengers_option(true);
1108
-        }
1109
-    }
1110
-
1111
-
1112
-    /**
1113
-     * Removes a message type active record from all messengers it is attached to.
1114
-     *
1115
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1116
-     *
1117
-     * @param      $message_type_name
1118
-     * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1119
-     *                                      If it is currently active, then remove.  Otherwise leave it alone.
1120
-     */
1121
-    public function remove_message_type_has_been_activated_from_all_messengers(
1122
-        $message_type_name,
1123
-        $consider_current_state = false
1124
-    ) {
1125
-        foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1126
-            $this->remove_message_type_has_been_activated_for_messenger(
1127
-                $message_type_name,
1128
-                $messenger_name,
1129
-                $consider_current_state
1130
-            );
1131
-        }
1132
-    }
15
+	/**
16
+	 * This option in the database is used to keep a record of message types that have been activated for a messenger
17
+	 * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
18
+	 * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
19
+	 * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
20
+	 * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
21
+	 * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
22
+	 * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
23
+	 * automated process (when an add-on registering the message type deactivates, or when some other code calls the
24
+	 * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
25
+	 * the "force" flag is respected if that message type is later re-registered.
26
+	 *
27
+	 * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
28
+	 *
29
+	 * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
30
+	 * option that got superseded by later behaviour requirements.
31
+	 */
32
+	const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
33
+
34
+	/**
35
+	 * @type boolean $_initialized
36
+	 */
37
+	protected $_initialized = false;
38
+
39
+	/**
40
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
41
+	 */
42
+	protected $_messenger_collection_loader;
43
+
44
+	/**
45
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
46
+	 */
47
+	protected $_message_type_collection_loader;
48
+
49
+	/**
50
+	 * @type EEM_Message_Template_Group $_message_template_group_model
51
+	 */
52
+	protected $_message_template_group_model;
53
+
54
+	/**
55
+	 * @type EE_messenger[]
56
+	 */
57
+	protected $_installed_messengers = array();
58
+
59
+	/**
60
+	 * @type EE_message_type[]
61
+	 */
62
+	protected $_installed_message_types = array();
63
+
64
+	/**
65
+	 * Array of active messengers.
66
+	 * Format is this:
67
+	 * array(
68
+	 *      'messenger_name' => EE_messenger
69
+	 * )
70
+	 *
71
+	 * @type EE_messenger[]
72
+	 */
73
+	protected $_active_messengers = array();
74
+
75
+	/**
76
+	 * Formatted array of active message types grouped per messenger.
77
+	 * Format is this:
78
+	 * array(
79
+	 *      'messenger_name' => array(
80
+	 *          'settings' => array(
81
+	 *              '{messenger_name}-message_types' => array(
82
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
83
+	 *              )
84
+	 *          )
85
+	 *      )
86
+	 * )
87
+	 *
88
+	 * @type array
89
+	 */
90
+	protected $_active_message_types = array();
91
+
92
+
93
+	/**
94
+	 * This holds the array of messengers and their corresponding message types that have
95
+	 * been activated on a site at some point.  This is an important record that helps the messages system
96
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
97
+	 *
98
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
99
+	 *
100
+	 * @type array
101
+	 */
102
+	protected $_has_activated_messengers_and_message_types = array();
103
+
104
+	/**
105
+	 * An array of unique message type contexts across all active message types.
106
+	 * The array will be indexed by either 'slugs' or 'all'.
107
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
108
+	 * slug. array(
109
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
110
+	 * );
111
+	 * The all index returns an array in this format:
112
+	 * array(
113
+	 *      'message_type_name' => array(
114
+	 *          'context_slug' => array(
115
+	 *              'label' => 'localized label for context',
116
+	 *              'description' => 'localized description for context'
117
+	 *          )
118
+	 *      )
119
+	 * );
120
+	 *
121
+	 * @type array
122
+	 */
123
+	protected $_contexts = array();
124
+
125
+
126
+	/**
127
+	 * EE_Message_Resource_Manager constructor.
128
+	 *
129
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
130
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
131
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
132
+	 */
133
+	public function __construct(
134
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
135
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
136
+		EEM_Message_Template_Group $Message_Template_Group_Model
137
+	) {
138
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
139
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
140
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @return void
146
+	 */
147
+	protected function _initialize_collections()
148
+	{
149
+		if ($this->_initialized) {
150
+			return;
151
+		}
152
+		$this->_initialized = true;
153
+		$this->_messenger_collection_loader->load_messengers_from_folder();
154
+		$this->_message_type_collection_loader->load_message_types_from_folder();
155
+		$this->get_has_activated_messengers_option(true);
156
+		$this->_set_active_messengers_and_message_types();
157
+	}
158
+
159
+
160
+	/**
161
+	 * @return EE_Messenger_Collection
162
+	 */
163
+	public function messenger_collection()
164
+	{
165
+		$this->_initialize_collections();
166
+		return $this->_messenger_collection_loader->messenger_collection();
167
+	}
168
+
169
+
170
+	/**
171
+	 * @return EE_messenger[]
172
+	 */
173
+	public function active_messengers()
174
+	{
175
+		$this->_initialize_collections();
176
+		return $this->_active_messengers;
177
+	}
178
+
179
+
180
+	/**
181
+	 * @param string $messenger_name
182
+	 * @return \EE_messenger
183
+	 */
184
+	public function get_messenger($messenger_name)
185
+	{
186
+		return $this->messenger_collection()->get_by_info($messenger_name);
187
+	}
188
+
189
+
190
+	/**
191
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
192
+	 *
193
+	 * @param string $messenger
194
+	 * @return EE_messenger | null
195
+	 */
196
+	public function get_active_messenger($messenger)
197
+	{
198
+		$this->_initialize_collections();
199
+		return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null;
200
+	}
201
+
202
+
203
+	/**
204
+	 * @return \EE_messenger[]
205
+	 */
206
+	public function installed_messengers()
207
+	{
208
+		if (empty($this->_installed_messengers)) {
209
+			$this->_installed_messengers = array();
210
+			$this->messenger_collection()->rewind();
211
+			while ($this->messenger_collection()->valid()) {
212
+				$this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current();
213
+				$this->messenger_collection()->next();
214
+			}
215
+		}
216
+		return $this->_installed_messengers;
217
+	}
218
+
219
+
220
+	/**
221
+	 * @param string $messenger_name
222
+	 * @return \EE_messenger
223
+	 * @throws EE_Error
224
+	 */
225
+	public function valid_messenger($messenger_name)
226
+	{
227
+		$messenger = $this->get_messenger($messenger_name);
228
+		if ($messenger instanceof EE_messenger) {
229
+			return $messenger;
230
+		}
231
+		throw new EE_Error(
232
+			sprintf(
233
+				esc_html__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
234
+				$messenger_name
235
+			)
236
+		);
237
+	}
238
+
239
+
240
+	/**
241
+	 * @return EE_Message_Type_Collection
242
+	 */
243
+	public function message_type_collection()
244
+	{
245
+		$this->_initialize_collections();
246
+		return $this->_message_type_collection_loader->message_type_collection();
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return array
252
+	 */
253
+	public function active_message_types()
254
+	{
255
+		$this->_initialize_collections();
256
+		return $this->_active_message_types;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @param string $message_type_name
262
+	 * @return \EE_message_type
263
+	 */
264
+	public function get_message_type($message_type_name)
265
+	{
266
+		return $this->message_type_collection()->get_by_info($message_type_name);
267
+	}
268
+
269
+
270
+	/**
271
+	 * This returns the EE_message_type from the active message types array ( if present );
272
+	 *
273
+	 * @param string $messenger_name
274
+	 * @param string $message_type_name
275
+	 * @return \EE_message_type|null
276
+	 */
277
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
278
+	{
279
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
280
+			? $this->get_message_type($message_type_name)
281
+			: null;
282
+	}
283
+
284
+
285
+	/**
286
+	 * Returns whether the given message type is active for the given messenger.
287
+	 *
288
+	 * @param string $messenger_name
289
+	 * @param string $message_type_name
290
+	 * @return bool
291
+	 */
292
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
293
+	{
294
+		$this->_initialize_collections();
295
+		return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
296
+	}
297
+
298
+
299
+	/**
300
+	 * Returns whether the given messenger is active.
301
+	 *
302
+	 * @param string $messenger_name the name of the messenger to check if active.
303
+	 * @return bool
304
+	 */
305
+	public function is_messenger_active($messenger_name)
306
+	{
307
+		$this->_initialize_collections();
308
+		return ! empty($this->_active_message_types[ $messenger_name ]);
309
+	}
310
+
311
+
312
+	/**
313
+	 * This returns any settings that might be on a message type for a messenger
314
+	 *
315
+	 * @param string $messenger_name    The slug of the messenger
316
+	 * @param string $message_type_name The slug of the message type getting the settings for.
317
+	 * @return array
318
+	 */
319
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
320
+	{
321
+		$settings = array();
322
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
323
+			$settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'])
324
+				? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']
325
+				: array();
326
+		}
327
+		return $settings;
328
+	}
329
+
330
+
331
+	/**
332
+	 * Returns whether the given messenger name has active message types on it.
333
+	 * Infers whether the messenger is active or not as well.
334
+	 *
335
+	 * @param string $messenger_name
336
+	 * @return bool
337
+	 */
338
+	public function messenger_has_active_message_types($messenger_name)
339
+	{
340
+		$this->_initialize_collections();
341
+		return
342
+			! empty($this->_active_message_types[ $messenger_name ])
343
+			&& ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]);
344
+	}
345
+
346
+
347
+	/**
348
+	 * This checks the _active_message_types property for any active message types
349
+	 * that are present for the given messenger and returns them.
350
+	 *
351
+	 * @since 4.9.0
352
+	 * @param string $messenger_name The messenger being checked
353
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
354
+	 */
355
+	public function get_active_message_types_for_messenger($messenger_name)
356
+	{
357
+		$message_types = array();
358
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
359
+			return $message_types;
360
+		}
361
+		$installed_message_types = $this->installed_message_types();
362
+		foreach ($installed_message_types as $message_type_name => $message_type) {
363
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
364
+				$message_types[ $message_type_name ] = $message_type;
365
+			}
366
+		}
367
+		return $message_types;
368
+	}
369
+
370
+
371
+	/**
372
+	 * This does NOT return the _active_message_types property but
373
+	 * simply returns an array of active message type names from that property.
374
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
375
+	 *
376
+	 * @return array message_type references (string)
377
+	 */
378
+	public function list_of_active_message_types()
379
+	{
380
+		$active_message_type_names = array();
381
+		$this->_initialize_collections();
382
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
383
+			if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) {
384
+				continue;
385
+			}
386
+			foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) {
387
+				if (! in_array($message_type_name, $active_message_type_names)) {
388
+					$active_message_type_names[] = $message_type_name;
389
+				}
390
+			}
391
+		}
392
+		return $active_message_type_names;
393
+	}
394
+
395
+
396
+	/**
397
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
398
+	 *
399
+	 * @since 4.9.0
400
+	 * @return \EE_message_type[]
401
+	 */
402
+	public function get_active_message_type_objects()
403
+	{
404
+		$active_message_types      = array();
405
+		$installed_message_types   = $this->installed_message_types();
406
+		$active_message_type_names = $this->list_of_active_message_types();
407
+		foreach ($active_message_type_names as $active_message_type_name) {
408
+			if (isset($installed_message_types[ $active_message_type_name ])) {
409
+				$active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ];
410
+			}
411
+		}
412
+		return $active_message_types;
413
+	}
414
+
415
+
416
+	/**
417
+	 * @return \EE_message_type[]
418
+	 */
419
+	public function installed_message_types()
420
+	{
421
+		if (empty($this->_installed_message_types)) {
422
+			$this->message_type_collection()->rewind();
423
+			while ($this->message_type_collection()->valid()) {
424
+				$this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current();
425
+				$this->message_type_collection()->next();
426
+			}
427
+		}
428
+		return $this->_installed_message_types;
429
+	}
430
+
431
+
432
+	/**
433
+	 * @param string $message_type_name
434
+	 * @return \EE_message_type
435
+	 * @throws EE_Error
436
+	 */
437
+	public function valid_message_type($message_type_name)
438
+	{
439
+		$message_type = $this->get_message_type($message_type_name);
440
+		if ($message_type instanceof EE_message_type) {
441
+			return $message_type;
442
+		}
443
+		throw new EE_Error(
444
+			sprintf(
445
+				esc_html__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
446
+				$message_type_name
447
+			)
448
+		);
449
+	}
450
+
451
+
452
+	/**
453
+	 * valid_message_type_for_messenger
454
+	 *
455
+	 * @param EE_messenger $messenger
456
+	 * @param string       $message_type_name
457
+	 * @return boolean
458
+	 * @throws EE_Error
459
+	 */
460
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
461
+	{
462
+		$valid_message_types = $messenger->get_valid_message_types();
463
+		if (! in_array($message_type_name, $valid_message_types)) {
464
+			throw new EE_Error(
465
+				sprintf(
466
+					esc_html__(
467
+						'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
468
+						'event_espresso'
469
+					),
470
+					$message_type_name,
471
+					__METHOD__,
472
+					$messenger->name
473
+				)
474
+			);
475
+		}
476
+		return true;
477
+	}
478
+
479
+
480
+	/**
481
+	 * Used to return active messengers array stored in the wp options table.
482
+	 * If no value is present in the option then an empty array is returned.
483
+	 *
484
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
485
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
486
+	 *                          $_active_message_types property is pulled.
487
+	 * @return array
488
+	 */
489
+	public function get_active_messengers_option($reset = false)
490
+	{
491
+		if ($reset) {
492
+			$this->_active_message_types = get_option('ee_active_messengers', array());
493
+		}
494
+		return $this->_active_message_types;
495
+	}
496
+
497
+
498
+	/**
499
+	 * Used to update the active messengers array stored in the wp options table.
500
+	 *
501
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
502
+	 *                                         representing this data is used.
503
+	 * @return bool FALSE if not updated, TRUE if updated.
504
+	 */
505
+	public function update_active_messengers_option($active_messenger_settings = array())
506
+	{
507
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
508
+		// make sure _active_message_types is updated (this is the internal cache for the settings).
509
+		$this->_active_message_types = $active_messenger_settings;
510
+		return update_option('ee_active_messengers', $active_messenger_settings);
511
+	}
512
+
513
+
514
+	/**
515
+	 * Used to return has activated message types for messengers array stored in the wp options table.
516
+	 * If no value is present in the option then an empty array is returned.
517
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
518
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
519
+	 *
520
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
521
+	 * @return array
522
+	 */
523
+	public function get_has_activated_messengers_option($reset = false)
524
+	{
525
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
526
+			$this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
527
+		}
528
+		return $this->_has_activated_messengers_and_message_types;
529
+	}
530
+
531
+
532
+	/**
533
+	 * Used to update the has activated option in the db.
534
+	 *
535
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
536
+	 *
537
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
538
+	 *                                        representing this data is used.
539
+	 * @return bool FALSE if not updated, TRUE if updated.
540
+	 */
541
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
542
+	{
543
+		// make sure the option has been retrieved from first so we don't overwrite it accidentally.
544
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
545
+			$this->get_has_activated_messengers_option();
546
+		}
547
+		$has_activated_messengers = empty($has_activated_messengers)
548
+			? $this->_has_activated_messengers_and_message_types
549
+			: $has_activated_messengers;
550
+		return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
551
+	}
552
+
553
+
554
+	/**
555
+	 * wrapper for _set_active_messengers_and_message_types()
556
+	 */
557
+	public function reset_active_messengers_and_message_types()
558
+	{
559
+		$this->_set_active_messengers_and_message_types();
560
+	}
561
+
562
+
563
+	/**
564
+	 * Generate list of active messengers and message types from collection.
565
+	 * This sets up the active messengers from what is present in the database.
566
+	 */
567
+	protected function _set_active_messengers_and_message_types()
568
+	{
569
+		// echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
570
+		// list of activated messengers as set via the admin
571
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
572
+		$this->get_active_messengers_option(true);
573
+		$this->ensure_messengers_are_active(array(), false, true);
574
+		$this->update_active_messengers_option();
575
+		$this->update_has_activated_messengers_option();
576
+	}
577
+
578
+
579
+	/**
580
+	 * Ensures that the specified messenger is currently active.
581
+	 * If not, activates it and its default message types.
582
+	 *
583
+	 * @param string $messenger_name
584
+	 * @param bool   $update_option Whether to update the option in the db or not.
585
+	 * @return boolean true if either already active or successfully activated.
586
+	 */
587
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
588
+	{
589
+		if (! isset($this->_active_messengers[ $messenger_name ])) {
590
+			try {
591
+				$this->activate_messenger($messenger_name, array(), $update_option);
592
+			} catch (EE_Error $e) {
593
+				EE_Error::add_error(
594
+					$e->getMessage(),
595
+					__FILE__,
596
+					__FUNCTION__,
597
+					__LINE__
598
+				);
599
+				return false;
600
+			}
601
+		}
602
+		return true;
603
+	}
604
+
605
+
606
+	/**
607
+	 * This ensures the given array of messenger names is active in the system.
608
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
609
+	 * it will automatically activate the default message types for the messenger if its not active.
610
+	 *
611
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
612
+	 *                                (default) then will attempt to set the active messengers from the
613
+	 *                                activated_messengers option
614
+	 *                                (stored in $_active_message_types property).
615
+	 * @param bool  $update_option    Whether to update the related active messengers option.
616
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
617
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
618
+	 *                                will automatically be deactivated.
619
+	 */
620
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
621
+	{
622
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
623
+
624
+		$not_installed = array();
625
+		foreach ($messenger_names as $messenger_name) {
626
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
627
+				$not_installed[] = $messenger_name;
628
+				$this->deactivate_messenger($messenger_name);
629
+				continue;
630
+			}
631
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
632
+		}
633
+
634
+		if (! empty($not_installed)) {
635
+			EE_Error::add_error(
636
+				sprintf(
637
+					esc_html__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
638
+					'<br />',
639
+					implode(', ', $not_installed)
640
+				),
641
+				__FILE__,
642
+				__FUNCTION__,
643
+				__LINE__
644
+			);
645
+		}
646
+	}
647
+
648
+
649
+	/**
650
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
651
+	 * This ALSO ensures that the given messenger is active as well!
652
+	 *
653
+	 * @param string $message_type_name message type name.
654
+	 * @param        $messenger_name
655
+	 * @param bool   $update_option     Whether to update the option in the db or not.
656
+	 * @return bool  Returns true if already is active or if was activated successfully.
657
+	 * @throws EE_Error
658
+	 */
659
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
660
+	{
661
+		// grab the messenger to work with.
662
+		$messenger = $this->valid_messenger($messenger_name);
663
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
664
+			// ensure messenger is active (that's an inherent coupling between active message types and the
665
+			// messenger they are being activated for.
666
+			try {
667
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
668
+					// all is good so let's just get it active
669
+					$this->activate_messenger($messenger, array($message_type_name), $update_option);
670
+				}
671
+			} catch (EE_Error $e) {
672
+				EE_Error::add_error(
673
+					$e->getMessage(),
674
+					__FILE__,
675
+					__FUNCTION__,
676
+					__LINE__
677
+				);
678
+				return false;
679
+			}
680
+		}
681
+		return true;
682
+	}
683
+
684
+
685
+	/**
686
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
687
+	 * messenger are active in one go.
688
+	 *
689
+	 * @param array  $message_type_names Array of message type names to ensure are active.
690
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
691
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
692
+	 */
693
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
694
+	{
695
+		$message_type_names = (array) $message_type_names;
696
+		foreach ($message_type_names as $message_type_name) {
697
+			// note, intentionally not updating option here because we're in a loop.
698
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
699
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
700
+		}
701
+		if ($update_option) {
702
+			$this->update_active_messengers_option();
703
+			$this->update_has_activated_messengers_option();
704
+		}
705
+	}
706
+
707
+
708
+	/**
709
+	 * Activates the specified messenger.
710
+	 *
711
+	 * @param EE_messenger|string $messenger    Instantiated EE_messenger OR messenger name if not already loaded!
712
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
713
+	 *                                          If included we do NOT setup the default message types
714
+	 *                                          (assuming they are already setup.)
715
+	 * @param bool   $update_active_messengers_option
716
+	 * @return array of generated templates
717
+	 * @throws EE_Error
718
+	 */
719
+	public function activate_messenger(
720
+		$messenger,
721
+		$message_type_names = array(),
722
+		$update_active_messengers_option = true
723
+	) {
724
+		$templates = array();
725
+		// grab the messenger to work with.
726
+		$messenger = $messenger instanceof EE_messenger
727
+			? $messenger
728
+			: $this->messenger_collection()->get_by_info($messenger);
729
+		// it's inactive. Activate it.
730
+		if ($messenger instanceof EE_messenger) {
731
+			$this->_active_messengers[ $messenger->name ] = $messenger;
732
+			// activate incoming message types set to be activated with messenger.
733
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
734
+			// setup any initial settings for the messenger if necessary.
735
+			$this->add_settings_for_messenger($messenger->name);
736
+			if ($update_active_messengers_option) {
737
+				$this->update_active_messengers_option();
738
+				$this->update_has_activated_messengers_option();
739
+			}
740
+			// generate new templates if necessary and ensure all related templates that are already in the database are
741
+			// marked active.  Note, this will also deactivate a message type for a messenger if the template
742
+			// cannot be successfully created during its attempt (only happens for global template attempts).
743
+			if (! empty($message_type_names)) {
744
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
745
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
746
+			}
747
+		}
748
+		return $templates;
749
+	}
750
+
751
+
752
+	/**
753
+	 * Activates given message types for the given EE_messenger object.
754
+	 * Note: (very important) This method does not persist the activation to the database.
755
+	 * See code implementing this method in this class for examples of how to persist.
756
+	 *
757
+	 * @param \EE_messenger $messenger
758
+	 * @param  array        $message_type_names
759
+	 * @return array
760
+	 */
761
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
762
+	{
763
+		// If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
764
+		// things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
765
+		// So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
766
+		// only override _active_message_types when an explicit array of $message_type_names has been provided.
767
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ])
768
+			? $messenger->get_default_message_types()
769
+			: (array) $message_type_names;
770
+
771
+		// now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
772
+		if (! isset($this->_active_message_types[ $messenger->name ])) {
773
+			$this->_active_message_types[ $messenger->name ]['settings'] = array();
774
+		}
775
+
776
+		if ($message_type_names) {
777
+			// cycle thru message types
778
+			foreach ($message_type_names as $message_type_name) {
779
+				// only register the message type as active IF it isn't already active
780
+				// and if its actually installed.
781
+				if (
782
+					! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
783
+				) {
784
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
785
+					$this->_set_messenger_has_activated_message_type(
786
+						$messenger,
787
+						$message_type_name
788
+					);
789
+				}
790
+			}
791
+		}
792
+		return $message_type_names;
793
+	}
794
+
795
+
796
+	/**
797
+	 * add_settings_for_message_type
798
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
799
+	 * $this->update_active_messengers_option to persist.
800
+	 *
801
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
802
+	 * @param  string $message_type_name The name of the message type adding the settings for
803
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
804
+	 */
805
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
806
+	{
807
+		// get installed message type from collection
808
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
809
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
810
+		// we need to setup any initial settings for message types
811
+		if ($message_type instanceof EE_message_type) {
812
+			$default_settings = $message_type->get_admin_settings_fields();
813
+			foreach ($default_settings as $field => $values) {
814
+				if (isset($new_settings[ $field ])) {
815
+					$existing_settings[ $field ] = $new_settings[ $field ];
816
+					continue;
817
+				}
818
+				if (! isset($existing_settings[ $field ])) {
819
+					$existing_settings[ $field ] = $values['default'];
820
+				}
821
+			}
822
+		}
823
+		$this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings;
824
+	}
825
+
826
+
827
+	/**
828
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
829
+	 * and message type.
830
+	 *
831
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
832
+	 *
833
+	 * @access protected
834
+	 * @param \EE_messenger $messenger
835
+	 * @param string        $message_type_name
836
+	 */
837
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
838
+	{
839
+
840
+		// if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
841
+		if (empty($this->_has_activated_messengers_and_message_types)) {
842
+			$this->get_has_activated_messengers_option();
843
+		}
844
+
845
+		// make sure this messenger has a record in the has_activated array
846
+		if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
847
+			$this->_has_activated_messengers_and_message_types[ $messenger->name ] = array();
848
+		}
849
+		// check if message type has already been added
850
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
851
+			$this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name;
852
+		}
853
+	}
854
+
855
+
856
+	/**
857
+	 * add_settings_for_messenger
858
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
859
+	 * $this->update_active_messengers_option to persist.
860
+	 *
861
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
862
+	 * @param array  $new_settings   An array of settings to update the existing settings.
863
+	 */
864
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
865
+	{
866
+		$messenger = $this->get_messenger($messenger_name);
867
+		if ($messenger instanceof EE_messenger) {
868
+			$msgr_settings = $messenger->get_admin_settings_fields();
869
+			if (! empty($msgr_settings)) {
870
+				foreach ($msgr_settings as $field => $value) {
871
+					// is there a new setting for this?
872
+					if (isset($new_settings[ $field ])) {
873
+						$this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ];
874
+						continue;
875
+					}
876
+					// only set the default if it isn't already set.
877
+					if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) {
878
+						$this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value;
879
+					}
880
+				}
881
+			}
882
+		}
883
+	}
884
+
885
+
886
+	/**
887
+	 * deactivate_messenger
888
+	 *
889
+	 * @param  string|EE_messenger $messenger_name name of messenger
890
+	 * @return void
891
+	 */
892
+	public function deactivate_messenger($messenger_name)
893
+	{
894
+		$this->_initialize_collections();
895
+		if ($messenger_name instanceof EE_messenger) {
896
+			$messenger_name = $messenger_name->name;
897
+		}
898
+		unset($this->_active_messengers[ $messenger_name ]);
899
+		unset($this->_active_message_types[ $messenger_name ]);
900
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
901
+		$this->update_active_messengers_option();
902
+	}
903
+
904
+
905
+	/**
906
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
907
+	 *
908
+	 * @param  string $message_type_name     name of message type being deactivated
909
+	 * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
910
+	 *                                       type.  However, this can be overridden if we don't want this set (usually when
911
+	 *                                       this is called as a part of deregistration of a custom message type)
912
+	 */
913
+	public function deactivate_message_type($message_type_name, $set_has_active_record = true)
914
+	{
915
+		$this->_initialize_collections();
916
+		if ($message_type_name instanceof EE_message_type) {
917
+			$message_type_name = $message_type_name->name;
918
+		}
919
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
920
+			unset(
921
+				$this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]
922
+			);
923
+
924
+			// we always record (even on deactivation) that a message type has been activated because there should at
925
+			// least be a record in the "has_activated" option that it WAS active at one point.
926
+			if ($set_has_active_record) {
927
+				$messenger = $this->get_messenger($messenger_name);
928
+				$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
929
+			}
930
+		}
931
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
932
+		$this->update_active_messengers_option();
933
+		$this->update_has_activated_messengers_option();
934
+	}
935
+
936
+
937
+	/**
938
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
939
+	 *
940
+	 * @param string $message_type_name Name of message type being deactivated.
941
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
942
+	 */
943
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
944
+	{
945
+		$this->_initialize_collections();
946
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
947
+			unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
948
+		}
949
+		$this->_message_template_group_model->deactivate_message_template_groups_for(
950
+			array($messenger_name),
951
+			array($message_type_name)
952
+		);
953
+		$this->update_active_messengers_option();
954
+	}
955
+
956
+
957
+	/**
958
+	 * Used to verify if a message can be sent for the given messenger and message type
959
+	 * and that it is a generating messenger (used for generating message templates).
960
+	 *
961
+	 * @param EE_messenger    $messenger    messenger used in trigger
962
+	 * @param EE_message_type $message_type message type used in trigger
963
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
964
+	 */
965
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
966
+	{
967
+		// get the $messengers the message type says it can be used with.
968
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
969
+			if (
970
+				$messenger->name === $generating_messenger
971
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
972
+			) {
973
+				return true;
974
+			}
975
+		}
976
+		return false;
977
+	}
978
+
979
+
980
+	/**
981
+	 * This returns all the contexts that are registered by all message types.
982
+	 * If $slugs_only is true,
983
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
984
+	 * array(
985
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
986
+	 * );
987
+	 * If $slugs_only is false, then the format is:
988
+	 * array(
989
+	 *      'message_type_name' => array(
990
+	 *          'context_slug' => array(
991
+	 *              'label' => 'localized label for context',
992
+	 *              'description' => 'localized description for context'
993
+	 *          )
994
+	 *      )
995
+	 * );
996
+	 * Keep in mind that although different message types may share the same context slugs,
997
+	 * it is possible that the context is described differently by the message type.
998
+	 *
999
+	 * @since 4.9.0
1000
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1001
+	 *                           or all contexts indexed by message type.
1002
+	 * @return array
1003
+	 */
1004
+	public function get_all_contexts($slugs_only = true)
1005
+	{
1006
+		$key = $slugs_only ? 'slugs' : 'all';
1007
+		// check if contexts has been setup yet.
1008
+		if (empty($this->_contexts[ $key ])) {
1009
+			// So let's get all active message type objects and loop through to get all unique contexts
1010
+			foreach ($this->get_active_message_type_objects() as $message_type) {
1011
+				if ($message_type instanceof EE_message_type) {
1012
+					$message_type_contexts = $message_type->get_contexts();
1013
+					if ($slugs_only) {
1014
+						foreach ($message_type_contexts as $context => $context_details) {
1015
+							$this->_contexts[ $key ][ $context ] = $context_details['label'];
1016
+						}
1017
+					} else {
1018
+						$this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts;
1019
+					}
1020
+				}
1021
+			}
1022
+		}
1023
+		return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array();
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * This checks the internal record of what message types are considered "active" and verifies that
1029
+	 * there is an installed class definition for that message type.  If the active message type does not have a
1030
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1031
+	 * any related message templates will be inactivated as well.
1032
+	 *
1033
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1034
+	 *                deactivated.
1035
+	 */
1036
+	public function validate_active_message_types_are_installed()
1037
+	{
1038
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1039
+		$installed_message_types           = $this->installed_message_types();
1040
+		$all_message_types_valid           = true;
1041
+		// loop through list of active message types and verify they are installed.
1042
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1043
+			if (! isset($installed_message_types[ $message_type_name ])) {
1044
+				$this->remove_message_type_has_been_activated_from_all_messengers(
1045
+					$message_type_name,
1046
+					true
1047
+				);
1048
+				$this->deactivate_message_type($message_type_name, false);
1049
+				$all_message_types_valid = false;
1050
+			}
1051
+		}
1052
+		return $all_message_types_valid;
1053
+	}
1054
+
1055
+
1056
+	/**
1057
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1058
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1059
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1060
+	 *
1061
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1062
+	 *
1063
+	 * @param $message_type_name
1064
+	 * @param $messenger_name
1065
+	 * @return bool
1066
+	 */
1067
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1068
+	{
1069
+		$has_activated = $this->get_has_activated_messengers_option();
1070
+		return isset($has_activated[ $messenger_name ])
1071
+			   && in_array($message_type_name, $has_activated[ $messenger_name ]);
1072
+	}
1073
+
1074
+
1075
+	/**
1076
+	 * This method unsets a message type from the given messenger has activated option.
1077
+	 *
1078
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1079
+	 *
1080
+	 * @param string $message_type_name
1081
+	 * @param string $messenger_name
1082
+	 * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1083
+	 *                                        If it is currently active, then remove.  Otherwise leave it alone.
1084
+	 */
1085
+	public function remove_message_type_has_been_activated_for_messenger(
1086
+		$message_type_name,
1087
+		$messenger_name,
1088
+		$consider_current_state = false
1089
+	) {
1090
+		if (
1091
+			$consider_current_state
1092
+			&& ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1093
+		) {
1094
+			// when consider current state is true, this means we don't want to change anything on the "has_activated"
1095
+			// record if the message type is currently active for this messenger.  This is used when we want to retain
1096
+			// the record for user initiated inactivations of the message type.
1097
+			return;
1098
+		}
1099
+		$has_activated = $this->get_has_activated_messengers_option();
1100
+		$key_for_message_type = isset($has_activated[ $messenger_name ])
1101
+			? array_search($message_type_name, $has_activated[ $messenger_name ], true)
1102
+			: false;
1103
+		if ($key_for_message_type !== false) {
1104
+			unset($has_activated[ $messenger_name ][ $key_for_message_type ]);
1105
+			$this->update_has_activated_messengers_option($has_activated);
1106
+			// reset the internal cached property
1107
+			$this->get_has_activated_messengers_option(true);
1108
+		}
1109
+	}
1110
+
1111
+
1112
+	/**
1113
+	 * Removes a message type active record from all messengers it is attached to.
1114
+	 *
1115
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1116
+	 *
1117
+	 * @param      $message_type_name
1118
+	 * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1119
+	 *                                      If it is currently active, then remove.  Otherwise leave it alone.
1120
+	 */
1121
+	public function remove_message_type_has_been_activated_from_all_messengers(
1122
+		$message_type_name,
1123
+		$consider_current_state = false
1124
+	) {
1125
+		foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1126
+			$this->remove_message_type_has_been_activated_for_messenger(
1127
+				$message_type_name,
1128
+				$messenger_name,
1129
+				$consider_current_state
1130
+			);
1131
+		}
1132
+	}
1133 1133
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
     public function get_active_messenger($messenger)
197 197
     {
198 198
         $this->_initialize_collections();
199
-        return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null;
199
+        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
200 200
     }
201 201
 
202 202
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
             $this->_installed_messengers = array();
210 210
             $this->messenger_collection()->rewind();
211 211
             while ($this->messenger_collection()->valid()) {
212
-                $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current();
212
+                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
213 213
                 $this->messenger_collection()->next();
214 214
             }
215 215
         }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
293 293
     {
294 294
         $this->_initialize_collections();
295
-        return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
295
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
296 296
     }
297 297
 
298 298
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
     public function is_messenger_active($messenger_name)
306 306
     {
307 307
         $this->_initialize_collections();
308
-        return ! empty($this->_active_message_types[ $messenger_name ]);
308
+        return ! empty($this->_active_message_types[$messenger_name]);
309 309
     }
310 310
 
311 311
 
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
     {
321 321
         $settings = array();
322 322
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
323
-            $settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'])
324
-                ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']
323
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
324
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
325 325
                 : array();
326 326
         }
327 327
         return $settings;
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
     {
340 340
         $this->_initialize_collections();
341 341
         return
342
-            ! empty($this->_active_message_types[ $messenger_name ])
343
-            && ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]);
342
+            ! empty($this->_active_message_types[$messenger_name])
343
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
344 344
     }
345 345
 
346 346
 
@@ -355,13 +355,13 @@  discard block
 block discarded – undo
355 355
     public function get_active_message_types_for_messenger($messenger_name)
356 356
     {
357 357
         $message_types = array();
358
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
358
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
359 359
             return $message_types;
360 360
         }
361 361
         $installed_message_types = $this->installed_message_types();
362 362
         foreach ($installed_message_types as $message_type_name => $message_type) {
363 363
             if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
364
-                $message_types[ $message_type_name ] = $message_type;
364
+                $message_types[$message_type_name] = $message_type;
365 365
             }
366 366
         }
367 367
         return $message_types;
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
         $active_message_type_names = array();
381 381
         $this->_initialize_collections();
382 382
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
383
-            if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) {
383
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
384 384
                 continue;
385 385
             }
386
-            foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) {
387
-                if (! in_array($message_type_name, $active_message_type_names)) {
386
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
387
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
388 388
                     $active_message_type_names[] = $message_type_name;
389 389
                 }
390 390
             }
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
         $installed_message_types   = $this->installed_message_types();
406 406
         $active_message_type_names = $this->list_of_active_message_types();
407 407
         foreach ($active_message_type_names as $active_message_type_name) {
408
-            if (isset($installed_message_types[ $active_message_type_name ])) {
409
-                $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ];
408
+            if (isset($installed_message_types[$active_message_type_name])) {
409
+                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
410 410
             }
411 411
         }
412 412
         return $active_message_types;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         if (empty($this->_installed_message_types)) {
422 422
             $this->message_type_collection()->rewind();
423 423
             while ($this->message_type_collection()->valid()) {
424
-                $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current();
424
+                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
425 425
                 $this->message_type_collection()->next();
426 426
             }
427 427
         }
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
461 461
     {
462 462
         $valid_message_types = $messenger->get_valid_message_types();
463
-        if (! in_array($message_type_name, $valid_message_types)) {
463
+        if ( ! in_array($message_type_name, $valid_message_types)) {
464 464
             throw new EE_Error(
465 465
                 sprintf(
466 466
                     esc_html__(
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
      */
587 587
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
588 588
     {
589
-        if (! isset($this->_active_messengers[ $messenger_name ])) {
589
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
590 590
             try {
591 591
                 $this->activate_messenger($messenger_name, array(), $update_option);
592 592
             } catch (EE_Error $e) {
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
             $this->ensure_messenger_is_active($messenger_name, $update_option);
632 632
         }
633 633
 
634
-        if (! empty($not_installed)) {
634
+        if ( ! empty($not_installed)) {
635 635
             EE_Error::add_error(
636 636
                 sprintf(
637 637
                     esc_html__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
             // ensure messenger is active (that's an inherent coupling between active message types and the
665 665
             // messenger they are being activated for.
666 666
             try {
667
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
667
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
668 668
                     // all is good so let's just get it active
669 669
                     $this->activate_messenger($messenger, array($message_type_name), $update_option);
670 670
                 }
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
             : $this->messenger_collection()->get_by_info($messenger);
729 729
         // it's inactive. Activate it.
730 730
         if ($messenger instanceof EE_messenger) {
731
-            $this->_active_messengers[ $messenger->name ] = $messenger;
731
+            $this->_active_messengers[$messenger->name] = $messenger;
732 732
             // activate incoming message types set to be activated with messenger.
733 733
             $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
734 734
             // setup any initial settings for the messenger if necessary.
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
             // generate new templates if necessary and ensure all related templates that are already in the database are
741 741
             // marked active.  Note, this will also deactivate a message type for a messenger if the template
742 742
             // cannot be successfully created during its attempt (only happens for global template attempts).
743
-            if (! empty($message_type_names)) {
743
+            if ( ! empty($message_type_names)) {
744 744
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
745 745
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
746 746
             }
@@ -764,13 +764,13 @@  discard block
 block discarded – undo
764 764
         // things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
765 765
         // So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
766 766
         // only override _active_message_types when an explicit array of $message_type_names has been provided.
767
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ])
767
+        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
768 768
             ? $messenger->get_default_message_types()
769 769
             : (array) $message_type_names;
770 770
 
771 771
         // now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
772
-        if (! isset($this->_active_message_types[ $messenger->name ])) {
773
-            $this->_active_message_types[ $messenger->name ]['settings'] = array();
772
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
773
+            $this->_active_message_types[$messenger->name]['settings'] = array();
774 774
         }
775 775
 
776 776
         if ($message_type_names) {
@@ -811,16 +811,16 @@  discard block
 block discarded – undo
811 811
         if ($message_type instanceof EE_message_type) {
812 812
             $default_settings = $message_type->get_admin_settings_fields();
813 813
             foreach ($default_settings as $field => $values) {
814
-                if (isset($new_settings[ $field ])) {
815
-                    $existing_settings[ $field ] = $new_settings[ $field ];
814
+                if (isset($new_settings[$field])) {
815
+                    $existing_settings[$field] = $new_settings[$field];
816 816
                     continue;
817 817
                 }
818
-                if (! isset($existing_settings[ $field ])) {
819
-                    $existing_settings[ $field ] = $values['default'];
818
+                if ( ! isset($existing_settings[$field])) {
819
+                    $existing_settings[$field] = $values['default'];
820 820
                 }
821 821
             }
822 822
         }
823
-        $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings;
823
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
824 824
     }
825 825
 
826 826
 
@@ -843,12 +843,12 @@  discard block
 block discarded – undo
843 843
         }
844 844
 
845 845
         // make sure this messenger has a record in the has_activated array
846
-        if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
847
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array();
846
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
847
+            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
848 848
         }
849 849
         // check if message type has already been added
850
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) {
851
-            $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name;
850
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
851
+            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
852 852
         }
853 853
     }
854 854
 
@@ -866,16 +866,16 @@  discard block
 block discarded – undo
866 866
         $messenger = $this->get_messenger($messenger_name);
867 867
         if ($messenger instanceof EE_messenger) {
868 868
             $msgr_settings = $messenger->get_admin_settings_fields();
869
-            if (! empty($msgr_settings)) {
869
+            if ( ! empty($msgr_settings)) {
870 870
                 foreach ($msgr_settings as $field => $value) {
871 871
                     // is there a new setting for this?
872
-                    if (isset($new_settings[ $field ])) {
873
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ];
872
+                    if (isset($new_settings[$field])) {
873
+                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
874 874
                         continue;
875 875
                     }
876 876
                     // only set the default if it isn't already set.
877
-                    if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) {
878
-                        $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value;
877
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
878
+                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
879 879
                     }
880 880
                 }
881 881
             }
@@ -895,8 +895,8 @@  discard block
 block discarded – undo
895 895
         if ($messenger_name instanceof EE_messenger) {
896 896
             $messenger_name = $messenger_name->name;
897 897
         }
898
-        unset($this->_active_messengers[ $messenger_name ]);
899
-        unset($this->_active_message_types[ $messenger_name ]);
898
+        unset($this->_active_messengers[$messenger_name]);
899
+        unset($this->_active_message_types[$messenger_name]);
900 900
         $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
901 901
         $this->update_active_messengers_option();
902 902
     }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
         }
919 919
         foreach ($this->_active_message_types as $messenger_name => $settings) {
920 920
             unset(
921
-                $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]
921
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
922 922
             );
923 923
 
924 924
             // we always record (even on deactivation) that a message type has been activated because there should at
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
     {
945 945
         $this->_initialize_collections();
946 946
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
947
-            unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]);
947
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
948 948
         }
949 949
         $this->_message_template_group_model->deactivate_message_template_groups_for(
950 950
             array($messenger_name),
@@ -1005,22 +1005,22 @@  discard block
 block discarded – undo
1005 1005
     {
1006 1006
         $key = $slugs_only ? 'slugs' : 'all';
1007 1007
         // check if contexts has been setup yet.
1008
-        if (empty($this->_contexts[ $key ])) {
1008
+        if (empty($this->_contexts[$key])) {
1009 1009
             // So let's get all active message type objects and loop through to get all unique contexts
1010 1010
             foreach ($this->get_active_message_type_objects() as $message_type) {
1011 1011
                 if ($message_type instanceof EE_message_type) {
1012 1012
                     $message_type_contexts = $message_type->get_contexts();
1013 1013
                     if ($slugs_only) {
1014 1014
                         foreach ($message_type_contexts as $context => $context_details) {
1015
-                            $this->_contexts[ $key ][ $context ] = $context_details['label'];
1015
+                            $this->_contexts[$key][$context] = $context_details['label'];
1016 1016
                         }
1017 1017
                     } else {
1018
-                        $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts;
1018
+                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
1019 1019
                     }
1020 1020
                 }
1021 1021
             }
1022 1022
         }
1023
-        return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array();
1023
+        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1024 1024
     }
1025 1025
 
1026 1026
 
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
         $all_message_types_valid           = true;
1041 1041
         // loop through list of active message types and verify they are installed.
1042 1042
         foreach ($list_of_active_message_type_names as $message_type_name) {
1043
-            if (! isset($installed_message_types[ $message_type_name ])) {
1043
+            if ( ! isset($installed_message_types[$message_type_name])) {
1044 1044
                 $this->remove_message_type_has_been_activated_from_all_messengers(
1045 1045
                     $message_type_name,
1046 1046
                     true
@@ -1067,8 +1067,8 @@  discard block
 block discarded – undo
1067 1067
     public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1068 1068
     {
1069 1069
         $has_activated = $this->get_has_activated_messengers_option();
1070
-        return isset($has_activated[ $messenger_name ])
1071
-               && in_array($message_type_name, $has_activated[ $messenger_name ]);
1070
+        return isset($has_activated[$messenger_name])
1071
+               && in_array($message_type_name, $has_activated[$messenger_name]);
1072 1072
     }
1073 1073
 
1074 1074
 
@@ -1097,11 +1097,11 @@  discard block
 block discarded – undo
1097 1097
             return;
1098 1098
         }
1099 1099
         $has_activated = $this->get_has_activated_messengers_option();
1100
-        $key_for_message_type = isset($has_activated[ $messenger_name ])
1101
-            ? array_search($message_type_name, $has_activated[ $messenger_name ], true)
1100
+        $key_for_message_type = isset($has_activated[$messenger_name])
1101
+            ? array_search($message_type_name, $has_activated[$messenger_name], true)
1102 1102
             : false;
1103 1103
         if ($key_for_message_type !== false) {
1104
-            unset($has_activated[ $messenger_name ][ $key_for_message_type ]);
1104
+            unset($has_activated[$messenger_name][$key_for_message_type]);
1105 1105
             $this->update_has_activated_messengers_option($has_activated);
1106 1106
             // reset the internal cached property
1107 1107
             $this->get_has_activated_messengers_option(true);
Please login to merge, or discard this patch.