Completed
Branch dev (96eba5)
by
unknown
11:47 queued 05:08
created
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +748 added lines, -748 removed lines patch added patch discarded remove patch
@@ -16,182 +16,182 @@  discard block
 block discarded – undo
16 16
  */
17 17
 abstract class EE_messenger extends EE_Messages_Base
18 18
 {
19
-    /**
20
-     * 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.
21
-     * This property gets set by the _set_default_message_types() method.
22
-     *
23
-     * @var array
24
-     */
25
-    protected $_default_message_types = array();
19
+	/**
20
+	 * 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.
21
+	 * This property gets set by the _set_default_message_types() method.
22
+	 *
23
+	 * @var array
24
+	 */
25
+	protected $_default_message_types = array();
26 26
 
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * This property holds the message types that are valid for use with this messenger.
32
-     * It gets set by the _set_valid_message_types() method.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $_valid_message_types = array();
30
+	/**
31
+	 * This property holds the message types that are valid for use with this messenger.
32
+	 * It gets set by the _set_valid_message_types() method.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $_valid_message_types = array();
37 37
 
38 38
 
39 39
 
40
-    /**
41
-     * 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.
42
-     *
43
-     * 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).
44
-     *
45
-     * Array should be in this format:
46
-     *
47
-     * array(
48
-     *  'field_name(i.e.to)' => array(
49
-     *      '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).
50
-     *      '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.
51
-     *      '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.,
52
-     *      '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.
53
-     *  )
54
-     * )
55
-     *
56
-     * @var array
57
-     */
58
-    protected $_validator_config = array();
40
+	/**
41
+	 * 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.
42
+	 *
43
+	 * 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).
44
+	 *
45
+	 * Array should be in this format:
46
+	 *
47
+	 * array(
48
+	 *  'field_name(i.e.to)' => array(
49
+	 *      '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).
50
+	 *      '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.
51
+	 *      '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.,
52
+	 *      '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.
53
+	 *  )
54
+	 * )
55
+	 *
56
+	 * @var array
57
+	 */
58
+	protected $_validator_config = array();
59 59
 
60 60
 
61 61
 
62
-    /**
63
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
64
-     * @var object
65
-     */
66
-    protected $_EEM_data;
62
+	/**
63
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
64
+	 * @var object
65
+	 */
66
+	protected $_EEM_data;
67 67
 
68 68
 
69 69
 
70
-    /**
71
-     * this property just holds an array of the various template refs.
72
-     * @var array
73
-     */
74
-    protected $_template_fields = array();
70
+	/**
71
+	 * this property just holds an array of the various template refs.
72
+	 * @var array
73
+	 */
74
+	protected $_template_fields = array();
75 75
 
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * This holds an array of the arguments used in parsing a template for the sender.
81
-     * @var array
82
-     */
83
-    protected $_template_args = array();
79
+	/**
80
+	 * This holds an array of the arguments used in parsing a template for the sender.
81
+	 * @var array
82
+	 */
83
+	protected $_template_args = array();
84 84
 
85 85
 
86 86
 
87 87
 
88 88
 
89 89
 
90
-    /**
91
-     * 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
92
-     *
93
-     * @protected
94
-     * @var array
95
-     */
96
-    protected $_test_settings_fields = array();
90
+	/**
91
+	 * 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
92
+	 *
93
+	 * @protected
94
+	 * @var array
95
+	 */
96
+	protected $_test_settings_fields = array();
97 97
 
98 98
 
99 99
 
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * 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.
105
-     *
106
-     * @since 4.5.0
107
-     *
108
-     * @var EE_Messages_Template_Pack
109
-     */
110
-    protected $_tmp_pack;
103
+	/**
104
+	 * 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.
105
+	 *
106
+	 * @since 4.5.0
107
+	 *
108
+	 * @var EE_Messages_Template_Pack
109
+	 */
110
+	protected $_tmp_pack;
111 111
 
112 112
 
113 113
 
114 114
 
115
-    /**
116
-     * 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.
117
-     *
118
-     * @since 4.5.0
119
-     *
120
-     * @var string
121
-     */
122
-    protected $_variation;
115
+	/**
116
+	 * 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.
117
+	 *
118
+	 * @since 4.5.0
119
+	 *
120
+	 * @var string
121
+	 */
122
+	protected $_variation;
123 123
 
124 124
 
125 125
 
126 126
 
127 127
 
128
-    /**
129
-     * 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:
130
-     *
131
-     *  - template pack
132
-     *  - template variation
133
-     *
134
-     * @since 4.5.0
135
-     *
136
-     * @var stdClass
137
-     */
138
-    protected $_supports_labels;
128
+	/**
129
+	 * 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:
130
+	 *
131
+	 *  - template pack
132
+	 *  - template variation
133
+	 *
134
+	 * @since 4.5.0
135
+	 *
136
+	 * @var stdClass
137
+	 */
138
+	protected $_supports_labels;
139 139
 
140 140
 
141 141
 
142 142
 
143 143
 
144
-    /**
145
-     * 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.
146
-     *
147
-     * @var EE_message_type
148
-     */
149
-    protected $_incoming_message_type;
144
+	/**
145
+	 * 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.
146
+	 *
147
+	 * @var EE_message_type
148
+	 */
149
+	protected $_incoming_message_type;
150 150
 
151 151
 
152 152
 
153
-    /**
154
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
155
-     *
156
-     * @var bool
157
-     */
158
-    public $activate_on_install = false;
153
+	/**
154
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
155
+	 *
156
+	 * @var bool
157
+	 */
158
+	public $activate_on_install = false;
159 159
 
160 160
 
161 161
 
162 162
 
163 163
 
164
-    public function __construct()
165
-    {
166
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
167
-        $this->_messages_item_type = 'messenger';
164
+	public function __construct()
165
+	{
166
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
167
+		$this->_messages_item_type = 'messenger';
168 168
 
169
-        parent::__construct();
169
+		parent::__construct();
170 170
 
171
-        $this->_set_test_settings_fields();
172
-        $this->_set_template_fields();
173
-        $this->_set_default_message_types();
174
-        $this->_set_valid_message_types();
175
-        $this->_set_validator_config();
171
+		$this->_set_test_settings_fields();
172
+		$this->_set_template_fields();
173
+		$this->_set_default_message_types();
174
+		$this->_set_valid_message_types();
175
+		$this->_set_validator_config();
176 176
 
177 177
 
178
-        $this->_supports_labels = new stdClass();
179
-        $this->_set_supports_labels();
180
-    }
178
+		$this->_supports_labels = new stdClass();
179
+		$this->_set_supports_labels();
180
+	}
181 181
 
182 182
 
183 183
 
184 184
 
185 185
 
186
-    /**
187
-     * _set_template_fields
188
-     * This sets up the fields that a messenger requires for the message to go out.
189
-     *
190
-     * @abstract
191
-     * @access  protected
192
-     * @return void
193
-     */
194
-    abstract protected function _set_template_fields();
186
+	/**
187
+	 * _set_template_fields
188
+	 * This sets up the fields that a messenger requires for the message to go out.
189
+	 *
190
+	 * @abstract
191
+	 * @access  protected
192
+	 * @return void
193
+	 */
194
+	abstract protected function _set_template_fields();
195 195
 
196 196
 
197 197
 
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 
202 202
 
203 203
 
204
-    /**
205
-     * This method sets the _default_message_type property (see definition in docs attached to property)
206
-     *
207
-     * @abstract
208
-     * @access protected
209
-     * @return void
210
-     */
211
-    abstract protected function _set_default_message_types();
204
+	/**
205
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
206
+	 *
207
+	 * @abstract
208
+	 * @access protected
209
+	 * @return void
210
+	 */
211
+	abstract protected function _set_default_message_types();
212 212
 
213 213
 
214 214
 
@@ -216,15 +216,15 @@  discard block
 block discarded – undo
216 216
 
217 217
 
218 218
 
219
-    /**
220
-     * Sets the _valid_message_types property (see definition in cods attached to property)
221
-     *
222
-     * @since 4.5.0
223
-     *
224
-     * @abstract
225
-     * @return void
226
-     */
227
-    abstract protected function _set_valid_message_types();
219
+	/**
220
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
221
+	 *
222
+	 * @since 4.5.0
223
+	 *
224
+	 * @abstract
225
+	 * @return void
226
+	 */
227
+	abstract protected function _set_valid_message_types();
228 228
 
229 229
 
230 230
 
@@ -232,171 +232,171 @@  discard block
 block discarded – undo
232 232
 
233 233
 
234 234
 
235
-    /**
236
-     * Child classes must declare the $_validator_config property using this method.
237
-     * See comments for $_validator_config for details on what it is used for.
238
-     *
239
-     * 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.
240
-     *
241
-     * @access protected
242
-     * @return void
243
-     */
244
-    abstract protected function _set_validator_config();
235
+	/**
236
+	 * Child classes must declare the $_validator_config property using this method.
237
+	 * See comments for $_validator_config for details on what it is used for.
238
+	 *
239
+	 * 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.
240
+	 *
241
+	 * @access protected
242
+	 * @return void
243
+	 */
244
+	abstract protected function _set_validator_config();
245 245
 
246 246
 
247 247
 
248 248
 
249 249
 
250 250
 
251
-    /**
252
-     * 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.
253
-     *
254
-     * @return bool|WP_Error
255
-     * @throw \Exception
256
-     */
257
-    abstract protected function _send_message();
251
+	/**
252
+	 * 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.
253
+	 *
254
+	 * @return bool|WP_Error
255
+	 * @throw \Exception
256
+	 */
257
+	abstract protected function _send_message();
258 258
 
259 259
 
260 260
 
261 261
 
262
-    /**
263
-     * We give you pretty previews of the messages!
264
-     * @return string html body for message content.
265
-     */
266
-    abstract protected function _preview();
262
+	/**
263
+	 * We give you pretty previews of the messages!
264
+	 * @return string html body for message content.
265
+	 */
266
+	abstract protected function _preview();
267 267
 
268 268
 
269 269
 
270 270
 
271
-    /**
272
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
273
-     *
274
-     * @since 4.5.0
275
-     *
276
-     * @return void
277
-     */
278
-    public function enqueue_scripts_styles()
279
-    {
280
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
281
-    }
271
+	/**
272
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
273
+	 *
274
+	 * @since 4.5.0
275
+	 *
276
+	 * @return void
277
+	 */
278
+	public function enqueue_scripts_styles()
279
+	{
280
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
281
+	}
282 282
 
283 283
 
284 284
 
285 285
 
286 286
 
287
-    /**
288
-     * This is used to indicate whether a messenger must be sent immediately or not.
289
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
290
-     * away.  The PDF messenger is similar.
291
-     *
292
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
293
-     *
294
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
295
-     *
296
-     * @since  4.9.0
297
-     * @return bool
298
-     */
299
-    public function send_now()
300
-    {
301
-        return false;
302
-    }
287
+	/**
288
+	 * This is used to indicate whether a messenger must be sent immediately or not.
289
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
290
+	 * away.  The PDF messenger is similar.
291
+	 *
292
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
293
+	 *
294
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
295
+	 *
296
+	 * @since  4.9.0
297
+	 * @return bool
298
+	 */
299
+	public function send_now()
300
+	{
301
+		return false;
302
+	}
303 303
 
304 304
 
305 305
 
306 306
 
307 307
 
308
-    /**
309
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
310
-     * Note: If the generated message is a for a preview, this value is ignored.
311
-     * @since 4.9.0
312
-     * @return bool
313
-     */
314
-    public function allow_empty_to_field()
315
-    {
316
-        return false;
317
-    }
308
+	/**
309
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
310
+	 * Note: If the generated message is a for a preview, this value is ignored.
311
+	 * @since 4.9.0
312
+	 * @return bool
313
+	 */
314
+	public function allow_empty_to_field()
315
+	{
316
+		return false;
317
+	}
318 318
 
319 319
 
320 320
 
321 321
 
322 322
 
323
-    /**
324
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
325
-     * @see property definition for info on how its formatted.
326
-     *
327
-     * @since 4.5.0;
328
-     * @return void
329
-     */
330
-    protected function _set_supports_labels()
331
-    {
332
-        $this->_set_supports_labels_defaults();
333
-    }
323
+	/**
324
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
325
+	 * @see property definition for info on how its formatted.
326
+	 *
327
+	 * @since 4.5.0;
328
+	 * @return void
329
+	 */
330
+	protected function _set_supports_labels()
331
+	{
332
+		$this->_set_supports_labels_defaults();
333
+	}
334 334
 
335 335
 
336 336
 
337 337
 
338 338
 
339
-    /**
340
-     * Sets the defaults for the _supports_labels property.
341
-     *
342
-     * @since 4.5.0
343
-     *
344
-     * @return void
345
-     */
346
-    private function _set_supports_labels_defaults()
347
-    {
348
-        $this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso');
349
-        $this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso');
350
-        $this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso');
339
+	/**
340
+	 * Sets the defaults for the _supports_labels property.
341
+	 *
342
+	 * @since 4.5.0
343
+	 *
344
+	 * @return void
345
+	 */
346
+	private function _set_supports_labels_defaults()
347
+	{
348
+		$this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso');
349
+		$this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso');
350
+		$this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso');
351 351
 
352
-        $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');
352
+		$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');
353 353
 
354
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
355
-    }
354
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
355
+	}
356 356
 
357 357
 
358 358
 
359 359
 
360 360
 
361
-    /**
362
-     * This returns the _supports_labels property.
363
-     *
364
-     * @since 4.5.0
365
-     *
366
-     * @return stdClass
367
-     */
368
-    public function get_supports_labels()
369
-    {
370
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
371
-            $this->_set_supports_labels_defaults();
372
-        }
373
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
374
-    }
361
+	/**
362
+	 * This returns the _supports_labels property.
363
+	 *
364
+	 * @since 4.5.0
365
+	 *
366
+	 * @return stdClass
367
+	 */
368
+	public function get_supports_labels()
369
+	{
370
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
371
+			$this->_set_supports_labels_defaults();
372
+		}
373
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
374
+	}
375 375
 
376 376
 
377 377
 
378 378
 
379
-    /**
380
-     * Used to retrieve a variation (typically the path/url to a css file)
381
-     *
382
-     * @since 4.5.0
383
-     *
384
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
385
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
386
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
387
-     * @param string                    $type What variation type to return. Default is 'main'.
388
-     * @param string               $variation What variation for the template pack
389
-     * @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.
390
-     *
391
-     * @return string                    path or url for the requested variation.
392
-     */
393
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
394
-    {
395
-        $this->_tmp_pack = $pack;
396
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
397
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
398
-        return $variation_path;
399
-    }
379
+	/**
380
+	 * Used to retrieve a variation (typically the path/url to a css file)
381
+	 *
382
+	 * @since 4.5.0
383
+	 *
384
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
385
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
386
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
387
+	 * @param string                    $type What variation type to return. Default is 'main'.
388
+	 * @param string               $variation What variation for the template pack
389
+	 * @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.
390
+	 *
391
+	 * @return string                    path or url for the requested variation.
392
+	 */
393
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
394
+	{
395
+		$this->_tmp_pack = $pack;
396
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
397
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
398
+		return $variation_path;
399
+	}
400 400
 
401 401
 
402 402
 
@@ -404,177 +404,177 @@  discard block
 block discarded – undo
404 404
 
405 405
 
406 406
 
407
-    /**
408
-     * This just returns the default message types associated with this messenger when it is first activated.
409
-     *
410
-     * @access public
411
-     * @return array
412
-     */
413
-    public function get_default_message_types()
414
-    {
415
-        $class = get_class($this);
407
+	/**
408
+	 * This just returns the default message types associated with this messenger when it is first activated.
409
+	 *
410
+	 * @access public
411
+	 * @return array
412
+	 */
413
+	public function get_default_message_types()
414
+	{
415
+		$class = get_class($this);
416 416
 
417
-        // messenger specific filter
418
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
417
+		// messenger specific filter
418
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
419 419
 
420
-        // all messengers filter
421
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
422
-        return $default_types;
423
-    }
420
+		// all messengers filter
421
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
422
+		return $default_types;
423
+	}
424 424
 
425 425
 
426 426
 
427 427
 
428
-    /**
429
-     * Returns the valid message types associated with this messenger.
430
-     *
431
-     * @since 4.5.0
432
-     *
433
-     * @return array
434
-     */
435
-    public function get_valid_message_types()
436
-    {
437
-        $class = get_class($this);
438
-
439
-        // messenger specific filter
440
-        // messenger specific filter
441
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
442
-
443
-        // all messengers filter
444
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
445
-        return $valid_types;
446
-    }
447
-
448
-
449
-
450
-
451
-
452
-    /**
453
-     * 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.
454
-     *
455
-     * @access public
456
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
457
-     */
458
-    public function set_validator_config($new_config)
459
-    {
460
-        $this->_validator_config = $new_config;
461
-    }
462
-
463
-
464
-
465
-
466
-    /**
467
-     * This returns the _validator_config property
468
-     *
469
-     * @access public
470
-     * @return array
471
-     */
472
-    public function get_validator_config()
473
-    {
474
-        $class = get_class($this);
475
-
476
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
477
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
478
-        return $config;
479
-    }
480
-
481
-
482
-
483
-
484
-    /**
485
-     * 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.
486
-     *
487
-     * @param string $page the slug of the EE admin page
488
-     * @param array $message_types an array of active message type objects
489
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
490
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
491
-     * @access public
492
-     * @return string content for page
493
-     */
494
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
495
-    {
496
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
497
-    }
498
-
499
-
500
-
501
-    /**
502
-     * @param $message_types
503
-     * @param array $extra
504
-     * @return mixed|string
505
-     */
506
-    protected function _get_admin_content_events_edit($message_types, $extra)
507
-    {
508
-        // defaults
509
-        $template_args = array();
510
-        $selector_rows = '';
511
-
512
-        // 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.
513
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
514
-
515
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
516
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
517
-
518
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
519
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
520
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
521
-        );
522
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
523
-            $event_id,
524
-            array(
525
-                'MTP_messenger' => $this->name,
526
-                'MTP_is_active' => true
527
-            )
528
-        );
529
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
530
-
531
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
532
-        foreach ($global_templates as $mtpgID => $mtpg) {
533
-            if ($mtpg instanceof EE_Message_Template_Group) {
534
-                // verify this message type is supposed to show on this page
535
-                $mtp_obj = $mtpg->message_type_obj();
536
-                if (! $mtp_obj instanceof EE_message_type) {
537
-                    continue;
538
-                }
539
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
540
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
541
-                    continue;
542
-                }
543
-                $select_values = array();
544
-                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
545
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
546
-                // 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.
547
-                if (! $mtpg->get('MTP_is_override')) {
548
-                    // any custom templates for this message type?
549
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
550
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
551
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
552
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
553
-                    }
554
-                }
555
-                // if there is no $default_value then we set it as the global
556
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
557
-                $edit_url_query_args = [
558
-                    'page' => 'espresso_messages',
559
-                    'action' => 'edit_message_template',
560
-                    'id' => $default_value,
561
-                    'evt_id' => $event_id
562
-                ];
563
-                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
564
-                $create_url_query_args = [
565
-                    'page' => 'espresso_messages',
566
-                    'action' => 'add_new_message_template',
567
-                    'GRP_ID' => $default_value
568
-                ];
569
-                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
570
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
571
-                $st_args['mt_slug'] = $mtpg->message_type();
572
-                $st_args['messenger_slug'] = $this->name;
573
-                $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');
574
-                // 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).
575
-                $st_args['create_button'] = $mtpg->get('MTP_is_override')
576
-                    ? ''
577
-                    : '
428
+	/**
429
+	 * Returns the valid message types associated with this messenger.
430
+	 *
431
+	 * @since 4.5.0
432
+	 *
433
+	 * @return array
434
+	 */
435
+	public function get_valid_message_types()
436
+	{
437
+		$class = get_class($this);
438
+
439
+		// messenger specific filter
440
+		// messenger specific filter
441
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
442
+
443
+		// all messengers filter
444
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
445
+		return $valid_types;
446
+	}
447
+
448
+
449
+
450
+
451
+
452
+	/**
453
+	 * 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.
454
+	 *
455
+	 * @access public
456
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
457
+	 */
458
+	public function set_validator_config($new_config)
459
+	{
460
+		$this->_validator_config = $new_config;
461
+	}
462
+
463
+
464
+
465
+
466
+	/**
467
+	 * This returns the _validator_config property
468
+	 *
469
+	 * @access public
470
+	 * @return array
471
+	 */
472
+	public function get_validator_config()
473
+	{
474
+		$class = get_class($this);
475
+
476
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
477
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
478
+		return $config;
479
+	}
480
+
481
+
482
+
483
+
484
+	/**
485
+	 * 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.
486
+	 *
487
+	 * @param string $page the slug of the EE admin page
488
+	 * @param array $message_types an array of active message type objects
489
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
490
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
491
+	 * @access public
492
+	 * @return string content for page
493
+	 */
494
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
495
+	{
496
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
497
+	}
498
+
499
+
500
+
501
+	/**
502
+	 * @param $message_types
503
+	 * @param array $extra
504
+	 * @return mixed|string
505
+	 */
506
+	protected function _get_admin_content_events_edit($message_types, $extra)
507
+	{
508
+		// defaults
509
+		$template_args = array();
510
+		$selector_rows = '';
511
+
512
+		// 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.
513
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
514
+
515
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
516
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
517
+
518
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
519
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
520
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
521
+		);
522
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
523
+			$event_id,
524
+			array(
525
+				'MTP_messenger' => $this->name,
526
+				'MTP_is_active' => true
527
+			)
528
+		);
529
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
530
+
531
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
532
+		foreach ($global_templates as $mtpgID => $mtpg) {
533
+			if ($mtpg instanceof EE_Message_Template_Group) {
534
+				// verify this message type is supposed to show on this page
535
+				$mtp_obj = $mtpg->message_type_obj();
536
+				if (! $mtp_obj instanceof EE_message_type) {
537
+					continue;
538
+				}
539
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
540
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
541
+					continue;
542
+				}
543
+				$select_values = array();
544
+				$select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
545
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
546
+				// 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.
547
+				if (! $mtpg->get('MTP_is_override')) {
548
+					// any custom templates for this message type?
549
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
550
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
551
+						$select_values[ $cmtpgID ] = $cmtpg->name();
552
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
553
+					}
554
+				}
555
+				// if there is no $default_value then we set it as the global
556
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
557
+				$edit_url_query_args = [
558
+					'page' => 'espresso_messages',
559
+					'action' => 'edit_message_template',
560
+					'id' => $default_value,
561
+					'evt_id' => $event_id
562
+				];
563
+				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
564
+				$create_url_query_args = [
565
+					'page' => 'espresso_messages',
566
+					'action' => 'add_new_message_template',
567
+					'GRP_ID' => $default_value
568
+				];
569
+				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
570
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
571
+				$st_args['mt_slug'] = $mtpg->message_type();
572
+				$st_args['messenger_slug'] = $this->name;
573
+				$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');
574
+				// 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).
575
+				$st_args['create_button'] = $mtpg->get('MTP_is_override')
576
+					? ''
577
+					: '
578 578
                     <a data-messenger="' . $this->name . '"
579 579
                        data-messagetype="' . $mtpg->message_type() . '" 
580 580
                        data-grpid="' . $default_value . '" 
@@ -584,18 +584,18 @@  discard block
 block discarded – undo
584 584
                     >
585 585
                         ' . esc_html__('Create New Custom', 'event_espresso') . '
586 586
                     </a>';
587
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(
588
-                    'ee_edit_messages',
589
-                    'espresso_messages_add_new_message_template'
590
-                )
591
-                    ? $st_args['create_button']
592
-                    : '';
593
-                $st_args['edit_button']   = EE_Registry::instance()->CAP->current_user_can(
594
-                    'ee_edit_message',
595
-                    'espresso_messages_edit_message_template',
596
-                    $mtpgID
597
-                )
598
-                    ? '
587
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(
588
+					'ee_edit_messages',
589
+					'espresso_messages_add_new_message_template'
590
+				)
591
+					? $st_args['create_button']
592
+					: '';
593
+				$st_args['edit_button']   = EE_Registry::instance()->CAP->current_user_can(
594
+					'ee_edit_message',
595
+					'espresso_messages_edit_message_template',
596
+					$mtpgID
597
+				)
598
+					? '
599 599
                     <a data-messagetype="' . $mtpg->message_type() . '" 
600 600
                        data-grpid="' . $default_value . '" 
601 601
                        target="_blank" 
@@ -604,322 +604,322 @@  discard block
 block discarded – undo
604 604
                     >
605 605
                         ' . esc_html__('Edit', 'event_espresso') . '
606 606
                     </a>'
607
-                    : '';
608
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
609
-            }
610
-        }
611
-
612
-        // if no selectors present then get out.
613
-        if (empty($selector_rows)) {
614
-            return '';
615
-        }
616
-
617
-        $template_args['selector_rows'] = $selector_rows;
618
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
619
-    }
620
-
621
-
622
-
623
-
624
-
625
-
626
-    /**
627
-     * get_template_fields
628
-     *
629
-     * @access public
630
-     * @return array $this->_template_fields
631
-     */
632
-    public function get_template_fields()
633
-    {
634
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
635
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
636
-        return $template_fields;
637
-    }
638
-
639
-
640
-
641
-
642
-    /** SETUP METHODS **/
643
-    /**
644
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
645
-     * @param string $item
646
-     * @param mixed $value
647
-     */
648
-    protected function _set_template_value($item, $value)
649
-    {
650
-        if (array_key_exists($item, $this->_template_fields)) {
651
-            $prop = '_' . $item;
652
-            $this->{$prop} = $value;
653
-        }
654
-    }
655
-
656
-    /**
657
-     * Sets up the message for sending.
658
-     *
659
-     * @param  EE_message $message the message object that contains details about the message.
660
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
661
-     *
662
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
663
-     *              added to EE_Error.
664
-     *              true = message sent successfully
665
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
666
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
667
-     *
668
-     * @throws SendMessageException
669
-     */
670
-    final public function send_message($message, EE_message_type $message_type)
671
-    {
672
-        try {
673
-            $this->_validate_and_setup($message);
674
-            $this->_incoming_message_type = $message_type;
675
-            $response = $this->_send_message();
676
-            if ($response instanceof WP_Error) {
677
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
678
-                $response = false;
679
-            }
680
-        } catch (\Exception $e) {
681
-            // convert to an instance of SendMessageException
682
-            throw new SendMessageException($e->getMessage());
683
-        }
684
-        return $response;
685
-    }
686
-
687
-
688
-
689
-    /**
690
-     * Sets up and returns message preview
691
-     * @param  EE_Message $message incoming message object
692
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
693
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
694
-     * @return string          return the message html content
695
-     */
696
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
697
-    {
698
-        $this->_validate_and_setup($message);
699
-
700
-        $this->_incoming_message_type = $message_type;
701
-
702
-        if ($send) {
703
-            // are we overriding any existing template fields?
704
-            $settings = apply_filters(
705
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
706
-                $this->get_existing_test_settings(),
707
-                $this,
708
-                $send,
709
-                $message,
710
-                $message_type
711
-            );
712
-            if (! empty($settings)) {
713
-                foreach ($settings as $field => $value) {
714
-                    $this->_set_template_value($field, $value);
715
-                }
716
-            }
717
-        }
718
-
719
-        // enqueue preview js so that any links/buttons on the page are disabled.
720
-        if (! $send) {
721
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
722
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
723
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
724
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
725
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
726
-        }
727
-
728
-        return $send ? $this->_send_message() : $this->_preview();
729
-    }
730
-
731
-
732
-
733
-
734
-    /**
735
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
736
-     *
737
-     * @since 4.5.0
738
-     *
739
-     * @return void
740
-     */
741
-    public function add_preview_script()
742
-    {
743
-        // error message
744
-        EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
745
-            __('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')
746
-        );
747
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
748
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
749
-        wp_enqueue_script('ee-messages-preview-js');
750
-    }
751
-
752
-
753
-
754
-
755
-    /**
756
-     * simply validates the incoming message object and then sets up the properties for the messenger
757
-     * @param  EE_Message $message
758
-     * @throws EE_Error
759
-     */
760
-    protected function _validate_and_setup(EE_Message $message)
761
-    {
762
-        $template_pack = $message->get_template_pack();
763
-        $variation = $message->get_template_pack_variation();
764
-
765
-        // verify we have the required template pack value on the $message object.
766
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
767
-            throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
768
-        }
769
-
770
-        $this->_tmp_pack = $template_pack;
771
-
772
-        $this->_variation = $variation ? $variation : 'default';
773
-
774
-        $template_fields = $this->get_template_fields();
775
-
776
-        foreach ($template_fields as $template => $value) {
777
-            if ($template !== 'extra') {
778
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
779
-                $message_template_value = $column_value ? $column_value : null;
780
-                $this->_set_template_value($template, $message_template_value);
781
-            }
782
-        }
783
-    }
784
-
785
-
786
-
787
-    /**
788
-     * Utility method for child classes to get the contents of a template file and return
789
-     *
790
-     * We're assuming the child messenger class has already setup template args!
791
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
792
-     * @return string
793
-     * @throws \EE_Error
794
-     */
795
-    protected function _get_main_template($preview = false)
796
-    {
797
-        $type = $preview ? 'preview' : 'main';
798
-
799
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
800
-
801
-        // check file exists and is readable
802
-        if (!is_readable($wrapper_template)) {
803
-            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));
804
-        }
805
-
806
-        // add message type to template args
807
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
808
-
809
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * set the _test_settings_fields property
816
-     *
817
-     * @access protected
818
-     * @return void
819
-     */
820
-    protected function _set_test_settings_fields()
821
-    {
822
-        $this->_test_settings_fields = array();
823
-    }
824
-
825
-
826
-
827
-    /**
828
-     * return the _test_settings_fields property
829
-     * @return array
830
-     */
831
-    public function get_test_settings_fields()
832
-    {
833
-        return $this->_test_settings_fields;
834
-    }
835
-
836
-
837
-
838
-
839
-    /**
840
-     * This just returns any existing test settings that might be saved in the database
841
-     *
842
-     * @access public
843
-     * @return array
844
-     */
845
-    public function get_existing_test_settings()
846
-    {
847
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
848
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
849
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
850
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
851
-    }
852
-
853
-
854
-
855
-    /**
856
-     * All this does is set the existing test settings (in the db) for the messenger
857
-     *
858
-     * @access public
859
-     * @param $settings
860
-     * @return bool success/fail
861
-     */
862
-    public function set_existing_test_settings($settings)
863
-    {
864
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
865
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
866
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
867
-        $existing[ $this->name ]['test_settings'] = $settings;
868
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
869
-    }
870
-
871
-
872
-
873
-    /**
874
-     * This just returns the field label for a given field setup in the _template_fields property.
875
-     *
876
-     * @since   4.3.0
877
-     *
878
-     * @param string $field The field to retrieve the label for
879
-     * @return string             The label
880
-     */
881
-    public function get_field_label($field)
882
-    {
883
-        // first let's see if the field requests is in the top level array.
884
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
885
-            return $this->_template[ $field ]['label'];
886
-        }
887
-
888
-        // 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.
889
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
890
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
891
-        }
892
-
893
-        // now it's possible this field may just be existing in any of the extra array items.
894
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
895
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
896
-                if (!is_array($subfields)) {
897
-                    continue;
898
-                }
899
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
900
-                    return $subfields[ $field ]['label'];
901
-                }
902
-            }
903
-        }
904
-
905
-        // if we made it here then there's no label set so let's just return the $field.
906
-        return $field;
907
-    }
908
-
909
-
910
-
911
-
912
-    /**
913
-     * 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).
914
-     *
915
-     * @since 4.5.0
916
-     *
917
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
918
-     *
919
-     * @return void
920
-     */
921
-    public function do_secondary_messenger_hooks($sending_messenger_name)
922
-    {
923
-        return;
924
-    }
607
+					: '';
608
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
609
+			}
610
+		}
611
+
612
+		// if no selectors present then get out.
613
+		if (empty($selector_rows)) {
614
+			return '';
615
+		}
616
+
617
+		$template_args['selector_rows'] = $selector_rows;
618
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
619
+	}
620
+
621
+
622
+
623
+
624
+
625
+
626
+	/**
627
+	 * get_template_fields
628
+	 *
629
+	 * @access public
630
+	 * @return array $this->_template_fields
631
+	 */
632
+	public function get_template_fields()
633
+	{
634
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
635
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
636
+		return $template_fields;
637
+	}
638
+
639
+
640
+
641
+
642
+	/** SETUP METHODS **/
643
+	/**
644
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
645
+	 * @param string $item
646
+	 * @param mixed $value
647
+	 */
648
+	protected function _set_template_value($item, $value)
649
+	{
650
+		if (array_key_exists($item, $this->_template_fields)) {
651
+			$prop = '_' . $item;
652
+			$this->{$prop} = $value;
653
+		}
654
+	}
655
+
656
+	/**
657
+	 * Sets up the message for sending.
658
+	 *
659
+	 * @param  EE_message $message the message object that contains details about the message.
660
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
661
+	 *
662
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
663
+	 *              added to EE_Error.
664
+	 *              true = message sent successfully
665
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
666
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
667
+	 *
668
+	 * @throws SendMessageException
669
+	 */
670
+	final public function send_message($message, EE_message_type $message_type)
671
+	{
672
+		try {
673
+			$this->_validate_and_setup($message);
674
+			$this->_incoming_message_type = $message_type;
675
+			$response = $this->_send_message();
676
+			if ($response instanceof WP_Error) {
677
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
678
+				$response = false;
679
+			}
680
+		} catch (\Exception $e) {
681
+			// convert to an instance of SendMessageException
682
+			throw new SendMessageException($e->getMessage());
683
+		}
684
+		return $response;
685
+	}
686
+
687
+
688
+
689
+	/**
690
+	 * Sets up and returns message preview
691
+	 * @param  EE_Message $message incoming message object
692
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
693
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
694
+	 * @return string          return the message html content
695
+	 */
696
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
697
+	{
698
+		$this->_validate_and_setup($message);
699
+
700
+		$this->_incoming_message_type = $message_type;
701
+
702
+		if ($send) {
703
+			// are we overriding any existing template fields?
704
+			$settings = apply_filters(
705
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
706
+				$this->get_existing_test_settings(),
707
+				$this,
708
+				$send,
709
+				$message,
710
+				$message_type
711
+			);
712
+			if (! empty($settings)) {
713
+				foreach ($settings as $field => $value) {
714
+					$this->_set_template_value($field, $value);
715
+				}
716
+			}
717
+		}
718
+
719
+		// enqueue preview js so that any links/buttons on the page are disabled.
720
+		if (! $send) {
721
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
722
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
723
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
724
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
725
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
726
+		}
727
+
728
+		return $send ? $this->_send_message() : $this->_preview();
729
+	}
730
+
731
+
732
+
733
+
734
+	/**
735
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
736
+	 *
737
+	 * @since 4.5.0
738
+	 *
739
+	 * @return void
740
+	 */
741
+	public function add_preview_script()
742
+	{
743
+		// error message
744
+		EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
745
+			__('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')
746
+		);
747
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
748
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
749
+		wp_enqueue_script('ee-messages-preview-js');
750
+	}
751
+
752
+
753
+
754
+
755
+	/**
756
+	 * simply validates the incoming message object and then sets up the properties for the messenger
757
+	 * @param  EE_Message $message
758
+	 * @throws EE_Error
759
+	 */
760
+	protected function _validate_and_setup(EE_Message $message)
761
+	{
762
+		$template_pack = $message->get_template_pack();
763
+		$variation = $message->get_template_pack_variation();
764
+
765
+		// verify we have the required template pack value on the $message object.
766
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
767
+			throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
768
+		}
769
+
770
+		$this->_tmp_pack = $template_pack;
771
+
772
+		$this->_variation = $variation ? $variation : 'default';
773
+
774
+		$template_fields = $this->get_template_fields();
775
+
776
+		foreach ($template_fields as $template => $value) {
777
+			if ($template !== 'extra') {
778
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
779
+				$message_template_value = $column_value ? $column_value : null;
780
+				$this->_set_template_value($template, $message_template_value);
781
+			}
782
+		}
783
+	}
784
+
785
+
786
+
787
+	/**
788
+	 * Utility method for child classes to get the contents of a template file and return
789
+	 *
790
+	 * We're assuming the child messenger class has already setup template args!
791
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
792
+	 * @return string
793
+	 * @throws \EE_Error
794
+	 */
795
+	protected function _get_main_template($preview = false)
796
+	{
797
+		$type = $preview ? 'preview' : 'main';
798
+
799
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
800
+
801
+		// check file exists and is readable
802
+		if (!is_readable($wrapper_template)) {
803
+			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));
804
+		}
805
+
806
+		// add message type to template args
807
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
808
+
809
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * set the _test_settings_fields property
816
+	 *
817
+	 * @access protected
818
+	 * @return void
819
+	 */
820
+	protected function _set_test_settings_fields()
821
+	{
822
+		$this->_test_settings_fields = array();
823
+	}
824
+
825
+
826
+
827
+	/**
828
+	 * return the _test_settings_fields property
829
+	 * @return array
830
+	 */
831
+	public function get_test_settings_fields()
832
+	{
833
+		return $this->_test_settings_fields;
834
+	}
835
+
836
+
837
+
838
+
839
+	/**
840
+	 * This just returns any existing test settings that might be saved in the database
841
+	 *
842
+	 * @access public
843
+	 * @return array
844
+	 */
845
+	public function get_existing_test_settings()
846
+	{
847
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
848
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
849
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
850
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
851
+	}
852
+
853
+
854
+
855
+	/**
856
+	 * All this does is set the existing test settings (in the db) for the messenger
857
+	 *
858
+	 * @access public
859
+	 * @param $settings
860
+	 * @return bool success/fail
861
+	 */
862
+	public function set_existing_test_settings($settings)
863
+	{
864
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
865
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
866
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
867
+		$existing[ $this->name ]['test_settings'] = $settings;
868
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
869
+	}
870
+
871
+
872
+
873
+	/**
874
+	 * This just returns the field label for a given field setup in the _template_fields property.
875
+	 *
876
+	 * @since   4.3.0
877
+	 *
878
+	 * @param string $field The field to retrieve the label for
879
+	 * @return string             The label
880
+	 */
881
+	public function get_field_label($field)
882
+	{
883
+		// first let's see if the field requests is in the top level array.
884
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
885
+			return $this->_template[ $field ]['label'];
886
+		}
887
+
888
+		// 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.
889
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
890
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
891
+		}
892
+
893
+		// now it's possible this field may just be existing in any of the extra array items.
894
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
895
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
896
+				if (!is_array($subfields)) {
897
+					continue;
898
+				}
899
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
900
+					return $subfields[ $field ]['label'];
901
+				}
902
+			}
903
+		}
904
+
905
+		// if we made it here then there's no label set so let's just return the $field.
906
+		return $field;
907
+	}
908
+
909
+
910
+
911
+
912
+	/**
913
+	 * 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).
914
+	 *
915
+	 * @since 4.5.0
916
+	 *
917
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
918
+	 *
919
+	 * @return void
920
+	 */
921
+	public function do_secondary_messenger_hooks($sending_messenger_name)
922
+	{
923
+		return;
924
+	}
925 925
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
         $class = get_class($this);
416 416
 
417 417
         // messenger specific filter
418
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
418
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
419 419
 
420 420
         // all messengers filter
421 421
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 
439 439
         // messenger specific filter
440 440
         // messenger specific filter
441
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
441
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
442 442
 
443 443
         // all messengers filter
444 444
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
     {
474 474
         $class = get_class($this);
475 475
 
476
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
476
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
477 477
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
478 478
         return $config;
479 479
     }
@@ -512,12 +512,12 @@  discard block
 block discarded – undo
512 512
         // 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.
513 513
         $event_id = isset($extra['event']) ? $extra['event'] : null;
514 514
 
515
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
516
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
515
+        $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
516
+        $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
517 517
 
518 518
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
519 519
         $global_templates = EEM_Message_Template_Group::instance()->get_all(
520
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
520
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
521 521
         );
522 522
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
523 523
             $event_id,
@@ -526,29 +526,29 @@  discard block
 block discarded – undo
526 526
                 'MTP_is_active' => true
527 527
             )
528 528
         );
529
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
529
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
530 530
 
531 531
         // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
532 532
         foreach ($global_templates as $mtpgID => $mtpg) {
533 533
             if ($mtpg instanceof EE_Message_Template_Group) {
534 534
                 // verify this message type is supposed to show on this page
535 535
                 $mtp_obj = $mtpg->message_type_obj();
536
-                if (! $mtp_obj instanceof EE_message_type) {
536
+                if ( ! $mtp_obj instanceof EE_message_type) {
537 537
                     continue;
538 538
                 }
539 539
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
540
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
540
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
541 541
                     continue;
542 542
                 }
543 543
                 $select_values = array();
544
-                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
544
+                $select_values[$mtpgID] = esc_html__('Global', 'event_espresso');
545 545
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
546 546
                 // 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.
547
-                if (! $mtpg->get('MTP_is_override')) {
547
+                if ( ! $mtpg->get('MTP_is_override')) {
548 548
                     // any custom templates for this message type?
549 549
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
550 550
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
551
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
551
+                        $select_values[$cmtpgID] = $cmtpg->name();
552 552
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
553 553
                     }
554 554
                 }
@@ -570,19 +570,19 @@  discard block
 block discarded – undo
570 570
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
571 571
                 $st_args['mt_slug'] = $mtpg->message_type();
572 572
                 $st_args['messenger_slug'] = $this->name;
573
-                $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');
573
+                $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');
574 574
                 // 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).
575 575
                 $st_args['create_button'] = $mtpg->get('MTP_is_override')
576 576
                     ? ''
577 577
                     : '
578
-                    <a data-messenger="' . $this->name . '"
579
-                       data-messagetype="' . $mtpg->message_type() . '" 
580
-                       data-grpid="' . $default_value . '" 
578
+                    <a data-messenger="' . $this->name.'"
579
+                       data-messagetype="' . $mtpg->message_type().'" 
580
+                       data-grpid="' . $default_value.'" 
581 581
                        target="_blank" 
582
-                       href="' . $create_url . '" 
582
+                       href="' . $create_url.'" 
583 583
                        class="button button--secondary button--small create-mtpg-button"
584 584
                     >
585
-                        ' . esc_html__('Create New Custom', 'event_espresso') . '
585
+                        ' . esc_html__('Create New Custom', 'event_espresso').'
586 586
                     </a>';
587 587
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(
588 588
                     'ee_edit_messages',
@@ -590,19 +590,19 @@  discard block
 block discarded – undo
590 590
                 )
591 591
                     ? $st_args['create_button']
592 592
                     : '';
593
-                $st_args['edit_button']   = EE_Registry::instance()->CAP->current_user_can(
593
+                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can(
594 594
                     'ee_edit_message',
595 595
                     'espresso_messages_edit_message_template',
596 596
                     $mtpgID
597 597
                 )
598 598
                     ? '
599
-                    <a data-messagetype="' . $mtpg->message_type() . '" 
600
-                       data-grpid="' . $default_value . '" 
599
+                    <a data-messagetype="' . $mtpg->message_type().'" 
600
+                       data-grpid="' . $default_value.'" 
601 601
                        target="_blank" 
602
-                       href="' . $edit_url . '" 
602
+                       href="' . $edit_url.'" 
603 603
                        class="button button--secondary button--small edit-mtpg-button"
604 604
                     >
605
-                        ' . esc_html__('Edit', 'event_espresso') . '
605
+                        ' . esc_html__('Edit', 'event_espresso').'
606 606
                     </a>'
607 607
                     : '';
608 608
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
      */
632 632
     public function get_template_fields()
633 633
     {
634
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
634
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
635 635
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
636 636
         return $template_fields;
637 637
     }
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
     protected function _set_template_value($item, $value)
649 649
     {
650 650
         if (array_key_exists($item, $this->_template_fields)) {
651
-            $prop = '_' . $item;
651
+            $prop = '_'.$item;
652 652
             $this->{$prop} = $value;
653 653
         }
654 654
     }
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
                 $message,
710 710
                 $message_type
711 711
             );
712
-            if (! empty($settings)) {
712
+            if ( ! empty($settings)) {
713 713
                 foreach ($settings as $field => $value) {
714 714
                     $this->_set_template_value($field, $value);
715 715
                 }
@@ -717,12 +717,12 @@  discard block
 block discarded – undo
717 717
         }
718 718
 
719 719
         // enqueue preview js so that any links/buttons on the page are disabled.
720
-        if (! $send) {
720
+        if ( ! $send) {
721 721
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
722 722
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
723
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
724
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
725
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
723
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
724
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
725
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
726 726
         }
727 727
 
728 728
         return $send ? $this->_send_message() : $this->_preview();
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
         EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
745 745
             __('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')
746 746
         );
747
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
747
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
748 748
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
749 749
         wp_enqueue_script('ee-messages-preview-js');
750 750
     }
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
         $variation = $message->get_template_pack_variation();
764 764
 
765 765
         // verify we have the required template pack value on the $message object.
766
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
766
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
767 767
             throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
768 768
         }
769 769
 
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 
776 776
         foreach ($template_fields as $template => $value) {
777 777
             if ($template !== 'extra') {
778
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
778
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
779 779
                 $message_template_value = $column_value ? $column_value : null;
780 780
                 $this->_set_template_value($template, $message_template_value);
781 781
             }
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
800 800
 
801 801
         // check file exists and is readable
802
-        if (!is_readable($wrapper_template)) {
802
+        if ( ! is_readable($wrapper_template)) {
803 803
             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));
804 804
         }
805 805
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
848 848
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
849 849
         $settings = $Message_Resource_Manager->get_active_messengers_option();
850
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
850
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
851 851
     }
852 852
 
853 853
 
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
865 865
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
866 866
         $existing = $Message_Resource_Manager->get_active_messengers_option();
867
-        $existing[ $this->name ]['test_settings'] = $settings;
867
+        $existing[$this->name]['test_settings'] = $settings;
868 868
         return $Message_Resource_Manager->update_active_messengers_option($existing);
869 869
     }
870 870
 
@@ -881,23 +881,23 @@  discard block
 block discarded – undo
881 881
     public function get_field_label($field)
882 882
     {
883 883
         // first let's see if the field requests is in the top level array.
884
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
885
-            return $this->_template[ $field ]['label'];
884
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
885
+            return $this->_template[$field]['label'];
886 886
         }
887 887
 
888 888
         // 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.
889
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
890
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
889
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
890
+            return $this->_template_fields['extra'][$field]['main']['label'];
891 891
         }
892 892
 
893 893
         // now it's possible this field may just be existing in any of the extra array items.
894
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
894
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
895 895
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
896
-                if (!is_array($subfields)) {
896
+                if ( ! is_array($subfields)) {
897 897
                     continue;
898 898
                 }
899
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
900
-                    return $subfields[ $field ]['label'];
899
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
900
+                    return $subfields[$field]['label'];
901 901
                 }
902 902
             }
903 903
         }
Please login to merge, or discard this patch.