Completed
Branch dev (0d2644)
by
unknown
07:54 queued 10s
created
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +770 added lines, -770 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,199 +404,199 @@  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
-        $msg_type_status_map = [
532
-            'payment' => 'PAP',
533
-            'payment_refund' => 'PRF',
534
-            'payment_reminder' => 'PPN',
535
-            'registration' => 'RAP',
536
-            'not_approved_registration' => 'RNA',
537
-            'pending_approval' => 'RPP',
538
-            'payment_declined' => 'PDC',
539
-            'declined_registration' => 'RDC',
540
-            'cancelled_registration' => 'RCN',
541
-            'payment_failed' => 'PFL',
542
-            'payment_cancelled' => 'PCN',
543
-        ];
544
-
545
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
546
-        foreach ($global_templates as $mtpgID => $mtpg) {
547
-            if ($mtpg instanceof EE_Message_Template_Group) {
548
-                // verify this message type is supposed to show on this page
549
-                $mtp_obj = $mtpg->message_type_obj();
550
-                if (! $mtp_obj instanceof EE_message_type) {
551
-                    continue;
552
-                }
553
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
554
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
555
-                    continue;
556
-                }
557
-                $select_values = array();
558
-                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
559
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
560
-                // 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.
561
-                if (! $mtpg->get('MTP_is_override')) {
562
-                    // any custom templates for this message type?
563
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
564
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
565
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
566
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
567
-                    }
568
-                }
569
-                // if there is no $default_value then we set it as the global
570
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
571
-                $edit_url_query_args = [
572
-                    'page' => 'espresso_messages',
573
-                    'action' => 'edit_message_template',
574
-                    'id' => $default_value,
575
-                    'evt_id' => $event_id
576
-                ];
577
-                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
578
-                $create_url_query_args = [
579
-                    'page' => 'espresso_messages',
580
-                    'action' => 'add_new_message_template',
581
-                    'GRP_ID' => $default_value
582
-                ];
583
-                $mt_slug = $mtpg->message_type();
584
-                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
585
-                $st_args['mtpgID'] = $mtpgID;
586
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
587
-                $st_args['mt_slug'] = $mt_slug;
588
-                $st_args['messenger_slug'] = $this->name;
589
-                $st_args['status_code'] = $msg_type_status_map[$mt_slug] ?? '';
590
-                $st_args['selector'] = EEH_Form_Fields::select_input(
591
-                    'event_message_templates_relation[' . $mtpgID . ']',
592
-                    $select_values, $default_value,
593
-                    'data-messenger="' . $this->name . '" data-messagetype="' . $mt_slug . '"',
594
-                    'message-template-selector'
595
-                );
596
-                // 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).
597
-                $st_args['create_button'] = $mtpg->get('MTP_is_override')
598
-                    ? ''
599
-                    : '
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
+		$msg_type_status_map = [
532
+			'payment' => 'PAP',
533
+			'payment_refund' => 'PRF',
534
+			'payment_reminder' => 'PPN',
535
+			'registration' => 'RAP',
536
+			'not_approved_registration' => 'RNA',
537
+			'pending_approval' => 'RPP',
538
+			'payment_declined' => 'PDC',
539
+			'declined_registration' => 'RDC',
540
+			'cancelled_registration' => 'RCN',
541
+			'payment_failed' => 'PFL',
542
+			'payment_cancelled' => 'PCN',
543
+		];
544
+
545
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
546
+		foreach ($global_templates as $mtpgID => $mtpg) {
547
+			if ($mtpg instanceof EE_Message_Template_Group) {
548
+				// verify this message type is supposed to show on this page
549
+				$mtp_obj = $mtpg->message_type_obj();
550
+				if (! $mtp_obj instanceof EE_message_type) {
551
+					continue;
552
+				}
553
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
554
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
555
+					continue;
556
+				}
557
+				$select_values = array();
558
+				$select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
559
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
560
+				// 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.
561
+				if (! $mtpg->get('MTP_is_override')) {
562
+					// any custom templates for this message type?
563
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
564
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
565
+						$select_values[ $cmtpgID ] = $cmtpg->name();
566
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
567
+					}
568
+				}
569
+				// if there is no $default_value then we set it as the global
570
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
571
+				$edit_url_query_args = [
572
+					'page' => 'espresso_messages',
573
+					'action' => 'edit_message_template',
574
+					'id' => $default_value,
575
+					'evt_id' => $event_id
576
+				];
577
+				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
578
+				$create_url_query_args = [
579
+					'page' => 'espresso_messages',
580
+					'action' => 'add_new_message_template',
581
+					'GRP_ID' => $default_value
582
+				];
583
+				$mt_slug = $mtpg->message_type();
584
+				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
585
+				$st_args['mtpgID'] = $mtpgID;
586
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
587
+				$st_args['mt_slug'] = $mt_slug;
588
+				$st_args['messenger_slug'] = $this->name;
589
+				$st_args['status_code'] = $msg_type_status_map[$mt_slug] ?? '';
590
+				$st_args['selector'] = EEH_Form_Fields::select_input(
591
+					'event_message_templates_relation[' . $mtpgID . ']',
592
+					$select_values, $default_value,
593
+					'data-messenger="' . $this->name . '" data-messagetype="' . $mt_slug . '"',
594
+					'message-template-selector'
595
+				);
596
+				// 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).
597
+				$st_args['create_button'] = $mtpg->get('MTP_is_override')
598
+					? ''
599
+					: '
600 600
                     <a data-messenger="' . $this->name . '"
601 601
                        data-messagetype="' . $mt_slug . '" 
602 602
                        data-grpid="' . $default_value . '" 
@@ -606,18 +606,18 @@  discard block
 block discarded – undo
606 606
                     >
607 607
                         ' . esc_html__('Create New Custom', 'event_espresso') . '
608 608
                     </a>';
609
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(
610
-                    'ee_edit_messages',
611
-                    'espresso_messages_add_new_message_template'
612
-                )
613
-                    ? $st_args['create_button']
614
-                    : '';
615
-                $st_args['edit_button']   = EE_Registry::instance()->CAP->current_user_can(
616
-                    'ee_edit_message',
617
-                    'espresso_messages_edit_message_template',
618
-                    $mtpgID
619
-                )
620
-                    ? '
609
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(
610
+					'ee_edit_messages',
611
+					'espresso_messages_add_new_message_template'
612
+				)
613
+					? $st_args['create_button']
614
+					: '';
615
+				$st_args['edit_button']   = EE_Registry::instance()->CAP->current_user_can(
616
+					'ee_edit_message',
617
+					'espresso_messages_edit_message_template',
618
+					$mtpgID
619
+				)
620
+					? '
621 621
                     <a data-messagetype="' . $mt_slug . '" 
622 622
                        data-grpid="' . $default_value . '" 
623 623
                        target="_blank" 
@@ -626,322 +626,322 @@  discard block
 block discarded – undo
626 626
                     >
627 627
                         ' . esc_html__('Edit', 'event_espresso') . '
628 628
                     </a>'
629
-                    : '';
630
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
631
-            }
632
-        }
633
-
634
-        // if no selectors present then get out.
635
-        if (empty($selector_rows)) {
636
-            return '';
637
-        }
638
-
639
-        $template_args['selector_rows'] = $selector_rows;
640
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
641
-    }
642
-
643
-
644
-
645
-
646
-
647
-
648
-    /**
649
-     * get_template_fields
650
-     *
651
-     * @access public
652
-     * @return array $this->_template_fields
653
-     */
654
-    public function get_template_fields()
655
-    {
656
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
657
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
658
-        return $template_fields;
659
-    }
660
-
661
-
662
-
663
-
664
-    /** SETUP METHODS **/
665
-    /**
666
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
667
-     * @param string $item
668
-     * @param mixed $value
669
-     */
670
-    protected function _set_template_value($item, $value)
671
-    {
672
-        if (array_key_exists($item, $this->_template_fields)) {
673
-            $prop = '_' . $item;
674
-            $this->{$prop} = $value;
675
-        }
676
-    }
677
-
678
-    /**
679
-     * Sets up the message for sending.
680
-     *
681
-     * @param  EE_message $message the message object that contains details about the message.
682
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
683
-     *
684
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
685
-     *              added to EE_Error.
686
-     *              true = message sent successfully
687
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
688
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
689
-     *
690
-     * @throws SendMessageException
691
-     */
692
-    final public function send_message($message, EE_message_type $message_type)
693
-    {
694
-        try {
695
-            $this->_validate_and_setup($message);
696
-            $this->_incoming_message_type = $message_type;
697
-            $response = $this->_send_message();
698
-            if ($response instanceof WP_Error) {
699
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
700
-                $response = false;
701
-            }
702
-        } catch (\Exception $e) {
703
-            // convert to an instance of SendMessageException
704
-            throw new SendMessageException($e->getMessage());
705
-        }
706
-        return $response;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * Sets up and returns message preview
713
-     * @param  EE_Message $message incoming message object
714
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
715
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
716
-     * @return string          return the message html content
717
-     */
718
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
719
-    {
720
-        $this->_validate_and_setup($message);
721
-
722
-        $this->_incoming_message_type = $message_type;
723
-
724
-        if ($send) {
725
-            // are we overriding any existing template fields?
726
-            $settings = apply_filters(
727
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
728
-                $this->get_existing_test_settings(),
729
-                $this,
730
-                $send,
731
-                $message,
732
-                $message_type
733
-            );
734
-            if (! empty($settings)) {
735
-                foreach ($settings as $field => $value) {
736
-                    $this->_set_template_value($field, $value);
737
-                }
738
-            }
739
-        }
740
-
741
-        // enqueue preview js so that any links/buttons on the page are disabled.
742
-        if (! $send) {
743
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
744
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
745
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
746
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
747
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
748
-        }
749
-
750
-        return $send ? $this->_send_message() : $this->_preview();
751
-    }
752
-
753
-
754
-
755
-
756
-    /**
757
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
758
-     *
759
-     * @since 4.5.0
760
-     *
761
-     * @return void
762
-     */
763
-    public function add_preview_script()
764
-    {
765
-        // error message
766
-        EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
767
-            __('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')
768
-        );
769
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
770
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
771
-        wp_enqueue_script('ee-messages-preview-js');
772
-    }
773
-
774
-
775
-
776
-
777
-    /**
778
-     * simply validates the incoming message object and then sets up the properties for the messenger
779
-     * @param  EE_Message $message
780
-     * @throws EE_Error
781
-     */
782
-    protected function _validate_and_setup(EE_Message $message)
783
-    {
784
-        $template_pack = $message->get_template_pack();
785
-        $variation = $message->get_template_pack_variation();
786
-
787
-        // verify we have the required template pack value on the $message object.
788
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
789
-            throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
790
-        }
791
-
792
-        $this->_tmp_pack = $template_pack;
793
-
794
-        $this->_variation = $variation ? $variation : 'default';
795
-
796
-        $template_fields = $this->get_template_fields();
797
-
798
-        foreach ($template_fields as $template => $value) {
799
-            if ($template !== 'extra') {
800
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
801
-                $message_template_value = $column_value ? $column_value : null;
802
-                $this->_set_template_value($template, $message_template_value);
803
-            }
804
-        }
805
-    }
806
-
807
-
808
-
809
-    /**
810
-     * Utility method for child classes to get the contents of a template file and return
811
-     *
812
-     * We're assuming the child messenger class has already setup template args!
813
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
814
-     * @return string
815
-     * @throws \EE_Error
816
-     */
817
-    protected function _get_main_template($preview = false)
818
-    {
819
-        $type = $preview ? 'preview' : 'main';
820
-
821
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
822
-
823
-        // check file exists and is readable
824
-        if (!is_readable($wrapper_template)) {
825
-            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));
826
-        }
827
-
828
-        // add message type to template args
829
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
830
-
831
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
832
-    }
833
-
834
-
835
-
836
-    /**
837
-     * set the _test_settings_fields property
838
-     *
839
-     * @access protected
840
-     * @return void
841
-     */
842
-    protected function _set_test_settings_fields()
843
-    {
844
-        $this->_test_settings_fields = array();
845
-    }
846
-
847
-
848
-
849
-    /**
850
-     * return the _test_settings_fields property
851
-     * @return array
852
-     */
853
-    public function get_test_settings_fields()
854
-    {
855
-        return $this->_test_settings_fields;
856
-    }
857
-
858
-
859
-
860
-
861
-    /**
862
-     * This just returns any existing test settings that might be saved in the database
863
-     *
864
-     * @access public
865
-     * @return array
866
-     */
867
-    public function get_existing_test_settings()
868
-    {
869
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
870
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
871
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
872
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
873
-    }
874
-
875
-
876
-
877
-    /**
878
-     * All this does is set the existing test settings (in the db) for the messenger
879
-     *
880
-     * @access public
881
-     * @param $settings
882
-     * @return bool success/fail
883
-     */
884
-    public function set_existing_test_settings($settings)
885
-    {
886
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
887
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
888
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
889
-        $existing[ $this->name ]['test_settings'] = $settings;
890
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
891
-    }
892
-
893
-
894
-
895
-    /**
896
-     * This just returns the field label for a given field setup in the _template_fields property.
897
-     *
898
-     * @since   4.3.0
899
-     *
900
-     * @param string $field The field to retrieve the label for
901
-     * @return string             The label
902
-     */
903
-    public function get_field_label($field)
904
-    {
905
-        // first let's see if the field requests is in the top level array.
906
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
907
-            return $this->_template[ $field ]['label'];
908
-        }
909
-
910
-        // 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.
911
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
912
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
913
-        }
914
-
915
-        // now it's possible this field may just be existing in any of the extra array items.
916
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
917
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
918
-                if (!is_array($subfields)) {
919
-                    continue;
920
-                }
921
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
922
-                    return $subfields[ $field ]['label'];
923
-                }
924
-            }
925
-        }
926
-
927
-        // if we made it here then there's no label set so let's just return the $field.
928
-        return $field;
929
-    }
930
-
931
-
932
-
933
-
934
-    /**
935
-     * 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).
936
-     *
937
-     * @since 4.5.0
938
-     *
939
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
940
-     *
941
-     * @return void
942
-     */
943
-    public function do_secondary_messenger_hooks($sending_messenger_name)
944
-    {
945
-        return;
946
-    }
629
+					: '';
630
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
631
+			}
632
+		}
633
+
634
+		// if no selectors present then get out.
635
+		if (empty($selector_rows)) {
636
+			return '';
637
+		}
638
+
639
+		$template_args['selector_rows'] = $selector_rows;
640
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
641
+	}
642
+
643
+
644
+
645
+
646
+
647
+
648
+	/**
649
+	 * get_template_fields
650
+	 *
651
+	 * @access public
652
+	 * @return array $this->_template_fields
653
+	 */
654
+	public function get_template_fields()
655
+	{
656
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
657
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
658
+		return $template_fields;
659
+	}
660
+
661
+
662
+
663
+
664
+	/** SETUP METHODS **/
665
+	/**
666
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
667
+	 * @param string $item
668
+	 * @param mixed $value
669
+	 */
670
+	protected function _set_template_value($item, $value)
671
+	{
672
+		if (array_key_exists($item, $this->_template_fields)) {
673
+			$prop = '_' . $item;
674
+			$this->{$prop} = $value;
675
+		}
676
+	}
677
+
678
+	/**
679
+	 * Sets up the message for sending.
680
+	 *
681
+	 * @param  EE_message $message the message object that contains details about the message.
682
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
683
+	 *
684
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
685
+	 *              added to EE_Error.
686
+	 *              true = message sent successfully
687
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
688
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
689
+	 *
690
+	 * @throws SendMessageException
691
+	 */
692
+	final public function send_message($message, EE_message_type $message_type)
693
+	{
694
+		try {
695
+			$this->_validate_and_setup($message);
696
+			$this->_incoming_message_type = $message_type;
697
+			$response = $this->_send_message();
698
+			if ($response instanceof WP_Error) {
699
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
700
+				$response = false;
701
+			}
702
+		} catch (\Exception $e) {
703
+			// convert to an instance of SendMessageException
704
+			throw new SendMessageException($e->getMessage());
705
+		}
706
+		return $response;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * Sets up and returns message preview
713
+	 * @param  EE_Message $message incoming message object
714
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
715
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
716
+	 * @return string          return the message html content
717
+	 */
718
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
719
+	{
720
+		$this->_validate_and_setup($message);
721
+
722
+		$this->_incoming_message_type = $message_type;
723
+
724
+		if ($send) {
725
+			// are we overriding any existing template fields?
726
+			$settings = apply_filters(
727
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
728
+				$this->get_existing_test_settings(),
729
+				$this,
730
+				$send,
731
+				$message,
732
+				$message_type
733
+			);
734
+			if (! empty($settings)) {
735
+				foreach ($settings as $field => $value) {
736
+					$this->_set_template_value($field, $value);
737
+				}
738
+			}
739
+		}
740
+
741
+		// enqueue preview js so that any links/buttons on the page are disabled.
742
+		if (! $send) {
743
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
744
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
745
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
746
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
747
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
748
+		}
749
+
750
+		return $send ? $this->_send_message() : $this->_preview();
751
+	}
752
+
753
+
754
+
755
+
756
+	/**
757
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
758
+	 *
759
+	 * @since 4.5.0
760
+	 *
761
+	 * @return void
762
+	 */
763
+	public function add_preview_script()
764
+	{
765
+		// error message
766
+		EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
767
+			__('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')
768
+		);
769
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
770
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
771
+		wp_enqueue_script('ee-messages-preview-js');
772
+	}
773
+
774
+
775
+
776
+
777
+	/**
778
+	 * simply validates the incoming message object and then sets up the properties for the messenger
779
+	 * @param  EE_Message $message
780
+	 * @throws EE_Error
781
+	 */
782
+	protected function _validate_and_setup(EE_Message $message)
783
+	{
784
+		$template_pack = $message->get_template_pack();
785
+		$variation = $message->get_template_pack_variation();
786
+
787
+		// verify we have the required template pack value on the $message object.
788
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
789
+			throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
790
+		}
791
+
792
+		$this->_tmp_pack = $template_pack;
793
+
794
+		$this->_variation = $variation ? $variation : 'default';
795
+
796
+		$template_fields = $this->get_template_fields();
797
+
798
+		foreach ($template_fields as $template => $value) {
799
+			if ($template !== 'extra') {
800
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
801
+				$message_template_value = $column_value ? $column_value : null;
802
+				$this->_set_template_value($template, $message_template_value);
803
+			}
804
+		}
805
+	}
806
+
807
+
808
+
809
+	/**
810
+	 * Utility method for child classes to get the contents of a template file and return
811
+	 *
812
+	 * We're assuming the child messenger class has already setup template args!
813
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
814
+	 * @return string
815
+	 * @throws \EE_Error
816
+	 */
817
+	protected function _get_main_template($preview = false)
818
+	{
819
+		$type = $preview ? 'preview' : 'main';
820
+
821
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
822
+
823
+		// check file exists and is readable
824
+		if (!is_readable($wrapper_template)) {
825
+			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));
826
+		}
827
+
828
+		// add message type to template args
829
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
830
+
831
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
832
+	}
833
+
834
+
835
+
836
+	/**
837
+	 * set the _test_settings_fields property
838
+	 *
839
+	 * @access protected
840
+	 * @return void
841
+	 */
842
+	protected function _set_test_settings_fields()
843
+	{
844
+		$this->_test_settings_fields = array();
845
+	}
846
+
847
+
848
+
849
+	/**
850
+	 * return the _test_settings_fields property
851
+	 * @return array
852
+	 */
853
+	public function get_test_settings_fields()
854
+	{
855
+		return $this->_test_settings_fields;
856
+	}
857
+
858
+
859
+
860
+
861
+	/**
862
+	 * This just returns any existing test settings that might be saved in the database
863
+	 *
864
+	 * @access public
865
+	 * @return array
866
+	 */
867
+	public function get_existing_test_settings()
868
+	{
869
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
870
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
871
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
872
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
873
+	}
874
+
875
+
876
+
877
+	/**
878
+	 * All this does is set the existing test settings (in the db) for the messenger
879
+	 *
880
+	 * @access public
881
+	 * @param $settings
882
+	 * @return bool success/fail
883
+	 */
884
+	public function set_existing_test_settings($settings)
885
+	{
886
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
887
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
888
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
889
+		$existing[ $this->name ]['test_settings'] = $settings;
890
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
891
+	}
892
+
893
+
894
+
895
+	/**
896
+	 * This just returns the field label for a given field setup in the _template_fields property.
897
+	 *
898
+	 * @since   4.3.0
899
+	 *
900
+	 * @param string $field The field to retrieve the label for
901
+	 * @return string             The label
902
+	 */
903
+	public function get_field_label($field)
904
+	{
905
+		// first let's see if the field requests is in the top level array.
906
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
907
+			return $this->_template[ $field ]['label'];
908
+		}
909
+
910
+		// 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.
911
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
912
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
913
+		}
914
+
915
+		// now it's possible this field may just be existing in any of the extra array items.
916
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
917
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
918
+				if (!is_array($subfields)) {
919
+					continue;
920
+				}
921
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
922
+					return $subfields[ $field ]['label'];
923
+				}
924
+			}
925
+		}
926
+
927
+		// if we made it here then there's no label set so let's just return the $field.
928
+		return $field;
929
+	}
930
+
931
+
932
+
933
+
934
+	/**
935
+	 * 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).
936
+	 *
937
+	 * @since 4.5.0
938
+	 *
939
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
940
+	 *
941
+	 * @return void
942
+	 */
943
+	public function do_secondary_messenger_hooks($sending_messenger_name)
944
+	{
945
+		return;
946
+	}
947 947
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 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,7 +526,7 @@  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
         $msg_type_status_map = [
532 532
             'payment' => 'PAP',
@@ -547,22 +547,22 @@  discard block
 block discarded – undo
547 547
             if ($mtpg instanceof EE_Message_Template_Group) {
548 548
                 // verify this message type is supposed to show on this page
549 549
                 $mtp_obj = $mtpg->message_type_obj();
550
-                if (! $mtp_obj instanceof EE_message_type) {
550
+                if ( ! $mtp_obj instanceof EE_message_type) {
551 551
                     continue;
552 552
                 }
553 553
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
554
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
554
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
555 555
                     continue;
556 556
                 }
557 557
                 $select_values = array();
558
-                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso');
558
+                $select_values[$mtpgID] = esc_html__('Global', 'event_espresso');
559 559
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
560 560
                 // 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.
561
-                if (! $mtpg->get('MTP_is_override')) {
561
+                if ( ! $mtpg->get('MTP_is_override')) {
562 562
                     // any custom templates for this message type?
563 563
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
564 564
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
565
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
565
+                        $select_values[$cmtpgID] = $cmtpg->name();
566 566
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
567 567
                     }
568 568
                 }
@@ -588,23 +588,23 @@  discard block
 block discarded – undo
588 588
                 $st_args['messenger_slug'] = $this->name;
589 589
                 $st_args['status_code'] = $msg_type_status_map[$mt_slug] ?? '';
590 590
                 $st_args['selector'] = EEH_Form_Fields::select_input(
591
-                    'event_message_templates_relation[' . $mtpgID . ']',
591
+                    'event_message_templates_relation['.$mtpgID.']',
592 592
                     $select_values, $default_value,
593
-                    'data-messenger="' . $this->name . '" data-messagetype="' . $mt_slug . '"',
593
+                    'data-messenger="'.$this->name.'" data-messagetype="'.$mt_slug.'"',
594 594
                     'message-template-selector'
595 595
                 );
596 596
                 // 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).
597 597
                 $st_args['create_button'] = $mtpg->get('MTP_is_override')
598 598
                     ? ''
599 599
                     : '
600
-                    <a data-messenger="' . $this->name . '"
601
-                       data-messagetype="' . $mt_slug . '" 
602
-                       data-grpid="' . $default_value . '" 
600
+                    <a data-messenger="' . $this->name.'"
601
+                       data-messagetype="' . $mt_slug.'" 
602
+                       data-grpid="' . $default_value.'" 
603 603
                        target="_blank" 
604
-                       href="' . $create_url . '" 
604
+                       href="' . $create_url.'" 
605 605
                        class="button button--secondary button--tiny create-mtpg-button"
606 606
                     >
607
-                        ' . esc_html__('Create New Custom', 'event_espresso') . '
607
+                        ' . esc_html__('Create New Custom', 'event_espresso').'
608 608
                     </a>';
609 609
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(
610 610
                     'ee_edit_messages',
@@ -612,19 +612,19 @@  discard block
 block discarded – undo
612 612
                 )
613 613
                     ? $st_args['create_button']
614 614
                     : '';
615
-                $st_args['edit_button']   = EE_Registry::instance()->CAP->current_user_can(
615
+                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can(
616 616
                     'ee_edit_message',
617 617
                     'espresso_messages_edit_message_template',
618 618
                     $mtpgID
619 619
                 )
620 620
                     ? '
621
-                    <a data-messagetype="' . $mt_slug . '" 
622
-                       data-grpid="' . $default_value . '" 
621
+                    <a data-messagetype="' . $mt_slug.'" 
622
+                       data-grpid="' . $default_value.'" 
623 623
                        target="_blank" 
624
-                       href="' . $edit_url . '" 
624
+                       href="' . $edit_url.'" 
625 625
                        class="button button--secondary button--tiny edit-mtpg-button"
626 626
                     >
627
-                        ' . esc_html__('Edit', 'event_espresso') . '
627
+                        ' . esc_html__('Edit', 'event_espresso').'
628 628
                     </a>'
629 629
                     : '';
630 630
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
      */
654 654
     public function get_template_fields()
655 655
     {
656
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
656
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
657 657
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
658 658
         return $template_fields;
659 659
     }
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
     protected function _set_template_value($item, $value)
671 671
     {
672 672
         if (array_key_exists($item, $this->_template_fields)) {
673
-            $prop = '_' . $item;
673
+            $prop = '_'.$item;
674 674
             $this->{$prop} = $value;
675 675
         }
676 676
     }
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
                 $message,
732 732
                 $message_type
733 733
             );
734
-            if (! empty($settings)) {
734
+            if ( ! empty($settings)) {
735 735
                 foreach ($settings as $field => $value) {
736 736
                     $this->_set_template_value($field, $value);
737 737
                 }
@@ -739,12 +739,12 @@  discard block
 block discarded – undo
739 739
         }
740 740
 
741 741
         // enqueue preview js so that any links/buttons on the page are disabled.
742
-        if (! $send) {
742
+        if ( ! $send) {
743 743
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
744 744
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
745
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
746
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
747
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
745
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
746
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
747
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
748 748
         }
749 749
 
750 750
         return $send ? $this->_send_message() : $this->_preview();
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
         EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
767 767
             __('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')
768 768
         );
769
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
769
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
770 770
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
771 771
         wp_enqueue_script('ee-messages-preview-js');
772 772
     }
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
         $variation = $message->get_template_pack_variation();
786 786
 
787 787
         // verify we have the required template pack value on the $message object.
788
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
788
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
789 789
             throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
790 790
         }
791 791
 
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 
798 798
         foreach ($template_fields as $template => $value) {
799 799
             if ($template !== 'extra') {
800
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
800
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
801 801
                 $message_template_value = $column_value ? $column_value : null;
802 802
                 $this->_set_template_value($template, $message_template_value);
803 803
             }
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
822 822
 
823 823
         // check file exists and is readable
824
-        if (!is_readable($wrapper_template)) {
824
+        if ( ! is_readable($wrapper_template)) {
825 825
             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));
826 826
         }
827 827
 
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
870 870
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
871 871
         $settings = $Message_Resource_Manager->get_active_messengers_option();
872
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
872
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
873 873
     }
874 874
 
875 875
 
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
887 887
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
888 888
         $existing = $Message_Resource_Manager->get_active_messengers_option();
889
-        $existing[ $this->name ]['test_settings'] = $settings;
889
+        $existing[$this->name]['test_settings'] = $settings;
890 890
         return $Message_Resource_Manager->update_active_messengers_option($existing);
891 891
     }
892 892
 
@@ -903,23 +903,23 @@  discard block
 block discarded – undo
903 903
     public function get_field_label($field)
904 904
     {
905 905
         // first let's see if the field requests is in the top level array.
906
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
907
-            return $this->_template[ $field ]['label'];
906
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
907
+            return $this->_template[$field]['label'];
908 908
         }
909 909
 
910 910
         // 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.
911
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
912
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
911
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
912
+            return $this->_template_fields['extra'][$field]['main']['label'];
913 913
         }
914 914
 
915 915
         // now it's possible this field may just be existing in any of the extra array items.
916
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
916
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
917 917
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
918
-                if (!is_array($subfields)) {
918
+                if ( ! is_array($subfields)) {
919 919
                     continue;
920 920
                 }
921
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
922
-                    return $subfields[ $field ]['label'];
921
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
922
+                    return $subfields[$field]['label'];
923 923
                 }
924 924
             }
925 925
         }
Please login to merge, or discard this patch.
messages/messenger/admin_templates/event_switcher_row.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,6 +41,6 @@
 block discarded – undo
41 41
         <label class='screen-reader-text for-event-message-actions'>
42 42
             <?php esc_html_e('Actions', 'event_espresso'); ?>
43 43
         </label>
44
-        <div class='event-message-actions'><?php echo $create_button . $edit_button; ?></div>
44
+        <div class='event-message-actions'><?php echo $create_button.$edit_button; ?></div>
45 45
     </td>
46 46
 </tr>
Please login to merge, or discard this patch.