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